|
@@ -6,23 +6,17 @@ import * as escodegen from 'escodegen-wallaby';
|
|
|
import * as ESTree from 'estree';
|
|
|
import * as packageJson from 'pjson';
|
|
|
|
|
|
-import { ICustomNodeGroup } from './interfaces/custom-nodes/ICustomNodeGroup';
|
|
|
import { IGeneratorOutput } from './interfaces/IGeneratorOutput';
|
|
|
import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator';
|
|
|
import { ILogger } from './interfaces/logger/ILogger';
|
|
|
-import { IObfuscationEventEmitter } from './interfaces/event-emitters/IObfuscationEventEmitter';
|
|
|
import { IObfuscationResult } from './interfaces/IObfuscationResult';
|
|
|
import { IOptions } from './interfaces/options/IOptions';
|
|
|
import { IRandomGenerator } from './interfaces/utils/IRandomGenerator';
|
|
|
import { ISourceMapCorrector } from './interfaces/source-map/ISourceMapCorrector';
|
|
|
-import { IStackTraceAnalyzer } from './interfaces/analyzers/stack-trace-analyzer/IStackTraceAnalyzer';
|
|
|
-import { IStackTraceData } from './interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
|
|
|
-import { IStorage } from './interfaces/storages/IStorage';
|
|
|
import { ITransformersRunner } from './interfaces/node-transformers/ITransformersRunner';
|
|
|
|
|
|
import { LoggingMessage } from './enums/logger/LoggingMessage';
|
|
|
import { NodeTransformer } from './enums/node-transformers/NodeTransformer';
|
|
|
-import { ObfuscationEvent } from './enums/event-emitters/ObfuscationEvent';
|
|
|
import { TransformationStage } from './enums/node-transformers/TransformationStage';
|
|
|
|
|
|
import { NodeGuards } from './node/NodeGuards';
|
|
@@ -45,6 +39,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
|
|
NodeTransformer.BlockStatementControlFlowTransformer,
|
|
|
NodeTransformer.ClassDeclarationTransformer,
|
|
|
NodeTransformer.CommentsTransformer,
|
|
|
+ NodeTransformer.CustomNodesTransformer,
|
|
|
NodeTransformer.DeadCodeInjectionTransformer,
|
|
|
NodeTransformer.EvalCallExpressionTransformer,
|
|
|
NodeTransformer.FunctionControlFlowTransformer,
|
|
@@ -63,21 +58,11 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
|
|
NodeTransformer.VariableDeclarationTransformer
|
|
|
];
|
|
|
|
|
|
- /**
|
|
|
- * @type {IStorage<ICustomNodeGroup>}
|
|
|
- */
|
|
|
- private readonly customNodeGroupStorage: IStorage<ICustomNodeGroup>;
|
|
|
-
|
|
|
/**
|
|
|
* @type {ILogger}
|
|
|
*/
|
|
|
private readonly logger: ILogger;
|
|
|
|
|
|
- /**
|
|
|
- * @type {IObfuscationEventEmitter}
|
|
|
- */
|
|
|
- private readonly obfuscationEventEmitter: IObfuscationEventEmitter;
|
|
|
-
|
|
|
/**
|
|
|
* @type {IOptions}
|
|
|
*/
|
|
@@ -93,20 +78,12 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
|
|
*/
|
|
|
private readonly sourceMapCorrector: ISourceMapCorrector;
|
|
|
|
|
|
- /**
|
|
|
- * @type {IStackTraceAnalyzer}
|
|
|
- */
|
|
|
- private readonly stackTraceAnalyzer: IStackTraceAnalyzer;
|
|
|
-
|
|
|
/**
|
|
|
* @type {ITransformersRunner}
|
|
|
*/
|
|
|
private readonly transformersRunner: ITransformersRunner;
|
|
|
|
|
|
/**
|
|
|
- * @param {IStackTraceAnalyzer} stackTraceAnalyzer
|
|
|
- * @param {IObfuscationEventEmitter} obfuscationEventEmitter
|
|
|
- * @param {IStorage<ICustomNodeGroup>} customNodeGroupStorage
|
|
|
* @param {ITransformersRunner} transformersRunner
|
|
|
* @param {ISourceMapCorrector} sourceMapCorrector
|
|
|
* @param {IRandomGenerator} randomGenerator
|
|
@@ -114,18 +91,12 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
|
|
* @param {IOptions} options
|
|
|
*/
|
|
|
constructor (
|
|
|
- @inject(ServiceIdentifiers.IStackTraceAnalyzer) stackTraceAnalyzer: IStackTraceAnalyzer,
|
|
|
- @inject(ServiceIdentifiers.IObfuscationEventEmitter) obfuscationEventEmitter: IObfuscationEventEmitter,
|
|
|
- @inject(ServiceIdentifiers.TCustomNodeGroupStorage) customNodeGroupStorage: IStorage<ICustomNodeGroup>,
|
|
|
@inject(ServiceIdentifiers.ITransformersRunner) transformersRunner: ITransformersRunner,
|
|
|
@inject(ServiceIdentifiers.ISourceMapCorrector) sourceMapCorrector: ISourceMapCorrector,
|
|
|
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
|
|
|
@inject(ServiceIdentifiers.ILogger) logger: ILogger,
|
|
|
@inject(ServiceIdentifiers.IOptions) options: IOptions
|
|
|
) {
|
|
|
- this.stackTraceAnalyzer = stackTraceAnalyzer;
|
|
|
- this.obfuscationEventEmitter = obfuscationEventEmitter;
|
|
|
- this.customNodeGroupStorage = customNodeGroupStorage;
|
|
|
this.transformersRunner = transformersRunner;
|
|
|
this.sourceMapCorrector = sourceMapCorrector;
|
|
|
this.randomGenerator = randomGenerator;
|
|
@@ -186,22 +157,6 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
|
|
|
|
|
astTree = this.runTransformationStage(astTree, TransformationStage.Preparing);
|
|
|
|
|
|
- this.logger.info(LoggingMessage.AnalyzingASTTreeStage);
|
|
|
- const stackTraceData: IStackTraceData[] = this.stackTraceAnalyzer.analyze(astTree);
|
|
|
-
|
|
|
- this.customNodeGroupStorage
|
|
|
- .getStorage()
|
|
|
- .forEach((customNodeGroup: ICustomNodeGroup) => {
|
|
|
- customNodeGroup.initialize();
|
|
|
-
|
|
|
- this.obfuscationEventEmitter.once(
|
|
|
- customNodeGroup.getAppendEvent(),
|
|
|
- customNodeGroup.appendCustomNodes.bind(customNodeGroup)
|
|
|
- );
|
|
|
- });
|
|
|
-
|
|
|
- this.obfuscationEventEmitter.emit(ObfuscationEvent.BeforeObfuscation, astTree, stackTraceData);
|
|
|
-
|
|
|
if (this.options.deadCodeInjection) {
|
|
|
astTree = this.runTransformationStage(astTree, TransformationStage.DeadCodeInjection);
|
|
|
}
|
|
@@ -214,8 +169,6 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
|
|
astTree = this.runTransformationStage(astTree, TransformationStage.Obfuscating);
|
|
|
astTree = this.runTransformationStage(astTree, TransformationStage.Finalizing);
|
|
|
|
|
|
- this.obfuscationEventEmitter.emit(ObfuscationEvent.AfterObfuscation, astTree, stackTraceData);
|
|
|
-
|
|
|
return astTree;
|
|
|
}
|
|
|
|