StringArrayNodesGroup.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
  2. import { AppendState } from '../enums/AppendState';
  3. import { StringArrayCallsWrapper } from '../custom-nodes/string-array-nodes/StringArrayCallsWrapper';
  4. import { StringArrayNode } from '../custom-nodes/string-array-nodes/StringArrayNode';
  5. import { StringArrayRotateFunctionNode } from '../custom-nodes/string-array-nodes/StringArrayRotateFunctionNode';
  6. import { AbstractNodesGroup } from './AbstractNodesGroup';
  7. import { StringArrayStorage } from '../storages/string-array/StringArrayStorage';
  8. import { Utils } from '../Utils';
  9. import { IStorage } from '../interfaces/IStorage';
  10. export class StringArrayNodesGroup extends AbstractNodesGroup {
  11. /**
  12. * @type {AppendState}
  13. */
  14. protected appendState: AppendState = AppendState.AfterObfuscation;
  15. /**
  16. * @type {string}
  17. */
  18. private stringArrayName: string = Utils.getRandomVariableName(StringArrayNode.ARRAY_RANDOM_LENGTH);
  19. /**
  20. * @type {string}
  21. */
  22. private stringArrayCallsWrapper: string = Utils.getRandomVariableName(StringArrayNode.ARRAY_RANDOM_LENGTH);
  23. /**
  24. * @type {number}
  25. */
  26. private stringArrayRotateValue: number;
  27. /**
  28. * @returns {Map<string, ICustomNode> | undefined}
  29. */
  30. public getNodes (): Map <string, ICustomNode> | undefined {
  31. if (!this.options.stringArray) {
  32. return;
  33. }
  34. if (this.options.rotateStringArray) {
  35. this.stringArrayRotateValue = Utils.getRandomInteger(100, 500);
  36. } else {
  37. this.stringArrayRotateValue = 0;
  38. }
  39. const stringArray: IStorage <string> = new StringArrayStorage();
  40. const stringArrayNode: ICustomNode = new StringArrayNode(
  41. stringArray,
  42. this.stringArrayName,
  43. this.stringArrayRotateValue,
  44. this.options
  45. );
  46. const customNodes: Map <string, ICustomNode> = new Map <string, ICustomNode> ([
  47. [
  48. 'stringArrayNode', stringArrayNode,
  49. ],
  50. [
  51. 'stringArrayCallsWrapper',
  52. new StringArrayCallsWrapper(
  53. this.stringArrayCallsWrapper,
  54. this.stringArrayName,
  55. stringArray,
  56. this.options
  57. )
  58. ]
  59. ]);
  60. if (this.options.rotateStringArray) {
  61. customNodes.set(
  62. 'stringArrayRotateFunctionNode',
  63. new StringArrayRotateFunctionNode(
  64. this.stringArrayName,
  65. stringArray,
  66. this.stringArrayRotateValue,
  67. this.options
  68. )
  69. );
  70. }
  71. return this.syncCustomNodesWithNodesGroup(customNodes);
  72. }
  73. }