import * as format from 'string-template';
import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement';
import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent';
import { IOptions } from '../../interfaces/options/IOptions';
import { ObfuscationEvents } from '../../enums/ObfuscationEvents';
import { DebugProtectionFunctionTemplate } from '../../templates/custom-nodes/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate';
import { AbstractCustomNode } from '../AbstractCustomNode';
import { NodeAppender } from '../../node/NodeAppender';
import { Utils } from '../../Utils';
export class DebugProtectionFunctionNode extends AbstractCustomNode {
/**
* @type {TObfuscationEvent}
*/
protected readonly appendEvent: TObfuscationEvent = ObfuscationEvents.BeforeObfuscation;
/**
* @type {string}
*/
private debugProtectionFunctionName: string;
/**
* @param debugProtectionFunctionName
* @param options
*/
constructor (debugProtectionFunctionName: string, options: IOptions) {
super(options);
this.debugProtectionFunctionName = debugProtectionFunctionName;
}
/**
* @param blockScopeNode
*/
public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
let programBodyLength: number = blockScopeNode.body.length,
randomIndex: number = Utils.getRandomInteger(0, programBodyLength);
NodeAppender.insertNodeAtIndex(blockScopeNode, this.getNode(), randomIndex);
}
/**
* @returns {string}
*/
public getCode (): string {
return format(DebugProtectionFunctionTemplate(), {
debugProtectionFunctionName: this.debugProtectionFunctionName
});
}
}
|