Przeglądaj źródła

decrease threshold for StackTraceAnalyzer

sanex3339 8 lat temu
rodzic
commit
73fd71effb

+ 2 - 2
dist/index.js

@@ -1673,7 +1673,7 @@ var JavaScriptObfuscatorCLI = function () {
                 return val.split(',');
             }).option('--reservedNames <list>', 'Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)', function (val) {
                 return val.split(',');
-            }).option('--rotateUnicodeArray <boolean>', 'Disable rotation of unicode array values during obfuscation', JavaScriptObfuscatorCLI.parseBoolean).option('--selfDefending <boolean>', 'Disables self-defending for obfuscated code', JavaScriptObfuscatorCLI.parseBoolean).option('--sourceMap <boolean>', 'Enables source map generation', JavaScriptObfuscatorCLI.parseBoolean).option('--sourceMapBaseUrl <string>', 'Sets base url to the source map import url when `--sourceMapMode=separate`').option('--sourceMapFileName <string>', 'Sets file name for output source map when `--sourceMapMode=separate`').option('--sourceMapMode <string> [inline, separate]', 'Specify source map output mode', JavaScriptObfuscatorCLI.parseSourceMapMode).option('--unicodeArray <boolean>', 'Disables gathering of all literal strings into an array and replacing every literal string with an array call', JavaScriptObfuscatorCLI.parseBoolean).option('--unicodeArrayEncoding <boolean|string> [base64, rc4]', 'All literals in Unicode array become encoded in using base64 or rc4 (this option can slightly slow down your code speed', JavaScriptObfuscatorCLI.parseUnicodeArrayEncoding).option('--unicodeArrayThreshold <number>', 'The probability that the literal string will be inserted into unicodeArray (Default: 0.8, Min: 0, Max: 1)', parseFloat).parse(this.rawArguments);
+            }).option('--rotateUnicodeArray <boolean>', 'Disable rotation of unicode array values during obfuscation', JavaScriptObfuscatorCLI.parseBoolean).option('--selfDefending <boolean>', 'Disables self-defending for obfuscated code', JavaScriptObfuscatorCLI.parseBoolean).option('--sourceMap <boolean>', 'Enables source map generation', JavaScriptObfuscatorCLI.parseBoolean).option('--sourceMapBaseUrl <string>', 'Sets base url to the source map import url when `--sourceMapMode=separate`').option('--sourceMapFileName <string>', 'Sets file name for output source map when `--sourceMapMode=separate`').option('--sourceMapMode <string> [inline, separate]', 'Specify source map output mode', JavaScriptObfuscatorCLI.parseSourceMapMode).option('--unicodeArray <boolean>', 'Disables gathering of all literal strings into an array and replacing every literal string with an array call', JavaScriptObfuscatorCLI.parseBoolean).option('--unicodeArrayEncoding <boolean|string> [true, false, base64, rc4]', 'All literals in Unicode array become encoded in using base64 or rc4 (this option can slightly slow down your code speed', JavaScriptObfuscatorCLI.parseUnicodeArrayEncoding).option('--unicodeArrayThreshold <number>', 'The probability that the literal string will be inserted into unicodeArray (Default: 0.8, Min: 0, Max: 1)', parseFloat).parse(this.rawArguments);
             this.commands.on('--help', function () {
                 console.log('  Examples:\n');
                 console.log('    %> javascript-obfuscator in.js --compact true --selfDefending false');
@@ -3610,7 +3610,7 @@ var StackTraceAnalyzer = function () {
 }();
 
 StackTraceAnalyzer.limitThresholdActivationLength = 25;
-StackTraceAnalyzer.limitThreshold = 0.1;
+StackTraceAnalyzer.limitThreshold = 0.002;
 exports.StackTraceAnalyzer = StackTraceAnalyzer;
 
 /***/ },

+ 1 - 1
src/stack-trace-analyzer/StackTraceAnalyzer.ts

@@ -56,7 +56,7 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
     /**
      * @type {number}
      */
-    private static limitThreshold: number = 0.1;
+    private static limitThreshold: number = 0.002;
 
     /**
      * @type {ESTree.Node[]}

+ 1 - 1
test/dev/dev-runtime-performance.ts

@@ -70,7 +70,7 @@ if (!(<any>global)._babelPolyfill) {
         } catch (error) {
             console.log(error);
         }
-    `).repeat(200)}
+    `).repeat(1000)}
     
     console.log = log;
     console.log(new Date() - start);

+ 8 - 10
test/unit-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts

@@ -7,17 +7,15 @@ const assert: any = chai.assert;
 describe('StackTraceAnalyzer', () => {
     describe('getLimitIndex (blockScopeBodyLength: number): number', () => {
         it('should returns correct limit index based on block scope body length', () => {
-            const blockScopeBodyLength1: number = 100;
-            const blockScopeBodyLength2: number = 22;
-            const blockScopeBodyLength3: number = 26;
-            const blockScopeBodyLength4: number = 28;
-            const blockScopeBodyLength5: number = 34;
+            const blockScopeBodyLength1: number = 10000;
+            const blockScopeBodyLength2: number = 1000;
+            const blockScopeBodyLength3: number = 25;
+            const blockScopeBodyLength4: number = 5;
 
-            assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength1), 34);
-            assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength2), 21);
-            assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength3), 25);
-            assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength4), 27);
-            assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength5), 27);
+            assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength1), 44);
+            assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength2), 26);
+            assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength3), 24);
+            assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength4), 4);
         });
     });
 });