mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
stringArray calls wrappers now inserted as FunctionDeclaration nodes at random indexes
This commit is contained in:
@@ -22,6 +22,7 @@ import { AbstractCustomCodeHelperGroup } from '../../AbstractCustomCodeHelperGro
|
||||
import { NodeAppender } from '../../../node/NodeAppender';
|
||||
import { StringArrayCallsWrapperCodeHelper } from '../StringArrayCallsWrapperCodeHelper';
|
||||
import { StringArrayCodeHelper } from '../StringArrayCodeHelper';
|
||||
import { TStatement } from '../../../types/node/TStatement';
|
||||
|
||||
@injectable()
|
||||
export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup {
|
||||
@@ -90,14 +91,22 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup {
|
||||
|
||||
// stringArrayCallsWrapper helper nodes append
|
||||
const stringArrayEncodingsLength: number = this.options.stringArrayEncoding.length;
|
||||
for (let i = 0; i < stringArrayEncodingsLength; i++) {
|
||||
// Stating from index 1 and forward. 0 index is reserved for string array itself.
|
||||
let randomIndex: number = 1;
|
||||
for (let i = 0; i < stringArrayEncodingsLength; i++, randomIndex++) {
|
||||
const stringArrayEncoding: TStringArrayEncoding = this.options.stringArrayEncoding[i];
|
||||
const stringArrayCallsWrapperCodeHelperName: CustomCodeHelper = this.getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding);
|
||||
|
||||
const scopeStatements: TStatement[] = NodeAppender.getScopeStatements(nodeWithStatements);
|
||||
randomIndex = this.randomGenerator.getRandomInteger(
|
||||
randomIndex,
|
||||
scopeStatements.length - 1
|
||||
);
|
||||
|
||||
this.appendCustomNodeIfExist(
|
||||
stringArrayCallsWrapperCodeHelperName,
|
||||
(customCodeHelper: ICustomCodeHelper<TInitialData<StringArrayCallsWrapperCodeHelper>>) => {
|
||||
NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), i + 1);
|
||||
NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), randomIndex);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
export function StringArrayCallsWrapperTemplate (): string {
|
||||
return `
|
||||
const {stringArrayCallsWrapperName} = function (index, key) {
|
||||
function {stringArrayCallsWrapperName} (index, key) {
|
||||
index = index - {indexShiftAmount};
|
||||
|
||||
let value = {stringArrayName}[index];
|
||||
@@ -11,6 +11,6 @@ export function StringArrayCallsWrapperTemplate (): string {
|
||||
{decodeCodeHelperTemplate}
|
||||
|
||||
return value;
|
||||
};
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
+12
-12
@@ -82,6 +82,18 @@ export class NodeAppender {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TNodeWithStatements} nodeWithStatements
|
||||
* @returns {TStatement[]}
|
||||
*/
|
||||
public static getScopeStatements (nodeWithStatements: TNodeWithStatements): TStatement[] {
|
||||
if (NodeGuards.isSwitchCaseNode(nodeWithStatements)) {
|
||||
return nodeWithStatements.consequent;
|
||||
}
|
||||
|
||||
return nodeWithStatements.body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TNodeWithStatements} nodeWithStatements
|
||||
* @param {TStatement[]} statements
|
||||
@@ -148,18 +160,6 @@ export class NodeAppender {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TNodeWithStatements} nodeWithStatements
|
||||
* @returns {TStatement[]}
|
||||
*/
|
||||
private static getScopeStatements (nodeWithStatements: TNodeWithStatements): TStatement[] {
|
||||
if (NodeGuards.isSwitchCaseNode(nodeWithStatements)) {
|
||||
return nodeWithStatements.consequent;
|
||||
}
|
||||
|
||||
return nodeWithStatements.body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TNodeWithStatements} nodeWithStatements
|
||||
* @param {TStatement[]} statements
|
||||
|
||||
Reference in New Issue
Block a user