js-confuser 2.0.0-alpha.5 → 2.0.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 (113) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +43 -43
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
  3. package/.github/workflows/node.js.yml +28 -28
  4. package/.prettierrc +4 -4
  5. package/CHANGELOG.md +1015 -989
  6. package/CODE_OF_CONDUCT.md +131 -131
  7. package/CONTRIBUTING.md +52 -52
  8. package/LICENSE +21 -21
  9. package/Migration.md +72 -71
  10. package/README.md +86 -78
  11. package/dist/constants.js +43 -43
  12. package/dist/index.js +14 -23
  13. package/dist/obfuscator.js +31 -25
  14. package/dist/order.js +4 -4
  15. package/dist/presets.js +31 -31
  16. package/dist/templates/integrityTemplate.js +4 -4
  17. package/dist/templates/template.js +1 -2
  18. package/dist/transforms/astScrambler.js +1 -2
  19. package/dist/transforms/calculator.js +1 -2
  20. package/dist/transforms/controlFlowFlattening.js +93 -63
  21. package/dist/transforms/deadCode.js +1 -2
  22. package/dist/transforms/dispatcher.js +4 -5
  23. package/dist/transforms/extraction/duplicateLiteralsRemoval.js +1 -2
  24. package/dist/transforms/extraction/objectExtraction.js +1 -2
  25. package/dist/transforms/finalizer.js +1 -2
  26. package/dist/transforms/flatten.js +1 -2
  27. package/dist/transforms/identifier/globalConcealing.js +15 -2
  28. package/dist/transforms/identifier/movedDeclarations.js +8 -7
  29. package/dist/transforms/identifier/renameVariables.js +7 -7
  30. package/dist/transforms/lock/integrity.js +11 -10
  31. package/dist/transforms/lock/lock.js +2 -3
  32. package/dist/transforms/minify.js +11 -29
  33. package/dist/transforms/opaquePredicates.js +1 -2
  34. package/dist/transforms/pack.js +5 -2
  35. package/dist/transforms/plugin.js +18 -19
  36. package/dist/transforms/preparation.js +16 -16
  37. package/dist/transforms/renameLabels.js +1 -2
  38. package/dist/transforms/rgf.js +8 -9
  39. package/dist/transforms/shuffle.js +1 -2
  40. package/dist/transforms/string/encoding.js +1 -2
  41. package/dist/transforms/string/stringCompression.js +3 -4
  42. package/dist/transforms/string/stringConcealing.js +8 -3
  43. package/dist/transforms/string/stringEncoding.js +1 -2
  44. package/dist/transforms/variableMasking.js +1 -2
  45. package/dist/utils/NameGen.js +2 -2
  46. package/dist/utils/PredicateGen.js +1 -2
  47. package/dist/utils/ast-utils.js +87 -88
  48. package/dist/utils/function-utils.js +8 -8
  49. package/dist/utils/node.js +5 -6
  50. package/dist/utils/object-utils.js +4 -4
  51. package/dist/utils/random-utils.js +20 -20
  52. package/dist/utils/static-utils.js +1 -2
  53. package/dist/validateOptions.js +4 -7
  54. package/index.d.ts +17 -17
  55. package/package.json +61 -59
  56. package/src/constants.ts +168 -168
  57. package/src/index.ts +118 -118
  58. package/src/obfuscationResult.ts +49 -49
  59. package/src/obfuscator.ts +501 -497
  60. package/src/options.ts +407 -407
  61. package/src/order.ts +54 -54
  62. package/src/presets.ts +125 -125
  63. package/src/templates/bufferToStringTemplate.ts +57 -57
  64. package/src/templates/deadCodeTemplates.ts +1185 -1185
  65. package/src/templates/getGlobalTemplate.ts +76 -76
  66. package/src/templates/integrityTemplate.ts +64 -64
  67. package/src/templates/setFunctionLengthTemplate.ts +11 -11
  68. package/src/templates/stringCompressionTemplate.ts +20 -20
  69. package/src/templates/tamperProtectionTemplates.ts +120 -120
  70. package/src/templates/template.ts +224 -224
  71. package/src/transforms/astScrambler.ts +99 -99
  72. package/src/transforms/calculator.ts +99 -99
  73. package/src/transforms/controlFlowFlattening.ts +1716 -1664
  74. package/src/transforms/deadCode.ts +82 -82
  75. package/src/transforms/dispatcher.ts +450 -450
  76. package/src/transforms/extraction/duplicateLiteralsRemoval.ts +156 -158
  77. package/src/transforms/extraction/objectExtraction.ts +186 -186
  78. package/src/transforms/finalizer.ts +74 -74
  79. package/src/transforms/flatten.ts +421 -420
  80. package/src/transforms/identifier/globalConcealing.ts +315 -295
  81. package/src/transforms/identifier/movedDeclarations.ts +252 -251
  82. package/src/transforms/identifier/renameVariables.ts +328 -321
  83. package/src/transforms/lock/integrity.ts +117 -114
  84. package/src/transforms/lock/lock.ts +418 -425
  85. package/src/transforms/minify.ts +615 -629
  86. package/src/transforms/opaquePredicates.ts +100 -100
  87. package/src/transforms/pack.ts +239 -231
  88. package/src/transforms/plugin.ts +173 -173
  89. package/src/transforms/preparation.ts +349 -347
  90. package/src/transforms/renameLabels.ts +175 -175
  91. package/src/transforms/rgf.ts +322 -322
  92. package/src/transforms/shuffle.ts +82 -82
  93. package/src/transforms/string/encoding.ts +144 -144
  94. package/src/transforms/string/stringCompression.ts +128 -128
  95. package/src/transforms/string/stringConcealing.ts +312 -298
  96. package/src/transforms/string/stringEncoding.ts +80 -80
  97. package/src/transforms/string/stringSplitting.ts +77 -77
  98. package/src/transforms/variableMasking.ts +257 -257
  99. package/src/utils/IntGen.ts +33 -33
  100. package/src/utils/NameGen.ts +116 -116
  101. package/src/utils/PredicateGen.ts +61 -61
  102. package/src/utils/ast-utils.ts +663 -663
  103. package/src/utils/function-utils.ts +50 -50
  104. package/src/utils/gen-utils.ts +48 -48
  105. package/src/utils/node.ts +78 -78
  106. package/src/utils/object-utils.ts +21 -21
  107. package/src/utils/random-utils.ts +93 -93
  108. package/src/utils/static-utils.ts +66 -66
  109. package/src/validateOptions.ts +256 -259
  110. package/tsconfig.json +13 -14
  111. package/dist/probability.js +0 -1
  112. package/dist/transforms/functionOutlining.js +0 -230
  113. package/dist/utils/ControlObject.js +0 -125
