SelfDefendingCustomNodesFactory.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
  2. import { AppendState } from '../../../enums/AppendState';
  3. import { NodeCallsControllerFunctionNode } from '../../node-calls-controller-nodes/NodeCallsControllerFunctionNode';
  4. import { SelfDefendingUnicodeNode } from '../SelfDefendingUnicodeNode';
  5. import { AbstractCustomNodesFactory } from '../../AbstractCustomNodesFactory';
  6. import { NodeAppender } from '../../../node/NodeAppender';
  7. import { Utils } from '../../../Utils';
  8. export class SelfDefendingCustomNodesFactory extends AbstractCustomNodesFactory {
  9. /**
  10. * @type {AppendState}
  11. */
  12. protected appendState: AppendState = AppendState.AfterObfuscation;
  13. /**
  14. * @returns {Map<string, ICustomNode> | undefined}
  15. */
  16. public getNodes (): Map <string, ICustomNode> | undefined {
  17. if (!this.options.selfDefending) {
  18. return;
  19. }
  20. const callsControllerFunctionName: string = Utils.getRandomVariableName();
  21. const randomStackTraceIndex: number = NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length);
  22. return this.syncCustomNodesWithNodesGroup(new Map <string, ICustomNode> ([
  23. [
  24. 'selfDefendingUnicodeNode',
  25. new SelfDefendingUnicodeNode(
  26. this.stackTraceData,
  27. callsControllerFunctionName,
  28. randomStackTraceIndex,
  29. this.options
  30. )
  31. ],
  32. [
  33. 'SelfDefendingNodeCallsControllerFunctionNode',
  34. new NodeCallsControllerFunctionNode(
  35. this.stackTraceData,
  36. callsControllerFunctionName,
  37. randomStackTraceIndex,
  38. this.options
  39. )
  40. ]
  41. ]));
  42. }
  43. }