StringArrayRotateFunctionTemplate.spec.ts 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'reflect-metadata';
  2. import { assert } from 'chai';
  3. import { IObfuscatedCode } from '../../../../../../src/interfaces/source-code/IObfuscatedCode';
  4. import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
  5. import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
  6. import { readFileAsString } from '../../../../../helpers/readFileAsString';
  7. describe('StringArrayRotateFunctionTemplate', () => {
  8. describe('Prevailing kind of variables', () => {
  9. describe('`var` kind', () => {
  10. let obfuscatedCode: string,
  11. stringArrayRotateFunctionRegExp: RegExp = /function\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\){var _0x([a-f0-9]){4,6} *= *function/;
  12. beforeEach(() => {
  13. const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js');
  14. const obfuscatedCodeObject: IObfuscatedCode = JavaScriptObfuscator.obfuscate(
  15. code,
  16. {
  17. ...NO_ADDITIONAL_NODES_PRESET,
  18. stringArray: true,
  19. stringArrayThreshold: 1,
  20. rotateStringArray: true
  21. }
  22. );
  23. obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode();
  24. });
  25. it('Should return correct kind of variables for string array rotate function', () => {
  26. assert.match(obfuscatedCode, stringArrayRotateFunctionRegExp);
  27. });
  28. it('Should does not break on obfuscating', () => {
  29. assert.doesNotThrow(() => obfuscatedCode);
  30. });
  31. });
  32. describe('`const` kind', () => {
  33. let obfuscatedCode: string,
  34. stringArrayRotateFunctionRegExp: RegExp = /function\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\){const _0x([a-f0-9]){4,6} *= *function/;
  35. beforeEach(() => {
  36. const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js');
  37. const obfuscatedCodeObject: IObfuscatedCode = JavaScriptObfuscator.obfuscate(
  38. code,
  39. {
  40. ...NO_ADDITIONAL_NODES_PRESET,
  41. stringArray: true,
  42. stringArrayThreshold: 1,
  43. rotateStringArray: true
  44. }
  45. );
  46. obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode();
  47. });
  48. it('Should return correct kind of variables for string array rotate function', () => {
  49. assert.match(obfuscatedCode, stringArrayRotateFunctionRegExp);
  50. });
  51. it('Should does not break on obfuscating', () => {
  52. assert.doesNotThrow(() => obfuscatedCode);
  53. });
  54. });
  55. describe('`let` kind', () => {
  56. let obfuscatedCode: string,
  57. stringArrayRotateFunctionRegExp: RegExp = /function\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\){const _0x([a-f0-9]){4,6} *= *function/;
  58. beforeEach(() => {
  59. const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js');
  60. const obfuscatedCodeObject: IObfuscatedCode = JavaScriptObfuscator.obfuscate(
  61. code,
  62. {
  63. ...NO_ADDITIONAL_NODES_PRESET,
  64. stringArray: true,
  65. stringArrayThreshold: 1,
  66. rotateStringArray: true
  67. }
  68. );
  69. obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode();
  70. });
  71. it('Should return correct kind of variables for string array rotate function', () => {
  72. assert.match(obfuscatedCode, stringArrayRotateFunctionRegExp);
  73. });
  74. it('Should does not break on obfuscating', () => {
  75. assert.doesNotThrow(() => obfuscatedCode);
  76. });
  77. });
  78. });
  79. });