js-confuser 1.7.3 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +6 -4
  2. package/CHANGELOG.md +70 -0
  3. package/Migration.md +57 -0
  4. package/README.md +23 -929
  5. package/dist/constants.js +65 -14
  6. package/dist/index.js +108 -160
  7. package/dist/obfuscator.js +316 -118
  8. package/dist/options.js +1 -119
  9. package/dist/order.js +30 -30
  10. package/dist/presets.js +47 -45
  11. package/dist/probability.js +25 -32
  12. package/dist/templates/bufferToStringTemplate.js +9 -0
  13. package/dist/templates/deadCodeTemplates.js +9 -0
  14. package/dist/templates/getGlobalTemplate.js +19 -0
  15. package/dist/templates/integrityTemplate.js +30 -0
  16. package/dist/templates/setFunctionLengthTemplate.js +9 -0
  17. package/dist/templates/stringCompressionTemplate.js +10 -0
  18. package/dist/templates/tamperProtectionTemplates.js +21 -0
  19. package/dist/templates/template.js +199 -184
  20. package/dist/transforms/astScrambler.js +100 -0
  21. package/dist/transforms/calculator.js +70 -127
  22. package/dist/transforms/controlFlowFlattening.js +1182 -0
  23. package/dist/transforms/deadCode.js +62 -587
  24. package/dist/transforms/dispatcher.js +300 -313
  25. package/dist/transforms/extraction/duplicateLiteralsRemoval.js +88 -189
  26. package/dist/transforms/extraction/objectExtraction.js +131 -215
  27. package/dist/transforms/finalizer.js +56 -59
  28. package/dist/transforms/flatten.js +275 -276
  29. package/dist/transforms/functionOutlining.js +230 -0
  30. package/dist/transforms/identifier/globalConcealing.js +214 -135
  31. package/dist/transforms/identifier/movedDeclarations.js +167 -91
  32. package/dist/transforms/identifier/renameVariables.js +239 -193
  33. package/dist/transforms/lock/integrity.js +61 -184
  34. package/dist/transforms/lock/lock.js +261 -387
  35. package/dist/transforms/minify.js +431 -436
  36. package/dist/transforms/opaquePredicates.js +65 -118
  37. package/dist/transforms/pack.js +160 -0
  38. package/dist/transforms/plugin.js +179 -0
  39. package/dist/transforms/preparation.js +261 -173
  40. package/dist/transforms/renameLabels.js +132 -56
  41. package/dist/transforms/rgf.js +140 -267
  42. package/dist/transforms/shuffle.js +52 -145
  43. package/dist/transforms/string/encoding.js +44 -175
  44. package/dist/transforms/string/stringCompression.js +79 -155
  45. package/dist/transforms/string/stringConcealing.js +189 -225
  46. package/dist/transforms/string/stringEncoding.js +32 -40
  47. package/dist/transforms/string/stringSplitting.js +54 -55
  48. package/dist/transforms/variableMasking.js +232 -0
  49. package/dist/utils/ControlObject.js +125 -0
  50. package/dist/utils/IntGen.js +46 -0
  51. package/dist/utils/NameGen.js +106 -0
  52. package/dist/utils/ast-utils.js +560 -0
  53. package/dist/utils/function-utils.js +56 -0
  54. package/dist/utils/gen-utils.js +48 -0
  55. package/dist/utils/node.js +77 -0
  56. package/dist/utils/object-utils.js +21 -0
  57. package/dist/utils/random-utils.js +91 -0
  58. package/dist/utils/static-utils.js +64 -0
  59. package/dist/validateOptions.js +122 -0
  60. package/index.d.ts +1 -17
  61. package/package.json +27 -22
  62. package/src/constants.ts +139 -82
  63. package/src/index.ts +70 -165
  64. package/src/obfuscationResult.ts +43 -0
  65. package/src/obfuscator.ts +328 -135
  66. package/src/options.ts +149 -658
  67. package/src/order.ts +14 -14
  68. package/src/presets.ts +39 -34
  69. package/src/probability.ts +21 -36
  70. package/src/templates/bufferToStringTemplate.ts +57 -0
  71. package/src/templates/deadCodeTemplates.ts +1185 -0
  72. package/src/templates/getGlobalTemplate.ts +72 -0
  73. package/src/templates/integrityTemplate.ts +69 -0
  74. package/src/templates/setFunctionLengthTemplate.ts +11 -0
  75. package/src/templates/stringCompressionTemplate.ts +42 -0
  76. package/src/templates/tamperProtectionTemplates.ts +116 -0
  77. package/src/templates/template.ts +149 -157
  78. package/src/transforms/astScrambler.ts +99 -0
  79. package/src/transforms/calculator.ts +96 -226
  80. package/src/transforms/controlFlowFlattening.ts +1594 -0
  81. package/src/transforms/deadCode.ts +85 -676
  82. package/src/transforms/dispatcher.ts +431 -640
  83. package/src/transforms/extraction/duplicateLiteralsRemoval.ts +147 -295
  84. package/src/transforms/extraction/objectExtraction.ts +160 -333
  85. package/src/transforms/finalizer.ts +63 -64
  86. package/src/transforms/flatten.ts +439 -557
  87. package/src/transforms/functionOutlining.ts +225 -0
  88. package/src/transforms/identifier/globalConcealing.ts +255 -266
  89. package/src/transforms/identifier/movedDeclarations.ts +228 -142
  90. package/src/transforms/identifier/renameVariables.ts +250 -271
  91. package/src/transforms/lock/integrity.ts +85 -263
  92. package/src/transforms/lock/lock.ts +338 -579
  93. package/src/transforms/minify.ts +523 -663
  94. package/src/transforms/opaquePredicates.ts +90 -229
  95. package/src/transforms/pack.ts +195 -0
  96. package/src/transforms/plugin.ts +185 -0
  97. package/src/transforms/preparation.ts +337 -231
  98. package/src/transforms/renameLabels.ts +176 -77
  99. package/src/transforms/rgf.ts +293 -424
  100. package/src/transforms/shuffle.ts +80 -254
  101. package/src/transforms/string/encoding.ts +20 -126
  102. package/src/transforms/string/stringCompression.ts +117 -307
  103. package/src/transforms/string/stringConcealing.ts +254 -342
  104. package/src/transforms/string/stringEncoding.ts +28 -47
  105. package/src/transforms/string/stringSplitting.ts +61 -75
  106. package/src/transforms/variableMasking.ts +257 -0
  107. package/src/utils/ControlObject.ts +141 -0
  108. package/src/utils/IntGen.ts +33 -0
  109. package/src/utils/NameGen.ts +106 -0
  110. package/src/utils/ast-utils.ts +667 -0
  111. package/src/utils/function-utils.ts +50 -0
  112. package/src/utils/gen-utils.ts +48 -0
  113. package/src/utils/node.ts +78 -0
  114. package/src/utils/object-utils.ts +21 -0
  115. package/src/utils/random-utils.ts +79 -0
  116. package/src/utils/static-utils.ts +66 -0
  117. package/src/validateOptions.ts +256 -0
  118. package/tsconfig.json +13 -8
  119. package/babel.config.js +0 -12
  120. package/dev.js +0 -8
  121. package/dist/compiler.js +0 -34
  122. package/dist/parser.js +0 -59
  123. package/dist/precedence.js +0 -66
  124. package/dist/templates/bufferToString.js +0 -129
  125. package/dist/templates/core.js +0 -35
  126. package/dist/templates/crash.js +0 -28
  127. package/dist/templates/es5.js +0 -137
  128. package/dist/templates/functionLength.js +0 -34
  129. package/dist/templates/globals.js +0 -9
  130. package/dist/transforms/antiTooling.js +0 -88
  131. package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +0 -1287
  132. package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +0 -131
  133. package/dist/transforms/es5/antiClass.js +0 -164
  134. package/dist/transforms/es5/antiDestructuring.js +0 -193
  135. package/dist/transforms/es5/antiES6Object.js +0 -185
  136. package/dist/transforms/es5/antiSpreadOperator.js +0 -35
  137. package/dist/transforms/es5/antiTemplate.js +0 -66
  138. package/dist/transforms/es5/es5.js +0 -123
  139. package/dist/transforms/extraction/classExtraction.js +0 -83
  140. package/dist/transforms/identifier/globalAnalysis.js +0 -83
  141. package/dist/transforms/identifier/variableAnalysis.js +0 -104
  142. package/dist/transforms/lock/antiDebug.js +0 -76
  143. package/dist/transforms/stack.js +0 -349
  144. package/dist/transforms/transform.js +0 -372
  145. package/dist/traverse.js +0 -110
  146. package/dist/util/compare.js +0 -145
  147. package/dist/util/gen.js +0 -564
  148. package/dist/util/guard.js +0 -14
  149. package/dist/util/identifiers.js +0 -355
  150. package/dist/util/insert.js +0 -362
  151. package/dist/util/math.js +0 -19
  152. package/dist/util/object.js +0 -40
  153. package/dist/util/random.js +0 -156
  154. package/dist/util/scope.js +0 -20
  155. package/docs/ControlFlowFlattening.md +0 -595
  156. package/docs/Countermeasures.md +0 -70
  157. package/docs/ES5.md +0 -197
  158. package/docs/Integrity.md +0 -82
  159. package/docs/RGF.md +0 -424
  160. package/docs/RenameVariables.md +0 -116
  161. package/docs/TamperProtection.md +0 -100
  162. package/docs/Template.md +0 -117
  163. package/samples/example.js +0 -15
  164. package/samples/high.js +0 -1
  165. package/samples/input.js +0 -3
  166. package/samples/javascriptobfuscator.com.js +0 -8
  167. package/samples/jscrambler_advanced.js +0 -1894
  168. package/samples/jscrambler_light.js +0 -1134
  169. package/samples/low.js +0 -1
  170. package/samples/medium.js +0 -1
  171. package/samples/obfuscator.io.js +0 -1686
  172. package/samples/preemptive.com.js +0 -16
  173. package/src/compiler.ts +0 -35
  174. package/src/parser.ts +0 -49
  175. package/src/precedence.ts +0 -61
  176. package/src/templates/bufferToString.ts +0 -136
  177. package/src/templates/core.ts +0 -29
  178. package/src/templates/crash.ts +0 -23
  179. package/src/templates/es5.ts +0 -131
  180. package/src/templates/functionLength.ts +0 -32
  181. package/src/templates/globals.ts +0 -3
  182. package/src/transforms/antiTooling.ts +0 -102
  183. package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +0 -2153
  184. package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +0 -179
  185. package/src/transforms/es5/antiClass.ts +0 -276
  186. package/src/transforms/es5/antiDestructuring.ts +0 -294
  187. package/src/transforms/es5/antiES6Object.ts +0 -267
  188. package/src/transforms/es5/antiSpreadOperator.ts +0 -56
  189. package/src/transforms/es5/antiTemplate.ts +0 -98
  190. package/src/transforms/es5/es5.ts +0 -149
  191. package/src/transforms/extraction/classExtraction.ts +0 -168
  192. package/src/transforms/identifier/globalAnalysis.ts +0 -102
  193. package/src/transforms/identifier/variableAnalysis.ts +0 -118
  194. package/src/transforms/lock/antiDebug.ts +0 -112
  195. package/src/transforms/stack.ts +0 -557
  196. package/src/transforms/transform.ts +0 -441
  197. package/src/traverse.ts +0 -120
  198. package/src/types.ts +0 -133
  199. package/src/util/compare.ts +0 -181
  200. package/src/util/gen.ts +0 -651
  201. package/src/util/guard.ts +0 -17
  202. package/src/util/identifiers.ts +0 -494
  203. package/src/util/insert.ts +0 -419
  204. package/src/util/math.ts +0 -15
  205. package/src/util/object.ts +0 -39
  206. package/src/util/random.ts +0 -221
  207. package/src/util/scope.ts +0 -21
  208. package/test/code/Cash.src.js +0 -1011
  209. package/test/code/Cash.test.ts +0 -132
  210. package/test/code/Dynamic.src.js +0 -118
  211. package/test/code/Dynamic.test.ts +0 -49
  212. package/test/code/ES6.src.js +0 -235
  213. package/test/code/ES6.test.ts +0 -42
  214. package/test/code/NewFeatures.test.ts +0 -19
  215. package/test/code/StrictMode.src.js +0 -65
  216. package/test/code/StrictMode.test.js +0 -37
  217. package/test/compare.test.ts +0 -104
  218. package/test/index.test.ts +0 -249
  219. package/test/options.test.ts +0 -150
  220. package/test/presets.test.ts +0 -22
  221. package/test/probability.test.ts +0 -44
  222. package/test/templates/template.test.ts +0 -224
  223. package/test/transforms/antiTooling.test.ts +0 -52
  224. package/test/transforms/calculator.test.ts +0 -78
  225. package/test/transforms/controlFlowFlattening/controlFlowFlattening.test.ts +0 -1274
  226. package/test/transforms/controlFlowFlattening/expressionObfuscation.test.ts +0 -192
  227. package/test/transforms/deadCode.test.ts +0 -85
  228. package/test/transforms/dispatcher.test.ts +0 -457
  229. package/test/transforms/es5/antiClass.test.ts +0 -427
  230. package/test/transforms/es5/antiDestructuring.test.ts +0 -157
  231. package/test/transforms/es5/antiES6Object.test.ts +0 -245
  232. package/test/transforms/es5/antiTemplate.test.ts +0 -116
  233. package/test/transforms/es5/es5.test.ts +0 -110
  234. package/test/transforms/extraction/classExtraction.test.ts +0 -86
  235. package/test/transforms/extraction/duplicateLiteralsRemoval.test.ts +0 -200
  236. package/test/transforms/extraction/objectExtraction.test.ts +0 -491
  237. package/test/transforms/flatten.test.ts +0 -721
  238. package/test/transforms/hexadecimalNumbers.test.ts +0 -62
  239. package/test/transforms/identifier/globalConcealing.test.ts +0 -142
  240. package/test/transforms/identifier/movedDeclarations.test.ts +0 -275
  241. package/test/transforms/identifier/renameVariables.test.ts +0 -695
  242. package/test/transforms/lock/antiDebug.test.ts +0 -66
  243. package/test/transforms/lock/browserLock.test.ts +0 -129
  244. package/test/transforms/lock/countermeasures.test.ts +0 -100
  245. package/test/transforms/lock/integrity.test.ts +0 -161
  246. package/test/transforms/lock/lock.test.ts +0 -204
  247. package/test/transforms/lock/osLock.test.ts +0 -312
  248. package/test/transforms/lock/selfDefending.test.ts +0 -68
  249. package/test/transforms/lock/tamperProtection.test.ts +0 -336
  250. package/test/transforms/minify.test.ts +0 -575
  251. package/test/transforms/opaquePredicates.test.ts +0 -43
  252. package/test/transforms/preparation.test.ts +0 -157
  253. package/test/transforms/renameLabels.test.ts +0 -95
  254. package/test/transforms/rgf.test.ts +0 -378
  255. package/test/transforms/shuffle.test.ts +0 -135
  256. package/test/transforms/stack.test.ts +0 -573
  257. package/test/transforms/string/stringCompression.test.ts +0 -120
  258. package/test/transforms/string/stringConcealing.test.ts +0 -299
  259. package/test/transforms/string/stringEncoding.test.ts +0 -95
  260. package/test/transforms/string/stringSplitting.test.ts +0 -135
  261. package/test/transforms/transform.test.ts +0 -66
  262. package/test/traverse.test.ts +0 -139
  263. package/test/util/compare.test.ts +0 -34
  264. package/test/util/gen.test.ts +0 -121
  265. package/test/util/identifiers.test.ts +0 -253
  266. package/test/util/insert.test.ts +0 -142
  267. package/test/util/math.test.ts +0 -5
  268. package/test/util/random.test.ts +0 -71
  269. /package/dist/{types.js → obfuscationResult.js} +0 -0
