mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
import { injectable, inject } from 'inversify';
|
|
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
|
|
|
|
import * as format from 'string-template';
|
|
|
|
import { IOptions } from '../../interfaces/options/IOptions';
|
|
import { IStorage } from '../../interfaces/storages/IStorage';
|
|
|
|
import { initializable } from '../../decorators/Initializable';
|
|
|
|
import { NO_CUSTOM_NODES_PRESET } from '../../preset-options/NoCustomNodesPreset';
|
|
|
|
import { SelfDefendingTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate';
|
|
import { StringArrayRotateFunctionTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/StringArrayRotateFunctionTemplate';
|
|
|
|
import { AbstractCustomNode } from '../AbstractCustomNode';
|
|
import { JavaScriptObfuscator } from '../../JavaScriptObfuscator';
|
|
import { Utils } from '../../Utils';
|
|
|
|
@injectable()
|
|
export class StringArrayRotateFunctionNode extends AbstractCustomNode {
|
|
/**
|
|
* @type {IStorage <string>}
|
|
*/
|
|
@initializable()
|
|
private stringArray: IStorage <string>;
|
|
|
|
/**
|
|
* @type {string}
|
|
*/
|
|
@initializable()
|
|
private stringArrayName: string;
|
|
|
|
/**
|
|
* @param {number}
|
|
*/
|
|
@initializable()
|
|
private stringArrayRotateValue: number;
|
|
|
|
/**
|
|
* @param options
|
|
*/
|
|
constructor (
|
|
@inject(ServiceIdentifiers.IOptions) options: IOptions
|
|
) {
|
|
super(options);
|
|
}
|
|
|
|
/**
|
|
* @param stringArray
|
|
* @param stringArrayName
|
|
* @param stringArrayRotateValue
|
|
*/
|
|
public initialize (
|
|
stringArray: IStorage <string>,
|
|
stringArrayName: string,
|
|
stringArrayRotateValue: number
|
|
): void {
|
|
this.stringArray = stringArray;
|
|
this.stringArrayName = stringArrayName;
|
|
this.stringArrayRotateValue = stringArrayRotateValue;
|
|
}
|
|
|
|
/**
|
|
* @returns {string}
|
|
*/
|
|
public getCode (): string {
|
|
let code: string = '',
|
|
timesName: string = Utils.getRandomVariableName(),
|
|
whileFunctionName: string = Utils.getRandomVariableName();
|
|
|
|
if (this.options.selfDefending) {
|
|
code = format(SelfDefendingTemplate(), {
|
|
timesName,
|
|
whileFunctionName
|
|
});
|
|
} else {
|
|
code = `${whileFunctionName}(++${timesName})`;
|
|
}
|
|
|
|
return JavaScriptObfuscator.obfuscate(
|
|
format(StringArrayRotateFunctionTemplate(), {
|
|
code,
|
|
timesName,
|
|
stringArrayName: this.stringArrayName,
|
|
stringArrayRotateValue: Utils.decToHex(this.stringArrayRotateValue),
|
|
whileFunctionName
|
|
}),
|
|
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
|
|
seed: this.options.seed
|
|
})
|
|
).getObfuscatedCode();
|
|
}
|
|
}
|