SelfDefendingNodesGroup.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
  2. import { IOptions } from '../interfaces/IOptions';
  3. import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData';
  4. import { AppendState } from '../enums/AppendState';
  5. import { AbstractNodesGroup } from './AbstractNodesGroup';
  6. import { NodeAppender } from '../NodeAppender';
  7. import { NodeCallsControllerFunctionNode } from '../custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode';
  8. import { SelfDefendingUnicodeNode } from '../custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode';
  9. import { Utils } from '../Utils';
  10. export class SelfDefendingNodesGroup extends AbstractNodesGroup {
  11. /**
  12. * @param stackTraceData
  13. * @param options
  14. */
  15. constructor (stackTraceData: IStackTraceData[], options: IOptions) {
  16. super(stackTraceData, options);
  17. if (!this.options.selfDefending) {
  18. return;
  19. }
  20. const callsControllerFunctionName: string = Utils.getRandomVariableName();
  21. const randomStackTraceIndex: number = NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length);
  22. const selfDefendingUnicodeNode: ICustomNode = new SelfDefendingUnicodeNode(
  23. this.stackTraceData,
  24. callsControllerFunctionName,
  25. randomStackTraceIndex,
  26. this.options
  27. );
  28. const nodeCallsControllerFunctionNode: ICustomNode = new NodeCallsControllerFunctionNode(
  29. this.stackTraceData,
  30. callsControllerFunctionName,
  31. randomStackTraceIndex,
  32. this.options
  33. );
  34. selfDefendingUnicodeNode.setAppendState(AppendState.AfterObfuscation);
  35. nodeCallsControllerFunctionNode.setAppendState(AppendState.AfterObfuscation);
  36. this.nodes.set(
  37. 'selfDefendingUnicodeNode',
  38. selfDefendingUnicodeNode
  39. );
  40. this.nodes.set(
  41. 'SelfDefendingNodeCallsControllerFunctionNode',
  42. nodeCallsControllerFunctionNode
  43. );
  44. }
  45. }