sanex3339 9 anni fa
parent
commit
f00cee7058

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

@@ -9,19 +9,19 @@ class UnicodeArrayNodesGroup extends NodesGroup_1.NodesGroup {
     constructor(options = {}) {
         super(options);
         this.unicodeArrayName = Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH);
-        this.unicodeArrayRotateValue = Utils_1.Utils.getRandomInteger(100, 500);
         this.unicodeArrayTranslatorName = Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH);
+        this.unicodeArrayRotateValue = this.options['rotateUnicodeArray'] ? Utils_1.Utils.getRandomInteger(100, 500) : 0;
         let unicodeArrayNode = new UnicodeArrayNode_1.UnicodeArrayNode(this.unicodeArrayName, this.unicodeArrayRotateValue), unicodeArray = unicodeArrayNode.getNodeData();
         this.nodes.set('unicodeArrayNode', unicodeArrayNode);
         if (this.options['wrapUnicodeArrayCalls']) {
             this.nodes.set('unicodeArrayCallsWrapper', new UnicodeArrayCallsWrapper_1.UnicodeArrayCallsWrapper(this.unicodeArrayTranslatorName, this.unicodeArrayName, unicodeArray));
         }
-        if (this.options['rotateUnicodeArray']) {
-            this.nodes.set('unicodeArrayRotateFunctionNode', new UnicodeArrayRotateFunctionNode_1.UnicodeArrayRotateFunctionNode(this.unicodeArrayName, unicodeArray, this.unicodeArrayRotateValue));
-        }
         if (this.options['encodeUnicodeArray']) {
             this.nodes.set('unicodeArrayDecodeNode', new UnicodeArrayDecodeNode_1.UnicodeArrayDecodeNode(this.unicodeArrayName, unicodeArray));
         }
+        if (this.options['rotateUnicodeArray']) {
+            this.nodes.set('unicodeArrayRotateFunctionNode', new UnicodeArrayRotateFunctionNode_1.UnicodeArrayRotateFunctionNode(this.unicodeArrayName, unicodeArray, this.unicodeArrayRotateValue));
+        }
     }
 }
 exports.UnicodeArrayNodesGroup = UnicodeArrayNodesGroup;

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

@@ -46,8 +46,7 @@ let JavaScriptObfuscator = require('../index'), obfuscatedCode = JavaScriptObfus
     })();
     `, {
     disableConsoleOutput: false,
-    encodeUnicodeArray: true,
-    rotateUnicodeArray: false
+    encodeUnicodeArray: true
 });
 console.log(obfuscatedCode);
 console.log(eval(obfuscatedCode));

+ 2 - 1
src/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.ts

@@ -68,7 +68,8 @@ export class UnicodeArrayDecodeNode extends Node {
             indexVariableName: string = Utils.getRandomVariableName(),
             node: INode = esprima.parse(`
                 (function () {
-                    !function(){function t(t){this.message=t}var r=[]["filter"]["constructor"]("return this")(),e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.prototype=new Error,t.prototype.name="InvalidCharacterError",r.atob||(r.atob=function(r){var o=String(r).replace(/=+$/,"");if(o.length%4==1)throw new t("Have a nice day!");for(var n,a,i=0,c=0,d="";a=o.charAt(c++);~a&&(n=i%4?64*n+a:a,i++%4)?d+=String.fromCharCode(255&n>>(-2*i&6)):0)a=e.indexOf(a);return d})}(); 
+                    //atob polyfill
+                    !function(){function t(t){this.message=t}var r=[]["filter"]["constructor"]("return this")(),e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.atob||(r.atob=function(r){var o=String(r).replace(/=+$/,"");for(var n,a,i=0,c=0,d="";a=o.charAt(c++);~a&&(n=i%4?64*n+a:a,i++%4)?d+=String.fromCharCode(255&n>>(-2*i&6)):0)a=e.indexOf(a);return d})}(); 
                     
                     var ${decodedTempArrayName} = [];
                     

+ 12 - 10
src/node-groups/UnicodeArrayNodesGroup.ts

@@ -16,7 +16,7 @@ export class UnicodeArrayNodesGroup extends NodesGroup {
     /**
      * @type {number}
      */
-    private unicodeArrayRotateValue: number = Utils.getRandomInteger(100, 500);
+    private unicodeArrayRotateValue: number;
 
     /**
      * @type {string}
@@ -29,6 +29,8 @@ export class UnicodeArrayNodesGroup extends NodesGroup {
     constructor (options: IOptions = {}) {
         super(options);
 
+        this.unicodeArrayRotateValue = this.options['rotateUnicodeArray'] ? Utils.getRandomInteger(100, 500) : 0;
+
         let unicodeArrayNode: UnicodeArrayNode = new UnicodeArrayNode(
                 this.unicodeArrayName,
                 this.unicodeArrayRotateValue
@@ -51,23 +53,23 @@ export class UnicodeArrayNodesGroup extends NodesGroup {
             );
         }
 
-        if (this.options['rotateUnicodeArray']) {
+        if (this.options['encodeUnicodeArray']) {
             this.nodes.set(
-                'unicodeArrayRotateFunctionNode',
-                new UnicodeArrayRotateFunctionNode(
+                'unicodeArrayDecodeNode',
+                new UnicodeArrayDecodeNode (
                     this.unicodeArrayName,
-                    unicodeArray,
-                    this.unicodeArrayRotateValue
+                    unicodeArray
                 )
             );
         }
 
-        if (this.options['encodeUnicodeArray']) {
+        if (this.options['rotateUnicodeArray']) {
             this.nodes.set(
-                'unicodeArrayDecodeNode',
-                new UnicodeArrayDecodeNode (
+                'unicodeArrayRotateFunctionNode',
+                new UnicodeArrayRotateFunctionNode(
                     this.unicodeArrayName,
-                    unicodeArray
+                    unicodeArray,
+                    this.unicodeArrayRotateValue
                 )
             );
         }

+ 1 - 2
tests/dev-test.ts

@@ -49,8 +49,7 @@ let JavaScriptObfuscator: any = require('../index'),
     `,
     {
         disableConsoleOutput: false,
-        encodeUnicodeArray: true,
-        rotateUnicodeArray: false
+        encodeUnicodeArray: true
     }
 );