BinaryExpressionFunctionNode.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { injectable, inject } from 'inversify';
  2. import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
  3. import * as format from 'string-template';
  4. import { TNodeWithBlockStatement } from '../../../types/node/TNodeWithBlockStatement';
  5. import { TObfuscationEvent } from '../../../types/event-emitters/TObfuscationEvent';
  6. import { IOptions } from '../../../interfaces/options/IOptions';
  7. import { IStackTraceData } from '../../../interfaces/stack-trace-analyzer/IStackTraceData';
  8. import { ObfuscationEvents } from '../../../enums/ObfuscationEvents';
  9. import { initializable } from '../../../decorators/Initializable';
  10. import { BinaryExpressionFunctionTemplate } from '../../../templates/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionFunctionTemplate';
  11. import { AbstractCustomNode } from '../../AbstractCustomNode';
  12. import { Utils } from '../../../Utils';
  13. @injectable()
  14. export class BinaryExpressionFunctionNode extends AbstractCustomNode {
  15. /**
  16. * @type {TObfuscationEvent}
  17. */
  18. protected readonly appendEvent: TObfuscationEvent = ObfuscationEvents.BeforeObfuscation;
  19. /**
  20. * @type {string}
  21. */
  22. @initializable()
  23. private operator: string;
  24. /**
  25. * @param options
  26. */
  27. constructor (
  28. @inject(ServiceIdentifiers.IOptions) options: IOptions
  29. ) {
  30. super(options);
  31. }
  32. /**
  33. * @param operator
  34. */
  35. initialize (operator: string): void {
  36. this.operator = operator;
  37. }
  38. /**
  39. * @param blockScopeNode
  40. * @param stackTraceData
  41. */
  42. public appendNode (blockScopeNode: TNodeWithBlockStatement, stackTraceData: IStackTraceData[]): void {}
  43. /**
  44. * @returns {string}
  45. */
  46. public getCode (): string {
  47. return format(BinaryExpressionFunctionTemplate(), {
  48. functionName: Utils.getRandomVariableName(1),
  49. operator: this.operator
  50. });
  51. }
  52. }