js-confuser 1.7.3 → 2.0.0-alpha.1

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 +313 -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 +327 -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,343 @@
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 _generator = _interopRequireDefault(require("@babel/generator"));
9
+ var _traverse = _interopRequireDefault(require("@babel/traverse"));
10
+ var _parser = require("@babel/parser");
11
+ var _validateOptions = require("./validateOptions");
10
12
  var _probability = require("./probability");
13
+ var _NameGen = require("./utils/NameGen");
14
+ var _order = require("./order");
15
+ var _plugin = require("./transforms/plugin");
11
16
  var _preparation = _interopRequireDefault(require("./transforms/preparation"));
12
- var _objectExtraction = _interopRequireDefault(require("./transforms/extraction/objectExtraction"));
13
- var _lock = _interopRequireDefault(require("./transforms/lock/lock"));
17
+ var _renameVariables = _interopRequireDefault(require("./transforms/identifier/renameVariables"));
18
+ var _variableMasking = _interopRequireDefault(require("./transforms/variableMasking"));
14
19
  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"));
20
+ var _duplicateLiteralsRemoval = _interopRequireDefault(require("./transforms/extraction/duplicateLiteralsRemoval"));
21
+ var _objectExtraction = _interopRequireDefault(require("./transforms/extraction/objectExtraction"));
22
+ var _functionOutlining = _interopRequireDefault(require("./transforms/functionOutlining"));
19
23
  var _globalConcealing = _interopRequireDefault(require("./transforms/identifier/globalConcealing"));
20
- var _stringSplitting = _interopRequireDefault(require("./transforms/string/stringSplitting"));
21
- var _stringConcealing = _interopRequireDefault(require("./transforms/string/stringConcealing"));
22
24
  var _stringCompression = _interopRequireDefault(require("./transforms/string/stringCompression"));
23
- var _duplicateLiteralsRemoval = _interopRequireDefault(require("./transforms/extraction/duplicateLiteralsRemoval"));
25
+ var _deadCode = _interopRequireDefault(require("./transforms/deadCode"));
26
+ var _stringSplitting = _interopRequireDefault(require("./transforms/string/stringSplitting"));
24
27
  var _shuffle = _interopRequireDefault(require("./transforms/shuffle"));
28
+ var _astScrambler = _interopRequireDefault(require("./transforms/astScrambler"));
29
+ var _calculator = _interopRequireDefault(require("./transforms/calculator"));
25
30
  var _movedDeclarations = _interopRequireDefault(require("./transforms/identifier/movedDeclarations"));
26
- var _renameVariables = _interopRequireDefault(require("./transforms/identifier/renameVariables"));
27
31
  var _renameLabels = _interopRequireDefault(require("./transforms/renameLabels"));
28
- var _minify = _interopRequireDefault(require("./transforms/minify"));
29
- var _es = _interopRequireDefault(require("./transforms/es5/es5"));
30
32
  var _rgf = _interopRequireDefault(require("./transforms/rgf"));
31
33
  var _flatten = _interopRequireDefault(require("./transforms/flatten"));
32
- var _stack = _interopRequireDefault(require("./transforms/stack"));
33
- var _antiTooling = _interopRequireDefault(require("./transforms/antiTooling"));
34
+ var _stringConcealing = _interopRequireDefault(require("./transforms/string/stringConcealing"));
35
+ var _lock = _interopRequireDefault(require("./transforms/lock/lock"));
36
+ var _controlFlowFlattening = _interopRequireDefault(require("./transforms/controlFlowFlattening"));
37
+ var _opaquePredicates = _interopRequireDefault(require("./transforms/opaquePredicates"));
38
+ var _minify = _interopRequireDefault(require("./transforms/minify"));
34
39
  var _finalizer = _interopRequireDefault(require("./transforms/finalizer"));
35
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
40
+ var _integrity = _interopRequireDefault(require("./transforms/lock/integrity"));
41
+ var _pack = _interopRequireDefault(require("./transforms/pack"));
42
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
43
+ 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; }
44
+ 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); }
45
+ 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); }); }; }
46
+ 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; } } }; }
47
+ 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; } }
48
+ 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; }
49
+ 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); }
50
+ 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; }
51
+ 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; }
52
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
53
+ 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); } }
54
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
36
55
  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];
56
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
57
+ 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
58
+ var DEFAULT_OPTIONS = exports.DEFAULT_OPTIONS = {
59
+ target: "node",
60
+ compact: true
61
+ };
62
+ var Obfuscator = exports["default"] = /*#__PURE__*/function () {
63
+ function Obfuscator(userOptions, parentObfuscator) {
64
+ var _this = this,
65
+ _this$options$lock;
66
+ _classCallCheck(this, Obfuscator);
67
+ _defineProperty(this, "plugins", []);
68
+ _defineProperty(this, "totalPossibleTransforms", 0);
69
+ _defineProperty(this, "globalState", {
70
+ lock: {
71
+ integrity: {
72
+ sensitivityRegex: / |\n|;|,|\{|\}|\(|\)|\.|\[|\]/g
73
+ },
74
+ createCountermeasuresCode: function createCountermeasuresCode() {
75
+ throw new Error("Not implemented");
76
+ }
77
+ },
78
+ // After RenameVariables completes, this map will contain the renamed variables
79
+ // Most use cases involve grabbing the Program(global) mappings
80
+ renamedVariables: new Map(),
81
+ // Internal functions, should not be renamed/removed
82
+ internals: {
83
+ stringCompressionLibraryName: "",
84
+ nativeFunctionName: "",
85
+ integrityHashName: "",
86
+ invokeCountermeasuresFnName: ""
61
87
  }
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);
88
+ });
89
+ _defineProperty(this, "index", 0);
90
+ this.parentObfuscator = parentObfuscator;
91
+ (0, _validateOptions.validateOptions)(userOptions);
92
+ this.options = (0, _validateOptions.applyDefaultsToOptions)(_objectSpread({}, userOptions));
93
+ this.nameGen = new _NameGen.NameGen(this.options.identifierGenerator);
94
+ var shouldAddLockTransform = this.options.lock && (Object.keys(this.options.lock).filter(function (key) {
95
+ return key !== "customLocks" && (0, _probability.isProbabilityMapProbable)(_this.options.lock[key]);
96
+ }).length > 0 || this.options.lock.customLocks.length > 0);
97
+ var allPlugins = [];
98
+ var push = function push(probabilityMap) {
99
+ for (var _len = arguments.length, pluginFns = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
100
+ pluginFns[_key - 1] = arguments[_key];
69
101
  }
102
+ _this.totalPossibleTransforms += pluginFns.length;
103
+ if (!(0, _probability.isProbabilityMapProbable)(probabilityMap)) return;
104
+ allPlugins.push.apply(allPlugins, pluginFns);
70
105
  };
106
+ push(true, _preparation["default"]);
107
+ push(this.options.objectExtraction, _objectExtraction["default"]);
108
+ push(this.options.flatten, _flatten["default"]);
109
+ push(shouldAddLockTransform, _lock["default"]);
110
+ push(this.options.rgf, _rgf["default"]);
111
+ push(this.options.dispatcher, _dispatcher["default"]);
112
+ push(this.options.deadCode, _deadCode["default"]);
113
+ push(this.options.controlFlowFlattening, _controlFlowFlattening["default"]);
114
+ push(this.options.calculator, _calculator["default"]);
115
+ push(this.options.globalConcealing, _globalConcealing["default"]);
116
+ push(this.options.opaquePredicates, _opaquePredicates["default"]);
117
+ push(this.options.functionOutlining, _functionOutlining["default"]);
118
+ push(this.options.stringSplitting, _stringSplitting["default"]);
119
+ push(this.options.stringConcealing, _stringConcealing["default"]);
120
+ push(this.options.stringCompression, _stringCompression["default"]);
121
+ push(this.options.variableMasking, _variableMasking["default"]);
122
+ push(this.options.duplicateLiteralsRemoval, _duplicateLiteralsRemoval["default"]);
123
+ push(this.options.shuffle, _shuffle["default"]);
124
+ push(this.options.movedDeclarations, _movedDeclarations["default"]);
125
+ push(this.options.renameLabels, _renameLabels["default"]);
126
+ push(this.options.minify, _minify["default"]);
127
+ push(this.options.astScrambler, _astScrambler["default"]);
128
+ push(this.options.renameVariables, _renameVariables["default"]);
129
+ push(true, _finalizer["default"]);
130
+ push(this.options.pack, _pack["default"]);
131
+ push((_this$options$lock = this.options.lock) === null || _this$options$lock === void 0 ? void 0 : _this$options$lock.integrity, _integrity["default"]);
132
+ allPlugins.map(function (pluginFunction) {
133
+ var pluginInstance;
134
+ var plugin = pluginFunction({
135
+ Plugin: function Plugin(order, mergeObject) {
136
+ (0, _assert.ok)(typeof order === "number");
137
+ var pluginOptions = {
138
+ order: order,
139
+ name: _order.Order[order]
140
+ };
141
+ var newPluginInstance = new _plugin.PluginInstance(pluginOptions, _this);
142
+ if (_typeof(mergeObject) === "object" && mergeObject) {
143
+ Object.assign(newPluginInstance, mergeObject);
144
+ }
145
+ pluginInstance = newPluginInstance;
71
146
 
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
147
+ // @ts-ignore
148
+ return newPluginInstance;
149
+ }
150
+ });
151
+ (0, _assert.ok)(pluginInstance, "Plugin instance not created: " + pluginFunction.toString());
152
+ _this.plugins.push({
153
+ plugin: plugin,
154
+ pluginInstance: pluginInstance
155
+ });
156
+ });
157
+ this.plugins = this.plugins.sort(function (a, b) {
158
+ return a.pluginInstance.order - b.pluginInstance.order;
159
+ });
160
+ if (!parentObfuscator && this.hasPlugin(_order.Order.StringCompression)) {
161
+ this.globalState.internals.stringCompressionLibraryName = this.nameGen.generate(false);
162
+ }
163
+ }
164
+ return _createClass(Obfuscator, [{
165
+ key: "isInternalVariable",
166
+ value: function isInternalVariable(name) {
167
+ return Object.values(this.globalState.internals).includes(name);
168
+ }
169
+ }, {
170
+ key: "shouldTransformNativeFunction",
171
+ value: function shouldTransformNativeFunction(nameAndPropertyPath) {
172
+ var _this$options$lock2;
173
+ if (!((_this$options$lock2 = this.options.lock) !== null && _this$options$lock2 !== void 0 && _this$options$lock2.tamperProtection)) {
174
+ return false;
175
+ }
96
176
 
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);
177
+ // Custom implementation for Tamper Protection
178
+ if (typeof this.options.lock.tamperProtection === "function") {
179
+ return this.options.lock.tamperProtection(nameAndPropertyPath.join("."));
180
+ }
181
+ if (this.options.target === "browser" && nameAndPropertyPath.length === 1 && nameAndPropertyPath[0] === "fetch") {
182
+ return true;
183
+ }
184
+ var globalObject = {};
185
+ try {
186
+ globalObject = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : new Function("return this")();
187
+ } catch (e) {}
188
+ var fn = globalObject;
189
+ var _iterator = _createForOfIteratorHelper(nameAndPropertyPath),
190
+ _step;
191
+ try {
192
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
193
+ var _fn;
194
+ var item = _step.value;
195
+ fn = (_fn = fn) === null || _fn === void 0 ? void 0 : _fn[item];
196
+ if (typeof fn === "undefined") return false;
197
+ }
198
+ } catch (err) {
199
+ _iterator.e(err);
200
+ } finally {
201
+ _iterator.f();
202
+ }
203
+ var hasNativeCode = typeof fn === "function" && ("" + fn).includes("[native code]");
204
+ return hasNativeCode;
205
+ }
206
+ }, {
207
+ key: "getStringCompressionLibraryName",
208
+ value: function getStringCompressionLibraryName() {
209
+ if (this.parentObfuscator) {
210
+ return this.parentObfuscator.getStringCompressionLibraryName();
211
+ }
212
+ return this.globalState.internals.stringCompressionLibraryName;
213
+ }
214
+ }, {
215
+ key: "getObfuscatedVariableName",
216
+ value: function getObfuscatedVariableName(originalName, programNode) {
217
+ var renamedVariables = this.globalState.renamedVariables.get(programNode);
218
+ return (renamedVariables === null || renamedVariables === void 0 ? void 0 : renamedVariables.get(originalName)) || originalName;
99
219
  }
100
220
 
101
- // Make array
102
- this.array = Object.values(this.transforms);
221
+ /**
222
+ * The main Name Generator for `Rename Variables`
223
+ */
224
+ }, {
225
+ key: "obfuscateAST",
226
+ value: function obfuscateAST(ast, options) {
227
+ var finalASTHandler = [];
228
+ for (var i = 0; i < this.plugins.length; i++) {
229
+ var _plugin$post;
230
+ this.index = i;
231
+ var _this$plugins$i = this.plugins[i],
232
+ plugin = _this$plugins$i.plugin,
233
+ pluginInstance = _this$plugins$i.pluginInstance;
103
234
 
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);
235
+ // Skip pack if disabled
236
+ if (pluginInstance.order === _order.Order.Pack && options !== null && options !== void 0 && options.disablePack) continue;
237
+ if (this.options.verbose) {
238
+ console.log("Applying ".concat(pluginInstance.name, " (").concat(i + 1, "/").concat(this.plugins.length, ")"));
239
+ }
240
+ (0, _traverse["default"])(ast, plugin.visitor);
241
+ (_plugin$post = plugin.post) === null || _plugin$post === void 0 || _plugin$post.call(plugin);
242
+ if (plugin.finalASTHandler) {
243
+ finalASTHandler.push(plugin.finalASTHandler);
244
+ }
245
+ if (options !== null && options !== void 0 && options.profiler) {
246
+ var _this$plugins;
247
+ options === null || options === void 0 || options.profiler({
248
+ index: i,
249
+ currentTransform: pluginInstance.name,
250
+ 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,
251
+ totalTransforms: this.plugins.length
252
+ });
253
+ }
254
+ }
255
+ for (var _i = 0, _finalASTHandler = finalASTHandler; _i < _finalASTHandler.length; _i++) {
256
+ var handler = _finalASTHandler[_i];
257
+ ast = handler(ast);
258
+ }
259
+ return ast;
110
260
  }
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);
261
+ }, {
262
+ key: "obfuscate",
263
+ value: function () {
264
+ var _obfuscate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(sourceCode) {
265
+ var ast, code;
266
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
267
+ while (1) switch (_context.prev = _context.next) {
268
+ case 0:
269
+ // Parse the source code into an AST
270
+ ast = Obfuscator.parseCode(sourceCode);
271
+ ast = this.obfuscateAST(ast);
272
+
273
+ // Generate the transformed code from the modified AST with comments removed and compacted output
274
+ code = this.generateCode(ast);
275
+ return _context.abrupt("return", {
276
+ code: code
277
+ });
278
+ case 4:
279
+ case "end":
280
+ return _context.stop();
281
+ }
282
+ }, _callee, this);
283
+ }));
284
+ function obfuscate(_x) {
285
+ return _obfuscate.apply(this, arguments);
130
286
  }
