DebugProtectionFunctionIntervalNode.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { injectable, inject } from 'inversify';
  2. import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
  3. import * as format from 'string-template';
  4. import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement';
  5. import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent';
  6. import { IOptions } from '../../interfaces/options/IOptions';
  7. import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData';
  8. import { ObfuscationEvents } from '../../enums/ObfuscationEvents';
  9. import { initializable } from '../../decorators/Initializable';
  10. import { DebugProtectionFunctionIntervalTemplate } from '../../templates/custom-nodes/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate';
  11. import { AbstractCustomNode } from '../AbstractCustomNode';
  12. import { NodeAppender } from '../../node/NodeAppender';
  13. @injectable()
  14. export class DebugProtectionFunctionIntervalNode extends AbstractCustomNode {
  15. /**
  16. * @type {TObfuscationEvent}
  17. */
  18. protected readonly appendEvent: TObfuscationEvent = ObfuscationEvents.BeforeObfuscation;
  19. /**
  20. * @type {string}
  21. */
  22. @initializable()
  23. private debugProtectionFunctionName: string;
  24. /**
  25. * @param options
  26. */
  27. constructor (
  28. @inject(ServiceIdentifiers.IOptions) options: IOptions
  29. ) {
  30. super(options);
  31. }
  32. /**
  33. * @param debugProtectionFunctionName
  34. */
  35. public initialize (debugProtectionFunctionName: string): void {
  36. this.debugProtectionFunctionName = debugProtectionFunctionName;
  37. }
  38. /**
  39. * @param blockScopeNode
  40. * @param stackTraceData
  41. */
  42. public appendNode (blockScopeNode: TNodeWithBlockStatement, stackTraceData: IStackTraceData[]): void {
  43. NodeAppender.appendNode(blockScopeNode, this.getNode());
  44. }
  45. /**
  46. * @returns {string}
  47. */
  48. public getCode (): string {
  49. return format(DebugProtectionFunctionIntervalTemplate(), {
  50. debugProtectionFunctionName: this.debugProtectionFunctionName
  51. });
  52. }
  53. }