StringLiteralControlFlowReplacer.spec.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { assert } from 'chai';
  2. import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
  3. import { readFileAsString } from '../../../../../helpers/readFileAsString';
  4. import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
  5. describe('StringLiteralControlFlowReplacer', () => {
  6. describe('replace', () => {
  7. const controlFlowStorageStringLiteralRegExp: RegExp = /var *_0x([a-f0-9]){4,6} *= *\{'\w{5}' *: *'test'\};/;
  8. const controlFlowStorageCallRegExp: RegExp = /var *_0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\['\w{5}'\];/;
  9. let obfuscatedCode: string;
  10. before(() => {
  11. const code: string = readFileAsString(__dirname + '/fixtures/input-1.js');
  12. obfuscatedCode = JavaScriptObfuscator.obfuscate(
  13. code,
  14. {
  15. ...NO_ADDITIONAL_NODES_PRESET,
  16. controlFlowFlattening: true,
  17. controlFlowFlatteningThreshold: 1
  18. }
  19. ).getObfuscatedCode();
  20. });
  21. it('should add string literal node as property of control flow storage node', () => {
  22. assert.match(obfuscatedCode, controlFlowStorageStringLiteralRegExp);
  23. });
  24. it('should replace string literal node with call to control flow storage node', () => {
  25. assert.match(obfuscatedCode, controlFlowStorageCallRegExp);
  26. });
  27. });
  28. });