Selaa lähdekoodia

Merge pull request #140 from javascript-obfuscator/0.12.5

0.12.5 release
Timofey Kachalov 7 vuotta sitten
vanhempi
commit
ae507adb86

+ 4 - 0
CHANGELOG.md

@@ -1,5 +1,9 @@
 Change Log
 ===
+v0.12.5
+---
+* https://github.com/javascript-obfuscator/javascript*-obfuscator/issues/139
+
 v0.12.4
 ---
 * https://github.com/javascript-obfuscator/javascript-obfuscator/issues/136

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
dist/index.js


+ 3 - 3
package.json

@@ -1,6 +1,6 @@
 {
   "name": "javascript-obfuscator",
-  "version": "0.12.4",
+  "version": "0.12.5",
   "description": "JavaScript obfuscator",
   "keywords": [
     "obfuscator",
@@ -51,7 +51,7 @@
     "@types/sinon": "4.0.0",
     "@types/string-template": "1.0.2",
     "@types/webpack-env": "1.13.2",
-    "awesome-typescript-loader": "3.4.0",
+    "awesome-typescript-loader": "3.4.1",
     "babel-cli": "6.26.0",
     "babel-loader": "7.1.2",
     "babel-plugin-array-includes": "2.0.3",
@@ -62,7 +62,7 @@
     "mocha": "4.0.1",
     "pre-commit": "1.2.2",
     "sinon": "4.1.2",
-    "threads": "^0.9.0",
+    "threads": "^0.10.0",
     "ts-node": "3.3.0",
     "tslint": "5.8.0",
     "tslint-eslint-rules": "4.1.1",

+ 12 - 3
src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts

@@ -10,13 +10,19 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
 
 import { initializable } from '../../decorators/Initializable';
 
-import { DebugProtectionFunctionCallTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate';
+import { DebugProtectionFunctionCallTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate';
 
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { NodeUtils } from '../../node/NodeUtils';
 
 @injectable()
 export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
+    /**
+     * @type {string}
+     */
+    @initializable()
+    private callsControllerFunctionName: string;
+
     /**
      * @type {string}
      */
@@ -36,9 +42,11 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
 
     /**
      * @param {string} debugProtectionFunctionName
+     * @param {string} callsControllerFunctionName
      */
-    public initialize (debugProtectionFunctionName: string): void {
+    public initialize (debugProtectionFunctionName: string, callsControllerFunctionName: string): void {
         this.debugProtectionFunctionName = debugProtectionFunctionName;
+        this.callsControllerFunctionName = callsControllerFunctionName;
     }
 
     /**
@@ -53,7 +61,8 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
      */
     protected getTemplate (): string {
         return format(DebugProtectionFunctionCallTemplate(), {
-            debugProtectionFunctionName: this.debugProtectionFunctionName
+            debugProtectionFunctionName: this.debugProtectionFunctionName,
+            singleNodeCallControllerFunctionName: this.callsControllerFunctionName
         });
     }
 }

+ 19 - 1
src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts

@@ -79,6 +79,19 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
 
             NodeAppender.insertNodeAtIndex(blockScopeNode, customNode.getNode(), randomIndex);
         });
+
+        // nodeCallsControllerFunctionNode append
+        this.appendCustomNodeIfExist(CustomNode.NodeCallsControllerFunctionNode, (customNode: ICustomNode) => {
+            let targetBlockScope: TNodeWithBlockStatement;
+
+            if (stackTraceData.length) {
+                targetBlockScope = NodeAppender.getOptimalBlockScope(stackTraceData, randomStackTraceIndex, 1);
+            } else {
+                targetBlockScope = blockScopeNode;
+            }
+
+            NodeAppender.prependNode(targetBlockScope, customNode.getNode());
+        });
     }
 
     public initialize (): void {
@@ -89,14 +102,17 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
         }
 
         const debugProtectionFunctionName: string = this.randomGenerator.getRandomVariableName(6);
+        const callsControllerFunctionName: string = this.randomGenerator.getRandomVariableName(6);
 
         const debugProtectionFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionNode);
         const debugProtectionFunctionCallNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionCallNode);
         const debugProtectionFunctionIntervalNode: ICustomNode = this.customNodeFactory(CustomNode.DebugProtectionFunctionIntervalNode);
+        const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNode.NodeCallsControllerFunctionNode);
 
         debugProtectionFunctionNode.initialize(debugProtectionFunctionName);
-        debugProtectionFunctionCallNode.initialize(debugProtectionFunctionName);
+        debugProtectionFunctionCallNode.initialize(debugProtectionFunctionName, callsControllerFunctionName);
         debugProtectionFunctionIntervalNode.initialize(debugProtectionFunctionName);
+        nodeCallsControllerFunctionNode.initialize(this.appendEvent, callsControllerFunctionName);
 
         this.customNodes.set(CustomNode.DebugProtectionFunctionNode, debugProtectionFunctionNode);
         this.customNodes.set(CustomNode.DebugProtectionFunctionCallNode, debugProtectionFunctionCallNode);
@@ -104,5 +120,7 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup {
         if (this.options.debugProtectionInterval) {
             this.customNodes.set(CustomNode.DebugProtectionFunctionIntervalNode, debugProtectionFunctionIntervalNode);
         }
+
+        this.customNodes.set(CustomNode.NodeCallsControllerFunctionNode, nodeCallsControllerFunctionNode);
     }
 }

+ 0 - 18
src/templates/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate.ts

