js-confuser 1.7.2 → 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/.github/workflows/node.js.yml +1 -1
- package/CHANGELOG.md +105 -0
- package/Migration.md +57 -0
- package/README.md +23 -913
- package/dist/constants.js +69 -13
- package/dist/index.js +108 -152
- package/dist/obfuscator.js +316 -118
- package/dist/options.js +1 -109
- 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 +213 -93
- 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 -577
- package/dist/transforms/dispatcher.js +300 -309
- 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 +217 -103
- package/dist/transforms/identifier/movedDeclarations.js +167 -91
- package/dist/transforms/identifier/renameVariables.js +240 -187
- package/dist/transforms/lock/integrity.js +61 -184
- package/dist/transforms/lock/lock.js +263 -303
- 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 +263 -163
- package/dist/transforms/renameLabels.js +132 -56
- package/dist/transforms/rgf.js +142 -240
- package/dist/transforms/shuffle.js +52 -145
- package/dist/transforms/string/encoding.js +45 -173
- package/dist/transforms/string/stringCompression.js +81 -126
- package/dist/transforms/string/stringConcealing.js +189 -224
- 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 -77
- package/src/index.ts +70 -163
- package/src/obfuscationResult.ts +43 -0
- package/src/obfuscator.ts +328 -135
- package/src/options.ts +154 -623
- package/src/order.ts +14 -14
- package/src/presets.ts +39 -34
- package/src/probability.ts +21 -36
- package/src/templates/{bufferToString.ts → bufferToStringTemplate.ts} +5 -54
- 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 +183 -92
- package/src/transforms/astScrambler.ts +99 -0
- package/src/transforms/calculator.ts +96 -224
- package/src/transforms/controlFlowFlattening.ts +1594 -0
- package/src/transforms/deadCode.ts +85 -628
- package/src/transforms/dispatcher.ts +431 -636
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +147 -299
- 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 +261 -189
- package/src/transforms/identifier/movedDeclarations.ts +228 -142
- package/src/transforms/identifier/renameVariables.ts +252 -258
- package/src/transforms/lock/integrity.ts +84 -260
- package/src/transforms/lock/lock.ts +342 -491
- 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 -215
- package/src/transforms/renameLabels.ts +176 -77
- package/src/transforms/rgf.ts +293 -386
- package/src/transforms/shuffle.ts +80 -254
- package/src/transforms/string/encoding.ts +26 -129
- package/src/transforms/string/stringCompression.ts +118 -236
- package/src/transforms/string/stringConcealing.ts +255 -339
- 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 -108
- package/dist/templates/crash.js +0 -59
- 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 -1281
- 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 -70
- package/dist/transforms/identifier/variableAnalysis.js +0 -104
- package/dist/transforms/lock/antiDebug.js +0 -76
- package/dist/transforms/stack.js +0 -343
- package/dist/transforms/transform.js +0 -350
- 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 -9
- 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 -130
- package/dist/util/scope.js +0 -20
- package/docs/ControlFlowFlattening.md +0 -595
- package/docs/Countermeasures.md +0 -63
- package/docs/ES5.md +0 -197
- package/docs/Integrity.md +0 -75
- package/docs/RGF.md +0 -419
- 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/crash.ts +0 -55
- 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 -2146
- package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +0 -179
- package/src/transforms/es5/antiClass.ts +0 -272
- 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 -85
- package/src/transforms/identifier/variableAnalysis.ts +0 -118
- package/src/transforms/lock/antiDebug.ts +0 -112
- package/src/transforms/stack.ts +0 -551
- package/src/transforms/transform.ts +0 -453
- package/src/traverse.ts +0 -120
- package/src/types.ts +0 -131
- package/src/util/compare.ts +0 -181
- package/src/util/gen.ts +0 -651
- package/src/util/guard.ts +0 -7
- 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 -141
- package/src/util/scope.ts +0 -21
- package/test/code/Cash.src.js +0 -1011
- package/test/code/Cash.test.ts +0 -49
- 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 -132
- package/test/presets.test.ts +0 -22
- package/test/probability.test.ts +0 -44
- package/test/templates/template.test.ts +0 -14
- 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 -72
- package/test/transforms/identifier/movedDeclarations.test.ts +0 -275
- package/test/transforms/identifier/renameVariables.test.ts +0 -621
- 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/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
|
-
*
|
|
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](https://docs.jscrambler.com/code-integrity/documentation/transformations/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](https://docs.jscrambler.com/code-integrity/documentation/transformations/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](https://docs.jscrambler.com/code-integrity/documentation/transformations/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
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* 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. (`"all"/true/false`)
|
|
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.
|
|
260
196
|
*
|
|
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,529 +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`)
|
|
370
|
-
*
|
|
371
|
-
* - Potency Medium
|
|
372
|
-
* - Resilience Medium
|
|
373
|
-
* - Cost Low
|
|
272
|
+
* Creates a calculator function to handle arithmetic and logical expressions.
|
|
374
273
|
*
|
|
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
|
-
*
|
|
292
|
+
* Tamper Protection safeguards the runtime behavior from being altered by JavaScript pitfalls.
|
|
402
293
|
*
|
|
403
|
-
*
|
|
294
|
+
* **⚠️ Tamper Protection requires eval and ran in a non-strict mode environment!**
|
|
404
295
|
*
|
|
405
|
-
*
|
|
296
|
+
* - **This can break your code.**
|
|
297
|
+
* - **Due to the security concerns of arbitrary code execution, you must enable this yourself.**
|
|
298
|
+
*
|
|
299
|
+
* @see https://github.com/MichaelXF/js-confuser/blob/master/TamperProtection.md
|
|
406
300
|
*/
|
|
407
|
-
|
|
301
|
+
tamperProtection?: boolean | ((varName: string) => boolean);
|
|
408
302
|
|
|
409
303
|
/**
|
|
410
|
-
* ### `lock.startDate`
|
|
411
|
-
*
|
|
412
304
|
* When the program is first able to be used. (`number` or `Date`)
|
|
413
305
|
*
|
|
414
306
|
* Number should be in milliseconds.
|
|
415
|
-
*
|
|
416
|
-
* - Potency Low
|
|
417
|
-
* - Resilience Medium
|
|
418
|
-
* - Cost Medium
|
|
419
|
-
*
|
|
420
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
421
307
|
*/
|
|
422
308
|
startDate?: number | Date | false;
|
|
423
309
|
|
|
424
310
|
/**
|
|
425
|
-
* ### `lock.endDate`
|
|
426
|
-
*
|
|
427
311
|
* When the program is no longer able to be used. (`number` or `Date`)
|
|
428
312
|
*
|
|
429
313
|
* Number should be in milliseconds.
|
|
430
|
-
*
|
|
431
|
-
* - Potency Low
|
|
432
|
-
* - Resilience Medium
|
|
433
|
-
* - Cost Medium
|
|
434
|
-
*
|
|
435
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
436
314
|
*/
|
|
437
315
|
endDate?: number | Date | false;
|
|
438
316
|
|
|
439
317
|
/**
|
|
440
|
-
*
|
|
441
|
-
* Array of regex strings that the `window.location.href` must follow. (`Regex[]` or `string[]`)
|
|
442
|
-
*
|
|
443
|
-
* - Potency Low
|
|
444
|
-
* - Resilience Medium
|
|
445
|
-
* - Cost Medium
|
|
446
|
-
*
|
|
447
|
-
* [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.
|
|
448
319
|
*/
|
|
449
320
|
domainLock?: RegExp[] | string[] | false;
|
|
450
321
|
|
|
451
322
|
/**
|
|
452
|
-
*
|
|
453
|
-
* Array of operating-systems where the script is allowed to run. (`string[]`)
|
|
454
|
-
*
|
|
455
|
-
* - Potency Low
|
|
456
|
-
* - Resilience Medium
|
|
457
|
-
* - Cost Medium
|
|
458
|
-
*
|
|
459
|
-
* Allowed values: `"linux"`, `"windows"`, `"osx"`, `"android"`, `"ios"`
|
|
460
|
-
*
|
|
461
|
-
* Example: `["linux", "windows"]`
|
|
462
|
-
*
|
|
463
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
464
|
-
*/
|
|
465
|
-
osLock?: ("linux" | "windows" | "osx" | "android" | "ios")[] | false;
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* ### `lock.browserLock`
|
|
469
|
-
* Array of browsers where the script is allowed to run. (`string[]`)
|
|
470
|
-
*
|
|
471
|
-
* - Potency Low
|
|
472
|
-
* - Resilience Medium
|
|
473
|
-
* - Cost Medium
|
|
323
|
+
* Integrity ensures the source code is unchanged.
|
|
474
324
|
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
* Example: `["firefox", "chrome"]`
|
|
478
|
-
*
|
|
479
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
325
|
+
* @see https://github.com/MichaelXF/js-confuser/blob/master/Integrity.md
|
|
480
326
|
*/
|
|
481
|
-
|
|
482
|
-
| ("firefox" | "chrome" | "iexplorer" | "edge" | "safari" | "opera")[]
|
|
483
|
-
| false;
|
|
327
|
+
integrity?: ProbabilityMap<boolean, (fnName: string) => boolean>;
|
|
484
328
|
|
|
485
329
|
/**
|
|
486
|
-
* ### `lock.integrity`
|
|
487
|
-
*
|
|
488
|
-
* Integrity ensures the source code is unchanged. (`true/false/0-1`)
|
|
489
|
-
*
|
|
490
|
-
* [Learn more here](https://github.com/MichaelXF/js-confuser/blob/master/Integrity.md).
|
|
491
|
-
*
|
|
492
|
-
* - Potency Medium
|
|
493
|
-
* - Resilience High
|
|
494
|
-
* - Cost High
|
|
495
|
-
*
|
|
496
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
497
|
-
*/
|
|
498
|
-
integrity?: ProbabilityMap<boolean>;
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* ### `lock.countermeasures`
|
|
502
|
-
*
|
|
503
330
|
* A custom callback function to invoke when a lock is triggered. (`string/false`)
|
|
504
331
|
*
|
|
505
332
|
* This could be due to an invalid domain, incorrect time, or code's integrity changed.
|
|
506
333
|
*
|
|
507
|
-
*
|
|
334
|
+
* If no countermeasures function is provided (`undefined` or `true`), the obfuscator falls back to crashing the process.
|
|
508
335
|
*
|
|
509
|
-
*
|
|
336
|
+
* If `countermeasures` is `false`, no crash will occur.
|
|
510
337
|
*
|
|
511
|
-
*
|
|
338
|
+
* @see https://github.com/MichaelXF/js-confuser/blob/master/Countermeasures.md
|
|
512
339
|
*/
|
|
513
340
|
countermeasures?: string | boolean;
|
|
341
|
+
|
|
342
|
+
customLocks?: CustomLock[];
|
|
514
343
|
};
|
|
515
344
|
|
|
345
|
+
functionOutlining?: ProbabilityMap<boolean>;
|
|
346
|
+
|
|
516
347
|
/**
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
* Moves variable declarations to the top of the context. (`true/false`)
|
|
520
|
-
*
|
|
521
|
-
* - Potency Medium
|
|
522
|
-
* - Resilience Medium
|
|
523
|
-
* - Cost Low
|
|
524
|
-
*
|
|
525
|
-
* [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.
|
|
526
349
|
*/
|
|
527
350
|
movedDeclarations?: ProbabilityMap<boolean>;
|
|
528
351
|
|
|
529
352
|
/**
|
|
530
|
-
* ### `opaquePredicates`
|
|
531
|
-
*
|
|
532
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
|
|
533
|
-
* understanding your code.
|
|
534
|
-
*
|
|
535
|
-
* - Potency Medium
|
|
536
|
-
* - Resilience Medium
|
|
537
|
-
* - Cost Low
|
|
538
|
-
*
|
|
539
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
354
|
+
* understanding your code.
|
|
540
355
|
*/
|
|
541
356
|
opaquePredicates?: ProbabilityMap<boolean>;
|
|
542
357
|
|
|
543
358
|
/**
|
|
544
|
-
* ### `shuffle`
|
|
545
|
-
*
|
|
546
359
|
* Shuffles the initial order of arrays. The order is brought back to the original during runtime. (`"hash"/true/false/0-1`)
|
|
547
|
-
*
|
|
548
|
-
* - Potency Medium
|
|
549
|
-
* - Resilience Low
|
|
550
|
-
* - Cost Low
|
|
551
|
-
*
|
|
552
|
-
* | Mode | Description |
|
|
553
|
-
* | --- | --- |
|
|
554
|
-
* | `"hash"`| Array is shifted based on hash of the elements |
|
|
555
|
-
* | `true`| Arrays are shifted *n* elements, unshifted at runtime |
|
|
556
|
-
* | `false` | Feature disabled |
|
|
557
|
-
*
|
|
558
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
559
360
|
*/
|
|
560
|
-
shuffle?: ProbabilityMap<boolean
|
|
361
|
+
shuffle?: ProbabilityMap<boolean>;
|
|
561
362
|
|
|
562
363
|
/**
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
* Enable logs to view the obfuscator's state. (`true/false`)
|
|
566
|
-
*
|
|
567
|
-
* [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.
|
|
568
365
|
*/
|
|
569
|
-
|
|
366
|
+
preserveFunctionLength?: boolean;
|
|
570
367
|
|
|
571
368
|
/**
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
* Set of global variables. *Optional*. (`Set<string>`)
|
|
575
|
-
*
|
|
576
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
369
|
+
* Semantically changes the AST to bypass automated tools.
|
|
577
370
|
*/
|
|
578
|
-
|
|
371
|
+
astScrambler?: boolean;
|
|
579
372
|
|
|
580
373
|
/**
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
* Enable debug comments. (`true/false`)
|
|
374
|
+
* Packs the output code into a single `Function()` call.
|
|
584
375
|
*
|
|
585
|
-
*
|
|
376
|
+
* Designed to escape strict mode constraints.
|
|
586
377
|
*/
|
|
587
|
-
|
|
378
|
+
pack?: boolean;
|
|
588
379
|
|
|
589
380
|
/**
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
* Modified functions will retain the correct `function.length` property. Enabled by default. (`true/false`)
|
|
593
|
-
*
|
|
594
|
-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
|
|
381
|
+
* Set of global variables. *Optional*.
|
|
595
382
|
*/
|
|
596
|
-
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
const validProperties = new Set([
|
|
600
|
-
"preset",
|
|
601
|
-
"target",
|
|
602
|
-
"indent",
|
|
603
|
-
"compact",
|
|
604
|
-
"hexadecimalNumbers",
|
|
605
|
-
"minify",
|
|
606
|
-
"es5",
|
|
607
|
-
"renameVariables",
|
|
608
|
-
"renameGlobals",
|
|
609
|
-
"identifierGenerator",
|
|
610
|
-
"controlFlowFlattening",
|
|
611
|
-
"globalConcealing",
|
|
612
|
-
"stringCompression",
|
|
613
|
-
"stringConcealing",
|
|
614
|
-
"stringEncoding",
|
|
615
|
-
"stringSplitting",
|
|
616
|
-
"duplicateLiteralsRemoval",
|
|
617
|
-
"dispatcher",
|
|
618
|
-
"rgf",
|
|
619
|
-
"objectExtraction",
|
|
620
|
-
"flatten",
|
|
621
|
-
"deadCode",
|
|
622
|
-
"calculator",
|
|
623
|
-
"lock",
|
|
624
|
-
"movedDeclarations",
|
|
625
|
-
"opaquePredicates",
|
|
626
|
-
"shuffle",
|
|
627
|
-
"stack",
|
|
628
|
-
"verbose",
|
|
629
|
-
"globalVariables",
|
|
630
|
-
"debugComments",
|
|
631
|
-
"preserveFunctionLength",
|
|
632
|
-
]);
|
|
633
|
-
|
|
634
|
-
const validOses = new Set(["windows", "linux", "osx", "ios", "android"]);
|
|
635
|
-
const validBrowsers = new Set([
|
|
636
|
-
"firefox",
|
|
637
|
-
"chrome",
|
|
638
|
-
"iexplorer",
|
|
639
|
-
"edge",
|
|
640
|
-
"safari",
|
|
641
|
-
"opera",
|
|
642
|
-
]);
|
|
643
|
-
|
|
644
|
-
export function validateOptions(options: ObfuscateOptions) {
|
|
645
|
-
if (!options || Object.keys(options).length <= 1) {
|
|
646
|
-
/**
|
|
647
|
-
* Give a welcoming introduction to those who skipped the documentation.
|
|
648
|
-
*/
|
|
649
|
-
var line = `You provided zero obfuscation options. By default everything is disabled.\nYou can use a preset with:\n\n> {target: '${
|
|
650
|
-
options.target || "node"
|
|
651
|
-
}', preset: 'high' | 'medium' | 'low'}.\n\n\nView all settings here:\nhttps://github.com/MichaelXF/js-confuser#options`;
|
|
652
|
-
throw new Error(
|
|
653
|
-
`\n\n` +
|
|
654
|
-
line
|
|
655
|
-
.split("\n")
|
|
656
|
-
.map((x) => `\t${x}`)
|
|
657
|
-
.join("\n") +
|
|
658
|
-
`\n\n`
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
ok(options, "options cannot be null");
|
|
663
|
-
ok(
|
|
664
|
-
options.target,
|
|
665
|
-
"Missing options.target option (required, must one the following: 'browser' or 'node')"
|
|
666
|
-
);
|
|
667
|
-
ok(
|
|
668
|
-
["browser", "node"].includes(options.target),
|
|
669
|
-
`'${options.target}' is not a valid target mode`
|
|
670
|
-
);
|
|
671
|
-
|
|
672
|
-
Object.keys(options).forEach((key) => {
|
|
673
|
-
if (!validProperties.has(key)) {
|
|
674
|
-
throw new TypeError("Invalid option: '" + key + "'");
|
|
675
|
-
}
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
if (
|
|
679
|
-
options.target === "node" &&
|
|
680
|
-
options.lock &&
|
|
681
|
-
options.lock.browserLock &&
|
|
682
|
-
options.lock.browserLock.length
|
|
683
|
-
) {
|
|
684
|
-
throw new TypeError('browserLock can only be used when target="browser"');
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
if (options.lock) {
|
|
688
|
-
// Validate browser-lock option
|
|
689
|
-
if (
|
|
690
|
-
options.lock.browserLock &&
|
|
691
|
-
typeof options.lock.browserLock !== "undefined"
|
|
692
|
-
) {
|
|
693
|
-
ok(
|
|
694
|
-
Array.isArray(options.lock.browserLock),
|
|
695
|
-
"browserLock must be an array"
|
|
696
|
-
);
|
|
697
|
-
ok(
|
|
698
|
-
!options.lock.browserLock.find(
|
|
699
|
-
(browserName) => !validBrowsers.has(browserName)
|
|
700
|
-
),
|
|
701
|
-
'Invalid browser name. Allowed: "firefox", "chrome", "iexplorer", "edge", "safari", "opera"'
|
|
702
|
-
);
|
|
703
|
-
}
|
|
704
|
-
// Validate os-lock option
|
|
705
|
-
if (options.lock.osLock && typeof options.lock.osLock !== "undefined") {
|
|
706
|
-
ok(Array.isArray(options.lock.osLock), "osLock must be an array");
|
|
707
|
-
ok(
|
|
708
|
-
!options.lock.osLock.find((osName) => !validOses.has(osName)),
|
|
709
|
-
'Invalid OS name. Allowed: "windows", "linux", "osx", "ios", "android"'
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
// Validate domain-lock option
|
|
713
|
-
if (
|
|
714
|
-
options.lock.domainLock &&
|
|
715
|
-
typeof options.lock.domainLock !== "undefined"
|
|
716
|
-
) {
|
|
717
|
-
ok(Array.isArray(options.lock.domainLock), "domainLock must be an array");
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
// Validate context option
|
|
721
|
-
if (options.lock.context && typeof options.lock.context !== "undefined") {
|
|
722
|
-
ok(Array.isArray(options.lock.context), "context must be an array");
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
// Validate start-date option
|
|
726
|
-
if (
|
|
727
|
-
typeof options.lock.startDate !== "undefined" &&
|
|
728
|
-
options.lock.startDate
|
|
729
|
-
) {
|
|
730
|
-
ok(
|
|
731
|
-
typeof options.lock.startDate === "number" ||
|
|
732
|
-
options.lock.startDate instanceof Date,
|
|
733
|
-
"startDate must be Date object or number"
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
// Validate end-date option
|
|
738
|
-
if (typeof options.lock.endDate !== "undefined" && options.lock.endDate) {
|
|
739
|
-
ok(
|
|
740
|
-
typeof options.lock.endDate === "number" ||
|
|
741
|
-
options.lock.endDate instanceof Date,
|
|
742
|
-
"endDate must be Date object or number"
|
|
743
|
-
);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
if (options.preset) {
|
|
748
|
-
if (!presets[options.preset]) {
|
|
749
|
-
throw new TypeError("Unknown preset of '" + options.preset + "'");
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
}
|
|
383
|
+
globalVariables?: Set<string>;
|
|
753
384
|
|
|
754
|
-
/**
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
*/
|
|
759
|
-
export async function correctOptions(
|
|
760
|
-
options: ObfuscateOptions
|
|
761
|
-
): Promise<ObfuscateOptions> {
|
|
762
|
-
if (options.preset) {
|
|
763
|
-
// Clone and allow overriding
|
|
764
|
-
options = Object.assign({}, presets[options.preset], options);
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
if (!options.hasOwnProperty("debugComments")) {
|
|
768
|
-
options.debugComments = false; // debugComments is off by default
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
if (!options.hasOwnProperty("compact")) {
|
|
772
|
-
options.compact = true; // Compact is on by default
|
|
773
|
-
}
|
|
774
|
-
if (!options.hasOwnProperty("renameGlobals")) {
|
|
775
|
-
options.renameGlobals = true; // RenameGlobals is on by default
|
|
776
|
-
}
|
|
777
|
-
if (!options.hasOwnProperty("preserveFunctionLength")) {
|
|
778
|
-
options.preserveFunctionLength = true; // preserveFunctionLength is on by default
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
if (options.globalVariables && !(options.globalVariables instanceof Set)) {
|
|
782
|
-
options.globalVariables = new Set(Object.keys(options.globalVariables));
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
if (options.lock && options.lock.selfDefending) {
|
|
786
|
-
options.compact = true; // self defending forcibly enables this
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
// options.globalVariables outlines generic globals that should be present in the execution context
|
|
790
|
-
if (!options.hasOwnProperty("globalVariables")) {
|
|
791
|
-
options.globalVariables = new Set([]);
|
|
792
|
-
|
|
793
|
-
if (options.target == "browser") {
|
|
794
|
-
// browser
|
|
795
|
-
[
|
|
796
|
-
"window",
|
|
797
|
-
"document",
|
|
798
|
-
"postMessage",
|
|
799
|
-
"alert",
|
|
800
|
-
"confirm",
|
|
801
|
-
"location",
|
|
802
|
-
"btoa",
|
|
803
|
-
"atob",
|
|
804
|
-
"unescape",
|
|
805
|
-
"encodeURIComponent",
|
|
806
|
-
].forEach((x) => options.globalVariables.add(x));
|
|
807
|
-
} else {
|
|
808
|
-
// node
|
|
809
|
-
[
|
|
810
|
-
"global",
|
|
811
|
-
"Buffer",
|
|
812
|
-
"require",
|
|
813
|
-
"process",
|
|
814
|
-
"exports",
|
|
815
|
-
"module",
|
|
816
|
-
"__dirname",
|
|
817
|
-
"__filename",
|
|
818
|
-
].forEach((x) => options.globalVariables.add(x));
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
[
|
|
822
|
-
"globalThis",
|
|
823
|
-
"console",
|
|
824
|
-
"parseInt",
|
|
825
|
-
"parseFloat",
|
|
826
|
-
"Math",
|
|
827
|
-
"JSON",
|
|
828
|
-
"Promise",
|
|
829
|
-
"String",
|
|
830
|
-
"Boolean",
|
|
831
|
-
"Function",
|
|
832
|
-
"Object",
|
|
833
|
-
"Array",
|
|
834
|
-
"Proxy",
|
|
835
|
-
"Error",
|
|
836
|
-
"TypeError",
|
|
837
|
-
"ReferenceError",
|
|
838
|
-
"RangeError",
|
|
839
|
-
"EvalError",
|
|
840
|
-
"setTimeout",
|
|
841
|
-
"clearTimeout",
|
|
842
|
-
"setInterval",
|
|
843
|
-
"clearInterval",
|
|
844
|
-
"setImmediate",
|
|
845
|
-
"clearImmediate",
|
|
846
|
-
"queueMicrotask",
|
|
847
|
-
"isNaN",
|
|
848
|
-
"isFinite",
|
|
849
|
-
"Set",
|
|
850
|
-
"Map",
|
|
851
|
-
"WeakSet",
|
|
852
|
-
"WeakMap",
|
|
853
|
-
"Symbol",
|
|
854
|
-
].forEach((x) => options.globalVariables.add(x));
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
return options;
|
|
385
|
+
/**
|
|
386
|
+
* Enable logs to view the obfuscator's state.
|
|
387
|
+
*/
|
|
388
|
+
verbose?: boolean;
|
|
858
389
|
}
|