UnicodeArrayNodesGroup.ts 2.9 KB

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