mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Sync with master
This commit is contained in:
@@ -70,7 +70,7 @@ export class ASTParserFacade {
|
||||
sourceType
|
||||
};
|
||||
|
||||
const program: ESTree.Program = <any>acorn
|
||||
const program: acorn.Node & ESTree.Program = <acorn.Node & ESTree.Program>acorn
|
||||
.parse(sourceCode, config);
|
||||
|
||||
if (comments.length) {
|
||||
|
||||
@@ -26,7 +26,8 @@ export class StringArrayCallsWrapperBase64CodeHelper extends StringArrayCallsWra
|
||||
atobFunctionName,
|
||||
selfDefendingCode,
|
||||
stringArrayName: this.stringArrayName,
|
||||
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
|
||||
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
|
||||
stringArrayCacheName: this.stringArrayCacheName
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,12 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
|
||||
@initializable()
|
||||
protected stringArrayCallsWrapperName!: string;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
protected stringArrayCacheName!: string;
|
||||
|
||||
/**
|
||||
* @type {IEscapeSequenceEncoder}
|
||||
*/
|
||||
@@ -84,6 +90,8 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
|
||||
this.stringArrayName = stringArrayName;
|
||||
this.stringArrayCallsWrapperName = stringArrayCallsWrapperName;
|
||||
this.indexShiftAmount = indexShiftAmount;
|
||||
|
||||
this.stringArrayCacheName = this.randomGenerator.getRandomString(6);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,6 +115,7 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
|
||||
decodeCodeHelperTemplate,
|
||||
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
|
||||
stringArrayName: this.stringArrayName,
|
||||
stringArrayCacheName: this.stringArrayCacheName,
|
||||
indexShiftAmount: this.indexShiftAmount
|
||||
}),
|
||||
{
|
||||
|
||||
@@ -13,12 +13,14 @@ export class StringArrayCallsWrapperRc4CodeHelper extends StringArrayCallsWrappe
|
||||
*/
|
||||
protected override getDecodeStringArrayTemplate (): string {
|
||||
const atobFunctionName: string = this.randomGenerator.getRandomString(6);
|
||||
const rc4FunctionName: string = this.randomGenerator.getRandomString(6);
|
||||
|
||||
const atobPolyfill: string = this.customCodeHelperFormatter.formatTemplate(AtobTemplate(), {
|
||||
atobFunctionName
|
||||
});
|
||||
const rc4Polyfill: string = this.customCodeHelperFormatter.formatTemplate(Rc4Template(), {
|
||||
atobFunctionName
|
||||
atobFunctionName,
|
||||
rc4FunctionName
|
||||
});
|
||||
|
||||
const selfDefendingCode: string = this.getSelfDefendingTemplate();
|
||||
@@ -27,10 +29,12 @@ export class StringArrayCallsWrapperRc4CodeHelper extends StringArrayCallsWrappe
|
||||
StringArrayRC4DecodeTemplate(this.randomGenerator),
|
||||
{
|
||||
atobPolyfill,
|
||||
rc4FunctionName,
|
||||
rc4Polyfill,
|
||||
selfDefendingCode,
|
||||
stringArrayName: this.stringArrayName,
|
||||
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
|
||||
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
|
||||
stringArrayCacheName: this.stringArrayCacheName
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
+8
-1
@@ -11,6 +11,8 @@ export function AtobTemplate (): string {
|
||||
const chars = '${base64alphabetSwapped}';
|
||||
|
||||
let output = '';
|
||||
let tempEncodedString = '';
|
||||
|
||||
for (
|
||||
let bc = 0, bs, buffer, idx = 0;
|
||||
buffer = input.charAt(idx++);
|
||||
@@ -19,7 +21,12 @@ export function AtobTemplate (): string {
|
||||
) {
|
||||
buffer = chars.indexOf(buffer);
|
||||
}
|
||||
return output;
|
||||
|
||||
for (let k = 0, length = output.length; k < length; k++) {
|
||||
tempEncodedString += '%' + ('00' + output.charCodeAt(k).toString(16)).slice(-2);
|
||||
}
|
||||
|
||||
return decodeURIComponent(tempEncodedString);
|
||||
};
|
||||
`;
|
||||
}
|
||||
|
||||
+4
-10
@@ -3,17 +3,11 @@
|
||||
*/
|
||||
export function Rc4Template (): string {
|
||||
return `
|
||||
const rc4 = function (str, key) {
|
||||
let s = [], j = 0, x, res = '', newStr = '';
|
||||
const {rc4FunctionName} = function (str, key) {
|
||||
let s = [], j = 0, x, output = '';
|
||||
|
||||
str = {atobFunctionName}(str);
|
||||
|
||||
for (let k = 0, length = str.length; k < length; k++) {
|
||||
newStr += '%' + ('00' + str.charCodeAt(k).toString(16)).slice(-2);
|
||||
}
|
||||
|
||||
str = decodeURIComponent(newStr);
|
||||
|
||||
let i;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
@@ -36,10 +30,10 @@ export function Rc4Template (): string {
|
||||
x = s[i];
|
||||
s[i] = s[j];
|
||||
s[j] = x;
|
||||
res += String.fromCharCode(str.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);
|
||||
output += String.fromCharCode(str.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);
|
||||
}
|
||||
|
||||
return res;
|
||||
return output;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
+9
-20
@@ -10,38 +10,27 @@ export function StringArrayBase64DecodeTemplate (
|
||||
): string {
|
||||
const identifierLength: number = 6;
|
||||
const initializedIdentifier: string = randomGenerator.getRandomString(identifierLength);
|
||||
const base64DecodeFunctionIdentifier: string = randomGenerator.getRandomString(identifierLength);
|
||||
const dataIdentifier: string = randomGenerator.getRandomString(identifierLength);
|
||||
const base64Identifier: string = randomGenerator.getRandomString(identifierLength);
|
||||
|
||||
return `
|
||||
if ({stringArrayCallsWrapperName}.${initializedIdentifier} === undefined) {
|
||||
{atobPolyfill}
|
||||
|
||||
{stringArrayCallsWrapperName}.${base64DecodeFunctionIdentifier} = function (str) {
|
||||
const string = {atobFunctionName}(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}.${base64Identifier} = {atobFunctionName};
|
||||
|
||||
{stringArrayCacheName} = arguments;
|
||||
|
||||
{stringArrayCallsWrapperName}.${initializedIdentifier} = true;
|
||||
}
|
||||
|
||||
const firstValue = {stringArrayName}[0];
|
||||
const cacheKey = index + firstValue;
|
||||
const cachedValue = {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey];
|
||||
|
||||
if (cachedValue === undefined) {
|
||||
const cachedValue = {stringArrayCacheName}[cacheKey];
|
||||
|
||||
if (!cachedValue) {
|
||||
{selfDefendingCode}
|
||||
|
||||
value = {stringArrayCallsWrapperName}.${base64DecodeFunctionIdentifier}(value);
|
||||
{stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey] = value;
|
||||
value = {stringArrayCallsWrapperName}.${base64Identifier}(value);
|
||||
{stringArrayCacheName}[cacheKey] = value;
|
||||
} else {
|
||||
value = cachedValue;
|
||||
}
|
||||
|
||||
+14
-7
@@ -1,16 +1,23 @@
|
||||
/**
|
||||
* 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} (index, key) {
|
||||
index = index - {indexShiftAmount};
|
||||
function {stringArrayCallsWrapperName} ({stringArrayCacheName}, key) {
|
||||
{stringArrayCallsWrapperName} = function (index, key) {
|
||||
index = index - {indexShiftAmount};
|
||||
|
||||
let value = {stringArrayName}[index];
|
||||
|
||||
{decodeCodeHelperTemplate}
|
||||
|
||||
let value = {stringArrayName}[index];
|
||||
|
||||
{decodeCodeHelperTemplate}
|
||||
|
||||
return value;
|
||||
return value;
|
||||
};
|
||||
|
||||
return {stringArrayCallsWrapperName}({stringArrayCacheName}, key);
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
+5
-7
@@ -11,26 +11,24 @@ 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 `
|
||||
if ({stringArrayCallsWrapperName}.${initializedIdentifier} === undefined) {
|
||||
{atobPolyfill}
|
||||
|
||||
{rc4Polyfill}
|
||||
{stringArrayCallsWrapperName}.${rc4Identifier} = rc4;
|
||||
{stringArrayCallsWrapperName}.${rc4Identifier} = {rc4FunctionName};
|
||||
|
||||
{stringArrayCallsWrapperName}.${dataIdentifier} = {};
|
||||
{stringArrayCacheName} = arguments;
|
||||
|
||||
{stringArrayCallsWrapperName}.${initializedIdentifier} = true;
|
||||
}
|
||||
|
||||
const firstValue = {stringArrayName}[0];
|
||||
const cacheKey = index + firstValue;
|
||||
const cachedValue = {stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey];
|
||||
const cachedValue = {stringArrayCacheName}[cacheKey];
|
||||
|
||||
if (cachedValue === undefined) {
|
||||
if (!cachedValue) {
|
||||
if ({stringArrayCallsWrapperName}.${onceIdentifier} === undefined) {
|
||||
{selfDefendingCode}
|
||||
|
||||
@@ -38,7 +36,7 @@ export function StringArrayRC4DecodeTemplate (
|
||||
}
|
||||
|
||||
value = {stringArrayCallsWrapperName}.${rc4Identifier}(value, key);
|
||||
{stringArrayCallsWrapperName}.${dataIdentifier}[cacheKey] = value;
|
||||
{stringArrayCacheName}[cacheKey] = value;
|
||||
} else {
|
||||
value = cachedValue;
|
||||
}
|
||||
|
||||
+8
-1
@@ -52,6 +52,13 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|
||||
NodeTransformer.ScopeIdentifiersTransformer
|
||||
];
|
||||
|
||||
/**
|
||||
* @type {NodeTransformer[]}
|
||||
*/
|
||||
public override readonly runAfter: NodeTransformer[] = [
|
||||
NodeTransformer.ScopeIdentifiersTransformer
|
||||
];
|
||||
|
||||
/**
|
||||
* @type {Set <BlockStatement>}
|
||||
*/
|
||||
@@ -237,7 +244,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|
||||
}
|
||||
};
|
||||
|
||||
case NodeTransformationStage.Finalizing:
|
||||
case NodeTransformationStage.RenameIdentifiers:
|
||||
if (!this.deadCodeInjectionRootAstHostNodeSet.size) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user