12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import 'format-unicorn';
- import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
- import { IOptions } from '../../interfaces/IOptions';
- import { AppendState } from '../../enums/AppendState';
- 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 {AppendState}
- */
- protected appendState: AppendState = AppendState.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.getRandomGenerator().integer({
- min: 0,
- max: programBodyLength
- });
- NodeAppender.insertNodeAtIndex(blockScopeNode, this.getNode(), randomIndex);
- }
- /**
- * @returns {string}
- */
- public getCode (): string {
- return DebugProtectionFunctionTemplate().formatUnicorn({
- debugProtectionFunctionName: this.debugProtectionFunctionName
- });
- }
- /**
- * @returns {string}
- */
- public getNodeIdentifier (): string {
- return this.debugProtectionFunctionName;
- }
- }
|