From 5f26fe2209ec8c1fec16af086af6cb688c9f6d3f Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Tue, 3 Jan 2017 15:33:51 +0300 Subject: [PATCH] 0.9.0-dev.7 - increased control flow storage key length --- dist/index.js | 5 ++++- .../AbstractControlFlowReplacer.ts | 5 ++++- .../FunctionControlFlowTransformer.spec.ts | 12 ++++++------ .../BinaryExpressionControlFlowReplacer.spec.ts | 6 +++--- .../CallExpressionControlFlowReplacer.spec.ts | 6 +++--- .../LogicalExpressionControlFlowReplacer.spec.ts | 8 ++++---- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/dist/index.js b/dist/index.js index 4e826fa9..1a692e38 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1977,9 +1977,12 @@ var AbstractControlFlowReplacer = AbstractControlFlowReplacer_1 = function () { if (RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomFloat(0, 1) > usingExistingIdentifierChance && storageKeysForCurrentId && storageKeysForCurrentId.length) { return RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().pickone(storageKeysForCurrentId); } - var storageKey = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomString(3); + var storageKey = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomString(4); storageKeysById.set(replacerId, [storageKey]); this.replacerDataByControlFlowStorageId.set(controlFlowStorageId, storageKeysById); + if (controlFlowStorage.getStorage().has(storageKey)) { + console.log(1); + } controlFlowStorage.set(storageKey, customNode); return storageKey; } diff --git a/src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts b/src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts index ea21861e..60e4b02f 100644 --- a/src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts +++ b/src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts @@ -95,10 +95,13 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace return RandomGeneratorUtils.getRandomGenerator().pickone(storageKeysForCurrentId); } - const storageKey: string = RandomGeneratorUtils.getRandomString(3); + const storageKey: string = RandomGeneratorUtils.getRandomString(4); storageKeysById.set(replacerId, [storageKey]); this.replacerDataByControlFlowStorageId.set(controlFlowStorageId, storageKeysById); + if (controlFlowStorage.getStorage().has(storageKey)) { + console.log(1); + } controlFlowStorage.set(storageKey, customNode); return storageKey; diff --git a/test/functional-tests/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.spec.ts b/test/functional-tests/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.spec.ts index 23b1346b..2caf8cba 100644 --- a/test/functional-tests/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.spec.ts +++ b/test/functional-tests/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.spec.ts @@ -12,15 +12,15 @@ describe('FunctionControlFlowTransformer', () => { const variableMatch: string = '_0x([a-z0-9]){4,6}'; const rootControlFlowStorageNodeMatch: string = `` + `var *${variableMatch} *= *\\{` + - `'(\\\\x[a-f0-9]*){3}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `'(\\\\x[a-f0-9]*){4}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + `return *${variableMatch} *\\+ *${variableMatch};` + `\\}` + `\\};` + ``; const innerControlFlowStorageNodeMatch: string = `` + `var *${variableMatch} *= *\\{` + - `'(\\\\x[a-f0-9]*){3}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + - `return *${variableMatch}\\['(\\\\x[a-f0-9]*){3}'\\]\\(${variableMatch}, *${variableMatch}\\);` + + `'(\\\\x[a-f0-9]*){4}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `return *${variableMatch}\\['(\\\\x[a-f0-9]*){4}'\\]\\(${variableMatch}, *${variableMatch}\\);` + `\\}` + `\\};` + ``; @@ -101,10 +101,10 @@ describe('FunctionControlFlowTransformer', () => { const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); const regexp: RegExp = new RegExp( `var *${variableMatch} *= *\\{` + - `'(\\\\x[a-f0-9]*){3}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `'(\\\\x[a-f0-9]*){4}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + `return *${variableMatch} *\\+ *${variableMatch};` + `\\}, *` + - `'(\\\\x[a-f0-9]*){3}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `'(\\\\x[a-f0-9]*){4}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + `return *${variableMatch} *- *${variableMatch};` + `\\}` + `\\};` @@ -138,7 +138,7 @@ describe('FunctionControlFlowTransformer', () => { const expectedValue: number = 0; const regExp: RegExp = new RegExp( `var *[a-zA-Z]{6} *= *\\{` + - `'(\\\\x[a-f0-9]*){3}' *: *function *_0x[0-9] *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `'(\\\\x[a-f0-9]*){4}' *: *function *_0x[0-9] *\\(${variableMatch}, *${variableMatch}\\) *\\{` + `return *${variableMatch} *\\+ *${variableMatch};` + `\\}` + `\\};` diff --git a/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.spec.ts index 216a9551..290e9938 100644 --- a/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.spec.ts @@ -22,7 +22,7 @@ describe('BinaryExpressionControlFlowReplacer', () => { } ); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); - const controlFlowStorageCallRegExp: RegExp = /var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\]\(0x1, *0x2\);/; + const controlFlowStorageCallRegExp: RegExp = /var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\]\(0x1, *0x2\);/; it('should replace binary expression node by call to control flow storage node', () => { assert.match(obfuscatedCode, controlFlowStorageCallRegExp); @@ -51,8 +51,8 @@ describe('BinaryExpressionControlFlowReplacer', () => { } ); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); - const controlFlowStorageCallRegExp1: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\])\(0x1, *0x2\);/; - const controlFlowStorageCallRegExp2: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\])\(0x2, *0x3\);/; + const controlFlowStorageCallRegExp1: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\])\(0x1, *0x2\);/; + const controlFlowStorageCallRegExp2: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\])\(0x2, *0x3\);/; const firstMatchArray: RegExpMatchArray | null = obfuscatedCode.match(controlFlowStorageCallRegExp1); const secondMatchArray: RegExpMatchArray | null = obfuscatedCode.match(controlFlowStorageCallRegExp2); diff --git a/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.spec.ts index b516d477..151616be 100644 --- a/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.spec.ts @@ -22,7 +22,7 @@ describe('CallExpressionControlFlowReplacer', () => { } ); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); - const controlFlowStorageCallRegExp: RegExp = /var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\]\(_0x([a-z0-9]){4,6}, *0x1, *0x2\);/; + const controlFlowStorageCallRegExp: RegExp = /var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\]\(_0x([a-z0-9]){4,6}, *0x1, *0x2\);/; it('should replace call expression node by call to control flow storage node', () => { assert.match(obfuscatedCode, controlFlowStorageCallRegExp); @@ -51,8 +51,8 @@ describe('CallExpressionControlFlowReplacer', () => { } ); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); - const controlFlowStorageCallRegExp1: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\])\(_0x([a-z0-9]){4,6}, *0x1, *0x2\);/; - const controlFlowStorageCallRegExp2: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\])\(_0x([a-z0-9]){4,6}, *0x2, *0x3\);/; + const controlFlowStorageCallRegExp1: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\])\(_0x([a-z0-9]){4,6}, *0x1, *0x2\);/; + const controlFlowStorageCallRegExp2: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\])\(_0x([a-z0-9]){4,6}, *0x2, *0x3\);/; const firstMatchArray: RegExpMatchArray | null = obfuscatedCode.match(controlFlowStorageCallRegExp1); const secondMatchArray: RegExpMatchArray | null = obfuscatedCode.match(controlFlowStorageCallRegExp2); diff --git a/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.spec.ts index e5615637..7a3ea525 100644 --- a/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/node-control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.spec.ts @@ -22,7 +22,7 @@ describe('LogicalExpressionControlFlowReplacer', () => { } ); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); - const controlFlowStorageCallRegExp: RegExp = /var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\]\(!!\[\], *!\[\]\);/; + const controlFlowStorageCallRegExp: RegExp = /var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\]\(!!\[\], *!\[\]\);/; it('should replace logical expression node by call to control flow storage node', () => { assert.match(obfuscatedCode, controlFlowStorageCallRegExp); @@ -51,8 +51,8 @@ describe('LogicalExpressionControlFlowReplacer', () => { } ); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); - const controlFlowStorageCallRegExp1: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\])\(!!\[\], *!\[\]\);/; - const controlFlowStorageCallRegExp2: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\])\(!\[\], *!!\[\]\);/; + const controlFlowStorageCallRegExp1: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\])\(!!\[\], *!\[\]\);/; + const controlFlowStorageCallRegExp2: RegExp = /var *_0x([a-z0-9]){4,6} *= *(_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\])\(!\[\], *!!\[\]\);/; const firstMatchArray: RegExpMatchArray | null = obfuscatedCode.match(controlFlowStorageCallRegExp1); const secondMatchArray: RegExpMatchArray | null = obfuscatedCode.match(controlFlowStorageCallRegExp2); @@ -86,7 +86,7 @@ describe('LogicalExpressionControlFlowReplacer', () => { } ); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); - const controlFlowStorageCallRegExp: RegExp = /var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){3}'\]\(!_0x([a-z0-9]){4,6}, *!_0x([a-z0-9]){4,6}\);/; + const controlFlowStorageCallRegExp: RegExp = /var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4,6}\['(\\x[a-f0-9]*){4}'\]\(!_0x([a-z0-9]){4,6}, *!_0x([a-z0-9]){4,6}\);/; it('should replace logical expression node with unary expression by call to control flow storage node', () => { assert.match(obfuscatedCode, controlFlowStorageCallRegExp);