@@ -3,148 +3,346 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports["default"] = exports.DEFAULT_OPTIONS = void 0;
7
7
  var _assert = require("assert");
8
- var _events = require("events");
9
- var _traverse = _interopRequireDefault(require("./traverse"));
8
+ var babel = _interopRequireWildcard(require("@babel/core"));
9
+ var _generator = _interopRequireDefault(require("@babel/generator"));
10
+ var _validateOptions = require("./validateOptions");
10
11
  var _probability = require("./probability");
12
+ var _NameGen = require("./utils/NameGen");
13
+ var _order = require("./order");
14
+ var _plugin = require("./transforms/plugin");
11
15
  var _preparation = _interopRequireDefault(require("./transforms/preparation"));
12
- var _objectExtraction = _interopRequireDefault(require("./transforms/extraction/objectExtraction"));
13
- var _lock = _interopRequireDefault(require("./transforms/lock/lock"));
16
+ var _renameVariables = _interopRequireDefault(require("./transforms/identifier/renameVariables"));
17
+ var _variableMasking = _interopRequireDefault(require("./transforms/variableMasking"));
14
18
  var _dispatcher = _interopRequireDefault(require("./transforms/dispatcher"));
15
- var _deadCode = _interopRequireDefault(require("./transforms/deadCode"));
16
- var _opaquePredicates = _interopRequireDefault(require("./transforms/opaquePredicates"));
17
- var _calculator = _interopRequireDefault(require("./transforms/calculator"));
18
- var _controlFlowFlattening = _interopRequireDefault(require("./transforms/controlFlowFlattening/controlFlowFlattening"));
19
+ var _duplicateLiteralsRemoval = _interopRequireDefault(require("./transforms/extraction/duplicateLiteralsRemoval"));
20
+ var _objectExtraction = _interopRequireDefault(require("./transforms/extraction/objectExtraction"));
21
+ var _functionOutlining = _interopRequireDefault(require("./transforms/functionOutlining"));
19
22
  var _globalConcealing = _interopRequireDefault(require("./transforms/identifier/globalConcealing"));
