dev.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. 'use strict';
  2. import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
  3. import { StringArrayEncoding } from '../../src/enums/node-transformers/string-array-transformers/StringArrayEncoding';
  4. import { StringArrayIndexesType } from '../../src/enums/node-transformers/string-array-transformers/StringArrayIndexesType';
  5. import { StringArrayWrappersType } from '../../src/enums/node-transformers/string-array-transformers/StringArrayWrappersType';
  6. (function () {
  7. const JavaScriptObfuscator: any = require('../../index');
  8. let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
  9. `
  10. (function(){
  11. var variable1 = '5' - 3;
  12. var variable2 = '5' + 3;
  13. var variable3 = '5' + - '2';
  14. var variable4 = ['10','10','10','10','10'].map(parseInt);
  15. var variable5 = 'foo ' + 1 + 1;
  16. console.log(variable1);
  17. console.log(variable2);
  18. console.log(variable3);
  19. console.log(variable4);
  20. console.log(variable5);
  21. })();
  22. (function(){
  23. if (true) {
  24. var foo = function () {
  25. console.log('abc');
  26. console.log('cde');
  27. console.log('efg');
  28. console.log('hij');
  29. };
  30. var bar = function () {
  31. console.log('klm');
  32. console.log('nop');
  33. console.log('qrs');
  34. };
  35. var baz = function () {
  36. console.log('tuv');
  37. console.log('wxy');
  38. console.log('z');
  39. };
  40. foo();
  41. bar();
  42. baz();
  43. }
  44. })();
  45. `,
  46. {
  47. ...NO_ADDITIONAL_NODES_PRESET,
  48. compact: false,
  49. controlFlowFlattening: true,
  50. controlFlowFlatteningThreshold: 1,
  51. deadCodeInjection: true,
  52. deadCodeInjectionThreshold: 1,
  53. numbersToExpressions: true,
  54. simplify: true,
  55. renameProperties: true,
  56. rotateStringArray: true,
  57. splitStrings: true,
  58. splitStringsChunkLength: 3,
  59. stringArray: true,
  60. stringArrayEncoding: [
  61. StringArrayEncoding.None,
  62. StringArrayEncoding.Base64,
  63. StringArrayEncoding.Rc4
  64. ],
  65. stringArrayIndexesType: [
  66. StringArrayIndexesType.HexadecimalNumber,
  67. StringArrayIndexesType.HexadecimalNumericString
  68. ],
  69. stringArrayIndexShift: true,
  70. stringArrayWrappersChainedCalls: true,
  71. stringArrayWrappersCount: 5,
  72. stringArrayWrappersParametersMaxCount: 5,
  73. stringArrayWrappersType: StringArrayWrappersType.Function,
  74. stringArrayThreshold: 1,
  75. transformObjectKeys: true,
  76. unicodeEscapeSequence: true
  77. }
  78. ).getObfuscatedCode();
  79. console.log(obfuscatedCode);
  80. console.log(eval(obfuscatedCode));
  81. })();