anobis
Version:
JavaScript obfuscator
71 lines (59 loc) • 2.73 kB
text/typescript
import { injectable, inject } from 'inversify';
import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
import * as ESTree from 'estree';
import { TControlFlowCustomNodeFactory } from '../../../types/container/custom-nodes/TControlFlowCustomNodeFactory';
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
import { IStorage } from '../../../interfaces/storages/IStorage';
import { ControlFlowCustomNode } from '../../../enums/container/custom-nodes/ControlFlowCustomNode';
import { ExpressionWithOperatorControlFlowReplacer } from './ExpressionWithOperatorControlFlowReplacer';
()
export class BinaryExpressionControlFlowReplacer extends ExpressionWithOperatorControlFlowReplacer {
/**
* @type {number}
*/
private static readonly usingExistingIdentifierChance: number = 0.5;
/**
* @param {TControlFlowCustomNodeFactory} controlFlowCustomNodeFactory
* @param {IRandomGenerator} randomGenerator
* @param {IOptions} options
*/
constructor (
(ServiceIdentifiers.Factory__IControlFlowCustomNode)
controlFlowCustomNodeFactory: TControlFlowCustomNodeFactory,
(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
(ServiceIdentifiers.IOptions) options: IOptions
) {
super(controlFlowCustomNodeFactory, randomGenerator, options);
}
/**
* @param {BinaryExpression} binaryExpressionNode
* @param {Node} parentNode
* @param {IStorage<ICustomNode>} controlFlowStorage
* @returns {Node}
*/
public replace (
binaryExpressionNode: ESTree.BinaryExpression,
parentNode: ESTree.Node,
controlFlowStorage: IStorage <ICustomNode>
): ESTree.Node {
const replacerId: string = binaryExpressionNode.operator;
const binaryExpressionFunctionCustomNode: ICustomNode = this.controlFlowCustomNodeFactory(
ControlFlowCustomNode.BinaryExpressionFunctionNode
);
binaryExpressionFunctionCustomNode.initialize(replacerId);
const storageKey: string = this.insertCustomNodeToControlFlowStorage(
binaryExpressionFunctionCustomNode,
controlFlowStorage,
replacerId,
BinaryExpressionControlFlowReplacer.usingExistingIdentifierChance
);
return this.getControlFlowStorageCallNode(
controlFlowStorage.getStorageId(),
storageKey,
binaryExpressionNode.left,
binaryExpressionNode.right
);
}
}