20
- var _stringSplitting = _interopRequireDefault(require("./transforms/string/stringSplitting"));
21
- var _stringConcealing = _interopRequireDefault(require("./transforms/string/stringConcealing"));
22
23
  var _stringCompression = _interopRequireDefault(require("./transforms/string/stringCompression"));
23
- var _duplicateLiteralsRemoval = _interopRequireDefault(require("./transforms/extraction/duplicateLiteralsRemoval"));
24
+ var _deadCode = _interopRequireDefault(require("./transforms/deadCode"));
25
+ var _stringSplitting = _interopRequireDefault(require("./transforms/string/stringSplitting"));
24
26
  var _shuffle = _interopRequireDefault(require("./transforms/shuffle"));
27
+ var _astScrambler = _interopRequireDefault(require("./transforms/astScrambler"));
28
+ var _calculator = _interopRequireDefault(require("./transforms/calculator"));
25
29
  var _movedDeclarations = _interopRequireDefault(require("./transforms/identifier/movedDeclarations"));
26
- var _renameVariables = _interopRequireDefault(require("./transforms/identifier/renameVariables"));
27
30
  var _renameLabels = _interopRequireDefault(require("./transforms/renameLabels"));
28
- var _minify = _interopRequireDefault(require("./transforms/minify"));
29
- var _es = _interopRequireDefault(require("./transforms/es5/es5"));
30
31
  var _rgf = _interopRequireDefault(require("./transforms/rgf"));
