UnicodeArrayNode.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import 'format-unicorn';
  2. import { INode } from '../../interfaces/nodes/INode';
  3. import { IOptions } from "../../interfaces/IOptions";
  4. import { TNodeWithBlockStatement } from "../../types/TNodeWithBlockStatement";
  5. import { AppendState } from '../../enums/AppendState';
  6. import { UnicodeArray } from '../../UnicodeArray';
  7. import { UnicodeArrayTemplate } from "../../templates/custom-nodes/unicode-array-nodes/unicode-array-node/UnicodeArrayTemplate";
  8. import { Node } from '../Node';
  9. import { NodeUtils } from "../../NodeUtils";
  10. export class UnicodeArrayNode extends Node {
  11. /**
  12. * @type {number}
  13. */
  14. public static UNICODE_ARRAY_RANDOM_LENGTH: number = 4;
  15. /**
  16. * @type {AppendState}
  17. */
  18. protected appendState: AppendState = AppendState.AfterObfuscation;
  19. /**
  20. * @type {UnicodeArray}
  21. */
  22. private unicodeArray: UnicodeArray;
  23. /**
  24. * @type {string}
  25. */
  26. private unicodeArrayName: string;
  27. /**
  28. * @type {number}
  29. */
  30. private unicodeArrayRotateValue: number;
  31. /**
  32. * @param unicodeArray
  33. * @param unicodeArrayName
  34. * @param unicodeArrayRotateValue
  35. * @param options
  36. */
  37. constructor (
  38. unicodeArray: UnicodeArray,
  39. unicodeArrayName: string,
  40. unicodeArrayRotateValue: number = 0,
  41. options: IOptions
  42. ) {
  43. super(options);
  44. this.unicodeArray = unicodeArray;
  45. this.unicodeArrayName = unicodeArrayName;
  46. this.unicodeArrayRotateValue = unicodeArrayRotateValue;
  47. }
  48. /**
  49. * @param blockScopeNode
  50. */
  51. public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
  52. if (!this.unicodeArray.getLength()) {
  53. return;
  54. }
  55. NodeUtils.prependNode(blockScopeNode.body, this.getNode());
  56. }
  57. /**
  58. * @returns {string}
  59. */
  60. public getNodeIdentifier (): string {
  61. return this.unicodeArrayName;
  62. }
  63. /**
  64. * @returns {UnicodeArray}
  65. */
  66. public getNodeData (): UnicodeArray {
  67. return this.unicodeArray;
  68. }
  69. /**
  70. * @returns {INode}
  71. */
  72. public getNode (): INode {
  73. this.unicodeArray.rotateArray(this.unicodeArrayRotateValue);
  74. return super.getNode();
  75. }
  76. /**
  77. * @param data
  78. */
  79. public updateNodeData (data: string): void {
  80. this.unicodeArray.addToArray(data);
  81. }
  82. /**
  83. * @returns {INode}
  84. */
  85. protected getNodeStructure (): INode {
  86. return NodeUtils.convertCodeToStructure(
  87. UnicodeArrayTemplate().formatUnicorn({
  88. unicodeArrayName: this.unicodeArrayName,
  89. unicodeArray: this.unicodeArray.toString()
  90. })
  91. );
  92. }
  93. }