@@ -1,18 +0,0 @@
-/**
- * @returns {string}
- */
-export function DebugProtectionFunctionCallTemplate (): string {
-    return `
-        (function () {
-            var regExp1 = new RegExp('function *\\\\( *\\\\)');
-            var regExp2 = new RegExp('\\\\+\\\\+ *\\(?:_0x([a-f0-9]){4,6}|\\\\b[a-zA-Z]{1,2}\\\\b\\)');
-            var result = {debugProtectionFunctionName}('init');
-            
-            if (!regExp1.test(result + 'chain') || !regExp2.test(result + 'input')) {
-                result('0');
-            } else {
-                {debugProtectionFunctionName}();
-            }
-        })();
-    `;
-}

+ 21 - 0
src/templates/debug-protection-nodes/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate.ts

@@ -0,0 +1,21 @@
+/**
+ * @returns {string}
+ */
+export function DebugProtectionFunctionCallTemplate (): string {
+    return `
+        (function () {
+            {singleNodeCallControllerFunctionName}(this, function () {
+                var regExp1 = new RegExp('function *\\\\( *\\\\)');
+                var regExp2 = new RegExp('\\\\+\\\\+ *\\(?:_0x(?:[a-f0-9]){4,6}|\\\\b[a-zA-Z]{1,2}\\\\b\\)');
+           
+                var result = {debugProtectionFunctionName}('init');
+                
+                if (!regExp1.test(result + 'chain') || !regExp2.test(result + 'input')) {
+                    result('0');
+                } else {
+                    {debugProtectionFunctionName}();
+                }
+            })();
+        })();
+    `;
+}

+ 36 - 1
test/functional-tests/templates/custom-nodes/debug-protection-nodes/DebufProtectionFunctionCallTemplate.spec.ts

@@ -100,7 +100,7 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
         });
     });
 
-    describe('variant #3: obfuscated code with removed debug protection function call', () => {
+    describe('variant #3: obfuscated code with removed debug protection code', () => {
         const expectedEvaluationResult: number = 0;
 
         let obfuscatedCode: string,
@@ -135,4 +135,39 @@ describe('DebugProtectionFunctionCallTemplate (): string', () => {
             assert.equal(evaluationResult, expectedEvaluationResult);
         });
     });
+
+    describe('variant #4: single call of debug protection code', () => {
+        const expectedEvaluationResult: number = 1;
+
+        let obfuscatedCode: string,
+            evaluationResult: number = 0;
+
+        beforeEach((done) => {
+            const code: string = readFileAsString(__dirname + '/fixtures/single-call.js');
+            const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
+                code,
+                {
+                    ...NO_CUSTOM_NODES_PRESET,
+                    debugProtection: true
+                }
+            );
+
+            obfuscatedCode = obfuscationResult.getObfuscatedCode();
+
+            spawnThread(
+                () => obfuscatedCode,
+                (response: number) => {
+                    evaluationResult = response;
+                    done();
+                },
+                () => {
+                    done();
+                }
+            );
+        });
+
+        it('should correctly evaluate code with enabled debug protection', () => {
+            assert.equal(evaluationResult, expectedEvaluationResult);
+        });
+    });
 });

+ 21 - 0
test/functional-tests/templates/custom-nodes/debug-protection-nodes/fixtures/single-call.js

@@ -0,0 +1,21 @@
+(function () {
+    function foo () {
+        function bar () {
+            function baz () {
+                return 1;
+            }
+
+            return baz();
+        }
+
+        return bar();
+    }
+
+    for (var i = 0; i <= 10000; i++) {
+        if (i < 10000) {
+            foo();
+        } else {
+            return foo();
+        }
+    }
+})();

+ 8 - 8
yarn.lock

@@ -252,9 +252,9 @@ atob@^2.0.0:
   version "2.0.3"
   resolved "https://registry.yarnpkg.com/atob/-/atob-2.0.3.tgz#19c7a760473774468f20b2d2d03372ad7d4cbf5d"
 
[email protected].0:
-  version "3.4.0"
-  resolved "https://registry.yarnpkg.com/awesome-typescript-loader/-/awesome-typescript-loader-3.4.0.tgz#aed2c83af614d617d11e3ec368ac3befb55d002f"
[email protected].1:
+  version "3.4.1"
+  resolved "https://registry.yarnpkg.com/awesome-typescript-loader/-/awesome-typescript-loader-3.4.1.tgz#22fa49800f0619ec18ab15383aef93b95378dea9"
   dependencies:
     colors "^1.1.2"
     enhanced-resolve "3.3.0"
@@ -1054,11 +1054,11 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
   dependencies:
     delayed-stream "~1.0.0"
 
[email protected], commander@^2.11.0, commander@^2.9.0:
[email protected]:
   version "2.11.0"
   resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
 
[email protected]:
[email protected], commander@^2.11.0, commander@^2.9.0:
   version "2.12.2"
   resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555"
 
@@ -3655,9 +3655,9 @@ text-encoding@^0.6.4:
   version "0.6.4"
   resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
 
-threads@^0.9.0:
-  version "0.9.0"
-  resolved "https://registry.yarnpkg.com/threads/-/threads-0.9.0.tgz#cf1132ee7b6b205253e8dedc13904cc7646dbcc4"
+threads@^0.10.0:
+  version "0.10.0"
+  resolved "https://registry.yarnpkg.com/threads/-/threads-0.10.0.tgz#a6b0bc5d916fa75434b166c612769684b65fead5"
   dependencies:
     eventemitter3 "^2.0.2"
     native-promise-only "^0.8.1"

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä