diff --git a/dist/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.js b/dist/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.js index 2538f921..bb890ce5 100644 --- a/dist/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.js +++ b/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, diff --git a/dist/src/node-obfuscators/NodeObfuscator.js b/dist/src/node-obfuscators/NodeObfuscator.js index d988d504..c925f3df 100644 --- a/dist/src/node-obfuscators/NodeObfuscator.js +++ b/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; diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.ts b/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.ts index 4f51a2fa..9680c195 100644 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.ts +++ b/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} */ diff --git a/src/interfaces/ICustomNode.d.ts b/src/interfaces/ICustomNode.d.ts index c46b4b59..04c93bc8 100644 --- a/src/interfaces/ICustomNode.d.ts +++ b/src/interfaces/ICustomNode.d.ts @@ -34,4 +34,9 @@ export interface ICustomNode { setNode (node: INode): void; updateNode (): void; + + /** + * @param data + */ + updateNodeData ? (data: any): void; } diff --git a/src/node-obfuscators/NodeObfuscator.ts b/src/node-obfuscators/NodeObfuscator.ts index 27f42395..5b489dd9 100644 --- a/src/node-obfuscators/NodeObfuscator.ts +++ b/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 = 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}]`; } }