Explorar el Código

`identifiersPrefix` option

sanex3339 hace 7 años
padre
commit
d4b801e71e

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@ Change Log
 ===
 ===
 v0.14.0
 v0.14.0
 ---
 ---
+* **New option:** `identifiersPrefix` sets prefix for all generated identifiers.
 * **New option:** `transformObjectKeys` enables object keys transformation and obfuscation.
 * **New option:** `transformObjectKeys` enables object keys transformation and obfuscation.
 * **New feature:** `eval` expressions obfuscation.
 * **New feature:** `eval` expressions obfuscation.
 * **Breaking change:** Now CLI obfuscating directory recursively. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/157
 * **Breaking change:** Now CLI obfuscating directory recursively. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/157

+ 9 - 0
README.md

@@ -277,6 +277,7 @@ Following options are available for the JS Obfuscator:
     disableConsoleOutput: false,
     disableConsoleOutput: false,
     domainLock: [],
     domainLock: [],
     identifierNamesGenerator: 'hexadecimal',
     identifierNamesGenerator: 'hexadecimal',
+    identifiersPrefix: '',
     log: false,
     log: false,
     renameGlobals: false,
     renameGlobals: false,
     reservedNames: [],
     reservedNames: [],
@@ -314,6 +315,7 @@ Following options are available for the JS Obfuscator:
     --disable-console-output <boolean>
     --disable-console-output <boolean>
     --domain-lock '<list>' (comma separated)
     --domain-lock '<list>' (comma separated)
     --identifier-names-generator <string> [hexadecimal, mangled]
     --identifier-names-generator <string> [hexadecimal, mangled]
+    --identifiers-prefix <string>
     --log <boolean>
     --log <boolean>
     --rename-globals <boolean>
     --rename-globals <boolean>
     --reserved-names '<list>' (comma separated)
     --reserved-names '<list>' (comma separated)
@@ -570,6 +572,13 @@ Available values:
 * `hexadecimal`: identifier names like `_0xabc123`
 * `hexadecimal`: identifier names like `_0xabc123`
 * `mangled`: short identifier names like `a`, `b`, `c`
 * `mangled`: short identifier names like `a`, `b`, `c`
 
 
+### `identifiersPrefix`
+Type: `string` Default: ``
+
+Sets prefix for all generated identifiers.
+
+Use this option when `identifierNamesGenerator: 'mangled'` and you want to obfuscate multiple files. This option will help to avoid conflicts between variables of these files. For each file prefix should be different.
+
 ### `log`
 ### `log`
 Type: `boolean` Default: `false`
 Type: `boolean` Default: `false`
 
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
dist/index.js


+ 5 - 5
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "javascript-obfuscator",
   "name": "javascript-obfuscator",
-  "version": "0.14.0-beta.2",
+  "version": "0.14.0-beta.3",
   "description": "JavaScript obfuscator",
   "description": "JavaScript obfuscator",
   "keywords": [
   "keywords": [
     "obfuscator",
     "obfuscator",
@@ -32,13 +32,13 @@
     "mkdirp": "0.5.1",
     "mkdirp": "0.5.1",
     "opencollective": "1.0.3",
     "opencollective": "1.0.3",
     "pjson": "1.0.9",
     "pjson": "1.0.9",
-    "reflect-metadata": "0.1.10",
-    "source-map-support": "0.5.0",
+    "reflect-metadata": "0.1.12",
+    "source-map-support": "0.5.1",
     "string-template": "1.0.0",
     "string-template": "1.0.0",
     "tslib": "1.8.1"
     "tslib": "1.8.1"
   },
   },
   "devDependencies": {
   "devDependencies": {
-    "@types/chai": "4.1.0",
+    "@types/chai": "4.1.1",
     "@types/chance": "0.7.36",
     "@types/chance": "0.7.36",
     "@types/escodegen": "0.0.6",
     "@types/escodegen": "0.0.6",
     "@types/esprima": "4.0.1",
     "@types/esprima": "4.0.1",
@@ -63,7 +63,7 @@
     "mocha": "4.1.0",
     "mocha": "4.1.0",
     "pre-commit": "1.2.2",
     "pre-commit": "1.2.2",
     "rimraf": "2.6.2",
     "rimraf": "2.6.2",
-    "sinon": "4.1.5",
+    "sinon": "4.1.6",
     "threads": "0.10.0",
     "threads": "0.10.0",
     "ts-node": "4.1.0",
     "ts-node": "4.1.0",
     "tslint": "5.9.1",
     "tslint": "5.9.1",

+ 4 - 0
src/cli/JavaScriptObfuscatorCLI.ts

@@ -244,6 +244,10 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
                 '--identifier-names-generator <string> [hexadecimal, mangled]', 'Sets identifier names generator (Default: hexadecimal)',
                 '--identifier-names-generator <string> [hexadecimal, mangled]', 'Sets identifier names generator (Default: hexadecimal)',
                 IdentifierNamesGeneratorSanitizer
                 IdentifierNamesGeneratorSanitizer
             )
             )
