Sfoglia il codice sorgente

selfDefending test implementation

sanex3339 9 anni fa
parent
commit
63ad322832

+ 17 - 2
dist/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.js

@@ -5,6 +5,7 @@ const NoCustomNodesPreset_1 = require("../../preset-options/NoCustomNodesPreset"
 const JavaScriptObfuscator_1 = require("../../JavaScriptObfuscator");
 const Node_1 = require('../Node');
 const NodeUtils_1 = require("../../NodeUtils");
+const Utils_1 = require("../../Utils");
 class SelfDefendingUnicodeNode extends Node_1.Node {
     constructor(options = {}) {
         super(options);
@@ -12,11 +13,25 @@ class SelfDefendingUnicodeNode extends Node_1.Node {
         this.node = this.getNodeStructure();
     }
     appendNode(blockScopeNode) {
-        NodeUtils_1.NodeUtils.prependNode(blockScopeNode.body, this.getNode());
+        let programBodyLength = blockScopeNode.body.length, randomIndex = 0;
+        if (programBodyLength > 2) {
+            randomIndex = Utils_1.Utils.getRandomInteger(programBodyLength, programBodyLength / 2);
+        }
+        NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), randomIndex);
     }
     getNodeStructure() {
         let node = esprima.parse(JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(`
-               
+                (function () {                                
+                    var func = function () {
+                        return '\x77\x69\x6e\x64\x6f\x77';
+                    };
+                                        
+                    if (
+                        !/(\\\\\[x|u](\\w){2,4})+/.test(func.toString())
+                    ) {
+                        console.log('LOL');
+                    }
+                })();
             `, NoCustomNodesPreset_1.NO_CUSTOM_NODES_PRESET));
         NodeUtils_1.NodeUtils.addXVerbatimPropertyToLiterals(node);
         return NodeUtils_1.NodeUtils.getBlockScopeNodeByIndex(node);

+ 6 - 6
dist/src/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.js

@@ -35,12 +35,12 @@ class UnicodeArrayCallsWrapper extends Node_1.Node {
                                                                       
                 if (
                     ${keyName} % ${Utils_1.Utils.getRandomInteger(this.unicodeArray.length / 8, this.unicodeArray.length / 2)} === 0 &&
-                    /\\w+ *\\(\\) *{\\w+ *['|"].+['|"];? *}/.test(
-                        ${environmentName}[${Utils_1.Utils.stringToUnicode('toString')}]()
-                    ) === true || ${keyName}++
-                ) {
-                    return ${this.unicodeArrayName}[parseInt(${keyName}, 16)];
-                }
+                    (
+                        /\\w+ *\\(\\) *{\\w+ *['|"].+['|"];? *}/.test(
+                            ${environmentName}[${Utils_1.Utils.stringToUnicode('toString')}]()
+                        ) === true || ${keyName}++
+                    )
+                );
                 
                 return ${this.unicodeArrayName}[parseInt(${keyName}, 16)];
             `;

+ 21 - 3
src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts

@@ -12,6 +12,7 @@ import { NO_CUSTOM_NODES_PRESET } from "../../preset-options/NoCustomNodesPreset
 import { JavaScriptObfuscator } from "../../JavaScriptObfuscator";
 import { Node } from '../Node';
 import { NodeUtils } from "../../NodeUtils";
+import { Utils } from "../../Utils";
 
 export class SelfDefendingUnicodeNode extends Node {
     /**
@@ -32,7 +33,14 @@ export class SelfDefendingUnicodeNode extends Node {
      * @param blockScopeNode
      */
     public appendNode (blockScopeNode: TBlockScopeNode): void {
-        NodeUtils.prependNode(blockScopeNode.body, this.getNode());
+        let programBodyLength: number = blockScopeNode.body.length,
+            randomIndex: number = 0;
+
+        if (programBodyLength > 2) {
+            randomIndex = Utils.getRandomInteger(programBodyLength, programBodyLength / 2);
+        }
+
+        NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), randomIndex);
     }
 
     /**
@@ -40,8 +48,18 @@ export class SelfDefendingUnicodeNode extends Node {
      */
     protected getNodeStructure (): INode {
         let node: INode = esprima.parse(
-             JavaScriptObfuscator.obfuscate(`
-               
+            JavaScriptObfuscator.obfuscate(`
+                (function () {                                
+                    var func = function () {
+                        return '\x77\x69\x6e\x64\x6f\x77';
+                    };
+                                        
+                    if (
+                        !/(\\\\\[x|u](\\w){2,4})+/.test(func.toString())
+                    ) {
+                        console.log('LOL');
+                    }
+                })();
             `, NO_CUSTOM_NODES_PRESET)
         );
 

+ 6 - 6
src/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.ts

@@ -95,12 +95,12 @@ export class UnicodeArrayCallsWrapper extends Node {
                                                                       
                 if (
                     ${keyName} % ${Utils.getRandomInteger(this.unicodeArray.length / 8, this.unicodeArray.length / 2)} === 0 &&
-                    /\\w+ *\\(\\) *{\\w+ *['|"].+['|"];? *}/.test(
-                        ${environmentName}[${Utils.stringToUnicode('toString')}]()
-                    ) === true || ${keyName}++
-                ) {
-                    return ${this.unicodeArrayName}[parseInt(${keyName}, 16)];
-                }
+                    (
+                        /\\w+ *\\(\\) *{\\w+ *['|"].+['|"];? *}/.test(
+                            ${environmentName}[${Utils.stringToUnicode('toString')}]()
+                        ) === true || ${keyName}++
+                    )
+                );
                 
                 return ${this.unicodeArrayName}[parseInt(${keyName}, 16)];
             `;