import { injectable, inject } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as format from 'string-template'; import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; import { IOptions } from '../../interfaces/options/IOptions'; import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData'; import { IStorage } from '../../interfaces/storages/IStorage'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; import { initializable } from '../../decorators/Initializable'; import { ControlFlowStorageTemplate } from '../../templates/custom-nodes/control-flow-storage-nodes/ControlFlowStorageTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { NodeAppender } from '../../node/NodeAppender'; @injectable() export class ControlFlowStorageNode extends AbstractCustomNode { /** * @type {TObfuscationEvent} */ protected readonly appendEvent: TObfuscationEvent = ObfuscationEvents.AfterObfuscation; /** * @type {IStorage } */ @initializable() private controlFlowStorage: IStorage ; /** * @type {string} */ @initializable() private controlFlowStorageName: string; /** * @param options */ constructor ( @inject(ServiceIdentifiers.IOptions) options: IOptions ) { super(options); } /** * @param controlFlowStorage * @param controlFlowStorageName */ public initialize (controlFlowStorage: IStorage , controlFlowStorageName: string): void { this.controlFlowStorage = controlFlowStorage; this.controlFlowStorageName = controlFlowStorageName; } /** * @param blockScopeNode * @param stackTraceData */ public appendNode (blockScopeNode: TNodeWithBlockStatement, stackTraceData: IStackTraceData[]): void { NodeAppender.prependNode(blockScopeNode, this.getNode()); } /** * @returns {string} */ public getCode (): string { return format(ControlFlowStorageTemplate(), { controlFlowStorage: this.controlFlowStorage.toString(), controlFlowStorageName: this.controlFlowStorageName }); } }