package/src/options.ts CHANGED
@@ -1,407 +1,407 @@
1
- import Template from "./templates/template";
2
-
3
- // JS-Confuser.com imports this file for Type support, therefore some additional types are included here.
4
-
5
- type Stringed<V> = V extends string ? V : never;
6
-
7
- /**
8
- * Configurable probabilities for obfuscator options.
9
- * - **`false`** = this feature is disabled
10
- * - **`true`** = this feature is enabled, use default mode
11
- * - **`0.5`** = 50% chance
12
- * - **`"mode"`** = enabled, use specified mode
13
- * - **`["mode1", "mode2"]`** - enabled, choose random mode each occurrence
14
- * - **`{"mode1": 0.5, "mode2": 0.5}`** - enabled, choose based on specified probabilities
15
- * - **`{"mode1": 50, "mode2": 50}`** - enabled, each is divided based on total
16
- * - **`function(x){ return "custom_implementation" }`** - enabled, use specified function
17
- */
18
- export type ProbabilityMap<
19
- T = boolean,
20
- F extends (...args: any[]) => any = () => boolean // Default to a generic function
21
- > =
22
- | false
23
- | true
24
- | number
25
- | F
26
- | (T extends never | boolean
27
- ? {
28
- value: ProbabilityMap<never, F>;
29
- limit?: number;
30
- }
31
- : T | T[] | { [key in Stringed<T>]?: number });
32
-
33
- export interface CustomLock {
34
- /**
35
- * Template lock code that must contain:
36
- *
37
- * - `{countermeasures}`
38
- *
39
- * The countermeasures function will be invoked when the lock is triggered.
40
- *
41
- * ```js
42
- * if(window.navigator.userAgent.includes('Chrome')){
43
- * {countermeasures}
44
- * }
45
- * ```
46
- *
47
- * Multiple templates can be passed a string array, a random one will be chosen each time.
48
- */
49
- code: string | string[] | Template;
50
- percentagePerBlock: number;
51
- maxCount?: number;
52
- minCount?: number;
53
- }
54
-
55
- export interface CustomStringEncoding {
56
- /**
57
- * Template string decoder that must contain:
58
- *
59
- * - `{fnName}`
60
- *
61
- * This function will be invoked by the obfuscated code to DECODE the string.
62
- *
63
- * ```js
64
- * function {fnName}(str){
65
- * return Buffer.from(str, 'base64').toString('utf-8')
66
- * }
67
- * ```
68
- */
69
- code?: string | Template;
70
- encode: (str: string) => string;
71
-
72
- /**
73
- * Optional. A decoder function can be provided to ensure the string is able to decode properly.
74
- * @param str
75
- * @returns
76
- */
77
- decode?: (str: string) => string;
78
-
79
- /**
80
- * Should be used when created 'shuffled' variants of the same encoding.
81
- */
82
- identity?: string;
83
- }
84
-
85
- export interface ObfuscateOptions {
86
- /**
87
- * The preset to use for obfuscation.
88
- */
89
- preset?: "high" | "medium" | "low" | false;
90
-
91
- /**
92
- * The execution context for your output. _Required_.
93
- *
94
- * 1. `"node"`
95
- * 2. `"browser"`
96
- */
97
- target: "node" | "browser";
98
-
99
- /**
100
- * Remove's whitespace from the final output.
101
- */
102
- compact?: boolean;
103
-
104
- /**
105
- * Uses the hexadecimal representation for numbers.
106
- */
107
- hexadecimalNumbers?: boolean;
108
-
109
- /**
110
- * Minifies redundant code.
111
- */
112
- minify?: boolean;
113
-
114
- /**
115
- * Renames labeled statements. Enabled by default.
116
- */
117
- renameLabels?: ProbabilityMap<boolean, (labelName: string) => boolean>;
118
-
119
- /**
120
- * Determines if variables should be renamed.
121
- */
122
- renameVariables?: ProbabilityMap<
123
- boolean,
124
- (variableName: string, topLevel: boolean) => boolean
125
- >;
126
-
127
- /**
128
- * Renames top-level variables, turn this off for web-related scripts. Enabled by default.
129
- */
130
- renameGlobals?: ProbabilityMap<boolean, (variableName: string) => boolean>;
131
-
132
- /**
133
- * Determines how variables are renamed.
134
- *
135
- * JS-Confuser tries to reuse names when possible, creating very potent code.
136
- */
137
- identifierGenerator?: ProbabilityMap<
138
- | "hexadecimal"
139
- | "randomized"
140
- | "zeroWidth"
141
- | "mangled"
142
- | "number"
143
- | "chinese",
144
- () => string
145
- >;
146
-
147
- /**
148
- * ⚠️ Significantly impacts performance, use sparingly!
149
- *
150
- * Control-flow Flattening hinders program comprehension by creating convoluted switch statements.
151
- *
152
- * Use a number to control the percentage from 0 to 1.
153
- */
154
- controlFlowFlattening?: ProbabilityMap<boolean>;
155
-
156
- /**
157
- * Global Concealing hides global variables being accessed.
158
- */
159
- globalConcealing?: ProbabilityMap<boolean, (globalName: string) => boolean>;
160
-
161
- /**
162
- * String Compression uses zlib compression algorithm to compress strings.
163
- *
164
- * `"console"` -> `inflate('replaĕ!ğğuģģ<~@')`
165
- */
166
- stringCompression?: ProbabilityMap<boolean, (strValue: string) => boolean>;
167
-
168
- /**
169
- * String Concealing involves encoding strings to conceal plain-text values.
170
- *
171
- * `"console"` -> `decrypt('<~@rH7+Dert~>')`
172
- */
173
- stringConcealing?: ProbabilityMap<boolean, (strValue: string) => boolean>;
174
-
175
- /**
176
- * Custom String Encodings allows you to define your own string encoding/decoding functions.
177
- */
178
- customStringEncodings?: (
179
- | CustomStringEncoding
180
- | ((encodingImplementations: {
181
- [identity: string]: CustomStringEncoding;
182
- }) => CustomStringEncoding | null)
183
- )[];
184
-
185
- /**
186
- * String Encoding transforms a string into an escaped unicode representation.
187
- *
188
- * `"console"` -> `'\x63\x6f\x6e\x73\x6f\x6c\x65'`
189
- */
190
- stringEncoding?: ProbabilityMap<boolean, (strValue: string) => boolean>;
191
-
192
- /**
193
- * String Splitting splits your strings into multiple expressions.
194
- *
195
- * `"console"` -> `String.fromCharCode(99) + 'ons' + 'ole'`
196
- */
197
- stringSplitting?: ProbabilityMap<boolean, (strValue: string) => boolean>;
198
-
199
- /**
200
- * Duplicate Literals Removal replaces duplicate literals with a single variable name.
201
- */
202
- duplicateLiteralsRemoval?: ProbabilityMap<boolean>;
203
-
204
- /**
205
- * Creates a middleman function to process function calls.
206
- */
207
- dispatcher?: ProbabilityMap<boolean, (fnName: string) => boolean>;
208
-
209
- /**
210
- * RGF (Runtime-Generated-Functions) uses the [`new Function(code...)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function) syntax to construct executable code from strings.
211
- *
212
- * - **This can break your code.**
213
- * - **Due to the security concerns of arbitrary code execution, you must enable this yourself.**
214
- * - The arbitrary code is also obfuscated.
215
- *
216
- * ```js
217
- * // Input
218
- * function log(x){
219
- * console.log(x)
220
- * }
221
- *
222
- * log("Hello World")
223
- *
224
- * // Output
225
- * var C6z0jyO=[new Function('a2Fjjl',"function OqNW8x(OqNW8x){console['log'](OqNW8x)}return OqNW8x(...Array.prototype.slice.call(arguments,1))")];(function(){return C6z0jyO[0](C6z0jyO,...arguments)}('Hello World'))
226
- * ```
227
- *
228
- */
229
- rgf?: ProbabilityMap<boolean, (fnName: string, isGlobal: boolean) => boolean>;
230
-
231
- /**
232
- * Local variables are consolidated into a rotating array.
233
- *
234
- * [Similar to Jscrambler's Variable Masking](https://docs.jscrambler.com/code-integrity/documentation/transformations/variable-masking)
235
- *
236
- * ```js
237
- * // Input
238
- * function add3(x, y, z){
239
- * return x + y + z;
240
- * }
241
- *
242
- * // Output
243
- * function iVQoGQD(...iVQoGQD){
244
- * ~(iVQoGQD.length = 3, iVQoGQD[215] = iVQoGQD[2], iVQoGQD[75] = 227, iVQoGQD[iVQoGQD[75] - (iVQoGQD[75] - 75)] = iVQoGQD[75] - (iVQoGQD[75] - 239), iVQoGQD[iVQoGQD[iVQoGQD[75] - 164] - 127] = iVQoGQD[iVQoGQD[75] - 238], iVQoGQD[iVQoGQD[75] - 104] = iVQoGQD[75] - 482, iVQoGQD[iVQoGQD[135] + 378] = iVQoGQD[iVQoGQD[135] + 318] - 335, iVQoGQD[21] = iVQoGQD[iVQoGQD[135] + 96], iVQoGQD[iVQoGQD[iVQoGQD[75] - 104] - (iVQoGQD[75] - 502)] = iVQoGQD[iVQoGQD[75] - 164] - 440);
245
- * return iVQoGQD[75] > iVQoGQD[75] + 90 ? iVQoGQD[iVQoGQD[135] - (iVQoGQD[135] + 54)] : iVQoGQD[iVQoGQD[135] + 117] + iVQoGQD[iVQoGQD[iVQoGQD[75] - (iVQoGQD[75] - (iVQoGQD[75] - 104))] - (iVQoGQD[135] - 112)] + iVQoGQD[215];
246
- * };
247
- * ```
248
- */
249
- variableMasking?: ProbabilityMap<boolean, (fnName: string) => boolean>;
250
-
251
- /**
252
- * Extracts object properties into separate variables.
253
- *
254
- * ```js
255
- * // Input
256
- * var utils = {
257
- * isString: x=>typeof x === "string",
258
- * isBoolean: x=>typeof x === "boolean"
259
- * }
260
- * if ( utils.isString("Hello") ) {
261
- * // ...
262
- * }
263
- *
264
- * // Output
265
- * var utils_isString = x=>typeof x === "string";
266
- * var utils_isBoolean = x=>typeof x === "boolean"
267
- * if ( utils_isString("Hello") ) {
268
- * // ...
269
- * }
270
- * ```
271
- */
272
- objectExtraction?: ProbabilityMap<boolean, (objectName: string) => boolean>;
273
-
274
- /**
275
- * Declares functions at the top of the program, preserving their original scope.
276
- */
277
- flatten?: ProbabilityMap<boolean, (fnName: string) => boolean>;
278
-
279
- /**
280
- * Randomly injects dead code.
281
- *
282
- * Use a number to control the percentage from 0 to 1.
283
- */
284
- deadCode?: ProbabilityMap<boolean>;
285
-
286
- /**
287
- * Creates a calculator function to handle arithmetic and logical expressions.
288
- *
289
- */
290
- calculator?: ProbabilityMap<boolean>;
291
-
292
- lock?: {
293
- /**
294
- * Prevents the use of code beautifiers or formatters against your code.
295
- *
296
- * [Identical to Obfuscator.io's Self Defending](https://github.com/javascript-obfuscator/javascript-obfuscator#selfdefending)
297
- *
298
- */
299
- selfDefending?: boolean;
300
-
301
- /**
302
- * Adds `debugger` statements throughout the code.
303
- */
304
- antiDebug?: ProbabilityMap<boolean>;
305
-
306
- /**
307
- * Tamper Protection safeguards the runtime behavior from being altered by JavaScript pitfalls.
308
- *
309
- * **⚠️ Tamper Protection requires eval and ran in a non-strict mode environment!**
310
- *
311
- * - **This can break your code.**
312
- * - **Due to the security concerns of arbitrary code execution, you must enable this yourself.**
313
- *
314
- * @see https://github.com/MichaelXF/js-confuser/blob/master/TamperProtection.md
315
- */
316
- tamperProtection?: ProbabilityMap<boolean, (varName: string) => boolean>;
317
-
318
- /**
319
- * When the program is first able to be used. (`number` or `Date`)
320
- *
321
- * Number should be in milliseconds.
322
- */
323
- startDate?: number | Date | false;
324
-
325
- /**
326
- * When the program is no longer able to be used. (`number` or `Date`)
327
- *
328
- * Number should be in milliseconds.
329
- */
330
- endDate?: number | Date | false;
331
-
332
- /**
333
- * Array of regex strings that the `window.location.href` must follow.
334
- */
335
- domainLock?: RegExp[] | string[] | false;
336
-
337
- /**
338
- * Integrity ensures the source code is unchanged.
339
- *
340
- * @see https://github.com/MichaelXF/js-confuser/blob/master/Integrity.md
341
- */
342
- integrity?: ProbabilityMap<boolean, (fnName: string) => boolean>;
343
-
344
- /**
345
- * A custom callback function to invoke when a lock is triggered. (`string/false`)
346
- *
347
- * This could be due to an invalid domain, incorrect time, or code's integrity changed.
348
- *
349
- * If no countermeasures function is provided (`undefined` or `true`), the obfuscator falls back to crashing the process.
350
- *
351
- * If `countermeasures` is `false`, no crash will occur.
352
- *
353
- * @see https://github.com/MichaelXF/js-confuser/blob/master/Countermeasures.md
354
- */
355
- countermeasures?: string | boolean;
356
-
357
- customLocks?: CustomLock[];
358
-
359
- /**
360
- * The default 'maxCount' for obfuscator and custom locks. Defaults to 25.
361
- */
362
- defaultMaxCount?: number;
363
- };
364
-
365
- /**
366
- * Moves variable declarations to the top of the context.
367
- */
368
- movedDeclarations?: ProbabilityMap<boolean>;
369
-
370
- /**
371
- * An [Opaque Predicate](https://en.wikipedia.org/wiki/Opaque_predicate) is a predicate(true/false) that is evaluated at runtime, this can confuse reverse engineers
372
- * understanding your code.
373
- */
374
- opaquePredicates?: ProbabilityMap<boolean>;
375
-
376
- /**
377
- * Shuffles the initial order of arrays. The order is brought back to the original during runtime. (`"hash"/true/false/0-1`)
378
- */
379
- shuffle?: ProbabilityMap<boolean>;
380
-
381
- /**
382
- * Modified functions will retain the correct `function.length` property. Enabled by default.
383
- */
384
- preserveFunctionLength?: boolean;
385
-
386
- /**
387
- * Semantically changes the AST to bypass automated tools.
388
- */
389
- astScrambler?: boolean;
390
-
391
- /**
392
- * Packs the output code into a single `Function()` call.
393
- *
394
- * Designed to escape strict mode constraints.
395
- */
396
- pack?: ProbabilityMap<boolean, (globalName: string) => boolean>;
397
-
398
- /**
399
- * Set of global variables. *Optional*.
400
- */
401
- globalVariables?: Set<string>;
402
-
403
- /**
404
- * Enable logs to view the obfuscator's state.
405
- */
406
- verbose?: boolean;
407
- }
1
+ import Template from "./templates/template";
2
+
3
+ // JS-Confuser.com imports this file for Type support, therefore some additional types are included here.
4
+
5
+ type Stringed<V> = V extends string ? V : never;
6
+
7
+ /**
8
+ * Configurable probabilities for obfuscator options.
9
+ * - **`false`** = this feature is disabled
10
+ * - **`true`** = this feature is enabled, use default mode
11
+ * - **`0.5`** = 50% chance
12
+ * - **`"mode"`** = enabled, use specified mode
13
+ * - **`["mode1", "mode2"]`** - enabled, choose random mode each occurrence
14
+ * - **`{"mode1": 0.5, "mode2": 0.5}`** - enabled, choose based on specified probabilities
15
+ * - **`{"mode1": 50, "mode2": 50}`** - enabled, each is divided based on total
16
+ * - **`function(x){ return "custom_implementation" }`** - enabled, use specified function
17
+ */
18
+ export type ProbabilityMap<
19
+ T = boolean,
20
+ F extends (...args: any[]) => any = () => boolean // Default to a generic function
21
+ > =
22
+ | false
23
+ | true
24
+ | number
25
+ | F
26
+ | (T extends never | boolean
27
+ ? {
28
+ value: ProbabilityMap<never, F>;
29
+ limit?: number;
30
+ }
31
+ : T | T[] | { [key in Stringed<T>]?: number });
32
+
33
+ export interface CustomLock {
34
+ /**
35
+ * Template lock code that must contain:
36
+ *
37
+ * - `{countermeasures}`
38
+ *
39
+ * The countermeasures function will be invoked when the lock is triggered.
40
+ *
41
+ * ```js
42
+ * if(window.navigator.userAgent.includes('Chrome')){
43
+ * {countermeasures}
44
+ * }
45
+ * ```
46
+ *
47
+ * Multiple templates can be passed a string array, a random one will be chosen each time.
48
+ */
49
+ code: string | string[] | Template;
50
+ percentagePerBlock: number;
51
+ maxCount?: number;
52
+ minCount?: number;
53
+ }
54
+
55
+ export interface CustomStringEncoding {
56
+ /**
57
+ * Template string decoder that must contain:
58
+ *
59
+ * - `{fnName}`
60
+ *
61
+ * This function will be invoked by the obfuscated code to DECODE the string.
62
+ *
63
+ * ```js
64
+ * function {fnName}(str){
65
+ * return Buffer.from(str, 'base64').toString('utf-8')
66
+ * }
67
+ * ```
68
+ */
69
+ code?: string | Template;
70
+ encode: (str: string) => string;
71
+
72
+ /**
73
+ * Optional. A decoder function can be provided to ensure the string is able to decode properly.
74
+ * @param str
75
+ * @returns
76
+ */
77
+ decode?: (str: string) => string;
78
+
79
+ /**
80
+ * Should be used when created 'shuffled' variants of the same encoding.
81
+ */
82
+ identity?: string;
83
+ }
84
+
85
+ export interface ObfuscateOptions {
86
+ /**
87
+ * The preset to use for obfuscation.
88
+ */
89
+ preset?: "high" | "medium" | "low" | false;
90
+
91
+ /**
92
+ * The execution context for your output. _Required_.
93
+ *
94
+ * 1. `"node"`
95
+ * 2. `"browser"`
96
+ */
97
+ target: "node" | "browser";
98
+
99
+ /**
100
+ * Remove's whitespace from the final output.
101
+ */
102
+ compact?: boolean;
103
+
104
+ /**
105
+ * Uses the hexadecimal representation for numbers.
106
+ */
107
+ hexadecimalNumbers?: boolean;
108
+
109
+ /**
110
+ * Minifies redundant code.
111
+ */
112
+ minify?: boolean;
113
+
114
+ /**
115
+ * Renames labeled statements. Enabled by default.
116
+ */
117
+ renameLabels?: ProbabilityMap<boolean, (labelName: string) => boolean>;
118
+
119
+ /**
120
+ * Determines if variables should be renamed.
121
+ */
122
+ renameVariables?: ProbabilityMap<
123
+ boolean,
124
+ (variableName: string, topLevel: boolean) => boolean
125
+ >;
126
+
127
+ /**
128
+ * Renames top-level variables, turn this off for web-related scripts. Enabled by default.
129
+ */
130
+ renameGlobals?: ProbabilityMap<boolean, (variableName: string) => boolean>;
131
+
132
+ /**
133
+ * Determines how variables are renamed.
134
+ *
135
+ * JS-Confuser tries to reuse names when possible, creating very potent code.
136
+ */
137
+ identifierGenerator?: ProbabilityMap<
138
+ | "hexadecimal"
139
+ | "randomized"
140
+ | "zeroWidth"
141
+ | "mangled"
142
+ | "number"
143
+ | "chinese",
144
+ () => string
145
+ >;
146
+
147
+ /**
148
+ * ⚠️ Significantly impacts performance, use sparingly!
149
+ *
150
+ * Control-flow Flattening hinders program comprehension by creating convoluted switch statements.
151
+ *
152
+ * Use a number to control the percentage from 0 to 1.
153
+ */
154
+ controlFlowFlattening?: ProbabilityMap<boolean>;
155
+
156
+ /**
157
+ * Global Concealing hides global variables being accessed.
158
+ */
159
+ globalConcealing?: ProbabilityMap<boolean, (globalName: string) => boolean>;
160
+
161
+ /**
162
+ * String Compression uses zlib compression algorithm to compress strings.
163
+ *
164
+ * `"console"` -> `inflate('replaĕ!ğğuģģ<~@')`
165
+ */
166
+ stringCompression?: ProbabilityMap<boolean, (strValue: string) => boolean>;
167
+
168
+ /**
169
+ * String Concealing involves encoding strings to conceal plain-text values.
170
+ *
171
+ * `"console"` -> `decrypt('<~@rH7+Dert~>')`
172
+ */
173
+ stringConcealing?: ProbabilityMap<boolean, (strValue: string) => boolean>;
174
+
175
+ /**
176
+ * Custom String Encodings allows you to define your own string encoding/decoding functions.
177
+ */
178
+ customStringEncodings?: (
179
+ | CustomStringEncoding
180
+ | ((encodingImplementations: {
181
+ [identity: string]: CustomStringEncoding;
182
+ }) => CustomStringEncoding | null)
183
+ )[];
184
+
185
+ /**
186
+ * String Encoding transforms a string into an escaped unicode representation.
187
+ *
188
+ * `"console"` -> `'\x63\x6f\x6e\x73\x6f\x6c\x65'`
189
+ */
190
+ stringEncoding?: ProbabilityMap<boolean, (strValue: string) => boolean>;
191
+
192
+ /**
193
+ * String Splitting splits your strings into multiple expressions.
194
+ *
195
+ * `"console"` -> `String.fromCharCode(99) + 'ons' + 'ole'`
196
+ */
197
+ stringSplitting?: ProbabilityMap<boolean, (strValue: string) => boolean>;
198
+
199
+ /**
200
+ * Duplicate Literals Removal replaces duplicate literals with a single variable name.
201
+ */
202
+ duplicateLiteralsRemoval?: ProbabilityMap<boolean>;
203
+
204
+ /**
205
+ * Creates a middleman function to process function calls.
206
+ */
207
+ dispatcher?: ProbabilityMap<boolean, (fnName: string) => boolean>;
208
+
209
+ /**
210
+ * RGF (Runtime-Generated-Functions) uses the [`new Function(code...)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function) syntax to construct executable code from strings.
211
+ *
212
+ * - **This can break your code.**
213
+ * - **Due to the security concerns of arbitrary code execution, you must enable this yourself.**
214
+ * - The arbitrary code is also obfuscated.
215
+ *
216
+ * ```js
217
+ * // Input
218
+ * function log(x){
219
+ * console.log(x)
220
+ * }
221
+ *
222
+ * log("Hello World")
223
+ *
224
+ * // Output
225
+ * var C6z0jyO=[new Function('a2Fjjl',"function OqNW8x(OqNW8x){console['log'](OqNW8x)}return OqNW8x(...Array.prototype.slice.call(arguments,1))")];(function(){return C6z0jyO[0](C6z0jyO,...arguments)}('Hello World'))
226
+ * ```
227
+ *
228
+ */
229
+ rgf?: ProbabilityMap<boolean, (fnName: string, isGlobal: boolean) => boolean>;
230
+
231
+ /**
232
+ * Local variables are consolidated into a rotating array.
233
+ *
234
+ * [Similar to Jscrambler's Variable Masking](https://docs.jscrambler.com/code-integrity/documentation/transformations/variable-masking)
235
+ *
236
+ * ```js
237
+ * // Input
238
+ * function add3(x, y, z){
239
+ * return x + y + z;
240
+ * }
241
+ *
242
+ * // Output
243
+ * function iVQoGQD(...iVQoGQD){
244
+ * ~(iVQoGQD.length = 3, iVQoGQD[215] = iVQoGQD[2], iVQoGQD[75] = 227, iVQoGQD[iVQoGQD[75] - (iVQoGQD[75] - 75)] = iVQoGQD[75] - (iVQoGQD[75] - 239), iVQoGQD[iVQoGQD[iVQoGQD[75] - 164] - 127] = iVQoGQD[iVQoGQD[75] - 238], iVQoGQD[iVQoGQD[75] - 104] = iVQoGQD[75] - 482, iVQoGQD[iVQoGQD[135] + 378] = iVQoGQD[iVQoGQD[135] + 318] - 335, iVQoGQD[21] = iVQoGQD[iVQoGQD[135] + 96], iVQoGQD[iVQoGQD[iVQoGQD[75] - 104] - (iVQoGQD[75] - 502)] = iVQoGQD[iVQoGQD[75] - 164] - 440);
245
+ * return iVQoGQD[75] > iVQoGQD[75] + 90 ? iVQoGQD[iVQoGQD[135] - (iVQoGQD[135] + 54)] : iVQoGQD[iVQoGQD[135] + 117] + iVQoGQD[iVQoGQD[iVQoGQD[75] - (iVQoGQD[75] - (iVQoGQD[75] - 104))] - (iVQoGQD[135] - 112)] + iVQoGQD[215];
246
+ * };
247
+ * ```
248
+ */
249
+ variableMasking?: ProbabilityMap<boolean, (fnName: string) => boolean>;
250
+
251
+ /**
252
+ * Extracts object properties into separate variables.
253
+ *
254
+ * ```js
255
+ * // Input
256
+ * var utils = {
257
+ * isString: x=>typeof x === "string",
258
+ * isBoolean: x=>typeof x === "boolean"
259
+ * }
260
+ * if ( utils.isString("Hello") ) {
261
+ * // ...
262
+ * }
263
+ *
264
+ * // Output
265
+ * var utils_isString = x=>typeof x === "string";
266
+ * var utils_isBoolean = x=>typeof x === "boolean"
267
+ * if ( utils_isString("Hello") ) {
268
+ * // ...
269
+ * }
270
+ * ```
271
+ */
272
+ objectExtraction?: ProbabilityMap<boolean, (objectName: string) => boolean>;
273
+
274
+ /**
275
+ * Declares functions at the top of the program, preserving their original scope.
276
+ */
277
+ flatten?: ProbabilityMap<boolean, (fnName: string) => boolean>;
278
+
279
+ /**
280
+ * Randomly injects dead code.
281
+ *
282
+ * Use a number to control the percentage from 0 to 1.
283
+ */
284
+ deadCode?: ProbabilityMap<boolean>;
285
+
286
+ /**
287
+ * Creates a calculator function to handle arithmetic and logical expressions.
288
+ *
289
+ */
290
+ calculator?: ProbabilityMap<boolean>;
291
+
292
+ lock?: {
293
+ /**
294
+ * Prevents the use of code beautifiers or formatters against your code.
295
+ *
296
+ * [Identical to Obfuscator.io's Self Defending](https://github.com/javascript-obfuscator/javascript-obfuscator#selfdefending)
297
+ *
298
+ */
299
+ selfDefending?: boolean;
300
+
301
+ /**
302
+ * Adds `debugger` statements throughout the code.
303
+ */
304
+ antiDebug?: ProbabilityMap<boolean>;
305
+
306
+ /**
307
+ * Tamper Protection safeguards the runtime behavior from being altered by JavaScript pitfalls.
308
+ *
309
+ * **⚠️ Tamper Protection requires eval and ran in a non-strict mode environment!**
310
+ *
311
+ * - **This can break your code.**
312
+ * - **Due to the security concerns of arbitrary code execution, you must enable this yourself.**
313
+ *
314
+ * @see https://github.com/MichaelXF/js-confuser/blob/master/TamperProtection.md
315
+ */
316
+ tamperProtection?: ProbabilityMap<boolean, (varName: string) => boolean>;
317
+
318
+ /**
319
+ * When the program is first able to be used. (`number` or `Date`)
320
+ *
321
+ * Number should be in milliseconds.
322
+ */
323
+ startDate?: number | Date | false;
324
+
325
+ /**
326
+ * When the program is no longer able to be used. (`number` or `Date`)
327
+ *
328
+ * Number should be in milliseconds.
329
+ */
330
+ endDate?: number | Date | false;
331
+
332
+ /**
333
+ * Array of regex strings that the `window.location.href` must follow.
334
+ */
335
+ domainLock?: RegExp[] | string[] | false;
336
+
337
+ /**
338
+ * Integrity ensures the source code is unchanged.
339
+ *
340
+ * @see https://github.com/MichaelXF/js-confuser/blob/master/Integrity.md
341
+ */
342
+ integrity?: ProbabilityMap<boolean, (fnName: string) => boolean>;
343
+
344
+ /**
345
+ * A custom callback function to invoke when a lock is triggered. (`string/false`)
346
+ *
347
+ * This could be due to an invalid domain, incorrect time, or code's integrity changed.
348
+ *
349
+ * If no countermeasures function is provided (`undefined` or `true`), the obfuscator falls back to crashing the process.
350
+ *
351
+ * If `countermeasures` is `false`, no crash will occur.
352
+ *
353
+ * @see https://github.com/MichaelXF/js-confuser/blob/master/Countermeasures.md
354
+ */
355
+ countermeasures?: string | boolean;
356
+
357
+ customLocks?: CustomLock[];
358
+
359
+ /**
360
+ * The default 'maxCount' for obfuscator and custom locks. Defaults to 25.
361
+ */
362
+ defaultMaxCount?: number;
363
+ };
364
+
365
+ /**
366
+ * Moves variable declarations to the top of the context.
367
+ */
368
+ movedDeclarations?: ProbabilityMap<boolean>;
369
+
370
+ /**
371
+ * An [Opaque Predicate](https://en.wikipedia.org/wiki/Opaque_predicate) is a predicate(true/false) that is evaluated at runtime, this can confuse reverse engineers
372
+ * understanding your code.
373
+ */
374
+ opaquePredicates?: ProbabilityMap<boolean>;
375
+
376
+ /**
377
+ * Shuffles the initial order of arrays. The order is brought back to the original during runtime. (`"hash"/true/false/0-1`)
378
+ */
379
+ shuffle?: ProbabilityMap<boolean>;
380
+
381
+ /**
382
+ * Modified functions will retain the correct `function.length` property. Enabled by default.
383
+ */
384
+ preserveFunctionLength?: boolean;
385
+
386
+ /**
387
+ * Semantically changes the AST to bypass automated tools.
388
+ */
389
+ astScrambler?: boolean;
390
+
391
+ /**
392
+ * Packs the output code into a single `Function()` call.
393
+ *
394
+ * Designed to escape strict mode constraints.
395
+ */
396
+ pack?: ProbabilityMap<boolean, (globalName: string) => boolean>;
397
+
398
+ /**
399
+ * Set of global variables. *Optional*.
400
+ */
401
+ globalVariables?: Set<string>;
402
+
403
+ /**
404
+ * Enable logs to view the obfuscator's state.
405
+ */
406
+ verbose?: boolean;
407
+ }