DebugProtectionFunctionIntervalCodeHelper.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { inject, injectable, } from 'inversify';
  2. import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
  3. import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
  4. import { TStatement } from '../../types/node/TStatement';
  5. import { ICustomCodeHelperFormatter } from '../../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
  6. import { ICustomCodeHelperObfuscator } from '../../interfaces/custom-code-helpers/ICustomCodeHelperObfuscator';
  7. import { IOptions } from '../../interfaces/options/IOptions';
  8. import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
  9. import { initializable } from '../../decorators/Initializable';
  10. import { DebugProtectionFunctionIntervalTemplate } from './templates/debug-protection-function-interval/DebugProtectionFunctionIntervalTemplate';
  11. import { AbstractCustomCodeHelper } from '../AbstractCustomCodeHelper';
  12. import { NodeUtils } from '../../node/NodeUtils';
  13. @injectable()
  14. export class DebugProtectionFunctionIntervalCodeHelper extends AbstractCustomCodeHelper {
  15. /**
  16. * @type {string}
  17. */
  18. @initializable()
  19. private debugProtectionFunctionName!: string;
  20. /**
  21. * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
  22. * @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
  23. * @param {ICustomCodeHelperObfuscator} customCodeHelperObfuscator
  24. * @param {IRandomGenerator} randomGenerator
  25. * @param {IOptions} options
  26. */
  27. public constructor (
  28. @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
  29. identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
  30. @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter,
  31. @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator,
  32. @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
  33. @inject(ServiceIdentifiers.IOptions) options: IOptions
  34. ) {
  35. super(
  36. identifierNamesGeneratorFactory,
  37. customCodeHelperFormatter,
  38. customCodeHelperObfuscator,
  39. randomGenerator,
  40. options
  41. );
  42. }
  43. /**
  44. * @param {string} debugProtectionFunctionName
  45. */
  46. public initialize (debugProtectionFunctionName: string): void {
  47. this.debugProtectionFunctionName = debugProtectionFunctionName;
  48. }
  49. /**
  50. * @param {string} codeHelperTemplate
  51. * @returns {TStatement[]}
  52. */
  53. protected getNodeStructure (codeHelperTemplate: string): TStatement[] {
  54. return NodeUtils.convertCodeToStructure(codeHelperTemplate);
  55. }
  56. /**
  57. * @returns {string}
  58. */
  59. protected getCodeHelperTemplate (): string {
  60. return this.customCodeHelperFormatter.formatTemplate(DebugProtectionFunctionIntervalTemplate(), {
  61. debugProtectionFunctionName: this.debugProtectionFunctionName
  62. });
  63. }
  64. }