forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringArrayBase64DecodeTemplate.ts
More file actions
47 lines (37 loc) · 1.79 KB
/
Copy pathStringArrayBase64DecodeTemplate.ts
File metadata and controls
47 lines (37 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { IRandomGenerator } from '../../../../interfaces/utils/IRandomGenerator';
/**
* @param {IRandomGenerator} randomGenerator
* @returns {string}
* @constructor
*/
export function StringArrayBase64DecodeTemplate (
randomGenerator: IRandomGenerator
): string {
const identifierLength: number = 6;
const initializedIdentifier: string = randomGenerator.getRandomString(identifierLength);
const base64DecodeFunctionIdentifier: string = randomGenerator.getRandomString(identifierLength);
const dataIdentifier: string = randomGenerator.getRandomString(identifierLength);
return `
if ({stringArrayCallsWrapperName}.${initializedIdentifier} === undefined) {
{atobPolyfill}
{stringArrayCallsWrapperName}.${base64DecodeFunctionIdentifier} = function (str) {
const string = atob(str);
let newStringChars = [];
for (let i = 0, length = string.length; i < length; i++) {
newStringChars += '%' + ('00' + string.charCodeAt(i).toString(16)).slice(-2);
}
return decodeURIComponent(newStringChars);
};
{stringArrayCallsWrapperName}.${dataIdentifier} = {};
{stringArrayCallsWrapperName}.${initializedIdentifier} = true;
}
const cachedValue = {stringArrayCallsWrapperName}.${dataIdentifier}[index];
if (cachedValue === undefined) {
{selfDefendingCode}
value = {stringArrayCallsWrapperName}.${base64DecodeFunctionIdentifier}(value);
{stringArrayCallsWrapperName}.${dataIdentifier}[index] = value;
} else {
value = cachedValue;
}
`;
}