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.
- package/.github/ISSUE_TEMPLATE/bug_report.md +6 -4
- package/CHANGELOG.md +70 -0
- package/Migration.md +57 -0
- package/README.md +23 -929
- package/dist/constants.js +65 -14
- package/dist/index.js +108 -160
- package/dist/obfuscator.js +316 -118
- package/dist/options.js +1 -119
- package/dist/order.js +30 -30
- package/dist/presets.js +47 -45
- package/dist/probability.js +25 -32
- package/dist/templates/bufferToStringTemplate.js +9 -0
- package/dist/templates/deadCodeTemplates.js +9 -0
- package/dist/templates/getGlobalTemplate.js +19 -0
- package/dist/templates/integrityTemplate.js +30 -0
- package/dist/templates/setFunctionLengthTemplate.js +9 -0
- package/dist/templates/stringCompressionTemplate.js +10 -0
- package/dist/templates/tamperProtectionTemplates.js +21 -0
- package/dist/templates/template.js +199 -184
- package/dist/transforms/astScrambler.js +100 -0
- package/dist/transforms/calculator.js +70 -127
- package/dist/transforms/controlFlowFlattening.js +1182 -0
- package/dist/transforms/deadCode.js +62 -587
- package/dist/transforms/dispatcher.js +300 -313
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +88 -189
- package/dist/transforms/extraction/objectExtraction.js +131 -215
- package/dist/transforms/finalizer.js +56 -59
- package/dist/transforms/flatten.js +275 -276
- package/dist/transforms/functionOutlining.js +230 -0
- package/dist/transforms/identifier/globalConcealing.js +214 -135
- package/dist/transforms/identifier/movedDeclarations.js +167 -91
- package/dist/transforms/identifier/renameVariables.js +239 -193
- package/dist/transforms/lock/integrity.js +61 -184
- package/dist/transforms/lock/lock.js +261 -387
- package/dist/transforms/minify.js +431 -436
- package/dist/transforms/opaquePredicates.js +65 -118
- package/dist/transforms/pack.js +160 -0
- package/dist/transforms/plugin.js +179 -0
- package/dist/transforms/preparation.js +261 -173
- package/dist/transforms/renameLabels.js +132 -56
- package/dist/transforms/rgf.js +140 -267
- package/dist/transforms/shuffle.js +52 -145
- package/dist/transforms/string/encoding.js +44 -175
- package/dist/transforms/string/stringCompression.js +79 -155
- package/dist/transforms/string/stringConcealing.js +189 -225
- package/dist/transforms/string/stringEncoding.js +32 -40
- package/dist/transforms/string/stringSplitting.js +54 -55
- package/dist/transforms/variableMasking.js +232 -0
- package/dist/utils/ControlObject.js +125 -0
- package/dist/utils/IntGen.js +46 -0
- package/dist/utils/NameGen.js +106 -0
- package/dist/utils/ast-utils.js +560 -0
- package/dist/utils/function-utils.js +56 -0
- package/dist/utils/gen-utils.js +48 -0
- package/dist/utils/node.js +77 -0
- package/dist/utils/object-utils.js +21 -0
- package/dist/utils/random-utils.js +91 -0
- package/dist/utils/static-utils.js +64 -0
- package/dist/validateOptions.js +122 -0
- package/index.d.ts +1 -17
- package/package.json +27 -22
- package/src/constants.ts +139 -82
- package/src/index.ts +70 -165
- package/src/obfuscationResult.ts +43 -0
- package/src/obfuscator.ts +328 -135
- package/src/options.ts +149 -658
- package/src/order.ts +14 -14
- package/src/presets.ts +39 -34
- package/src/probability.ts +21 -36
- package/src/templates/bufferToStringTemplate.ts +57 -0
- package/src/templates/deadCodeTemplates.ts +1185 -0
- package/src/templates/getGlobalTemplate.ts +72 -0
- package/src/templates/integrityTemplate.ts +69 -0
- package/src/templates/setFunctionLengthTemplate.ts +11 -0
- package/src/templates/stringCompressionTemplate.ts +42 -0
- package/src/templates/tamperProtectionTemplates.ts +116 -0
- package/src/templates/template.ts +149 -157
- package/src/transforms/astScrambler.ts +99 -0
- package/src/transforms/calculator.ts +96 -226
- package/src/transforms/controlFlowFlattening.ts +1594 -0
- package/src/transforms/deadCode.ts +85 -676
- package/src/transforms/dispatcher.ts +431 -640
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +147 -295
- package/src/transforms/extraction/objectExtraction.ts +160 -333
- package/src/transforms/finalizer.ts +63 -64
- package/src/transforms/flatten.ts +439 -557
- package/src/transforms/functionOutlining.ts +225 -0
- package/src/transforms/identifier/globalConcealing.ts +255 -266
- package/src/transforms/identifier/movedDeclarations.ts +228 -142
- package/src/transforms/identifier/renameVariables.ts +250 -271
- package/src/transforms/lock/integrity.ts +85 -263
- package/src/transforms/lock/lock.ts +338 -579
- package/src/transforms/minify.ts +523 -663
- package/src/transforms/opaquePredicates.ts +90 -229
- package/src/transforms/pack.ts +195 -0
- package/src/transforms/plugin.ts +185 -0
- package/src/transforms/preparation.ts +337 -231
- package/src/transforms/renameLabels.ts +176 -77
- package/src/transforms/rgf.ts +293 -424
- package/src/transforms/shuffle.ts +80 -254
- package/src/transforms/string/encoding.ts +20 -126
- package/src/transforms/string/stringCompression.ts +117 -307
- package/src/transforms/string/stringConcealing.ts +254 -342
- package/src/transforms/string/stringEncoding.ts +28 -47
- package/src/transforms/string/stringSplitting.ts +61 -75
- package/src/transforms/variableMasking.ts +257 -0
- package/src/utils/ControlObject.ts +141 -0
- package/src/utils/IntGen.ts +33 -0
- package/src/utils/NameGen.ts +106 -0
- package/src/utils/ast-utils.ts +667 -0
- package/src/utils/function-utils.ts +50 -0
- package/src/utils/gen-utils.ts +48 -0
- package/src/utils/node.ts +78 -0
- package/src/utils/object-utils.ts +21 -0
- package/src/utils/random-utils.ts +79 -0
- package/src/utils/static-utils.ts +66 -0
- package/src/validateOptions.ts +256 -0
- package/tsconfig.json +13 -8
- package/babel.config.js +0 -12
- package/dev.js +0 -8
- package/dist/compiler.js +0 -34
- package/dist/parser.js +0 -59
- package/dist/precedence.js +0 -66
- package/dist/templates/bufferToString.js +0 -129
- package/dist/templates/core.js +0 -35
- package/dist/templates/crash.js +0 -28
- package/dist/templates/es5.js +0 -137
- package/dist/templates/functionLength.js +0 -34
- package/dist/templates/globals.js +0 -9
- package/dist/transforms/antiTooling.js +0 -88
- package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +0 -1287
- package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +0 -131
- package/dist/transforms/es5/antiClass.js +0 -164
- package/dist/transforms/es5/antiDestructuring.js +0 -193
- package/dist/transforms/es5/antiES6Object.js +0 -185
- package/dist/transforms/es5/antiSpreadOperator.js +0 -35
- package/dist/transforms/es5/antiTemplate.js +0 -66
- package/dist/transforms/es5/es5.js +0 -123
- package/dist/transforms/extraction/classExtraction.js +0 -83
- package/dist/transforms/identifier/globalAnalysis.js +0 -83
- package/dist/transforms/identifier/variableAnalysis.js +0 -104
- package/dist/transforms/lock/antiDebug.js +0 -76
- package/dist/transforms/stack.js +0 -349
- package/dist/transforms/transform.js +0 -372
- package/dist/traverse.js +0 -110
- package/dist/util/compare.js +0 -145
- package/dist/util/gen.js +0 -564
- package/dist/util/guard.js +0 -14
- package/dist/util/identifiers.js +0 -355
- package/dist/util/insert.js +0 -362
- package/dist/util/math.js +0 -19
- package/dist/util/object.js +0 -40
- package/dist/util/random.js +0 -156
- package/dist/util/scope.js +0 -20
- package/docs/ControlFlowFlattening.md +0 -595
- package/docs/Countermeasures.md +0 -70
- package/docs/ES5.md +0 -197
- package/docs/Integrity.md +0 -82
- package/docs/RGF.md +0 -424
- package/docs/RenameVariables.md +0 -116
- package/docs/TamperProtection.md +0 -100
- package/docs/Template.md +0 -117
- package/samples/example.js +0 -15
- package/samples/high.js +0 -1
- package/samples/input.js +0 -3
- package/samples/javascriptobfuscator.com.js +0 -8
- package/samples/jscrambler_advanced.js +0 -1894
- package/samples/jscrambler_light.js +0 -1134
- package/samples/low.js +0 -1
- package/samples/medium.js +0 -1
- package/samples/obfuscator.io.js +0 -1686
- package/samples/preemptive.com.js +0 -16
- package/src/compiler.ts +0 -35
- package/src/parser.ts +0 -49
- package/src/precedence.ts +0 -61
- package/src/templates/bufferToString.ts +0 -136
- package/src/templates/core.ts +0 -29
- package/src/templates/crash.ts +0 -23
- package/src/templates/es5.ts +0 -131
- package/src/templates/functionLength.ts +0 -32
- package/src/templates/globals.ts +0 -3
- package/src/transforms/antiTooling.ts +0 -102
- package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +0 -2153
- package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +0 -179
- package/src/transforms/es5/antiClass.ts +0 -276
- package/src/transforms/es5/antiDestructuring.ts +0 -294
- package/src/transforms/es5/antiES6Object.ts +0 -267
- package/src/transforms/es5/antiSpreadOperator.ts +0 -56
- package/src/transforms/es5/antiTemplate.ts +0 -98
- package/src/transforms/es5/es5.ts +0 -149
- package/src/transforms/extraction/classExtraction.ts +0 -168
- package/src/transforms/identifier/globalAnalysis.ts +0 -102
- package/src/transforms/identifier/variableAnalysis.ts +0 -118
- package/src/transforms/lock/antiDebug.ts +0 -112
- package/src/transforms/stack.ts +0 -557
- package/src/transforms/transform.ts +0 -441
- package/src/traverse.ts +0 -120
- package/src/types.ts +0 -133
- package/src/util/compare.ts +0 -181
- package/src/util/gen.ts +0 -651
- package/src/util/guard.ts +0 -17
- package/src/util/identifiers.ts +0 -494
- package/src/util/insert.ts +0 -419
- package/src/util/math.ts +0 -15
- package/src/util/object.ts +0 -39
- package/src/util/random.ts +0 -221
- package/src/util/scope.ts +0 -21
- package/test/code/Cash.src.js +0 -1011
- package/test/code/Cash.test.ts +0 -132
- package/test/code/Dynamic.src.js +0 -118
- package/test/code/Dynamic.test.ts +0 -49
- package/test/code/ES6.src.js +0 -235
- package/test/code/ES6.test.ts +0 -42
- package/test/code/NewFeatures.test.ts +0 -19
- package/test/code/StrictMode.src.js +0 -65
- package/test/code/StrictMode.test.js +0 -37
- package/test/compare.test.ts +0 -104
- package/test/index.test.ts +0 -249
- package/test/options.test.ts +0 -150
- package/test/presets.test.ts +0 -22
- package/test/probability.test.ts +0 -44
- package/test/templates/template.test.ts +0 -224
- package/test/transforms/antiTooling.test.ts +0 -52
- package/test/transforms/calculator.test.ts +0 -78
- package/test/transforms/controlFlowFlattening/controlFlowFlattening.test.ts +0 -1274
- package/test/transforms/controlFlowFlattening/expressionObfuscation.test.ts +0 -192
- package/test/transforms/deadCode.test.ts +0 -85
- package/test/transforms/dispatcher.test.ts +0 -457
- package/test/transforms/es5/antiClass.test.ts +0 -427
- package/test/transforms/es5/antiDestructuring.test.ts +0 -157
- package/test/transforms/es5/antiES6Object.test.ts +0 -245
- package/test/transforms/es5/antiTemplate.test.ts +0 -116
- package/test/transforms/es5/es5.test.ts +0 -110
- package/test/transforms/extraction/classExtraction.test.ts +0 -86
- package/test/transforms/extraction/duplicateLiteralsRemoval.test.ts +0 -200
- package/test/transforms/extraction/objectExtraction.test.ts +0 -491
- package/test/transforms/flatten.test.ts +0 -721
- package/test/transforms/hexadecimalNumbers.test.ts +0 -62
- package/test/transforms/identifier/globalConcealing.test.ts +0 -142
- package/test/transforms/identifier/movedDeclarations.test.ts +0 -275
- package/test/transforms/identifier/renameVariables.test.ts +0 -695
- package/test/transforms/lock/antiDebug.test.ts +0 -66
- package/test/transforms/lock/browserLock.test.ts +0 -129
- package/test/transforms/lock/countermeasures.test.ts +0 -100
- package/test/transforms/lock/integrity.test.ts +0 -161
- package/test/transforms/lock/lock.test.ts +0 -204
- package/test/transforms/lock/osLock.test.ts +0 -312
- package/test/transforms/lock/selfDefending.test.ts +0 -68
- package/test/transforms/lock/tamperProtection.test.ts +0 -336
- package/test/transforms/minify.test.ts +0 -575
- package/test/transforms/opaquePredicates.test.ts +0 -43
- package/test/transforms/preparation.test.ts +0 -157
- package/test/transforms/renameLabels.test.ts +0 -95
- package/test/transforms/rgf.test.ts +0 -378
- package/test/transforms/shuffle.test.ts +0 -135
- package/test/transforms/stack.test.ts +0 -573
- package/test/transforms/string/stringCompression.test.ts +0 -120
- package/test/transforms/string/stringConcealing.test.ts +0 -299
- package/test/transforms/string/stringEncoding.test.ts +0 -95
- package/test/transforms/string/stringSplitting.test.ts +0 -135
- package/test/transforms/transform.test.ts +0 -66
- package/test/traverse.test.ts +0 -139
- package/test/util/compare.test.ts +0 -34
- package/test/util/gen.test.ts +0 -121
- package/test/util/identifiers.test.ts +0 -253
- package/test/util/insert.test.ts +0 -142
- package/test/util/math.test.ts +0 -5
- package/test/util/random.test.ts +0 -71
- /package/dist/{types.js → obfuscationResult.js} +0 -0
package/src/options.ts
CHANGED
|
@@ -1,264 +1,200 @@
|
|
|
1
|
-
import
|
|
2
|
-
import presets from "./presets";
|
|
3
|
-
import { ProbabilityMap } from "./probability";
|
|
1
|
+
import Template from "./templates/template";
|
|
4
2
|
|
|
5
|
-
|
|
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) | "true" | "false";
|
|
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,
|
|
20
|
+
F extends (...args: any[]) => any = () => boolean // Default to a generic function
|
|
21
|
+
> = false | true | number | T | T[] | { [key in Stringed<T>]?: number } | F;
|
|
22
|
+
|
|
23
|
+
export interface CustomLock {
|
|
6
24
|
/**
|
|
7
|
-
*
|
|
25
|
+
* Template lock code that must contain:
|
|
8
26
|
*
|
|
9
|
-
*
|
|
27
|
+
* - `{countermeasures}`
|
|
10
28
|
*
|
|
11
|
-
*
|
|
12
|
-
* | --- | --- | --- | --- |
|
|
13
|
-
* | High | 22/25 | 98% | [Sample](https://github.com/MichaelXF/js-confuser/blob/master/samples/high.js) |
|
|
14
|
-
* | Medium | 19/25 | 52% | [Sample](https://github.com/MichaelXF/js-confuser/blob/master/samples/medium.js) |
|
|
15
|
-
* | Low | 15/25 | 30% | [Sample](https://github.com/MichaelXF/js-confuser/blob/master/samples/low.js) |
|
|
29
|
+
* The countermeasures function will be invoked when the lock is triggered.
|
|
16
30
|
*
|
|
17
|
-
*
|
|
31
|
+
* ```js
|
|
32
|
+
* if(window.navigator.userAgent.includes('Chrome')){
|
|
33
|
+
* {countermeasures}
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
18
36
|
*
|
|
19
|
-
*
|
|
37
|
+
* Multiple templates can be passed a string array, a random one will be chosen each time.
|
|
20
38
|
*/
|
|
21
|
-
|
|
39
|
+
code: string | string[] | Template;
|
|
40
|
+
percentagePerBlock: number;
|
|
41
|
+
maxCount?: number;
|
|
42
|
+
minCount?: number;
|
|
43
|
+
}
|
|
22
44
|
|
|
45
|
+
export interface CustomStringEncoding {
|
|
23
46
|
/**
|
|
24
|
-
*
|
|
47
|
+
* Template string decoder that must contain:
|
|
25
48
|
*
|
|
26
|
-
*
|
|
49
|
+
* - `{fnName}`
|
|
27
50
|
*
|
|
28
|
-
*
|
|
29
|
-
* 2. `"browser"`
|
|
51
|
+
* This function will be invoked by the obfuscated code to DECODE the string.
|
|
30
52
|
*
|
|
31
|
-
*
|
|
53
|
+
* ```js
|
|
54
|
+
* function {fnName}(str){
|
|
55
|
+
* return Buffer.from(str, 'base64').toString('utf-8')
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
32
58
|
*/
|
|
33
|
-
|
|
59
|
+
code?: string | Template;
|
|
60
|
+
encode: (str: string) => string;
|
|
34
61
|
|
|
35
62
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
63
|
+
* Optional. A decoder function can be provided to ensure the string is able to decode properly.
|
|
64
|
+
* @param str
|
|
65
|
+
* @returns
|
|
41
66
|
*/
|
|
42
|
-
|
|
67
|
+
decode?: (str: string) => string;
|
|
43
68
|
|
|
44
69
|
/**
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
70
|
+
* Should be used when created 'shuffled' variants of the same encoding.
|
|
71
|
+
*/
|
|
72
|
+
identity?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ObfuscateOptions {
|
|
76
|
+
/**
|
|
77
|
+
* The preset to use for obfuscation.
|
|
78
|
+
*/
|
|
79
|
+
preset?: "high" | "medium" | "low" | false;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The execution context for your output. _Required_.
|
|
48
83
|
*
|
|
49
|
-
*
|
|
84
|
+
* 1. `"node"`
|
|
85
|
+
* 2. `"browser"`
|
|
86
|
+
*/
|
|
87
|
+
target: "node" | "browser";
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Remove's whitespace from the final output.
|
|
50
91
|
*/
|
|
51
92
|
compact?: boolean;
|
|
52
93
|
|
|
53
94
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* Uses the hexadecimal representation for numbers. (`true/false`)
|
|
95
|
+
* Uses the hexadecimal representation for numbers.
|
|
57
96
|
*/
|
|
58
97
|
hexadecimalNumbers?: boolean;
|
|
59
98
|
|
|
60
99
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* Minifies redundant code. (`true/false`)
|
|
64
|
-
*
|
|
65
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
100
|
+
* Minifies redundant code.
|
|
66
101
|
*/
|
|
67
102
|
minify?: boolean;
|
|
68
103
|
|
|
69
104
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* Converts output to ES5-compatible code. (`true/false`)
|
|
73
|
-
*
|
|
74
|
-
* Does not cover all cases such as Promises or Generator functions. Use [Babel](https://babel.dev/).
|
|
75
|
-
*
|
|
76
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
105
|
+
* Renames labeled statements. Enabled by default.
|
|
77
106
|
*/
|
|
78
|
-
|
|
107
|
+
renameLabels?: ProbabilityMap<boolean, (labelName: string) => boolean>;
|
|
79
108
|
|
|
80
109
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* Determines if variables should be renamed. (`true/false`)
|
|
84
|
-
* - Potency High
|
|
85
|
-
* - Resilience High
|
|
86
|
-
* - Cost Medium
|
|
87
|
-
*
|
|
88
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
110
|
+
* Determines if variables should be renamed.
|
|
89
111
|
*/
|
|
90
|
-
renameVariables?: ProbabilityMap<
|
|
112
|
+
renameVariables?: ProbabilityMap<
|
|
113
|
+
boolean,
|
|
114
|
+
(variableName: string, topLevel: boolean) => boolean
|
|
115
|
+
>;
|
|
91
116
|
|
|
92
117
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* Renames top-level variables, turn this off for web-related scripts. Enabled by default. (`true/false`)
|
|
96
|
-
*
|
|
97
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
118
|
+
* Renames top-level variables, turn this off for web-related scripts. Enabled by default.
|
|
98
119
|
*/
|
|
99
|
-
renameGlobals?: ProbabilityMap<boolean>;
|
|
120
|
+
renameGlobals?: ProbabilityMap<boolean, (variableName: string) => boolean>;
|
|
100
121
|
|
|
101
122
|
/**
|
|
102
|
-
* ### `identifierGenerator`
|
|
103
|
-
*
|
|
104
123
|
* Determines how variables are renamed.
|
|
105
124
|
*
|
|
106
|
-
*
|
|
107
|
-
* | --- | --- | --- |
|
|
108
|
-
* | `"hexadecimal"` | Random hex strings | \_0xa8db5 |
|
|
109
|
-
* | `"randomized"` | Random characters | w$Tsu4G |
|
|
110
|
-
* | `"zeroWidth"` | Invisible characters | U+200D |
|
|
111
|
-
* | `"mangled"` | Alphabet sequence | a, b, c |
|
|
112
|
-
* | `"number"` | Numbered sequence | var_1, var_2 |
|
|
113
|
-
* | `<function>` | Write a custom name generator | See Below |
|
|
114
|
-
*
|
|
115
|
-
* ```js
|
|
116
|
-
* // Custom implementation
|
|
117
|
-
* JsConfuser.obfuscate(code, {
|
|
118
|
-
* target: "node",
|
|
119
|
-
* renameVariables: true,
|
|
120
|
-
* identifierGenerator: function () {
|
|
121
|
-
* return "$" + Math.random().toString(36).substring(7);
|
|
122
|
-
* },
|
|
123
|
-
* });
|
|
124
|
-
*
|
|
125
|
-
* // Numbered variables
|
|
126
|
-
* var counter = 0;
|
|
127
|
-
* JsConfuser.obfuscate(code, {
|
|
128
|
-
* target: "node",
|
|
129
|
-
* renameVariables: true,
|
|
130
|
-
* identifierGenerator: function () {
|
|
131
|
-
* return "var_" + (counter++);
|
|
132
|
-
* },
|
|
133
|
-
* });
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
* JSConfuser tries to reuse names when possible, creating very potent code.
|
|
137
|
-
*
|
|
138
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
125
|
+
* JS-Confuser tries to reuse names when possible, creating very potent code.
|
|
139
126
|
*/
|
|
140
127
|
identifierGenerator?: ProbabilityMap<
|
|
141
|
-
"hexadecimal" | "randomized" | "zeroWidth" | "mangled" | "number"
|
|
128
|
+
"hexadecimal" | "randomized" | "zeroWidth" | "mangled" | "number",
|
|
129
|
+
() => string
|
|
142
130
|
>;
|
|
143
131
|
|
|
144
132
|
/**
|
|
145
|
-
* ### `controlFlowFlattening`
|
|
146
|
-
*
|
|
147
133
|
* ⚠️ Significantly impacts performance, use sparingly!
|
|
148
134
|
*
|
|
149
|
-
* Control-flow Flattening hinders program comprehension by creating convoluted switch statements.
|
|
135
|
+
* Control-flow Flattening hinders program comprehension by creating convoluted switch statements.
|
|
150
136
|
*
|
|
151
137
|
* Use a number to control the percentage from 0 to 1.
|
|
152
|
-
*
|
|
153
|
-
* - Potency High
|
|
154
|
-
* - Resilience High
|
|
155
|
-
* - Cost High
|
|
156
|
-
*
|
|
157
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
158
138
|
*/
|
|
159
139
|
controlFlowFlattening?: ProbabilityMap<boolean>;
|
|
160
140
|
|
|
161
141
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* Global Concealing hides global variables being accessed. (`true/false`)
|
|
165
|
-
*
|
|
166
|
-
* - Potency Medium
|
|
167
|
-
* - Resilience High
|
|
168
|
-
* - Cost Low
|
|
169
|
-
*
|
|
170
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
142
|
+
* Global Concealing hides global variables being accessed.
|
|
171
143
|
*/
|
|
172
|
-
globalConcealing?: ProbabilityMap<boolean>;
|
|
144
|
+
globalConcealing?: ProbabilityMap<boolean, (globalName: string) => boolean>;
|
|
173
145
|
|
|
174
146
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* String Compression uses LZW's compression algorithm to compress strings. (`true/false/0-1`)
|
|
147
|
+
* String Compression uses LZW's compression algorithm to compress strings.
|
|
178
148
|
*
|
|
179
149
|
* `"console"` -> `inflate('replaĕ!ğğuģģ<~@')`
|
|
180
|
-
*
|
|
181
|
-
* - Potency High
|
|
182
|
-
* - Resilience Medium
|
|
183
|
-
* - Cost Medium
|
|
184
150
|
*/
|
|
185
|
-
stringCompression?: ProbabilityMap<boolean>;
|
|
151
|
+
stringCompression?: ProbabilityMap<boolean, (strValue: string) => boolean>;
|
|
186
152
|
|
|
187
153
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* String Concealing involves encoding strings to conceal plain-text values. (`true/false/0-1`)
|
|
154
|
+
* String Concealing involves encoding strings to conceal plain-text values.
|
|
191
155
|
*
|
|
192
156
|
* `"console"` -> `decrypt('<~@rH7+Dert~>')`
|
|
193
|
-
*
|
|
194
|
-
* - Potency High
|
|
195
|
-
* - Resilience Medium
|
|
196
|
-
* - Cost Medium
|
|
197
157
|
*/
|
|
198
|
-
stringConcealing?: ProbabilityMap<boolean>;
|
|
158
|
+
stringConcealing?: ProbabilityMap<boolean, (strValue: string) => boolean>;
|
|
199
159
|
|
|
200
160
|
/**
|
|
201
|
-
*
|
|
202
|
-
|
|
203
|
-
|
|
161
|
+
* Custom String Encodings allows you to define your own string encoding/decoding functions.
|
|
162
|
+
*/
|
|
163
|
+
customStringEncodings?: (
|
|
164
|
+
| CustomStringEncoding
|
|
165
|
+
| ((encodingImplementations: {
|
|
166
|
+
[identity: string]: CustomStringEncoding;
|
|
167
|
+
}) => CustomStringEncoding | null)
|
|
168
|
+
)[];
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* String Encoding transforms a string into an escaped unicode representation.
|
|
204
172
|
*
|
|
205
173
|
* `"console"` -> `'\x63\x6f\x6e\x73\x6f\x6c\x65'`
|
|
206
|
-
*
|
|
207
|
-
* - Potency Low
|
|
208
|
-
* - Resilience Low
|
|
209
|
-
* - Cost Low
|
|
210
|
-
*
|
|
211
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
212
174
|
*/
|
|
213
|
-
stringEncoding?: ProbabilityMap<boolean>;
|
|
175
|
+
stringEncoding?: ProbabilityMap<boolean, (strValue: string) => boolean>;
|
|
214
176
|
|
|
215
177
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* String Splitting splits your strings into multiple expressions. (`true/false/0-1`)
|
|
178
|
+
* String Splitting splits your strings into multiple expressions.
|
|
219
179
|
*
|
|
220
180
|
* `"console"` -> `String.fromCharCode(99) + 'ons' + 'ole'`
|
|
221
|
-
*
|
|
222
|
-
* - Potency Medium
|
|
223
|
-
* - Resilience Medium
|
|
224
|
-
* - Cost Medium
|
|
225
|
-
*
|
|
226
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
227
181
|
*/
|
|
228
|
-
stringSplitting?: ProbabilityMap<boolean>;
|
|
182
|
+
stringSplitting?: ProbabilityMap<boolean, (strValue: string) => boolean>;
|
|
229
183
|
|
|
230
184
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* Duplicate Literals Removal replaces duplicate literals with a single variable name. (`true/false`)
|
|
234
|
-
*
|
|
235
|
-
* - Potency Medium
|
|
236
|
-
* - Resilience Low
|
|
237
|
-
* - Cost High
|
|
238
|
-
*
|
|
239
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
185
|
+
* Duplicate Literals Removal replaces duplicate literals with a single variable name.
|
|
240
186
|
*/
|
|
241
187
|
duplicateLiteralsRemoval?: ProbabilityMap<boolean>;
|
|
242
188
|
|
|
243
189
|
/**
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
* Creates a middleman function to process function calls. (`true/false/0-1`)
|
|
247
|
-
*
|
|
248
|
-
* - Potency Medium
|
|
249
|
-
* - Resilience Medium
|
|
250
|
-
* - Cost High
|
|
251
|
-
*
|
|
252
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
190
|
+
* Creates a middleman function to process function calls.
|
|
253
191
|
*/
|
|
254
|
-
dispatcher?: ProbabilityMap<boolean>;
|
|
192
|
+
dispatcher?: ProbabilityMap<boolean, (fnName: string) => boolean>;
|
|
255
193
|
|
|
256
194
|
/**
|
|
257
|
-
*
|
|
195
|
+
* 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.
|
|
258
196
|
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* - **This can break your code.
|
|
197
|
+
* - **This can break your code.**
|
|
262
198
|
* - **Due to the security concerns of arbitrary code execution, you must enable this yourself.**
|
|
263
199
|
* - The arbitrary code is also obfuscated.
|
|
264
200
|
*
|
|
@@ -274,21 +210,14 @@ export interface ObfuscateOptions {
|
|
|
274
210
|
* 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'))
|
|
275
211
|
* ```
|
|
276
212
|
*
|
|
277
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
278
213
|
*/
|
|
279
|
-
rgf?: ProbabilityMap<boolean>;
|
|
214
|
+
rgf?: ProbabilityMap<boolean, (fnName: string, isGlobal: boolean) => boolean>;
|
|
280
215
|
|
|
281
216
|
/**
|
|
282
|
-
* ### `stack`
|
|
283
|
-
*
|
|
284
217
|
* Local variables are consolidated into a rotating array.
|
|
285
218
|
*
|
|
286
219
|
* [Similar to Jscrambler's Variable Masking](https://docs.jscrambler.com/code-integrity/documentation/transformations/variable-masking)
|
|
287
220
|
*
|
|
288
|
-
* - Potency Medium
|
|
289
|
-
* - Resilience Medium
|
|
290
|
-
* - Cost Low
|
|
291
|
-
*
|
|
292
221
|
* ```js
|
|
293
222
|
* // Input
|
|
294
223
|
* function add3(x, y, z){
|
|
@@ -302,16 +231,10 @@ export interface ObfuscateOptions {
|
|
|
302
231
|
* };
|
|
303
232
|
* ```
|
|
304
233
|
*/
|
|
305
|
-
|
|
234
|
+
variableMasking?: ProbabilityMap<boolean, (fnName: string) => boolean>;
|
|
306
235
|
|
|
307
236
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* Extracts object properties into separate variables. (`true/false`)
|
|
311
|
-
*
|
|
312
|
-
* - Potency Medium
|
|
313
|
-
* - Resilience Medium
|
|
314
|
-
* - Cost Low
|
|
237
|
+
* Extracts object properties into separate variables.
|
|
315
238
|
*
|
|
316
239
|
* ```js
|
|
317
240
|
* // Input
|
|
@@ -330,569 +253,137 @@ export interface ObfuscateOptions {
|
|
|
330
253
|
* // ...
|
|
331
254
|
* }
|
|
332
255
|
* ```
|
|
333
|
-
*
|
|
334
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
335
256
|
*/
|
|
336
|
-
objectExtraction?: ProbabilityMap<boolean>;
|
|
257
|
+
objectExtraction?: ProbabilityMap<boolean, (objectName: string) => boolean>;
|
|
337
258
|
|
|
338
259
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* Brings independent declarations to the highest scope. (`true/false`)
|
|
342
|
-
*
|
|
343
|
-
* - Potency Medium
|
|
344
|
-
* - Resilience Medium
|
|
345
|
-
* - Cost High
|
|
346
|
-
*
|
|
347
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
260
|
+
* Declares functions at the top of the program, preserving their original scope.
|
|
348
261
|
*/
|
|
349
|
-
flatten?: ProbabilityMap<boolean>;
|
|
262
|
+
flatten?: ProbabilityMap<boolean, (fnName: string) => boolean>;
|
|
350
263
|
|
|
351
264
|
/**
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* Randomly injects dead code. (`true/false/0-1`)
|
|
265
|
+
* Randomly injects dead code.
|
|
355
266
|
*
|
|
356
267
|
* Use a number to control the percentage from 0 to 1.
|
|
357
|
-
*
|
|
358
|
-
* - Potency Medium
|
|
359
|
-
* - Resilience Medium
|
|
360
|
-
* - Cost Low
|
|
361
|
-
*
|
|
362
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
363
268
|
*/
|
|
364
269
|
deadCode?: ProbabilityMap<boolean>;
|
|
365
270
|
|
|
366
271
|
/**
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
* Creates a calculator function to handle arithmetic and logical expressions. (`true/false/0-1`)
|
|
272
|
+
* Creates a calculator function to handle arithmetic and logical expressions.
|
|
370
273
|
*
|
|
371
|
-
* - Potency Medium
|
|
372
|
-
* - Resilience Medium
|
|
373
|
-
* - Cost Low
|
|
374
|
-
*
|
|
375
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
376
274
|
*/
|
|
377
275
|
calculator?: ProbabilityMap<boolean>;
|
|
378
276
|
|
|
379
277
|
lock?: {
|
|
380
278
|
/**
|
|
381
|
-
* ### `lock.selfDefending`
|
|
382
|
-
*
|
|
383
279
|
* Prevents the use of code beautifiers or formatters against your code.
|
|
384
280
|
*
|
|
385
281
|
* [Identical to Obfuscator.io's Self Defending](https://github.com/javascript-obfuscator/javascript-obfuscator#selfdefending)
|
|
386
282
|
*
|
|
387
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
388
283
|
*/
|
|
389
284
|
selfDefending?: boolean;
|
|
390
285
|
|
|
391
286
|
/**
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
* Adds `debugger` statements throughout the code. Additionally adds a background function for DevTools detection. (`true/false/0-1`)
|
|
395
|
-
*
|
|
396
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
287
|
+
* Adds `debugger` statements throughout the code.
|
|
397
288
|
*/
|
|
398
289
|
antiDebug?: ProbabilityMap<boolean>;
|
|
399
290
|
|
|
400
291
|
/**
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
* Properties that must be present on the `window` object (or `global` for NodeJS). (`string[]`)
|
|
404
|
-
*
|
|
405
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
406
|
-
*/
|
|
407
|
-
context?: string[];
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* ### `lock.tamperProtection`
|
|
411
|
-
*
|
|
412
|
-
* Tamper Protection safeguards the runtime behavior from being altered by JavaScript pitfalls. (`true/false`)
|
|
292
|
+
* Tamper Protection safeguards the runtime behavior from being altered by JavaScript pitfalls.
|
|
413
293
|
*
|
|
414
294
|
* **⚠️ Tamper Protection requires eval and ran in a non-strict mode environment!**
|
|
415
295
|
*
|
|
416
296
|
* - **This can break your code.**
|
|
417
297
|
* - **Due to the security concerns of arbitrary code execution, you must enable this yourself.**
|
|
418
298
|
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
299
|
+
* @see https://github.com/MichaelXF/js-confuser/blob/master/TamperProtection.md
|
|
422
300
|
*/
|
|
423
301
|
tamperProtection?: boolean | ((varName: string) => boolean);
|
|
424
302
|
|
|
425
303
|
/**
|
|
426
|
-
* ### `lock.startDate`
|
|
427
|
-
*
|
|
428
304
|
* When the program is first able to be used. (`number` or `Date`)
|
|
429
305
|
*
|
|
430
306
|
* Number should be in milliseconds.
|
|
431
|
-
*
|
|
432
|
-
* - Potency Low
|
|
433
|
-
* - Resilience Medium
|
|
434
|
-
* - Cost Medium
|
|
435
|
-
*
|
|
436
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
437
307
|
*/
|
|
438
308
|
startDate?: number | Date | false;
|
|
439
309
|
|
|
440
310
|
/**
|
|
441
|
-
* ### `lock.endDate`
|
|
442
|
-
*
|
|
443
311
|
* When the program is no longer able to be used. (`number` or `Date`)
|
|
444
312
|
*
|
|
445
313
|
* Number should be in milliseconds.
|
|
446
|
-
*
|
|
447
|
-
* - Potency Low
|
|
448
|
-
* - Resilience Medium
|
|
449
|
-
* - Cost Medium
|
|
450
|
-
*
|
|
451
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
452
314
|
*/
|
|
453
315
|
endDate?: number | Date | false;
|
|
454
316
|
|
|
455
317
|
/**
|
|
456
|
-
*
|
|
457
|
-
* Array of regex strings that the `window.location.href` must follow. (`Regex[]` or `string[]`)
|
|
458
|
-
*
|
|
459
|
-
* - Potency Low
|
|
460
|
-
* - Resilience Medium
|
|
461
|
-
* - Cost Medium
|
|
462
|
-
*
|
|
463
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
318
|
+
* Array of regex strings that the `window.location.href` must follow.
|
|
464
319
|
*/
|
|
465
320
|
domainLock?: RegExp[] | string[] | false;
|
|
466
321
|
|
|
467
322
|
/**
|
|
468
|
-
*
|
|
469
|
-
* Array of operating-systems where the script is allowed to run. (`string[]`)
|
|
470
|
-
*
|
|
471
|
-
* - Potency Low
|
|
472
|
-
* - Resilience Medium
|
|
473
|
-
* - Cost Medium
|
|
474
|
-
*
|
|
475
|
-
* Allowed values: `"linux"`, `"windows"`, `"osx"`, `"android"`, `"ios"`
|
|
476
|
-
*
|
|
477
|
-
* Example: `["linux", "windows"]`
|
|
478
|
-
*
|
|
479
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
480
|
-
*/
|
|
481
|
-
osLock?: ("linux" | "windows" | "osx" | "android" | "ios")[] | false;
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* ### `lock.browserLock`
|
|
485
|
-
* Array of browsers where the script is allowed to run. (`string[]`)
|
|
486
|
-
*
|
|
487
|
-
* - Potency Low
|
|
488
|
-
* - Resilience Medium
|
|
489
|
-
* - Cost Medium
|
|
490
|
-
*
|
|
491
|
-
* Allowed values: `"firefox"`, `"chrome"`, `"iexplorer"`, `"edge"`, `"safari"`, `"opera"`
|
|
492
|
-
*
|
|
493
|
-
* Example: `["firefox", "chrome"]`
|
|
494
|
-
*
|
|
495
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
496
|
-
*/
|
|
497
|
-
browserLock?:
|
|
498
|
-
| ("firefox" | "chrome" | "iexplorer" | "edge" | "safari" | "opera")[]
|
|
499
|
-
| false;
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* ### `lock.integrity`
|
|
503
|
-
*
|
|
504
|
-
* Integrity ensures the source code is unchanged. (`true/false/0-1`)
|
|
505
|
-
*
|
|
506
|
-
* [Learn more here](https://github.com/MichaelXF/js-confuser/blob/master/Integrity.md).
|
|
507
|
-
*
|
|
508
|
-
* - Potency Medium
|
|
509
|
-
* - Resilience High
|
|
510
|
-
* - Cost High
|
|
323
|
+
* Integrity ensures the source code is unchanged.
|
|
511
324
|
*
|
|
512
|
-
*
|
|
325
|
+
* @see https://github.com/MichaelXF/js-confuser/blob/master/Integrity.md
|
|
513
326
|
*/
|
|
514
|
-
integrity?: ProbabilityMap<boolean>;
|
|
327
|
+
integrity?: ProbabilityMap<boolean, (fnName: string) => boolean>;
|
|
515
328
|
|
|
516
329
|
/**
|
|
517
|
-
* ### `lock.countermeasures`
|
|
518
|
-
*
|
|
519
330
|
* A custom callback function to invoke when a lock is triggered. (`string/false`)
|
|
520
331
|
*
|
|
521
332
|
* This could be due to an invalid domain, incorrect time, or code's integrity changed.
|
|
522
333
|
*
|
|
523
|
-
*
|
|
334
|
+
* If no countermeasures function is provided (`undefined` or `true`), the obfuscator falls back to crashing the process.
|
|
524
335
|
*
|
|
525
|
-
*
|
|
336
|
+
* If `countermeasures` is `false`, no crash will occur.
|
|
526
337
|
*
|
|
527
|
-
*
|
|
338
|
+
* @see https://github.com/MichaelXF/js-confuser/blob/master/Countermeasures.md
|
|
528
339
|
*/
|
|
529
340
|
countermeasures?: string | boolean;
|
|
341
|
+
|
|
342
|
+
customLocks?: CustomLock[];
|
|
530
343
|
};
|
|
531
344
|
|
|
345
|
+
functionOutlining?: ProbabilityMap<boolean>;
|
|
346
|
+
|
|
532
347
|
/**
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
* Moves variable declarations to the top of the context. (`true/false`)
|
|
536
|
-
*
|
|
537
|
-
* - Potency Medium
|
|
538
|
-
* - Resilience Medium
|
|
539
|
-
* - Cost Low
|
|
540
|
-
*
|
|
541
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
348
|
+
* Moves variable declarations to the top of the context.
|
|
542
349
|
*/
|
|
543
350
|
movedDeclarations?: ProbabilityMap<boolean>;
|
|
544
351
|
|
|
545
352
|
/**
|
|
546
|
-
* ### `opaquePredicates`
|
|
547
|
-
*
|
|
548
353
|
* 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
|
|
549
|
-
* understanding your code.
|
|
550
|
-
*
|
|
551
|
-
* - Potency Medium
|
|
552
|
-
* - Resilience Medium
|
|
553
|
-
* - Cost Low
|
|
554
|
-
*
|
|
555
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
354
|
+
* understanding your code.
|
|
556
355
|
*/
|
|
557
356
|
opaquePredicates?: ProbabilityMap<boolean>;
|
|
558
357
|
|
|
559
358
|
/**
|
|
560
|
-
* ### `shuffle`
|
|
561
|
-
*
|
|
562
359
|
* Shuffles the initial order of arrays. The order is brought back to the original during runtime. (`"hash"/true/false/0-1`)
|
|
563
|
-
*
|
|
564
|
-
* - Potency Medium
|
|
565
|
-
* - Resilience Low
|
|
566
|
-
* - Cost Low
|
|
567
|
-
*
|
|
568
|
-
* | Mode | Description |
|
|
569
|
-
* | --- | --- |
|
|
570
|
-
* | `"hash"`| Array is shifted based on hash of the elements |
|
|
571
|
-
* | `true`| Arrays are shifted *n* elements, unshifted at runtime |
|
|
572
|
-
* | `false` | Feature disabled |
|
|
573
|
-
*
|
|
574
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
575
360
|
*/
|
|
576
|
-
shuffle?: ProbabilityMap<boolean
|
|
361
|
+
shuffle?: ProbabilityMap<boolean>;
|
|
577
362
|
|
|
578
363
|
/**
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* Enable logs to view the obfuscator's state. (`true/false`)
|
|
582
|
-
*
|
|
583
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
364
|
+
* Modified functions will retain the correct `function.length` property. Enabled by default.
|
|
584
365
|
*/
|
|
585
|
-
|
|
366
|
+
preserveFunctionLength?: boolean;
|
|
586
367
|
|
|
587
368
|
/**
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
* Set of global variables. *Optional*. (`Set<string>`)
|
|
591
|
-
*
|
|
592
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
369
|
+
* Semantically changes the AST to bypass automated tools.
|
|
593
370
|
*/
|
|
594
|
-
|
|
371
|
+
astScrambler?: boolean;
|
|
595
372
|
|
|
596
373
|
/**
|
|
597
|
-
*
|
|
374
|
+
* Packs the output code into a single `Function()` call.
|
|
598
375
|
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
376
|
+
* Designed to escape strict mode constraints.
|
|
602
377
|
*/
|
|
603
|
-
|
|
378
|
+
pack?: boolean;
|
|
604
379
|
|
|
605
380
|
/**
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
* Modified functions will retain the correct `function.length` property. Enabled by default. (`true/false`)
|
|
609
|
-
*
|
|
610
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
381
|
+
* Set of global variables. *Optional*.
|
|
611
382
|
*/
|
|
612
|
-
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
const validProperties = new Set([
|
|
616
|
-
"preset",
|
|
617
|
-
"target",
|
|
618
|
-
"indent",
|
|
619
|
-
"compact",
|
|
620
|
-
"hexadecimalNumbers",
|
|
621
|
-
"minify",
|
|
622
|
-
"es5",
|
|
623
|
-
"renameVariables",
|
|
624
|
-
"renameGlobals",
|
|
625
|
-
"identifierGenerator",
|
|
626
|
-
"controlFlowFlattening",
|
|
627
|
-
"globalConcealing",
|
|
628
|
-
"stringCompression",
|
|
629
|
-
"stringConcealing",
|
|
630
|
-
"stringEncoding",
|
|
631
|
-
"stringSplitting",
|
|
632
|
-
"duplicateLiteralsRemoval",
|
|
633
|
-
"dispatcher",
|
|
634
|
-
"rgf",
|
|
635
|
-
"objectExtraction",
|
|
636
|
-
"flatten",
|
|
637
|
-
"deadCode",
|
|
638
|
-
"calculator",
|
|
639
|
-
"lock",
|
|
640
|
-
"movedDeclarations",
|
|
641
|
-
"opaquePredicates",
|
|
642
|
-
"shuffle",
|
|
643
|
-
"stack",
|
|
644
|
-
"verbose",
|
|
645
|
-
"globalVariables",
|
|
646
|
-
"debugComments",
|
|
647
|
-
"preserveFunctionLength",
|
|
648
|
-
]);
|
|
649
|
-
|
|
650
|
-
const validLockProperties = new Set([
|
|
651
|
-
"selfDefending",
|
|
652
|
-
"antiDebug",
|
|
653
|
-
"context",
|
|
654
|
-
"tamperProtection",
|
|
655
|
-
"startDate",
|
|
656
|
-
"endDate",
|
|
657
|
-
"domainLock",
|
|
658
|
-
"osLock",
|
|
659
|
-
"browserLock",
|
|
660
|
-
"integrity",
|
|
661
|
-
"countermeasures",
|
|
662
|
-
]);
|
|
663
|
-
|
|
664
|
-
const validOses = new Set(["windows", "linux", "osx", "ios", "android"]);
|
|
665
|
-
const validBrowsers = new Set([
|
|
666
|
-
"firefox",
|
|
667
|
-
"chrome",
|
|
668
|
-
"iexplorer",
|
|
669
|
-
"edge",
|
|
670
|
-
"safari",
|
|
671
|
-
"opera",
|
|
672
|
-
]);
|
|
673
|
-
|
|
674
|
-
export function validateOptions(options: ObfuscateOptions) {
|
|
675
|
-
if (!options || Object.keys(options).length <= 1) {
|
|
676
|
-
/**
|
|
677
|
-
* Give a welcoming introduction to those who skipped the documentation.
|
|
678
|
-
*/
|
|
679
|
-
var line = `You provided zero obfuscation options. By default everything is disabled.\nYou can use a preset with:\n\n> {target: '${
|
|
680
|
-
options.target || "node"
|
|
681
|
-
}', preset: 'high' | 'medium' | 'low'}.\n\n\nView all settings here:\nhttps://github.com/MichaelXF/js-confuser#options`;
|
|
682
|
-
throw new Error(
|
|
683
|
-
`\n\n` +
|
|
684
|
-
line
|
|
685
|
-
.split("\n")
|
|
686
|
-
.map((x) => `\t${x}`)
|
|
687
|
-
.join("\n") +
|
|
688
|
-
`\n\n`
|
|
689
|
-
);
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
ok(options, "options cannot be null");
|
|
693
|
-
ok(
|
|
694
|
-
options.target,
|
|
695
|
-
"Missing options.target option (required, must one the following: 'browser' or 'node')"
|
|
696
|
-
);
|
|
697
|
-
|
|
698
|
-
ok(
|
|
699
|
-
["browser", "node"].includes(options.target),
|
|
700
|
-
`'${options.target}' is not a valid target mode`
|
|
701
|
-
);
|
|
702
|
-
|
|
703
|
-
Object.keys(options).forEach((key) => {
|
|
704
|
-
if (!validProperties.has(key)) {
|
|
705
|
-
throw new TypeError("Invalid option: '" + key + "'");
|
|
706
|
-
}
|
|
707
|
-
});
|
|
708
|
-
|
|
709
|
-
if (
|
|
710
|
-
options.target === "node" &&
|
|
711
|
-
options.lock &&
|
|
712
|
-
options.lock.browserLock &&
|
|
713
|
-
options.lock.browserLock.length
|
|
714
|
-
) {
|
|
715
|
-
throw new TypeError('browserLock can only be used when target="browser"');
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
if (options.lock) {
|
|
719
|
-
ok(typeof options.lock === "object", "options.lock must be an object");
|
|
720
|
-
Object.keys(options.lock).forEach((key) => {
|
|
721
|
-
if (!validLockProperties.has(key)) {
|
|
722
|
-
throw new TypeError("Invalid lock option: '" + key + "'");
|
|
723
|
-
}
|
|
724
|
-
});
|
|
725
|
-
|
|
726
|
-
// Validate browser-lock option
|
|
727
|
-
if (
|
|
728
|
-
options.lock.browserLock &&
|
|
729
|
-
typeof options.lock.browserLock !== "undefined"
|
|
730
|
-
) {
|
|
731
|
-
ok(
|
|
732
|
-
Array.isArray(options.lock.browserLock),
|
|
733
|
-
"browserLock must be an array"
|
|
734
|
-
);
|
|
735
|
-
ok(
|
|
736
|
-
!options.lock.browserLock.find(
|
|
737
|
-
(browserName) => !validBrowsers.has(browserName)
|
|
738
|
-
),
|
|
739
|
-
'Invalid browser name. Allowed: "firefox", "chrome", "iexplorer", "edge", "safari", "opera"'
|
|
740
|
-
);
|
|
741
|
-
}
|
|
742
|
-
// Validate os-lock option
|
|
743
|
-
if (options.lock.osLock && typeof options.lock.osLock !== "undefined") {
|
|
744
|
-
ok(Array.isArray(options.lock.osLock), "osLock must be an array");
|
|
745
|
-
ok(
|
|
746
|
-
!options.lock.osLock.find((osName) => !validOses.has(osName)),
|
|
747
|
-
'Invalid OS name. Allowed: "windows", "linux", "osx", "ios", "android"'
|
|
748
|
-
);
|
|
749
|
-
}
|
|
750
|
-
// Validate domain-lock option
|
|
751
|
-
if (
|
|
752
|
-
options.lock.domainLock &&
|
|
753
|
-
typeof options.lock.domainLock !== "undefined"
|
|
754
|
-
) {
|
|
755
|
-
ok(Array.isArray(options.lock.domainLock), "domainLock must be an array");
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
// Validate context option
|
|
759
|
-
if (options.lock.context && typeof options.lock.context !== "undefined") {
|
|
760
|
-
ok(Array.isArray(options.lock.context), "context must be an array");
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
// Validate start-date option
|
|
764
|
-
if (
|
|
765
|
-
typeof options.lock.startDate !== "undefined" &&
|
|
766
|
-
options.lock.startDate
|
|
767
|
-
) {
|
|
768
|
-
ok(
|
|
769
|
-
typeof options.lock.startDate === "number" ||
|
|
770
|
-
options.lock.startDate instanceof Date,
|
|
771
|
-
"startDate must be Date object or number"
|
|
772
|
-
);
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
// Validate end-date option
|
|
776
|
-
if (typeof options.lock.endDate !== "undefined" && options.lock.endDate) {
|
|
777
|
-
ok(
|
|
778
|
-
typeof options.lock.endDate === "number" ||
|
|
779
|
-
options.lock.endDate instanceof Date,
|
|
780
|
-
"endDate must be Date object or number"
|
|
781
|
-
);
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
if (options.preset) {
|
|
786
|
-
if (!presets[options.preset]) {
|
|
787
|
-
throw new TypeError("Unknown preset of '" + options.preset + "'");
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
}
|
|
383
|
+
globalVariables?: Set<string>;
|
|
791
384
|
|
|
792
|
-
/**
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
*/
|
|
797
|
-
export async function correctOptions(
|
|
798
|
-
options: ObfuscateOptions
|
|
799
|
-
): Promise<ObfuscateOptions> {
|
|
800
|
-
if (options.preset) {
|
|
801
|
-
// Clone and allow overriding
|
|
802
|
-
options = Object.assign({}, presets[options.preset], options);
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
if (!options.hasOwnProperty("debugComments")) {
|
|
806
|
-
options.debugComments = false; // debugComments is off by default
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
if (!options.hasOwnProperty("compact")) {
|
|
810
|
-
options.compact = true; // Compact is on by default
|
|
811
|
-
}
|
|
812
|
-
if (!options.hasOwnProperty("renameGlobals")) {
|
|
813
|
-
options.renameGlobals = true; // RenameGlobals is on by default
|
|
814
|
-
}
|
|
815
|
-
if (!options.hasOwnProperty("preserveFunctionLength")) {
|
|
816
|
-
options.preserveFunctionLength = true; // preserveFunctionLength is on by default
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
if (options.globalVariables && !(options.globalVariables instanceof Set)) {
|
|
820
|
-
options.globalVariables = new Set(Object.keys(options.globalVariables));
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
if (options.lock) {
|
|
824
|
-
if (options.lock.selfDefending) {
|
|
825
|
-
options.compact = true; // self defending forcibly enables this
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
// options.globalVariables outlines generic globals that should be present in the execution context
|
|
830
|
-
if (!options.hasOwnProperty("globalVariables")) {
|
|
831
|
-
options.globalVariables = new Set([]);
|
|
832
|
-
|
|
833
|
-
if (options.target == "browser") {
|
|
834
|
-
// browser
|
|
835
|
-
[
|
|
836
|
-
"window",
|
|
837
|
-
"document",
|
|
838
|
-
"postMessage",
|
|
839
|
-
"alert",
|
|
840
|
-
"confirm",
|
|
841
|
-
"location",
|
|
842
|
-
"btoa",
|
|
843
|
-
"atob",
|
|
844
|
-
"unescape",
|
|
845
|
-
"encodeURIComponent",
|
|
846
|
-
].forEach((x) => options.globalVariables.add(x));
|
|
847
|
-
} else {
|
|
848
|
-
// node
|
|
849
|
-
[
|
|
850
|
-
"global",
|
|
851
|
-
"Buffer",
|
|
852
|
-
"require",
|
|
853
|
-
"process",
|
|
854
|
-
"exports",
|
|
855
|
-
"module",
|
|
856
|
-
"__dirname",
|
|
857
|
-
"__filename",
|
|
858
|
-
].forEach((x) => options.globalVariables.add(x));
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
[
|
|
862
|
-
"globalThis",
|
|
863
|
-
"console",
|
|
864
|
-
"parseInt",
|
|
865
|
-
"parseFloat",
|
|
866
|
-
"Math",
|
|
867
|
-
"JSON",
|
|
868
|
-
"Promise",
|
|
869
|
-
"String",
|
|
870
|
-
"Boolean",
|
|
871
|
-
"Function",
|
|
872
|
-
"Object",
|
|
873
|
-
"Array",
|
|
874
|
-
"Proxy",
|
|
875
|
-
"Error",
|
|
876
|
-
"TypeError",
|
|
877
|
-
"ReferenceError",
|
|
878
|
-
"RangeError",
|
|
879
|
-
"EvalError",
|
|
880
|
-
"setTimeout",
|
|
881
|
-
"clearTimeout",
|
|
882
|
-
"setInterval",
|
|
883
|
-
"clearInterval",
|
|
884
|
-
"setImmediate",
|
|
885
|
-
"clearImmediate",
|
|
886
|
-
"queueMicrotask",
|
|
887
|
-
"isNaN",
|
|
888
|
-
"isFinite",
|
|
889
|
-
"Set",
|
|
890
|
-
"Map",
|
|
891
|
-
"WeakSet",
|
|
892
|
-
"WeakMap",
|
|
893
|
-
"Symbol",
|
|
894
|
-
].forEach((x) => options.globalVariables.add(x));
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
return options;
|
|
385
|
+
/**
|
|
386
|
+
* Enable logs to view the obfuscator's state.
|
|
387
|
+
*/
|
|
388
|
+
verbose?: boolean;
|
|
898
389
|
}
|