瀏覽代碼

Merge pull request #555 from javascript-obfuscator/new-mangled-names-generator

Improved mangled identifier names generator
Timofey Kachalov 5 年之前
父節點
當前提交
daba144e76
共有 100 個文件被更改,包括 1023 次插入460 次删除
  1. 1 0
      .ncurc
  2. 1 0
      CHANGELOG.md
  3. 0 0
      dist/index.browser.js
  4. 0 0
      dist/index.cli.js
  5. 0 0
      dist/index.js
  6. 9 9
      package.json
  7. 2 0
      src/container/InversifyContainerFacade.ts
  8. 2 1
      src/container/ServiceIdentifiers.ts
  9. 10 0
      src/container/modules/custom-nodes/CustomNodesModule.ts
  10. 13 0
      src/container/modules/node/NodeModule.ts
  11. 17 20
      src/custom-nodes/AbstractCustomNode.ts
  12. 1 1
      src/custom-nodes/AbstractCustomNodeGroup.ts
  13. 75 0
      src/custom-nodes/CustomNodeObfuscator.ts
  14. 0 0
      src/custom-nodes/common/templates/GlobalVariableNoEvalTemplate.ts
  15. 0 0
      src/custom-nodes/common/templates/GlobalVariableTemplate1.ts
  16. 0 0
      src/custom-nodes/common/templates/GlobalVariableTemplate2.ts
  17. 0 0
      src/custom-nodes/common/templates/SingleNodeCallControllerTemplate.ts
  18. 13 4
      src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts
  19. 0 0
      src/custom-nodes/console-output-nodes/templates/ConsoleOutputDisableExpressionTemplate.ts
  20. 11 2
      src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts
  21. 11 2
      src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts
  22. 11 2
      src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts
  23. 11 2
      src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts
  24. 11 2
      src/custom-nodes/control-flow-flattening-nodes/StringLiteralNode.ts
  25. 11 2
      src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts
  26. 11 2
      src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts
  27. 10 1
      src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts
  28. 11 2
      src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts
  29. 11 2
      src/custom-nodes/dead-code-injection-nodes/BlockStatementDeadCodeInjectionNode.ts
  30. 12 3
      src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts
  31. 12 3
      src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts
  32. 14 5
      src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts
  33. 0 0
      src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate.ts
  34. 0 0
      src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate.ts
  35. 0 0
      src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-node/DebugProtectionFunctionTemplate.ts
  36. 0 0
      src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-node/DebuggerTemplate.ts
  37. 0 0
      src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-node/DebuggerTemplateNoEval.ts
  38. 14 5
      src/custom-nodes/domain-lock-nodes/DomainLockNode.ts
  39. 1 1
      src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts
  40. 0 0
      src/custom-nodes/domain-lock-nodes/templates/DomainLockNodeTemplate.ts
  41. 15 15
      src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts
  42. 19 4
      src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts
  43. 15 13
      src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts
  44. 1 1
      src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts
  45. 0 0
      src/custom-nodes/self-defending-nodes/templates/SelfDefendingTemplate.ts
  46. 22 22
      src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts
  47. 12 3
      src/custom-nodes/string-array-nodes/StringArrayNode.ts
  48. 19 15
      src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts
  49. 0 0
      src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/AtobTemplate.ts
  50. 0 0
      src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/Rc4Template.ts
  51. 2 2
      src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/SelfDefendingTemplate.ts
  52. 1 1
      src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts
  53. 0 0
      src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts
  54. 1 1
      src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate.ts
  55. 0 0
      src/custom-nodes/string-array-nodes/templates/string-array-node/StringArrayTemplate.ts
  56. 1 1
      src/custom-nodes/string-array-nodes/templates/string-array-rotate-function-node/SelfDefendingTemplate.ts
  57. 0 0
      src/custom-nodes/string-array-nodes/templates/string-array-rotate-function-node/StringArrayRotateFunctionTemplate.ts
  58. 14 17
      src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts
  59. 39 21
      src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts
  60. 43 6
      src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts
  61. 10 0
      src/interfaces/custom-nodes/ICustomNodeObfuscator.ts
  62. 2 7
      src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts
  63. 17 0
      src/interfaces/node/IScopeIdentifiersTraverser.ts
  64. 11 0
      src/interfaces/node/IScopeIdentifiersTraverserCallbackData.ts
  65. 21 6
      src/node-transformers/converting-transformers/object-expression-extractors/ObjectExpressionToVariableDeclarationExtractor.ts
  66. 36 72
      src/node-transformers/obfuscating-transformers/ScopeIdentifiersTransformer.ts
  67. 64 62
      src/node-transformers/preparing-transformers/VariablePreserveTransformer.ts
  68. 0 34
      src/node/NodeGuards.ts
  69. 102 0
      src/node/ScopeIdentifiersTraverser.ts
  70. 3 0
      src/types/node/TScopeIdentifiersTraverserCallback.ts
  71. 5 9
      test/dev/dev.ts
  72. 1 1
      test/functional-tests/custom-nodes/common/templates/GlobalVariableNoEvalTemplate.spec.ts
  73. 5 5
      test/functional-tests/custom-nodes/debug-protection-nodes/templates/DebugProtectionFunctionCallTemplate.spec.ts
  74. 0 0
      test/functional-tests/custom-nodes/debug-protection-nodes/templates/fixtures/input.js
  75. 0 0
      test/functional-tests/custom-nodes/debug-protection-nodes/templates/fixtures/single-call.js
  76. 0 0
      test/functional-tests/custom-nodes/debug-protection-nodes/templates/workers/evaluation-worker.js
  77. 10 10
      test/functional-tests/custom-nodes/domain-lock-nodes/templates/DomainLockNodeTemplate.spec.ts
  78. 0 0
      test/functional-tests/custom-nodes/domain-lock-nodes/templates/fixtures/prevailing-kind-of-variables-const.js
  79. 0 0
      test/functional-tests/custom-nodes/domain-lock-nodes/templates/fixtures/prevailing-kind-of-variables-let.js
  80. 0 0
      test/functional-tests/custom-nodes/domain-lock-nodes/templates/fixtures/prevailing-kind-of-variables-var.js
  81. 15 15
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper-node-template/StringArrayCallsWrapperNodeTemplate.spec.ts
  82. 0 0
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-const.js
  83. 0 0
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-let.js
  84. 0 0
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-var.js
  85. 4 4
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts
  86. 0 0
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-const.js
  87. 0 0
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-let.js
  88. 0 0
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-var.js
  89. 4 4
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-template/StringArrayTemplate.spec.ts
  90. 0 0
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-template/fixtures/prevailing-kind-of-variables-const.js
  91. 0 0
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-template/fixtures/prevailing-kind-of-variables-let.js
  92. 0 0
      test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-template/fixtures/prevailing-kind-of-variables-var.js
  93. 165 5
      test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/MangledIdentifierNamesGenerator.spec.ts
  94. 3 0
      test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/fixtures/lexical-block-scope-identifiers-1.js
  95. 3 1
      test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/fixtures/string-array-storage-name-conflict-2.js
  96. 8 8
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts
  97. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/prevent-using-of-preserved-identifiers.js
  98. 6 6
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts
  99. 0 0
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/prevent-using-of-preserved-identifiers-1.js
  100. 18 18
      test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts

+ 1 - 0
.ncurc

@@ -1,5 +1,6 @@
 {
   "reject": [
+    "@types/node",
     "ts-node"
   ]
 }

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@ Change Log
 
 v0.25.0
 ---
+* Improved `mangled` identifier names generator logic
 * Fixed conflicts between generated names and names from untouched identifiers from source code. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/550. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/549
 * Prevented transformation of object keys in sequence expression that has `super` call
 

文件差異過大導致無法顯示
+ 0 - 0
dist/index.browser.js


文件差異過大導致無法顯示
+ 0 - 0
dist/index.cli.js


文件差異過大導致無法顯示
+ 0 - 0
dist/index.js


+ 9 - 9
package.json

@@ -45,14 +45,14 @@
     "tslib": "1.10.0"
   },
   "devDependencies": {
-    "@types/chai": "4.2.8",
+    "@types/chai": "4.2.9",
     "@types/chance": "1.0.8",
     "@types/escodegen": "0.0.6",
     "@types/eslint-scope": "3.7.0",
     "@types/estraverse": "0.0.6",
     "@types/estree": "0.0.42",
     "@types/md5": "2.1.33",
-    "@types/mkdirp": "0.5.2",
+    "@types/mkdirp": "1.0.0",
     "@types/mocha": "7.0.1",
     "@types/multimatch": "4.0.0",
     "@types/node": "12.12.14",
@@ -60,8 +60,8 @@
     "@types/sinon": "7.5.1",
     "@types/string-template": "1.0.2",
     "@types/webpack-env": "1.15.1",
-    "@typescript-eslint/eslint-plugin": "2.19.0",
-    "@typescript-eslint/parser": "2.19.0",
+    "@typescript-eslint/eslint-plugin": "2.19.2",
+    "@typescript-eslint/parser": "2.19.2",
     "chai": "4.2.0",
     "coveralls": "3.0.9",
     "eslint": "6.8.0",
@@ -69,21 +69,21 @@
     "eslint-plugin-jsdoc": "21.0.0",
     "eslint-plugin-no-null": "1.0.2",
     "eslint-plugin-prefer-arrow": "1.1.7",
-    "eslint-plugin-unicorn": "16.0.0",
+    "eslint-plugin-unicorn": "16.1.0",
     "fork-ts-checker-notifier-webpack-plugin": "2.0.0",
     "fork-ts-checker-webpack-plugin": "4.0.3",
     "mocha": "7.0.1",
     "nyc": "15.0.0",
     "pjson": "1.0.9",
     "pre-commit": "1.2.2",
-    "rimraf": "3.0.1",
+    "rimraf": "3.0.2",
     "sinon": "8.1.1",
-    "threads": "1.0.2",
+    "threads": "1.1.0",
     "ts-loader": "6.2.1",
     "ts-node": "6.1.0",
     "typescript": "3.8.0-beta",
-    "webpack": "4.41.5",
-    "webpack-cli": "3.3.10",
+    "webpack": "4.41.6",
+    "webpack-cli": "3.3.11",
     "webpack-node-externals": "1.7.2"
   },
   "repository": {

+ 2 - 0
src/container/InversifyContainerFacade.ts

@@ -7,6 +7,7 @@ import { convertingTransformersModule } from './modules/node-transformers/Conver
 import { customNodesModule } from './modules/custom-nodes/CustomNodesModule';
 import { finalizingTransformersModule } from './modules/node-transformers/FinalizingTransformersModule';
 import { generatorsModule } from './modules/generators/GeneratorsModule';
+import { nodeModule } from './modules/node/NodeModule';
 import { nodeTransformersModule } from './modules/node-transformers/NodeTransformersModule';
 import { obfuscatingTransformersModule } from './modules/node-transformers/ObfuscatingTransformersModule';
 import { optionsModule } from './modules/options/OptionsModule';
@@ -196,6 +197,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
         this.container.load(customNodesModule);
         this.container.load(finalizingTransformersModule);
         this.container.load(generatorsModule);
+        this.container.load(nodeModule);
         this.container.load(nodeTransformersModule);
         this.container.load(obfuscatingTransformersModule);
         this.container.load(optionsModule);

+ 2 - 1
src/container/ServiceIdentifiers.ts

@@ -22,6 +22,7 @@ export enum ServiceIdentifiers {
     ICustomNodeGroup = 'ICustomNodeGroup',
     IControlFlowReplacer = 'IControlFlowReplacer',
     ICustomNodeFormatter = 'ICustomNodeFormatter',
+    ICustomNodeObfuscator = 'ICustomNodeObfuscator',
     IEscapeSequenceEncoder = 'IEscapeSequenceEncoder',
     IIdentifierNamesGenerator = 'IIdentifierNamesGenerator',
     IIdentifierObfuscatingReplacer = 'IIdentifierObfuscatingReplacer',
@@ -39,8 +40,8 @@ export enum ServiceIdentifiers {
     IPrevailingKindOfVariablesAnalyzer = 'IPrevailingKindOfVariablesAnalyzer',
     IObjectExpressionExtractor = 'IObjectExpressionExtractor',
     IRandomGenerator = 'IRandomGenerator',
+    IScopeIdentifiersTraverser = 'IScopeIdentifiersTraverser',
     ISourceCode = 'ISourceCode',
-    ISourceMapCorrector = 'ISourceMapCorrector',
     IScopeAnalyzer = 'IScopeAnalyzer',
     IStringArrayStorage = 'IStringArrayStorage',
     IStringArrayStorageAnalyzer = 'IStringArrayStorageAnalyzer',

+ 10 - 0
src/container/modules/custom-nodes/CustomNodesModule.ts

@@ -40,6 +40,8 @@ import { StringArrayNode } from '../../../custom-nodes/string-array-nodes/String
 import { StringArrayRotateFunctionNode } from '../../../custom-nodes/string-array-nodes/StringArrayRotateFunctionNode';
 import { StringLiteralControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode';
 import { StringLiteralNode } from '../../../custom-nodes/control-flow-flattening-nodes/StringLiteralNode';
+import { ICustomNodeObfuscator } from '../../../interfaces/custom-nodes/ICustomNodeObfuscator';
+import { CustomNodeObfuscator } from '../../../custom-nodes/CustomNodeObfuscator';
 
 export const customNodesModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
     // custom nodes
@@ -163,6 +165,7 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
                 ServiceIdentifiers.Newable__ICustomNode,
                 ServiceIdentifiers.Factory__IIdentifierNamesGenerator,
                 ServiceIdentifiers.ICustomNodeFormatter,
+                ServiceIdentifiers.ICustomNodeObfuscator,
                 ServiceIdentifiers.IRandomGenerator,
                 ServiceIdentifiers.IOptions,
                 ServiceIdentifiers.IPrevailingKindOfVariablesAnalyzer
@@ -175,6 +178,7 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
                 ServiceIdentifiers.Newable__ICustomNode,
                 ServiceIdentifiers.Factory__IIdentifierNamesGenerator,
                 ServiceIdentifiers.ICustomNodeFormatter,
+                ServiceIdentifiers.ICustomNodeObfuscator,
                 ServiceIdentifiers.IRandomGenerator,
                 ServiceIdentifiers.IOptions
             ));
@@ -186,6 +190,7 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
                 ServiceIdentifiers.Newable__ICustomNode,
                 ServiceIdentifiers.Factory__IIdentifierNamesGenerator,
                 ServiceIdentifiers.ICustomNodeFormatter,
+                ServiceIdentifiers.ICustomNodeObfuscator,
                 ServiceIdentifiers.IRandomGenerator,
                 ServiceIdentifiers.IOptions,
                 ServiceIdentifiers.IPrevailingKindOfVariablesAnalyzer
@@ -200,4 +205,9 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
     bind<ICustomNodeFormatter>(ServiceIdentifiers.ICustomNodeFormatter)
         .to(CustomNodeFormatter)
         .inSingletonScope();
+
+    // custom node obfuscator
+    bind<ICustomNodeObfuscator>(ServiceIdentifiers.ICustomNodeObfuscator)
+        .to(CustomNodeObfuscator)
+        .inSingletonScope();
 });

