sanex3339 7 роки тому
батько
коміт
07a26e21d0

+ 2 - 1
CHANGELOG.md

@@ -3,9 +3,10 @@ Change Log
 v0.14.0
 ---
 * **New option:** `transformObjectKeys` enables object keys transformation and obfuscation.
+* **New feature:** `eval` expressions obfuscation.
 * **Breaking change:** Now CLI obfuscating directory recursively. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/157
-* Obfuscator now can obfuscate `eval` expressions.
 * Fixed runtime errors when `deadCodeInjection` is enabled and `identifierNamesGenerator` is set to `mangled`
+* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/171
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/166
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/156
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/159

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
dist/index.js


+ 0 - 18
src/custom-nodes/AbstractCustomNode.ts

@@ -12,8 +12,6 @@ import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
 import { GlobalVariableTemplate1 } from '../templates/GlobalVariableTemplate1';
 import { GlobalVariableTemplate2 } from '../templates/GlobalVariableTemplate2';
 
-import { NodeUtils } from '../node/NodeUtils';
-
 @injectable()
 export abstract class AbstractCustomNode implements ICustomNode {
     /**
@@ -24,11 +22,6 @@ export abstract class AbstractCustomNode implements ICustomNode {
         GlobalVariableTemplate2()
     ];
 
-    /**
-     * @type {string}
-     */
-    protected cachedCode: string;
-
     /**
      * @type {TStatement[]}
      */
@@ -70,17 +63,6 @@ export abstract class AbstractCustomNode implements ICustomNode {
      */
     public abstract initialize (...args: any[]): void;
 
-    /**
-     * @returns {string}
-     */
-    public getCode (): string {
-        if (!this.cachedCode) {
-            this.cachedCode = NodeUtils.convertStructureToCode(this.getNode());
-        }
-
-        return this.cachedCode;
-    }
-
     /**
      * @returns {TStatement[]}
      */

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

@@ -3,11 +3,6 @@ import { TStatement } from '../../types/node/TStatement';
 import { IInitializable } from '../IInitializable';
 
 export interface ICustomNode extends IInitializable {
-    /**
-     * @returns {string}
-     */
-    getCode (): string;
-
     /**
      * @returns ESTree.Node[]
      */

+ 3 - 1
src/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.ts

@@ -61,10 +61,12 @@ export class BlockStatementControlFlowTransformer extends AbstractNodeTransforme
                 || NodeGuards.isContinueStatementNode(statement);
             const isVariableDeclarationWithLetOrConstKind: boolean = NodeGuards.isVariableDeclarationNode(statement)
                 && (statement.kind === 'const' || statement.kind === 'let');
+            const isClassDeclaration: boolean = NodeGuards.isClassDeclarationNode(statement);
 
             return NodeGuards.isFunctionDeclarationNode(statement)
                 || isBreakOrContinueStatement
-                || isVariableDeclarationWithLetOrConstKind;
+                || isVariableDeclarationWithLetOrConstKind
+                || isClassDeclaration;
         });
     }
 

+ 26 - 2
test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts

@@ -454,7 +454,31 @@ describe('BlockStatementControlFlowTransformer', function () {
             });
         });
 
-        describe('variant #13: `controlFlowFlatteningThreshold` chance', () => {
+        describe('variant #13: block statement contain class declaration', () => {
+            const statementRegExp: RegExp = /^\(function *\( *\) *{ * *class *_0x([a-f0-9]){4,6} *{.*?} *}.*class *_0x([a-f0-9]){4,6} *{.*?} *}.*class *_0x([a-f0-9]){4,6} *{.*?} *}/;
+
+            let obfuscatedCode: string;
+
+            before(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/class-declaration.js');
+                const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET,
+                        controlFlowFlattening: true,
+                        controlFlowFlatteningThreshold: 1
+                    }
+                );
+
+                obfuscatedCode = obfuscationResult.getObfuscatedCode();
+            });
+
+            it('shouldn\'t transform block statement', () => {
+                assert.match(obfuscatedCode, statementRegExp);
+            });
+        });
+
+        describe('variant #14: `controlFlowFlatteningThreshold` chance', () => {
             const samples: number = 1000;
             const delta: number = 0.1;
 
@@ -499,7 +523,7 @@ describe('BlockStatementControlFlowTransformer', function () {
             });
         });
 
-        describe('variant #14: No `unreachable code after return statement` warning', () => {
+        describe('variant #15: No `unreachable code after return statement` warning', () => {
             const switchCaseRegExp: RegExp = /switch *\(_0x([a-f0-9]){4,6}\[_0x([a-f0-9]){4,6}\+\+\]\) *\{/;
             const switchCaseLengthRegExp: RegExp = /case *'[0-5]': *console\['log'\]\(0x[0-6]\);/g;
             const returnStatementRegExp: RegExp = /case *'[0-5]': *return; *(case|})/;

+ 29 - 0
test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/class-declaration.js

@@ -0,0 +1,29 @@
+(function(){
+    class Test1 {
+        foo () {
+            var that = this;
+
+            console.log(that.foo);
+        }
+    }
+
+    class Test2 {
+        bar () {
+            var that = this;
+
+            console.log(that.bar);
+        }
+    }
+
+    class Test3 {
+        baz () {
+            var that = this;
+
+            console.log(that.baz);
+        }
+    }
+
+    console.log(new Test1().foo());
+    console.log(new Test2().bar());
+    console.log(new Test3().baz());
+})();

Деякі файли не було показано, через те що забагато файлів було змінено