+            .option(
+                '--identifiers-prefix <string>',
+                'Sets prefix for all generated identifiers.',
+            )
             .option(
             .option(
                 '--log <boolean>', 'Enables logging of the information to the console',
                 '--log <boolean>', 'Enables logging of the information to the console',
                 BooleanSanitizer
                 BooleanSanitizer

+ 4 - 4
src/container/InversifyContainerFacade.ts

@@ -9,6 +9,7 @@ import { finalizingTransformersModule } from './modules/node-transformers/Finali
 import { generatorsModule } from './modules/generators/GeneratorsModule';
 import { generatorsModule } from './modules/generators/GeneratorsModule';
 import { nodeTransformersModule } from './modules/node-transformers/NodeTransformersModule';
 import { nodeTransformersModule } from './modules/node-transformers/NodeTransformersModule';
 import { obfuscatingTransformersModule } from './modules/node-transformers/ObfuscatingTransformersModule';
 import { obfuscatingTransformersModule } from './modules/node-transformers/ObfuscatingTransformersModule';
+import { optionsModule } from './modules/options/OptionsModule';
 import { preparingTransformersModule } from './modules/node-transformers/PreparingTransformersModule';
 import { preparingTransformersModule } from './modules/node-transformers/PreparingTransformersModule';
 import { storagesModule } from './modules/storages/StoragesModule';
 import { storagesModule } from './modules/storages/StoragesModule';
 import { utilsModule } from './modules/utils/UtilsModule';
 import { utilsModule } from './modules/utils/UtilsModule';
@@ -20,7 +21,6 @@ import { IJavaScriptObfuscator } from '../interfaces/IJavaScriptObfsucator';
 import { ILogger } from '../interfaces/logger/ILogger';
 import { ILogger } from '../interfaces/logger/ILogger';
 import { IObfuscationEventEmitter } from '../interfaces/event-emitters/IObfuscationEventEmitter';
 import { IObfuscationEventEmitter } from '../interfaces/event-emitters/IObfuscationEventEmitter';
 import { IObfuscationResult } from '../interfaces/IObfuscationResult';
 import { IObfuscationResult } from '../interfaces/IObfuscationResult';
-import { IOptions } from '../interfaces/options/IOptions';
 import { ISourceCode } from '../interfaces/ISourceCode';
 import { ISourceCode } from '../interfaces/ISourceCode';
 import { ISourceMapCorrector } from '../interfaces/source-map/ISourceMapCorrector';
 import { ISourceMapCorrector } from '../interfaces/source-map/ISourceMapCorrector';
 import { ITransformersRunner } from '../interfaces/node-transformers/ITransformersRunner';
 import { ITransformersRunner } from '../interfaces/node-transformers/ITransformersRunner';
@@ -29,7 +29,6 @@ import { JavaScriptObfuscator } from '../JavaScriptObfuscator';
 import { Logger } from '../logger/Logger';
 import { Logger } from '../logger/Logger';
 import { ObfuscationEventEmitter } from '../event-emitters/ObfuscationEventEmitter';
 import { ObfuscationEventEmitter } from '../event-emitters/ObfuscationEventEmitter';
 import { ObfuscationResult } from '../ObfuscationResult';
 import { ObfuscationResult } from '../ObfuscationResult';
-import { Options } from "../options/Options";
 import { SourceCode } from '../SourceCode';
 import { SourceCode } from '../SourceCode';
 import { SourceMapCorrector } from '../source-map/SourceMapCorrector';
 import { SourceMapCorrector } from '../source-map/SourceMapCorrector';
 import { TransformersRunner } from '../node-transformers/TransformersRunner';
 import { TransformersRunner } from '../node-transformers/TransformersRunner';
@@ -147,8 +146,8 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
             .inSingletonScope();
             .inSingletonScope();
 
 
         this.container
         this.container
-            .bind<IOptions>(ServiceIdentifiers.IOptions)
-            .toDynamicValue(() => new Options(options))
+            .bind<TInputOptions>(ServiceIdentifiers.TInputOptions)
+            .toDynamicValue(() => options)
             .inSingletonScope();
             .inSingletonScope();
 
 
         this.container
         this.container
@@ -203,6 +202,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
         this.container.load(generatorsModule);
         this.container.load(generatorsModule);
         this.container.load(nodeTransformersModule);
         this.container.load(nodeTransformersModule);
         this.container.load(obfuscatingTransformersModule);
         this.container.load(obfuscatingTransformersModule);
+        this.container.load(optionsModule);
         this.container.load(preparingTransformersModule);
         this.container.load(preparingTransformersModule);
         this.container.load(storagesModule);
         this.container.load(storagesModule);
         this.container.load(utilsModule);
         this.container.load(utilsModule);

+ 2 - 0
src/container/ServiceIdentifiers.ts

@@ -28,6 +28,7 @@ export enum ServiceIdentifiers {
     IObfuscationEventEmitter = 'IObfuscationEventEmitter',
     IObfuscationEventEmitter = 'IObfuscationEventEmitter',
     IObfuscationResult = 'IObfuscationResult',
     IObfuscationResult = 'IObfuscationResult',
     IOptions = 'IOptions',
     IOptions = 'IOptions',
+    IOptionsNormalizer = 'IOptionsNormalizer',
     IObfuscatingReplacer = 'IObfuscatingReplacer',
     IObfuscatingReplacer = 'IObfuscatingReplacer',
     IRandomGenerator = 'IRandomGenerator',
     IRandomGenerator = 'IRandomGenerator',
     ISourceCode = 'ISourceCode',
     ISourceCode = 'ISourceCode',
@@ -37,5 +38,6 @@ export enum ServiceIdentifiers {
     Newable__ICustomNode = 'Newable<ICustomNode>',
     Newable__ICustomNode = 'Newable<ICustomNode>',
     Newable__TControlFlowStorage = 'Newable<TControlFlowStorage>',
     Newable__TControlFlowStorage = 'Newable<TControlFlowStorage>',
     TCustomNodeGroupStorage = 'TCustomNodeGroupStorage',
     TCustomNodeGroupStorage = 'TCustomNodeGroupStorage',
+    TInputOptions = 'TInputOptions',
     TStringArrayStorage = 'TStringArrayStorage'
     TStringArrayStorage = 'TStringArrayStorage'
 }
 }

+ 18 - 0
src/container/modules/options/OptionsModule.ts

@@ -0,0 +1,18 @@
+import { ContainerModule, interfaces } from 'inversify';
+import { ServiceIdentifiers } from '../../ServiceIdentifiers';
+
+import { IOptions } from '../../../interfaces/options/IOptions';
+import { IOptionsNormalizer } from '../../../interfaces/options/IOptionsNormalizer';
+
+import { Options } from '../../../options/Options';
+import { OptionsNormalizer } from '../../../options/OptionsNormalizer';
+
+export const optionsModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
+    bind<IOptions>(ServiceIdentifiers.IOptions)
+        .to(Options)
+        .inSingletonScope();
+
+    bind<IOptionsNormalizer>(ServiceIdentifiers.IOptionsNormalizer)
+        .to(OptionsNormalizer)
+        .inSingletonScope();
+});

