Просмотр исходного кода

Merge pull request #133 from javascript-obfuscator/minification

Identifier name generators: Hexadecimal and Mangled
Timofey Kachalov 7 лет назад
Родитель
Сommit
5fb3320641
63 измененных файлов с 682 добавлено и 177 удалено
  1. 5 1
      CHANGELOG.md
  2. 0 0
      dist/index.js
  3. 1 2
      package.json
  4. 0 5
      src/JavaScriptObfuscator.ts
  5. 2 0
      src/container/InversifyContainerFacade.ts
  6. 2 1
      src/container/ServiceIdentifiers.ts
  7. 1 0
      src/container/modules/custom-nodes/CustomNodesModule.ts
  8. 58 0
      src/container/modules/generators/GeneratorsModule.ts
  9. 4 1
      src/container/modules/storages/StoragesModule.ts
  10. 11 0
      src/custom-nodes/AbstractCustomNode.ts
  11. 13 2
      src/custom-nodes/AbstractCustomNodeGroup.ts
  12. 6 2
      src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts
  13. 6 2
      src/custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup.ts
  14. 5 1
      src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts
  15. 5 1
      src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts
  16. 5 1
      src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts
  17. 5 1
      src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts
  18. 5 1
      src/custom-nodes/control-flow-flattening-nodes/StringLiteralNode.ts
  19. 5 1
      src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts
  20. 5 1
      src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts
  21. 5 1
      src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts
  22. 5 1
      src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts
  23. 5 1
      src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts
  24. 5 1
      src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts
  25. 5 1
      src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts
  26. 7 3
      src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts
  27. 6 2
      src/custom-nodes/domain-lock-nodes/DomainLockNode.ts
  28. 6 2
      src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts
  29. 6 1
      src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts
  30. 7 2
      src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts
  31. 6 2
      src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts
  32. 6 1
      src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts
  33. 5 1
      src/custom-nodes/string-array-nodes/StringArrayNode.ts
  34. 8 3
      src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts
  35. 8 6
      src/custom-nodes/string-array-nodes/group/StringArrayCustomNodeGroup.ts
  36. 0 5
      src/declarations/esmangle.d.ts
  37. 4 0
      src/enums/generators/identifier-name-generators/IdentifierNameGenerator.ts
  38. 37 0
      src/generators/identifier-name-generators/AbstractIdentifierNameGenerator.ts
  39. 48 0
      src/generators/identifier-name-generators/HexadecimalIdentifierNameGenerator.ts
  40. 116 0
      src/generators/identifier-name-generators/MangledIdentifierNameGenerator.ts
  41. 7 0
      src/interfaces/generators/identifier-name-generators/IIdentifierNameGenerator.d.ts
  42. 0 13
      src/interfaces/node-transformers/dead-code-injection-transformers/IDeadCodeInjectionReplacer.d.ts
  43. 0 6
      src/interfaces/utils/IRandomGenerator.d.ts
  44. 12 9
      src/node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer.ts
  45. 1 2
      src/node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/StringLiteralObfuscatingReplacer.ts
  46. 10 1
      src/storages/ArrayStorage.ts
  47. 10 1
      src/storages/MapStorage.ts
  48. 5 2
      src/storages/control-flow/ControlFlowStorage.ts
  49. 4 1
      src/storages/custom-node-group/CustomNodeGroupStorage.ts
  50. 21 4
      src/storages/string-array/StringArrayStorage.ts
  51. 2 2
      src/templates/debug-protection-nodes/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate.ts
  52. 5 0
      src/types/container/TInversifyContainerModuleFactory.d.ts
  53. 4 0
      src/types/container/generators/TIdentifierNameGeneratorFactory.d.ts
  54. 0 28
      src/utils/RandomGenerator.ts
  55. 1 2
      test/dev/dev.ts
  56. 1 1
      test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts
  57. 1 1
      test/functional-tests/templates/custom-nodes/debug-protection-nodes/DebufProtectionFunctionCallTemplate.spec.ts
  58. 2 1
      test/index.spec.ts
  59. 52 0
      test/unit-tests/generators/identifier-name-generators/HexadecimalIdentifierNameGenerator.spec.ts
  60. 95 0
      test/unit-tests/generators/identifier-name-generators/MangledlIdentifierNameGenerator.spec.ts
  61. 5 1
      test/unit-tests/storages/ArrayStorage.spec.ts
  62. 5 1
      test/unit-tests/storages/MapStorage.spec.ts
  63. 0 45
      test/unit-tests/utils/RandomGeneratorUtils.spec.ts

+ 5 - 1
CHANGELOG.md

@@ -1,8 +1,12 @@
 Change Log
 ===
+v0.13.0
+---
+* Implemented custom `mangle` option algorithm without `esmangle`; fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/110
+
 v0.12.5
 ---
-* https://github.com/javascript-obfuscator/javascript*-obfuscator/issues/139
+* https://github.com/javascript-obfuscator/javascript-obfuscator/issues/139
 
 v0.12.4
 ---

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
dist/index.js


+ 1 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "javascript-obfuscator",
-  "version": "0.12.5",
+  "version": "0.13.0-dev.0",
   "description": "JavaScript obfuscator",
   "keywords": [
     "obfuscator",
@@ -24,7 +24,6 @@
     "class-validator": "0.7.3",
     "commander": "2.12.2",
     "escodegen-wallaby": "1.6.15",
-    "esmangle": "1.0.1",
     "esprima": "4.0.0",
     "estraverse": "4.2.0",
     "inversify": "4.5.2",

+ 0 - 5
src/JavaScriptObfuscator.ts

@@ -3,7 +3,6 @@ import { ServiceIdentifiers } from './container/ServiceIdentifiers';
 
 import * as esprima from 'esprima';
 import * as escodegen from 'escodegen-wallaby';
-import * as esmangle from 'esmangle';
 import * as ESTree from 'estree';
 
 import { ICustomNodeGroup } from './interfaces/custom-nodes/ICustomNodeGroup';
@@ -270,10 +269,6 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
             escodegenParams.sourceContent = sourceCode;
         }
 
-        if (this.options.mangle) {
-            astTree = esmangle.mangle(astTree);
-        }
-
         const generatorOutput: IGeneratorOutput = escodegen.generate(astTree, {
             ...escodegenParams,
             format: {

+ 2 - 0
src/container/InversifyContainerFacade.ts

@@ -5,6 +5,7 @@ import { analyzersModule } from './modules/analyzers/AnalyzersModule';
 import { controlFlowTransformersModule } from './modules/node-transformers/ControlFlowTransformersModule';
 import { convertingTransformersModule } from './modules/node-transformers/ConvertingTransformersModule';
 import { customNodesModule } from './modules/custom-nodes/CustomNodesModule';
+import { generatorsModule } from './modules/generators/GeneratorsModule';
 import { nodeTransformersModule } from './modules/node-transformers/NodeTransformersModule';
 import { obfuscatingTransformersModule } from './modules/node-transformers/ObfuscatingTransformersModule';
 import { preparingTransformersModule } from './modules/node-transformers/PreparingTransformersModule';
@@ -197,6 +198,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
         this.container.load(controlFlowTransformersModule);
         this.container.load(convertingTransformersModule);
         this.container.load(customNodesModule);
+        this.container.load(generatorsModule);
         this.container.load(nodeTransformersModule);
         this.container.load(obfuscatingTransformersModule);
         this.container.load(preparingTransformersModule);

+ 2 - 1
src/container/ServiceIdentifiers.ts

@@ -4,6 +4,7 @@ export enum ServiceIdentifiers {
     Factory__IControlFlowReplacer = 'Factory<IControlFlowReplacer>',
     Factory__ICustomNode = 'Factory<ICustomNode>',
     Factory__ICustomNodeGroup = 'Factory<ICustomNodeGroup>',
+    Factory__IIdentifierNameGenerator = 'Factory<IIdentifierNameGenerator>',
     Factory__IIdentifierObfuscatingReplacer = 'Factory<IIdentifierObfuscatingReplacer>',
     Factory__INodeGuard = 'Factory<INodeGuard>',
     Factory__INodeTransformer = 'Factory<INodeTransformer[]>',
@@ -16,8 +17,8 @@ export enum ServiceIdentifiers {
     ICustomNode = 'ICustomNode',
     ICustomNodeGroup = 'ICustomNodeGroup',
     IControlFlowReplacer = 'IControlFlowReplacer',
-    IDeadCodeInjectionReplacer = 'IDeadCodeInjectionReplacer',
     IEscapeSequenceEncoder = 'IEscapeSequenceEncoder',
+    IIdentifierNameGenerator = 'IIdentifierNameGenerator',
     IIdentifierObfuscatingReplacer = 'IIdentifierObfuscatingReplacer',
     IJavaScriptObfuscator = 'IJavaScriptObfuscator',
     ILogger = 'ILogger',

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

@@ -145,6 +145,7 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
         .toFactory<ICustomNode>(InversifyContainerFacade
             .getConstructorFactory<ControlFlowCustomNode, ICustomNode>(
                 ServiceIdentifiers.Newable__ICustomNode,
+                ServiceIdentifiers.Factory__IIdentifierNameGenerator,
                 ServiceIdentifiers.IRandomGenerator,
                 ServiceIdentifiers.IOptions
             ));

+ 58 - 0
src/container/modules/generators/GeneratorsModule.ts

@@ -0,0 +1,58 @@
+import { ContainerModule, interfaces } from 'inversify';
+import { ServiceIdentifiers } from '../../ServiceIdentifiers';
+
+import { IIdentifierNameGenerator } from '../../../interfaces/generators/identifier-name-generators/IIdentifierNameGenerator';
+import { IOptions } from '../../../interfaces/options/IOptions';
+
+import { IdentifierNameGenerator } from '../../../enums/generators/identifier-name-generators/IdentifierNameGenerator';
+
+import { HexadecimalIdentifierNameGenerator } from '../../../generators/identifier-name-generators/HexadecimalIdentifierNameGenerator';
+import { MangledIdentifierNameGenerator } from '../../../generators/identifier-name-generators/MangledIdentifierNameGenerator';
+
+export const generatorsModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
+    // identifier name generators
+    bind<IIdentifierNameGenerator>(ServiceIdentifiers.IIdentifierNameGenerator)
+        .to(HexadecimalIdentifierNameGenerator)
+        .inSingletonScope()
+        .whenTargetNamed(IdentifierNameGenerator.HexadecimalIdentifierNameGenerator);
+
+    bind<IIdentifierNameGenerator>(ServiceIdentifiers.IIdentifierNameGenerator)
+        .to(MangledIdentifierNameGenerator)
+        .inSingletonScope()
+        .whenTargetNamed(IdentifierNameGenerator.MangledIdentifierNameGenerator);
+
+    // identifier name generator factory
+    bind<IIdentifierNameGenerator>(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+        .toFactory<IIdentifierNameGenerator>((context: interfaces.Context): (options: IOptions) => IIdentifierNameGenerator => {
+            const cache: Map <boolean, IIdentifierNameGenerator> = new Map();
+
+            return (options: IOptions) => {
+                if (cache.has(options.mangle)) {
+                    return <IIdentifierNameGenerator>cache.get(options.mangle);
+                }
+
+                let identifierNameGenerator: IIdentifierNameGenerator;
+
+                switch (options.mangle) {
+                    case true:
+                        identifierNameGenerator = context.container.getNamed<IIdentifierNameGenerator>(
+                            ServiceIdentifiers.IIdentifierNameGenerator,
+                            IdentifierNameGenerator.MangledIdentifierNameGenerator
+                        );
+
+                        break;
+
+                    case false:
+                    default:
+                        identifierNameGenerator = context.container.getNamed<IIdentifierNameGenerator>(
+                            ServiceIdentifiers.IIdentifierNameGenerator,
+                            IdentifierNameGenerator.HexadecimalIdentifierNameGenerator
+                        );
+                }
+
+                cache.set(options.mangle, identifierNameGenerator);
+
+                return identifierNameGenerator;
+            };
+        });
+});

+ 4 - 1
src/container/modules/storages/StoragesModule.ts

@@ -5,6 +5,7 @@ import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage
 import { TCustomNodeGroupStorage } from '../../../types/storages/TCustomNodeGroupStorage';
 import { TStringArrayStorage } from '../../../types/storages/TStringArrayStorage';
 
+import { IOptions } from '../../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
 
 import { ControlFlowStorage } from '../../../storages/control-flow/ControlFlowStorage';
@@ -32,8 +33,10 @@ export const storagesModule: interfaces.ContainerModule = new ContainerModule((b
                     .get<interfaces.Newable<TControlFlowStorage>>(ServiceIdentifiers.Newable__TControlFlowStorage);
                 const randomGenerator: IRandomGenerator = context.container
                     .get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator);
+                const options: IOptions = context.container
+                    .get<IOptions>(ServiceIdentifiers.IOptions);
 
-                const storage: TControlFlowStorage = new constructor(randomGenerator);
+                const storage: TControlFlowStorage = new constructor(randomGenerator, options);
 
                 storage.initialize();
 

+ 11 - 0
src/custom-nodes/AbstractCustomNode.ts

@@ -1,9 +1,11 @@
 import { inject, injectable } from 'inversify';
 import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 
+import { TIdentifierNameGeneratorFactory } from '../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../types/node/TStatement';
 
 import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
+import { IIdentifierNameGenerator } from '../interfaces/generators/identifier-name-generators/IIdentifierNameGenerator';
 import { IOptions } from '../interfaces/options/IOptions';
 import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
 
@@ -32,6 +34,11 @@ export abstract class AbstractCustomNode implements ICustomNode {
      */
     protected cachedNode: TStatement[];
 
+    /**
+     * @type {IIdentifierNameGenerator}
+     */
+    protected readonly identifierNameGenerator: IIdentifierNameGenerator;
+
     /**
      * @type {IOptions}
      */
@@ -43,13 +50,17 @@ export abstract class AbstractCustomNode implements ICustomNode {
     protected readonly randomGenerator: IRandomGenerator;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
+        this.identifierNameGenerator = identifierNameGeneratorFactory(options);
         this.randomGenerator = randomGenerator;
         this.options = options;
     }

+ 13 - 2
src/custom-nodes/AbstractCustomNodeGroup.ts

@@ -1,10 +1,12 @@
 import { inject, injectable } from 'inversify';
 import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 
+import { TIdentifierNameGeneratorFactory } from '../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TNodeWithBlockStatement } from '../types/node/TNodeWithBlockStatement';
 
 import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
 import { ICustomNodeGroup } from '../interfaces/custom-nodes/ICustomNodeGroup';
+import { IIdentifierNameGenerator } from '../interfaces/generators/identifier-name-generators/IIdentifierNameGenerator';
 import { IOptions } from '../interfaces/options/IOptions';
 import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
 import { IStackTraceData } from '../interfaces/analyzers/stack-trace-analyzer/IStackTraceData';
@@ -25,9 +27,9 @@ export abstract class AbstractCustomNodeGroup implements ICustomNodeGroup {
     protected abstract customNodes: Map <CustomNode, ICustomNode>;
 
     /**
-     * @type {IStackTraceData[]}
+     * @type {IIdentifierNameGenerator}
      */
-    protected readonly stackTraceData: IStackTraceData[];
+    protected readonly identifierNameGenerator: IIdentifierNameGenerator;
 
     /**
      * @type {IOptions}
@@ -40,13 +42,22 @@ export abstract class AbstractCustomNodeGroup implements ICustomNodeGroup {
     protected readonly randomGenerator: IRandomGenerator;
 
     /**
+     * @type {IStackTraceData[]}
+     */
+    protected readonly stackTraceData: IStackTraceData[];
+
+    /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
+        this.identifierNameGenerator = identifierNameGeneratorFactory(options);
         this.randomGenerator = randomGenerator;
         this.options = options;
     }

+ 6 - 2
src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts

@@ -17,6 +17,7 @@ import { initializable } from '../../decorators/Initializable';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeUtils } from '../../node/NodeUtils';
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 
 @injectable()
 export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
@@ -27,14 +28,17 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
     private callsControllerFunctionName: string;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**
@@ -60,7 +64,7 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
             : GlobalVariableNoEvalTemplate();
 
         return format(ConsoleOutputDisableExpressionTemplate(), {
-            consoleLogDisableFunctionName: this.randomGenerator.getRandomVariableName(6),
+            consoleLogDisableFunctionName: this.identifierNameGenerator.generate(6),
             globalVariableTemplate,
             singleNodeCallControllerFunctionName: this.callsControllerFunctionName
         });

+ 6 - 2
src/custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup.ts

@@ -2,6 +2,7 @@ import { inject, injectable, } from 'inversify';
 import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 
 import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
+import { TIdentifierNameGeneratorFactory } from '../../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TNodeWithBlockStatement } from '../../../types/node/TNodeWithBlockStatement';
 
 import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -37,15 +38,18 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
 
     /**
      * @param {TCustomNodeFactory} customNodeFactory
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
         @inject(ServiceIdentifiers.Factory__ICustomNode) customNodeFactory: TCustomNodeFactory,
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
 
         this.customNodeFactory = customNodeFactory;
     }
@@ -88,7 +92,7 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = this.randomGenerator.getRandomVariableName(6);
+        const callsControllerFunctionName: string = this.identifierNameGenerator.generate(6);
 
         const consoleOutputDisableExpressionNode: ICustomNode = this.customNodeFactory(CustomNode.ConsoleOutputDisableExpressionNode);
         const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);

+ 5 - 1
src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import { BinaryOperator } from 'estree';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -23,14 +24,17 @@ export class BinaryExpressionFunctionNode extends AbstractCustomNode {
     private operator: BinaryOperator;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 5 - 1
src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as ESTree from 'estree';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -36,14 +37,17 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode
     private shuffledKeys: number[];
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 5 - 1
src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as ESTree from 'estree';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -23,14 +24,17 @@ export class CallExpressionFunctionNode extends AbstractCustomNode {
     private expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[];
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 5 - 1
src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import { LogicalOperator } from 'estree';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -23,14 +24,17 @@ export class LogicalExpressionFunctionNode extends AbstractCustomNode {
     private operator: LogicalOperator;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 5 - 1
src/custom-nodes/control-flow-flattening-nodes/StringLiteralNode.ts

@@ -1,6 +1,7 @@
 import { inject, injectable, } from 'inversify';
 import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -20,14 +21,17 @@ export class StringLiteralNode extends AbstractCustomNode {
     private literalValue: string;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 5 - 1
src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts

@@ -4,6 +4,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 import * as ESTree from 'estree';
 import { Expression } from 'estree';
 
+import { TIdentifierNameGeneratorFactory } from '../../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../../types/node/TStatement';
 
 import { IOptions } from '../../../interfaces/options/IOptions';
@@ -42,14 +43,17 @@ export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode
     private expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[];
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 5 - 1
src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 
 import * as ESTree from 'estree';
 
+import { TIdentifierNameGeneratorFactory } from '../../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../../types/node/TStatement';
 
 import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -25,14 +26,17 @@ export class ControlFlowStorageNode extends AbstractCustomNode {
     private controlFlowStorage: IStorage <ICustomNode>;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

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

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 
 import { Expression } from 'estree';
 
+import { TIdentifierNameGeneratorFactory } from '../../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../../types/node/TStatement';
 
 import { IOptions } from '../../../interfaces/options/IOptions';
@@ -41,14 +42,17 @@ export class ExpressionWithOperatorControlFlowStorageCallNode extends AbstractCu
     private rightValue: Expression;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 5 - 1
src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts

@@ -1,6 +1,7 @@
 import { inject, injectable, } from 'inversify';
 import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 
+import { TIdentifierNameGeneratorFactory } from '../../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../../types/node/TStatement';
 
 import { IOptions } from '../../../interfaces/options/IOptions';
@@ -27,14 +28,17 @@ export class StringLiteralControlFlowStorageCallNode extends AbstractCustomNode
     private controlFlowStorageName: string;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 5 - 1
src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as format from 'string-template';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -30,14 +31,17 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
     private debugProtectionFunctionName: string;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 5 - 1
src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as format from 'string-template';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -24,14 +25,17 @@ export class DebugProtectionFunctionIntervalNode extends AbstractCustomNode {
     private debugProtectionFunctionName: string;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

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

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as format from 'string-template';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -28,14 +29,17 @@ export class DebugProtectionFunctionNode extends AbstractCustomNode {
     private debugProtectionFunctionName: string;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 7 - 3
src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts

@@ -2,6 +2,7 @@ import { inject, injectable, } from 'inversify';
 import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 
 import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
+import { TIdentifierNameGeneratorFactory } from '../../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TNodeWithBlockStatement } from '../../../types/node/TNodeWithBlockStatement';
 
 import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -37,15 +38,18 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
 
     /**
      * @param {TCustomNodeFactory} customNodeFactory
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
         @inject(ServiceIdentifiers.Factory__ICustomNode) customNodeFactory: TCustomNodeFactory,
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
 
         this.customNodeFactory = customNodeFactory;
     }
@@ -101,8 +105,8 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const debugProtectionFunctionName: string = this.randomGenerator.getRandomVariableName(6);
-        const callsControllerFunctionName: string = this.randomGenerator.getRandomVariableName(6);
+        const debugProtectionFunctionName: string = this.identifierNameGenerator.generate(6);
+        const callsControllerFunctionName: string = this.identifierNameGenerator.generate(6);
 
         const debugProtectionFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionNode);
         const debugProtectionFunctionCallNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionCallNode);

+ 6 - 2
src/custom-nodes/domain-lock-nodes/DomainLockNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as format from 'string-template';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { ICryptUtils } from '../../interfaces/utils/ICryptUtils';
@@ -33,16 +34,19 @@ export class DomainLockNode extends AbstractCustomNode {
     private readonly cryptUtils: ICryptUtils;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {ICryptUtils} cryptUtils
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.ICryptUtils) cryptUtils: ICryptUtils,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
 
         this.cryptUtils = cryptUtils;
     }
@@ -75,7 +79,7 @@ export class DomainLockNode extends AbstractCustomNode {
             : GlobalVariableNoEvalTemplate();
 
         return format(DomainLockNodeTemplate(), {
-            domainLockFunctionName: this.randomGenerator.getRandomVariableName(6),
+            domainLockFunctionName: this.identifierNameGenerator.generate(6),
             diff: diff,
             domains: hiddenDomainsString,
             globalVariableTemplate,

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

@@ -2,6 +2,7 @@ import { inject, injectable, } from 'inversify';
 import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 
 import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
+import { TIdentifierNameGeneratorFactory } from '../../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TNodeWithBlockStatement } from '../../../types/node/TNodeWithBlockStatement';
 
 import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -37,15 +38,18 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
 
     /**
      * @param {TCustomNodeFactory} customNodeFactory
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
         @inject(ServiceIdentifiers.Factory__ICustomNode) customNodeFactory: TCustomNodeFactory,
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
 
         this.customNodeFactory = customNodeFactory;
     }
@@ -88,7 +92,7 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = this.randomGenerator.getRandomVariableName(6);
+        const callsControllerFunctionName: string = this.identifierNameGenerator.generate(6);
 
         const domainLockNode: ICustomNode = this.customNodeFactory(CustomNode.DomainLockNode);
         const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);

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

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as format from 'string-template';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -35,14 +36,17 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
     private appendEvent: ObfuscationEvent;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**
@@ -72,6 +76,7 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
                 }),
                 {
                     ...NO_CUSTOM_NODES_PRESET,
+                    mangle: this.options.mangle,
                     seed: this.options.seed
                 }
             ).getObfuscatedCode();

+ 7 - 2
src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as format from 'string-template';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
@@ -33,16 +34,19 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
     private callsControllerFunctionName: string;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
 
         this.escapeSequenceEncoder = escapeSequenceEncoder;
     }
@@ -67,11 +71,12 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
     protected getTemplate (): string {
         return JavaScriptObfuscator.obfuscate(
             format(SelfDefendingTemplate(this.escapeSequenceEncoder), {
-                selfDefendingFunctionName: this.randomGenerator.getRandomVariableName(6),
+                selfDefendingFunctionName: this.identifierNameGenerator.generate(6),
                 singleNodeCallControllerFunctionName: this.callsControllerFunctionName
             }),
             {
                 ...NO_CUSTOM_NODES_PRESET,
+                mangle: this.options.mangle,
                 seed: this.options.seed,
                 unicodeEscapeSequence: true
             }

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

@@ -2,6 +2,7 @@ import { inject, injectable, } from 'inversify';
 import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 
 import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
+import { TIdentifierNameGeneratorFactory } from '../../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TNodeWithBlockStatement } from '../../../types/node/TNodeWithBlockStatement';
 
 import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -37,15 +38,18 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
 
     /**
      * @param {TCustomNodeFactory} customNodeFactory
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
         @inject(ServiceIdentifiers.Factory__ICustomNode) customNodeFactory: TCustomNodeFactory,
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
 
         this.customNodeFactory = customNodeFactory;
     }
@@ -88,7 +92,7 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = this.randomGenerator.getRandomVariableName(6);
+        const callsControllerFunctionName: string = this.identifierNameGenerator.generate(6);
 
         const selfDefendingUnicodeNode: ICustomNode = this.customNodeFactory(CustomNode.SelfDefendingUnicodeNode);
         const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);

+ 6 - 1
src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as format from 'string-template';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
@@ -48,16 +49,19 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
     private stringArrayCallsWrapperName: string;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
 
         this.escapeSequenceEncoder = escapeSequenceEncoder;
     }
@@ -95,6 +99,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
             }),
             {
                 ...NO_CUSTOM_NODES_PRESET,
+                mangle: this.options.mangle,
                 seed: this.options.seed
             }
         ).getObfuscatedCode();

+ 5 - 1
src/custom-nodes/string-array-nodes/StringArrayNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as format from 'string-template';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -38,14 +39,17 @@ export class StringArrayNode extends AbstractCustomNode {
     private stringArrayRotateValue: number;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
     }
 
     /**

+ 8 - 3
src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts

@@ -3,6 +3,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as format from 'string-template';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TStatement } from '../../types/node/TStatement';
 
 import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
@@ -41,16 +42,19 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
     private stringArrayRotateValue: number;
 
     /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IRandomGenerator} randomGenerator
      * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
      * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
 
         this.escapeSequenceEncoder = escapeSequenceEncoder;
     }
@@ -78,8 +82,8 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
      * @returns {string}
      */
     protected getTemplate (): string {
-        const timesName: string = this.randomGenerator.getRandomVariableName(6);
-        const whileFunctionName: string = this.randomGenerator.getRandomVariableName(6);
+        const timesName: string = this.identifierNameGenerator.generate(6);
+        const whileFunctionName: string = this.identifierNameGenerator.generate(6);
 
         let code: string = '';
 
@@ -102,6 +106,7 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
             }),
             {
                 ...NO_CUSTOM_NODES_PRESET,
+                mangle: this.options.mangle,
                 seed: this.options.seed
             }
         ).getObfuscatedCode();

+ 8 - 6
src/custom-nodes/string-array-nodes/group/StringArrayCustomNodeGroup.ts

@@ -2,6 +2,7 @@ import { inject, injectable, } from 'inversify';
 import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
 
 import { TCustomNodeFactory } from '../../../types/container/custom-nodes/TCustomNodeFactory';
+import { TIdentifierNameGeneratorFactory } from '../../../types/container/generators/TIdentifierNameGeneratorFactory';
 import { TNodeWithBlockStatement } from '../../../types/node/TNodeWithBlockStatement';
 
 import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
@@ -17,7 +18,6 @@ import { ObfuscationEvent } from '../../../enums/event-emitters/ObfuscationEvent
 
 import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup';
 import { NodeAppender } from '../../../node/NodeAppender';
-import { Utils } from '../../../utils/Utils';
 
 @injectable()
 export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
@@ -45,17 +45,20 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
 
     /**
      * @param {TCustomNodeFactory} customNodeFactory
-     * @param {IRandomGenerator} randomGenerator
      * @param {IStorage<string>} stringArrayStorage
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
+     * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
      */
     constructor (
         @inject(ServiceIdentifiers.Factory__ICustomNode) customNodeFactory: TCustomNodeFactory,
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.TStringArrayStorage) stringArrayStorage: IStorage<string>,
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator, options);
+        super(identifierNameGeneratorFactory, randomGenerator, options);
 
         this.customNodeFactory = customNodeFactory;
         this.stringArrayStorage = stringArrayStorage;
@@ -99,8 +102,7 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
 
         const stringArrayStorageId: string = this.stringArrayStorage.getStorageId();
 
-        const stringArrayName: string = `_${Utils.hexadecimalPrefix}${stringArrayStorageId}`;
-        const stringArrayCallsWrapperName: string = `_${Utils.hexadecimalPrefix}${Utils.stringRotate(stringArrayStorageId, 1)}`;
+        const [stringArrayName, stringArrayCallsWrapperName]: string[] = stringArrayStorageId.split('|');
 
         let stringArrayRotateValue: number;
 

+ 0 - 5
src/declarations/esmangle.d.ts

@@ -1,5 +0,0 @@
-declare module "esmangle" {
-    import * as ESTree from 'estree';
-
-    function mangle (ast: ESTree.Program): ESTree.Program;
-}

+ 4 - 0
src/enums/generators/identifier-name-generators/IdentifierNameGenerator.ts

@@ -0,0 +1,4 @@
+export enum IdentifierNameGenerator {
+    HexadecimalIdentifierNameGenerator,
+    MangledIdentifierNameGenerator
+}

+ 37 - 0
src/generators/identifier-name-generators/AbstractIdentifierNameGenerator.ts

@@ -0,0 +1,37 @@
+import { inject, injectable } from 'inversify';
+import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
+
+import { IIdentifierNameGenerator } from '../../interfaces/generators/identifier-name-generators/IIdentifierNameGenerator';
+import { IOptions } from '../../interfaces/options/IOptions';
+import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
+
+@injectable()
+export abstract class AbstractIdentifierNameGenerator implements IIdentifierNameGenerator {
+    /**
+     * @type {IOptions}
+     */
+    protected readonly options: IOptions;
+
+    /**
+     * @type {IRandomGenerator}
+     */
+    protected readonly randomGenerator: IRandomGenerator;
+
+    /**
+     * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
+     */
+    constructor (
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
+    ) {
+        this.randomGenerator = randomGenerator;
+        this.options = options;
+    }
+
+    /**
+     * @param {number} length
+     * @returns {string}
+     */
+    public abstract generate (length: number): string;
+}

+ 48 - 0
src/generators/identifier-name-generators/HexadecimalIdentifierNameGenerator.ts

@@ -0,0 +1,48 @@
+import { inject, injectable } from 'inversify';
+import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
+
+import { IOptions } from '../../interfaces/options/IOptions';
+import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
+
+import { AbstractIdentifierNameGenerator } from './AbstractIdentifierNameGenerator';
+import { Utils } from '../../utils/Utils';
+
+@injectable()
+export class HexadecimalIdentifierNameGenerator extends AbstractIdentifierNameGenerator {
+    /**
+     * @type {Set<string>}
+     */
+    private readonly randomVariableNameSet: Set <string> = new Set();
+
+    /**
+     * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
+     */
+    constructor (
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
+    ) {
+        super(randomGenerator, options);
+    }
+
+    /**
+     * @param {number} length
+     * @returns {string}
+     */
+    public generate (length: number): string {
+        const prefix: string = `_${Utils.hexadecimalPrefix}`;
+        const rangeMinInteger: number = 10000;
+        const rangeMaxInteger: number = 99999999;
+        const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger);
+        const hexadecimalNumber: string = Utils.decToHex(randomInteger);
+        const randomVariableName: string = `${prefix}${hexadecimalNumber.substr(0, length)}`;
+
+        if (this.randomVariableNameSet.has(randomVariableName)) {
+            return this.generate(length);
+        }
+
+        this.randomVariableNameSet.add(randomVariableName);
+
+        return randomVariableName;
+    }
+}

+ 116 - 0
src/generators/identifier-name-generators/MangledIdentifierNameGenerator.ts

@@ -0,0 +1,116 @@
+import { inject, injectable } from 'inversify';
+import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
+
+import { IOptions } from '../../interfaces/options/IOptions';
+import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
+
+import { AbstractIdentifierNameGenerator } from './AbstractIdentifierNameGenerator';
+
+@injectable()
+export class MangledIdentifierNameGenerator extends AbstractIdentifierNameGenerator {
+    /**
+     * @type {string}
+     */
+    private static initMangledNameCharacter: string = '9';
+
+    /**
+     * @type {string[]}
+     */
+    private static nameSequence: string[] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
+
+    /**
+     * Reserved JS words with length of 2-4 symbols that can be possible generated with this replacer
+     *
+     * @type {string[]}
+     */
+    private static reservedNames: string[] = [
+        'byte', 'case', 'char', 'do', 'else', 'enum', 'eval', 'for', 'goto',
+        'if', 'in', 'int', 'let', 'long', 'new', 'null', 'this', 'true', 'try',
+        'var', 'void', 'with'
+    ];
+
+    /**
+     * @type {string}
+     */
+    private previousMangledName: string = MangledIdentifierNameGenerator.initMangledNameCharacter;
+
+    /**
+     * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
+     */
+    constructor (
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
+    ) {
+        super(randomGenerator, options);
+    }
+
+    /**
+     * @param {string} previousMangledName
+     * @returns {string}
+     */
+    private static generateNewMangledName (previousMangledName: string): string {
+        const generateNewMangledName: (name: string) => string = (name: string): string => {
+            const nameSequence: string[] = MangledIdentifierNameGenerator.nameSequence;
+            const zeroSequenceCache: string[] = [];
+
+            const zeroSequence: (num: number) => string = (num: number): string => {
+                let result: string = zeroSequenceCache[num];
+
+                if (result !== undefined) {
+                    return result;
+                }
+
+                result = '0'.repeat(num);
+                zeroSequenceCache[num] = result;
+
+                return result;
+            };
+
+            let cur: number = name.length - 1;
+
+            do {
+                let character: string, index: number;
+
+                character = name.charAt(cur);
+                index = nameSequence.indexOf(character);
+
+                if (index !== (nameSequence.length - 1)) {
+                    return name.substring(0, cur) + nameSequence[index + 1] + zeroSequence(name.length - (cur + 1));
+                }
+
+                --cur;
+            } while (cur >= 0);
+
+            return `a${zeroSequence(name.length)}`;
+        };
+
+        let newMangledName: string = generateNewMangledName(previousMangledName);
+
+        if (!MangledIdentifierNameGenerator.validateMangledName(newMangledName)) {
+            newMangledName = MangledIdentifierNameGenerator.generateNewMangledName(newMangledName);
+        }
+
+        return newMangledName;
+    }
+
+    /**
+     * @param {string} mangledName
+     * @returns {boolean}
+     */
+    private static validateMangledName (mangledName: string): boolean {
+        return !MangledIdentifierNameGenerator.reservedNames.includes(mangledName);
+    }
+
+    /**
+     * @param {number} length
+     * @returns {string}
+     */
+    public generate (length: number): string {
+        const newName: string = MangledIdentifierNameGenerator.generateNewMangledName(this.previousMangledName);
+
+        this.previousMangledName = newName;
+
+        return newName;
+    }
+}

+ 7 - 0
src/interfaces/generators/identifier-name-generators/IIdentifierNameGenerator.d.ts

@@ -0,0 +1,7 @@
+export interface IIdentifierNameGenerator {
+    /**
+     * @param {number} length
+     * @returns {string}
+     */
+    generate (length: number): string;
+}

+ 0 - 13
src/interfaces/node-transformers/dead-code-injection-transformers/IDeadCodeInjectionReplacer.d.ts

@@ -1,13 +0,0 @@
-import * as ESTree from 'estree';
-
-export interface IDeadCodeInjectionReplacer {
-    /**
-     * @param node
-     * @param parentNode
-     * @returns ESTree.Node
-     */
-    replace (
-        node: ESTree.Node,
-        parentNode: ESTree.Node
-    ): ESTree.Node;
-}

+ 0 - 6
src/interfaces/utils/IRandomGenerator.d.ts

@@ -32,12 +32,6 @@ export interface IRandomGenerator {
      */
     getRandomString (length: number, pool?: string): string;
 
-    /**
-     * @param length
-     * @returns {string}
-     */
-    getRandomVariableName (length: number): string;
-
     /**
      * @returns {number}
      */

+ 12 - 9
src/node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer.ts

@@ -3,9 +3,11 @@ import { ServiceIdentifiers } from '../../../../container/ServiceIdentifiers';
 
 import * as ESTree from 'estree';
 
+import { TIdentifierNameGeneratorFactory } from '../../../../types/container/generators/TIdentifierNameGeneratorFactory';
+
+import { IIdentifierNameGenerator } from '../../../../interfaces/generators/identifier-name-generators/IIdentifierNameGenerator';
 import { IIdentifierObfuscatingReplacer } from '../../../../interfaces/node-transformers/obfuscating-transformers/obfuscating-replacers/IIdentifierObfuscatingReplacer';
 import { IOptions } from '../../../../interfaces/options/IOptions';
-import { IRandomGenerator } from '../../../../interfaces/utils/IRandomGenerator';
 
 import { AbstractObfuscatingReplacer } from '../AbstractObfuscatingReplacer';
 import { Nodes } from '../../../../node/Nodes';
@@ -13,26 +15,27 @@ import { Nodes } from '../../../../node/Nodes';
 @injectable()
 export class BaseIdentifierObfuscatingReplacer extends AbstractObfuscatingReplacer implements IIdentifierObfuscatingReplacer {
     /**
-     * @type {Map<string, string>}
+     * @type {IIdentifierNameGenerator}
      */
-    private readonly namesMap: Map<string, string> = new Map();
+    private readonly identifierNameGenerator: IIdentifierNameGenerator;
 
     /**
-     * @type {IRandomGenerator}
+     * @type {Map<string, string>}
      */
-    private readonly randomGenerator: IRandomGenerator;
+    private readonly namesMap: Map<string, string> = new Map();
 
     /**
-     * @param {IRandomGenerator} randomGenerator
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IOptions} options
      */
     constructor (
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         super(options);
 
-        this.randomGenerator = randomGenerator;
+        this.identifierNameGenerator = identifierNameGeneratorFactory(options);
     }
 
     /**
@@ -62,7 +65,7 @@ export class BaseIdentifierObfuscatingReplacer extends AbstractObfuscatingReplac
             return;
         }
 
-        this.namesMap.set(`${nodeName}-${String(nodeIdentifier)}`, this.randomGenerator.getRandomVariableName(6));
+        this.namesMap.set(`${nodeName}-${String(nodeIdentifier)}`, this.identifierNameGenerator.generate(6));
     }
 
     /**

+ 1 - 2
src/node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/StringLiteralObfuscatingReplacer.ts

@@ -229,8 +229,7 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
         const escapedValue: string = this.escapeSequenceEncoder.encode(encodedValue, this.options.unicodeEscapeSequence);
 
         const stringArrayStorageLength: number = this.stringArrayStorage.getLength();
-        const rotatedStringArrayStorageId: string = Utils.stringRotate(this.stringArrayStorage.getStorageId(), 1);
-        const stringArrayStorageCallsWrapperName: string = `_${Utils.hexadecimalPrefix}${rotatedStringArrayStorageId}`;
+        const stringArrayStorageCallsWrapperName: string = this.stringArrayStorage.getStorageId().split('|')[1];
 
         const { fromCache, index }: IStringArrayIndexData = this.getStringArrayHexadecimalIndex(
             escapedValue,

+ 10 - 1
src/storages/ArrayStorage.ts

@@ -1,6 +1,7 @@
 import { inject, injectable, postConstruct } from 'inversify';
 import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 
+import { IOptions } from '../interfaces/options/IOptions';
 import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
 import { IStorage } from '../interfaces/storages/IStorage';
 
@@ -13,6 +14,11 @@ export abstract class ArrayStorage <T> implements IStorage <T> {
      */
     protected readonly randomGenerator: IRandomGenerator;
 
+    /**
+     * @type {IOptions}
+     */
+    protected readonly options: IOptions;
+
     /**
      * @type {T[]}
      */
@@ -32,11 +38,14 @@ export abstract class ArrayStorage <T> implements IStorage <T> {
 
     /**
      * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
      */
     constructor (
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         this.randomGenerator = randomGenerator;
+        this.options = options;
     }
 
     @postConstruct()

+ 10 - 1
src/storages/MapStorage.ts

@@ -1,6 +1,7 @@
 import { inject, injectable, postConstruct } from 'inversify';
 import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 
+import { IOptions } from '../interfaces/options/IOptions';
 import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
 import { IStorage } from '../interfaces/storages/IStorage';
 
@@ -8,6 +9,11 @@ import { initializable } from '../decorators/Initializable';
 
 @injectable()
 export abstract class MapStorage <T> implements IStorage <T> {
+    /**
+     * @type {IOptions}
+     */
+    protected readonly options: IOptions;
+
     /**
      * @type {IRandomGenerator}
      */
@@ -27,11 +33,14 @@ export abstract class MapStorage <T> implements IStorage <T> {
 
     /**
      * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
      */
     constructor (
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
         this.randomGenerator = randomGenerator;
+        this.options = options;
     }
 
     @postConstruct()

+ 5 - 2
src/storages/control-flow/ControlFlowStorage.ts

@@ -2,6 +2,7 @@ import { inject, injectable, } from 'inversify';
 import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
+import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 import { MapStorage } from '../MapStorage';
@@ -10,10 +11,12 @@ import { MapStorage } from '../MapStorage';
 export class ControlFlowStorage extends MapStorage <ICustomNode> {
     /**
      * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
      */
     constructor (
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator);
+        super(randomGenerator, options);
     }
 }

+ 4 - 1
src/storages/custom-node-group/CustomNodeGroupStorage.ts

@@ -4,6 +4,7 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { TCustomNodeGroupFactory } from '../../types/container/custom-nodes/TCustomNodeGroupFactory';
 
 import { ICustomNodeGroup } from '../../interfaces/custom-nodes/ICustomNodeGroup';
+import { IOptions } from '../../interfaces/options/IOptions';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 import { CustomNodeGroup } from '../../enums/custom-nodes/CustomNodeGroup';
@@ -31,12 +32,14 @@ export class CustomNodeGroupStorage extends MapStorage <ICustomNodeGroup> {
     /**
      * @param {TCustomNodeGroupFactory} customNodeGroupFactory
      * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
      */
     constructor (
         @inject(ServiceIdentifiers.Factory__ICustomNodeGroup) customNodeGroupFactory: TCustomNodeGroupFactory,
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator);
+        super(randomGenerator, options);
 
         this.customNodeGroupFactory = customNodeGroupFactory;
     }

+ 21 - 4
src/storages/string-array/StringArrayStorage.ts

@@ -4,8 +4,11 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 import { IArrayUtils } from '../../interfaces/utils/IArrayUtils';
 import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
+import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
+import { IIdentifierNameGenerator } from '../../interfaces/generators/identifier-name-generators/IIdentifierNameGenerator';
+import { IOptions } from '../../interfaces/options/IOptions';
+
 import { ArrayStorage } from '../ArrayStorage';
-import { RandomGenerator } from '../../utils/RandomGenerator';
 
 @injectable()
 export class StringArrayStorage extends ArrayStorage <string> {
@@ -15,15 +18,26 @@ export class StringArrayStorage extends ArrayStorage <string> {
     private readonly arrayUtils: IArrayUtils;
 
     /**
+     * @type {IIdentifierNameGenerator}
+     */
+    private readonly identifierNameGenerator: IIdentifierNameGenerator;
+
+    /**
+     * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
      * @param {IArrayUtils} arrayUtils
      * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
      */
     constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
+            identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
         @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils,
-        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
     ) {
-        super(randomGenerator);
+        super(randomGenerator, options);
 
+        this.identifierNameGenerator = identifierNameGeneratorFactory(options);
         this.arrayUtils = arrayUtils;
     }
 
@@ -31,7 +45,10 @@ export class StringArrayStorage extends ArrayStorage <string> {
     public initialize (): void {
         super.initialize();
 
-        this.storageId = this.randomGenerator.getRandomString(4, RandomGenerator.randomGeneratorPoolHexadecimal);
+        const stringArrayName: string = this.identifierNameGenerator.generate(4);
+        const stringArrayCallsWrapperName: string = this.identifierNameGenerator.generate(4);
+
+        this.storageId = `${stringArrayName}|${stringArrayCallsWrapperName}`;
     }
 
     /**

+ 2 - 2
src/templates/debug-protection-nodes/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate.ts

@@ -6,8 +6,8 @@ export function DebugProtectionFunctionCallTemplate (): string {
         (function () {
             {singleNodeCallControllerFunctionName}(this, function () {
                 var regExp1 = new RegExp('function *\\\\( *\\\\)');
-                var regExp2 = new RegExp('\\\\+\\\\+ *\\(?:_0x(?:[a-f0-9]){4,6}|\\\\b[a-zA-Z]{1,2}\\\\b\\)');
-           
+                var regExp2 = new RegExp('\\\\+\\\\+ *\\(?:_0x(?:[a-f0-9]){4,6}|(?:\\\\b|\\\\d)[a-z0-9]{1,4}(?:\\\\b|\\\\d)\\)', 'i');
+       
                 var result = {debugProtectionFunctionName}('init');
                 
                 if (!regExp1.test(result + 'chain') || !regExp2.test(result + 'input')) {

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

@@ -0,0 +1,5 @@
+import { interfaces } from 'inversify';
+
+import { TInputOptions } from '../options/TInputOptions';
+
+export type TInversifyContainerModuleFactory = (options: TInputOptions) => interfaces.ContainerModule;

+ 4 - 0
src/types/container/generators/TIdentifierNameGeneratorFactory.d.ts

@@ -0,0 +1,4 @@
+import { IIdentifierNameGenerator } from '../../../interfaces/generators/identifier-name-generators/IIdentifierNameGenerator';
+import { IOptions } from '../../../interfaces/options/IOptions';
+
+export type TIdentifierNameGeneratorFactory = (options: IOptions) => IIdentifierNameGenerator;

+ 0 - 28
src/utils/RandomGenerator.ts

@@ -11,8 +11,6 @@ import { ISourceCode } from '../interfaces/ISourceCode';
 
 import { initializable } from '../decorators/Initializable';
 
-import { Utils } from './Utils';
-
 @injectable()
 export class RandomGenerator implements IRandomGenerator, IInitializable {
     /**
@@ -35,11 +33,6 @@ export class RandomGenerator implements IRandomGenerator, IInitializable {
      */
     private readonly options: IOptions;
 
-    /**
-     * @type {Set<string>}
-     */
-    private readonly randomVariableNameSet: Set <string> = new Set();
-
     /**
      * @type {Chance.Chance | Chance.SeededChance}
      */
@@ -139,27 +132,6 @@ export class RandomGenerator implements IRandomGenerator, IInitializable {
         return this.getRandomGenerator().string({ length, pool });
     }
 
-    /**
-     * @param {number} length
-     * @returns {string}
-     */
-    public getRandomVariableName (length: number): string {
-        const prefix: string = `_${Utils.hexadecimalPrefix}`;
-        const rangeMinInteger: number = 10000;
-        const rangeMaxInteger: number = 99999999;
-        const randomInteger: number = this.getRandomInteger(rangeMinInteger, rangeMaxInteger);
-        const hexadecimalNumber: string = Utils.decToHex(randomInteger);
-        const randomVariableName: string = `${prefix}${hexadecimalNumber.substr(0, length)}`;
-
-        if (this.randomVariableNameSet.has(randomVariableName)) {
-            return this.getRandomVariableName(length);
-        }
-
-        this.randomVariableNameSet.add(randomVariableName);
-
-        return randomVariableName;
-    }
-
     /**
      * @returns {number}
      */

+ 1 - 2
test/dev/dev.ts

@@ -35,8 +35,7 @@ import { NO_CUSTOM_NODES_PRESET } from '../../src/options/presets/NoCustomNodes'
         {
             ...NO_CUSTOM_NODES_PRESET,
             compact: false,
-            deadCodeInjection: true,
-            deadCodeInjectionThreshold: 1
+            mangle: true
         }
     ).getObfuscatedCode();
 

+ 1 - 1
test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts

@@ -445,7 +445,7 @@ describe('JavaScriptObfuscator', () => {
         });
 
         describe('mangle', () => {
-            const regExp: RegExp = /var *a *= *0x1/;
+            const regExp: RegExp = /var *c *= *0x1/;
 
             let obfuscatedCode: string;
 

+ 1 - 1
test/functional-tests/templates/custom-nodes/debug-protection-nodes/DebufProtectionFunctionCallTemplate.spec.ts

@@ -117,7 +117,7 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
             );
 
             obfuscatedCode = obfuscationResult.getObfuscatedCode();
-            obfuscatedCode = obfuscatedCode.replace(/\+\+ *_0x([a-f0-9]){4,6}/, '++abc');
+            obfuscatedCode = obfuscatedCode.replace(/\+\+ *_0x([a-f0-9]){4,6}/, '');
 
             spawnThread(
                 () => obfuscatedCode,

+ 2 - 1
test/index.spec.ts

@@ -14,6 +14,8 @@ import './unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec';
 import './unit-tests/cli/utils/CLIUtils.spec';
 import './unit-tests/cli/utils/SourceCodeReader.spec';
 import './unit-tests/decorators/initializable/Initializable.spec';
+import './unit-tests/generators/identifier-name-generators/HexadecimalIdentifierNameGenerator.spec';
+import './unit-tests/generators/identifier-name-generators/MangledlIdentifierNameGenerator.spec';
 import './unit-tests/javascript-obfuscator/JavaScriptObfuscator.spec';
 import './unit-tests/logger/Logger.spec';
 import './unit-tests/node/node-appender/NodeAppender.spec';
@@ -27,7 +29,6 @@ import './unit-tests/storages/ArrayStorage.spec';
 import './unit-tests/storages/MapStorage.spec';
 import './unit-tests/utils/ArrayUtils.spec';
 import './unit-tests/utils/CryptUtils.spec';
-import './unit-tests/utils/RandomGeneratorUtils.spec';
 import './unit-tests/utils/EscapeSequenceEncoder.spec';
 import './unit-tests/utils/Utils.spec';
 

+ 52 - 0
test/unit-tests/generators/identifier-name-generators/HexadecimalIdentifierNameGenerator.spec.ts

@@ -0,0 +1,52 @@
+import 'reflect-metadata';
+
+import { assert } from 'chai';
+
+import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers';
+
+import { IIdentifierNameGenerator } from '../../../../src/interfaces/generators/identifier-name-generators/IIdentifierNameGenerator';
+import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade';
+
+import { IdentifierNameGenerator } from '../../../../src/enums/generators/identifier-name-generators/IdentifierNameGenerator';
+
+import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
+
+describe('HexadecimalIdentifierNameGenerator', () => {
+    describe('generate (length: number): string', () => {
+        let identifierNameGenerator: IIdentifierNameGenerator,
+            hexadecimalIdentifierName: string,
+            regExp: RegExp;
+
+        before(() => {
+            const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
+
+            inversifyContainerFacade.load('', {});
+            identifierNameGenerator = inversifyContainerFacade.getNamed<IIdentifierNameGenerator>(
+                ServiceIdentifiers.IIdentifierNameGenerator,
+                IdentifierNameGenerator.HexadecimalIdentifierNameGenerator
+            )
+        });
+
+        describe('variant #1: hexadecimal name with length `4`', () => {
+            before(() => {
+                hexadecimalIdentifierName = identifierNameGenerator.generate(4);
+                regExp = /^_0x(\w){4}$/;
+            });
+
+            it('should return hexadecimal name', () => {
+                assert.match(hexadecimalIdentifierName, regExp);
+            })
+        });
+
+        describe('variant #2: hexadecimal name with length `6`', () => {
+            before(() => {
+                hexadecimalIdentifierName = identifierNameGenerator.generate(6);
+                regExp = /^_0x(\w){4,6}$/;
+            });
+
+            it('should return hexadecimal name', () => {
+                assert.match(hexadecimalIdentifierName, regExp);
+            })
+        });
+    });
+});

+ 95 - 0
test/unit-tests/generators/identifier-name-generators/MangledlIdentifierNameGenerator.spec.ts

@@ -0,0 +1,95 @@
+import 'reflect-metadata';
+
+import { assert } from 'chai';
+
+import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers';
+
+import { IIdentifierNameGenerator } from '../../../../src/interfaces/generators/identifier-name-generators/IIdentifierNameGenerator';
+import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade';
+
+import { IdentifierNameGenerator } from '../../../../src/enums/generators/identifier-name-generators/IdentifierNameGenerator';
+
+import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
+
+describe('MangledIdentifierNameGenerator', () => {
+    describe('generate (length: number): string', () => {
+        let identifierNameGenerator: IIdentifierNameGenerator,
+            mangledIdentifierName: string;
+
+        before(() => {
+            const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
+
+            inversifyContainerFacade.load('', {});
+            identifierNameGenerator = inversifyContainerFacade.getNamed<IIdentifierNameGenerator>(
+                ServiceIdentifiers.IIdentifierNameGenerator,
+                IdentifierNameGenerator.MangledIdentifierNameGenerator
+            )
+        });
+
+        describe('variant #1: initial mangled name', () => {
+            const expectedMangledIdentifierName: string = 'a';
+
+            before(() => {
+                mangledIdentifierName = identifierNameGenerator.generate(4);
+            });
+
+            it('should return hexadecimal name', () => {
+                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+            })
+        });
+
+        describe('variant #2: second mangled name', () => {
+            const expectedMangledIdentifierName: string = 'b';
+
+            before(() => {
+                mangledIdentifierName = identifierNameGenerator.generate(6);
+            });
+
+            it('should return hexadecimal name', () => {
+                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+            })
+        });
+
+        describe('variant #3: last mangled name with single character', () => {
+            const expectedMangledIdentifierName: string = 'Z';
+
+            before(() => {
+                for (let i: number = 0; i <= 49; i++) {
+                    mangledIdentifierName = identifierNameGenerator.generate(6);
+                }
+            });
+
+            it('should return hexadecimal name', () => {
+                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+            })
+        });
+
+        describe('variant #4: correct increase of mangled name length', () => {
+            const expectedMangledIdentifierName: string = 'a0';
+
+            before(() => {
+                for (let i: number = 0; i < 1; i++) {
+                    mangledIdentifierName = identifierNameGenerator.generate(6);
+                }
+            });
+
+            it('should return hexadecimal name', () => {
+                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+            })
+        });
+
+        describe('variant #4: correct increase of mangled name length #2', () => {
+            const expectedMangledIdentifierName: string = 'aa';
+
+            before(() => {
+                for (let i: number = 0; i < 10; i++) {
+                    mangledIdentifierName = identifierNameGenerator.generate(6);
+                }
+            });
+
+            it('should return hexadecimal name', () => {
+                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+            })
+        });
+    });
+});

+ 5 - 1
test/unit-tests/storages/ArrayStorage.spec.ts

@@ -3,6 +3,7 @@ import { assert } from 'chai';
 import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
 
 import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
+import { IOptions } from '../../../src/interfaces/options/IOptions';
 import { IRandomGenerator } from '../../../src/interfaces/utils/IRandomGenerator';
 import { IStorage } from '../../../src/interfaces/storages/IStorage';
 
@@ -15,7 +16,10 @@ class ConcreteStorage extends ArrayStorage <string> {
 
         inversifyContainerFacade.load('', {});
 
-        super(inversifyContainerFacade.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator));
+        super(
+            inversifyContainerFacade.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator),
+            inversifyContainerFacade.get<IOptions>(ServiceIdentifiers.IOptions)
+        );
     }
 }
 

+ 5 - 1
test/unit-tests/storages/MapStorage.spec.ts

@@ -3,6 +3,7 @@ import { assert } from 'chai';
 import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
 
 import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
+import { IOptions } from '../../../src/interfaces/options/IOptions';
 import { IRandomGenerator } from '../../../src/interfaces/utils/IRandomGenerator';
 import { IStorage } from '../../../src/interfaces/storages/IStorage';
 
@@ -15,7 +16,10 @@ class ConcreteStorage extends MapStorage <string> {
 
         inversifyContainerFacade.load('', {});
 
-        super(inversifyContainerFacade.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator));
+        super(
+            inversifyContainerFacade.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator),
+            inversifyContainerFacade.get<IOptions>(ServiceIdentifiers.IOptions)
+        );
     }
 }
 

+ 0 - 45
test/unit-tests/utils/RandomGeneratorUtils.spec.ts

@@ -1,45 +0,0 @@
-import { assert } from 'chai';
-
-import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
-
-import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
-import { IRandomGenerator } from '../../../src/interfaces/utils/IRandomGenerator';
-
-import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
-
-describe('RandomGeneratorUtils', () => {
-    describe('getRandomVariableName (length: number = 6): string', () => {
-        let randomGenerator: IRandomGenerator,
-            randomVariableName: string,
-            regExp: RegExp;
-
-        before(() => {
-            const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
-
-            inversifyContainerFacade.load('', {});
-            randomGenerator = inversifyContainerFacade.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator)
-        });
-
-        describe('variant #1: string with random variable of length `4`', () => {
-            before(() => {
-                randomVariableName = randomGenerator.getRandomVariableName(4);
-                regExp = /^_0x(\w){4}$/;
-            });
-
-            it('should return random variable name', () => {
-                assert.match(randomVariableName, regExp);
-            })
-        });
-
-        describe('variant #2: string with random variable of length `6`', () => {
-            before(() => {
-                randomVariableName = randomGenerator.getRandomVariableName(6);
-                regExp = /^_0x(\w){4,6}$/;
-            });
-
-            it('should return random variable name', () => {
-                assert.match(randomVariableName, regExp);
-            })
-        });
-    });
-});

Некоторые файлы не были показаны из-за большого количества измененных файлов