31
32
  var _flatten = _interopRequireDefault(require("./transforms/flatten"));
32
- var _stack = _interopRequireDefault(require("./transforms/stack"));
33
- var _antiTooling = _interopRequireDefault(require("./transforms/antiTooling"));
33
+ var _stringConcealing = _interopRequireDefault(require("./transforms/string/stringConcealing"));
34
+ var _lock = _interopRequireDefault(require("./transforms/lock/lock"));
35
+ var _controlFlowFlattening = _interopRequireDefault(require("./transforms/controlFlowFlattening"));
36
+ var _opaquePredicates = _interopRequireDefault(require("./transforms/opaquePredicates"));
37
+ var _minify = _interopRequireDefault(require("./transforms/minify"));
34
38
  var _finalizer = _interopRequireDefault(require("./transforms/finalizer"));
35
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
39
+ var _integrity = _interopRequireDefault(require("./transforms/lock/integrity"));
40
+ var _pack = _interopRequireDefault(require("./transforms/pack"));
41
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
42
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
43
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
44
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
45
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
46
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
47
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
48
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
49
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
50
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
51
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
52
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
53
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
54
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
55
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
36
56
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
37
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
38
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
39
- /**
40
- * The parent transformation holding the `state`.
41
- */
42
- class Obfuscator extends _events.EventEmitter {
43
- constructor(options) {
44
- var _this;
45
- super();
46
- _this = this;
47
- this.options = options;
48
- _defineProperty(this, "varCount", void 0);
49
- _defineProperty(this, "transforms", void 0);
50
- _defineProperty(this, "array", void 0);
51
- _defineProperty(this, "state", "transform");
52
- _defineProperty(this, "generated", void 0);
53
- _defineProperty(this, "totalPossibleTransforms", void 0);
54
- this.varCount = 0;
55
- this.transforms = Object.create(null);
56
- this.generated = new Set();
57
- this.totalPossibleTransforms = 0;
58
- const test = function (map) {
59
- for (var _len = arguments.length, transformers = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
60
- transformers[_key - 1] = arguments[_key];
57
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
58
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // Transforms
59
+ var DEFAULT_OPTIONS = exports.DEFAULT_OPTIONS = {
60
+ target: "node",
61
+ compact: true
62
+ };
63
+ var Obfuscator = exports["default"] = /*#__PURE__*/function () {
64
+ function Obfuscator(userOptions, parentObfuscator) {
65
+ var _this = this,
66
+ _this$options$lock;
67
+ _classCallCheck(this, Obfuscator);
68
+ _defineProperty(this, "plugins", []);
69
+ _defineProperty(this, "totalPossibleTransforms", 0);
70
+ _defineProperty(this, "globalState", {
71
+ lock: {
72
+ integrity: {
73
+ sensitivityRegex: / |\n|;|,|\{|\}|\(|\)|\.|\[|\]/g
74
+ },
75
+ createCountermeasuresCode: function createCountermeasuresCode() {
76
+ throw new Error("Not implemented");
77
+ }
78
+ },
79
+ // After RenameVariables completes, this map will contain the renamed variables
80
+ // Most use cases involve grabbing the Program(global) mappings
81
+ renamedVariables: new Map(),
82
+ // Internal functions, should not be renamed/removed
83
+ internals: {
84
+ stringCompressionLibraryName: "",
85
+ nativeFunctionName: "",
86
+ integrityHashName: "",
87
+ invokeCountermeasuresFnName: ""
61
88
  }
62
- _this.totalPossibleTransforms += transformers.length;
63
- if ((0, _probability.isProbabilityMapProbable)(map)) {
64
- // options.verbose && console.log("+ Added " + transformer.name);
65
-
66
- transformers.forEach(Transformer => _this.push(new Transformer(_this)));
67
- } else {
68
- // options.verbose && console.log("- Skipped adding " + transformer.name);
89
+ });
90
+ _defineProperty(this, "index", 0);
91
+ this.parentObfuscator = parentObfuscator;
92
+ (0, _validateOptions.validateOptions)(userOptions);
93
+ this.options = (0, _validateOptions.applyDefaultsToOptions)(_objectSpread({}, userOptions));
94
+ this.nameGen = new _NameGen.NameGen(this.options.identifierGenerator);
95
+ var shouldAddLockTransform = this.options.lock && (Object.keys(this.options.lock).filter(function (key) {
96
+ return key !== "customLocks" && (0, _probability.isProbabilityMapProbable)(_this.options.lock[key]);
97
+ }).length > 0 || this.options.lock.customLocks.length > 0);
98
+ var allPlugins = [];
99
+ var push = function push(probabilityMap) {
100
+ for (var _len = arguments.length, pluginFns = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
101
+ pluginFns[_key - 1] = arguments[_key];
69
102
  }
103
+ _this.totalPossibleTransforms += pluginFns.length;
104
+ if (!(0, _probability.isProbabilityMapProbable)(probabilityMap)) return;
105
+ allPlugins.push.apply(allPlugins, pluginFns);
70
106
  };
107
+ push(true, _preparation["default"]);
108
+ push(this.options.objectExtraction, _objectExtraction["default"]);
109
+ push(this.options.flatten, _flatten["default"]);
110
+ push(shouldAddLockTransform, _lock["default"]);
111
+ push(this.options.rgf, _rgf["default"]);
112
+ push(this.options.dispatcher, _dispatcher["default"]);
113
+ push(this.options.deadCode, _deadCode["default"]);
114
+ push(this.options.controlFlowFlattening, _controlFlowFlattening["default"]);
115
+ push(this.options.calculator, _calculator["default"]);
116
+ push(this.options.globalConcealing, _globalConcealing["default"]);
117
+ push(this.options.opaquePredicates, _opaquePredicates["default"]);
118
+ push(this.options.functionOutlining, _functionOutlining["default"]);
119
+ push(this.options.stringSplitting, _stringSplitting["default"]);
120
+ push(this.options.stringConcealing, _stringConcealing["default"]);
121
+ push(this.options.stringCompression, _stringCompression["default"]);
122
+ push(this.options.variableMasking, _variableMasking["default"]);
123
+ push(this.options.duplicateLiteralsRemoval, _duplicateLiteralsRemoval["default"]);
124
+ push(this.options.shuffle, _shuffle["default"]);
125
+ push(this.options.movedDeclarations, _movedDeclarations["default"]);
126
+ push(this.options.renameLabels, _renameLabels["default"]);
127
+ push(this.options.minify, _minify["default"]);
128
+ push(this.options.astScrambler, _astScrambler["default"]);
129
+ push(this.options.renameVariables, _renameVariables["default"]);
130
+ push(true, _finalizer["default"]);
131
+ push(this.options.pack, _pack["default"]);
132
+ push((_this$options$lock = this.options.lock) === null || _this$options$lock === void 0 ? void 0 : _this$options$lock.integrity, _integrity["default"]);
133
+ allPlugins.map(function (pluginFunction) {
134
+ var pluginInstance;
135
+ var plugin = pluginFunction({
136
+ Plugin: function Plugin(order, mergeObject) {
137
+ (0, _assert.ok)(typeof order === "number");
138
+ var pluginOptions = {
139
+ order: order,
140
+ name: _order.Order[order]
141
+ };
142
+ var newPluginInstance = new _plugin.PluginInstance(pluginOptions, _this);
143
+ if (_typeof(mergeObject) === "object" && mergeObject) {
144
+ Object.assign(newPluginInstance, mergeObject);
145
+ }
146
+ pluginInstance = newPluginInstance;
71
147
 
72
- // Optimization: Only add needed transformers. If a probability always return false, no need in running that extra code.
73
- test(true, _preparation.default);
74
- test(true, _renameLabels.default);
75
- test(options.objectExtraction, _objectExtraction.default);
76
- test(options.flatten, _flatten.default);
77
- test(options.rgf, _rgf.default);
78
- test(options.dispatcher, _dispatcher.default);
79
- test(options.deadCode, _deadCode.default);
80
- test(options.calculator, _calculator.default);
81
- test(options.controlFlowFlattening, _controlFlowFlattening.default);
82
- test(options.globalConcealing, _globalConcealing.default);
83
- test(options.opaquePredicates, _opaquePredicates.default);
84
- test(options.stringSplitting, _stringSplitting.default);
85
- test(options.stringConcealing, _stringConcealing.default);
86
- test(options.stringCompression, _stringCompression.default);
87
- test(options.stack, _stack.default);
88
- test(options.duplicateLiteralsRemoval, _duplicateLiteralsRemoval.default);
89
- test(options.shuffle, _shuffle.default);
90
- test(options.movedDeclarations, _movedDeclarations.default);
91
- test(options.minify, _minify.default);
92
- test(options.renameVariables, _renameVariables.default);
93
- test(options.es5, _es.default);
94
- test(true, _antiTooling.default);
95
- test(true, _finalizer.default); // String Encoding, Hexadecimal Numbers, BigInt support is included
148
+ // @ts-ignore
149
+ return newPluginInstance;
150
+ }
151
+ });
152
+ (0, _assert.ok)(pluginInstance, "Plugin instance not created: " + pluginFunction.toString());
153
+ _this.plugins.push({
154
+ plugin: plugin,
155
+ pluginInstance: pluginInstance
156
+ });
157
+ });
158
+ this.plugins = this.plugins.sort(function (a, b) {
159
+ return a.pluginInstance.order - b.pluginInstance.order;
160
+ });
161
+ if (!parentObfuscator && this.hasPlugin(_order.Order.StringCompression)) {
162
+ this.globalState.internals.stringCompressionLibraryName = this.nameGen.generate(false);
163
+ }
164
+ }
165
+ return _createClass(Obfuscator, [{
166
+ key: "isInternalVariable",
167
+ value: function isInternalVariable(name) {
168
+ return Object.values(this.globalState.internals).includes(name);
169
+ }
170
+ }, {
171
+ key: "shouldTransformNativeFunction",
172
+ value: function shouldTransformNativeFunction(nameAndPropertyPath) {
173
+ var _this$options$lock2;
174
+ if (!((_this$options$lock2 = this.options.lock) !== null && _this$options$lock2 !== void 0 && _this$options$lock2.tamperProtection)) {
175
+ return false;
176
+ }
96
177
 
97
- if (options.lock && Object.keys(options.lock).filter(x => x == "domainLock" ? options.lock.domainLock && options.lock.domainLock.length : options.lock[x]).length) {
98
- test(true, _lock.default);
178
+ // Custom implementation for Tamper Protection
179
+ if (typeof this.options.lock.tamperProtection === "function") {
180
+ return this.options.lock.tamperProtection(nameAndPropertyPath.join("."));
181
+ }
182
+ if (this.options.target === "browser" && nameAndPropertyPath.length === 1 && nameAndPropertyPath[0] === "fetch") {
183
+ return true;
184
+ }
185
+ var globalObject = {};
186
+ try {
187
+ globalObject = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : new Function("return this")();
188
+ } catch (e) {}
189
+ var fn = globalObject;
190
+ var _iterator = _createForOfIteratorHelper(nameAndPropertyPath),
191
+ _step;
192
+ try {
193
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
194
+ var _fn;
195
+ var item = _step.value;
196
+ fn = (_fn = fn) === null || _fn === void 0 ? void 0 : _fn[item];
197
+ if (typeof fn === "undefined") return false;
198
+ }
199
+ } catch (err) {
200
+ _iterator.e(err);
201
+ } finally {
202
+ _iterator.f();
203
+ }
204
+ var hasNativeCode = typeof fn === "function" && ("" + fn).includes("[native code]");
205
+ return hasNativeCode;
206
+ }
207
+ }, {
208
+ key: "getStringCompressionLibraryName",
209
+ value: function getStringCompressionLibraryName() {
210
+ if (this.parentObfuscator) {
211
+ return this.parentObfuscator.getStringCompressionLibraryName();
212
+ }
213
+ return this.globalState.internals.stringCompressionLibraryName;
214
+ }
215
+ }, {
216
+ key: "getObfuscatedVariableName",
217
+ value: function getObfuscatedVariableName(originalName, programNode) {
218
+ var renamedVariables = this.globalState.renamedVariables.get(programNode);
219
+ return (renamedVariables === null || renamedVariables === void 0 ? void 0 : renamedVariables.get(originalName)) || originalName;
99
220
  }
100
221
 
101
- // Make array
102
- this.array = Object.values(this.transforms);
222
+ /**
223
+ * The main Name Generator for `Rename Variables`
224
+ */
225
+ }, {
226
+ key: "obfuscateAST",
227
+ value: function obfuscateAST(ast, options) {
228
+ var finalASTHandler = [];
229
+ for (var i = 0; i < this.plugins.length; i++) {
230
+ var _plugin$post;
231
+ this.index = i;
232
+ var _this$plugins$i = this.plugins[i],
233
+ plugin = _this$plugins$i.plugin,
234
+ pluginInstance = _this$plugins$i.pluginInstance;
103
235
 
104
- // Sort transformations based on their priority
105
- this.array.sort((a, b) => a.priority - b.priority);
106
- }
107
- push(transform) {
108
- if (transform.className) {
109
- (0, _assert.ok)(!this.transforms[transform.className], "Already have " + transform.className);
236
+ // Skip pack if disabled
237
+ if (pluginInstance.order === _order.Order.Pack && options !== null && options !== void 0 && options.disablePack) continue;
238
+ if (this.options.verbose) {
239
+ console.log("Applying ".concat(pluginInstance.name, " (").concat(i + 1, "/").concat(this.plugins.length, ")"));
240
+ }
241
+ babel.traverse(ast, plugin.visitor);
242
+ (_plugin$post = plugin.post) === null || _plugin$post === void 0 || _plugin$post.call(plugin);
243
+ if (plugin.finalASTHandler) {
244
+ finalASTHandler.push(plugin.finalASTHandler);
245
+ }
246
+ if (options !== null && options !== void 0 && options.profiler) {
247
+ var _this$plugins;
248
+ options === null || options === void 0 || options.profiler({
249
+ index: i,
250
+ currentTransform: pluginInstance.name,
251
+ nextTransform: (_this$plugins = this.plugins[i + 1]) === null || _this$plugins === void 0 || (_this$plugins = _this$plugins.pluginInstance) === null || _this$plugins === void 0 ? void 0 : _this$plugins.name,
252
+ totalTransforms: this.plugins.length
253
+ });
254
+ }
255
+ }
256
+ for (var _i = 0, _finalASTHandler = finalASTHandler; _i < _finalASTHandler.length; _i++) {
257
+ var handler = _finalASTHandler[_i];
258
+ ast = handler(ast);
259
+ }
260
+ return ast;
110
261
  }
111
- this.transforms[transform.className] = transform;
112
- }
113
- resetState() {
114
- this.varCount = 0;
115
- this.generated = new Set();
116
- this.state = "transform";
117
- }
118
- async apply(tree) {
119
- let debugMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
120
- (0, _assert.ok)(tree.type == "Program", "The root node must be type 'Program'");
121
- (0, _assert.ok)(Array.isArray(tree.body), "The root's body property must be an array");
122
- (0, _assert.ok)(Array.isArray(this.array));
123
- this.resetState();
124
- var completed = 0;
125
- for (var transform of this.array) {
126
- await transform.apply(tree);
127
- completed++;
128
- if (debugMode) {
129
- this.emit("debug", transform.className, tree, completed);
262
+ }, {
263
+ key: "obfuscate",
264
+ value: function () {
265
+ var _obfuscate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(sourceCode) {
266
+ var ast, code;
267
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
268
+ while (1) switch (_context.prev = _context.next) {
269
+ case 0:
270
+ // Parse the source code into an AST
271
+ ast = Obfuscator.parseCode(sourceCode);
272
+ ast = this.obfuscateAST(ast);
273
+
274
+ // Generate the transformed code from the modified AST with comments removed and compacted output
275
+ code = this.generateCode(ast);
276
+ return _context.abrupt("return", {
277
+ code: code
278
+ });
279
+ case 4:
280
+ case "end":
281
+ return _context.stop();
282
+ }
283
+ }, _callee, this);
284
+ }));
285
+ function obfuscate(_x) {
286
+ return _obfuscate.apply(this, arguments);
130
287
  }
288
+ return obfuscate;
289
+ }()
290
+ }, {
291
+ key: "getPlugin",
292
+ value: function getPlugin(order) {
293
+ return this.plugins.find(function (x) {
294
+ return x.pluginInstance.order === order;
295
+ });
131
296
  }
132
- if (this.options.verbose) {
133
- console.log("-> Check for Eval Callbacks");
297
+ }, {
298
+ key: "hasPlugin",
299
+ value: function hasPlugin(order) {
300
+ return !!this.getPlugin(order);
134
301
  }
135
- this.state = "eval";
136
302
 
137
- // Find eval callbacks
138
- (0, _traverse.default)(tree, (o, p) => {
139
- if (o.$eval) {
140
- return () => {
141
- o.$eval(o, p);
142
- };
143
- }
144
- });
145
- if (this.options.verbose) {
146
- console.log("<- Done");
303
+ /**
304
+ * Calls `Obfuscator.generateCode` with the current instance options
305
+ */
306
+ }, {
307
+ key: "generateCode",
308
+ value: function generateCode(ast) {
309
+ return Obfuscator.generateCode(ast, this.options);
147
310
  }
148
- }
149
- }
150
- exports.default = Obfuscator;
311
+
312
+ /**
313
+ * Generates code from an AST using `@babel/generator`
314
+ */
315
+ }], [{
316
+ key: "generateCode",
317
+ value: function generateCode(ast) {
318
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
319
+ var compact = !!options.compact;
320
+ var _generate = (0, _generator["default"])(ast, {
321
+ comments: false,
322
+ // Remove comments
323
+ minified: compact
324
+ // jsescOption: {
325
+ // String Encoding using Babel
326
+ // escapeEverything: true,
327
+ // },
328
+ }),
329
+ code = _generate.code;
330
+ return code;
331
+ }
332
+
333
+ /**
334
+ * Parses the source code into an AST using `babel.parseSync`
335
+ */
336
+ }, {
337
+ key: "parseCode",
338
+ value: function parseCode(sourceCode) {
339
+ // Parse the source code into an AST
340
+ var ast = babel.parseSync(sourceCode, {
341
+ sourceType: "unambiguous",
342
+ babelrc: false,
343
+ configFile: false
344
+ });
345
+ return ast;
346
+ }
347
+ }]);
348
+ }();
package/dist/options.js CHANGED
@@ -2,122 +2,4 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
6
- exports.correctOptions = correctOptions;
7
- exports.validateOptions = validateOptions;
8
- var _assert = require("assert");
9
- var _presets = _interopRequireDefault(require("./presets"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const validProperties = new Set(["preset", "target", "indent", "compact", "hexadecimalNumbers", "minify", "es5", "renameVariables", "renameGlobals", "identifierGenerator", "controlFlowFlattening", "globalConcealing", "stringCompression", "stringConcealing", "stringEncoding", "stringSplitting", "duplicateLiteralsRemoval", "dispatcher", "rgf", "objectExtraction", "flatten", "deadCode", "calculator", "lock", "movedDeclarations", "opaquePredicates", "shuffle", "stack", "verbose", "globalVariables", "debugComments", "preserveFunctionLength"]);
12
- const validLockProperties = new Set(["selfDefending", "antiDebug", "context", "tamperProtection", "startDate", "endDate", "domainLock", "osLock", "browserLock", "integrity", "countermeasures"]);
13
- const validOses = new Set(["windows", "linux", "osx", "ios", "android"]);
14
- const validBrowsers = new Set(["firefox", "chrome", "iexplorer", "edge", "safari", "opera"]);
15
- function validateOptions(options) {
16
- if (!options || Object.keys(options).length <= 1) {
17
- /**
18
- * Give a welcoming introduction to those who skipped the documentation.
19
- */
20
- var line = `You provided zero obfuscation options. By default everything is disabled.\nYou can use a preset with:\n\n> {target: '${options.target || "node"}', preset: 'high' | 'medium' | 'low'}.\n\n\nView all settings here:\nhttps://github.com/MichaelXF/js-confuser#options`;
21
- throw new Error(`\n\n` + line.split("\n").map(x => `\t${x}`).join("\n") + `\n\n`);
22
- }
23
- (0, _assert.ok)(options, "options cannot be null");
24
- (0, _assert.ok)(options.target, "Missing options.target option (required, must one the following: 'browser' or 'node')");
25
- (0, _assert.ok)(["browser", "node"].includes(options.target), `'${options.target}' is not a valid target mode`);
26
- Object.keys(options).forEach(key => {
27
- if (!validProperties.has(key)) {
28
- throw new TypeError("Invalid option: '" + key + "'");
29
- }
30
- });
31
- if (options.target === "node" && options.lock && options.lock.browserLock && options.lock.browserLock.length) {
32
- throw new TypeError('browserLock can only be used when target="browser"');
33
- }
34
- if (options.lock) {
35
- (0, _assert.ok)(typeof options.lock === "object", "options.lock must be an object");
36
- Object.keys(options.lock).forEach(key => {
37
- if (!validLockProperties.has(key)) {
38
- throw new TypeError("Invalid lock option: '" + key + "'");
39
- }
40
- });
41
-
42
- // Validate browser-lock option
43
- if (options.lock.browserLock && typeof options.lock.browserLock !== "undefined") {
44
- (0, _assert.ok)(Array.isArray(options.lock.browserLock), "browserLock must be an array");
45
- (0, _assert.ok)(!options.lock.browserLock.find(browserName => !validBrowsers.has(browserName)), 'Invalid browser name. Allowed: "firefox", "chrome", "iexplorer", "edge", "safari", "opera"');
46
- }
47
- // Validate os-lock option
48
- if (options.lock.osLock && typeof options.lock.osLock !== "undefined") {
49
- (0, _assert.ok)(Array.isArray(options.lock.osLock), "osLock must be an array");
50
- (0, _assert.ok)(!options.lock.osLock.find(osName => !validOses.has(osName)), 'Invalid OS name. Allowed: "windows", "linux", "osx", "ios", "android"');
51
- }
52
- // Validate domain-lock option
53
- if (options.lock.domainLock && typeof options.lock.domainLock !== "undefined") {
54
- (0, _assert.ok)(Array.isArray(options.lock.domainLock), "domainLock must be an array");
55
- }
56
-
57
- // Validate context option
58
- if (options.lock.context && typeof options.lock.context !== "undefined") {
59
- (0, _assert.ok)(Array.isArray(options.lock.context), "context must be an array");
60
- }
61
-
62
- // Validate start-date option
63
- if (typeof options.lock.startDate !== "undefined" && options.lock.startDate) {
64
- (0, _assert.ok)(typeof options.lock.startDate === "number" || options.lock.startDate instanceof Date, "startDate must be Date object or number");
65
- }
66
-
67
- // Validate end-date option
68
- if (typeof options.lock.endDate !== "undefined" && options.lock.endDate) {
69
- (0, _assert.ok)(typeof options.lock.endDate === "number" || options.lock.endDate instanceof Date, "endDate must be Date object or number");
70
- }
71
- }
72
- if (options.preset) {
73
- if (!_presets.default[options.preset]) {
74
- throw new TypeError("Unknown preset of '" + options.preset + "'");
75
- }
76
- }
77
- }
78
-
79
- /**
80
- * Corrects the user's options. Sets the default values and validates the configuration.
81
- * @param options
82
- * @returns
83
- */
84
- async function correctOptions(options) {
85
- if (options.preset) {
86
- // Clone and allow overriding
87
- options = Object.assign({}, _presets.default[options.preset], options);
88
- }
89
- if (!options.hasOwnProperty("debugComments")) {
90
- options.debugComments = false; // debugComments is off by default
91
- }
92
- if (!options.hasOwnProperty("compact")) {
93
- options.compact = true; // Compact is on by default
94
- }
95
- if (!options.hasOwnProperty("renameGlobals")) {
96
- options.renameGlobals = true; // RenameGlobals is on by default
97
- }
98
- if (!options.hasOwnProperty("preserveFunctionLength")) {
99
- options.preserveFunctionLength = true; // preserveFunctionLength is on by default
100
- }
101
- if (options.globalVariables && !(options.globalVariables instanceof Set)) {
102
- options.globalVariables = new Set(Object.keys(options.globalVariables));
103
- }
104
- if (options.lock) {
105
- if (options.lock.selfDefending) {
106
- options.compact = true; // self defending forcibly enables this
107
- }
108
- }
109
-
110
- // options.globalVariables outlines generic globals that should be present in the execution context
111
- if (!options.hasOwnProperty("globalVariables")) {
112
- options.globalVariables = new Set([]);
113
- if (options.target == "browser") {
114
- // browser
115
- ["window", "document", "postMessage", "alert", "confirm", "location", "btoa", "atob", "unescape", "encodeURIComponent"].forEach(x => options.globalVariables.add(x));
116
- } else {
117
- // node
118
- ["global", "Buffer", "require", "process", "exports", "module", "__dirname", "__filename"].forEach(x => options.globalVariables.add(x));
119
- }
120
- ["globalThis", "console", "parseInt", "parseFloat", "Math", "JSON", "Promise", "String", "Boolean", "Function", "Object", "Array", "Proxy", "Error", "TypeError", "ReferenceError", "RangeError", "EvalError", "setTimeout", "clearTimeout", "setInterval", "clearInterval", "setImmediate", "clearImmediate", "queueMicrotask", "isNaN", "isFinite", "Set", "Map", "WeakSet", "WeakMap", "Symbol"].forEach(x => options.globalVariables.add(x));
121
- }
122
- return options;
123
- }
5
+ });