StringArrayRotateFunctionNode.spec.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { assert } from 'chai';
  2. import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
  3. import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
  4. import { readFileAsString } from '../../../helpers/readFileAsString';
  5. import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
  6. describe('StringArrayRotateFunctionNode', () => {
  7. const regExp: RegExp = /while *\(-- *_0x([a-f0-9]){4,6}\) *\{/;
  8. describe('`stringArray` option is set', () => {
  9. let obfuscatedCode: string;
  10. before(() => {
  11. const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
  12. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  13. code,
  14. {
  15. ...NO_CUSTOM_NODES_PRESET,
  16. rotateStringArray: true,
  17. stringArray: true,
  18. stringArrayThreshold: 1
  19. }
  20. );
  21. obfuscatedCode = obfuscationResult.getObfuscatedCode();
  22. });
  23. it('should correctly append custom node into the obfuscated code', () => {
  24. assert.match(obfuscatedCode, regExp);
  25. });
  26. });
  27. describe('`stringArray` option isn\'t set', () => {
  28. let obfuscatedCode: string;
  29. before(() => {
  30. const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
  31. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  32. code,
  33. {
  34. ...NO_CUSTOM_NODES_PRESET,
  35. rotateStringArray: false,
  36. stringArray: true,
  37. stringArrayThreshold: 1
  38. }
  39. );
  40. obfuscatedCode = obfuscationResult.getObfuscatedCode();
  41. });
  42. it('shouldn\'t append custom node into the obfuscated code', () => {
  43. assert.notMatch(obfuscatedCode, regExp);
  44. });
  45. });
  46. });