This commit is contained in:
Timofey Kachalov
2025-11-30 00:39:32 +04:00
committed by GitHub
parent 6640907504
commit 64edd44d68
8 changed files with 21 additions and 28 deletions
@@ -29,7 +29,7 @@ export class StringArrayCallsWrapperBase64CodeHelper extends StringArrayCallsWra
atobFunctionName,
selfDefendingCode,
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
stringArrayCacheName: this.stringArrayCacheName
stringArrayFunctionName: this.stringArrayFunctionName
}
);
}
@@ -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
}),
@@ -39,7 +39,7 @@ export class StringArrayCallsWrapperRc4CodeHelper extends StringArrayCallsWrappe
rc4Polyfill,
selfDefendingCode,
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
stringArrayCacheName: this.stringArrayCacheName
stringArrayFunctionName: this.stringArrayFunctionName
}
);
}
@@ -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;
}
@@ -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;
}
`;
}
@@ -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;
}