forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtobTemplate.ts
More file actions
40 lines (34 loc) · 1.44 KB
/
Copy pathAtobTemplate.ts
File metadata and controls
40 lines (34 loc) · 1.44 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
import { base64alphabetSwapped } from '../../../../constants/Base64AlphabetSwapped';
/**
* This atob logic completely ignores padding characters
*
* @returns {string}
*/
export function AtobTemplate (selfDefending: boolean): string {
return `
var {atobFunctionName} = function (input) {
const chars = '${base64alphabetSwapped}';
let output = '';
let tempEncodedString = '';
${selfDefending ? 'let func = output + {atobFunctionName};' : ''}
for (
let bc = 0, bs, buffer, idx = 0;
buffer = input.charAt(idx++);
~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4)
? output += ${((): string => {
const basePart: string = 'String.fromCharCode(255 & bs >> (-2 * bc & 6))';
return selfDefending
? `((func.charCodeAt(idx + 10) - 10 !== 0) ? ${basePart} : bc)`
: basePart;
})()}
: 0
) {
buffer = chars.indexOf(buffer);
}
for (let k = 0, length = output.length; k < length; k++) {
tempEncodedString += '%' + ('00' + output.charCodeAt(k).toString(16)).slice(-2);
}
return decodeURIComponent(tempEncodedString);
};
`;
}