+ 1 - 1
src/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.ts

@@ -30,7 +30,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
      * @returns {string}
      * @returns {string}
      */
      */
     public generate (length: number): string {
     public generate (length: number): string {
-        const prefix: string = `_${Utils.hexadecimalPrefix}`;
+        const prefix: string = `${this.options.identifiersPrefix}_${Utils.hexadecimalPrefix}`;
         const rangeMinInteger: number = 10000;
         const rangeMinInteger: number = 10000;
         const rangeMaxInteger: number = 99999999;
         const rangeMaxInteger: number = 99999999;
         const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger);
         const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger);

+ 4 - 1
src/generators/identifier-names-generators/MangledIdentifierNamesGenerator.ts

@@ -102,10 +102,13 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
      * @returns {string}
      * @returns {string}
      */
      */
     public generate (length: number): string {
     public generate (length: number): string {
+        const prefix: string = this.options.identifiersPrefix ?
+            `${this.options.identifiersPrefix}_`
+            : '';
         const newName: string = MangledIdentifierNamesGenerator.generateNewMangledName(this.previousMangledName);
         const newName: string = MangledIdentifierNamesGenerator.generateNewMangledName(this.previousMangledName);
 
 
         this.previousMangledName = newName;
         this.previousMangledName = newName;
 
 
-        return newName;
+        return `${prefix}${newName}`;
     }
     }
 }
 }

+ 1 - 0
src/interfaces/options/IOptions.d.ts

@@ -15,6 +15,7 @@ export interface IOptions {
     readonly disableConsoleOutput: boolean;
     readonly disableConsoleOutput: boolean;
     readonly domainLock: string[];
     readonly domainLock: string[];
     readonly identifierNamesGenerator: IdentifierNamesGenerator;
     readonly identifierNamesGenerator: IdentifierNamesGenerator;
+    readonly identifiersPrefix: string;
     readonly log: boolean;
     readonly log: boolean;
     readonly renameGlobals: boolean;
     readonly renameGlobals: boolean;
     readonly reservedNames: string[];
     readonly reservedNames: string[];

+ 9 - 0
src/interfaces/options/IOptionsNormalizer.d.ts

@@ -0,0 +1,9 @@
+import { IOptions } from './IOptions';
+
+export interface IOptionsNormalizer {
+    /**
+     * @param {IOptions} options
+     * @returns {IOptions}
+     */
+    normalize (options: IOptions): IOptions;
+}

+ 15 - 4
src/options/Options.ts

@@ -1,4 +1,5 @@
-import { injectable } from 'inversify';
+import { inject, injectable } from 'inversify';
+import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 
 
 import {
 import {
     ArrayUnique,
     ArrayUnique,
@@ -20,6 +21,7 @@ import { TInputOptions } from '../types/options/TInputOptions';
 import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding';
 import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding';
 
 
 import { IOptions } from '../interfaces/options/IOptions';
 import { IOptions } from '../interfaces/options/IOptions';
+import { IOptionsNormalizer } from '../interfaces/options/IOptionsNormalizer';
 
 
 import { IdentifierNamesGenerator } from '../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
 import { IdentifierNamesGenerator } from '../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
 import { ObfuscationTarget } from '../enums/ObfuscationTarget';
 import { ObfuscationTarget } from '../enums/ObfuscationTarget';
@@ -28,7 +30,6 @@ import { StringArrayEncoding } from '../enums/StringArrayEncoding';
 
 
 import { DEFAULT_PRESET } from './presets/Default';
 import { DEFAULT_PRESET } from './presets/Default';
 
 
-import { OptionsNormalizer } from './OptionsNormalizer';
 import { ValidationErrorsFormatter } from './ValidationErrorsFormatter';
 import { ValidationErrorsFormatter } from './ValidationErrorsFormatter';
 
 
 @injectable()
 @injectable()
@@ -111,6 +112,12 @@ export class Options implements IOptions {
     ])
     ])
     public readonly identifierNamesGenerator: IdentifierNamesGenerator;
     public readonly identifierNamesGenerator: IdentifierNamesGenerator;
 
 
