Browse Source

Merge branch 'dev'

sanex3339 8 years ago
parent
commit
f9a6016db2

+ 11 - 0
CHANGELOG.md

@@ -1,5 +1,16 @@
 Change Log
 ===
+v0.9.0
+---
+* **Breaking change:** dropped `[email protected]` and `[email protected]` support.
+* **New option:** `controlFlowFlattening` allows to enable/disable **Control Flow flattening**. Control flow flattening is a structure transformation of the source code that hinders program comprehension.
+* **New option:** `controlFlowFlatteningThreshold` allows to set percentage of nodes that will affected by `controlFlowFlattening`.
+* Significantly increased obfuscation performance.
+* Huge internal refactoring.
+* Better `es2015` support: correct obfuscation of `TemplateLiteral`, `ArrayPattern`, `AssignmentPattern` nodes.
+* Switched from `npm` to `yarn` internally.
+* Various bug fixes.
+
 v0.9.0-beta.5
 ---
 * Increased performance

+ 66 - 51
README.md

@@ -71,39 +71,59 @@ var obfuscationResult = JavaScriptObfuscator.obfuscate(
 
 console.log(obfuscationResult.getObfuscatedCode());
 /*
-var _0x20c3 = [
+var _0x6b22 = [
+    '\x67\x63\x73',
+    '\x32\x7c\x34\x7c\x30\x7c\x35\x7c\x31\x7c\x33',
+    '\x73\x70\x6c\x69\x74',
     '\x6c\x6f\x67',
-    '\x78\x4c\x77',
-    '\x51\x72\x6b'
+    '\x68\x49\x4d'
 ];
-(function (_0x3cd8ee, _0x363b84) {
-    var _0x52ec75 = function (_0xda70d7) {
-        while (--_0xda70d7) {
-            _0x3cd8ee['\x70\x75\x73\x68'](_0x3cd8ee['\x73\x68\x69\x66\x74']());
+(function (_0xe12ddf, _0x9bc9d1) {
+    var _0x3a950b = function (_0x78e498) {
+        while (--_0x78e498) {
+            _0xe12ddf['\x70\x75\x73\x68'](_0xe12ddf['\x73\x68\x69\x66\x74']());
         }
     };
-    _0x52ec75(++_0x363b84);
-}(_0x20c3, 0x11e));
-var _0xc320 = function (_0x578269, _0x5685a1) {
-    var _0x578269 = parseInt(_0x578269, 0x10);
-    var _0xef46f2 = _0x20c3[_0x578269];
-    return _0xef46f2;
+    _0x3a950b(++_0x9bc9d1);
+}(_0x6b22, 0x1cd));
+var _0x26b2 = function (_0x348b1e, _0x346c2a) {
+    _0x348b1e = _0x348b1e - 0x0;
+    var _0x45ae32 = _0x6b22[_0x348b1e];
+    return _0x45ae32;
 };
 (function () {
-    var _0x2559cb = {
-        '\x78\x4c\x77': function _0x1(_0x1936fd, _0x5ed38f) {
-            return _0x1936fd + _0x5ed38f;
+    var _0x3a3615 = {
+        '\x68\x49\x4d': function _0x4c002e(_0x5a880a, _0xe710e3) {
+            return _0x5a880a - _0xe710e3;
         },
-        '\x51\x72\x6b': function _0x3(_0x4414d6, _0x1db310) {
-            return _0x4414d6 + _0x1db310;
+        '\x67\x63\x73': function _0x4cbf4b(_0xe1f02d, _0x5d1157) {
+            return _0xe1f02d + _0x5d1157;
         }
     };
-    var _0x32d9b = '\x35' - 0x3;
-    var _0x2b7aac = _0x2559cb[_0xc320('0x0')]('\x35', 0x3);
-    var _0x3c7304 = _0x2559cb['\x51\x72\x6b']('\x35', -'\x32');
-    console['\x6c\x6f\x67'](_0x32d9b);
-    console[_0xc320('0x2')](_0x2b7aac);
-    console[_0xc320('0x2')](_0x3c7304);
+    var _0x26dbf0 = _0x26b2('0x0')[_0x26b2('0x1')]('\x7c'), _0x345ed7 = 0x0;
+    while (!![]) {
+        switch (_0x26dbf0[_0x345ed7++]) {
+        case '\x30':
+            var _0x5eb388 = '\x35' + -'\x32';
+            continue;
+        case '\x31':
+            console[_0x26b2('0x2')](_0x52a502);
+            continue;
+        case '\x32':
+            var _0xd18cf9 = _0x3a3615[_0x26b2('0x3')]('\x35', 0x3);
+            continue;
+        case '\x33':
+            console[_0x26b2('0x2')](_0x5eb388);
+            continue;
+        case '\x34':
+            var _0x52a502 = _0x3a3615[_0x26b2('0x4')]('\x35', 0x3);
+            continue;
+        case '\x35':
+            console[_0x26b2('0x2')](_0xd18cf9);
+            continue;
+        }
+        break;
+    }
 }());
 */
 ```
@@ -231,41 +251,36 @@ Example:
 
 // output
 (function () {
-    var _0x4cd5dd = {
-        '\x42\x4e\x62': function _0x14cffe(_0x38a20c, _0x42b1f2) {
-            return _0x38a20c + _0x42b1f2;
-        }
-    };
-    function _0xd58698() {
-        var _0x36cac7 = {
-            '\x6a\x52\x79': function _0x2d3ac9(_0x2e037c, _0x457f42) {
-                return _0x4cd5dd['BNb'](_0x2e037c, _0x457f42);
-            }
-        };
+    function _0x425898() {
         return function () {
-            var _0x42a17d = '5\x7c3\x7c2\x7c6\x7c4\x7c1\x7c0'['split']('\x7c'), _0x1fcdcf = 0x0;
+            var _0x2b972d = {
+                '\x42\x6c\x67': function _0x160d18(_0xdc9f31, _0x3741dd) {
+                    return _0xdc9f31 + _0x3741dd;
+                }
+            };
+            var _0x170490 = '\x35\x7c\x34\x7c\x33\x7c\x32\x7c\x30\x7c\x36\x7c\x31'['\x73\x70\x6c\x69\x74']('\x7c'), _0x4f3437 = 0x0;
             while (!![]) {
-                switch (_0x42a17d[_0x1fcdcf++]) {
-                case '0':
-                    console['log'](0x6);
+                switch (_0x170490[_0x4f3437++]) {
+                case '\x30':
+                    console['\x6c\x6f\x67'](0x4);
                     continue;
-                case '1':
-                    console['log'](0x5);
+                case '\x31':
+                    console['\x6c\x6f\x67'](0x6);
                     continue;
-                case '2':
-                    console['log'](0x2);
+                case '\x32':
+                    console['\x6c\x6f\x67'](0x3);
                     continue;
-                case '3':
-                    console['log'](0x1);
+                case '\x33':
+                    console['\x6c\x6f\x67'](0x2);
                     continue;
-                case '4':
-                    console['log'](0x4);
+                case '\x34':
+                    console['\x6c\x6f\x67'](0x1);
                     continue;
-                case '5':
-                    var _0x15a932 = _0x36cac7['jRy'](0x1, 0x2);
+                case '\x35':
+                    var _0x476f51 = _0x2b972d['\x42\x6c\x67'](0x1, 0x2);
                     continue;
-                case '6':
-                    console['log'](0x3);
+                case '\x36':
+                    console['\x6c\x6f\x67'](0x5);
                     continue;
                 }
                 break;

File diff suppressed because it is too large
+ 196 - 206
dist/index.js


+ 5 - 5
package.json

@@ -1,6 +1,6 @@
 {
   "name": "javascript-obfuscator",
-  "version": "0.9.0-beta.5",
+  "version": "0.9.0",
   "description": "JavaScript obfuscator",
   "keywords": [
     "obfuscator",
@@ -29,7 +29,7 @@
     "lodash": "4.17.4",
     "mkdirp": "0.5.1",
     "reflect-metadata": "0.1.9",
-    "source-map-support": "0.4.10",
+    "source-map-support": "0.4.11",
     "string-template": "1.0.0",
     "tslib": "1.5.0"
   },
@@ -41,10 +41,10 @@
     "@types/esprima": "2.1.33",
     "@types/estraverse": "0.0.6",
     "@types/estree": "0.0.34",
-    "@types/lodash": "4.14.50",
+    "@types/lodash": "4.14.51",
     "@types/mkdirp": "0.3.29",
     "@types/mocha": "2.2.38",
-    "@types/node": "7.0.3",
+    "@types/node": "7.0.4",
     "@types/sinon": "1.16.34",
     "@types/string-template": "1.0.2",
     "awesome-typescript-loader": "3.0.0-beta.18",
@@ -58,7 +58,7 @@
     "mocha": "3.2.0",
     "sinon": "2.0.0-pre.4",
     "ts-node": "2.0.0",
-    "tslint": "4.3.1",
+    "tslint": "4.4.2",
     "tslint-loader": "3.3.0",
     "typescript": "2.1.5",
     "webpack": "2.2.0",

+ 7 - 7
src/Obfuscator.ts

@@ -4,7 +4,7 @@ import { ServiceIdentifiers } from './container/ServiceIdentifiers';
 import * as estraverse from 'estraverse';
 import * as ESTree from 'estree';
 
-import { TNodeTransformersFactory } from './types/container/TNodeTransformersFactory';
+import { TNodeTransformerFactory } from './types/container/TNodeTransformerFactory';
 import { TVisitorDirection } from './types/TVisitorDirection';
 import { TVisitorFunction } from './types/TVisitorFunction';
 
@@ -62,9 +62,9 @@ export class Obfuscator implements IObfuscator {
     private readonly customNodeGroupStorage: IStorage<ICustomNodeGroup>;
 
     /**
-     * @type {TNodeTransformersFactory}
+     * @type {TNodeTransformerFactory}
      */
-    private readonly nodeTransformersFactory: TNodeTransformersFactory;
+    private readonly nodeTransformerFactory: TNodeTransformerFactory;
 
     /**
      * @type {IObfuscationEventEmitter}
@@ -85,20 +85,20 @@ export class Obfuscator implements IObfuscator {
      * @param stackTraceAnalyzer
      * @param obfuscationEventEmitter
      * @param customNodeGroupStorage
-     * @param nodeTransformersFactory
+     * @param nodeTransformerFactory
      * @param options
      */
     constructor (
         @inject(ServiceIdentifiers.IStackTraceAnalyzer) stackTraceAnalyzer: IStackTraceAnalyzer,
         @inject(ServiceIdentifiers.IObfuscationEventEmitter) obfuscationEventEmitter: IObfuscationEventEmitter,
         @inject(ServiceIdentifiers.TCustomNodeGroupStorage) customNodeGroupStorage: IStorage<ICustomNodeGroup>,
-        @inject(ServiceIdentifiers.Factory__INodeTransformer) nodeTransformersFactory: TNodeTransformersFactory,
+        @inject(ServiceIdentifiers.Factory__INodeTransformer) nodeTransformerFactory: TNodeTransformerFactory,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         this.stackTraceAnalyzer = stackTraceAnalyzer;
         this.obfuscationEventEmitter = obfuscationEventEmitter;
         this.customNodeGroupStorage = customNodeGroupStorage;
-        this.nodeTransformersFactory = nodeTransformersFactory;
+        this.nodeTransformerFactory = nodeTransformerFactory;
         this.options = options;
     }
 
@@ -160,7 +160,7 @@ export class Obfuscator implements IObfuscator {
         let visitor: IVisitor;
 
         for (let i: number = 0; i < nodeTransformersLength; i++) {
-            visitor = this.nodeTransformersFactory(nodeTransformers[i]).getVisitor();
+            visitor = this.nodeTransformerFactory(nodeTransformers[i]).getVisitor();
 
             if (visitor.enter) {
                 enterVisitors.push(visitor);

+ 2 - 2
src/container/ServiceIdentifiers.ts

@@ -5,7 +5,7 @@ export const ServiceIdentifiers: any = {
     Factory__ICustomNodeGroup: Symbol('Factory<ICustomNodeGroup>'),
     Factory__INodeTransformer: Symbol('Factory<INodeTransformer[]>'),
     Factory__IObfuscationResult: Symbol('Factory<IObfuscationResult>'),
-    Factory__IObfuscatorReplacer: Symbol('Factory<IObfuscationReplacer>'),
+    Factory__IObfuscationReplacer: Symbol('Factory<IObfuscationReplacer>'),
     Factory__TControlFlowStorage: Symbol('Factory<TControlFlowStorage>'),
     ICalleeDataExtractor: Symbol('ICalleeDataExtractor'),
     ICustomNodeGroup: Symbol('ICustomNodeGroup'),
@@ -16,7 +16,7 @@ export const ServiceIdentifiers: any = {
     IObfuscationResult: Symbol('IObfuscationResult'),
     IObfuscator: Symbol('IObfuscator'),
     IOptions: Symbol('IOptions'),
-    IObfuscatorReplacer: Symbol('IObfuscationReplacer'),
+    IObfuscationReplacer: Symbol('IObfuscationReplacer'),
     ISourceMapCorrector: Symbol('ISourceMapCorrector'),
     IStackTraceAnalyzer: Symbol('IStackTraceAnalyzer'),
     Newable__ICustomNode: Symbol('Newable<ICustomNode>'),

+ 6 - 6
src/container/modules/node-transformers/ControlFlowTransformersModule.ts

@@ -3,7 +3,7 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
 
 import { IControlFlowReplacer } from '../../../interfaces/node-transformers/IControlFlowReplacer';
 
-import { NodeControlFlowReplacers } from '../../../enums/container/NodeControlFlowReplacers';
+import { ControlFlowReplacers } from '../../../enums/container/ControlFlowReplacers';
 
 import { BinaryExpressionControlFlowReplacer } from '../../../node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer';
 import { CallExpressionControlFlowReplacer } from '../../../node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer';
@@ -12,21 +12,21 @@ import { LogicalExpressionControlFlowReplacer } from '../../../node-transformers
 export const controlFlowTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
     bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
         .to(BinaryExpressionControlFlowReplacer)
-        .whenTargetNamed(NodeControlFlowReplacers.BinaryExpressionControlFlowReplacer);
+        .whenTargetNamed(ControlFlowReplacers.BinaryExpressionControlFlowReplacer);
 
     bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
         .to(CallExpressionControlFlowReplacer)
-        .whenTargetNamed(NodeControlFlowReplacers.CallExpressionControlFlowReplacer);
+        .whenTargetNamed(ControlFlowReplacers.CallExpressionControlFlowReplacer);
 
     bind<IControlFlowReplacer>(ServiceIdentifiers.IControlFlowReplacer)
         .to(LogicalExpressionControlFlowReplacer)
-        .whenTargetNamed(NodeControlFlowReplacers.LogicalExpressionControlFlowReplacer);
+        .whenTargetNamed(ControlFlowReplacers.LogicalExpressionControlFlowReplacer);
 
     bind<IControlFlowReplacer>(ServiceIdentifiers.Factory__IControlFlowReplacer)
         .toFactory<IControlFlowReplacer>((context: interfaces.Context) => {
-            const cache: Map <NodeControlFlowReplacers, IControlFlowReplacer> = new Map();
+            const cache: Map <ControlFlowReplacers, IControlFlowReplacer> = new Map();
 
-            return (replacerName: NodeControlFlowReplacers) => {
+            return (replacerName: ControlFlowReplacers) => {
                 if (cache.has(replacerName)) {
                     return <IControlFlowReplacer>cache.get(replacerName);
                 }

+ 13 - 13
src/container/modules/node-transformers/ObfuscatingTransformersModule.ts

@@ -3,7 +3,7 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
 
 import { IObfuscationReplacer } from '../../../interfaces/node-transformers/IObfuscationReplacer';
 
-import { NodeObfuscatorsReplacers } from '../../../enums/container/NodeObfuscationReplacers';
+import { ObfuscationReplacers } from '../../../enums/container/ObfuscationReplacers';
 
 import { BooleanLiteralReplacer } from '../../../node-transformers/obfuscating-transformers/replacers/BooleanLiteralReplacer';
 import { IdentifierReplacer } from '../../../node-transformers/obfuscating-transformers/replacers/IdentifierReplacer';
@@ -11,33 +11,33 @@ import { NumberLiteralReplacer } from '../../../node-transformers/obfuscating-tr
 import { StringLiteralReplacer } from '../../../node-transformers/obfuscating-transformers/replacers/StringLiteralReplacer';
 
 export const obfuscatingTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
-    bind<IObfuscationReplacer>(ServiceIdentifiers.IObfuscatorReplacer)
+    bind<IObfuscationReplacer>(ServiceIdentifiers.IObfuscationReplacer)
         .to(BooleanLiteralReplacer)
-        .whenTargetNamed(NodeObfuscatorsReplacers.BooleanReplacer);
+        .whenTargetNamed(ObfuscationReplacers.BooleanReplacer);
 
-    bind<IObfuscationReplacer>(ServiceIdentifiers.IObfuscatorReplacer)
+    bind<IObfuscationReplacer>(ServiceIdentifiers.IObfuscationReplacer)
         .to(IdentifierReplacer)
-        .whenTargetNamed(NodeObfuscatorsReplacers.IdentifierReplacer);
+        .whenTargetNamed(ObfuscationReplacers.IdentifierReplacer);
 
-    bind<IObfuscationReplacer>(ServiceIdentifiers.IObfuscatorReplacer)
+    bind<IObfuscationReplacer>(ServiceIdentifiers.IObfuscationReplacer)
         .to(NumberLiteralReplacer)
-        .whenTargetNamed(NodeObfuscatorsReplacers.NumberLiteralReplacer);
+        .whenTargetNamed(ObfuscationReplacers.NumberLiteralReplacer);
 
-    bind<IObfuscationReplacer>(ServiceIdentifiers.IObfuscatorReplacer)
+    bind<IObfuscationReplacer>(ServiceIdentifiers.IObfuscationReplacer)
         .to(StringLiteralReplacer)
-        .whenTargetNamed(NodeObfuscatorsReplacers.StringLiteralReplacer);
+        .whenTargetNamed(ObfuscationReplacers.StringLiteralReplacer);
 
-    bind<IObfuscationReplacer>(ServiceIdentifiers.Factory__IObfuscatorReplacer)
+    bind<IObfuscationReplacer>(ServiceIdentifiers.Factory__IObfuscationReplacer)
         .toFactory<IObfuscationReplacer>((context: interfaces.Context) => {
-            const cache: Map <NodeObfuscatorsReplacers, IObfuscationReplacer> = new Map();
+            const cache: Map <ObfuscationReplacers, IObfuscationReplacer> = new Map();
 
-            return (replacerName: NodeObfuscatorsReplacers) => {
+            return (replacerName: ObfuscationReplacers) => {
                 if (cache.has(replacerName)) {
                     return <IObfuscationReplacer>cache.get(replacerName);
                 }
 
                 const obfuscationReplacer: IObfuscationReplacer = context.container.getNamed<IObfuscationReplacer>(
-                    ServiceIdentifiers.IObfuscatorReplacer,
+                    ServiceIdentifiers.IObfuscationReplacer,
                     replacerName
                 );
 

+ 1 - 1
src/enums/container/NodeControlFlowReplacers.ts → src/enums/container/ControlFlowReplacers.ts

@@ -1,4 +1,4 @@
-export enum NodeControlFlowReplacers {
+export enum ControlFlowReplacers {
     BinaryExpressionControlFlowReplacer,
     CallExpressionControlFlowReplacer,
     LogicalExpressionControlFlowReplacer

+ 1 - 1
src/enums/container/NodeObfuscationReplacers.ts → src/enums/container/ObfuscationReplacers.ts

@@ -1,4 +1,4 @@
-export enum NodeObfuscatorsReplacers {
+export enum ObfuscationReplacers {
     BooleanReplacer,
     IdentifierReplacer,
     NumberLiteralReplacer,

+ 7 - 7
src/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.ts

@@ -20,19 +20,19 @@ import { NodeType } from '../../enums/NodeType';
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
 import { Node } from '../../node/Node';
 import { NodeAppender } from '../../node/NodeAppender';
-import { NodeControlFlowReplacers } from '../../enums/container/NodeControlFlowReplacers';
+import { ControlFlowReplacers } from '../../enums/container/ControlFlowReplacers';
 import { NodeUtils } from '../../node/NodeUtils';
 import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils';
 
 @injectable()
 export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
     /**
-     * @type {Map <string, NodeControlFlowReplacers>}
+     * @type {Map <string, ControlFlowReplacers>}
      */
-    private static readonly controlFlowReplacersMap: Map <string, NodeControlFlowReplacers> = new Map([
-        [NodeType.BinaryExpression, NodeControlFlowReplacers.BinaryExpressionControlFlowReplacer],
-        [NodeType.CallExpression, NodeControlFlowReplacers.CallExpressionControlFlowReplacer],
-        [NodeType.LogicalExpression, NodeControlFlowReplacers.LogicalExpressionControlFlowReplacer]
+    private static readonly controlFlowReplacersMap: Map <string, ControlFlowReplacers> = new Map([
+        [NodeType.BinaryExpression, ControlFlowReplacers.BinaryExpressionControlFlowReplacer],
+        [NodeType.CallExpression, ControlFlowReplacers.CallExpressionControlFlowReplacer],
+        [NodeType.LogicalExpression, ControlFlowReplacers.LogicalExpressionControlFlowReplacer]
     ]);
 
     /**
@@ -217,7 +217,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
                     return node;
                 }
 
-                const controlFlowReplacerName: NodeControlFlowReplacers = <NodeControlFlowReplacers>FunctionControlFlowTransformer
+                const controlFlowReplacerName: ControlFlowReplacers = <ControlFlowReplacers>FunctionControlFlowTransformer
                     .controlFlowReplacersMap.get(node.type);
 
                 return {

+ 6 - 5
src/node-transformers/obfuscating-transformers/CatchClauseTransformer.ts

@@ -4,12 +4,13 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import * as estraverse from 'estraverse';
 import * as ESTree from 'estree';
 
+import { TObfuscationReplacerFactory } from '../../types/container/TObfuscationReplacerFactory';
+
 import { IOptions } from '../../interfaces/options/IOptions';
-import { IObfuscationReplacer } from '../../interfaces/node-transformers/IObfuscationReplacer';
 import { IObfuscationReplacerWithStorage } from '../../interfaces/node-transformers/IObfuscationReplacerWithStorage';
 import { IVisitor } from '../../interfaces/IVisitor';
 
-import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscationReplacers';
+import { ObfuscationReplacers } from '../../enums/container/ObfuscationReplacers';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
 import { Node } from '../../node/Node';
@@ -30,16 +31,16 @@ export class CatchClauseTransformer extends AbstractNodeTransformer {
     private readonly identifierReplacer: IObfuscationReplacerWithStorage;
 
     /**
-     * @param replacersFactory
+     * @param obfuscationReplacerFactory
      * @param options
      */
     constructor (
-        @inject(ServiceIdentifiers.Factory__IObfuscatorReplacer) replacersFactory: (replacer: NodeObfuscatorsReplacers) => IObfuscationReplacer,
+        @inject(ServiceIdentifiers.Factory__IObfuscationReplacer) obfuscationReplacerFactory: TObfuscationReplacerFactory,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         super(options);
 
-        this.identifierReplacer = <IObfuscationReplacerWithStorage>replacersFactory(NodeObfuscatorsReplacers.IdentifierReplacer);
+        this.identifierReplacer = <IObfuscationReplacerWithStorage>obfuscationReplacerFactory(ObfuscationReplacers.IdentifierReplacer);
     }
 
     /**

+ 26 - 21
src/node-transformers/obfuscating-transformers/FunctionDeclarationTransformer.ts

@@ -5,13 +5,13 @@ import * as estraverse from 'estraverse';
 import * as ESTree from 'estree';
 
 import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement';
+import { TObfuscationReplacerFactory } from '../../types/container/TObfuscationReplacerFactory';
 
 import { IOptions } from '../../interfaces/options/IOptions';
-import { IObfuscationReplacer } from '../../interfaces/node-transformers/IObfuscationReplacer';
 import { IObfuscationReplacerWithStorage } from '../../interfaces/node-transformers/IObfuscationReplacerWithStorage';
 import { IVisitor } from '../../interfaces/IVisitor';
 
-import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscationReplacers';
+import { ObfuscationReplacers } from '../../enums/container/ObfuscationReplacers';
 import { NodeType } from '../../enums/NodeType';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
@@ -40,16 +40,16 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
     private readonly replaceableIdentifiers: Map <ESTree.Node, ESTree.Identifier[]> = new Map();
 
     /**
-     * @param nodeObfuscatorsReplacersFactory
+     * @param obfuscationReplacerFactory
      * @param options
      */
     constructor (
-        @inject(ServiceIdentifiers.Factory__IObfuscatorReplacer) nodeObfuscatorsReplacersFactory: (replacer: NodeObfuscatorsReplacers) => IObfuscationReplacer,
+        @inject(ServiceIdentifiers.Factory__IObfuscationReplacer) obfuscationReplacerFactory: TObfuscationReplacerFactory,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         super(options);
 
-        this.identifierReplacer = <IObfuscationReplacerWithStorage>nodeObfuscatorsReplacersFactory(NodeObfuscatorsReplacers.IdentifierReplacer);
+        this.identifierReplacer = <IObfuscationReplacerWithStorage>obfuscationReplacerFactory(ObfuscationReplacers.IdentifierReplacer);
     }
 
     /**
@@ -80,7 +80,13 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
         }
 
         this.storeFunctionName(functionDeclarationNode, nodeIdentifier);
-        this.replaceFunctionName(blockScopeOfFunctionDeclarationNode, nodeIdentifier);
+
+        // check for cached identifiers for current scope node. If exist - loop through them.
+        if (this.replaceableIdentifiers.has(blockScopeOfFunctionDeclarationNode)) {
+            this.replaceScopeCachedIdentifiers(blockScopeOfFunctionDeclarationNode, nodeIdentifier);
+        } else {
+            this.replaceScopeIdentifiers(blockScopeOfFunctionDeclarationNode, nodeIdentifier);
+        }
 
         return functionDeclarationNode;
     }
@@ -97,21 +103,20 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
      * @param scopeNode
      * @param nodeIdentifier
      */
-    private replaceFunctionName (scopeNode: ESTree.Node, nodeIdentifier: number): void {
-        let replaceableIdentifiersForCurrentScope: ESTree.Identifier[];
+    private replaceScopeCachedIdentifiers (scopeNode: ESTree.Node, nodeIdentifier: number): void {
+        const cachedReplaceableIdentifiers: ESTree.Identifier[] = <ESTree.Identifier[]>this.replaceableIdentifiers.get(scopeNode);
 
-        // check for cached identifiers for current scope node. If exist - loop through them.
-        if (this.replaceableIdentifiers.has(scopeNode)) {
-            replaceableIdentifiersForCurrentScope = <ESTree.Identifier[]>this.replaceableIdentifiers.get(scopeNode);
-
-            replaceableIdentifiersForCurrentScope.forEach((replaceableIdentifier: ESTree.Identifier) => {
-                replaceableIdentifier.name = this.identifierReplacer.replace(replaceableIdentifier.name, nodeIdentifier);
-            });
-
-            return;
-        }
+        cachedReplaceableIdentifiers.forEach((replaceableIdentifier: ESTree.Identifier) => {
+            replaceableIdentifier.name = this.identifierReplacer.replace(replaceableIdentifier.name, nodeIdentifier);
+        });
+    }
 
-        replaceableIdentifiersForCurrentScope = [];
+    /**
+     * @param scopeNode
+     * @param nodeIdentifier
+     */
+    private replaceScopeIdentifiers (scopeNode: ESTree.Node, nodeIdentifier: number): void {
+        const storedReplaceableIdentifiers: ESTree.Identifier[] = [];
 
         estraverse.replace(scopeNode, {
             enter: (node: ESTree.Node, parentNode: ESTree.Node): any => {
@@ -121,12 +126,12 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
                     if (node.name !== newNodeName) {
                         node.name = newNodeName;
                     } else {
-                        replaceableIdentifiersForCurrentScope.push(node);
+                        storedReplaceableIdentifiers.push(node);
                     }
                 }
             }
         });
 
-        this.replaceableIdentifiers.set(scopeNode, replaceableIdentifiersForCurrentScope);
+        this.replaceableIdentifiers.set(scopeNode, storedReplaceableIdentifiers);
     }
 }

+ 6 - 5
src/node-transformers/obfuscating-transformers/FunctionTransformer.ts

@@ -4,12 +4,13 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import * as estraverse from 'estraverse';
 import * as ESTree from 'estree';
 
+import { TObfuscationReplacerFactory } from '../../types/container/TObfuscationReplacerFactory';
+
 import { IOptions } from '../../interfaces/options/IOptions';
-import { IObfuscationReplacer } from '../../interfaces/node-transformers/IObfuscationReplacer';
 import { IObfuscationReplacerWithStorage } from '../../interfaces/node-transformers/IObfuscationReplacerWithStorage';
 import { IVisitor } from '../../interfaces/IVisitor';
 
-import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscationReplacers';
+import { ObfuscationReplacers } from '../../enums/container/ObfuscationReplacers';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
 import { Node } from '../../node/Node';
@@ -30,16 +31,16 @@ export class FunctionTransformer extends AbstractNodeTransformer {
     private readonly identifierReplacer: IObfuscationReplacerWithStorage;
 
     /**
-     * @param nodeObfuscatorsReplacersFactory
+     * @param obfuscationReplacerFactory
      * @param options
      */
     constructor (
-        @inject(ServiceIdentifiers.Factory__IObfuscatorReplacer) nodeObfuscatorsReplacersFactory: (replacer: NodeObfuscatorsReplacers) => IObfuscationReplacer,
+        @inject(ServiceIdentifiers.Factory__IObfuscationReplacer) obfuscationReplacerFactory: TObfuscationReplacerFactory,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         super(options);
 
-        this.identifierReplacer = <IObfuscationReplacerWithStorage>nodeObfuscatorsReplacersFactory(NodeObfuscatorsReplacers.IdentifierReplacer);
+        this.identifierReplacer = <IObfuscationReplacerWithStorage>obfuscationReplacerFactory(ObfuscationReplacers.IdentifierReplacer);
     }
 
     /**

+ 6 - 5
src/node-transformers/obfuscating-transformers/LabeledStatementTransformer.ts

@@ -4,12 +4,13 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import * as estraverse from 'estraverse';
 import * as ESTree from 'estree';
 
+import { TObfuscationReplacerFactory } from '../../types/container/TObfuscationReplacerFactory';
+
 import { IOptions } from '../../interfaces/options/IOptions';
-import { IObfuscationReplacer } from '../../interfaces/node-transformers/IObfuscationReplacer';
 import { IObfuscationReplacerWithStorage } from '../../interfaces/node-transformers/IObfuscationReplacerWithStorage';
 import { IVisitor } from '../../interfaces/IVisitor';
 
-import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscationReplacers';
+import { ObfuscationReplacers } from '../../enums/container/ObfuscationReplacers';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
 import { Node } from '../../node/Node';
@@ -38,16 +39,16 @@ export class LabeledStatementTransformer extends AbstractNodeTransformer {
     private readonly identifierReplacer: IObfuscationReplacerWithStorage;
 
     /**
-     * @param nodeObfuscatorsReplacersFactory
+     * @param obfuscationReplacerFactory
      * @param options
      */
     constructor (
-        @inject(ServiceIdentifiers.Factory__IObfuscatorReplacer) nodeObfuscatorsReplacersFactory: (replacer: NodeObfuscatorsReplacers) => IObfuscationReplacer,
+        @inject(ServiceIdentifiers.Factory__IObfuscationReplacer) obfuscationReplacerFactory: TObfuscationReplacerFactory,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         super(options);
 
-        this.identifierReplacer = <IObfuscationReplacerWithStorage>nodeObfuscatorsReplacersFactory(NodeObfuscatorsReplacers.IdentifierReplacer);
+        this.identifierReplacer = <IObfuscationReplacerWithStorage>obfuscationReplacerFactory(ObfuscationReplacers.IdentifierReplacer);
     }
 
     /**

+ 11 - 10
src/node-transformers/obfuscating-transformers/LiteralTransformer.ts

@@ -4,11 +4,12 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import * as escodegen from 'escodegen';
 import * as ESTree from 'estree';
 
+import { TObfuscationReplacerFactory } from '../../types/container/TObfuscationReplacerFactory';
+
 import { IOptions } from '../../interfaces/options/IOptions';
-import { IObfuscationReplacer } from '../../interfaces/node-transformers/IObfuscationReplacer';
 import { IVisitor } from '../../interfaces/IVisitor';
 
-import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscationReplacers';
+import { ObfuscationReplacers } from '../../enums/container/ObfuscationReplacers';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
 import { Node } from '../../node/Node';
@@ -16,21 +17,21 @@ import { Node } from '../../node/Node';
 @injectable()
 export class LiteralTransformer extends AbstractNodeTransformer {
     /**
-     * @type {(replacer: NodeObfuscatorsReplacers) => IObfuscationReplacer}
+     * @type {TObfuscationReplacerFactory}
      */
-    private readonly replacersFactory: (replacer: NodeObfuscatorsReplacers) => IObfuscationReplacer;
+    private readonly obfuscationReplacerFactory: TObfuscationReplacerFactory;
 
     /**
-     * @param replacersFactory
+     * @param obfuscationReplacerFactory
      * @param options
      */
     constructor (
-        @inject(ServiceIdentifiers.Factory__IObfuscatorReplacer) replacersFactory: (replacer: NodeObfuscatorsReplacers) => IObfuscationReplacer,
+        @inject(ServiceIdentifiers.Factory__IObfuscationReplacer) obfuscationReplacerFactory: TObfuscationReplacerFactory,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         super(options);
 
-        this.replacersFactory = replacersFactory;
+        this.obfuscationReplacerFactory = obfuscationReplacerFactory;
     }
 
     /**
@@ -60,19 +61,19 @@ export class LiteralTransformer extends AbstractNodeTransformer {
 
         switch (typeof literalNode.value) {
             case 'boolean':
-                content = this.replacersFactory(NodeObfuscatorsReplacers.BooleanReplacer)
+                content = this.obfuscationReplacerFactory(ObfuscationReplacers.BooleanReplacer)
                     .replace(<boolean>literalNode.value);
 
                 break;
 
             case 'number':
-                content = this.replacersFactory(NodeObfuscatorsReplacers.NumberLiteralReplacer)
+                content = this.obfuscationReplacerFactory(ObfuscationReplacers.NumberLiteralReplacer)
                     .replace(<number>literalNode.value);
 
                 break;
 
             case 'string':
-                content = this.replacersFactory(NodeObfuscatorsReplacers.StringLiteralReplacer)
+                content = this.obfuscationReplacerFactory(ObfuscationReplacers.StringLiteralReplacer)
                     .replace(<string>literalNode.value);
 
                 break;

+ 26 - 21
src/node-transformers/obfuscating-transformers/VariableDeclarationTransformer.ts

@@ -5,13 +5,13 @@ import * as estraverse from 'estraverse';
 import * as ESTree from 'estree';
 
 import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement';
+import { TObfuscationReplacerFactory } from '../../types/container/TObfuscationReplacerFactory';
 
 import { IOptions } from '../../interfaces/options/IOptions';
-import { IObfuscationReplacer } from '../../interfaces/node-transformers/IObfuscationReplacer';
 import { IObfuscationReplacerWithStorage } from '../../interfaces/node-transformers/IObfuscationReplacerWithStorage';
 import { IVisitor } from '../../interfaces/IVisitor';
 
-import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscationReplacers';
+import { ObfuscationReplacers } from '../../enums/container/ObfuscationReplacers';
 import { NodeType } from '../../enums/NodeType';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
@@ -41,16 +41,16 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
     private readonly replaceableIdentifiers: Map <ESTree.Node, ESTree.Identifier[]> = new Map();
 
     /**
-     * @param replacersFactory
+     * @param obfuscationReplacerFactory
      * @param options
      */
     constructor (
-        @inject(ServiceIdentifiers.Factory__IObfuscatorReplacer) replacersFactory: (replacer: NodeObfuscatorsReplacers) => IObfuscationReplacer,
+        @inject(ServiceIdentifiers.Factory__IObfuscationReplacer) obfuscationReplacerFactory: TObfuscationReplacerFactory,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         super(options);
 
-        this.identifierReplacer = <IObfuscationReplacerWithStorage>replacersFactory(NodeObfuscatorsReplacers.IdentifierReplacer);
+        this.identifierReplacer = <IObfuscationReplacerWithStorage>obfuscationReplacerFactory(ObfuscationReplacers.IdentifierReplacer);
     }
 
     /**
@@ -85,7 +85,13 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
             : parentNode;
 
         this.storeVariableNames(variableDeclarationNode, nodeIdentifier);
-        this.replaceVariableNames(scopeNode, nodeIdentifier);
+
+        // check for cached identifiers for current scope node. If exist - loop through them.
+        if (this.replaceableIdentifiers.has(scopeNode)) {
+            this.replaceScopeCachedIdentifiers(scopeNode, nodeIdentifier);
+        } else {
+            this.replaceScopeIdentifiers(scopeNode, nodeIdentifier);
+        }
 
         return variableDeclarationNode;
     }
@@ -111,21 +117,20 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
      * @param scopeNode
      * @param nodeIdentifier
      */
-    private replaceVariableNames (scopeNode: ESTree.Node, nodeIdentifier: number): void {
-        let replaceableIdentifiersForCurrentScope: ESTree.Identifier[];
-
-        // check for cached identifiers for current scope node. If exist - loop through them.
-        if (this.replaceableIdentifiers.has(scopeNode)) {
-            replaceableIdentifiersForCurrentScope = <ESTree.Identifier[]>this.replaceableIdentifiers.get(scopeNode);
-
-            replaceableIdentifiersForCurrentScope.forEach((replaceableIdentifier: ESTree.Identifier) => {
-                replaceableIdentifier.name = this.identifierReplacer.replace(replaceableIdentifier.name, nodeIdentifier);
-            });
+    private replaceScopeCachedIdentifiers (scopeNode: ESTree.Node, nodeIdentifier: number): void {
+        const cachedReplaceableIdentifiers: ESTree.Identifier[] = <ESTree.Identifier[]>this.replaceableIdentifiers.get(scopeNode);
 
-            return;
-        }
+        cachedReplaceableIdentifiers.forEach((replaceableIdentifier: ESTree.Identifier) => {
+            replaceableIdentifier.name = this.identifierReplacer.replace(replaceableIdentifier.name, nodeIdentifier);
+        });
+    }
 
-        replaceableIdentifiersForCurrentScope = [];
+    /**
+     * @param scopeNode
+     * @param nodeIdentifier
+     */
+    private replaceScopeIdentifiers (scopeNode: ESTree.Node, nodeIdentifier: number): void {
+        const storedReplaceableIdentifiers: ESTree.Identifier[] = [];
 
         estraverse.replace(scopeNode, {
             enter: (node: ESTree.Node, parentNode: ESTree.Node): any => {
@@ -135,12 +140,12 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
                     if (node.name !== newNodeName) {
                         node.name = newNodeName;
                     } else {
-                        replaceableIdentifiersForCurrentScope.push(node);
+                        storedReplaceableIdentifiers.push(node);
                     }
                 }
             }
         });
 
-        this.replaceableIdentifiers.set(scopeNode, replaceableIdentifiersForCurrentScope);
+        this.replaceableIdentifiers.set(scopeNode, storedReplaceableIdentifiers);
     }
 }

+ 5 - 5
src/stack-trace-analyzer/StackTraceAnalyzer.ts

@@ -4,7 +4,7 @@ import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 import * as estraverse from 'estraverse';
 import * as ESTree from 'estree';
 
-import { TCalleeDataExtractorsFactory } from '../types/container/TCalleeDataExtractorsFactory';
+import { TCalleeDataExtractorFactory } from '../types/container/TCalleeDataExtractorFactory';
 
 import { ICalleeData } from '../interfaces/stack-trace-analyzer/ICalleeData';
 import { ICalleeDataExtractor } from '../interfaces/stack-trace-analyzer/ICalleeDataExtractor';
@@ -71,12 +71,12 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
     /**
      * @type {(calleeDataExtractorName: CalleeDataExtractors) => ICalleeDataExtractor}
      */
-    private calleeDataExtractorsFactory: (calleeDataExtractorName: CalleeDataExtractors) => ICalleeDataExtractor;
+    private calleeDataExtractorFactory: (calleeDataExtractorName: CalleeDataExtractors) => ICalleeDataExtractor;
 
     constructor (
-        @inject(ServiceIdentifiers.Factory__ICalleeDataExtractor) calleeDataExtractorsFactory: TCalleeDataExtractorsFactory
+        @inject(ServiceIdentifiers.Factory__ICalleeDataExtractor) calleeDataExtractorFactory: TCalleeDataExtractorFactory
     ) {
-        this.calleeDataExtractorsFactory = calleeDataExtractorsFactory;
+        this.calleeDataExtractorFactory = calleeDataExtractorFactory;
     }
 
     /**
@@ -156,7 +156,7 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
         callExpressionNode: ESTree.CallExpression
     ): void {
         StackTraceAnalyzer.calleeDataExtractorsList.forEach((calleeDataExtractorName: CalleeDataExtractors) => {
-            const calleeData: ICalleeData | null = this.calleeDataExtractorsFactory(calleeDataExtractorName)
+            const calleeData: ICalleeData | null = this.calleeDataExtractorFactory(calleeDataExtractorName)
                 .extract(blockScopeBody, callExpressionNode.callee);
 
             if (!calleeData) {

+ 1 - 1
src/types/container/TCalleeDataExtractorsFactory.d.ts → src/types/container/TCalleeDataExtractorFactory.d.ts

@@ -2,4 +2,4 @@ import { ICalleeDataExtractor } from '../../interfaces/stack-trace-analyzer/ICal
 
 import { CalleeDataExtractors } from '../../enums/container/CalleeDataExtractors';
 
-export type TCalleeDataExtractorsFactory = (calleeDataExtractorName: CalleeDataExtractors) => ICalleeDataExtractor;
+export type TCalleeDataExtractorFactory = (calleeDataExtractorName: CalleeDataExtractors) => ICalleeDataExtractor;

+ 2 - 2
src/types/container/TControlFlowReplacerFactory.d.ts

@@ -1,5 +1,5 @@
 import { IControlFlowReplacer } from '../../interfaces/node-transformers/IControlFlowReplacer';
 
-import { NodeControlFlowReplacers } from '../../enums/container/NodeControlFlowReplacers';
+import { ControlFlowReplacers } from '../../enums/container/ControlFlowReplacers';
 
-export type TControlFlowReplacerFactory = (replacer: NodeControlFlowReplacers) => IControlFlowReplacer;
+export type TControlFlowReplacerFactory = (replacer: ControlFlowReplacers) => IControlFlowReplacer;

+ 1 - 1
src/types/container/TNodeTransformersFactory.d.ts → src/types/container/TNodeTransformerFactory.d.ts

@@ -2,4 +2,4 @@ import { INodeTransformer } from '../../interfaces/node-transformers/INodeTransf
 
 import { NodeTransformers } from '../../enums/container/NodeTransformers';
 
-export type TNodeTransformersFactory = (nodeTransformerName: NodeTransformers) => INodeTransformer;
+export type TNodeTransformerFactory = (nodeTransformerName: NodeTransformers) => INodeTransformer;

+ 5 - 0
src/types/container/TObfuscationReplacerFactory.d.ts

@@ -0,0 +1,5 @@
+import { IObfuscationReplacer } from '../../interfaces/node-transformers/IObfuscationReplacer';
+
+import { ObfuscationReplacers } from '../../enums/container/ObfuscationReplacers';
+
+export type TObfuscationReplacerFactory = (replacer: ObfuscationReplacers) => IObfuscationReplacer;

+ 7 - 2
src/utils/RandomGeneratorUtils.ts

@@ -11,12 +11,17 @@ export class RandomGeneratorUtils {
     /**
      * @type {string}
      */
-    public static readonly randomGeneratorPoolHexadecimal: string = 'abcdef0123456789';
+    public static readonly randomGeneratorPoolNumbers: string = '0123456789';
 
     /**
      * @type {string}
      */
-    public static readonly randomGeneratorPoolWithNumbers: string = `${RandomGeneratorUtils.randomGeneratorPool}0123456789`;
+    public static readonly randomGeneratorPoolHexadecimal: string = `abcdef${RandomGeneratorUtils.randomGeneratorPoolNumbers}`;
+
+    /**
+     * @type {string}
+     */
+    public static readonly randomGeneratorPoolWithNumbers: string = `${RandomGeneratorUtils.randomGeneratorPool}${RandomGeneratorUtils.randomGeneratorPoolNumbers}`;
 
     /**
      * @type {Set<string>}

Some files were not shown because too many files changed in this diff