UnicodeArrayNodesGroup.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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('rotateUnicodeArray')) {
  27. this.unicodeArrayRotateValue = Utils.getRandomGenerator().integer({
  28. min: 100,
  29. max: 500
  30. });
  31. } else {
  32. this.unicodeArrayRotateValue = 0;
  33. }
  34. let unicodeArrayNode: UnicodeArrayNode = new UnicodeArrayNode(
  35. this.unicodeArrayName,
  36. this.unicodeArrayRotateValue,
  37. this.options
  38. ),
  39. unicodeArray: string [] = unicodeArrayNode.getNodeData();
  40. this.nodes.set(
  41. 'unicodeArrayNode',
  42. unicodeArrayNode
  43. );
  44. if (this.options.get('wrapUnicodeArrayCalls')) {
  45. this.nodes.set(
  46. 'unicodeArrayCallsWrapper',
  47. new UnicodeArrayCallsWrapper(
  48. this.unicodeArrayTranslatorName,
  49. this.unicodeArrayName,
  50. unicodeArray,
  51. this.options
  52. )
  53. );
  54. }
  55. if (this.options.get('encodeUnicodeLiterals')) {
  56. this.nodes.set(
  57. 'unicodeArrayDecodeNode',
  58. new UnicodeArrayDecodeNode (
  59. this.unicodeArrayName,
  60. unicodeArray,
  61. this.options
  62. )
  63. );
  64. }
  65. if (this.options.get('rotateUnicodeArray')) {
  66. this.nodes.set(
  67. 'unicodeArrayRotateFunctionNode',
  68. new UnicodeArrayRotateFunctionNode(
  69. this.unicodeArrayName,
  70. unicodeArray,
  71. this.unicodeArrayRotateValue,
  72. this.options
  73. )
  74. );
  75. }
  76. }
  77. }