Browse Source

custom node templates rework

sanex3339 8 năm trước cách đây
mục cha
commit
225bbfd6b4

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


+ 6 - 1
src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts

@@ -1,3 +1,5 @@
+import 'format-unicorn';
+
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
 import { TStatement } from '../../types/TStatement';
@@ -11,6 +13,7 @@ import { ConsoleOutputDisableExpressionTemplate } from '../../templates/custom-n
 import { AbstractCustomNode } from '../AbstractCustomNode';
 import { CustomNodeAppender } from '../CustomNodeAppender';
 import { NodeUtils } from '../../NodeUtils';
+import { Utils } from '../../Utils';
 
 export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
     /**
@@ -49,7 +52,9 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
      */
     protected getNodeStructure (): TStatement[] {
         return NodeUtils.convertCodeToStructure(
-            ConsoleOutputDisableExpressionTemplate()
+            ConsoleOutputDisableExpressionTemplate().formatUnicorn({
+                consoleLogDisableFunctionName: Utils.getRandomVariableName()
+            })
         );
     }
 }

+ 9 - 1
src/node-obfuscators/replacers/StringLiteralReplacer.ts

@@ -9,6 +9,11 @@ import { UnicodeArray } from '../../UnicodeArray';
 import { Utils } from '../../Utils';
 
 export class StringLiteralReplacer extends AbstractReplacer {
+    /**
+     * @type {number}
+     */
+    private static minimumLengthForUnicodeArray: number = 2;
+
     /**
      * @type {string[]}
      */
@@ -20,7 +25,10 @@ export class StringLiteralReplacer extends AbstractReplacer {
      * @returns {string}
      */
     public replace (nodeValue: string): string {
-        const replaceWithUnicodeArrayFlag: boolean = Math.random() <= this.options.unicodeArrayThreshold;
+        const replaceWithUnicodeArrayFlag: boolean = (
+            nodeValue.length > StringLiteralReplacer.minimumLengthForUnicodeArray
+            && Math.random() <= this.options.unicodeArrayThreshold
+        );
 
         if (this.options.unicodeArray && replaceWithUnicodeArrayFlag) {
             return this.replaceStringLiteralWithUnicodeArrayCall(nodeValue);

+ 9 - 7
src/templates/custom-nodes/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts

@@ -3,18 +3,18 @@
  */
 export function ConsoleOutputDisableExpressionTemplate (): string {
     return `
-        (function () {
+        var {consoleLogDisableFunctionName} = function () {
             var getGlobal = function () {
                 if (typeof self !== 'undefined') { return self; }
                 if (typeof window !== 'undefined') { return window; }
                 if (typeof global !== 'undefined') { return global; }
             };
-        
-            if (getGlobal().firstRun) {
-                return false;
+            
+            if (getGlobal().fetchPolyfillDisabledFlag) {
+                return;
             }
-                                                    
-            getGlobal().firstRun = true;
+                                                          
+            getGlobal().fetchPolyfillDisabledFlag = true;
             
             var _ = '(\u0004\u0006\u0003\u0005[]' + '["filter"]["\u0007tructor"]' + '("return this")()' + '.' + '\u0003;\u0006\u0002\u0005\u0004};' + '_\u0003.log\u0001.in' + 'fo\u0001.' + 'war' + 'n\u0001.er' + 'r' + 'or\u0001})();' + '\u0001\u0005_\u0002;' + '_\u0003\u0002function' + '\u0003\u0007ole\u0004\u0002 ()' + '{\u0005 = \u0006var ' + '_\u0007cons', 
                 Y, 
@@ -26,6 +26,8 @@ export function ConsoleOutputDisableExpressionTemplate (): string {
             }
             
             []["filter"]["constructor"](_)();
-        })()
+        };
+        
+        {consoleLogDisableFunctionName}();
     `;
 }

+ 4 - 4
src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate.ts

@@ -21,11 +21,11 @@ export function DomainLockNodeTemplate (): string {
             };
   
             if (
-                !getGlobal().argv ||
-                !getGlobal().argv.appParams
+                !getGlobal().promisePolyfillActivationFlag ||
+                !getGlobal().promisePolyfillActivationFlag.isActive
             ) {            
-                getGlobal().argv = {
-                    appParams: -1
+                getGlobal().promisePolyfillActivationFlag = {
+                    isActive: true
                 };
                 
                 var regExp = new RegExp("[{diff}]", "g");

+ 4 - 4
src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts

@@ -16,14 +16,14 @@ export function SelfDefendingTemplate (): string {
             };
         
             if (
-                getGlobal().process && 
-                getGlobal().process.appTimeoutStateCounter++ && 
-                getGlobal().process.appTimeoutStateCounter !== 50
+                getGlobal().argvProcess && 
+                getGlobal().argvProcess.appTimeoutStateCounter++ && 
+                getGlobal().argvProcess.appTimeoutStateCounter !== 50
             ) {
                 return false;
             }
             
-            getGlobal().process = {
+            getGlobal().argvProcess = {
                 appTimeoutStateCounter: 50
             };
               

+ 30 - 2
test/functional-tests/node-obfuscators/LiteralObfuscator.spec.ts

@@ -17,7 +17,35 @@ describe('LiteralObfuscator', () => {
             assert.match(obfuscationResult.getObfuscatedCode(),  /^var *test *= *'\\x74\\x65\\x73\\x74';$/);
         });
 
-        it('should replace literal node value with unicode value encoded using base64', () => {
+        it('should replace literal node value with unicode array value', () => {
+            let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
+                `var test = 'test';`,
+                Object.assign({}, NO_CUSTOM_NODES_PRESET, {
+                    unicodeArray: true,
+                    unicodeArrayThreshold: 1
+                })
+            );
+
+            assert.match(
+                obfuscationResult.getObfuscatedCode(),
+                /^var *_0x([a-z0-9]){4} *= *\['\\x74\\x65\\x73\\x74'\];/
+            );
+            assert.match(obfuscationResult.getObfuscatedCode(),  /var *test *= *_0x([a-z0-9]){4}\('0x0'\);/);
+        });
+
+        it('shouldn\'t replace short literal node value with unicode array value', () => {
+            let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
+                `var test = 'te';`,
+                Object.assign({}, NO_CUSTOM_NODES_PRESET, {
+                    unicodeArray: true,
+                    unicodeArrayThreshold: 1
+                })
+            );
+
+            assert.match(obfuscationResult.getObfuscatedCode(),  /var *test *= *'\\x74\\x65';/);
+        });
+
+        it('should replace literal node value with unicode array value encoded using base64', () => {
             let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
                 `var test = 'test';`,
                 Object.assign({}, NO_CUSTOM_NODES_PRESET, {
@@ -34,7 +62,7 @@ describe('LiteralObfuscator', () => {
             assert.match(obfuscationResult.getObfuscatedCode(),  /var *test *= *_0x([a-z0-9]){4}\('0x0'\);/);
         });
 
-        it('should replace literal node value with unicode value encoded using rc4', () => {
+        it('should replace literal node value with unicode array value encoded using rc4', () => {
             let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
                 `var test = 'test';`,
                 Object.assign({}, NO_CUSTOM_NODES_PRESET, {

+ 1 - 1
test/functional-tests/templates/custom-nodes/domain-lock-nodes/DomainLockNodeTemplate.spec.ts

@@ -76,6 +76,6 @@ describe('DomainLockNodeTemplate (): string', () => {
     });
 
     afterEach(() => {
-        delete (<any>global).argv;
+        delete (<any>global).promisePolyfillActivationFlag;
     });
 });

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