import 'format-unicorn';
import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
import { TStatement } from '../../types/TStatement';
import { IOptions } from '../../interfaces/IOptions';
import { AppendState } from '../../enums/AppendState';
import { NO_CUSTOM_NODES_PRESET } from '../../preset-options/NoCustomNodesPreset';
import { SelfDefendingTemplate } from '../../templates/custom-nodes/unicode-array-nodes/unicode-array-rotate-function-node/SelfDefendingTemplate';
import { UnicodeArrayRotateFunctionTemplate } from '../../templates/custom-nodes/unicode-array-nodes/unicode-array-rotate-function-node/UnicodeArrayRotateFunctionTemplate';
import { AbstractCustomNode } from '../AbstractCustomNode';
import { JavaScriptObfuscator } from '../../JavaScriptObfuscator';
import { NodeAppender } from '../../NodeAppender';
import { NodeUtils } from '../../NodeUtils';
import { UnicodeArray } from '../../UnicodeArray';
import { Utils } from '../../Utils';
export class UnicodeArrayRotateFunctionNode extends AbstractCustomNode {
/**
* @type {AppendState}
*/
protected appendState: AppendState = AppendState.AfterObfuscation;
/**
* @type {UnicodeArray}
*/
private unicodeArray: UnicodeArray;
/**
* @type {string}
*/
private unicodeArrayName: string;
/**
* @param {number}
*/
private unicodeArrayRotateValue: number;
/**
* @param unicodeArrayName
* @param unicodeArray
* @param unicodeArrayRotateValue
* @param options
*/
constructor (
unicodeArrayName: string,
unicodeArray: UnicodeArray,
unicodeArrayRotateValue: number,
options: IOptions
) {
super(options);
this.unicodeArrayName = unicodeArrayName;
this.unicodeArray = unicodeArray;
this.unicodeArrayRotateValue = unicodeArrayRotateValue;
}
/**
* @param blockScopeNode
*/
public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
Iif (!this.unicodeArray.getLength()) {
return;
}
NodeAppender.insertNodeAtIndex(blockScopeNode, this.getNode(), 1);
}
/**
* @returns {TStatement[]}
*/
public getNode (): TStatement[] {
return super.getNode();
}
/**
* @returns {TStatement[]}
*/
protected getNodeStructure (): TStatement[] {
let code: string = '',
timesName: string = Utils.getRandomVariableName(),
whileFunctionName: string = Utils.getRandomVariableName();
if (this.options.selfDefending) {
code = SelfDefendingTemplate().formatUnicorn({
timesName,
whileFunctionName
});
} else {
code = `${whileFunctionName}(++${timesName})`;
}
return NodeUtils.convertCodeToStructure(
JavaScriptObfuscator.obfuscate(
UnicodeArrayRotateFunctionTemplate().formatUnicorn({
code,
timesName,
unicodeArrayName: this.unicodeArrayName,
unicodeArrayRotateValue: Utils.decToHex(this.unicodeArrayRotateValue),
whileFunctionName
}),
NO_CUSTOM_NODES_PRESET
).getObfuscatedCode()
);
}
}
|