Browse Source

Sync with master

sanex3339 7 năm trước cách đây
mục cha
commit
c8534978d9

+ 2 - 0
CHANGELOG.md

@@ -4,6 +4,8 @@ v0.14.0
 ---
 * **New option:** `transformObjectKeys` enables object keys transformation and obfuscation.
 * **Breaking change:** Now CLI obfuscating directory recursively. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/157
+* Fixed runtime errors when `deadCodeInjection` is enabled and `identifierNamesGenerator` is set to `mangled`
+* 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
 

+ 1 - 0
README.md

@@ -35,6 +35,7 @@ Example of obfuscated code: [gist.github.com](https://gist.github.com/sanex3339/
 
 #### You can support this project by donating:
 * (Bitcoin) 14yhtZxLNp6ekZAgmEmPJqEKUP2VtUxQK6
+* (Ether) 0x5Df9eBcFB2D0f3315d03Ac112104b9023C409dc1
 * (OpenCollective) https://opencollective.com/javascript-obfuscator
 
 Big thanks to all supporters!

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 1933
dist/index.js


+ 2 - 2
src/custom-nodes/dead-code-injection-nodes/BlockStatementDeadCodeInjectionNode.ts

@@ -63,8 +63,8 @@ export class BlockStatementDeadCodeInjectionNode extends AbstractCustomNode {
         const random2: boolean = this.randomGenerator.getMathRandom() > 0.5;
 
         const operator: BinaryOperator = random1 ? '===' : '!==';
-        const leftString: string = this.randomGenerator.getRandomString(3);
-        const rightString: string = random2 ? leftString : this.randomGenerator.getRandomString(3);
+        const leftString: string = this.randomGenerator.getRandomString(5);
+        const rightString: string = random2 ? leftString : this.randomGenerator.getRandomString(5);
 
         const [consequent, alternate]: [BlockStatement, BlockStatement] = random1 === random2
             ? [this.blockStatementNode, this.randomBlockStatementNode]

+ 6 - 1
src/node-transformers/obfuscating-transformers/obfuscating-replacers/literal-obfuscating-replacers/StringLiteralObfuscatingReplacer.ts

@@ -250,8 +250,13 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
             ));
         }
 
+        const stringArrayIdentifierNode: ESTree.Identifier = Nodes.getIdentifierNode(stringArrayStorageCallsWrapperName);
+
+        // prevent obfuscation of this identifier
+        stringArrayIdentifierNode.obfuscatedNode = true;
+
         return Nodes.getCallExpressionNode(
-            Nodes.getIdentifierNode(stringArrayStorageCallsWrapperName),
+            stringArrayIdentifierNode,
             callExpressionArgs
         );
     }

+ 2 - 1
src/node/NodeGuards.ts

@@ -271,11 +271,12 @@ export class NodeGuards {
         );
         const parentNodeIsMethodDefinitionNode: boolean = NodeGuards.isMethodDefinitionNode(parentNode) &&
             !parentNode.computed;
+        const isLabelIdentifierNode: boolean = NodeGuards.isLabelIdentifierNode(node, parentNode);
 
         return !parentNodeIsPropertyNode &&
             !parentNodeIsMemberExpressionNode &&
             !parentNodeIsMethodDefinitionNode &&
-            !NodeGuards.isLabelIdentifierNode(node, parentNode);
+            !isLabelIdentifierNode;
     }
 
     /**

+ 26 - 0
test/functional-tests/node-transformers/obfuscating-transformers/literal-transformer/LiteralTransformer.spec.ts

@@ -2,6 +2,7 @@ import { assert } from 'chai';
 
 import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
 
+import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
 import { StringArrayEncoding } from '../../../../../src/enums/StringArrayEncoding';
 
 import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
@@ -289,6 +290,31 @@ describe('LiteralTransformer', () => {
                 assert.closeTo(noStringArrayProbability, stringArrayThreshold, delta);
             });
         });
+
+        describe('variant #11: string array calls wrapper name', () => {
+            const regExp: RegExp = /console\[b\('0x0'\)]\('a'\);/;
+
+            let obfuscatedCode: string;
+
+            before(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/string-array-calls-wrapper-name.js');
+                const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET,
+                        stringArray: true,
+                        stringArrayThreshold: 1,
+                        identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator
+                    }
+                );
+
+                obfuscatedCode = obfuscationResult.getObfuscatedCode();
+            });
+
+            it('match #1: should keep identifier with string array calls wrapper name untouched after obfuscation', () => {
+                assert.match(obfuscatedCode, regExp);
+            });
+        });
     });
 
     describe('transformation of literal node with boolean value', () => {

+ 7 - 0
test/functional-tests/node-transformers/obfuscating-transformers/literal-transformer/fixtures/string-array-calls-wrapper-name.js

@@ -0,0 +1,7 @@
+(function(){
+    function foo () {
+        console.log('a');
+        var b;
+        function b () {}
+    }
+})();

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác