Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class StringArrayCallsWrapperBase64CodeHelper extends StringArrayCallsWra
atobFunctionName,
selfDefendingCode,
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
stringArrayCacheName: this.stringArrayCacheName
stringArrayFunctionName: this.stringArrayFunctionName
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class StringArrayCallsWrapperRc4CodeHelper extends StringArrayCallsWrappe
rc4Polyfill,
selfDefendingCode,
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
stringArrayCacheName: this.stringArrayCacheName
stringArrayFunctionName: this.stringArrayFunctionName
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 `
Expand All @@ -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) {
Expand All @@ -36,7 +37,7 @@ export function StringArrayRC4DecodeTemplate (
}

value = {stringArrayCallsWrapperName}.${rc4Identifier}(value, key);
{stringArrayCacheName}[cacheKey] = value;
{stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey] = value;
} else {
value = cachedValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading