StringArrayRotateFunctionNode.spec.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
  2. import { NO_CUSTOM_NODES_PRESET } from '../../../../src/preset-options/NoCustomNodesPreset';
  3. import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator';
  4. const assert: Chai.AssertStatic = require('chai').assert;
  5. describe('StringArrayRotateFunctionNode', () => {
  6. it('should correctly append `StringArrayRotateFunctionNode` custom node into the obfuscated code if `rotateStringArray` option is set', () => {
  7. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  8. `var test = 'test';`,
  9. Object.assign({}, NO_CUSTOM_NODES_PRESET, {
  10. rotateStringArray: true,
  11. stringArray: true,
  12. stringArrayThreshold: 1
  13. })
  14. );
  15. assert.match(obfuscationResult.getObfuscatedCode(), /while *\(-- *_0x([a-z0-9]){4,6}\) *\{/);
  16. });
  17. it('should\'t append `StringArrayRotateFunctionNode` custom node into the obfuscated code if `rotateStringArray` option is not set', () => {
  18. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  19. `var test = 'test';`,
  20. Object.assign({}, NO_CUSTOM_NODES_PRESET, {
  21. rotateStringArray: false,
  22. stringArray: true,
  23. stringArrayThreshold: 1
  24. })
  25. );
  26. assert.notMatch(obfuscationResult.getObfuscatedCode(), /while *\(-- *_0x([a-z0-9]){4,6}\) *\{/);
  27. });
  28. });