+    /**
+     * @type {string}
+     */
+    @IsString()
+    public readonly identifiersPrefix: string;
+
     /**
     /**
      * @type {boolean}
      * @type {boolean}
      */
      */
@@ -220,8 +227,12 @@ export class Options implements IOptions {
 
 
     /**
     /**
      * @param {TInputOptions} inputOptions
      * @param {TInputOptions} inputOptions
+     * @param {IOptionsNormalizer} optionsNormalizer
      */
      */
-    constructor (inputOptions: TInputOptions) {
+    constructor (
+        @inject(ServiceIdentifiers.TInputOptions) inputOptions: TInputOptions,
+        @inject(ServiceIdentifiers.IOptionsNormalizer) optionsNormalizer: IOptionsNormalizer
+    ) {
         Object.assign(this, DEFAULT_PRESET, inputOptions);
         Object.assign(this, DEFAULT_PRESET, inputOptions);
 
 
         const errors: ValidationError[] = validateSync(this, Options.validatorOptions);
         const errors: ValidationError[] = validateSync(this, Options.validatorOptions);
@@ -230,6 +241,6 @@ export class Options implements IOptions {
             throw new ReferenceError(`Validation failed. errors:\n${ValidationErrorsFormatter.format(errors)}`);
             throw new ReferenceError(`Validation failed. errors:\n${ValidationErrorsFormatter.format(errors)}`);
         }
         }
 
 
-        Object.assign(this, OptionsNormalizer.normalizeOptions(this));
+        Object.assign(this, optionsNormalizer.normalize(this));
     }
     }
 }
 }

+ 6 - 2
src/options/OptionsNormalizer.ts

@@ -1,6 +1,9 @@
+import { injectable } from 'inversify';
+
 import { TOptionsNormalizerRule } from '../types/options/TOptionsNormalizerRule';
 import { TOptionsNormalizerRule } from '../types/options/TOptionsNormalizerRule';
 
 
 import { IOptions } from '../interfaces/options/IOptions';
 import { IOptions } from '../interfaces/options/IOptions';
+import { IOptionsNormalizer } from '../interfaces/options/IOptionsNormalizer';
 
 
 import { ControlFlowFlatteningThresholdRule } from './normalizer-rules/ControlFlowFlatteningThresholdRule';
 import { ControlFlowFlatteningThresholdRule } from './normalizer-rules/ControlFlowFlatteningThresholdRule';
 import { DeadCodeInjectionRule } from './normalizer-rules/DeadCodeInjectionRule';
 import { DeadCodeInjectionRule } from './normalizer-rules/DeadCodeInjectionRule';
@@ -13,7 +16,8 @@ import { StringArrayRule } from './normalizer-rules/StringArrayRule';
 import { StringArrayEncodingRule } from './normalizer-rules/StringArrayEncodingRule';
 import { StringArrayEncodingRule } from './normalizer-rules/StringArrayEncodingRule';
 import { StringArrayThresholdRule } from './normalizer-rules/StringArrayThresholdRule';
 import { StringArrayThresholdRule } from './normalizer-rules/StringArrayThresholdRule';
 
 
