sanex3339 9 лет назад
Родитель
Сommit
3bfc3cf869

+ 2 - 1
dist/src/JavaScriptObfuscator.js

@@ -3,9 +3,10 @@ const esprima = require('esprima');
 const escodegen = require('escodegen');
 const DefaultPreset_1 = require('./preset-options/DefaultPreset');
 const Obfuscator_1 = require('./Obfuscator');
+const OptionsNormalizer_1 = require("./OptionsNormalizer");
 class JavaScriptObfuscator {
     static obfuscate(sourceCode, customOptions) {
-        let astTree = esprima.parse(sourceCode), options = Object.assign({}, DefaultPreset_1.DEFAULT_PRESET, customOptions), obfuscator = new Obfuscator_1.Obfuscator(options);
+        let astTree = esprima.parse(sourceCode), options = OptionsNormalizer_1.OptionsNormalizer.normalize(Object.assign({}, DefaultPreset_1.DEFAULT_PRESET, customOptions)), obfuscator = new Obfuscator_1.Obfuscator(options);
         astTree = obfuscator.obfuscateNode(astTree);
         return JavaScriptObfuscator.generateCode(astTree, options);
     }

+ 21 - 0
dist/src/OptionsNormalizer.js

@@ -0,0 +1,21 @@
+"use strict";
+class OptionsNormalizer {
+    static normalize(options) {
+        let normalizedOptions = Object.assign({}, options);
+        normalizedOptions = OptionsNormalizer.unicodeArrayRule(normalizedOptions);
+        return normalizedOptions;
+    }
+    static unicodeArrayRule(options) {
+        const disabledUnicodeArrayOptions = {
+            encodeUnicodeLiterals: false,
+            rotateUnicodeArray: false,
+            unicodeArray: false,
+            wrapUnicodeArrayCalls: false
+        };
+        if (!options['unicodeArray']) {
+            Object.assign(options, disabledUnicodeArrayOptions);
+        }
+        return options;
+    }
+}
+exports.OptionsNormalizer = OptionsNormalizer;

+ 1 - 1
dist/src/node-groups/UnicodeArrayNodesGroup.js

@@ -19,7 +19,7 @@ class UnicodeArrayNodesGroup extends NodesGroup_1.NodesGroup {
         if (this.options['wrapUnicodeArrayCalls']) {
             this.nodes.set('unicodeArrayCallsWrapper', new UnicodeArrayCallsWrapper_1.UnicodeArrayCallsWrapper(this.unicodeArrayTranslatorName, this.unicodeArrayName, unicodeArray));
         }
-        if (this.options['encodeUnicodeArray']) {
+        if (this.options['encodeUnicodeLiterals']) {
             this.nodes.set('unicodeArrayDecodeNode', new UnicodeArrayDecodeNode_1.UnicodeArrayDecodeNode(this.unicodeArrayName, unicodeArray));
         }
         if (this.options['rotateUnicodeArray']) {

+ 1 - 1
dist/src/node-obfuscators/NodeObfuscator.js

@@ -31,7 +31,7 @@ class NodeObfuscator {
     }
     replaceLiteralValueByUnicodeValue(nodeValue) {
         let value = nodeValue;
-        if (this.options['unicodeArray'] && this.options['encodeUnicodeArray']) {
+        if (this.options['encodeUnicodeLiterals']) {
             value = new Buffer(encodeURI(value)).toString('base64');
         }
         value = Utils_1.Utils.stringToUnicode(value);

+ 1 - 1
dist/src/preset-options/DefaultPreset.js

@@ -4,8 +4,8 @@ exports.DEFAULT_PRESET = Object.freeze({
     debugProtection: false,
     debugProtectionInterval: false,
     disableConsoleOutput: true,
-    encodeUnicodeArray: false,
     rotateUnicodeArray: true,
+    encodeUnicodeLiterals: false,
     unicodeArray: true,
     wrapUnicodeArrayCalls: true
 });

+ 1 - 1
dist/src/preset-options/NoCustomNodesPreset.js

@@ -4,8 +4,8 @@ exports.NO_CUSTOM_NODES_PRESET = Object.freeze({
     debugProtection: false,
     debugProtectionInterval: false,
     disableConsoleOutput: false,
-    encodeUnicodeArray: false,
     rotateUnicodeArray: false,
+    encodeUnicodeLiterals: false,
     unicodeArray: false,
     wrapUnicodeArrayCalls: false
 });

+ 1 - 1
dist/tests/dev-test.js

@@ -48,7 +48,7 @@ let obfuscatedCode = JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(`
     })();
     `, {
     disableConsoleOutput: false,
-    encodeUnicodeArray: true
+    encodeUnicodeLiterals: true
 });
 console.log(obfuscatedCode);
 console.log(eval(obfuscatedCode));

+ 2 - 1
src/JavaScriptObfuscator.ts

@@ -9,6 +9,7 @@ import { IOptions } from './interfaces/IOptions';
 import { DEFAULT_PRESET } from './preset-options/DefaultPreset';
 
 import { Obfuscator } from './Obfuscator';
+import { OptionsNormalizer } from "./OptionsNormalizer";
 
 export class JavaScriptObfuscator {
     /**
@@ -24,7 +25,7 @@ export class JavaScriptObfuscator {
      */
     public static obfuscate (sourceCode: string, customOptions?: IOptions): string {
         let astTree: INode = esprima.parse(sourceCode),
-            options: any = Object.assign({}, DEFAULT_PRESET, customOptions),
+            options: IOptions = OptionsNormalizer.normalize(Object.assign({}, DEFAULT_PRESET, customOptions)),
             obfuscator: Obfuscator = new Obfuscator(options);
 
         astTree = obfuscator.obfuscateNode(astTree);

+ 30 - 0
src/OptionsNormalizer.ts

@@ -0,0 +1,30 @@
+import { IOptions } from "./interfaces/IOptions";
+
+export class OptionsNormalizer {
+    public static normalize (options: IOptions): IOptions {
+        let normalizedOptions: IOptions = Object.assign({}, options);
+        
+        normalizedOptions = OptionsNormalizer.unicodeArrayRule(normalizedOptions);
+        
+        return normalizedOptions;
+    }
+
+    /**
+     * @param options
+     * @returns {IOptions}
+     */
+    private static unicodeArrayRule (options: IOptions): IOptions {
+        const disabledUnicodeArrayOptions: {[index: string]: boolean} = {
+            encodeUnicodeLiterals: false,
+            rotateUnicodeArray: false,
+            unicodeArray: false,
+            wrapUnicodeArrayCalls: false
+        };
+        
+        if (!options['unicodeArray']) {
+            Object.assign(options, disabledUnicodeArrayOptions);
+        }
+        
+        return options;
+    }
+}

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

@@ -3,8 +3,8 @@ export interface IOptions {
     debugProtection?: boolean;
     debugProtectionInterval?: boolean;
     disableConsoleOutput?: boolean;
-    encodeUnicodeArray?: boolean;
     rotateUnicodeArray?: boolean;
+    encodeUnicodeLiterals?: boolean;
     unicodeArray?: boolean;
     wrapUnicodeArrayCalls?: boolean;
 }

+ 1 - 1
src/node-groups/UnicodeArrayNodesGroup.ts

@@ -57,7 +57,7 @@ export class UnicodeArrayNodesGroup extends NodesGroup {
             );
         }
 
-        if (this.options['encodeUnicodeArray']) {
+        if (this.options['encodeUnicodeLiterals']) {
             this.nodes.set(
                 'unicodeArrayDecodeNode',
                 new UnicodeArrayDecodeNode (

+ 1 - 1
src/node-obfuscators/NodeObfuscator.ts

@@ -88,7 +88,7 @@ export abstract class NodeObfuscator implements INodeObfuscator {
     protected replaceLiteralValueByUnicodeValue (nodeValue: string): string {
         let value: string = nodeValue;
 
-        if (this.options['unicodeArray'] && this.options['encodeUnicodeArray']) {
+        if (this.options['encodeUnicodeLiterals']) {
             value = new Buffer(encodeURI(value)).toString('base64');
         }
 

+ 1 - 1
src/preset-options/DefaultPreset.ts

@@ -5,8 +5,8 @@ export const DEFAULT_PRESET: IOptions = Object.freeze({
     debugProtection: false,
     debugProtectionInterval: false,
     disableConsoleOutput: true,
-    encodeUnicodeArray: false,
     rotateUnicodeArray: true,
+    encodeUnicodeLiterals: false,
     unicodeArray: true,
     wrapUnicodeArrayCalls: true
 });

+ 1 - 1
src/preset-options/NoCustomNodesPreset.ts

@@ -5,8 +5,8 @@ export const NO_CUSTOM_NODES_PRESET: IOptions = Object.freeze({
     debugProtection: false,
     debugProtectionInterval: false,
     disableConsoleOutput: false,
-    encodeUnicodeArray: false,
     rotateUnicodeArray: false,
+    encodeUnicodeLiterals: false,
     unicodeArray: false,
     wrapUnicodeArrayCalls: false
 });

+ 1 - 1
tests/dev-test.ts

@@ -50,7 +50,7 @@ let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
     `,
     {
         disableConsoleOutput: false,
-        encodeUnicodeArray: true
+        encodeUnicodeLiterals: true
     }
 );