UnicodeArrayNodesGroup.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { IOptions } from '../interfaces/IOptions';
  2. import { AbstractNodesGroup } from './AbstractNodesGroup';
  3. import { UnicodeArray } from '../UnicodeArray';
  4. import { UnicodeArrayCallsWrapper } from '../custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper';
  5. import { UnicodeArrayDecodeNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode';
  6. import { UnicodeArrayNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayNode';
  7. import { UnicodeArrayRotateFunctionNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode';
  8. import { Utils } from '../Utils';
  9. export class UnicodeArrayNodesGroup extends AbstractNodesGroup {
  10. /**
  11. * @type {string}
  12. */
  13. private unicodeArrayName: string = Utils.getRandomVariableName(UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH);
  14. /**
  15. * @type {number}
  16. */
  17. private unicodeArrayRotateValue: number;
  18. /**
  19. * @type {string}
  20. */
  21. private unicodeArrayTranslatorName: string = Utils.getRandomVariableName(UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH);
  22. /**
  23. * @param options
  24. */
  25. constructor (options: IOptions) {
  26. super(options);
  27. if (!this.options.unicodeArray) {
  28. return;
  29. }
  30. if (this.options.rotateUnicodeArray) {
  31. this.unicodeArrayRotateValue = Utils.getRandomGenerator().integer({
  32. min: 100,
  33. max: 500
  34. });
  35. } else {
  36. this.unicodeArrayRotateValue = 0;
  37. }
  38. let unicodeArray: UnicodeArray = new UnicodeArray(),
  39. unicodeArrayNode: UnicodeArrayNode = new UnicodeArrayNode(
  40. unicodeArray,
  41. this.unicodeArrayName,
  42. this.unicodeArrayRotateValue,
  43. this.options
  44. );
  45. this.nodes.set(
  46. 'unicodeArrayNode',
  47. unicodeArrayNode
  48. );
  49. if (this.options.wrapUnicodeArrayCalls) {
  50. this.nodes.set(
  51. 'unicodeArrayCallsWrapper',
  52. new UnicodeArrayCallsWrapper(
  53. this.unicodeArrayTranslatorName,
  54. this.unicodeArrayName,
  55. unicodeArray,
  56. this.options
  57. )
  58. );
  59. }
  60. if (this.options.encodeUnicodeLiterals) {
  61. this.nodes.set(
  62. 'unicodeArrayDecodeNode',
  63. new UnicodeArrayDecodeNode (
  64. this.unicodeArrayName,
  65. unicodeArray,
  66. this.options
  67. )
  68. );
  69. }
  70. if (this.options.rotateUnicodeArray) {
  71. this.nodes.set(
  72. 'unicodeArrayRotateFunctionNode',
  73. new UnicodeArrayRotateFunctionNode(
  74. this.unicodeArrayName,
  75. unicodeArray,
  76. this.unicodeArrayRotateValue,
  77. this.options
  78. )
  79. );
  80. }
  81. }
  82. }