+ 13 - 0
src/container/modules/node/NodeModule.ts

@@ -0,0 +1,13 @@
+import { ContainerModule, interfaces } from 'inversify';
+import { ServiceIdentifiers } from '../../ServiceIdentifiers';
+
+import { IScopeIdentifiersTraverser } from '../../../interfaces/node/IScopeIdentifiersTraverser';
+
+import { ScopeIdentifiersTraverser } from '../../../node/ScopeIdentifiersTraverser';
+
+export const nodeModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
+    // scope identifiers traverser
+    bind<IScopeIdentifiersTraverser>(ServiceIdentifiers.IScopeIdentifiersTraverser)
+        .to(ScopeIdentifiersTraverser)
+        .inSingletonScope();
+});

+ 17 - 20
src/custom-nodes/AbstractCustomNode.ts

@@ -5,13 +5,14 @@ import { TIdentifierNamesGeneratorFactory } from '../types/container/generators/
 import { TStatement } from '../types/node/TStatement';
 
 import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
+import { ICustomNodeFormatter } from '../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IIdentifierNamesGenerator } from '../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
 import { IOptions } from '../interfaces/options/IOptions';
 import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../interfaces/custom-nodes/ICustomNodeFormatter';
 
-import { GlobalVariableTemplate1 } from '../templates/GlobalVariableTemplate1';
-import { GlobalVariableTemplate2 } from '../templates/GlobalVariableTemplate2';
+import { GlobalVariableTemplate1 } from './common/templates/GlobalVariableTemplate1';
+import { GlobalVariableTemplate2 } from './common/templates/GlobalVariableTemplate2';
 
 @injectable()
 export abstract class AbstractCustomNode <
@@ -30,6 +31,16 @@ export abstract class AbstractCustomNode <
      */
     protected cachedNode: TStatement[] | null = null;
 
+    /**
+     * @type {ICustomNodeFormatter}
+     */
+    protected readonly customNodeFormatter: ICustomNodeFormatter;
+
+    /**
+     * @type {ICustomNodeObfuscator}
+     */
+    protected readonly customNodeObfuscator: ICustomNodeObfuscator;
+
     /**
      * @type {IIdentifierNamesGenerator}
      */
@@ -45,14 +56,10 @@ export abstract class AbstractCustomNode <
      */
     protected readonly randomGenerator: IRandomGenerator;
 
-    /**
-     * @type {ICustomNodeFormatter}
-     */
-    protected readonly customNodeFormatter: ICustomNodeFormatter;
-
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -60,11 +67,13 @@ export abstract class AbstractCustomNode <
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         this.identifierNamesGenerator = identifierNamesGeneratorFactory(options);
         this.customNodeFormatter = customNodeFormatter;
+        this.customNodeObfuscator = customNodeObfuscator;
         this.randomGenerator = randomGenerator;
         this.options = options;
     }
@@ -100,18 +109,6 @@ export abstract class AbstractCustomNode <
         return '';
     }
 
-    /**
-     * @param {string[]} additionalNames
-     * @returns {string[]}
-     */
-    protected getPreservedNames (additionalNames: string[]): string[] {
-        return Array.from(new Set([
-            ...Array.from(this.identifierNamesGenerator.getPreservedNames().values()),
-            ...additionalNames
-        ]).values())
-        .map((preservedName: string) => `^${preservedName}$`);
-    }
-
     /**
      * @param {TInitialData} args
      */

+ 1 - 1
src/custom-nodes/AbstractCustomNodeGroup.ts

@@ -4,12 +4,12 @@ import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TNodeWithStatements } from '../types/node/TNodeWithStatements';
 
+import { ICallsGraphData } from '../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
 import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
 import { ICustomNodeGroup } from '../interfaces/custom-nodes/ICustomNodeGroup';
 import { IIdentifierNamesGenerator } from '../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
 import { IOptions } from '../interfaces/options/IOptions';
 import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
-import { ICallsGraphData } from '../interfaces/analyzers/calls-graph-analyzer/ICallsGraphData';
 
 import { CustomNode } from '../enums/custom-nodes/CustomNode';
 import { ObfuscationEvent } from '../enums/event-emitters/ObfuscationEvent';

+ 75 - 0
src/custom-nodes/CustomNodeObfuscator.ts

@@ -0,0 +1,75 @@
+import { inject, injectable } from 'inversify';
+import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
+
+import { TInputOptions } from '../types/options/TInputOptions';
+
+import { ICustomNodeObfuscator } from '../interfaces/custom-nodes/ICustomNodeObfuscator';
+import { IOptions } from '../interfaces/options/IOptions';
+import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
+
+import { IdentifierNamesGenerator } from '../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
+
+import { NO_ADDITIONAL_NODES_PRESET } from '../options/presets/NoCustomNodes';
+
+import { JavaScriptObfuscator } from '../JavaScriptObfuscatorFacade';
+
+@injectable()
+export class CustomNodeObfuscator implements ICustomNodeObfuscator {
+    /**
+     * @type {IOptions}
+     */
+    private readonly options: IOptions;
+
+    /**
+     * @type {IRandomGenerator}
+     */
+    private readonly randomGenerator: IRandomGenerator;
+
+    /**
+     * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
+     */
+    public constructor (
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
+    ) {
+        this.randomGenerator = randomGenerator;
+        this.options = options;
+    }
+
+    /**
+     * @param {string} template
+     * @param {TInputOptions} additionalOptions
+     * @returns {string}
+     */
+    public obfuscateTemplate (template: string, additionalOptions: TInputOptions = {}): string {
+        /**
+         * During the first pass we should rename all identifiers to a random one
+         */
+        const firstPassObfuscatedCode = JavaScriptObfuscator.obfuscate(
+            template,
+            {
+                ...NO_ADDITIONAL_NODES_PRESET,
+                identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
+                seed: 1
+            }
+        ).getObfuscatedCode();
+
+        /**
+         * During the seconds pass we should obfuscate template to the same format as the main code
+         * Also, we should add additional transformations that depends on the custom node
+         */
+        const secondPassObfuscatedCode = JavaScriptObfuscator.obfuscate(
+            firstPassObfuscatedCode,
+            {
+                ...NO_ADDITIONAL_NODES_PRESET,
+                identifierNamesGenerator: this.options.identifierNamesGenerator,
+                identifiersDictionary: this.options.identifiersDictionary,
+                seed: this.randomGenerator.getRawSeed(),
+                ...additionalOptions
+            }
+        ).getObfuscatedCode();
+
+        return secondPassObfuscatedCode;
+    }
+}

+ 0 - 0
src/templates/GlobalVariableNoEvalTemplate.ts → src/custom-nodes/common/templates/GlobalVariableNoEvalTemplate.ts


+ 0 - 0
src/templates/GlobalVariableTemplate1.ts → src/custom-nodes/common/templates/GlobalVariableTemplate1.ts


+ 0 - 0
src/templates/GlobalVariableTemplate2.ts → src/custom-nodes/common/templates/GlobalVariableTemplate2.ts


+ 0 - 0
src/templates/SingleNodeCallControllerTemplate.ts → src/custom-nodes/common/templates/SingleNodeCallControllerTemplate.ts


+ 13 - 4
src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts

@@ -4,14 +4,15 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
 
-import { ConsoleOutputDisableExpressionTemplate } from '../../templates/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate';
-import { GlobalVariableNoEvalTemplate } from '../../templates/GlobalVariableNoEvalTemplate';
+import { ConsoleOutputDisableExpressionTemplate } from './templates/ConsoleOutputDisableExpressionTemplate';
+import { GlobalVariableNoEvalTemplate } from '../common/templates/GlobalVariableNoEvalTemplate';
 
 import { initializable } from '../../decorators/Initializable';
 
@@ -29,6 +30,7 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -36,10 +38,17 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 0 - 0
src/templates/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts → src/custom-nodes/console-output-nodes/templates/ConsoleOutputDisableExpressionTemplate.ts


+ 11 - 2
src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts

@@ -6,9 +6,10 @@ import type { BinaryOperator } from 'estree';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeFactory } from '../../node/NodeFactory';
@@ -24,6 +25,7 @@ export class BinaryExpressionFunctionNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -31,10 +33,17 @@ export class BinaryExpressionFunctionNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 11 - 2
src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts

@@ -6,9 +6,10 @@ import * as ESTree from 'estree';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../decorators/Initializable';
 
@@ -40,6 +41,7 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -47,10 +49,17 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 11 - 2
src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts

@@ -6,9 +6,10 @@ import * as ESTree from 'estree';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../decorators/Initializable';
 
@@ -27,6 +28,7 @@ export class CallExpressionFunctionNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -34,10 +36,17 @@ export class CallExpressionFunctionNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 11 - 2
src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts

@@ -6,9 +6,10 @@ import type { LogicalOperator } from 'estree';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeFactory } from '../../node/NodeFactory';
@@ -24,6 +25,7 @@ export class LogicalExpressionFunctionNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -31,10 +33,17 @@ export class LogicalExpressionFunctionNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 11 - 2
src/custom-nodes/control-flow-flattening-nodes/StringLiteralNode.ts

@@ -4,9 +4,10 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../decorators/Initializable';
 
@@ -24,6 +25,7 @@ export class StringLiteralNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -31,10 +33,17 @@ export class StringLiteralNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 11 - 2
src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts

@@ -6,9 +6,10 @@ import type * as ESTree from 'estree';
 import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../../decorators/Initializable';
 
@@ -45,6 +46,7 @@ export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -52,10 +54,17 @@ export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 11 - 2
src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts

@@ -7,10 +7,11 @@ import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage
 import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../../decorators/Initializable';
 
@@ -30,6 +31,7 @@ export class ControlFlowStorageNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -37,10 +39,17 @@ export class ControlFlowStorageNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 10 - 1
src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts

@@ -6,6 +6,7 @@ import type { Expression } from 'estree';
 import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../../types/node/TStatement';
 
+import { ICustomNodeObfuscator } from '../../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
 import { ICustomNodeFormatter } from '../../../interfaces/custom-nodes/ICustomNodeFormatter';
@@ -43,6 +44,7 @@ export class ExpressionWithOperatorControlFlowStorageCallNode extends AbstractCu
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -50,10 +52,17 @@ export class ExpressionWithOperatorControlFlowStorageCallNode extends AbstractCu
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 11 - 2
src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts

@@ -4,9 +4,10 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../../decorators/Initializable';
 
@@ -31,6 +32,7 @@ export class StringLiteralControlFlowStorageCallNode extends AbstractCustomNode
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -38,10 +40,17 @@ export class StringLiteralControlFlowStorageCallNode extends AbstractCustomNode
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 11 - 2
src/custom-nodes/dead-code-injection-nodes/BlockStatementDeadCodeInjectionNode.ts

@@ -6,9 +6,10 @@ import type { BinaryOperator, BlockStatement } from 'estree';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeFactory } from '../../node/NodeFactory';
@@ -29,6 +30,7 @@ export class BlockStatementDeadCodeInjectionNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -36,10 +38,17 @@ export class BlockStatementDeadCodeInjectionNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 12 - 3
src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts

@@ -4,13 +4,14 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { DebugProtectionFunctionCallTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate';
+import { DebugProtectionFunctionCallTemplate } from './templates/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeUtils } from '../../node/NodeUtils';
@@ -32,6 +33,7 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -39,10 +41,17 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 12 - 3
src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts

@@ -4,13 +4,14 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { DebugProtectionFunctionIntervalTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate';
+import { DebugProtectionFunctionIntervalTemplate } from './templates/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeUtils } from '../../node/NodeUtils';
@@ -26,6 +27,7 @@ export class DebugProtectionFunctionIntervalNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -33,10 +35,17 @@ export class DebugProtectionFunctionIntervalNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 14 - 5
src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts

@@ -4,17 +4,18 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { DebuggerTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplate';
-import { DebuggerTemplateNoEval } from '../../templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplateNoEval';
-import { DebugProtectionFunctionTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate';
+import { DebuggerTemplate } from './templates/debug-protection-function-node/DebuggerTemplate';
+import { DebuggerTemplateNoEval } from './templates/debug-protection-function-node/DebuggerTemplateNoEval';
+import { DebugProtectionFunctionTemplate } from './templates/debug-protection-function-node/DebugProtectionFunctionTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeUtils } from '../../node/NodeUtils';
@@ -30,6 +31,7 @@ export class DebugProtectionFunctionNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -37,10 +39,17 @@ export class DebugProtectionFunctionNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 0 - 0
src/templates/debug-protection-nodes/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate.ts → src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate.ts


+ 0 - 0
src/templates/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate.ts → src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate.ts


+ 0 - 0
src/templates/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate.ts → src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-node/DebugProtectionFunctionTemplate.ts


+ 0 - 0
src/templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplate.ts → src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-node/DebuggerTemplate.ts


+ 0 - 0
src/templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplateNoEval.ts → src/custom-nodes/debug-protection-nodes/templates/debug-protection-function-node/DebuggerTemplateNoEval.ts


+ 14 - 5
src/custom-nodes/domain-lock-nodes/DomainLockNode.ts

@@ -4,17 +4,18 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { ICryptUtils } from '../../interfaces/utils/ICryptUtils';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { DomainLockNodeTemplate } from '../../templates/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate';
-import { GlobalVariableNoEvalTemplate } from '../../templates/GlobalVariableNoEvalTemplate';
+import { DomainLockNodeTemplate } from './templates/DomainLockNodeTemplate';
+import { GlobalVariableNoEvalTemplate } from '../common/templates/GlobalVariableNoEvalTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeUtils } from '../../node/NodeUtils';
@@ -35,6 +36,7 @@ export class DomainLockNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      * @param {ICryptUtils} cryptUtils
@@ -43,11 +45,18 @@ export class DomainLockNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions,
         @inject(ServiceIdentifiers.ICryptUtils) cryptUtils: ICryptUtils
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
 
         this.cryptUtils = cryptUtils;
     }
@@ -81,7 +90,7 @@ export class DomainLockNode extends AbstractCustomNode {
             : GlobalVariableNoEvalTemplate();
 
         return this.customNodeFormatter.formatTemplate(DomainLockNodeTemplate(), {
-            domainLockFunctionName: this.identifierNamesGenerator.generate(),
+            domainLockFunctionName: this.randomGenerator.getRandomString(5),
             diff,
             domains: hiddenDomainsString,
             globalVariableTemplate,

+ 1 - 1
src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts

@@ -91,7 +91,7 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
+        const callsControllerFunctionName: string = this.randomGenerator.getRandomString(5);
 
         const domainLockNode: ICustomNode<TInitialData<DomainLockNode>> =
             this.customNodeFactory(CustomNode.DomainLockNode);

+ 0 - 0
src/templates/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate.ts → src/custom-nodes/domain-lock-nodes/templates/DomainLockNodeTemplate.ts


+ 15 - 15
src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts

@@ -4,6 +4,8 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
@@ -11,14 +13,10 @@ import { ObfuscationEvent } from '../../enums/event-emitters/ObfuscationEvent';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { SingleNodeCallControllerTemplate } from '../../templates/SingleNodeCallControllerTemplate';
-
-import { NO_ADDITIONAL_NODES_PRESET } from '../../options/presets/NoCustomNodes';
+import { SingleNodeCallControllerTemplate } from '../common/templates/SingleNodeCallControllerTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
-import { JavaScriptObfuscator } from '../../JavaScriptObfuscatorFacade';
 import { NodeUtils } from '../../node/NodeUtils';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 @injectable()
 export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
@@ -37,6 +35,7 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -44,10 +43,17 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**
@@ -72,17 +78,11 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
      */
     protected getNodeTemplate (): string {
         if (this.appendEvent === ObfuscationEvent.AfterObfuscation) {
-            return JavaScriptObfuscator.obfuscate(
+            return this.customNodeObfuscator.obfuscateTemplate(
                 this.customNodeFormatter.formatTemplate(SingleNodeCallControllerTemplate(), {
                     singleNodeCallControllerFunctionName: this.callsControllerFunctionName
-                }),
-                {
-                    ...NO_ADDITIONAL_NODES_PRESET,
-                    identifierNamesGenerator: this.options.identifierNamesGenerator,
-                    identifiersDictionary: this.options.identifiersDictionary,
-                    seed: this.options.seed
-                }
-            ).getObfuscatedCode();
+                })
+            );
         }
 
         return this.customNodeFormatter.formatTemplate(SingleNodeCallControllerTemplate(), {

+ 19 - 4
src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts

@@ -4,17 +4,23 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import * as ESTree from 'estree';
 
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
+import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeFactory } from '../../node/NodeFactory';
 
 @injectable()
 export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomNode {
+    /**
+     * @type {TNodeWithLexicalScope}
+     */
+    private lexicalScopeNode!: TNodeWithLexicalScope;
     /**
      * @ type {Property}
      */
@@ -23,6 +29,7 @@ export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomN
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -30,13 +37,21 @@ export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomN
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
-    public initialize (properties: ESTree.Property[]): void {
+    public initialize (lexicalScopeNode: TNodeWithLexicalScope, properties: ESTree.Property[]): void {
+        this.lexicalScopeNode = lexicalScopeNode;
         this.properties = properties;
     }
 
@@ -49,7 +64,7 @@ export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomN
             [
                 NodeFactory.variableDeclaratorNode(
                     NodeFactory.identifierNode(
-                        this.identifierNamesGenerator.generate()
+                        this.identifierNamesGenerator.generateForLexicalScope(this.lexicalScopeNode)
                     ),
                     NodeFactory.objectExpressionNode(this.properties)
                 )

+ 15 - 13
src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts

@@ -4,19 +4,17 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../options/presets/NoCustomNodes';
-
-import { SelfDefendingTemplate } from '../../templates/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate';
+import { SelfDefendingTemplate } from './templates/SelfDefendingTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
-import { JavaScriptObfuscator } from '../../JavaScriptObfuscatorFacade';
 import { NodeUtils } from '../../node/NodeUtils';
 
 @injectable()
@@ -35,6 +33,7 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
@@ -43,11 +42,18 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions,
         @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
 
         this.escapeSequenceEncoder = escapeSequenceEncoder;
     }
@@ -71,18 +77,14 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
      * @returns {string}
      */
     protected getNodeTemplate (): string {
-        return JavaScriptObfuscator.obfuscate(
+        return this.customNodeObfuscator.obfuscateTemplate(
             this.customNodeFormatter.formatTemplate(SelfDefendingTemplate(this.escapeSequenceEncoder), {
-                selfDefendingFunctionName: this.identifierNamesGenerator.generate(),
+                selfDefendingFunctionName: this.randomGenerator.getRandomString(5),
                 singleNodeCallControllerFunctionName: this.callsControllerFunctionName
             }),
             {
-                ...NO_ADDITIONAL_NODES_PRESET,
-                identifierNamesGenerator: this.options.identifierNamesGenerator,
-                identifiersDictionary: this.options.identifiersDictionary,
-                seed: this.options.seed,
                 unicodeEscapeSequence: true
             }
-        ).getObfuscatedCode();
+        );
     }
 }

+ 1 - 1
src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts

@@ -91,7 +91,7 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
+        const callsControllerFunctionName: string = this.randomGenerator.getRandomString(5);
 
         const selfDefendingUnicodeNode: ICustomNode<TInitialData<SelfDefendingUnicodeNode>> =
             this.customNodeFactory(CustomNode.SelfDefendingUnicodeNode);

+ 0 - 0
src/templates/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts → src/custom-nodes/self-defending-nodes/templates/SelfDefendingTemplate.ts


+ 22 - 22
src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts

@@ -4,28 +4,26 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
 import { StringArrayEncoding } from '../../enums/StringArrayEncoding';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../options/presets/NoCustomNodes';
-
-import { AtobTemplate } from '../../templates/AtobTemplate';
-import { GlobalVariableNoEvalTemplate } from '../../templates/GlobalVariableNoEvalTemplate';
-import { Rc4Template } from '../../templates/Rc4Template';
-import { SelfDefendingTemplate } from '../../templates/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate';
-import { StringArrayBase64DecodeNodeTemplate } from '../../templates/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate';
-import { StringArrayCallsWrapperTemplate } from '../../templates/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate';
-import { StringArrayRc4DecodeNodeTemplate } from '../../templates/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate';
+import { AtobTemplate } from './templates/string-array-calls-wrapper/AtobTemplate';
+import { GlobalVariableNoEvalTemplate } from '../common/templates/GlobalVariableNoEvalTemplate';
+import { Rc4Template } from './templates/string-array-calls-wrapper/Rc4Template';
+import { SelfDefendingTemplate } from './templates/string-array-calls-wrapper/SelfDefendingTemplate';
+import { StringArrayBase64DecodeNodeTemplate } from './templates/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate';
+import { StringArrayCallsWrapperTemplate } from './templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate';
+import { StringArrayRc4DecodeNodeTemplate } from './templates/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
-import { JavaScriptObfuscator } from '../../JavaScriptObfuscatorFacade';
 import { NodeUtils } from '../../node/NodeUtils';
 
 @injectable()
@@ -50,6 +48,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
@@ -58,11 +57,18 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions,
         @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
 
         this.escapeSequenceEncoder = escapeSequenceEncoder;
     }
@@ -93,24 +99,18 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
     protected getNodeTemplate (): string {
         const decodeNodeTemplate: string = this.getDecodeStringArrayTemplate();
 
-        const preservedNames: string[] = this.getPreservedNames([this.stringArrayName]);
+        const preservedNames: string[] = [this.stringArrayName];
 
-        return JavaScriptObfuscator.obfuscate(
+        return this.customNodeObfuscator.obfuscateTemplate(
             this.customNodeFormatter.formatTemplate(StringArrayCallsWrapperTemplate(), {
                 decodeNodeTemplate,
                 stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
                 stringArrayName: this.stringArrayName
             }),
             {
-                ...NO_ADDITIONAL_NODES_PRESET,
-                identifierNamesGenerator: this.options.identifierNamesGenerator,
-                identifiersDictionary: this.options.identifiersDictionary,
-                reservedNames: [
-                    ...preservedNames
-                ],
-                seed: this.randomGenerator.getRawSeed()
+                reservedNames: preservedNames
             }
-        ).getObfuscatedCode();
+        );
     }
 
     /**

+ 12 - 3
src/custom-nodes/string-array-nodes/StringArrayNode.ts

@@ -4,14 +4,15 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 import { IStringArrayStorage } from '../../interfaces/storages/string-array-storage/IStringArrayStorage';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { StringArrayTemplate } from '../../templates/string-array-nodes/string-array-node/StringArrayTemplate';
+import { StringArrayTemplate } from './templates/string-array-node/StringArrayTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeUtils } from '../../node/NodeUtils';
@@ -33,6 +34,7 @@ export class StringArrayNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
@@ -40,10 +42,17 @@ export class StringArrayNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
     }
 
     /**

+ 19 - 15
src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts

@@ -4,20 +4,18 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
+import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
+import { ICustomNodeObfuscator } from '../../interfaces/custom-nodes/ICustomNodeObfuscator';
 import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../options/presets/NoCustomNodes';
-
-import { SelfDefendingTemplate } from '../../templates/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate';
-import { StringArrayRotateFunctionTemplate } from '../../templates/string-array-nodes/string-array-rotate-function-node/StringArrayRotateFunctionTemplate';
+import { SelfDefendingTemplate } from './templates/string-array-rotate-function-node/SelfDefendingTemplate';
+import { StringArrayRotateFunctionTemplate } from './templates/string-array-rotate-function-node/StringArrayRotateFunctionTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
-import { JavaScriptObfuscator } from '../../JavaScriptObfuscatorFacade';
 import { NodeUtils } from '../../node/NodeUtils';
 import { NumberUtils } from '../../utils/NumberUtils';
 
@@ -43,6 +41,7 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
     /**
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
      * @param {ICustomNodeFormatter} customNodeFormatter
+     * @param {ICustomNodeObfuscator} customNodeObfuscator
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
@@ -51,11 +50,18 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
         @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
+        @inject(ServiceIdentifiers.ICustomNodeObfuscator) customNodeObfuscator: ICustomNodeObfuscator,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions,
         @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder
     ) {
-        super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
+        super(
+            identifierNamesGeneratorFactory,
+            customNodeFormatter,
+            customNodeObfuscator,
+            randomGenerator,
+            options
+        );
 
         this.escapeSequenceEncoder = escapeSequenceEncoder;
     }
@@ -86,6 +92,7 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
     protected getNodeTemplate (): string {
         const timesName: string = this.identifierNamesGenerator.generate();
         const whileFunctionName: string = this.identifierNamesGenerator.generate();
+        const preservedNames: string[] = [this.stringArrayName];
 
         let code: string = '';
 
@@ -98,20 +105,17 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
             code = `${whileFunctionName}(++${timesName})`;
         }
 
-        return JavaScriptObfuscator.obfuscate(
+        return this.customNodeObfuscator.obfuscateTemplate(
             this.customNodeFormatter.formatTemplate(StringArrayRotateFunctionTemplate(), {
                 code,
                 timesName,
+                whileFunctionName,
                 stringArrayName: this.stringArrayName,
-                stringArrayRotationAmount: NumberUtils.toHex(this.stringArrayRotationAmount),
-                whileFunctionName
+                stringArrayRotationAmount: NumberUtils.toHex(this.stringArrayRotationAmount)
             }),
             {
-                ...NO_ADDITIONAL_NODES_PRESET,
-                identifierNamesGenerator: this.options.identifierNamesGenerator,
-                identifiersDictionary: this.options.identifiersDictionary,
-                seed: this.randomGenerator.getRawSeed()
+                reservedNames: preservedNames
             }
-        ).getObfuscatedCode();
+        );
     }
 }

+ 0 - 0
src/templates/AtobTemplate.ts → src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/AtobTemplate.ts


+ 0 - 0
src/templates/Rc4Template.ts → src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/Rc4Template.ts


+ 2 - 2
src/templates/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts → src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/SelfDefendingTemplate.ts

@@ -1,5 +1,5 @@
-import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder';
-import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
+import { IEscapeSequenceEncoder } from '../../../../interfaces/utils/IEscapeSequenceEncoder';
+import { IRandomGenerator } from '../../../../interfaces/utils/IRandomGenerator';
 
 /**
  * @param {IRandomGenerator} randomGenerator

+ 1 - 1
src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts → src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts

@@ -1,4 +1,4 @@
-import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
+import { IRandomGenerator } from '../../../../interfaces/utils/IRandomGenerator';
 
 /**
  * @param {IRandomGenerator} randomGenerator

+ 0 - 0
src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts → src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts


+ 1 - 1
src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate.ts → src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate.ts

@@ -1,4 +1,4 @@
-import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
+import { IRandomGenerator } from '../../../../interfaces/utils/IRandomGenerator';
 
 /**
  * @param {IRandomGenerator} randomGenerator

+ 0 - 0
src/templates/string-array-nodes/string-array-node/StringArrayTemplate.ts → src/custom-nodes/string-array-nodes/templates/string-array-node/StringArrayTemplate.ts


+ 1 - 1
src/templates/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts → src/custom-nodes/string-array-nodes/templates/string-array-rotate-function-node/SelfDefendingTemplate.ts

@@ -1,4 +1,4 @@
-import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder';
+import { IEscapeSequenceEncoder } from '../../../../interfaces/utils/IEscapeSequenceEncoder';
 
 /**
  * SelfDefendingTemplate. Enter code in infinity loop.

+ 0 - 0
src/templates/string-array-nodes/string-array-rotate-function-node/StringArrayRotateFunctionTemplate.ts → src/custom-nodes/string-array-nodes/templates/string-array-rotate-function-node/StringArrayRotateFunctionTemplate.ts


+ 14 - 17
src/generators/identifier-names-generators/AbstractIdentifierNamesGenerator.ts

@@ -41,13 +41,6 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
         this.options = options;
     }
 
-    /**
-     * @returns {Set<string>}
-     */
-    public getPreservedNames (): Set<string> {
-        return this.preservedNamesSet;
-    }
-
     /**
      * @param {string} name
      */
@@ -60,8 +53,6 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
      * @param {TNodeWithLexicalScope} lexicalScopeNode
      */
     public preserveNameForLexicalScope (name: string, lexicalScopeNode: TNodeWithLexicalScope): void {
-        this.preservedNamesSet.add(name);
-
         const preservedNamesForLexicalScopeSet: Set<string> =
             this.lexicalScopesPreservedNamesMap.get(lexicalScopeNode) ?? new Set();
 
@@ -80,22 +71,28 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
 
     /**
      * @param {string} name
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
+     * @param {TNodeWithLexicalScope[]} lexicalScopeNodes
      * @returns {boolean}
      */
-    public isValidIdentifierNameInLexicalScope (name: string, lexicalScopeNode: TNodeWithLexicalScope): boolean {
-        if (!this.notReservedName(name)) {
+    public isValidIdentifierNameInLexicalScopes (name: string, lexicalScopeNodes: TNodeWithLexicalScope[]): boolean {
+        if (!this.isValidIdentifierName(name)) {
             return false;
         }
 
-        const preservedNamesForLexicalScopeSet: Set<string> | null =
-            this.lexicalScopesPreservedNamesMap.get(lexicalScopeNode) ?? null;
+        for (const lexicalScope of lexicalScopeNodes) {
+            const preservedNamesForLexicalScopeSet: Set<string> | null =
+                this.lexicalScopesPreservedNamesMap.get(lexicalScope) ?? null;
+
+            if (!preservedNamesForLexicalScopeSet) {
+                continue;
+            }
 
-        if (!preservedNamesForLexicalScopeSet) {
-            return true;
+            if (preservedNamesForLexicalScopeSet.has(name)) {
+                return false;
+            }
         }
 
-        return !preservedNamesForLexicalScopeSet.has(name);
+        return true;
     }
 
     /**

+ 39 - 21
src/generators/identifier-names-generators/DictionaryIdentifierNamesGenerator.ts

@@ -7,6 +7,7 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 import { AbstractIdentifierNamesGenerator } from './AbstractIdentifierNamesGenerator';
 import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
+import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
 
 @injectable()
 export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator {
@@ -69,26 +70,11 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG
     }
 
     public generate (): string {
-        if (!this.identifierNamesSet.size) {
-            throw new Error('Too many identifiers in the code, add more words to identifiers dictionary');
-        }
+        const identifierName: string = this.generateNewDictionaryName();
 
-        const iteratorResult: IteratorResult<string> = this.identifiersIterator.next();
+        this.preserveName(identifierName);
 
-        if (!iteratorResult.done) {
-            const identifierName: string =iteratorResult.value;
-
-            if (!this.isValidIdentifierName(identifierName)) {
-                return this.generate();
-            }
-
-            return iteratorResult.value;
-        }
-
-        this.identifierNamesSet = new Set(this.getIncrementedIdentifierNames([...this.identifierNamesSet]));
-        this.identifiersIterator = this.identifierNamesSet.values();
-
-        return this.generate();
+        return identifierName;
     }
 
     /**
@@ -96,12 +82,18 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG
      * @returns {string}
      */
     public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope): string {
-        const identifierName: string = this.generate();
+        const lexicalScopes: TNodeWithLexicalScope[] = [
+            lexicalScopeNode,
+            ...NodeLexicalScopeUtils.getLexicalScopes(lexicalScopeNode)
+        ];
+        const identifierName: string = this.generateNewDictionaryName();
 
-        if (!this.isValidIdentifierNameInLexicalScope(identifierName, lexicalScopeNode)) {
+        if (!this.isValidIdentifierNameInLexicalScopes(identifierName, lexicalScopes)) {
             return this.generateForLexicalScope(lexicalScopeNode);
         }
 
+        this.preserveNameForLexicalScope(identifierName, lexicalScopeNode);
+
         return identifierName;
     }
 
@@ -112,7 +104,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG
         const prefix: string = this.options.identifiersPrefix ?
             `${this.options.identifiersPrefix}`
             : '';
-        const identifierName: string = this.generate();
+        const identifierName: string = this.generateNewDictionaryName();
         const identifierNameWithPrefix: string = `${prefix}${identifierName}`;
 
         if (!this.isValidIdentifierName(identifierNameWithPrefix)) {
@@ -124,6 +116,32 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG
         return identifierNameWithPrefix;
     }
 
+    /**
+     * @returns {string}
+     */
+    private generateNewDictionaryName (): string {
+        if (!this.identifierNamesSet.size) {
+            throw new Error('Too many identifiers in the code, add more words to identifiers dictionary');
+        }
+
+        const iteratorResult: IteratorResult<string> = this.identifiersIterator.next();
+
+        if (!iteratorResult.done) {
+            const identifierName: string =iteratorResult.value;
+
+            if (!this.isValidIdentifierName(identifierName)) {
+                return this.generateNewDictionaryName();
+            }
+
+            return iteratorResult.value;
+        }
+
+        this.identifierNamesSet = new Set(this.getIncrementedIdentifierNames([...this.identifierNamesSet]));
+        this.identifiersIterator = this.identifierNamesSet.values();
+
+        return this.generateNewDictionaryName();
+    }
+
     /**
      * @param {string[]} identifierNames
      * @returns {string[]}

+ 43 - 6
src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts

@@ -7,6 +7,7 @@ import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 import { AbstractIdentifierNamesGenerator } from './AbstractIdentifierNamesGenerator';
+import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
 
 @injectable()
 export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator {
@@ -15,6 +16,11 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
      */
     private static readonly initMangledNameCharacter: string = '9';
 
+    /**
+     * @type {Map<TNodeWithLexicalScope, string>}
+     */
+    private static readonly lastMangledNameInScopeMap: Map <TNodeWithLexicalScope, string> = new Map();
+
     /**
      * @type {string[]}
      */
@@ -56,6 +62,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
         const identifierName: string = this.generateNewMangledName(this.previousMangledName);
 
         this.previousMangledName = identifierName;
+        this.preserveName(identifierName);
 
         return identifierName;
     }
@@ -66,13 +73,22 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
      * @returns {string}
      */
     public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string {
-        const identifierName: string = this.generateNewMangledName(this.previousMangledName);
+        const lexicalScopes: TNodeWithLexicalScope[] = [
+            lexicalScopeNode,
+            ...NodeLexicalScopeUtils.getLexicalScopes(lexicalScopeNode)
+        ];
 
-        if (!this.isValidIdentifierNameInLexicalScope(identifierName, lexicalScopeNode)) {
-            return this.generateForLexicalScope(lexicalScopeNode, nameLength);
-        }
+        const lastMangledNameForScope: string = this.getLastMangledNameForScopes(lexicalScopes);
 
-        this.previousMangledName = identifierName;
+        let identifierName: string = lastMangledNameForScope;
+
+        do {
+            identifierName = this.generateNewMangledName(identifierName);
+        } while (!this.isValidIdentifierNameInLexicalScopes(identifierName, lexicalScopes));
+
+        MangledIdentifierNamesGenerator.lastMangledNameInScopeMap.set(lexicalScopeNode, identifierName);
+
+        this.preserveNameForLexicalScope(identifierName, lexicalScopeNode);
 
         return identifierName;
     }
@@ -85,9 +101,11 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
         const prefix: string = this.options.identifiersPrefix ?
             `${this.options.identifiersPrefix}`
             : '';
-        const identifierName: string = this.generate(nameLength);
+        const identifierName: string = this.generateNewMangledName(this.previousMangledName);
         const identifierNameWithPrefix: string = `${prefix}${identifierName}`;
 
+        this.previousMangledName = identifierName;
+
         if (!this.isValidIdentifierName(identifierNameWithPrefix)) {
             return this.generateWithPrefix(nameLength);
         }
@@ -150,4 +168,23 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
 
         return newMangledName;
     }
+
+    /**
+     * @param {TNodeWithLexicalScope[]} lexicalScopeNodes
+     * @returns {string}
+     */
+    private getLastMangledNameForScopes (lexicalScopeNodes: TNodeWithLexicalScope[]): string {
+        for (const lexicalScope of lexicalScopeNodes) {
+            const lastMangledName: string | null = MangledIdentifierNamesGenerator.lastMangledNameInScopeMap
+                .get(lexicalScope) ?? null;
+
+            if (!lastMangledName) {
+                continue;
+            }
+
+            return lastMangledName;
+        }
+
+        return MangledIdentifierNamesGenerator.initMangledNameCharacter;
+    }
 }

+ 10 - 0
src/interfaces/custom-nodes/ICustomNodeObfuscator.ts

@@ -0,0 +1,10 @@
+import { TInputOptions } from '../../types/options/TInputOptions';
+
+export interface ICustomNodeObfuscator {
+    /**
+     * @param {string} template
+     * @param {TInputOptions} additionalOptions
+     * @returns {string}
+     */
+    obfuscateTemplate (template: string, additionalOptions?: TInputOptions): string;
+}

+ 2 - 7
src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator.ts

@@ -21,11 +21,6 @@ export interface IIdentifierNamesGenerator {
      */
     generateWithPrefix (nameLength?: number): string;
 
-    /**
-     * @returns {Set<string>}
-     */
-    getPreservedNames (): Set<string>;
-
     /**
      * @param {string} identifierName
      * @returns {boolean}
@@ -34,10 +29,10 @@ export interface IIdentifierNamesGenerator {
 
     /**
      * @param {string} identifierName
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
+     * @param {TNodeWithLexicalScope[]} lexicalScopeNodes
      * @returns {boolean}
      */
-    isValidIdentifierNameInLexicalScope (identifierName: string, lexicalScopeNode: TNodeWithLexicalScope): boolean;
+    isValidIdentifierNameInLexicalScopes (identifierName: string, lexicalScopeNodes: TNodeWithLexicalScope[]): boolean;
 
     /**
      * @param {string} identifierName

+ 17 - 0
src/interfaces/node/IScopeIdentifiersTraverser.ts

@@ -0,0 +1,17 @@
+import * as ESTree from 'estree';
+
+import { TScopeIdentifiersTraverserCallback } from '../../types/node/TScopeIdentifiersTraverserCallback';
+
+export interface IScopeIdentifiersTraverser {
+    /**
+     * @param {Program} programNode
+     * @param {Node | null} parentNode
+     * @param {TScopeIdentifiersTraverserCallback} callback
+     */
+    traverse (
+        programNode: ESTree.Program,
+        parentNode: ESTree.Node | null,
+        callback: TScopeIdentifiersTraverserCallback
+    ): void;
+
+}

+ 11 - 0
src/interfaces/node/IScopeIdentifiersTraverserCallbackData.ts

@@ -0,0 +1,11 @@
+import * as eslintScope from 'eslint-scope';
+
+import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
+
+export interface IScopeIdentifiersTraverserCallbackData {
+    isGlobalDeclaration: boolean;
+    rootScope: eslintScope.Scope;
+    variable: eslintScope.Variable;
+    variableLexicalScopeNode: TNodeWithLexicalScope;
+    variableScope: eslintScope.Scope;
+}

+ 21 - 6
src/node-transformers/converting-transformers/object-expression-extractors/ObjectExpressionToVariableDeclarationExtractor.ts

@@ -19,6 +19,8 @@ import { NodeAppender } from '../../../node/NodeAppender';
 import { NodeGuards } from '../../../node/NodeGuards';
 import { NodeStatementUtils } from '../../../node/NodeStatementUtils';
 import { NodeUtils } from '../../../node/NodeUtils';
+import { TNodeWithLexicalScope } from '../../../types/node/TNodeWithLexicalScope';
+import { NodeLexicalScopeUtils } from '../../../node/NodeLexicalScopeUtils';
 
 @injectable()
 export class ObjectExpressionToVariableDeclarationExtractor implements IObjectExpressionExtractor {
@@ -74,12 +76,18 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx
         objectExpressionNode: ESTree.ObjectExpression,
         hostStatement: ESTree.Statement
     ): IObjectExpressionExtractorResult {
-        const properties: ESTree.Property[] = objectExpressionNode.properties;
+        const lexicalScopeNode: TNodeWithLexicalScope | null = NodeLexicalScopeUtils.getLexicalScope(hostStatement) ?? null;
 
-        const newObjectExpressionHostStatement: ESTree.VariableDeclaration = this.getObjectExpressionHostNode(properties);
-        const newObjectExpressionIdentifier: ESTree.Identifier = this.getObjectExpressionIdentifierNode(newObjectExpressionHostStatement);
-        const newObjectExpressionNode: ESTree.ObjectExpression = this.getObjectExpressionNode(newObjectExpressionHostStatement);
+        if (!lexicalScopeNode) {
+            throw new Error('Cannot find lexical scope node for the host statement node');
+        }
+
+        const properties: ESTree.Property[] = objectExpressionNode.properties;
 
+        const newObjectExpressionHostStatement: ESTree.VariableDeclaration = this.getObjectExpressionHostNode(
+            lexicalScopeNode,
+            properties
+        );
         const statementsToInsert: TStatement[] = [newObjectExpressionHostStatement];
         const hostNodeWithStatements: TNodeWithStatements = NodeStatementUtils.getScopeOfNode(hostStatement);
 
@@ -87,6 +95,9 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx
         NodeUtils.parentizeAst(newObjectExpressionHostStatement);
         NodeUtils.parentizeNode(newObjectExpressionHostStatement, hostNodeWithStatements);
 
+        const newObjectExpressionIdentifier: ESTree.Identifier = this.getObjectExpressionIdentifierNode(newObjectExpressionHostStatement);
+        const newObjectExpressionNode: ESTree.ObjectExpression = this.getObjectExpressionNode(newObjectExpressionHostStatement);
+
         return {
             nodeToReplace: newObjectExpressionIdentifier,
             objectExpressionHostStatement: newObjectExpressionHostStatement,
@@ -95,16 +106,20 @@ export class ObjectExpressionToVariableDeclarationExtractor implements IObjectEx
     }
 
     /**
+     * @param {TNodeWithLexicalScope} lexicalScopeNode
      * @param {Property[]} properties
      * @returns {VariableDeclaration}
      */
-    private getObjectExpressionHostNode (properties: ESTree.Property[]): ESTree.VariableDeclaration {
+    private getObjectExpressionHostNode (
+        lexicalScopeNode: TNodeWithLexicalScope,
+        properties: ESTree.Property[]
+    ): ESTree.VariableDeclaration {
         const variableDeclarationHostNodeCustomNode: ICustomNode<TInitialData<ObjectExpressionVariableDeclarationHostNode>> =
             this.objectExpressionKeysTransformerCustomNodeFactory(
                 ObjectExpressionKeysTransformerCustomNode.ObjectExpressionVariableDeclarationHostNode
             );
 
-        variableDeclarationHostNodeCustomNode.initialize(properties);
+        variableDeclarationHostNodeCustomNode.initialize(lexicalScopeNode, properties);
 
         const statementNode: TStatement = variableDeclarationHostNodeCustomNode.getNode()[0];
 

+ 36 - 72
src/node-transformers/obfuscating-transformers/ScopeIdentifiersTransformer.ts

@@ -11,7 +11,8 @@ import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
 import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer';
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
-import { IScopeAnalyzer } from '../../interfaces/analyzers/scope-analyzer/IScopeAnalyzer';
+import { IScopeIdentifiersTraverser } from '../../interfaces/node/IScopeIdentifiersTraverser';
+import { IScopeIdentifiersTraverserCallbackData } from '../../interfaces/node/IScopeIdentifiersTraverserCallbackData';
 import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
 
 import { IdentifierObfuscatingReplacer } from '../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer';
@@ -26,19 +27,6 @@ import { NodeMetadata } from '../../node/NodeMetadata';
  */
 @injectable()
 export class ScopeIdentifiersTransformer extends AbstractNodeTransformer {
-    /**
-     * @type {string}
-     */
-    private static readonly argumentsVariableName: string = 'arguments';
-
-    /**
-     * @type {string[]}
-     */
-    private static readonly globalScopeNames: string[] = [
-        'global',
-        'module'
-    ];
-
     /**
      * @type {IIdentifierObfuscatingReplacer}
      */
@@ -50,29 +38,29 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer {
     private readonly lexicalScopesWithObjectPatternWithoutDeclarationMap: Map<TNodeWithLexicalScope, boolean> = new Map();
 
     /**
-     * @type {IScopeAnalyzer}
+     * @type {IScopeIdentifiersTraverser}
      */
-    private readonly scopeAnalyzer: IScopeAnalyzer;
+    private readonly scopeIdentifiersTraverser: IScopeIdentifiersTraverser;
 
     /**
      * @param {TIdentifierObfuscatingReplacerFactory} identifierObfuscatingReplacerFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
-     * @param {IScopeAnalyzer} scopeAnalyzer
+     * @param {IScopeIdentifiersTraverser} scopeIdentifiersTraverser
      */
     public constructor (
         @inject(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
             identifierObfuscatingReplacerFactory: TIdentifierObfuscatingReplacerFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions,
-        @inject(ServiceIdentifiers.IScopeAnalyzer) scopeAnalyzer: IScopeAnalyzer
+        @inject(ServiceIdentifiers.IScopeIdentifiersTraverser) scopeIdentifiersTraverser: IScopeIdentifiersTraverser
     ) {
         super(randomGenerator, options);
 
         this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
             IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
         );
-        this.scopeAnalyzer = scopeAnalyzer;
+        this.scopeIdentifiersTraverser = scopeIdentifiersTraverser;
     }
 
     /**
@@ -85,8 +73,6 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer {
                 return {
                     enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => {
                         if (parentNode && NodeGuards.isProgramNode(node)) {
-                            this.analyzeNode(node, parentNode);
-
                             return this.transformNode(node, parentNode);
                         }
                     }
@@ -97,66 +83,44 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer {
         }
     }
 
-    /**
-     * @param {Program} programNode
-     * @param {Node | null} parentNode
-     * @returns {Node}
-     */
-    public analyzeNode (programNode: ESTree.Program, parentNode: ESTree.Node | null): void {
-        this.scopeAnalyzer.analyze(programNode);
-    }
-
     /**
      * @param {VariableDeclaration} programNode
      * @param {NodeGuards} parentNode
      * @returns {NodeGuards}
      */
     public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node {
-        const globalScope: eslintScope.Scope = this.scopeAnalyzer.acquireScope(programNode);
-
-        this.traverseScopeVariables(globalScope);
-
-        return programNode;
-    }
-
-    /**
-     * @param {Scope} scope
-     */
-    private traverseScopeVariables (scope: eslintScope.Scope): void {
-        const lexicalScope: eslintScope.Scope = scope.variableScope;
-        const nodeWithLexicalScope: TNodeWithLexicalScope | null = NodeGuards.isNodeWithBlockLexicalScope(lexicalScope.block)
-            ? lexicalScope.block
-            : null;
-        const isGlobalDeclaration: boolean = ScopeIdentifiersTransformer.globalScopeNames.includes(lexicalScope.type);
-
-        if (!nodeWithLexicalScope) {
-            return;
-        }
-
-        for (const variable of scope.variables) {
-            if (variable.name === ScopeIdentifiersTransformer.argumentsVariableName) {
-                continue;
-            }
-
-            if (!this.options.renameGlobals && isGlobalDeclaration) {
-                const isImportBindingOrCatchClauseIdentifier: boolean = variable.defs
-                    .every((definition: eslintScope.Definition) =>
-                        definition.type === 'ImportBinding'
-                        || definition.type === 'CatchClause'
-                    );
-
-                // skip all global identifiers except import statement and catch clause parameter identifiers
-                if (!isImportBindingOrCatchClauseIdentifier) {
-                    continue;
+        this.scopeIdentifiersTraverser.traverse(
+            programNode,
+            parentNode,
+            (data: IScopeIdentifiersTraverserCallbackData) => {
+                const {
+                    isGlobalDeclaration,
+                    variable,
+                    variableLexicalScopeNode
+                } = data;
+
+                if (!this.options.renameGlobals && isGlobalDeclaration) {
+                    const isImportBindingOrCatchClauseIdentifier: boolean = variable.defs
+                        .every((definition: eslintScope.Definition) =>
+                            definition.type === 'ImportBinding'
+                            || definition.type === 'CatchClause'
+                        );
+
+                    // skip all global identifiers except import statement and catch clause parameter identifiers
+                    if (!isImportBindingOrCatchClauseIdentifier) {
+                        return;
+                    }
                 }
-            }
 
-            this.transformScopeVariableIdentifiers(variable, nodeWithLexicalScope, isGlobalDeclaration);
-        }
+                this.transformScopeVariableIdentifiers(
+                    variable,
+                    variableLexicalScopeNode,
+                    isGlobalDeclaration
+                );
+            }
+        );
 
-        for (const childScope of scope.childScopes) {
-            this.traverseScopeVariables(childScope);
-        }
+        return programNode;
     }
 
     /**

+ 64 - 62
src/node-transformers/preparing-transformers/VariablePreserveTransformer.ts

@@ -1,5 +1,6 @@
 import { inject, injectable, } from 'inversify';
 import * as ESTree from 'estree';
+import * as eslintScope from 'eslint-scope';
 
 import { TIdentifierObfuscatingReplacerFactory } from '../../types/container/node-transformers/TIdentifierObfuscatingReplacerFactory';
 import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
@@ -8,12 +9,14 @@ import { IIdentifierObfuscatingReplacer } from '../../interfaces/node-transforme
 import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
-import { IdentifierObfuscatingReplacer } from '../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer';
+import { IScopeIdentifiersTraverser } from '../../interfaces/node/IScopeIdentifiersTraverser';
+import { IScopeIdentifiersTraverserCallbackData } from '../../interfaces/node/IScopeIdentifiersTraverserCallbackData';
 
 import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TransformationStage } from '../../enums/node-transformers/TransformationStage';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
+import { IdentifierObfuscatingReplacer } from '../../enums/node-transformers/obfuscating-transformers/obfuscating-replacers/IdentifierObfuscatingReplacer';
 import { NodeGuards } from '../../node/NodeGuards';
 
 /**
@@ -22,31 +25,34 @@ import { NodeGuards } from '../../node/NodeGuards';
 @injectable()
 export class VariablePreserveTransformer extends AbstractNodeTransformer {
     /**
-     * @type {TNodeWithLexicalScope[]}
+     * @type {IIdentifierObfuscatingReplacer}
      */
-    private readonly enteredLexicalScopesStack: TNodeWithLexicalScope[] = [];
+    private readonly identifierObfuscatingReplacer: IIdentifierObfuscatingReplacer;
 
     /**
-     * @type {IIdentifierObfuscatingReplacer}
+     * @type {IScopeIdentifiersTraverser}
      */
-    private readonly identifierObfuscatingReplacer: IIdentifierObfuscatingReplacer;
+    private readonly scopeIdentifiersTraverser: IScopeIdentifiersTraverser;
 
     /**
      * @param {TIdentifierObfuscatingReplacerFactory} identifierObfuscatingReplacerFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
+     * @param {IScopeIdentifiersTraverser} scopeIdentifiersTraverser
      */
     public constructor (
         @inject(ServiceIdentifiers.Factory__IIdentifierObfuscatingReplacer)
             identifierObfuscatingReplacerFactory: TIdentifierObfuscatingReplacerFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
-        @inject(ServiceIdentifiers.IOptions) options: IOptions
+        @inject(ServiceIdentifiers.IOptions) options: IOptions,
+        @inject(ServiceIdentifiers.IScopeIdentifiersTraverser) scopeIdentifiersTraverser: IScopeIdentifiersTraverser
     ) {
         super(randomGenerator, options);
 
         this.identifierObfuscatingReplacer = identifierObfuscatingReplacerFactory(
             IdentifierObfuscatingReplacer.BaseIdentifierObfuscatingReplacer
         );
+        this.scopeIdentifiersTraverser = scopeIdentifiersTraverser;
     }
 
     /**
@@ -58,29 +64,9 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer {
             case TransformationStage.Preparing:
                 return {
                     enter: (node: ESTree.Node, parentNode: ESTree.Node | null): ESTree.Node | undefined => {
-                        if (NodeGuards.isNodeWithLexicalScope(node)) {
-                            this.addLexicalScopeToEnteredLexicalScopesStack(node);
-                        }
-
-                        if (
-                            NodeGuards.isIdentifierNode(node)
-                            && parentNode
-                        ) {
-                            const isOnTheRootLexicalScope: boolean = this.enteredLexicalScopesStack.length === 1;
-
-                            if (isOnTheRootLexicalScope) {
-                                this.preserveIdentifierNameForRootLexicalScope(node, parentNode);
-                            } else {
-                                this.preserveIdentifierNameForLexicalScope(node, parentNode);
-                            }
-
+                        if (parentNode && NodeGuards.isProgramNode(node)) {
                             return this.transformNode(node, parentNode);
                         }
-                    },
-                    leave: (node: ESTree.Node): void => {
-                        if (NodeGuards.isNodeWithLexicalScope(node)) {
-                            this.removeLexicalScopeFromEnteredLexicalScopesStack(node);
-                        }
                     }
                 };
 
@@ -90,58 +76,74 @@ export class VariablePreserveTransformer extends AbstractNodeTransformer {
     }
 
     /**
-     * @param {Identifier} identifierNode
-     * @param {Node} parentNode
-     * @returns {Node}
+     * @param {VariableDeclaration} programNode
+     * @param {NodeGuards} parentNode
+     * @returns {NodeGuards}
      */
-    public transformNode (identifierNode: ESTree.Identifier, parentNode: ESTree.Node): ESTree.Node {
-        return identifierNode;
+    public transformNode (programNode: ESTree.Program, parentNode: ESTree.Node): ESTree.Node {
+        this.scopeIdentifiersTraverser.traverse(
+            programNode,
+            parentNode,
+            (data: IScopeIdentifiersTraverserCallbackData) => {
+                const {
+                    isGlobalDeclaration,
+                    variable,
+                    variableScope
+                } = data;
+
+                this.preserveScopeVariableIdentifiers(
+                    variable,
+                    variableScope,
+                    isGlobalDeclaration
+                );
+            }
+        );
+
+        return programNode;
     }
 
     /**
-     * @param {Identifier} identifierNode
-     * @param {Node} parentNode
+     * @param {Variable} variable
+     * @param {Scope} variableScope
+     * @param {boolean} isGlobalDeclaration
      */
-    private preserveIdentifierNameForRootLexicalScope (
-        identifierNode: ESTree.Identifier,
-        parentNode: ESTree.Node
+    private preserveScopeVariableIdentifiers (
+        variable: eslintScope.Variable,
+        variableScope: eslintScope.Scope,
+        isGlobalDeclaration: boolean
     ): void {
+        for (const identifier of variable.identifiers) {
+            if (isGlobalDeclaration) {
+                this.preserveIdentifierNameForRootLexicalScope(identifier);
+            } else {
+                this.preserveIdentifierNameForLexicalScope(identifier, variableScope);
+            }
+        }
+    }
+
+    /**
+     * @param {Identifier} identifierNode
+     */
+    private preserveIdentifierNameForRootLexicalScope (identifierNode: ESTree.Identifier): void {
         this.identifierObfuscatingReplacer.preserveName(identifierNode);
     }
 
     /**
      * @param {Identifier} identifierNode
-     * @param {Node} parentNode
+     * @param {Scope} variableScope
      */
     private preserveIdentifierNameForLexicalScope (
         identifierNode: ESTree.Identifier,
-        parentNode: ESTree.Node
+        variableScope: eslintScope.Scope
     ): void {
-        if (
-            !NodeGuards.parentNodeIsPropertyNode(identifierNode, parentNode)
-            && !NodeGuards.parentNodeIsMemberExpressionNode(identifierNode, parentNode)
-            && !NodeGuards.parentNodeIsMethodDefinitionNode(identifierNode, parentNode)
-            && !NodeGuards.isLabelIdentifierNode(identifierNode, parentNode)
-        ) {
-            return;
-        }
+        const lexicalScopeNode: TNodeWithLexicalScope | null = NodeGuards.isNodeWithLexicalScope(variableScope.block)
+            ? variableScope.block
+            : null;
 
-        for (const lexicalScope of this.enteredLexicalScopesStack) {
-            this.identifierObfuscatingReplacer.preserveNameForLexicalScope(identifierNode, lexicalScope);
+        if (!lexicalScopeNode) {
+            return;
         }
-    }
-
-    /**
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private addLexicalScopeToEnteredLexicalScopesStack (lexicalScopeNode: TNodeWithLexicalScope): void {
-        this.enteredLexicalScopesStack.push(lexicalScopeNode);
-    }
 
-    /**
-     * @param {TNodeWithLexicalScope} lexicalScopeNode
-     */
-    private removeLexicalScopeFromEnteredLexicalScopesStack (lexicalScopeNode: TNodeWithLexicalScope): void {
-        this.enteredLexicalScopesStack.pop();
+        this.identifierObfuscatingReplacer.preserveNameForLexicalScope(identifierNode, lexicalScopeNode);
     }
 }

+ 0 - 34
src/node/NodeGuards.ts

@@ -309,40 +309,6 @@ export class NodeGuards {
         return node.type === NodeType.Property;
     }
 
-    /**
-     * @param {Node} node
-     * @param {Node} parentNode
-     * @returns {boolean}
-     */
-    public static parentNodeIsPropertyNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier {
-        return NodeGuards.isPropertyNode(parentNode)
-            && !parentNode.computed
-            && parentNode.key === node;
-    }
-
-    /**
-     * @param {Node} node
-     * @param {Node} parentNode
-     * @returns {boolean}
-     */
-    public static parentNodeIsMemberExpressionNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier {
-        return (
-            NodeGuards.isMemberExpressionNode(parentNode)
-            && !parentNode.computed
-            && parentNode.property === node
-        );
-    }
-
-    /**
-     * @param {Node} node
-     * @param {Node} parentNode
-     * @returns {boolean}
-     */
-    public static parentNodeIsMethodDefinitionNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier {
-        return NodeGuards.isMethodDefinitionNode(parentNode)
-            && !parentNode.computed;
-    }
-
     /**
      * @param {Node} node
      * @returns {boolean}

+ 102 - 0
src/node/ScopeIdentifiersTraverser.ts

@@ -0,0 +1,102 @@
+import { inject, injectable, } from 'inversify';
+import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
+
+import * as eslintScope from 'eslint-scope';
+import * as ESTree from 'estree';
+
+import { TNodeWithLexicalScope } from '../types/node/TNodeWithLexicalScope';
+import { TScopeIdentifiersTraverserCallback } from '../types/node/TScopeIdentifiersTraverserCallback';
+
+import { IScopeAnalyzer } from '../interfaces/analyzers/scope-analyzer/IScopeAnalyzer';
+import { IScopeIdentifiersTraverser } from '../interfaces/node/IScopeIdentifiersTraverser';
+
+import { NodeGuards } from './NodeGuards';
+
+/**
+ * Scope traverser
+ */
+@injectable()
+export class ScopeIdentifiersTraverser implements IScopeIdentifiersTraverser {
+    /**
+     * @type {string}
+     */
+    private static readonly argumentsVariableName: string = 'arguments';
+
+    /**
+     * @type {string[]}
+     */
+    private static readonly globalScopeNames: string[] = [
+        'global',
+        'module'
+    ];
+
+    /**
+     * @type {IScopeAnalyzer}
+     */
+    private readonly scopeAnalyzer: IScopeAnalyzer;
+
+    /**
+     * @param {IScopeAnalyzer} scopeAnalyzer
+     */
+    public constructor (
+        @inject(ServiceIdentifiers.IScopeAnalyzer) scopeAnalyzer: IScopeAnalyzer
+    ) {
+        this.scopeAnalyzer = scopeAnalyzer;
+    }
+
+    /**
+     * @param {Program} programNode
+     * @param {Node | null} parentNode
+     * @param {TScopeIdentifiersTraverserCallback} callback
+     */
+    public traverse (
+        programNode: ESTree.Program,
+        parentNode: ESTree.Node | null,
+        callback: TScopeIdentifiersTraverserCallback
+    ): void {
+        this.scopeAnalyzer.analyze(programNode);
+
+        const globalScope: eslintScope.Scope = this.scopeAnalyzer.acquireScope(programNode);
+
+        this.traverseScopeVariables(globalScope, globalScope, callback);
+    }
+
+    /**
+     * @param {Scope} rootScope
+     * @param {Scope} currentScope
+     * @param {TScopeIdentifiersTraverserCallback} callback
+     */
+    private traverseScopeVariables (
+        rootScope: eslintScope.Scope,
+        currentScope: eslintScope.Scope,
+        callback: TScopeIdentifiersTraverserCallback
+    ): void {
+        const variableScope: eslintScope.Scope = currentScope.variableScope;
+        const variableLexicalScopeNode: TNodeWithLexicalScope | null = NodeGuards.isNodeWithBlockLexicalScope(variableScope.block)
+            ? variableScope.block
+            : null;
+        const isGlobalDeclaration: boolean = ScopeIdentifiersTraverser.globalScopeNames.includes(variableScope.type);
+
+        if (!variableLexicalScopeNode) {
+            return;
+        }
+
+        for (const variable of currentScope.variables) {
+            if (variable.name === ScopeIdentifiersTraverser.argumentsVariableName) {
+                continue;
+            }
+
+            callback({
+                isGlobalDeclaration,
+                rootScope,
+                variable,
+                variableScope,
+                variableLexicalScopeNode
+            });
+        }
+
+        for (const childScope of currentScope.childScopes) {
+            this.traverseScopeVariables(rootScope, childScope, callback);
+        }
+    }
+}

+ 3 - 0
src/types/node/TScopeIdentifiersTraverserCallback.ts

@@ -0,0 +1,3 @@
+import { IScopeIdentifiersTraverserCallbackData } from '../../interfaces/node/IScopeIdentifiersTraverserCallbackData';
+
+export type TScopeIdentifiersTraverserCallback = (data: IScopeIdentifiersTraverserCallbackData) => void;

+ 5 - 9
test/dev/dev.ts

@@ -8,20 +8,16 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
     let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
         `
             function foo () {
-                const testA = 'abc';
-                const testB = 'abc';
-                const testC = 'abc';
-                const testD = 'abc';
+            
             }
         `,
         {
             ...NO_ADDITIONAL_NODES_PRESET,
             compact: false,
-            identifierNamesGenerator: 'dictionary',
-            identifiersDictionary: ['a', 'b', 'aa'],
-            identifiersPrefix: 'a',
-            stringArray: true,
-            stringArrayThreshold: 1
+            identifierNamesGenerator: 'mangled',
+            renameGlobals: true,
+            reservedNames: ['a'],
+            log: true
         }
     ).getObfuscatedCode();
 

+ 1 - 1
test/functional-tests/templates/GlobalVariableNoEvalTemplate.spec.ts → test/functional-tests/custom-nodes/common/templates/GlobalVariableNoEvalTemplate.spec.ts

@@ -4,7 +4,7 @@ import format from 'string-template';
 
 import { assert } from 'chai';
 
-import { GlobalVariableNoEvalTemplate } from '../../../src/templates/GlobalVariableNoEvalTemplate';
+import { GlobalVariableNoEvalTemplate } from '../../../../../src/custom-nodes/common/templates/GlobalVariableNoEvalTemplate';
 
 describe('GlobalVariableNoEvalTemplate', () => {
     describe('Variant #1: simple', () => {

+ 5 - 5
test/functional-tests/templates/debug-protection-nodes/DebugProtectionFunctionCallTemplate.spec.ts → test/functional-tests/custom-nodes/debug-protection-nodes/templates/DebugProtectionFunctionCallTemplate.spec.ts

@@ -1,14 +1,14 @@
 import { assert } from 'chai';
 import { spawn, Thread, Worker } from 'threads/dist';
 
-import { readFileAsString } from '../../../helpers/readFileAsString';
+import { readFileAsString } from '../../../../helpers/readFileAsString';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
 
-import { IdentifierNamesGenerator } from '../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
-import { ObfuscationTarget } from '../../../../src/enums/ObfuscationTarget';
+import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
+import { ObfuscationTarget } from '../../../../../src/enums/ObfuscationTarget';
 
-import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
+import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
 
 async function spawnThread(obfuscatedCode: string, threadCallback: Function, timeoutCallback: Function): Promise<void> {
     const evaluationWorker = await spawn(new Worker('./workers/evaluation-worker'));

+ 0 - 0
test/functional-tests/templates/debug-protection-nodes/fixtures/input.js → test/functional-tests/custom-nodes/debug-protection-nodes/templates/fixtures/input.js


+ 0 - 0
test/functional-tests/templates/debug-protection-nodes/fixtures/single-call.js → test/functional-tests/custom-nodes/debug-protection-nodes/templates/fixtures/single-call.js


+ 0 - 0
test/functional-tests/templates/debug-protection-nodes/workers/evaluation-worker.js → test/functional-tests/custom-nodes/debug-protection-nodes/templates/workers/evaluation-worker.js


+ 10 - 10
test/functional-tests/templates/domain-lock-nodes/DomainLockNodeTemplate.spec.ts → test/functional-tests/custom-nodes/domain-lock-nodes/templates/DomainLockNodeTemplate.spec.ts

@@ -4,20 +4,20 @@ import format from 'string-template';
 
 import { assert } from 'chai';
 
-import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers';
+import { ServiceIdentifiers } from '../../../../../src/container/ServiceIdentifiers';
 
-import { ICryptUtils } from '../../../../src/interfaces/utils/ICryptUtils';
-import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade';
-import { IObfuscatedCode } from '../../../../src/interfaces/source-code/IObfuscatedCode';
+import { ICryptUtils } from '../../../../../src/interfaces/utils/ICryptUtils';
+import { IInversifyContainerFacade } from '../../../../../src/interfaces/container/IInversifyContainerFacade';
+import { IObfuscatedCode } from '../../../../../src/interfaces/source-code/IObfuscatedCode';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
 
-import { DomainLockNodeTemplate } from '../../../../src/templates/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate';
-import { GlobalVariableTemplate1 } from '../../../../src/templates/GlobalVariableTemplate1';
+import { DomainLockNodeTemplate } from '../../../../../src/custom-nodes/domain-lock-nodes/templates/DomainLockNodeTemplate';
+import { GlobalVariableTemplate1 } from '../../../../../src/custom-nodes/common/templates/GlobalVariableTemplate1';
 
-import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
-import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
-import { readFileAsString } from '../../../helpers/readFileAsString';
+import { InversifyContainerFacade } from '../../../../../src/container/InversifyContainerFacade';
+import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
+import { readFileAsString } from '../../../../helpers/readFileAsString';
 
 /**
  * @param {string} currentDomain

+ 0 - 0
test/functional-tests/templates/domain-lock-nodes/fixtures/prevailing-kind-of-variables-const.js → test/functional-tests/custom-nodes/domain-lock-nodes/templates/fixtures/prevailing-kind-of-variables-const.js


+ 0 - 0
test/functional-tests/templates/domain-lock-nodes/fixtures/prevailing-kind-of-variables-let.js → test/functional-tests/custom-nodes/domain-lock-nodes/templates/fixtures/prevailing-kind-of-variables-let.js


+ 0 - 0
test/functional-tests/templates/domain-lock-nodes/fixtures/prevailing-kind-of-variables-var.js → test/functional-tests/custom-nodes/domain-lock-nodes/templates/fixtures/prevailing-kind-of-variables-var.js


+ 15 - 15
test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/StringArrayCallsWrapperNodeTemplate.spec.ts → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper-node-template/StringArrayCallsWrapperNodeTemplate.spec.ts

@@ -4,25 +4,25 @@ import format from 'string-template';
 
 import { assert } from 'chai';
 
-import { ServiceIdentifiers } from '../../../../../src/container/ServiceIdentifiers';
+import { ServiceIdentifiers } from '../../../../../../src/container/ServiceIdentifiers';
 
-import { ICryptUtils } from '../../../../../src/interfaces/utils/ICryptUtils';
-import { IInversifyContainerFacade } from '../../../../../src/interfaces/container/IInversifyContainerFacade';
-import { IObfuscatedCode } from '../../../../../src/interfaces/source-code/IObfuscatedCode';
-import { IRandomGenerator } from '../../../../../src/interfaces/utils/IRandomGenerator';
+import { ICryptUtils } from '../../../../../../src/interfaces/utils/ICryptUtils';
+import { IInversifyContainerFacade } from '../../../../../../src/interfaces/container/IInversifyContainerFacade';
+import { IObfuscatedCode } from '../../../../../../src/interfaces/source-code/IObfuscatedCode';
+import { IRandomGenerator } from '../../../../../../src/interfaces/utils/IRandomGenerator';
 
-import { AtobTemplate } from '../../../../../src/templates/AtobTemplate';
-import { GlobalVariableTemplate1 } from '../../../../../src/templates/GlobalVariableTemplate1';
-import { Rc4Template } from '../../../../../src/templates/Rc4Template';
-import { StringArrayBase64DecodeNodeTemplate } from '../../../../../src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate';
-import { StringArrayCallsWrapperTemplate } from '../../../../../src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate';
-import { StringArrayRc4DecodeNodeTemplate } from '../../../../../src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate';
+import { AtobTemplate } from '../../../../../../src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/AtobTemplate';
+import { GlobalVariableTemplate1 } from '../../../../../../src/custom-nodes/common/templates/GlobalVariableTemplate1';
+import { Rc4Template } from '../../../../../../src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/Rc4Template';
+import { StringArrayBase64DecodeNodeTemplate } from '../../../../../../src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate';
+import { StringArrayCallsWrapperTemplate } from '../../../../../../src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate';
+import { StringArrayRc4DecodeNodeTemplate } from '../../../../../../src/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
 
-import { InversifyContainerFacade } from '../../../../../src/container/InversifyContainerFacade';
-import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
-import { readFileAsString } from '../../../../helpers/readFileAsString';
+import { InversifyContainerFacade } from '../../../../../../src/container/InversifyContainerFacade';
+import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
+import { readFileAsString } from '../../../../../helpers/readFileAsString';
 
 describe('StringArrayCallsWrapperNodeTemplate', () => {
     const stringArrayName: string = 'stringArrayName';

+ 0 - 0
test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-const.js → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-const.js


+ 0 - 0
test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-let.js → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-let.js


+ 0 - 0
test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-var.js → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-var.js


+ 4 - 4
test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts

@@ -2,12 +2,12 @@ import 'reflect-metadata';
 
 import { assert } from 'chai';
 
-import { IObfuscatedCode } from '../../../../../src/interfaces/source-code/IObfuscatedCode';
+import { IObfuscatedCode } from '../../../../../../src/interfaces/source-code/IObfuscatedCode';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
 
-import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
-import { readFileAsString } from '../../../../helpers/readFileAsString';
+import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
+import { readFileAsString } from '../../../../../helpers/readFileAsString';
 
 describe('StringArrayRotateFunctionTemplate', () => {
     describe('Prevailing kind of variables', () => {

+ 0 - 0
test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-const.js → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-const.js


+ 0 - 0
test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-let.js → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-let.js


+ 0 - 0
test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-var.js → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-var.js


+ 4 - 4
test/functional-tests/templates/string-array-nodes/string-array-template/StringArrayTemplate.spec.ts → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-template/StringArrayTemplate.spec.ts

@@ -2,12 +2,12 @@ import 'reflect-metadata';
 
 import { assert } from 'chai';
 
-import { IObfuscatedCode } from '../../../../../src/interfaces/source-code/IObfuscatedCode';
+import { IObfuscatedCode } from '../../../../../../src/interfaces/source-code/IObfuscatedCode';
 
-import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
 
-import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
-import { readFileAsString } from '../../../../helpers/readFileAsString';
+import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
+import { readFileAsString } from '../../../../../helpers/readFileAsString';
 
 describe('StringArrayTemplate', () => {
     describe('Prevailing kind of variables', () => {

+ 0 - 0
test/functional-tests/templates/string-array-nodes/string-array-template/fixtures/prevailing-kind-of-variables-const.js → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-template/fixtures/prevailing-kind-of-variables-const.js


+ 0 - 0
test/functional-tests/templates/string-array-nodes/string-array-template/fixtures/prevailing-kind-of-variables-let.js → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-template/fixtures/prevailing-kind-of-variables-let.js


+ 0 - 0
test/functional-tests/templates/string-array-nodes/string-array-template/fixtures/prevailing-kind-of-variables-var.js → test/functional-tests/custom-nodes/string-array-nodes/templates/string-array-template/fixtures/prevailing-kind-of-variables-var.js


+ 165 - 5
test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/MangledIdentifierNamesGenerator.spec.ts

@@ -78,6 +78,7 @@ describe('MangledIdentifierNamesGenerator', () => {
         describe('Variant #2: should not generate same prefixed name for identifier in code as prefixed name of string array', () => {
             describe('Variant #1: `renameGlobals` option is disabled', () => {
                 const stringArrayStorageRegExp: RegExp = /const aa *= *\['abc', *'last'];/;
+                const functionDeclarationIdentifierNameRegExp: RegExp = /function foo *\(\) *{/;
                 const lastVariableDeclarationIdentifierNameRegExp: RegExp = /const ac *= *ab\('0x1'\);/;
 
                 let obfuscatedCode: string;
@@ -98,18 +99,23 @@ describe('MangledIdentifierNamesGenerator', () => {
                     ).getObfuscatedCode();
                 });
 
-                it('Match #1: should generate correct identifier for string array', () => {
+                it('Match #1: should generate correct identifier name for string array', () => {
                     assert.match(obfuscatedCode, stringArrayStorageRegExp);
                 });
 
-                it('Match #2: should keep identifier name for last variable declaration', () => {
+                it('Match #2: should keep identifier name for function declaration', () => {
+                    assert.match(obfuscatedCode, functionDeclarationIdentifierNameRegExp);
+                });
+
+                it('Match #3: should keep identifier name for last variable declaration', () => {
                     assert.match(obfuscatedCode, lastVariableDeclarationIdentifierNameRegExp);
                 });
             });
 
             describe('Variant #2: `renameGlobals` option is enabled', () => {
                 const stringArrayStorageRegExp: RegExp = /const aa *= *\['abc', *'last'];/;
-                const lastVariableDeclarationIdentifierNameRegExp: RegExp = /const ae *= *ab\('0x1'\);/;
+                const functionDeclarationIdentifierNameRegExp: RegExp = /function ac *\(\) *{/;
+                const lastVariableDeclarationIdentifierNameRegExp: RegExp = /const ad *= *ab\('0x1'\);/;
 
                 let obfuscatedCode: string;
 
@@ -130,14 +136,168 @@ describe('MangledIdentifierNamesGenerator', () => {
                     ).getObfuscatedCode();
                 });
 
-                it('Match #1: should generate correct identifier for string array', () => {
+                it('Match #1: should generate correct identifier name for string array', () => {
                     assert.match(obfuscatedCode, stringArrayStorageRegExp);
                 });
 
-                it('Match #2: should keep identifier name for last variable declaration', () => {
+                it('Match #2: should generate correct identifier name for function declaration', () => {
+                    assert.match(obfuscatedCode, functionDeclarationIdentifierNameRegExp);
+                });
+
+                it('Match #3: should keep identifier name for last variable declaration', () => {
                     assert.match(obfuscatedCode, lastVariableDeclarationIdentifierNameRegExp);
                 });
             });
         });
     });
+
+    describe('generateForLexicalScope', () => {
+        describe('Variant #1: Should generate different names set for different lexical scopes', () => {
+            describe('Variant #1: `renameGlobals` option is disabled', () => {
+                const variableIdentifierRegExp: RegExp = /var foo *= *'abc';/;
+                const functionDeclarationRegExp1: RegExp = /function bar *\(a, *b\) *{}/;
+                const functionDeclarationRegExp2: RegExp = /function baz *\(a, *b\) *{}/;
+
+                let obfuscatedCode: string;
+
+                before(() => {
+                    const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-1.js');
+
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        code,
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('Match #1: should keep identifier name for variable declaration', () => {
+                    assert.match(obfuscatedCode, variableIdentifierRegExp);
+                });
+
+                it('Match #2: should generate valid identifier names for function', () => {
+                    assert.match(obfuscatedCode, functionDeclarationRegExp1);
+                });
+
+                it('Match #3: should generate valid identifier names for function', () => {
+                    assert.match(obfuscatedCode, functionDeclarationRegExp2);
+                });
+            });
+
+            describe('Variant #2: `renameGlobals` option is enabled', () => {
+                const variableIdentifierRegExp: RegExp = /var a *= *'abc';/;
+                const functionDeclarationRegExp1: RegExp = /function b *\(d, *e\) *{}/;
+                const functionDeclarationRegExp2: RegExp = /function c *\(d, *e\) *{}/;
+
+                let obfuscatedCode: string;
+
+                before(() => {
+                    const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-1.js');
+
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        code,
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
+                            renameGlobals: true
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('Match #1: should generate valid identifier name for variable declaration', () => {
+                    assert.match(obfuscatedCode, variableIdentifierRegExp);
+                });
+
+                it('Match #2: should generate valid identifier names for function', () => {
+                    assert.match(obfuscatedCode, functionDeclarationRegExp1);
+                });
+
+                it('Match #3: should generate valid identifier names for function', () => {
+                    assert.match(obfuscatedCode, functionDeclarationRegExp2);
+                });
+            });
+        });
+
+        describe('Variant #2: Should generate different names set for different lexical scopes when string array is enabled', () => {
+            describe('Variant #1: `renameGlobals` option is disabled', () => {
+                const stringArrayIdentifierRegExp: RegExp = /var a *= *\['abc'];/;
+                const variableIdentifierRegExp: RegExp = /var foo *= *b\('0x0'\);/;
+                const functionDeclarationRegExp1: RegExp = /function bar *\(c, *d\) *{}/;
+                const functionDeclarationRegExp2: RegExp = /function baz *\(c, *d\) *{}/;
+
+                let obfuscatedCode: string;
+
+                before(() => {
+                    const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-1.js');
+
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        code,
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
+                            stringArray: true,
+                            stringArrayThreshold: 1
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('Match #1: should generate valid identifier names for string array', () => {
+                    assert.match(obfuscatedCode, stringArrayIdentifierRegExp);
+                });
+
+                it('Match #2: should keep identifier name for variable declaration', () => {
+                    assert.match(obfuscatedCode, variableIdentifierRegExp);
+                });
+
+                it('Match #3: should generate valid identifier names for function', () => {
+                    assert.match(obfuscatedCode, functionDeclarationRegExp1);
+                });
+
+                it('Match #4: should generate valid identifier names for function', () => {
+                    assert.match(obfuscatedCode, functionDeclarationRegExp2);
+                });
+            });
+
+            describe('Variant #2: `renameGlobals` option is enabled', () => {
+                const stringArrayIdentifierRegExp: RegExp = /var a *= *\['abc'];/;
+                const variableIdentifierRegExp: RegExp = /var c *= *b\('0x0'\);/;
+                const functionDeclarationRegExp1: RegExp = /function d *\(f, *g\) *{}/;
+                const functionDeclarationRegExp2: RegExp = /function e *\(f, *g\) *{}/;
+
+                let obfuscatedCode: string;
+
+                before(() => {
+                    const code: string = readFileAsString(__dirname + '/fixtures/lexical-block-scope-identifiers-1.js');
+
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        code,
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
+                            renameGlobals: true,
+                            stringArray: true,
+                            stringArrayThreshold: 1
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('Match #1: should generate valid identifier names for string array', () => {
+                    assert.match(obfuscatedCode, stringArrayIdentifierRegExp);
+                });
+
+                it('Match #2: should generate valid identifier name for variable declaration', () => {
+                    assert.match(obfuscatedCode, variableIdentifierRegExp);
+                });
+
+                it('Match #3: should generate valid identifier names for function', () => {
+                    assert.match(obfuscatedCode, functionDeclarationRegExp1);
+                });
+
+                it('Match #4: should generate valid identifier names for function', () => {
+                    assert.match(obfuscatedCode, functionDeclarationRegExp2);
+                });
+            });
+        });
+    });
 });

+ 3 - 0
test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/fixtures/lexical-block-scope-identifiers-1.js

@@ -0,0 +1,3 @@
+var foo = 'abc';
+function bar (bar1, bar2) {}
+function baz (baz1, baz2) {}

+ 3 - 1
test/functional-tests/generators/identifier-names-generators/mangled-identifier-names-generator/fixtures/string-array-storage-name-conflict-2.js

@@ -59,5 +59,7 @@ function foo () {
     const test32 = 'abc';
     const test33 = 'abc';
     const test34 = 'abc';
-    const test35 = 'last';
+    const test35 = 'abc';
+    const test36 = 'abc';
+    const test38 = 'last';
 }

+ 8 - 8
test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec.ts

@@ -482,15 +482,15 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => {
             });
         });
 
-        describe('Variant #3: already renamed identifiers shouldn\'t be renamed twice', () => {
-            const classDeclarationRegExp: RegExp = /class *b *{/;
-            const variableDeclarationsRegExp: RegExp = /let c, *d, *e, *f;/;
-            const classReferenceRegExp: RegExp = /new b\(\);/;
+        describe('Variant #3: preserved identifier names shouldn\'t be used as identifier names', () => {
+            const classDeclarationRegExp: RegExp = /class *e *{/;
+            const variableDeclarationsRegExp: RegExp = /let f, *g, *h, *i;/;
+            const classReferenceRegExp: RegExp = /new e\(\);/;
 
             let obfuscatedCode: string;
 
             before(() => {
-                const code: string = readFileAsString(__dirname + '/fixtures/prevent-renaming-of-renamed-identifiers.js');
+                const code: string = readFileAsString(__dirname + '/fixtures/prevent-using-of-preserved-identifiers.js');
 
                 obfuscatedCode = JavaScriptObfuscator.obfuscate(
                     code,
@@ -501,15 +501,15 @@ describe('ScopeIdentifiersTransformer ClassDeclaration identifiers', () => {
                 ).getObfuscatedCode();
             });
 
-            it('Match #1: shouldn\'t rename twice class declaration name', () => {
+            it('Match #1: shouldn\'t use preserved identifier name as class declaration name', () => {
                 assert.match(obfuscatedCode, classDeclarationRegExp);
             });
 
-            it('Match #2: should correctly rename variable declarations', () => {
+            it('Match #2: shouldn\'t use preserved identifier name as variable declarations', () => {
                 assert.match(obfuscatedCode, variableDeclarationsRegExp);
             });
 
-            it('Match #3: should correctly rename class reference identifier', () => {
+            it('Match #3: shouldn\'t use preserved identifier name as class reference identifier', () => {
                 assert.match(obfuscatedCode, classReferenceRegExp);
             });
         });

+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/prevent-renaming-of-renamed-identifiers.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/fixtures/prevent-using-of-preserved-identifiers.js


+ 6 - 6
test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec.ts

@@ -143,15 +143,15 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => {
             });
         });
 
-        describe('Variant #5: already renamed identifiers shouldn\'t be renamed twice', () => {
+        describe('Variant #5: preserved identifier names shouldn\'t be used as identifier names', () => {
             describe('Variant #1', () => {
-                const functionDeclarationRegExp: RegExp = /function *a\(\) *{/;
-                const variableDeclarationsRegExp: RegExp = /let c, *d, *e, *f;/;
+                const functionDeclarationRegExp: RegExp = /function *e\(\) *{/;
+                const variableDeclarationsRegExp: RegExp = /let f, *g, *h, *i;/;
 
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/prevent-renaming-of-renamed-identifiers-1.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/prevent-using-of-preserved-identifiers-1.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -162,11 +162,11 @@ describe('ScopeIdentifiersTransformer FunctionDeclaration identifiers', () => {
                     ).getObfuscatedCode();
                 });
 
-                it('Match #1: shouldn\'t rename twice function declaration name', () => {
+                it('Match #1: shouldn\'t use preserved identifier name as function declaration name', () => {
                     assert.match(obfuscatedCode, functionDeclarationRegExp);
                 });
 
-                it('Match #2: should correctly rename variable declarations', () => {
+                it('Match #2: shouldn\'t use preserved identifier name as variable declarations', () => {
                     assert.match(obfuscatedCode, variableDeclarationsRegExp);
                 });
             });

+ 0 - 0
test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/prevent-renaming-of-renamed-identifiers-1.js → test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/fixtures/prevent-using-of-preserved-identifiers-1.js


+ 18 - 18
test/functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec.ts

@@ -454,18 +454,18 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => {
         });
     });
 
-    describe('Variant #13: already renamed identifiers shouldn\'t be renamed twice', () => {
+    describe('Variant #13: preserved identifier names shouldn\'t be used as identifier names', () => {
         describe('Variant #1', () => {
-            const variableDeclarationRegExp: RegExp = /var b *= *0x1;/;
-            const functionDeclarationRegExp1: RegExp = /function *c *\(\) *{}/;
-            const functionDeclarationRegExp2: RegExp = /function *d *\(\) *{}/;
-            const functionDeclarationRegExp3: RegExp = /function *e *\(\) *{}/;
-            const functionDeclarationRegExp4: RegExp = /function *f *\(\) *{}/;
+            const variableDeclarationRegExp: RegExp = /var e *= *0x1;/;
+            const functionDeclarationRegExp1: RegExp = /function *f *\(\) *{}/;
+            const functionDeclarationRegExp2: RegExp = /function *g *\(\) *{}/;
+            const functionDeclarationRegExp3: RegExp = /function *h *\(\) *{}/;
+            const functionDeclarationRegExp4: RegExp = /function *i *\(\) *{}/;
 
             let obfuscatedCode: string;
 
             before(() => {
-                const code: string = readFileAsString(__dirname + '/fixtures/prevent-renaming-of-renamed-identifiers-1.js');
+                const code: string = readFileAsString(__dirname + '/fixtures/prevent-using-of-preserved-identifiers-1.js');
 
                 obfuscatedCode = JavaScriptObfuscator.obfuscate(
                     code,
@@ -476,23 +476,23 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => {
                 ).getObfuscatedCode();
             });
 
-            it('Match #1: shouldn\'t rename twice variable declaration name', () => {
+            it('Match #1: shouldn\'t use preserved identifier name as variable declaration name', () => {
                 assert.match(obfuscatedCode, variableDeclarationRegExp);
             });
 
-            it('Match #2: should correctly rename function declaration name', () => {
+            it('Match #2: shouldn\'t use preserved identifier name as function declaration name', () => {
                 assert.match(obfuscatedCode, functionDeclarationRegExp1);
             });
 
-            it('Match #3: should correctly rename function declaration name', () => {
+            it('Match #3: shouldn\'t use preserved identifier name as function declaration name', () => {
                 assert.match(obfuscatedCode, functionDeclarationRegExp2);
             });
 
-            it('Match #4: should correctly rename function declaration name', () => {
+            it('Match #4: shouldn\'t use preserved identifier name as function declaration name', () => {
                 assert.match(obfuscatedCode, functionDeclarationRegExp3);
             });
 
-            it('Match #5: should correctly rename function declaration name', () => {
+            it('Match #5: shouldn\'t use preserved identifier name as function declaration name', () => {
                 assert.match(obfuscatedCode, functionDeclarationRegExp4);
             });
         });
@@ -501,12 +501,12 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => {
             const variableDeclarationRegExp1: RegExp = /var b *= *0x1;/;
             const variableDeclarationRegExp2: RegExp = /var c;/;
             const functionDeclarationRegExp: RegExp = /function *d *\(\) *{/;
-            const variableDeclarationRegExp3: RegExp = /var e *= *function *\(\) *{}/;
+            const variableDeclarationRegExp3: RegExp = /var f *= *function *\(\) *{}/;
 
             let obfuscatedCode: string;
 
             before(() => {
-                const code: string = readFileAsString(__dirname + '/fixtures/prevent-renaming-of-renamed-identifiers-2.js');
+                const code: string = readFileAsString(__dirname + '/fixtures/prevent-using-of-preserved-identifiers-2.js');
 
                 obfuscatedCode = JavaScriptObfuscator.obfuscate(
                     code,
@@ -517,19 +517,19 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => {
                 ).getObfuscatedCode();
             });
 
-            it('Match #1: shouldn\'t rename twice variable declaration name', () => {
+            it('Match #1: shouldn\'t use preserved identifier name as variable declaration name', () => {
                 assert.match(obfuscatedCode, variableDeclarationRegExp1);
             });
 
-            it('Match #2: shouldn\'t rename twice variable declaration name', () => {
+            it('Match #2: shouldn\'t use preserved identifier name as variable declaration name', () => {
                 assert.match(obfuscatedCode, variableDeclarationRegExp2);
             });
 
-            it('Match #3: should correctly rename function declaration name', () => {
+            it('Match #3: shouldn\'t use preserved identifier name as function declaration name', () => {
                 assert.match(obfuscatedCode, functionDeclarationRegExp);
             });
 
-            it('Match #4: should correctly rename variable declaration name', () => {
+            it('Match #4: shouldn\'t use preserved identifier name as variable declaration name', () => {
                 assert.match(obfuscatedCode, variableDeclarationRegExp3);
             });
         });

部分文件因文件數量過多而無法顯示