-export class OptionsNormalizer {
+@injectable()
+export class OptionsNormalizer implements IOptionsNormalizer {
     /**
     /**
      * @type {TOptionsNormalizerRule[]}
      * @type {TOptionsNormalizerRule[]}
      */
      */
@@ -34,7 +38,7 @@ export class OptionsNormalizer {
      * @param {IOptions} options
      * @param {IOptions} options
      * @returns {IOptions}
      * @returns {IOptions}
      */
      */
-    public static normalizeOptions (options: IOptions): IOptions {
+    public normalize (options: IOptions): IOptions {
         let normalizedOptions: IOptions = {
         let normalizedOptions: IOptions = {
             ...options
             ...options
         };
         };

+ 1 - 0
src/options/presets/Default.ts

@@ -16,6 +16,7 @@ export const DEFAULT_PRESET: TInputOptions = Object.freeze({
     disableConsoleOutput: false,
     disableConsoleOutput: false,
     domainLock: [],
     domainLock: [],
     identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
     identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
+    identifiersPrefix: '',
     log: false,
     log: false,
     renameGlobals: false,
     renameGlobals: false,
     reservedNames: [],
     reservedNames: [],

+ 1 - 0
src/options/presets/NoCustomNodes.ts

@@ -15,6 +15,7 @@ export const NO_ADDITIONAL_NODES_PRESET: TInputOptions = Object.freeze({
     disableConsoleOutput: false,
     disableConsoleOutput: false,
     domainLock: [],
     domainLock: [],
     identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
     identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
+    identifiersPrefix: '',
     log: false,
     log: false,
     renameGlobals: false,
     renameGlobals: false,
     reservedNames: [],
     reservedNames: [],

+ 3 - 1
test/dev/dev.ts

@@ -16,7 +16,9 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
         `,
         `,
         {
         {
             ...NO_ADDITIONAL_NODES_PRESET,
             ...NO_ADDITIONAL_NODES_PRESET,
-            compact: false
+            compact: false,
+            identifiersPrefix: 'foo',
+            identifierNamesGenerator: 'mangled'
         }
         }
     ).getObfuscatedCode();
     ).getObfuscatedCode();
 
 

+ 17 - 5
test/unit-tests/options/OptionsNormalizer.spec.ts → test/functional-tests/options/OptionsNormalizer.spec.ts

@@ -1,28 +1,40 @@
+import 'reflect-metadata';
+
+import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
+
 import { assert } from 'chai';
 import { assert } from 'chai';
 
 
 import { TInputOptions } from '../../../src/types/options/TInputOptions';
 import { TInputOptions } from '../../../src/types/options/TInputOptions';
 
 
+import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
 import { IOptions } from '../../../src/interfaces/options/IOptions';
 import { IOptions } from '../../../src/interfaces/options/IOptions';
+import { IOptionsNormalizer } from '../../../src/interfaces/options/IOptionsNormalizer';
 
 
 import { StringArrayEncoding } from '../../../src/enums/StringArrayEncoding';
 import { StringArrayEncoding } from '../../../src/enums/StringArrayEncoding';
 
 
 import { DEFAULT_PRESET } from '../../../src/options/presets/Default';
 import { DEFAULT_PRESET } from '../../../src/options/presets/Default';
 
 
-import { Options } from '../../../src/options/Options';
-import { OptionsNormalizer } from '../../../src/options/OptionsNormalizer';
+import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
 
 
 /**
 /**
  * @param optionsPreset
  * @param optionsPreset
  * @returns {IOptions}
  * @returns {IOptions}
  */
  */
 function getNormalizedOptions (optionsPreset: TInputOptions): TInputOptions {
 function getNormalizedOptions (optionsPreset: TInputOptions): TInputOptions {
-    const options: IOptions = new Options(optionsPreset);
+    const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
+
+    inversifyContainerFacade.load('', optionsPreset);
+
+    const options: IOptions = inversifyContainerFacade
+        .get<IOptions>(ServiceIdentifiers.IOptions);
+    const optionsNormalizer: IOptionsNormalizer = inversifyContainerFacade
+        .get<IOptionsNormalizer>(ServiceIdentifiers.IOptionsNormalizer);
 
 
-    return OptionsNormalizer.normalizeOptions(options);
+    return optionsNormalizer.normalize(options);
 }
 }
 
 
 describe('OptionsNormalizer', () => {
 describe('OptionsNormalizer', () => {
-    describe('normalizeOptions (options: IObfuscatorOptions): IObfuscatorOptions', () => {
+    describe('normalize (options: IObfuscatorOptions): IObfuscatorOptions', () => {
         let optionsPreset: TInputOptions,
         let optionsPreset: TInputOptions,
             expectedOptionsPreset: TInputOptions;
             expectedOptionsPreset: TInputOptions;
 
 

+ 1 - 1
test/index.spec.ts

@@ -24,7 +24,6 @@ import './unit-tests/node/node-guards/NodeGuards.spec';
 import './unit-tests/node/node-utils/NodeUtils.spec';
 import './unit-tests/node/node-utils/NodeUtils.spec';
 import './unit-tests/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.spec';
 import './unit-tests/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.spec';
 import './unit-tests/obfuscation-result/ObfuscationResult.spec';
 import './unit-tests/obfuscation-result/ObfuscationResult.spec';
-import './unit-tests/options/OptionsNormalizer.spec';
 import './unit-tests/options/ValidationErrorsFormatter.spec';
 import './unit-tests/options/ValidationErrorsFormatter.spec';
 import './unit-tests/source-map/SourceMapCorrector.spec';
 import './unit-tests/source-map/SourceMapCorrector.spec';
 import './unit-tests/storages/ArrayStorage.spec';
 import './unit-tests/storages/ArrayStorage.spec';
@@ -68,6 +67,7 @@ import './functional-tests/node-transformers/preparing-transformers/eval-call-ex
 import './functional-tests/node-transformers/preparing-transformers/comments-transformer/CommentsTransformer.spec';
 import './functional-tests/node-transformers/preparing-transformers/comments-transformer/CommentsTransformer.spec';
 import './functional-tests/node-transformers/preparing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec';
 import './functional-tests/node-transformers/preparing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec';
 import './functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec';
 import './functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec';
+import './functional-tests/options/OptionsNormalizer.spec';
 import './functional-tests/templates/debug-protection-nodes/DebugProtectionFunctionCallTemplate.spec';
 import './functional-tests/templates/debug-protection-nodes/DebugProtectionFunctionCallTemplate.spec';
 import './functional-tests/templates/domain-lock-nodes/DomainLockNodeTemplate.spec';
 import './functional-tests/templates/domain-lock-nodes/DomainLockNodeTemplate.spec';
 import './functional-tests/templates/GlobalVariableNoEvalTemplate.spec';
 import './functional-tests/templates/GlobalVariableNoEvalTemplate.spec';

+ 56 - 25
test/unit-tests/generators/identifier-names-generators/HexadecimalIdentifierNamesGenerator.spec.ts

@@ -13,40 +13,71 @@ import { InversifyContainerFacade } from '../../../../src/container/InversifyCon
 
 
 describe('HexadecimalIdentifierNamesGenerator', () => {
 describe('HexadecimalIdentifierNamesGenerator', () => {
     describe('generate (length: number): string', () => {
     describe('generate (length: number): string', () => {
-        let identifierNamesGenerator: IIdentifierNamesGenerator,
-            hexadecimalIdentifierName: string,
-            regExp: RegExp;
-
-        before(() => {
-            const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
-
-            inversifyContainerFacade.load('', {});
-            identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
-                ServiceIdentifiers.IIdentifierNamesGenerator,
-                IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
-            )
-        });
+        describe('Hexadecimal name without prefix', () => {
+            let identifierNamesGenerator: IIdentifierNamesGenerator,
+                hexadecimalIdentifierName: string,
+                regExp: RegExp;
 
 
-        describe('variant #1: hexadecimal name with length `4`', () => {
             before(() => {
             before(() => {
-                hexadecimalIdentifierName = identifierNamesGenerator.generate(4);
-                regExp = /^_0x(\w){4}$/;
+                const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
+
+                inversifyContainerFacade.load('', {});
+                identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
+                    ServiceIdentifiers.IIdentifierNamesGenerator,
+                    IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
+                )
+            });
+
+            describe('variant #1: hexadecimal name with length `4`', () => {
+                before(() => {
+                    hexadecimalIdentifierName = identifierNamesGenerator.generate(4);
+                    regExp = /^_0x(\w){4}$/;
+                });
+
+                it('should return hexadecimal name', () => {
+                    assert.match(hexadecimalIdentifierName, regExp);
+                })
             });
             });
 
 
-            it('should return hexadecimal name', () => {
-                assert.match(hexadecimalIdentifierName, regExp);
-            })
+            describe('variant #2: hexadecimal name with length `6`', () => {
+                before(() => {
+                    hexadecimalIdentifierName = identifierNamesGenerator.generate(6);
+                    regExp = /^_0x(\w){4,6}$/;
+                });
+
+                it('should return hexadecimal name', () => {
+                    assert.match(hexadecimalIdentifierName, regExp);
+                })
+            });
         });
         });
 
 
-        describe('variant #2: hexadecimal name with length `6`', () => {
+        describe('Hexadecimal name with prefix', () => {
+            let identifierNamesGenerator: IIdentifierNamesGenerator,
+                hexadecimalIdentifierName: string,
+                regExp: RegExp;
+
             before(() => {
             before(() => {
-                hexadecimalIdentifierName = identifierNamesGenerator.generate(6);
-                regExp = /^_0x(\w){4,6}$/;
+                const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
+
+                inversifyContainerFacade.load('', {
+                    identifiersPrefix: 'foo'
+                });
+                identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
+                    ServiceIdentifiers.IIdentifierNamesGenerator,
+                    IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
+                )
             });
             });
 
 
-            it('should return hexadecimal name', () => {
-                assert.match(hexadecimalIdentifierName, regExp);
-            })
+            describe('variant #1: hexadecimal name with prefix', () => {
+                before(() => {
+                    hexadecimalIdentifierName = identifierNamesGenerator.generate(6);
+                    regExp = /^foo_0x(\w){4,6}$/;
+                });
+
+                it('should return hexadecimal name', () => {
+                    assert.match(hexadecimalIdentifierName, regExp);
+                })
+            });
         });
         });
     });
     });
 });
 });

+ 112 - 81
test/unit-tests/generators/identifier-names-generators/MangledlIdentifierNamesGenerator.spec.ts

@@ -13,118 +13,149 @@ import { InversifyContainerFacade } from '../../../../src/container/InversifyCon
 
 
 describe('MangledIdentifierNamesGenerator', () => {
 describe('MangledIdentifierNamesGenerator', () => {
     describe('generate (length: number): string', () => {
     describe('generate (length: number): string', () => {
-        let identifierNamesGenerator: IIdentifierNamesGenerator,
-            mangledIdentifierName: string;
+        describe('Mangled name without prefix', () => {
+            let identifierNamesGenerator: IIdentifierNamesGenerator,
+                mangledIdentifierName: string;
 
 
-        beforeEach(() => {
-            const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
+            beforeEach(() => {
+                const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
 
 
-            inversifyContainerFacade.load('', {});
-            identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
-                ServiceIdentifiers.IIdentifierNamesGenerator,
-                IdentifierNamesGenerator.MangledIdentifierNamesGenerator
-            );
-        });
+                inversifyContainerFacade.load('', {});
+                identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
+                    ServiceIdentifiers.IIdentifierNamesGenerator,
+                    IdentifierNamesGenerator.MangledIdentifierNamesGenerator
+                );
+            });
 
 
-        describe('variant #1: initial mangled name', () => {
-            const expectedMangledIdentifierName: string = 'a';
+            describe('variant #1: initial mangled name', () => {
+                const expectedMangledIdentifierName: string = 'a';
 
 
-            beforeEach(() => {
-                mangledIdentifierName = identifierNamesGenerator.generate(4);
-            });
+                beforeEach(() => {
+                    mangledIdentifierName = identifierNamesGenerator.generate(4);
+                });
 
 
-            it('should return mangled name', () => {
-                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                it('should return mangled name', () => {
+                    assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                });
             });
             });
-        });
 
 
-        describe('variant #2: second mangled name', () => {
-            const expectedMangledIdentifierName: string = 'b';
-            const expectedMangledIdentifierPosition: number = 1;
+            describe('variant #2: second mangled name', () => {
+                const expectedMangledIdentifierName: string = 'b';
+                const expectedMangledIdentifierPosition: number = 1;
 
 
-            beforeEach(() => {
-                for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
-                    mangledIdentifierName = identifierNamesGenerator.generate(6);
-                }
-            });
+                beforeEach(() => {
+                    for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
+                        mangledIdentifierName = identifierNamesGenerator.generate(6);
+                    }
+                });
 
 
-            it('should return mangled name', () => {
-                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                it('should return mangled name', () => {
+                    assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                });
             });
             });
-        });
 
 
-        describe('variant #3: last mangled name with single character', () => {
-            const expectedMangledIdentifierName: string = 'Z';
-            const expectedMangledIdentifierPosition: number = 51;
+            describe('variant #3: last mangled name with single character', () => {
+                const expectedMangledIdentifierName: string = 'Z';
+                const expectedMangledIdentifierPosition: number = 51;
 
 
-            beforeEach(() => {
-                for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
-                    mangledIdentifierName = identifierNamesGenerator.generate(6);
-                }
-            });
+                beforeEach(() => {
+                    for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
+                        mangledIdentifierName = identifierNamesGenerator.generate(6);
+                    }
+                });
 
 
-            it('should return mangled name', () => {
-                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                it('should return mangled name', () => {
+                    assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                });
             });
             });
-        });
 
 
-        describe('variant #4: correct increase of mangled name length', () => {
-            const expectedMangledIdentifierName: string = 'a0';
-            const expectedMangledIdentifierPosition: number = 52;
+            describe('variant #4: correct increase of mangled name length', () => {
+                const expectedMangledIdentifierName: string = 'a0';
+                const expectedMangledIdentifierPosition: number = 52;
 
 
-            beforeEach(() => {
-                for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
-                    mangledIdentifierName = identifierNamesGenerator.generate(6);
-                }
-            });
+                beforeEach(() => {
+                    for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
+                        mangledIdentifierName = identifierNamesGenerator.generate(6);
+                    }
+                });
 
 
-            it('should return mangled name', () => {
-                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                it('should return mangled name', () => {
+                    assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                });
             });
             });
-        });
 
 
-        describe('variant #5: correct increase of mangled name length #2', () => {
-            const expectedMangledIdentifierName: string = 'aa';
-            const expectedMangledIdentifierPosition: number = 62;
+            describe('variant #5: correct increase of mangled name length #2', () => {
+                const expectedMangledIdentifierName: string = 'aa';
+                const expectedMangledIdentifierPosition: number = 62;
 
 
-            beforeEach(() => {
-                for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
-                    mangledIdentifierName = identifierNamesGenerator.generate(6);
-                }
-            });
+                beforeEach(() => {
+                    for (let i: number = 0; i <= expectedMangledIdentifierPosition; i++) {
+                        mangledIdentifierName = identifierNamesGenerator.generate(6);
+                    }
+                });
 
 
-            it('should return mangled name', () => {
-                assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                it('should return mangled name', () => {
+                    assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                });
             });
             });
-        });
 
 
-        describe('variant #6: reserved names', () => {
-            const expectedMangledIdentifierName1: string = 'dn';
-            const expectedMangledIdentifierName2: string = 'dp';
-            const expectedMangledIdentifierPosition1: number = 261;
-            const expectedMangledIdentifierPosition2: number = 262;
+            describe('variant #6: reserved names', () => {
+                const expectedMangledIdentifierName1: string = 'dn';
+                const expectedMangledIdentifierName2: string = 'dp';
+                const expectedMangledIdentifierPosition1: number = 261;
+                const expectedMangledIdentifierPosition2: number = 262;
 
 
-            let mangledIdentifierName1: string,
-                mangledIdentifierName2: string;
+                let mangledIdentifierName1: string,
+                    mangledIdentifierName2: string;
 
 
-            beforeEach(() => {
-                for (let i: number = 0; i <= expectedMangledIdentifierPosition2; i++) {
-                    mangledIdentifierName = identifierNamesGenerator.generate(6);
+                beforeEach(() => {
+                    for (let i: number = 0; i <= expectedMangledIdentifierPosition2; i++) {
+                        mangledIdentifierName = identifierNamesGenerator.generate(6);
 
 
-                    if (i === expectedMangledIdentifierPosition1) {
-                        mangledIdentifierName1 = mangledIdentifierName;
-                    } else if (i === expectedMangledIdentifierPosition2) {
-                        mangledIdentifierName2 = mangledIdentifierName;
+                        if (i === expectedMangledIdentifierPosition1) {
+                            mangledIdentifierName1 = mangledIdentifierName;
+                        } else if (i === expectedMangledIdentifierPosition2) {
+                            mangledIdentifierName2 = mangledIdentifierName;
+                        }
                     }
                     }
-                }
+                });
+
+                it('should return mangled name', () => {
+                    assert.equal(mangledIdentifierName1, expectedMangledIdentifierName1);
+                });
+
+                it('shouldn\'t return reserved mangled name', () => {
+                    assert.equal(mangledIdentifierName2, expectedMangledIdentifierName2);
+                });
             });
             });
+        });
+
+        describe('Mangled name with prefix', () => {
+            let identifierNamesGenerator: IIdentifierNamesGenerator,
+                mangledIdentifierName: string;
 
 
-            it('should return mangled name', () => {
-                assert.equal(mangledIdentifierName1, expectedMangledIdentifierName1);
+            beforeEach(() => {
+                const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
+
+                inversifyContainerFacade.load('', {
+                    identifiersPrefix: 'foo'
+                });
+                identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
+                    ServiceIdentifiers.IIdentifierNamesGenerator,
+                    IdentifierNamesGenerator.MangledIdentifierNamesGenerator
+                );
             });
             });
 
 
-            it('shouldn\'t return reserved mangled name', () => {
-                assert.equal(mangledIdentifierName2, expectedMangledIdentifierName2);
+            describe('variant #1: initial mangled name', () => {
+                const expectedMangledIdentifierName: string = 'foo_a';
+
+                beforeEach(() => {
+                    mangledIdentifierName = identifierNamesGenerator.generate(4);
+                });
+
+                it('should return mangled name', () => {
+                    assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
+                });
             });
             });
         });
         });
     });
     });

+ 23 - 11
yarn.lock

@@ -3107,9 +3107,9 @@ readdirp@^2.0.0:
     readable-stream "^2.0.2"
     readable-stream "^2.0.2"
     set-immediate-shim "^1.0.1"
     set-immediate-shim "^1.0.1"
 
 
[email protected]0:
-  version "0.1.10"
-  resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.10.tgz#b4f83704416acad89988c9b15635d47e03b9344a"
[email protected]2:
+  version "0.1.12"
+  resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.12.tgz#311bf0c6b63cd782f228a81abe146a2bfa9c56f2"
 
 
 regenerate@^1.2.1:
 regenerate@^1.2.1:
   version "1.3.3"
   version "1.3.3"
@@ -3329,16 +3329,16 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
   version "3.0.2"
   version "3.0.2"
   resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
   resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
 
 
[email protected].4:
-  version "4.1.4"
-  resolved "https://registry.yarnpkg.com/sinon/-/sinon-4.1.4.tgz#36bb237bae38ddf9cc92dcc1b16c51e7785bbc9c"
[email protected].6:
+  version "4.1.6"
+  resolved "https://registry.yarnpkg.com/sinon/-/sinon-4.1.6.tgz#9cb346bddb180d68a804429ffe14978d7fafd629"
   dependencies:
   dependencies:
     diff "^3.1.0"
     diff "^3.1.0"
     formatio "1.2.0"
     formatio "1.2.0"
     lodash.get "^4.4.2"
     lodash.get "^4.4.2"
     lolex "^2.2.0"
     lolex "^2.2.0"
     nise "^1.2.0"
     nise "^1.2.0"
-    supports-color "^4.4.0"
+    supports-color "^5.1.0"
     type-detect "^4.0.5"
     type-detect "^4.0.5"
 
 
 slash@^1.0.0:
 slash@^1.0.0:
@@ -3392,9 +3392,9 @@ source-map-resolve@^0.5.0:
     source-map-url "^0.4.0"
     source-map-url "^0.4.0"
     urix "^0.1.0"
     urix "^0.1.0"
 
 
[email protected].0, source-map-support@^0.5.0:
-  version "0.5.0"
-  resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.0.tgz#2018a7ad2bdf8faf2691e5fddab26bed5a2bacab"
[email protected].1:
+  version "0.5.1"
+  resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.1.tgz#72291517d1fd0cb9542cee6c27520884b5da1a07"
   dependencies:
   dependencies:
     source-map "^0.6.0"
     source-map "^0.6.0"
 
 
@@ -3404,6 +3404,12 @@ source-map-support@^0.4.15:
   dependencies:
   dependencies:
     source-map "^0.5.6"
     source-map "^0.5.6"
 
 
+source-map-support@^0.5.0:
+  version "0.5.0"
+  resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.0.tgz#2018a7ad2bdf8faf2691e5fddab26bed5a2bacab"
+  dependencies:
+    source-map "^0.6.0"
+
 source-map-url@^0.4.0:
 source-map-url@^0.4.0:
   version "0.4.0"
   version "0.4.0"
   resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
   resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
@@ -3576,12 +3582,18 @@ supports-color@^3.1.2:
   dependencies:
   dependencies:
     has-flag "^1.0.0"
     has-flag "^1.0.0"
 
 
-supports-color@^4.0.0, supports-color@^4.2.1, supports-color@^4.4.0:
+supports-color@^4.0.0, supports-color@^4.2.1:
   version "4.5.0"
   version "4.5.0"
   resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b"
   resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b"
   dependencies:
   dependencies:
     has-flag "^2.0.0"
     has-flag "^2.0.0"
 
 
+supports-color@^5.1.0:
+  version "5.1.0"
+  resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.1.0.tgz#058a021d1b619f7ddf3980d712ea3590ce7de3d5"
+  dependencies:
+    has-flag "^2.0.0"
+
 tapable@^0.2.5, tapable@^0.2.7:
 tapable@^0.2.5, tapable@^0.2.7:
   version "0.2.8"
   version "0.2.8"
   resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22"
   resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22"

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio