sanex3339 9 gadi atpakaļ
vecāks
revīzija
39f3741d0d

+ 3 - 0
dist/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.js

@@ -31,6 +31,9 @@ class UnicodeArrayNode extends Node_1.Node {
         this.updateNode();
         return super.getNode();
     }
+    updateNodeData(data) {
+        this.unicodeArray.push(data);
+    }
     getNodeStructure() {
         return {
             'type': NodeType_1.NodeType.VariableDeclaration,

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

@@ -41,19 +41,19 @@ class NodeObfuscator {
         return this.replaceLiteralValueByUnicodeArrayCall(value);
     }
     replaceLiteralValueByUnicodeArrayCall(value) {
-        let unicodeArray = this.nodes.get('unicodeArrayNode').getNodeData(), sameIndex = unicodeArray.indexOf(value), index, hexadecimalIndex;
-        if (sameIndex < 0) {
-            index = unicodeArray.length;
-            unicodeArray.push(value);
+        let unicodeArrayNode = this.nodes.get('unicodeArrayNode'), unicodeArray = unicodeArrayNode.getNodeData(), sameIndex = unicodeArray.indexOf(value), index, hexadecimalIndex;
+        if (sameIndex >= 0) {
+            index = sameIndex;
         }
         else {
-            index = sameIndex;
+            index = unicodeArray.length;
+            unicodeArrayNode.updateNodeData(value);
         }
         hexadecimalIndex = this.replaceLiteralNumberByHexadecimalValue(index);
         if (this.options['wrapUnicodeArrayCalls']) {
             return `${this.nodes.get('unicodeArrayCallsWrapper').getNodeIdentifier()}('${hexadecimalIndex}')`;
         }
-        return `${this.nodes.get('unicodeArrayNode').getNodeIdentifier()}[${hexadecimalIndex}]`;
+        return `${unicodeArrayNode.getNodeIdentifier()}[${hexadecimalIndex}]`;
     }
 }
 exports.NodeObfuscator = NodeObfuscator;

+ 7 - 0
src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.ts

@@ -87,6 +87,13 @@ export class UnicodeArrayNode extends Node {
         return super.getNode();
     }
 
+    /**
+     * @param data
+     */
+    public updateNodeData (data: string): void {
+        this.unicodeArray.push(data);
+    }
+
     /**
      * @returns {INode}
      */

+ 5 - 0
src/interfaces/ICustomNode.d.ts

@@ -34,4 +34,9 @@ export interface ICustomNode {
     setNode (node: INode): void;
 
     updateNode (): void;
+
+    /**
+     * @param data
+     */
+    updateNodeData ? (data: any): void;
 }

+ 8 - 6
src/node-obfuscators/NodeObfuscator.ts

@@ -7,6 +7,7 @@ import { JSFuck } from "../enums/JSFuck";
 
 import { NodeUtils } from "../NodeUtils";
 import { Utils } from '../Utils';
+import {UnicodeArrayNode} from "../custom-nodes/unicode-array-nodes/UnicodeArrayNode";
 
 export abstract class NodeObfuscator implements INodeObfuscator {
     /**
@@ -106,16 +107,17 @@ export abstract class NodeObfuscator implements INodeObfuscator {
      * @returns {string}
      */
     protected replaceLiteralValueByUnicodeArrayCall (value: string): string {
-        let unicodeArray: string[] = this.nodes.get('unicodeArrayNode').getNodeData(),
+        let unicodeArrayNode: UnicodeArrayNode = <UnicodeArrayNode> this.nodes.get('unicodeArrayNode'),
+            unicodeArray: string[] = unicodeArrayNode.getNodeData(),
             sameIndex: number = unicodeArray.indexOf(value),
             index: number,
             hexadecimalIndex: string;
 
-        if (sameIndex < 0) {
-            index = unicodeArray.length;
-            unicodeArray.push(value);
-        } else {
+        if (sameIndex >= 0) {
             index = sameIndex;
+        } else {
+            index = unicodeArray.length;
+            unicodeArrayNode.updateNodeData(value);
         }
 
         hexadecimalIndex = this.replaceLiteralNumberByHexadecimalValue(index);
@@ -124,6 +126,6 @@ export abstract class NodeObfuscator implements INodeObfuscator {
             return `${this.nodes.get('unicodeArrayCallsWrapper').getNodeIdentifier()}('${hexadecimalIndex}')`;
         }
 
-        return `${this.nodes.get('unicodeArrayNode').getNodeIdentifier()}[${hexadecimalIndex}]`;
+        return `${unicodeArrayNode.getNodeIdentifier()}[${hexadecimalIndex}]`;
     }
 }