UnicodeArrayCallsWrapper.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { INode } from "../../interfaces/nodes/INode";
  2. import { IOptions } from "../../interfaces/IOptions";
  3. import { TNodeWithBlockStatement } from "../../types/TNodeWithBlockStatement";
  4. import { AppendState } from "../../enums/AppendState";
  5. import { Node } from '../Node';
  6. import { NodeUtils } from "../../NodeUtils";
  7. import { Utils } from "../../Utils";
  8. export class UnicodeArrayCallsWrapper extends Node {
  9. /**
  10. * @type {AppendState}
  11. */
  12. protected appendState: AppendState = AppendState.AfterObfuscation;
  13. /**
  14. * @type {string[]}
  15. */
  16. private unicodeArray: string[];
  17. /**
  18. * @type {string}
  19. */
  20. private unicodeArrayName: string;
  21. /**
  22. * @type {string}
  23. */
  24. private unicodeArrayCallsWrapperName: string;
  25. /**
  26. * @param unicodeArrayCallsWrapperName
  27. * @param unicodeArrayName
  28. * @param unicodeArray
  29. * @param options
  30. */
  31. constructor (
  32. unicodeArrayCallsWrapperName: string,
  33. unicodeArrayName: string,
  34. unicodeArray: string[],
  35. options: IOptions
  36. ) {
  37. super(options);
  38. this.unicodeArrayCallsWrapperName = unicodeArrayCallsWrapperName;
  39. this.unicodeArrayName = unicodeArrayName;
  40. this.unicodeArray = unicodeArray;
  41. }
  42. /**
  43. * @param blockScopeNode
  44. */
  45. public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
  46. NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
  47. }
  48. /**
  49. * @returns {string}
  50. */
  51. public getNodeIdentifier (): string {
  52. return this.unicodeArrayCallsWrapperName;
  53. };
  54. /**
  55. * @returns {INode}
  56. */
  57. public getNode (): INode {
  58. if (!this.unicodeArray.length) {
  59. return;
  60. }
  61. return super.getNode();
  62. }
  63. /**
  64. * @returns {INode}
  65. */
  66. protected getNodeStructure (): INode {
  67. let keyName: string = Utils.getRandomVariableName();
  68. return NodeUtils.convertCodeToStructure(`
  69. var ${this.unicodeArrayCallsWrapperName} = function (${keyName}) {
  70. return ${this.unicodeArrayName}[parseInt(${keyName}, 0x010)];
  71. };
  72. `);
  73. }
  74. }