diff --git a/CHANGELOG.md b/CHANGELOG.md index 78f4a67c1..140f80acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Change Log v4.1.2 --- * Fix `transformObjectKeys` performance in some edge-cases +* Revert `Improved stringArray calls wrapper templates` commit. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1330 * Update `class-validator` version. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1324 * Update other dependencies diff --git a/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts index 80afd3e43..43f60033d 100644 --- a/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts @@ -29,7 +29,7 @@ export class StringArrayCallsWrapperBase64CodeHelper extends StringArrayCallsWra atobFunctionName, selfDefendingCode, stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, - stringArrayCacheName: this.stringArrayCacheName + stringArrayFunctionName: this.stringArrayFunctionName } ); } diff --git a/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts index 5d684915f..e599643dd 100644 --- a/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts @@ -114,7 +114,6 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper this.customCodeHelperFormatter.formatTemplate(StringArrayCallsWrapperTemplate(), { decodeCodeHelperTemplate, stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, - stringArrayCacheName: this.stringArrayCacheName, stringArrayFunctionName: this.stringArrayFunctionName, indexShiftAmount: this.indexShiftAmount }), diff --git a/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts b/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts index c1ce13a8d..48074fc00 100644 --- a/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts +++ b/src/custom-code-helpers/string-array/StringArrayCallsWrapperRc4CodeHelper.ts @@ -39,7 +39,7 @@ export class StringArrayCallsWrapperRc4CodeHelper extends StringArrayCallsWrappe rc4Polyfill, selfDefendingCode, stringArrayCallsWrapperName: this.stringArrayCallsWrapperName, - stringArrayCacheName: this.stringArrayCacheName + stringArrayFunctionName: this.stringArrayFunctionName } ); } diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts index df56184c8..b1b0a4f89 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate.ts @@ -11,26 +11,27 @@ export function StringArrayBase64DecodeTemplate ( const identifierLength: number = 6; const initializedIdentifier: string = randomGenerator.getRandomString(identifierLength); const base64Identifier: string = randomGenerator.getRandomString(identifierLength); + const dataIdentifier: string = randomGenerator.getRandomString(identifierLength); return ` if ({stringArrayCallsWrapperName}.${initializedIdentifier} === undefined) { {atobPolyfill} {stringArrayCallsWrapperName}.${base64Identifier} = {atobFunctionName}; - {stringArrayCacheName} = arguments; + {stringArrayCallsWrapperName}.${dataIdentifier} = {}; {stringArrayCallsWrapperName}.${initializedIdentifier} = true; } const firstValue = stringArray[0]; const cacheKey = index + firstValue; - const cachedValue = {stringArrayCacheName}[cacheKey]; + const cachedValue = {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey]; if (!cachedValue) { {selfDefendingCode} value = {stringArrayCallsWrapperName}.${base64Identifier}(value); - {stringArrayCacheName}[cacheKey] = value; + {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey] = value; } else { value = cachedValue; } diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts index 9ef2e4f79..c7dcaca94 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts @@ -1,25 +1,17 @@ /** - * The first parameter of the outer stringArrayCallsWrapperName function will be used as an initial index - * and later as a cache variable that will be captured by the inner function - * * @returns {string} */ export function StringArrayCallsWrapperTemplate (): string { return ` - function {stringArrayCallsWrapperName} ({stringArrayCacheName}, key) { + function {stringArrayCallsWrapperName} (index, key) { + index = index - {indexShiftAmount}; + const stringArray = {stringArrayFunctionName}(); - - {stringArrayCallsWrapperName} = function (index, key) { - index = index - {indexShiftAmount}; + let value = stringArray[index]; - let value = stringArray[index]; - - {decodeCodeHelperTemplate} - - return value; - }; - - return {stringArrayCallsWrapperName}({stringArrayCacheName}, key); + {decodeCodeHelperTemplate} + + return value; } `; } diff --git a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts index 0459e8fe1..4a8bcbf68 100644 --- a/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts +++ b/src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayRC4DecodeTemplate.ts @@ -11,6 +11,7 @@ export function StringArrayRC4DecodeTemplate ( const identifierLength: number = 6; const initializedIdentifier: string = randomGenerator.getRandomString(identifierLength); const rc4Identifier: string = randomGenerator.getRandomString(identifierLength); + const dataIdentifier: string = randomGenerator.getRandomString(identifierLength); const onceIdentifier: string = randomGenerator.getRandomString(identifierLength); return ` @@ -19,14 +20,14 @@ export function StringArrayRC4DecodeTemplate ( {rc4Polyfill} {stringArrayCallsWrapperName}.${rc4Identifier} = {rc4FunctionName}; - {stringArrayCacheName} = arguments; + {stringArrayCallsWrapperName}.${dataIdentifier} = {}; {stringArrayCallsWrapperName}.${initializedIdentifier} = true; } const firstValue = stringArray[0]; const cacheKey = index + firstValue; - const cachedValue = {stringArrayCacheName}[cacheKey]; + const cachedValue = {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey]; if (!cachedValue) { if ({stringArrayCallsWrapperName}.${onceIdentifier} === undefined) { @@ -36,7 +37,7 @@ export function StringArrayRC4DecodeTemplate ( } value = {stringArrayCallsWrapperName}.${rc4Identifier}(value, key); - {stringArrayCacheName}[cacheKey] = value; + {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey] = value; } else { value = cachedValue; } diff --git a/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts b/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts index f537f85b3..b5efc053c 100644 --- a/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts +++ b/test/functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec.ts @@ -97,10 +97,9 @@ describe('StringArrayCallsWrapperCodeHelper', () => { describe('Preserve string array name', () => { const callsWrapperRegExp: RegExp = new RegExp(`` + `function *b *\\(c, *d\\) *{ *` + - `var e *= *a\\(\\); *` + - `b *= *function *\\(f, *g\\) *{` + - `f *= *f *- *0x0; *` + - `var h *= *e\\[f]; *` + + `c *= *c *- *0x0; *` + + `var e *= *a *\\(\\);` + + `var f *= *e\\[c]; *` + ``); let obfuscatedCode: string;