287
+ return obfuscate;
288
+ }()
289
+ }, {
290
+ key: "getPlugin",
291
+ value: function getPlugin(order) {
292
+ return this.plugins.find(function (x) {
293
+ return x.pluginInstance.order === order;
294
+ });
131
295
  }
132
- if (this.options.verbose) {
133
- console.log("-> Check for Eval Callbacks");
296
+ }, {
297
+ key: "hasPlugin",
298
+ value: function hasPlugin(order) {
299
+ return !!this.getPlugin(order);
134
300
  }
135
- this.state = "eval";
136
301
 
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");
302
+ /**
303
+ * Calls `Obfuscator.generateCode` with the current instance options
304
+ */
305
+ }, {
306
+ key: "generateCode",
307
+ value: function generateCode(ast) {
308
+ return Obfuscator.generateCode(ast, this.options);
147
309
  }
148
- }
149
- }
150
- exports.default = Obfuscator;
310
+
311
+ /**
312
+ * Generates code from an AST using `@babel/generator`
313
+ */
314
+ }], [{
315
+ key: "generateCode",
316
+ value: function generateCode(ast) {
317
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
318
+ var compact = !!options.compact;
319
+ var _generate = (0, _generator["default"])(ast, {
320
+ comments: false,
321
+ // Remove comments
322
+ minified: compact
323
+ // jsescOption: {
324
+ // String Encoding using Babel
325
+ // escapeEverything: true,
326
+ // },
327
+ }),
328
+ code = _generate.code;
329
+ return code;
330
+ }
331
+
332
+ /**
333
+ * Parses the source code into an AST using `babel.parseSync`
334
+ */
335
+ }, {
336
+ key: "parseCode",
337
+ value: function parseCode(sourceCode) {
338
+ // Parse the source code into an AST
339
+ var ast = (0, _parser.parse)(sourceCode, {
340
+ sourceType: "unambiguous"
341
+ });
342
+ return ast;
343
+ }
344
+ }]);
345
+ }();
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
+ });