Enum names refactoring

This commit is contained in:
sanex3339
2017-06-10 17:30:21 +03:00
parent aabbd8a596
commit f1045c20c1
49 changed files with 512 additions and 514 deletions
+243 -244
View File
File diff suppressed because it is too large Load Diff
+26 -26
View File
@@ -17,8 +17,8 @@ import { IStackTraceData } from './interfaces/stack-trace-analyzer/IStackTraceDa
import { IStorage } from './interfaces/storages/IStorage';
import { IVisitor } from './interfaces/IVisitor';
import { NodeTransformers } from './enums/container/node-transformers/NodeTransformers';
import { ObfuscationEvents } from './enums/event-emitters/ObfuscationEvents';
import { NodeTransformer } from './enums/container/node-transformers/NodeTransformer';
import { ObfuscationEvent } from './enums/event-emitters/ObfuscationEvent';
import { VisitorDirection } from './enums/VisitorDirection';
import { Node } from './node/Node';
@@ -27,40 +27,40 @@ import { NodeUtils } from './node/NodeUtils';
@injectable()
export class Obfuscator implements IObfuscator {
/**
* @type {NodeTransformers[]}
* @type {NodeTransformer[]}
*/
private static readonly controlFlowTransformersList: NodeTransformers[] = [
NodeTransformers.BlockStatementControlFlowTransformer,
NodeTransformers.FunctionControlFlowTransformer
private static readonly controlFlowTransformersList: NodeTransformer[] = [
NodeTransformer.BlockStatementControlFlowTransformer,
NodeTransformer.FunctionControlFlowTransformer
];
/**
* @type {NodeTransformers[]}
* @type {NodeTransformer[]}
*/
private static readonly convertingTransformersList: NodeTransformers[] = [
NodeTransformers.MemberExpressionTransformer,
NodeTransformers.MethodDefinitionTransformer,
NodeTransformers.TemplateLiteralTransformer
private static readonly convertingTransformersList: NodeTransformer[] = [
NodeTransformer.MemberExpressionTransformer,
NodeTransformer.MethodDefinitionTransformer,
NodeTransformer.TemplateLiteralTransformer
];
/**
* @type {NodeTransformers[]}
* @type {NodeTransformer[]}
*/
private static readonly deadCodeInjectionTransformersList: NodeTransformers[] = [
NodeTransformers.DeadCodeInjectionTransformer
private static readonly deadCodeInjectionTransformersList: NodeTransformer[] = [
NodeTransformer.DeadCodeInjectionTransformer
];
/**
* @type {NodeTransformers[]}
* @type {NodeTransformer[]}
*/
private static readonly obfuscatingTransformersList: NodeTransformers[] = [
NodeTransformers.CatchClauseTransformer,
NodeTransformers.FunctionDeclarationTransformer,
NodeTransformers.FunctionTransformer,
NodeTransformers.LabeledStatementTransformer,
NodeTransformers.LiteralTransformer,
NodeTransformers.ObjectExpressionTransformer,
NodeTransformers.VariableDeclarationTransformer
private static readonly obfuscatingTransformersList: NodeTransformer[] = [
NodeTransformer.CatchClauseTransformer,
NodeTransformer.FunctionDeclarationTransformer,
NodeTransformer.FunctionTransformer,
NodeTransformer.LabeledStatementTransformer,
NodeTransformer.LiteralTransformer,
NodeTransformer.ObjectExpressionTransformer,
NodeTransformer.VariableDeclarationTransformer
];
/**
@@ -134,7 +134,7 @@ export class Obfuscator implements IObfuscator {
);
});
this.obfuscationEventEmitter.emit(ObfuscationEvents.BeforeObfuscation, astTree, stackTraceData);
this.obfuscationEventEmitter.emit(ObfuscationEvent.BeforeObfuscation, astTree, stackTraceData);
// first pass transformers: dead code injection transformer
astTree = this.transformAstTree(astTree, [
@@ -152,7 +152,7 @@ export class Obfuscator implements IObfuscator {
...Obfuscator.obfuscatingTransformersList
]);
this.obfuscationEventEmitter.emit(ObfuscationEvents.AfterObfuscation, astTree, stackTraceData);
this.obfuscationEventEmitter.emit(ObfuscationEvent.AfterObfuscation, astTree, stackTraceData);
return astTree;
}
@@ -163,7 +163,7 @@ export class Obfuscator implements IObfuscator {
*/
private transformAstTree (
astTree: ESTree.Program,
nodeTransformers: NodeTransformers[]
nodeTransformers: NodeTransformer[]
): ESTree.Program {
if (!nodeTransformers.length) {
return astTree;
@@ -6,8 +6,8 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { ICustomNodeGroup } from '../../../interfaces/custom-nodes/ICustomNodeGroup';
import { IOptions } from '../../../interfaces/options/IOptions';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { CustomNodeGroups } from '../../../enums/container/custom-nodes/CustomNodeGroups';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { CustomNodeGroup } from '../../../enums/container/custom-nodes/CustomNodeGroup';
import { ConsoleOutputCustomNodeGroup } from '../../../custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup';
import { DebugProtectionCustomNodeGroup } from '../../../custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup';
@@ -39,109 +39,109 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
// custom nodes
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(BinaryExpressionFunctionNode)
.whenTargetNamed(CustomNodes.BinaryExpressionFunctionNode);
.whenTargetNamed(CustomNode.BinaryExpressionFunctionNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(BlockStatementControlFlowFlatteningNode)
.whenTargetNamed(CustomNodes.BlockStatementControlFlowFlatteningNode);
.whenTargetNamed(CustomNode.BlockStatementControlFlowFlatteningNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(CallExpressionControlFlowStorageCallNode)
.whenTargetNamed(CustomNodes.CallExpressionControlFlowStorageCallNode);
.whenTargetNamed(CustomNode.CallExpressionControlFlowStorageCallNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(CallExpressionFunctionNode)
.whenTargetNamed(CustomNodes.CallExpressionFunctionNode);
.whenTargetNamed(CustomNode.CallExpressionFunctionNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(ControlFlowStorageNode)
.whenTargetNamed(CustomNodes.ControlFlowStorageNode);
.whenTargetNamed(CustomNode.ControlFlowStorageNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(ConsoleOutputDisableExpressionNode)
.whenTargetNamed(CustomNodes.ConsoleOutputDisableExpressionNode);
.whenTargetNamed(CustomNode.ConsoleOutputDisableExpressionNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(DebugProtectionFunctionCallNode)
.whenTargetNamed(CustomNodes.DebugProtectionFunctionCallNode);
.whenTargetNamed(CustomNode.DebugProtectionFunctionCallNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(DebugProtectionFunctionIntervalNode)
.whenTargetNamed(CustomNodes.DebugProtectionFunctionIntervalNode);
.whenTargetNamed(CustomNode.DebugProtectionFunctionIntervalNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(DebugProtectionFunctionNode)
.whenTargetNamed(CustomNodes.DebugProtectionFunctionNode);
.whenTargetNamed(CustomNode.DebugProtectionFunctionNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(DomainLockNode)
.whenTargetNamed(CustomNodes.DomainLockNode);
.whenTargetNamed(CustomNode.DomainLockNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(ExpressionWithOperatorControlFlowStorageCallNode)
.whenTargetNamed(CustomNodes.ExpressionWithOperatorControlFlowStorageCallNode);
.whenTargetNamed(CustomNode.ExpressionWithOperatorControlFlowStorageCallNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(LogicalExpressionFunctionNode)
.whenTargetNamed(CustomNodes.LogicalExpressionFunctionNode);
.whenTargetNamed(CustomNode.LogicalExpressionFunctionNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(NodeCallsControllerFunctionNode)
.whenTargetNamed(CustomNodes.NodeCallsControllerFunctionNode);
.whenTargetNamed(CustomNode.NodeCallsControllerFunctionNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(SelfDefendingUnicodeNode)
.whenTargetNamed(CustomNodes.SelfDefendingUnicodeNode);
.whenTargetNamed(CustomNode.SelfDefendingUnicodeNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(StringArrayCallsWrapper)
.whenTargetNamed(CustomNodes.StringArrayCallsWrapper);
.whenTargetNamed(CustomNode.StringArrayCallsWrapper);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(StringArrayNode)
.whenTargetNamed(CustomNodes.StringArrayNode);
.whenTargetNamed(CustomNode.StringArrayNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(StringArrayRotateFunctionNode)
.whenTargetNamed(CustomNodes.StringArrayRotateFunctionNode);
.whenTargetNamed(CustomNode.StringArrayRotateFunctionNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(StringLiteralControlFlowStorageCallNode)
.whenTargetNamed(CustomNodes.StringLiteralControlFlowStorageCallNode);
.whenTargetNamed(CustomNode.StringLiteralControlFlowStorageCallNode);
bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
.toConstructor(StringLiteralNode)
.whenTargetNamed(CustomNodes.StringLiteralNode);
.whenTargetNamed(CustomNode.StringLiteralNode);
// node groups
bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
.to(ConsoleOutputCustomNodeGroup)
.whenTargetNamed(CustomNodeGroups.ConsoleOutputCustomNodeGroup);
.whenTargetNamed(CustomNodeGroup.ConsoleOutputCustomNodeGroup);
bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
.to(DebugProtectionCustomNodeGroup)
.whenTargetNamed(CustomNodeGroups.DebugProtectionCustomNodeGroup);
.whenTargetNamed(CustomNodeGroup.DebugProtectionCustomNodeGroup);
bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
.to(DomainLockCustomNodeGroup)
.whenTargetNamed(CustomNodeGroups.DomainLockCustomNodeGroup);
.whenTargetNamed(CustomNodeGroup.DomainLockCustomNodeGroup);
bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
.to(SelfDefendingCustomNodeGroup)
.whenTargetNamed(CustomNodeGroups.SelfDefendingCustomNodeGroup);
.whenTargetNamed(CustomNodeGroup.SelfDefendingCustomNodeGroup);
bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
.to(StringArrayCustomNodeGroup)
.whenTargetNamed(CustomNodeGroups.StringArrayCustomNodeGroup);
.whenTargetNamed(CustomNodeGroup.StringArrayCustomNodeGroup);
// customNode factory
bind<ICustomNode>(ServiceIdentifiers.Factory__ICustomNode)
.toFactory<ICustomNode>((context: interfaces.Context) => {
const cache: Map <CustomNodes, interfaces.Newable<ICustomNode>> = new Map();
const cache: Map <CustomNode, interfaces.Newable<ICustomNode>> = new Map();
let cachedOptions: IOptions;
return (customNodeName: CustomNodes) => {
return (customNodeName: CustomNode) => {
if (!cachedOptions) {
cachedOptions = context.container.get<IOptions>(ServiceIdentifiers.IOptions);
}
@@ -165,5 +165,5 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
// customNodeGroup factory
bind<ICustomNodeGroup>(ServiceIdentifiers.Factory__ICustomNodeGroup)
.toFactory<ICustomNodeGroup>(InversifyContainerFacade
.getFactory<CustomNodeGroups, ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup));
.getFactory<CustomNodeGroup, ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup));
});
@@ -4,7 +4,7 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
import { IControlFlowReplacer } from '../../../interfaces/node-transformers/control-flow-transformers/IControlFlowReplacer';
import { ControlFlowReplacers } from '../../../enums/container/node-transformers/ControlFlowReplacers';
import { ControlFlowReplacer } from '../../../enums/container/node-transformers/ControlFlowReplacer';
import { BinaryExpressionControlFlowReplacer } from '../../../node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer';
import { CallExpressionControlFlowReplacer } from '../../../node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer';
@@ -14,21 +14,21 @@ import { StringLiteralControlFlowReplacer } from '../../../node-transformers/con
export const controlFlowTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
.to(BinaryExpressionControlFlowReplacer)
.whenTargetNamed(ControlFlowReplacers.BinaryExpressionControlFlowReplacer);
.whenTargetNamed(ControlFlowReplacer.BinaryExpressionControlFlowReplacer);
bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
.to(CallExpressionControlFlowReplacer)
.whenTargetNamed(ControlFlowReplacers.CallExpressionControlFlowReplacer);
.whenTargetNamed(ControlFlowReplacer.CallExpressionControlFlowReplacer);
bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
.to(LogicalExpressionControlFlowReplacer)
.whenTargetNamed(ControlFlowReplacers.LogicalExpressionControlFlowReplacer);
.whenTargetNamed(ControlFlowReplacer.LogicalExpressionControlFlowReplacer);
bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
.to(StringLiteralControlFlowReplacer)
.whenTargetNamed(ControlFlowReplacers.StringLiteralControlFlowReplacer);
.whenTargetNamed(ControlFlowReplacer.StringLiteralControlFlowReplacer);
bind<IControlFlowReplacer>(ServiceIdentifiers.Factory__IControlFlowReplacer)
.toFactory<IControlFlowReplacer>(InversifyContainerFacade
.getCacheFactory<ControlFlowReplacers, IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer));
.getCacheFactory<ControlFlowReplacer, IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer));
});
@@ -4,7 +4,7 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
import { INodeTransformer } from '../../../interfaces/node-transformers/INodeTransformer';
import { NodeTransformers } from '../../../enums/container/node-transformers/NodeTransformers';
import { NodeTransformer } from '../../../enums/container/node-transformers/NodeTransformer';
import { FunctionControlFlowTransformer } from '../../../node-transformers/control-flow-transformers/FunctionControlFlowTransformer';
@@ -25,60 +25,60 @@ export const nodeTransformersModule: interfaces.ContainerModule = new ContainerM
// control flow transformers
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(BlockStatementControlFlowTransformer)
.whenTargetNamed(NodeTransformers.BlockStatementControlFlowTransformer);
.whenTargetNamed(NodeTransformer.BlockStatementControlFlowTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(DeadCodeInjectionTransformer)
.whenTargetNamed(NodeTransformers.DeadCodeInjectionTransformer);
.whenTargetNamed(NodeTransformer.DeadCodeInjectionTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(FunctionControlFlowTransformer)
.whenTargetNamed(NodeTransformers.FunctionControlFlowTransformer);
.whenTargetNamed(NodeTransformer.FunctionControlFlowTransformer);
// converting transformers
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(MemberExpressionTransformer)
.whenTargetNamed(NodeTransformers.MemberExpressionTransformer);
.whenTargetNamed(NodeTransformer.MemberExpressionTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(MethodDefinitionTransformer)
.whenTargetNamed(NodeTransformers.MethodDefinitionTransformer);
.whenTargetNamed(NodeTransformer.MethodDefinitionTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(TemplateLiteralTransformer)
.whenTargetNamed(NodeTransformers.TemplateLiteralTransformer);
.whenTargetNamed(NodeTransformer.TemplateLiteralTransformer);
// obfuscation transformers
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(CatchClauseTransformer)
.whenTargetNamed(NodeTransformers.CatchClauseTransformer);
.whenTargetNamed(NodeTransformer.CatchClauseTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(FunctionDeclarationTransformer)
.whenTargetNamed(NodeTransformers.FunctionDeclarationTransformer);
.whenTargetNamed(NodeTransformer.FunctionDeclarationTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(FunctionTransformer)
.whenTargetNamed(NodeTransformers.FunctionTransformer);
.whenTargetNamed(NodeTransformer.FunctionTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(LabeledStatementTransformer)
.whenTargetNamed(NodeTransformers.LabeledStatementTransformer);
.whenTargetNamed(NodeTransformer.LabeledStatementTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(LiteralTransformer)
.whenTargetNamed(NodeTransformers.LiteralTransformer);
.whenTargetNamed(NodeTransformer.LiteralTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(ObjectExpressionTransformer)
.whenTargetNamed(NodeTransformers.ObjectExpressionTransformer);
.whenTargetNamed(NodeTransformer.ObjectExpressionTransformer);
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(VariableDeclarationTransformer)
.whenTargetNamed(NodeTransformers.VariableDeclarationTransformer);
.whenTargetNamed(NodeTransformer.VariableDeclarationTransformer);
// node transformers factory
bind<INodeTransformer>(ServiceIdentifiers.Factory__INodeTransformer)
.toFactory<INodeTransformer>(InversifyContainerFacade
.getCacheFactory<NodeTransformers, INodeTransformer>(ServiceIdentifiers.INodeTransformer));
.getCacheFactory<NodeTransformer, INodeTransformer>(ServiceIdentifiers.INodeTransformer));
});
@@ -5,11 +5,11 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
import { IIdentifierObfuscatingReplacer } from '../../../interfaces/node-transformers/obfuscating-transformers/IIdentifierObfuscatingReplacer';
import { IObfuscatingReplacer } from '../../../interfaces/node-transformers/obfuscating-transformers/IObfuscatingReplacer';
import { IdentifierObfuscatingReplacers } from '../../../enums/container/node-transformers/IdentifierObfuscatingReplacers';
import { LiteralObfuscatingReplacers } from '../../../enums/container/node-transformers/LiteralObfuscatingReplacers';
import { IdentifierObfuscatingReplacer } from '../../../enums/container/node-transformers/IdentifierObfuscatingReplacer';
import { LiteralObfuscatingReplacer } from '../../../enums/container/node-transformers/LiteralObfuscatingReplacer';
import { BaseIdentifierObfuscatingReplacer } from '../../../node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer';
import { BooleanLiteralObfuscatingReplacer } from '../../../node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/BooleanLiteralObfuscatingReplacer';
import { IdentifierObfuscatingReplacer } from '../../../node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/IdentifierObfuscatingReplacer';
import { NumberLiteralObfuscatingReplacer } from '../../../node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/NumberLiteralObfuscatingReplacer';
import { StringLiteralObfuscatingReplacer } from '../../../node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/StringLiteralObfuscatingReplacer';
@@ -17,32 +17,32 @@ export const obfuscatingTransformersModule: interfaces.ContainerModule = new Con
// literal obfuscating replacers
bind<IObfuscatingReplacer>(ServiceIdentifiers.IObfuscatingReplacer)
.to(BooleanLiteralObfuscatingReplacer)
.whenTargetNamed(LiteralObfuscatingReplacers.BooleanLiteralObfuscatingReplacer);
.whenTargetNamed(LiteralObfuscatingReplacer.BooleanLiteralObfuscatingReplacer);
bind<IObfuscatingReplacer>(ServiceIdentifiers.IObfuscatingReplacer)
.to(NumberLiteralObfuscatingReplacer)
.whenTargetNamed(LiteralObfuscatingReplacers.NumberLiteralObfuscatingReplacer);
.whenTargetNamed(LiteralObfuscatingReplacer.NumberLiteralObfuscatingReplacer);
bind<IObfuscatingReplacer>(ServiceIdentifiers.IObfuscatingReplacer)
.to(StringLiteralObfuscatingReplacer)
.whenTargetNamed(LiteralObfuscatingReplacers.StringLiteralObfuscatingReplacer);
.whenTargetNamed(LiteralObfuscatingReplacer.StringLiteralObfuscatingReplacer);
// identifier obfuscating replacers
bind<IIdentifierObfuscatingReplacer>(ServiceIdentifiers.IIdentifierObfuscatingReplacer)
.to(IdentifierObfuscatingReplacer)
.whenTargetNamed(IdentifierObfuscatingReplacers.IdentifierObfuscatingReplacer);
.to(BaseIdentifierObfuscatingReplacer)
.whenTargetNamed(IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer);
// literal obfuscating replacer factory
bind<IObfuscatingReplacer>(ServiceIdentifiers.Factory__IObfuscatingReplacer)
.toFactory<IObfuscatingReplacer>(InversifyContainerFacade
.getCacheFactory<LiteralObfuscatingReplacers, IObfuscatingReplacer>(
.getCacheFactory<LiteralObfuscatingReplacer, IObfuscatingReplacer>(
ServiceIdentifiers.IObfuscatingReplacer
));
// identifier obfuscating replacer factory
bind<IIdentifierObfuscatingReplacer>(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
.toFactory<IIdentifierObfuscatingReplacer>(InversifyContainerFacade
.getCacheFactory<IdentifierObfuscatingReplacers, IIdentifierObfuscatingReplacer>(
.getCacheFactory<IdentifierObfuscatingReplacer, IIdentifierObfuscatingReplacer>(
ServiceIdentifiers.IIdentifierObfuscatingReplacer
));
});
@@ -5,7 +5,7 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
import { ICalleeDataExtractor } from '../../../interfaces/stack-trace-analyzer/ICalleeDataExtractor';
import { IStackTraceAnalyzer } from '../../../interfaces/stack-trace-analyzer/IStackTraceAnalyzer';
import { CalleeDataExtractors } from '../../../enums/container/stack-trace-analyzer/CalleeDataExtractors';
import { CalleeDataExtractor } from '../../../enums/container/stack-trace-analyzer/CalleeDataExtractor';
import { FunctionDeclarationCalleeDataExtractor } from '../../../stack-trace-analyzer/callee-data-extractors/FunctionDeclarationCalleeDataExtractor';
import { FunctionExpressionCalleeDataExtractor } from '../../../stack-trace-analyzer/callee-data-extractors/FunctionExpressionCalleeDataExtractor';
import { ObjectExpressionCalleeDataExtractor } from '../../../stack-trace-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor';
@@ -20,20 +20,20 @@ export const stackTraceAnalyzerModule: interfaces.ContainerModule = new Containe
// callee data extractors
bind<ICalleeDataExtractor>(ServiceIdentifiers.ICalleeDataExtractor)
.to(FunctionDeclarationCalleeDataExtractor)
.whenTargetNamed(CalleeDataExtractors.FunctionDeclarationCalleeDataExtractor);
.whenTargetNamed(CalleeDataExtractor.FunctionDeclarationCalleeDataExtractor);
bind<ICalleeDataExtractor>(ServiceIdentifiers.ICalleeDataExtractor)
.to(FunctionExpressionCalleeDataExtractor)
.whenTargetNamed(CalleeDataExtractors.FunctionExpressionCalleeDataExtractor);
.whenTargetNamed(CalleeDataExtractor.FunctionExpressionCalleeDataExtractor);
bind<ICalleeDataExtractor>(ServiceIdentifiers.ICalleeDataExtractor)
.to(ObjectExpressionCalleeDataExtractor)
.whenTargetNamed(CalleeDataExtractors.ObjectExpressionCalleeDataExtractor);
.whenTargetNamed(CalleeDataExtractor.ObjectExpressionCalleeDataExtractor);
// node transformers factory
bind<ICalleeDataExtractor>(ServiceIdentifiers.Factory__ICalleeDataExtractor)
.toFactory<ICalleeDataExtractor>(InversifyContainerFacade
.getCacheFactory<CalleeDataExtractors, ICalleeDataExtractor>(
.getCacheFactory<CalleeDataExtractor, ICalleeDataExtractor>(
ServiceIdentifiers.ICalleeDataExtractor
));
});
+6 -6
View File
@@ -9,7 +9,7 @@ import { ICustomNodeGroup } from '../interfaces/custom-nodes/ICustomNodeGroup';
import { IOptions } from '../interfaces/options/IOptions';
import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData';
import { CustomNodes } from '../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../enums/container/custom-nodes/CustomNode';
@injectable()
export abstract class AbstractCustomNodeGroup implements ICustomNodeGroup {
@@ -19,9 +19,9 @@ export abstract class AbstractCustomNodeGroup implements ICustomNodeGroup {
protected abstract readonly appendEvent: TObfuscationEvent;
/**
* @type {Map<CustomNodes, ICustomNode>}
* @type {Map<CustomNode, ICustomNode>}
*/
protected abstract customNodes: Map <CustomNodes, ICustomNode>;
protected abstract customNodes: Map <CustomNode, ICustomNode>;
/**
* @type {IStackTraceData[]}
@@ -56,9 +56,9 @@ export abstract class AbstractCustomNodeGroup implements ICustomNodeGroup {
}
/**
* @returns {Map<CustomNodes, ICustomNode>}
* @returns {Map<CustomNode, ICustomNode>}
*/
public getCustomNodes (): Map <CustomNodes, ICustomNode> {
public getCustomNodes (): Map <CustomNode, ICustomNode> {
return this.customNodes;
}
@@ -68,7 +68,7 @@ export abstract class AbstractCustomNodeGroup implements ICustomNodeGroup {
* @param customNodeName
* @param callback
*/
protected appendCustomNodeIfExist (customNodeName: CustomNodes, callback: (customNode: ICustomNode) => void): void {
protected appendCustomNodeIfExist (customNodeName: CustomNode, callback: (customNode: ICustomNode) => void): void {
const customNode: ICustomNode | undefined = this.customNodes.get(customNodeName);
if (!customNode) {
@@ -12,8 +12,8 @@ import { IStackTraceData } from '../../../interfaces/stack-trace-analyzer/IStack
import { initializable } from '../../../decorators/Initializable';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { ObfuscationEvents } from '../../../enums/event-emitters/ObfuscationEvents';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { NodeAppender } from '../../../node/NodeAppender';
@@ -24,13 +24,13 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @type {TObfuscationEvent}
*/
protected readonly appendEvent: TObfuscationEvent = ObfuscationEvents.BeforeObfuscation;
protected readonly appendEvent: TObfuscationEvent = ObfuscationEvent.BeforeObfuscation;
/**
* @type {Map<CustomNodes, ICustomNode>}
* @type {Map<CustomNode, ICustomNode>}
*/
@initializable()
protected customNodes: Map <CustomNodes, ICustomNode>;
protected customNodes: Map <CustomNode, ICustomNode>;
/**
* @type {TCustomNodeFactory}
@@ -66,7 +66,7 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
const randomStackTraceIndex: number = NodeAppender.getRandomStackTraceIndex(stackTraceData.length);
// consoleOutputDisableExpressionNode append
this.appendCustomNodeIfExist(CustomNodes.ConsoleOutputDisableExpressionNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.ConsoleOutputDisableExpressionNode, (customNode: ICustomNode) => {
NodeAppender.appendNodeToOptimalBlockScope(
stackTraceData,
blockScopeNode,
@@ -76,7 +76,7 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
});
// nodeCallsControllerFunctionNode append
this.appendCustomNodeIfExist(CustomNodes.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
let targetBlockScope: TNodeWithBlockStatement;
if (stackTraceData.length) {
@@ -90,7 +90,7 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
}
public initialize (): void {
this.customNodes = new Map <CustomNodes, ICustomNode> ();
this.customNodes = new Map <CustomNode, ICustomNode> ();
if (!this.options.disableConsoleOutput) {
return;
@@ -98,13 +98,13 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
const callsControllerFunctionName: string = RandomGeneratorUtils.getRandomVariableName(6);
const consoleOutputDisableExpressionNode: ICustomNode = this.customNodeFactory(CustomNodes.ConsoleOutputDisableExpressionNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.NodeCallsControllerFunctionNode);
const consoleOutputDisableExpressionNode: ICustomNode = this.customNodeFactory(CustomNode.ConsoleOutputDisableExpressionNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
consoleOutputDisableExpressionNode.initialize(callsControllerFunctionName);
nodeCallsControllerFunctionNode.initialize(this.appendEvent, callsControllerFunctionName);
this.customNodes.set(CustomNodes.ConsoleOutputDisableExpressionNode, consoleOutputDisableExpressionNode);
this.customNodes.set(CustomNodes.NodeCallsControllerFunctionNode, nodeCallsControllerFunctionNode);
this.customNodes.set(CustomNode.ConsoleOutputDisableExpressionNode, consoleOutputDisableExpressionNode);
this.customNodes.set(CustomNode.NodeCallsControllerFunctionNode, nodeCallsControllerFunctionNode);
}
}
@@ -12,8 +12,8 @@ import { IStackTraceData } from '../../../interfaces/stack-trace-analyzer/IStack
import { initializable } from '../../../decorators/Initializable';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { ObfuscationEvents } from '../../../enums/event-emitters/ObfuscationEvents';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { NodeAppender } from '../../../node/NodeAppender';
@@ -24,13 +24,13 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @type {TObfuscationEvent}
*/
protected readonly appendEvent: TObfuscationEvent = ObfuscationEvents.BeforeObfuscation;
protected readonly appendEvent: TObfuscationEvent = ObfuscationEvent.BeforeObfuscation;
/**
* @type {Map<CustomNodes, ICustomNode>}
* @type {Map<CustomNode, ICustomNode>}
*/
@initializable()
protected customNodes: Map <CustomNodes, ICustomNode>;
protected customNodes: Map <CustomNode, ICustomNode>;
/**
* @type {TCustomNodeFactory}
@@ -64,17 +64,17 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
*/
public appendCustomNodes (blockScopeNode: TNodeWithBlockStatement, stackTraceData: IStackTraceData[]): void {
// debugProtectionFunctionNode append
this.appendCustomNodeIfExist(CustomNodes.DebugProtectionFunctionNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.DebugProtectionFunctionNode, (customNode: ICustomNode) => {
NodeAppender.appendNode(blockScopeNode, customNode.getNode());
});
// debugProtectionFunctionCallNode append
this.appendCustomNodeIfExist(CustomNodes.DebugProtectionFunctionCallNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.DebugProtectionFunctionCallNode, (customNode: ICustomNode) => {
NodeAppender.appendNode(blockScopeNode, customNode.getNode());
});
// debugProtectionFunctionIntervalNode append
this.appendCustomNodeIfExist(CustomNodes.DebugProtectionFunctionIntervalNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.DebugProtectionFunctionIntervalNode, (customNode: ICustomNode) => {
const programBodyLength: number = blockScopeNode.body.length;
const randomIndex: number = RandomGeneratorUtils.getRandomInteger(0, programBodyLength);
@@ -83,7 +83,7 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
}
public initialize (): void {
this.customNodes = new Map <CustomNodes, ICustomNode> ();
this.customNodes = new Map <CustomNode, ICustomNode> ();
if (!this.options.debugProtection) {
return;
@@ -91,19 +91,19 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
const debugProtectionFunctionName: string = RandomGeneratorUtils.getRandomVariableName(6);
const debugProtectionFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.DebugProtectionFunctionNode);
const debugProtectionFunctionCallNode: ICustomNode = this.customNodeFactory(CustomNodes.DebugProtectionFunctionCallNode);
const debugProtectionFunctionIntervalNode: ICustomNode = this.customNodeFactory(CustomNodes.DebugProtectionFunctionIntervalNode);
const debugProtectionFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionNode);
const debugProtectionFunctionCallNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionCallNode);
const debugProtectionFunctionIntervalNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionIntervalNode);
debugProtectionFunctionNode.initialize(debugProtectionFunctionName);
debugProtectionFunctionCallNode.initialize(debugProtectionFunctionName);
debugProtectionFunctionIntervalNode.initialize(debugProtectionFunctionName);
this.customNodes.set(CustomNodes.DebugProtectionFunctionNode, debugProtectionFunctionNode);
this.customNodes.set(CustomNodes.DebugProtectionFunctionCallNode, debugProtectionFunctionCallNode);
this.customNodes.set(CustomNode.DebugProtectionFunctionNode, debugProtectionFunctionNode);
this.customNodes.set(CustomNode.DebugProtectionFunctionCallNode, debugProtectionFunctionCallNode);
if (this.options.debugProtectionInterval) {
this.customNodes.set(CustomNodes.DebugProtectionFunctionIntervalNode, debugProtectionFunctionIntervalNode);
this.customNodes.set(CustomNode.DebugProtectionFunctionIntervalNode, debugProtectionFunctionIntervalNode);
}
}
}
@@ -12,8 +12,8 @@ import { IStackTraceData } from '../../../interfaces/stack-trace-analyzer/IStack
import { initializable } from '../../../decorators/Initializable';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { ObfuscationEvents } from '../../../enums/event-emitters/ObfuscationEvents';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { NodeAppender } from '../../../node/NodeAppender';
@@ -24,13 +24,13 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @type {TObfuscationEvent}
*/
protected readonly appendEvent: TObfuscationEvent = ObfuscationEvents.BeforeObfuscation;
protected readonly appendEvent: TObfuscationEvent = ObfuscationEvent.BeforeObfuscation;
/**
* @type {Map<CustomNodes, ICustomNode>}
* @type {Map<CustomNode, ICustomNode>}
*/
@initializable()
protected customNodes: Map <CustomNodes, ICustomNode>;
protected customNodes: Map <CustomNode, ICustomNode>;
/**
* @type {TCustomNodeFactory}
@@ -66,7 +66,7 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
const randomStackTraceIndex: number = NodeAppender.getRandomStackTraceIndex(stackTraceData.length);
// domainLockNode append
this.appendCustomNodeIfExist(CustomNodes.DomainLockNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.DomainLockNode, (customNode: ICustomNode) => {
NodeAppender.appendNodeToOptimalBlockScope(
stackTraceData,
blockScopeNode,
@@ -76,7 +76,7 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
});
// nodeCallsControllerFunctionNode append
this.appendCustomNodeIfExist(CustomNodes.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
let targetBlockScope: TNodeWithBlockStatement;
if (stackTraceData.length) {
@@ -90,7 +90,7 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
}
public initialize (): void {
this.customNodes = new Map <CustomNodes, ICustomNode> ();
this.customNodes = new Map <CustomNode, ICustomNode> ();
if (!this.options.domainLock.length) {
return;
@@ -98,13 +98,13 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
const callsControllerFunctionName: string = RandomGeneratorUtils.getRandomVariableName(6);
const domainLockNode: ICustomNode = this.customNodeFactory(CustomNodes.DomainLockNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.NodeCallsControllerFunctionNode);
const domainLockNode: ICustomNode = this.customNodeFactory(CustomNode.DomainLockNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
domainLockNode.initialize(callsControllerFunctionName);
nodeCallsControllerFunctionNode.initialize(this.appendEvent, callsControllerFunctionName);
this.customNodes.set(CustomNodes.DomainLockNode, domainLockNode);
this.customNodes.set(CustomNodes.NodeCallsControllerFunctionNode, nodeCallsControllerFunctionNode);
this.customNodes.set(CustomNode.DomainLockNode, domainLockNode);
this.customNodes.set(CustomNode.NodeCallsControllerFunctionNode, nodeCallsControllerFunctionNode);
}
}
@@ -8,7 +8,7 @@ import { TStatement } from '../../types/node/TStatement';
import { IOptions } from '../../interfaces/options/IOptions';
import { ObfuscationEvents } from '../../enums/event-emitters/ObfuscationEvents';
import { ObfuscationEvent } from '../../enums/event-emitters/ObfuscationEvent';
import { initializable } from '../../decorators/Initializable';
@@ -63,7 +63,7 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
* @returns {string}
*/
protected getTemplate (): string {
if (this.appendEvent === ObfuscationEvents.AfterObfuscation) {
if (this.appendEvent === ObfuscationEvent.AfterObfuscation) {
return JavaScriptObfuscator.obfuscate(
format(SingleNodeCallControllerTemplate(), {
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
@@ -12,8 +12,8 @@ import { IStackTraceData } from '../../../interfaces/stack-trace-analyzer/IStack
import { initializable } from '../../../decorators/Initializable';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { ObfuscationEvents } from '../../../enums/event-emitters/ObfuscationEvents';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { NodeAppender } from '../../../node/NodeAppender';
@@ -24,13 +24,13 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @type {TObfuscationEvent}
*/
protected appendEvent: TObfuscationEvent = ObfuscationEvents.AfterObfuscation;
protected appendEvent: TObfuscationEvent = ObfuscationEvent.AfterObfuscation;
/**
* @type {Map<CustomNodes, ICustomNode>}
* @type {Map<CustomNode, ICustomNode>}
*/
@initializable()
protected customNodes: Map <CustomNodes, ICustomNode>;
protected customNodes: Map <CustomNode, ICustomNode>;
/**
* @type {TCustomNodeFactory}
@@ -66,7 +66,7 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
const randomStackTraceIndex: number = NodeAppender.getRandomStackTraceIndex(stackTraceData.length);
// selfDefendingUnicodeNode append
this.appendCustomNodeIfExist(CustomNodes.SelfDefendingUnicodeNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.SelfDefendingUnicodeNode, (customNode: ICustomNode) => {
NodeAppender.appendNodeToOptimalBlockScope(
stackTraceData,
blockScopeNode,
@@ -76,7 +76,7 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
});
// nodeCallsControllerFunctionNode append
this.appendCustomNodeIfExist(CustomNodes.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
let targetBlockScope: TNodeWithBlockStatement;
if (stackTraceData.length) {
@@ -90,7 +90,7 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
}
public initialize (): void {
this.customNodes = new Map <CustomNodes, ICustomNode> ();
this.customNodes = new Map <CustomNode, ICustomNode> ();
if (!this.options.selfDefending) {
return;
@@ -98,13 +98,13 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
const callsControllerFunctionName: string = RandomGeneratorUtils.getRandomVariableName(6);
const selfDefendingUnicodeNode: ICustomNode = this.customNodeFactory(CustomNodes.SelfDefendingUnicodeNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.NodeCallsControllerFunctionNode);
const selfDefendingUnicodeNode: ICustomNode = this.customNodeFactory(CustomNode.SelfDefendingUnicodeNode);
const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
selfDefendingUnicodeNode.initialize(callsControllerFunctionName);
nodeCallsControllerFunctionNode.initialize(this.appendEvent, callsControllerFunctionName);
this.customNodes.set(CustomNodes.SelfDefendingUnicodeNode, selfDefendingUnicodeNode);
this.customNodes.set(CustomNodes.NodeCallsControllerFunctionNode, nodeCallsControllerFunctionNode);
this.customNodes.set(CustomNode.SelfDefendingUnicodeNode, selfDefendingUnicodeNode);
this.customNodes.set(CustomNode.NodeCallsControllerFunctionNode, nodeCallsControllerFunctionNode);
}
}
@@ -13,8 +13,8 @@ import { IStorage } from '../../../interfaces/storages/IStorage';
import { initializable } from '../../../decorators/Initializable';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { ObfuscationEvents } from '../../../enums/event-emitters/ObfuscationEvents';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent';
import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
import { NodeAppender } from '../../../node/NodeAppender';
@@ -26,13 +26,13 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @type {TObfuscationEvent}
*/
protected appendEvent: TObfuscationEvent = ObfuscationEvents.AfterObfuscation;
protected appendEvent: TObfuscationEvent = ObfuscationEvent.AfterObfuscation;
/**
* @type {Map<CustomNodes, ICustomNode>}
* @type {Map<CustomNode, ICustomNode>}
*/
@initializable()
protected customNodes: Map <CustomNodes, ICustomNode>;
protected customNodes: Map <CustomNode, ICustomNode>;
/**
* @type {TCustomNodeFactory}
@@ -79,31 +79,31 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
}
// stringArrayNode append
this.appendCustomNodeIfExist(CustomNodes.StringArrayNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.StringArrayNode, (customNode: ICustomNode) => {
NodeAppender.prependNode(blockScopeNode, customNode.getNode());
});
// stringArrayCallsWrapper append
this.appendCustomNodeIfExist(CustomNodes.StringArrayCallsWrapper, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.StringArrayCallsWrapper, (customNode: ICustomNode) => {
NodeAppender.insertNodeAtIndex(blockScopeNode, customNode.getNode(), 1);
});
// stringArrayRotateFunctionNode append
this.appendCustomNodeIfExist(CustomNodes.StringArrayRotateFunctionNode, (customNode: ICustomNode) => {
this.appendCustomNodeIfExist(CustomNode.StringArrayRotateFunctionNode, (customNode: ICustomNode) => {
NodeAppender.insertNodeAtIndex(blockScopeNode, customNode.getNode(), 1);
});
}
public initialize (): void {
this.customNodes = new Map <CustomNodes, ICustomNode> ();
this.customNodes = new Map <CustomNode, ICustomNode> ();
if (!this.options.stringArray) {
return;
}
const stringArrayNode: ICustomNode = this.customNodeFactory(CustomNodes.StringArrayNode);
const stringArrayCallsWrapper: ICustomNode = this.customNodeFactory(CustomNodes.StringArrayCallsWrapper);
const stringArrayRotateFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.StringArrayRotateFunctionNode);
const stringArrayNode: ICustomNode = this.customNodeFactory(CustomNode.StringArrayNode);
const stringArrayCallsWrapper: ICustomNode = this.customNodeFactory(CustomNode.StringArrayCallsWrapper);
const stringArrayRotateFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.StringArrayRotateFunctionNode);
const stringArrayStorageId: string = this.stringArrayStorage.getStorageId();
@@ -122,11 +122,11 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
stringArrayCallsWrapper.initialize(this.stringArrayStorage, stringArrayName, stringArrayCallsWrapperName);
stringArrayRotateFunctionNode.initialize(this.stringArrayStorage, stringArrayName, stringArrayRotateValue);
this.customNodes.set(CustomNodes.StringArrayNode, stringArrayNode);
this.customNodes.set(CustomNodes.StringArrayCallsWrapper, stringArrayCallsWrapper);
this.customNodes.set(CustomNode.StringArrayNode, stringArrayNode);
this.customNodes.set(CustomNode.StringArrayCallsWrapper, stringArrayCallsWrapper);
if (this.options.rotateStringArray) {
this.customNodes.set(CustomNodes.StringArrayRotateFunctionNode, stringArrayRotateFunctionNode);
this.customNodes.set(CustomNode.StringArrayRotateFunctionNode, stringArrayRotateFunctionNode);
}
}
}
@@ -1,4 +1,4 @@
export enum CustomNodes {
export enum CustomNode {
BinaryExpressionFunctionNode,
BlockStatementControlFlowFlatteningNode,
CallExpressionControlFlowStorageCallNode,
@@ -1,4 +1,4 @@
export enum CustomNodeGroups {
export enum CustomNodeGroup {
ConsoleOutputCustomNodeGroup,
DebugProtectionCustomNodeGroup,
DomainLockCustomNodeGroup,
@@ -1,4 +1,4 @@
export enum ControlFlowReplacers {
export enum ControlFlowReplacer {
BinaryExpressionControlFlowReplacer,
CallExpressionControlFlowReplacer,
LogicalExpressionControlFlowReplacer,
@@ -0,0 +1,3 @@
export enum IdentifierObfuscatingReplacer {
BaseIdentifierObfuscatingReplacer
}
@@ -1,3 +0,0 @@
export enum IdentifierObfuscatingReplacers {
IdentifierObfuscatingReplacer
}
@@ -1,4 +1,4 @@
export enum LiteralObfuscatingReplacers {
export enum LiteralObfuscatingReplacer {
BooleanLiteralObfuscatingReplacer,
NumberLiteralObfuscatingReplacer,
StringLiteralObfuscatingReplacer
@@ -1,4 +1,4 @@
export enum NodeTransformers {
export enum NodeTransformer {
BlockStatementControlFlowTransformer,
DeadCodeInjectionTransformer,
FunctionControlFlowTransformer,
@@ -1,4 +1,4 @@
export enum CalleeDataExtractors {
export enum CalleeDataExtractor {
FunctionDeclarationCalleeDataExtractor,
FunctionExpressionCalleeDataExtractor,
ObjectExpressionCalleeDataExtractor,
@@ -1,6 +1,6 @@
import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent';
export const ObfuscationEvents: {
export const ObfuscationEvent: {
AfterObfuscation: TObfuscationEvent,
BeforeObfuscation: TObfuscationEvent
} = {
+3 -3
View File
@@ -5,7 +5,7 @@ import { ICustomNode } from './ICustomNode';
import { IInitializable } from '../IInitializable';
import { IStackTraceData } from '../stack-trace-analyzer/IStackTraceData';
import { CustomNodes } from '../../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../../enums/container/custom-nodes/CustomNode';
export interface ICustomNodeGroup extends IInitializable {
/**
@@ -20,9 +20,9 @@ export interface ICustomNodeGroup extends IInitializable {
getAppendEvent (): TObfuscationEvent;
/**
* @type {Map <CustomNodes, ICustomNode>}
* @type {Map <CustomNode, ICustomNode>}
*/
getCustomNodes (): Map <CustomNodes, ICustomNode>;
getCustomNodes (): Map <CustomNode, ICustomNode>;
initialize (): void;
@@ -9,7 +9,7 @@ import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../interfaces/options/IOptions';
import { IVisitor } from '../../interfaces/IVisitor';
import { CustomNodes } from '../../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../../enums/container/custom-nodes/CustomNode';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { Node } from '../../node/Node';
@@ -86,7 +86,7 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme
const shuffledKeys: number[] = Utils.arrayShuffle(originalKeys);
const originalKeysIndexesInShuffledArray: number[] = originalKeys.map((key: number) => shuffledKeys.indexOf(key));
const blockStatementControlFlowFlatteningCustomNode: ICustomNode = this.customNodeFactory(
CustomNodes.BlockStatementControlFlowFlatteningNode
CustomNode.BlockStatementControlFlowFlatteningNode
);
blockStatementControlFlowFlatteningCustomNode.initialize(
@@ -14,26 +14,26 @@ import { IOptions } from '../../interfaces/options/IOptions';
import { IStorage } from '../../interfaces/storages/IStorage';
import { IVisitor } from '../../interfaces/IVisitor';
import { CustomNodes } from '../../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../../enums/container/custom-nodes/CustomNode';
import { NodeType } from '../../enums/NodeType';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { Node } from '../../node/Node';
import { NodeAppender } from '../../node/NodeAppender';
import { ControlFlowReplacers } from '../../enums/container/node-transformers/ControlFlowReplacers';
import { ControlFlowReplacer } from '../../enums/container/node-transformers/ControlFlowReplacer';
import { NodeUtils } from '../../node/NodeUtils';
import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils';
@injectable()
export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
/**
* @type {Map <string, ControlFlowReplacers>}
* @type {Map <string, ControlFlowReplacer>}
*/
private static readonly controlFlowReplacersMap: Map <string, ControlFlowReplacers> = new Map([
[NodeType.BinaryExpression, ControlFlowReplacers.BinaryExpressionControlFlowReplacer],
[NodeType.CallExpression, ControlFlowReplacers.CallExpressionControlFlowReplacer],
[NodeType.LogicalExpression, ControlFlowReplacers.LogicalExpressionControlFlowReplacer],
[NodeType.Literal, ControlFlowReplacers.StringLiteralControlFlowReplacer]
private static readonly controlFlowReplacersMap: Map <string, ControlFlowReplacer> = new Map([
[NodeType.BinaryExpression, ControlFlowReplacer.BinaryExpressionControlFlowReplacer],
[NodeType.CallExpression, ControlFlowReplacer.CallExpressionControlFlowReplacer],
[NodeType.LogicalExpression, ControlFlowReplacer.LogicalExpressionControlFlowReplacer],
[NodeType.Literal, ControlFlowReplacer.StringLiteralControlFlowReplacer]
]);
/**
@@ -158,7 +158,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
return functionNode;
}
const controlFlowStorageCustomNode: ICustomNode = this.customNodeFactory(CustomNodes.ControlFlowStorageNode);
const controlFlowStorageCustomNode: ICustomNode = this.customNodeFactory(CustomNode.ControlFlowStorageNode);
controlFlowStorageCustomNode.initialize(controlFlowStorage);
NodeAppender.prependNode(hostNode, controlFlowStorageCustomNode.getNode());
@@ -218,7 +218,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
return node;
}
const controlFlowReplacerName: ControlFlowReplacers = <ControlFlowReplacers>FunctionControlFlowTransformer
const controlFlowReplacerName: ControlFlowReplacer = <ControlFlowReplacer>FunctionControlFlowTransformer
.controlFlowReplacersMap.get(node.type);
if (controlFlowReplacerName === undefined) {
@@ -9,7 +9,7 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IStorage } from '../../../interfaces/storages/IStorage';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { ExpressionWithOperatorControlFlowReplacer } from './ExpressionWithOperatorControlFlowReplacer';
@@ -43,7 +43,7 @@ export class BinaryExpressionControlFlowReplacer extends ExpressionWithOperatorC
controlFlowStorage: IStorage <ICustomNode>
): ESTree.Node {
const replacerId: string = binaryExpressionNode.operator;
const binaryExpressionFunctionCustomNode: ICustomNode = this.customNodeFactory(CustomNodes.BinaryExpressionFunctionNode);
const binaryExpressionFunctionCustomNode: ICustomNode = this.customNodeFactory(CustomNode.BinaryExpressionFunctionNode);
binaryExpressionFunctionCustomNode.initialize(replacerId);
@@ -10,7 +10,7 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IStorage } from '../../../interfaces/storages/IStorage';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer';
import { Node } from '../../../node/Node';
@@ -51,7 +51,7 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac
}
const replacerId: string = String(callExpressionNode.arguments.length);
const callExpressionFunctionCustomNode: ICustomNode = this.customNodeFactory(CustomNodes.CallExpressionFunctionNode);
const callExpressionFunctionCustomNode: ICustomNode = this.customNodeFactory(CustomNode.CallExpressionFunctionNode);
const expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[] = callExpressionNode.arguments;
callExpressionFunctionCustomNode.initialize(expressionArguments);
@@ -86,7 +86,7 @@ export class CallExpressionControlFlowReplacer extends AbstractControlFlowReplac
expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[]
): ESTree.Node {
const controlFlowStorageCallCustomNode: ICustomNode = this.customNodeFactory(
CustomNodes.CallExpressionControlFlowStorageCallNode
CustomNode.CallExpressionControlFlowStorageCallNode
);
controlFlowStorageCallCustomNode.initialize(controlFlowStorageId, storageKey, callee, expressionArguments);
@@ -10,7 +10,7 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { Node } from '../../../node/Node';
@injectable()
@@ -55,7 +55,7 @@ export abstract class ExpressionWithOperatorControlFlowReplacer extends Abstract
rightExpression: ESTree.Expression
): ESTree.Node {
const controlFlowStorageCallCustomNode: ICustomNode = this.customNodeFactory(
CustomNodes.ExpressionWithOperatorControlFlowStorageCallNode
CustomNode.ExpressionWithOperatorControlFlowStorageCallNode
);
controlFlowStorageCallCustomNode.initialize(controlFlowStorageId, storageKey, leftExpression, rightExpression);
@@ -9,7 +9,7 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IStorage } from '../../../interfaces/storages/IStorage';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { ExpressionWithOperatorControlFlowReplacer } from './ExpressionWithOperatorControlFlowReplacer';
import { Node } from '../../../node/Node';
@@ -49,7 +49,7 @@ export class LogicalExpressionControlFlowReplacer extends ExpressionWithOperator
}
const replacerId: string = logicalExpressionNode.operator;
const logicalExpressionFunctionCustomNode: ICustomNode = this.customNodeFactory(CustomNodes.LogicalExpressionFunctionNode);
const logicalExpressionFunctionCustomNode: ICustomNode = this.customNodeFactory(CustomNode.LogicalExpressionFunctionNode);
logicalExpressionFunctionCustomNode.initialize(replacerId);
@@ -10,7 +10,7 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../../interfaces/options/IOptions';
import { IStorage } from '../../../interfaces/storages/IStorage';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer';
import { Node } from '../../../node/Node';
@@ -53,7 +53,7 @@ export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplace
}
const replacerId: string = String(literalNode.value);
const literalFunctionCustomNode: ICustomNode = this.customNodeFactory(CustomNodes.StringLiteralNode);
const literalFunctionCustomNode: ICustomNode = this.customNodeFactory(CustomNode.StringLiteralNode);
literalFunctionCustomNode.initialize(literalNode.value);
@@ -77,7 +77,7 @@ export class StringLiteralControlFlowReplacer extends AbstractControlFlowReplace
storageKey: string
): ESTree.Node {
const controlFlowStorageCallCustomNode: ICustomNode = this.customNodeFactory(
CustomNodes.StringLiteralControlFlowStorageCallNode
CustomNode.StringLiteralControlFlowStorageCallNode
);
controlFlowStorageCallCustomNode.initialize(controlFlowStorageId, storageKey);
@@ -10,7 +10,7 @@ import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transforme
import { IOptions } from '../../interfaces/options/IOptions';
import { IVisitor } from '../../interfaces/IVisitor';
import { IdentifierObfuscatingReplacers } from '../../enums/container/node-transformers/IdentifierObfuscatingReplacers';
import { IdentifierObfuscatingReplacer } from '../../enums/container/node-transformers/IdentifierObfuscatingReplacer';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { Node } from '../../node/Node';
@@ -42,7 +42,7 @@ export class CatchClauseTransformer extends AbstractNodeTransformer {
super(options);
this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
IdentifierObfuscatingReplacers.IdentifierObfuscatingReplacer
IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
);
}
@@ -11,7 +11,7 @@ import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transforme
import { IOptions } from '../../interfaces/options/IOptions';
import { IVisitor } from '../../interfaces/IVisitor';
import { IdentifierObfuscatingReplacers } from "../../enums/container/node-transformers/IdentifierObfuscatingReplacers";
import { IdentifierObfuscatingReplacer } from "../../enums/container/node-transformers/IdentifierObfuscatingReplacer";
import { NodeType } from '../../enums/NodeType';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
@@ -51,7 +51,7 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
super(options);
this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
IdentifierObfuscatingReplacers.IdentifierObfuscatingReplacer
IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
);
}
@@ -10,7 +10,7 @@ import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transforme
import { IOptions } from '../../interfaces/options/IOptions';
import { IVisitor } from '../../interfaces/IVisitor';
import { IdentifierObfuscatingReplacers } from '../../enums/container/node-transformers/IdentifierObfuscatingReplacers';
import { IdentifierObfuscatingReplacer } from '../../enums/container/node-transformers/IdentifierObfuscatingReplacer';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { Node } from '../../node/Node';
@@ -42,7 +42,7 @@ export class FunctionTransformer extends AbstractNodeTransformer {
super(options);
this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
IdentifierObfuscatingReplacers.IdentifierObfuscatingReplacer
IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
);
}
@@ -10,7 +10,7 @@ import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transforme
import { IOptions } from '../../interfaces/options/IOptions';
import { IVisitor } from '../../interfaces/IVisitor';
import { IdentifierObfuscatingReplacers } from '../../enums/container/node-transformers/IdentifierObfuscatingReplacers';
import { IdentifierObfuscatingReplacer } from '../../enums/container/node-transformers/IdentifierObfuscatingReplacer';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { Node } from '../../node/Node';
@@ -50,7 +50,7 @@ export class LabeledStatementTransformer extends AbstractNodeTransformer {
super(options);
this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
IdentifierObfuscatingReplacers.IdentifierObfuscatingReplacer
IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
);
}
@@ -8,7 +8,7 @@ import { TLiteralObfuscatingReplacerFactory } from '../../types/container/node-t
import { IOptions } from '../../interfaces/options/IOptions';
import { IVisitor } from '../../interfaces/IVisitor';
import { LiteralObfuscatingReplacers } from '../../enums/container/node-transformers/LiteralObfuscatingReplacers';
import { LiteralObfuscatingReplacer } from '../../enums/container/node-transformers/LiteralObfuscatingReplacer';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { Node } from '../../node/Node';
@@ -59,15 +59,15 @@ export class LiteralTransformer extends AbstractNodeTransformer {
switch (typeof literalNode.value) {
case 'boolean':
return this.literalObfuscatingReplacerFactory(LiteralObfuscatingReplacers.BooleanLiteralObfuscatingReplacer)
return this.literalObfuscatingReplacerFactory(LiteralObfuscatingReplacer.BooleanLiteralObfuscatingReplacer)
.replace(<boolean>literalNode.value);
case 'number':
return this.literalObfuscatingReplacerFactory(LiteralObfuscatingReplacers.NumberLiteralObfuscatingReplacer)
return this.literalObfuscatingReplacerFactory(LiteralObfuscatingReplacer.NumberLiteralObfuscatingReplacer)
.replace(<number>literalNode.value);
case 'string':
return this.literalObfuscatingReplacerFactory(LiteralObfuscatingReplacers.StringLiteralObfuscatingReplacer)
return this.literalObfuscatingReplacerFactory(LiteralObfuscatingReplacer.StringLiteralObfuscatingReplacer)
.replace(<string>literalNode.value);
default:
@@ -11,7 +11,7 @@ import { IOptions } from '../../interfaces/options/IOptions';
import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transformers/obfuscating-transformers/IIdentifierObfuscatingReplacer';
import { IVisitor } from '../../interfaces/IVisitor';
import { IdentifierObfuscatingReplacers } from "../../enums/container/node-transformers/IdentifierObfuscatingReplacers";
import { IdentifierObfuscatingReplacer } from "../../enums/container/node-transformers/IdentifierObfuscatingReplacer";
import { NodeType } from '../../enums/NodeType';
import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
@@ -52,7 +52,7 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
super(options);
this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
IdentifierObfuscatingReplacers.IdentifierObfuscatingReplacer
IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
);
}
@@ -11,7 +11,7 @@ import { Nodes } from '../../../../node/Nodes';
import { RandomGeneratorUtils } from '../../../../utils/RandomGeneratorUtils';
@injectable()
export class IdentifierObfuscatingReplacer extends AbstractObfuscatingReplacer implements IIdentifierObfuscatingReplacer {
export class BaseIdentifierObfuscatingReplacer extends AbstractObfuscatingReplacer implements IIdentifierObfuscatingReplacer {
/**
* @type {Map<string, string>}
*/
@@ -10,13 +10,13 @@ import { ICalleeData } from '../interfaces/stack-trace-analyzer/ICalleeData';
import { IStackTraceAnalyzer } from '../interfaces/stack-trace-analyzer/IStackTraceAnalyzer';
import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData';
import { CalleeDataExtractors } from '../enums/container/stack-trace-analyzer/CalleeDataExtractors';
import { CalleeDataExtractor } from '../enums/container/stack-trace-analyzer/CalleeDataExtractor';
import { Node } from '../node/Node';
import { NodeUtils } from '../node/NodeUtils';
/**
* This class generates a data with code stack trace functions calls
* This class generates a data with a stack trace of functions calls
*
* For example:
*
@@ -49,12 +49,12 @@ import { NodeUtils } from '../node/NodeUtils';
@injectable()
export class StackTraceAnalyzer implements IStackTraceAnalyzer {
/**
* @type {CalleeDataExtractors[]}
* @type {CalleeDataExtractor[]}
*/
private static readonly calleeDataExtractorsList: CalleeDataExtractors[] = [
CalleeDataExtractors.FunctionDeclarationCalleeDataExtractor,
CalleeDataExtractors.FunctionExpressionCalleeDataExtractor,
CalleeDataExtractors.ObjectExpressionCalleeDataExtractor
private static readonly calleeDataExtractorsList: CalleeDataExtractor[] = [
CalleeDataExtractor.FunctionDeclarationCalleeDataExtractor,
CalleeDataExtractor.FunctionExpressionCalleeDataExtractor,
CalleeDataExtractor.ObjectExpressionCalleeDataExtractor
];
/**
@@ -154,7 +154,7 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
blockScopeBody: ESTree.Node[],
callExpressionNode: ESTree.CallExpression
): void {
StackTraceAnalyzer.calleeDataExtractorsList.forEach((calleeDataExtractorName: CalleeDataExtractors) => {
StackTraceAnalyzer.calleeDataExtractorsList.forEach((calleeDataExtractorName: CalleeDataExtractor) => {
const calleeData: ICalleeData | null = this.calleeDataExtractorFactory(calleeDataExtractorName)
.extract(blockScopeBody, callExpressionNode.callee);
@@ -17,15 +17,15 @@ export class FunctionDeclarationCalleeDataExtractor extends AbstractCalleeDataEx
* @returns {ICalleeData|null}
*/
public extract (blockScopeBody: ESTree.Node[], callee: ESTree.Identifier): ICalleeData|null {
let calleeBlockStatement: ESTree.BlockStatement|null = null;
if (Node.isIdentifierNode(callee)) {
calleeBlockStatement = this.getCalleeBlockStatement(
NodeUtils.getBlockScopesOfNode(blockScopeBody[0])[0],
callee.name
);
if (!Node.isIdentifierNode(callee)) {
return null;
}
const calleeBlockStatement: ESTree.BlockStatement|null = this.getCalleeBlockStatement(
NodeUtils.getBlockScopesOfNode(blockScopeBody[0])[0],
callee.name
);
if (!calleeBlockStatement) {
return null;
}
@@ -19,23 +19,22 @@ export class ObjectExpressionCalleeDataExtractor extends AbstractCalleeDataExtra
* @returns {ICalleeData|null}
*/
public extract (blockScopeBody: ESTree.Node[], callee: ESTree.MemberExpression): ICalleeData|null {
let calleeBlockStatement: ESTree.BlockStatement|null = null,
functionExpressionName: string|number|null = null;
if (Node.isMemberExpressionNode(callee)) {
const objectMembersCallsChain: TObjectMembersCallsChain = this.createObjectMembersCallsChain([], callee);
if (!objectMembersCallsChain.length) {
return null;
}
functionExpressionName = objectMembersCallsChain[objectMembersCallsChain.length - 1];
calleeBlockStatement = this.getCalleeBlockStatement(
NodeUtils.getBlockScopesOfNode(blockScopeBody[0])[0],
objectMembersCallsChain
);
if (!Node.isMemberExpressionNode(callee)) {
return null;
}
const objectMembersCallsChain: TObjectMembersCallsChain = this.createObjectMembersCallsChain([], callee);
if (!objectMembersCallsChain.length) {
return null;
}
const functionExpressionName: string|number|null = objectMembersCallsChain[objectMembersCallsChain.length - 1];
const calleeBlockStatement: ESTree.BlockStatement|null = this.getCalleeBlockStatement(
NodeUtils.getBlockScopesOfNode(blockScopeBody[0])[0],
objectMembersCallsChain
);
if (!calleeBlockStatement) {
return null;
}
@@ -6,7 +6,7 @@ import { TCustomNodeGroupFactory } from '../../types/container/custom-nodes/TCus
import { ICustomNodeGroup } from '../../interfaces/custom-nodes/ICustomNodeGroup';
import { IOptions } from '../../interfaces/options/IOptions';
import { CustomNodeGroups } from '../../enums/container/custom-nodes/CustomNodeGroups';
import { CustomNodeGroup } from '../../enums/container/custom-nodes/CustomNodeGroup';
import { MapStorage } from '../MapStorage';
import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils';
@@ -14,14 +14,14 @@ import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils';
@injectable()
export class CustomNodeGroupStorage extends MapStorage <ICustomNodeGroup> {
/**
* @type {CustomNodeGroups[]}
* @type {CustomNodeGroup[]}
*/
private static readonly customNodeGroupsList: CustomNodeGroups[] = [
CustomNodeGroups.ConsoleOutputCustomNodeGroup,
CustomNodeGroups.DebugProtectionCustomNodeGroup,
CustomNodeGroups.DomainLockCustomNodeGroup,
CustomNodeGroups.SelfDefendingCustomNodeGroup,
CustomNodeGroups.StringArrayCustomNodeGroup
private static readonly customNodeGroupsList: CustomNodeGroup[] = [
CustomNodeGroup.ConsoleOutputCustomNodeGroup,
CustomNodeGroup.DebugProtectionCustomNodeGroup,
CustomNodeGroup.DomainLockCustomNodeGroup,
CustomNodeGroup.SelfDefendingCustomNodeGroup,
CustomNodeGroup.StringArrayCustomNodeGroup
];
/**
@@ -54,7 +54,7 @@ export class CustomNodeGroupStorage extends MapStorage <ICustomNodeGroup> {
this.storage = new Map <string, ICustomNodeGroup> ();
this.storageId = RandomGeneratorUtils.getRandomString(6);
CustomNodeGroupStorage.customNodeGroupsList.forEach((customNodeGroupName: CustomNodeGroups) => {
CustomNodeGroupStorage.customNodeGroupsList.forEach((customNodeGroupName: CustomNodeGroup) => {
const customNodeGroup: ICustomNodeGroup = this.customNodeGroupFactory(
customNodeGroupName
);
+2 -2
View File
@@ -1,5 +1,5 @@
import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
import { CustomNode } from '../../../enums/container/custom-nodes/CustomNode';
export type TCustomNodeFactory = (customNodeName: CustomNodes) => ICustomNode;
export type TCustomNodeFactory = (customNodeName: CustomNode) => ICustomNode;
@@ -1,5 +1,5 @@
import { ICustomNodeGroup } from '../../../interfaces/custom-nodes/ICustomNodeGroup';
import { CustomNodeGroups } from '../../../enums/container/custom-nodes/CustomNodeGroups';
import { CustomNodeGroup } from '../../../enums/container/custom-nodes/CustomNodeGroup';
export type TCustomNodeGroupFactory = (customNodeGroupName: CustomNodeGroups) => ICustomNodeGroup;
export type TCustomNodeGroupFactory = (customNodeGroupName: CustomNodeGroup) => ICustomNodeGroup;
@@ -1,5 +1,5 @@
import { IControlFlowReplacer } from '../../../interfaces/node-transformers/control-flow-transformers/IControlFlowReplacer';
import { ControlFlowReplacers } from '../../../enums/container/node-transformers/ControlFlowReplacers';
import { ControlFlowReplacer } from '../../../enums/container/node-transformers/ControlFlowReplacer';
export type TControlFlowReplacerFactory = (replacer: ControlFlowReplacers) => IControlFlowReplacer;
export type TControlFlowReplacerFactory = (replacer: ControlFlowReplacer) => IControlFlowReplacer;
@@ -1,5 +1,5 @@
import { IIdentifierObfuscatingReplacer } from '../../../interfaces/node-transformers/obfuscating-transformers/IIdentifierObfuscatingReplacer';
import { IdentifierObfuscatingReplacers } from '../../../enums/container/node-transformers/IdentifierObfuscatingReplacers';
import { IdentifierObfuscatingReplacer } from '../../../enums/container/node-transformers/IdentifierObfuscatingReplacer';
export type TIdentifierObfuscatingReplacerFactory = (replacer: IdentifierObfuscatingReplacers) => IIdentifierObfuscatingReplacer;
export type TIdentifierObfuscatingReplacerFactory = (replacer: IdentifierObfuscatingReplacer) => IIdentifierObfuscatingReplacer;
@@ -1,5 +1,5 @@
import { IObfuscatingReplacer } from '../../../interfaces/node-transformers/obfuscating-transformers/IObfuscatingReplacer';
import { LiteralObfuscatingReplacers } from '../../../enums/container/node-transformers/LiteralObfuscatingReplacers';
import { LiteralObfuscatingReplacer } from '../../../enums/container/node-transformers/LiteralObfuscatingReplacer';
export type TLiteralObfuscatingReplacerFactory = (replacer: LiteralObfuscatingReplacers) => IObfuscatingReplacer;
export type TLiteralObfuscatingReplacerFactory = (replacer: LiteralObfuscatingReplacer) => IObfuscatingReplacer;
@@ -1,5 +1,5 @@
import { INodeTransformer } from '../../../interfaces/node-transformers/INodeTransformer';
import { NodeTransformers } from '../../../enums/container/node-transformers/NodeTransformers';
import { NodeTransformer } from '../../../enums/container/node-transformers/NodeTransformer';
export type TNodeTransformerFactory = (nodeTransformerName: NodeTransformers) => INodeTransformer;
export type TNodeTransformerFactory = (nodeTransformerName: NodeTransformer) => INodeTransformer;
@@ -1,5 +1,5 @@
import { ICalleeDataExtractor } from '../../../interfaces/stack-trace-analyzer/ICalleeDataExtractor';
import { CalleeDataExtractors } from '../../../enums/container/stack-trace-analyzer/CalleeDataExtractors';
import { CalleeDataExtractor } from '../../../enums/container/stack-trace-analyzer/CalleeDataExtractor';
export type TCalleeDataExtractorFactory = (calleeDataExtractorName: CalleeDataExtractors) => ICalleeDataExtractor;
export type TCalleeDataExtractorFactory = (calleeDataExtractorName: CalleeDataExtractor) => ICalleeDataExtractor;