js-confuser 1.7.1 → 1.7.2
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/CHANGELOG.md +38 -0
- package/README.md +12 -27
- package/dist/compiler.js +2 -8
- package/dist/constants.js +17 -10
- package/dist/index.js +7 -30
- package/dist/obfuscator.js +15 -62
- package/dist/options.js +21 -38
- package/dist/order.js +4 -7
- package/dist/parser.js +5 -13
- package/dist/precedence.js +6 -8
- package/dist/presets.js +4 -6
- package/dist/probability.js +13 -24
- package/dist/templates/bufferToString.js +100 -5
- package/dist/templates/crash.js +51 -9
- package/dist/templates/es5.js +125 -6
- package/dist/templates/functionLength.js +24 -6
- package/dist/templates/globals.js +9 -0
- package/dist/templates/template.js +71 -30
- package/dist/transforms/antiTooling.js +26 -22
- package/dist/transforms/calculator.js +18 -54
- package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +236 -333
- package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +46 -25
- package/dist/transforms/deadCode.js +528 -27
- package/dist/transforms/dispatcher.js +106 -110
- package/dist/transforms/es5/antiClass.js +70 -44
- package/dist/transforms/es5/antiDestructuring.js +14 -38
- package/dist/transforms/es5/antiES6Object.js +39 -48
- package/dist/transforms/es5/antiSpreadOperator.js +5 -14
- package/dist/transforms/es5/antiTemplate.js +10 -19
- package/dist/transforms/es5/es5.js +7 -40
- package/dist/transforms/extraction/classExtraction.js +83 -0
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +41 -80
- package/dist/transforms/extraction/objectExtraction.js +24 -56
- package/dist/transforms/finalizer.js +6 -20
- package/dist/transforms/flatten.js +51 -99
- package/dist/transforms/identifier/globalAnalysis.js +8 -26
- package/dist/transforms/identifier/globalConcealing.js +35 -54
- package/dist/transforms/identifier/movedDeclarations.js +66 -38
- package/dist/transforms/identifier/renameVariables.js +29 -68
- package/dist/transforms/identifier/variableAnalysis.js +21 -48
- package/dist/transforms/lock/antiDebug.js +20 -25
- package/dist/transforms/lock/integrity.js +48 -47
- package/dist/transforms/lock/lock.js +62 -113
- package/dist/transforms/minify.js +77 -108
- package/dist/transforms/opaquePredicates.js +11 -48
- package/dist/transforms/preparation.js +17 -50
- package/dist/transforms/renameLabels.js +5 -22
- package/dist/transforms/rgf.js +93 -69
- package/dist/transforms/shuffle.js +41 -46
- package/dist/transforms/stack.js +35 -98
- package/dist/transforms/string/encoding.js +73 -27
- package/dist/transforms/string/stringCompression.js +44 -68
- package/dist/transforms/string/stringConcealing.js +125 -134
- package/dist/transforms/string/stringEncoding.js +6 -26
- package/dist/transforms/string/stringSplitting.js +5 -30
- package/dist/transforms/transform.js +50 -100
- package/dist/traverse.js +11 -18
- package/dist/util/compare.js +27 -29
- package/dist/util/gen.js +32 -86
- package/dist/util/guard.js +0 -1
- package/dist/util/identifiers.js +9 -72
- package/dist/util/insert.js +27 -77
- package/dist/util/math.js +0 -3
- package/dist/util/object.js +3 -7
- package/dist/util/random.js +5 -36
- package/dist/util/scope.js +6 -3
- package/package.json +3 -3
- package/src/constants.ts +12 -0
- package/src/options.ts +13 -0
- package/src/order.ts +2 -2
- package/src/templates/bufferToString.ts +49 -11
- package/src/templates/functionLength.ts +21 -3
- package/src/templates/globals.ts +3 -0
- package/src/templates/template.ts +85 -25
- package/src/transforms/antiTooling.ts +33 -11
- package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +2 -2
- package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +46 -10
- package/src/transforms/deadCode.ts +0 -16
- package/src/transforms/dispatcher.ts +91 -69
- package/src/transforms/es5/antiClass.ts +10 -1
- package/src/transforms/extraction/classExtraction.ts +168 -0
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +9 -10
- package/src/transforms/extraction/objectExtraction.ts +4 -15
- package/src/transforms/flatten.ts +20 -5
- package/src/transforms/identifier/globalConcealing.ts +29 -65
- package/src/transforms/identifier/movedDeclarations.ts +90 -24
- package/src/transforms/minify.ts +27 -12
- package/src/transforms/rgf.ts +94 -5
- package/src/transforms/stack.ts +12 -3
- package/src/transforms/string/encoding.ts +85 -51
- package/src/transforms/string/stringCompression.ts +5 -8
- package/src/transforms/string/stringConcealing.ts +139 -113
- package/src/transforms/string/stringEncoding.ts +1 -2
- package/src/transforms/string/stringSplitting.ts +1 -2
- package/src/transforms/transform.ts +30 -1
- package/src/util/compare.ts +39 -5
- package/src/util/gen.ts +10 -3
- package/src/util/insert.ts +17 -0
- package/src/util/scope.ts +14 -2
- package/test/code/Cash.test.ts +10 -4
- package/test/code/StrictMode.src.js +65 -0
- package/test/code/StrictMode.test.js +37 -0
- package/test/compare.test.ts +62 -2
- package/test/options.test.ts +111 -55
- package/test/transforms/controlFlowFlattening/expressionObfuscation.test.ts +37 -18
- package/test/transforms/dispatcher.test.ts +55 -0
- package/test/transforms/extraction/classExtraction.test.ts +86 -0
- package/test/transforms/extraction/duplicateLiteralsRemoval.test.ts +8 -0
- package/test/transforms/extraction/objectExtraction.test.ts +2 -0
- package/test/transforms/identifier/globalConcealing.test.ts +19 -0
- package/test/transforms/identifier/movedDeclarations.test.ts +61 -0
- package/test/transforms/minify.test.ts +37 -0
- package/test/transforms/rgf.test.ts +50 -0
- package/dist/transforms/controlFlowFlattening/choiceFlowObfuscation.js +0 -62
- package/dist/transforms/controlFlowFlattening/controlFlowObfuscation.js +0 -159
- package/dist/transforms/controlFlowFlattening/switchCaseObfuscation.js +0 -106
- package/dist/transforms/eval.js +0 -84
- package/dist/transforms/hexadecimalNumbers.js +0 -63
- package/dist/transforms/hideInitializingCode.js +0 -270
- package/dist/transforms/identifier/nameRecycling.js +0 -218
- package/dist/transforms/label.js +0 -67
- package/dist/transforms/preparation/nameConflicts.js +0 -116
- package/dist/transforms/preparation/preparation.js +0 -188
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
# `1.7.2`
|
|
2
|
+
Updates
|
|
3
|
+
|
|
4
|
+
- `Anti Tooling` & `Expression Obfuscation` improvements
|
|
5
|
+
- - No longer expanded by [webcrack](https://github.com/j4k0xb/webcrack), [synchrony](https://github.com/relative/synchrony) & [REstringer](https://github.com/PerimeterX/restringer)
|
|
6
|
+
|
|
7
|
+
- `String Concealing` improvements
|
|
8
|
+
- - Randomizes the charset for each obfuscation
|
|
9
|
+
- - Place multiple decryption functions throughout the code
|
|
10
|
+
- - These changes aim to defeat [JSConfuser-String-Decryptor](https://github.com/0v41n/JSConfuser-String-Decryptor) and any other RegEx-based decoders
|
|
11
|
+
|
|
12
|
+
- `Moved Declarations` improvements
|
|
13
|
+
- - Now moves some variables as unused parameters on certain functions
|
|
14
|
+
|
|
15
|
+
- `RGF` improvements
|
|
16
|
+
- - More likely to transform functions containing functions
|
|
17
|
+
|
|
18
|
+
- Fixed [#96](https://github.com/MichaelXF/js-confuser/issues/96)
|
|
19
|
+
- - Removed hardcoded limits on `String Concealing`, `String Compression`, and `Duplicate Literals Removal`
|
|
20
|
+
|
|
21
|
+
- Fixed [#106](https://github.com/MichaelXF/js-confuser/issues/106)
|
|
22
|
+
- - Final fix with const variables for `Object Extraction`
|
|
23
|
+
|
|
24
|
+
- Fixed [#131](https://github.com/MichaelXF/js-confuser/issues/131)
|
|
25
|
+
- - __dirname is no longer changed by `Global Concealing`
|
|
26
|
+
|
|
27
|
+
**New Option**
|
|
28
|
+
|
|
29
|
+
### `preserveFunctionLength`
|
|
30
|
+
- Modified functions will retain the correct `function.length` property. (`true/false`)
|
|
31
|
+
Enabled by default.
|
|
32
|
+
|
|
33
|
+
Minor improvements
|
|
34
|
+
- Preserve `function.length`
|
|
35
|
+
- Preserve Strict Mode behaviors
|
|
36
|
+
- Preserve indirect vs. direct [`eval`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) use
|
|
37
|
+
|
|
38
|
+
|
|
1
39
|
# `1.7.1`
|
|
2
40
|
Updates
|
|
3
41
|
|
package/README.md
CHANGED
|
@@ -131,6 +131,8 @@ Converts output to ES5-compatible code. (`true/false`)
|
|
|
131
131
|
|
|
132
132
|
Does not cover all cases such as Promises or Generator functions. Use [Babel](https://babel.dev/).
|
|
133
133
|
|
|
134
|
+
[Learn more here.](https://github.com/MichaelXF/js-confuser/blob/master/docs/ES5.md)
|
|
135
|
+
|
|
134
136
|
### `renameVariables`
|
|
135
137
|
|
|
136
138
|
Determines if variables should be renamed. (`true/false`)
|
|
@@ -185,29 +187,6 @@ qFaI6S();
|
|
|
185
187
|
|
|
186
188
|
Renames top-level variables, turn this off for web-related scripts. Enabled by default. (`true/false`)
|
|
187
189
|
|
|
188
|
-
```js
|
|
189
|
-
// Output (Same input from above)
|
|
190
|
-
var twoSum = function (Oc4nmjB, Fk3nptX) {
|
|
191
|
-
var on_KnCm = {};
|
|
192
|
-
var lqAauc = Oc4nmjB["length"];
|
|
193
|
-
for (var mALijp8 = 0; mALijp8 < lqAauc; mALijp8++) {
|
|
194
|
-
if (Oc4nmjB[mALijp8] in on_KnCm) {
|
|
195
|
-
return [on_KnCm[Oc4nmjB[mALijp8]], mALijp8];
|
|
196
|
-
}
|
|
197
|
-
on_KnCm[Fk3nptX - Oc4nmjB[mALijp8]] = mALijp8;
|
|
198
|
-
}
|
|
199
|
-
return [-1, -1];
|
|
200
|
-
};
|
|
201
|
-
var test = function () {
|
|
202
|
-
var y5ySeZ = [2, 7, 11, 15];
|
|
203
|
-
var gHYMOm = 9;
|
|
204
|
-
var aAdj3v = [0, 1];
|
|
205
|
-
var GnLVHX = twoSum(y5ySeZ, gHYMOm);
|
|
206
|
-
!(ok(GnLVHX[0] === aAdj3v[0]), ok(GnLVHX[1] === aAdj3v[1]));
|
|
207
|
-
};
|
|
208
|
-
test();
|
|
209
|
-
```
|
|
210
|
-
|
|
211
190
|
### `identifierGenerator`
|
|
212
191
|
|
|
213
192
|
Determines how variables are renamed.
|
|
@@ -392,8 +371,11 @@ yAt1T_y(-93)["log"]("Hello World");
|
|
|
392
371
|
```
|
|
393
372
|
|
|
394
373
|
### `stringCompression`
|
|
374
|
+
|
|
395
375
|
String Compression uses LZW's compression algorithm to compress strings. (`true/false/0-1`)
|
|
396
376
|
|
|
377
|
+
Use a number to control the percentage of strings.
|
|
378
|
+
|
|
397
379
|
`"console"` -> `inflate('replaĕ!ğğuģģ<~@')`
|
|
398
380
|
|
|
399
381
|
### `stringConcealing`
|
|
@@ -666,9 +648,8 @@ function getAreaOfCircle(radius) {
|
|
|
666
648
|
}
|
|
667
649
|
|
|
668
650
|
// Output
|
|
669
|
-
function getAreaOfCircle(yLu5YB1) {
|
|
670
|
-
|
|
671
|
-
var F8QuPL = Math["PI"];
|
|
651
|
+
function getAreaOfCircle(yLu5YB1, eUf7Wle, XVYH4D, F8QuPL) {
|
|
652
|
+
F8QuPL = Math["PI"];
|
|
672
653
|
typeof ((eUf7Wle = Math["pow"](yLu5YB1, 2)), (XVYH4D = F8QuPL * eUf7Wle));
|
|
673
654
|
return XVYH4D;
|
|
674
655
|
}
|
|
@@ -835,7 +816,11 @@ These features are experimental or a security concern.
|
|
|
835
816
|
// experimental
|
|
836
817
|
identifierGenerator: function(){
|
|
837
818
|
return "myvar_" + (counter++);
|
|
838
|
-
}
|
|
819
|
+
},
|
|
820
|
+
|
|
821
|
+
// Modified functions will retain the correct `function.length` property.
|
|
822
|
+
// Enabled by default.
|
|
823
|
+
preserveFunctionLength: false
|
|
839
824
|
}
|
|
840
825
|
```
|
|
841
826
|
|
package/dist/compiler.js
CHANGED
|
@@ -5,22 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.compileJsSync = compileJsSync;
|
|
7
7
|
exports.default = compileJs;
|
|
8
|
-
|
|
9
8
|
const escodegen = require("escodegen");
|
|
10
|
-
|
|
11
9
|
async function compileJs(tree, options) {
|
|
12
10
|
return compileJsSync(tree, options);
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
function compileJsSync(tree, options) {
|
|
16
13
|
var api = {
|
|
17
|
-
format: {
|
|
14
|
+
format: {
|
|
15
|
+
...escodegen.FORMAT_MINIFY
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
|
-
|
|
21
18
|
if (!options.compact) {
|
|
22
19
|
api = {};
|
|
23
|
-
|
|
24
20
|
if (options.indent && options.indent != 4) {
|
|
25
21
|
api.format = {};
|
|
26
22
|
api.format.indent = {
|
|
@@ -31,10 +27,8 @@ function compileJsSync(tree, options) {
|
|
|
31
27
|
};
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
if (options.debugComments) {
|
|
36
31
|
api.comment = true;
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
return escodegen.generate(tree, api);
|
|
40
34
|
}
|
package/dist/constants.js
CHANGED
|
@@ -3,20 +3,27 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.reservedKeywords = exports.reservedIdentifiers = exports.placeholderVariablePrefix = exports.noRenameVariablePrefix = void 0;
|
|
7
|
-
|
|
6
|
+
exports.reservedKeywords = exports.reservedIdentifiers = exports.predictableFunctionTag = exports.placeholderVariablePrefix = exports.noRenameVariablePrefix = exports.criticalFunctionTag = void 0;
|
|
8
7
|
/**
|
|
9
8
|
* Keywords disallowed for variable names in ES5 and under.
|
|
10
9
|
*/
|
|
11
|
-
const reservedKeywords = new Set(["abstract", "arguments", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield"]);
|
|
10
|
+
const reservedKeywords = exports.reservedKeywords = new Set(["abstract", "arguments", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield"]);
|
|
11
|
+
|
|
12
12
|
/**
|
|
13
13
|
* Identifiers that are not actually variables.
|
|
14
14
|
*/
|
|
15
|
+
const reservedIdentifiers = exports.reservedIdentifiers = new Set(["undefined", "null", "NaN", "Infinity", "eval", "arguments"]);
|
|
16
|
+
const noRenameVariablePrefix = exports.noRenameVariablePrefix = "__NO_JS_CONFUSER_RENAME__";
|
|
17
|
+
const placeholderVariablePrefix = exports.placeholderVariablePrefix = "__p_";
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
exports.
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Tells the obfuscator this function is predictable:
|
|
21
|
+
* - Never called with extraneous parameters
|
|
22
|
+
*/
|
|
23
|
+
const predictableFunctionTag = exports.predictableFunctionTag = "__JS_PREDICT__";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Tells the obfuscator this function is critical for the Obfuscated code.
|
|
27
|
+
* - Example: string decryption function
|
|
28
|
+
*/
|
|
29
|
+
const criticalFunctionTag = exports.criticalFunctionTag = "__JS_CRITICAL__";
|
package/dist/index.js
CHANGED
|
@@ -24,29 +24,17 @@ Object.defineProperty(exports, "presets", {
|
|
|
24
24
|
return _presets.default;
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
-
|
|
28
27
|
var _compiler = _interopRequireWildcard(require("./compiler"));
|
|
29
|
-
|
|
30
28
|
var _parser = _interopRequireWildcard(require("./parser"));
|
|
31
|
-
|
|
32
29
|
var _obfuscator = _interopRequireDefault(require("./obfuscator"));
|
|
33
|
-
|
|
34
30
|
var _transform = _interopRequireDefault(require("./transforms/transform"));
|
|
35
|
-
|
|
36
31
|
var _object = require("./util/object");
|
|
37
|
-
|
|
38
32
|
var _presets = _interopRequireDefault(require("./presets"));
|
|
39
|
-
|
|
40
33
|
var assert = _interopRequireWildcard(require("assert"));
|
|
41
|
-
|
|
42
34
|
var _options = require("./options");
|
|
43
|
-
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
47
|
-
|
|
48
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
49
|
-
|
|
35
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
36
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
37
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
50
38
|
/**
|
|
51
39
|
* **JsConfuser**: Obfuscates JavaScript.
|
|
52
40
|
* @param code - The code to be obfuscated.
|
|
@@ -55,6 +43,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
55
43
|
async function obfuscate(code, options) {
|
|
56
44
|
return await JsConfuser(code, options);
|
|
57
45
|
}
|
|
46
|
+
|
|
58
47
|
/**
|
|
59
48
|
* Obfuscates an [ESTree](https://github.com/estree/estree) compliant AST.
|
|
60
49
|
*
|
|
@@ -65,8 +54,6 @@ async function obfuscate(code, options) {
|
|
|
65
54
|
*
|
|
66
55
|
* [See all settings here](https://github.com/MichaelXF/js-confuser#options)
|
|
67
56
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
57
|
async function obfuscateAST(AST, options) {
|
|
71
58
|
assert.ok(typeof AST === "object", "AST must be type object");
|
|
72
59
|
assert.ok(AST.type == "Program", "AST.type must be equal to 'Program'");
|
|
@@ -77,18 +64,16 @@ async function obfuscateAST(AST, options) {
|
|
|
77
64
|
options.verbose && console.log("* Removing $ properties");
|
|
78
65
|
(0, _object.remove$Properties)(AST);
|
|
79
66
|
}
|
|
67
|
+
|
|
80
68
|
/**
|
|
81
69
|
* **JsConfuser**: Obfuscates JavaScript.
|
|
82
70
|
* @param code - The code to be obfuscated.
|
|
83
71
|
* @param options - An object of obfuscation options: `{preset: "medium", target: "browser"}`.
|
|
84
72
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
73
|
var JsConfuser = async function (code, options) {
|
|
88
74
|
if (typeof code !== "string") {
|
|
89
75
|
throw new TypeError("code must be type string");
|
|
90
76
|
}
|
|
91
|
-
|
|
92
77
|
(0, _options.validateOptions)(options);
|
|
93
78
|
options = await (0, _options.correctOptions)(options);
|
|
94
79
|
options.verbose && console.log("* Parsing source code");
|
|
@@ -102,7 +87,6 @@ var JsConfuser = async function (code, options) {
|
|
|
102
87
|
var result = await (0, _compiler.default)(tree, options);
|
|
103
88
|
return result;
|
|
104
89
|
};
|
|
105
|
-
|
|
106
90
|
const debugTransformations = async function (code, options) {
|
|
107
91
|
(0, _options.validateOptions)(options);
|
|
108
92
|
options = await (0, _options.correctOptions)(options);
|
|
@@ -121,6 +105,7 @@ const debugTransformations = async function (code, options) {
|
|
|
121
105
|
await obfuscator.apply(tree, true);
|
|
122
106
|
return frames;
|
|
123
107
|
};
|
|
108
|
+
|
|
124
109
|
/**
|
|
125
110
|
* This method is used by the obfuscator website to display a progress bar and additional information
|
|
126
111
|
* about the obfuscation.
|
|
@@ -130,10 +115,7 @@ const debugTransformations = async function (code, options) {
|
|
|
130
115
|
* @param callback - Progress callback, called after each transformation
|
|
131
116
|
* @returns
|
|
132
117
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
118
|
exports.debugTransformations = debugTransformations;
|
|
136
|
-
|
|
137
119
|
const debugObfuscation = async function (code, options, callback, performance) {
|
|
138
120
|
const startTime = performance.now();
|
|
139
121
|
(0, _options.validateOptions)(options);
|
|
@@ -166,7 +148,6 @@ const debugObfuscation = async function (code, options, callback, performance) {
|
|
|
166
148
|
totalPossibleTransforms: obfuscator.totalPossibleTransforms
|
|
167
149
|
};
|
|
168
150
|
};
|
|
169
|
-
|
|
170
151
|
exports.debugObfuscation = debugObfuscation;
|
|
171
152
|
JsConfuser.obfuscate = obfuscate;
|
|
172
153
|
JsConfuser.obfuscateAST = obfuscateAST;
|
|
@@ -175,14 +156,10 @@ JsConfuser.debugTransformations = debugTransformations;
|
|
|
175
156
|
JsConfuser.debugObfuscation = debugObfuscation;
|
|
176
157
|
JsConfuser.Obfuscator = _obfuscator.default;
|
|
177
158
|
JsConfuser.Transform = _transform.default;
|
|
178
|
-
|
|
179
159
|
if (typeof window !== "undefined") {
|
|
180
160
|
window["JsConfuser"] = JsConfuser;
|
|
181
161
|
}
|
|
182
|
-
|
|
183
162
|
if (typeof global !== "undefined") {
|
|
184
163
|
global["JsConfuser"] = JsConfuser;
|
|
185
164
|
}
|
|
186
|
-
|
|
187
|
-
var _default = JsConfuser;
|
|
188
|
-
exports.default = _default;
|
|
165
|
+
var _default = exports.default = JsConfuser;
|
package/dist/obfuscator.js
CHANGED
|
@@ -4,110 +4,72 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _assert = require("assert");
|
|
9
|
-
|
|
10
8
|
var _events = require("events");
|
|
11
|
-
|
|
12
9
|
var _traverse = _interopRequireDefault(require("./traverse"));
|
|
13
|
-
|
|
14
10
|
var _probability = require("./probability");
|
|
15
|
-
|
|
16
11
|
var _preparation = _interopRequireDefault(require("./transforms/preparation"));
|
|
17
|
-
|
|
18
12
|
var _objectExtraction = _interopRequireDefault(require("./transforms/extraction/objectExtraction"));
|
|
19
|
-
|
|
20
13
|
var _lock = _interopRequireDefault(require("./transforms/lock/lock"));
|
|
21
|
-
|
|
22
14
|
var _dispatcher = _interopRequireDefault(require("./transforms/dispatcher"));
|
|
23
|
-
|
|
24
15
|
var _deadCode = _interopRequireDefault(require("./transforms/deadCode"));
|
|
25
|
-
|
|
26
16
|
var _opaquePredicates = _interopRequireDefault(require("./transforms/opaquePredicates"));
|
|
27
|
-
|
|
28
17
|
var _calculator = _interopRequireDefault(require("./transforms/calculator"));
|
|
29
|
-
|
|
30
18
|
var _controlFlowFlattening = _interopRequireDefault(require("./transforms/controlFlowFlattening/controlFlowFlattening"));
|
|
31
|
-
|
|
32
19
|
var _globalConcealing = _interopRequireDefault(require("./transforms/identifier/globalConcealing"));
|
|
33
|
-
|
|
34
20
|
var _stringSplitting = _interopRequireDefault(require("./transforms/string/stringSplitting"));
|
|
35
|
-
|
|
36
21
|
var _stringConcealing = _interopRequireDefault(require("./transforms/string/stringConcealing"));
|
|
37
|
-
|
|
38
22
|
var _stringCompression = _interopRequireDefault(require("./transforms/string/stringCompression"));
|
|
39
|
-
|
|
40
23
|
var _duplicateLiteralsRemoval = _interopRequireDefault(require("./transforms/extraction/duplicateLiteralsRemoval"));
|
|
41
|
-
|
|
42
24
|
var _shuffle = _interopRequireDefault(require("./transforms/shuffle"));
|
|
43
|
-
|
|
44
25
|
var _movedDeclarations = _interopRequireDefault(require("./transforms/identifier/movedDeclarations"));
|
|
45
|
-
|
|
46
26
|
var _renameVariables = _interopRequireDefault(require("./transforms/identifier/renameVariables"));
|
|
47
|
-
|
|
48
27
|
var _renameLabels = _interopRequireDefault(require("./transforms/renameLabels"));
|
|
49
|
-
|
|
50
28
|
var _minify = _interopRequireDefault(require("./transforms/minify"));
|
|
51
|
-
|
|
52
29
|
var _es = _interopRequireDefault(require("./transforms/es5/es5"));
|
|
53
|
-
|
|
54
30
|
var _rgf = _interopRequireDefault(require("./transforms/rgf"));
|
|
55
|
-
|
|
56
31
|
var _flatten = _interopRequireDefault(require("./transforms/flatten"));
|
|
57
|
-
|
|
58
32
|
var _stack = _interopRequireDefault(require("./transforms/stack"));
|
|
59
|
-
|
|
60
33
|
var _antiTooling = _interopRequireDefault(require("./transforms/antiTooling"));
|
|
61
|
-
|
|
62
34
|
var _finalizer = _interopRequireDefault(require("./transforms/finalizer"));
|
|
63
|
-
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
function
|
|
67
|
-
|
|
35
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
36
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
37
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
38
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
68
39
|
/**
|
|
69
40
|
* The parent transformation holding the `state`.
|
|
70
41
|
*/
|
|
71
42
|
class Obfuscator extends _events.EventEmitter {
|
|
72
43
|
constructor(options) {
|
|
73
44
|
var _this;
|
|
74
|
-
|
|
75
45
|
super();
|
|
76
46
|
_this = this;
|
|
77
47
|
this.options = options;
|
|
78
|
-
|
|
79
48
|
_defineProperty(this, "varCount", void 0);
|
|
80
|
-
|
|
81
49
|
_defineProperty(this, "transforms", void 0);
|
|
82
|
-
|
|
83
50
|
_defineProperty(this, "array", void 0);
|
|
84
|
-
|
|
85
51
|
_defineProperty(this, "state", "transform");
|
|
86
|
-
|
|
87
52
|
_defineProperty(this, "generated", void 0);
|
|
88
|
-
|
|
89
53
|
_defineProperty(this, "totalPossibleTransforms", void 0);
|
|
90
|
-
|
|
91
54
|
this.varCount = 0;
|
|
92
55
|
this.transforms = Object.create(null);
|
|
93
56
|
this.generated = new Set();
|
|
94
57
|
this.totalPossibleTransforms = 0;
|
|
95
|
-
|
|
96
58
|
const test = function (map) {
|
|
97
59
|
for (var _len = arguments.length, transformers = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
98
60
|
transformers[_key - 1] = arguments[_key];
|
|
99
61
|
}
|
|
100
|
-
|
|
101
62
|
_this.totalPossibleTransforms += transformers.length;
|
|
102
|
-
|
|
103
63
|
if ((0, _probability.isProbabilityMapProbable)(map)) {
|
|
104
64
|
// options.verbose && console.log("+ Added " + transformer.name);
|
|
65
|
+
|
|
105
66
|
transformers.forEach(Transformer => _this.push(new Transformer(_this)));
|
|
106
|
-
} else {
|
|
67
|
+
} else {
|
|
68
|
+
// options.verbose && console.log("- Skipped adding " + transformer.name);
|
|
107
69
|
}
|
|
108
|
-
};
|
|
109
|
-
|
|
70
|
+
};
|
|
110
71
|
|
|
72
|
+
// Optimization: Only add needed transformers. If a probability always return false, no need in running that extra code.
|
|
111
73
|
test(true, _preparation.default);
|
|
112
74
|
test(true, _renameLabels.default);
|
|
113
75
|
test(options.objectExtraction, _objectExtraction.default);
|
|
@@ -134,28 +96,25 @@ class Obfuscator extends _events.EventEmitter {
|
|
|
134
96
|
|
|
135
97
|
if (options.lock && Object.keys(options.lock).filter(x => x == "domainLock" ? options.lock.domainLock && options.lock.domainLock.length : options.lock[x]).length) {
|
|
136
98
|
test(true, _lock.default);
|
|
137
|
-
}
|
|
138
|
-
|
|
99
|
+
}
|
|
139
100
|
|
|
140
|
-
|
|
101
|
+
// Make array
|
|
102
|
+
this.array = Object.values(this.transforms);
|
|
141
103
|
|
|
104
|
+
// Sort transformations based on their priority
|
|
142
105
|
this.array.sort((a, b) => a.priority - b.priority);
|
|
143
106
|
}
|
|
144
|
-
|
|
145
107
|
push(transform) {
|
|
146
108
|
if (transform.className) {
|
|
147
109
|
(0, _assert.ok)(!this.transforms[transform.className], "Already have " + transform.className);
|
|
148
110
|
}
|
|
149
|
-
|
|
150
111
|
this.transforms[transform.className] = transform;
|
|
151
112
|
}
|
|
152
|
-
|
|
153
113
|
resetState() {
|
|
154
114
|
this.varCount = 0;
|
|
155
115
|
this.generated = new Set();
|
|
156
116
|
this.state = "transform";
|
|
157
117
|
}
|
|
158
|
-
|
|
159
118
|
async apply(tree) {
|
|
160
119
|
let debugMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
161
120
|
(0, _assert.ok)(tree.type == "Program", "The root node must be type 'Program'");
|
|
@@ -163,22 +122,19 @@ class Obfuscator extends _events.EventEmitter {
|
|
|
163
122
|
(0, _assert.ok)(Array.isArray(this.array));
|
|
164
123
|
this.resetState();
|
|
165
124
|
var completed = 0;
|
|
166
|
-
|
|
167
125
|
for (var transform of this.array) {
|
|
168
126
|
await transform.apply(tree);
|
|
169
127
|
completed++;
|
|
170
|
-
|
|
171
128
|
if (debugMode) {
|
|
172
129
|
this.emit("debug", transform.className, tree, completed);
|
|
173
130
|
}
|
|
174
131
|
}
|
|
175
|
-
|
|
176
132
|
if (this.options.verbose) {
|
|
177
133
|
console.log("-> Check for Eval Callbacks");
|
|
178
134
|
}
|
|
135
|
+
this.state = "eval";
|
|
179
136
|
|
|
180
|
-
|
|
181
|
-
|
|
137
|
+
// Find eval callbacks
|
|
182
138
|
(0, _traverse.default)(tree, (o, p) => {
|
|
183
139
|
if (o.$eval) {
|
|
184
140
|
return () => {
|
|
@@ -186,12 +142,9 @@ class Obfuscator extends _events.EventEmitter {
|
|
|
186
142
|
};
|
|
187
143
|
}
|
|
188
144
|
});
|
|
189
|
-
|
|
190
145
|
if (this.options.verbose) {
|
|
191
146
|
console.log("<- Done");
|
|
192
147
|
}
|
|
193
148
|
}
|
|
194
|
-
|
|
195
149
|
}
|
|
196
|
-
|
|
197
150
|
exports.default = Obfuscator;
|
package/dist/options.js
CHANGED
|
@@ -5,116 +5,101 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.correctOptions = correctOptions;
|
|
7
7
|
exports.validateOptions = validateOptions;
|
|
8
|
-
|
|
9
8
|
var _assert = require("assert");
|
|
10
|
-
|
|
11
9
|
var _presets = _interopRequireDefault(require("./presets"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const validProperties = new Set(["preset", "target", "indent", "compact", "hexadecimalNumbers", "minify", "es5", "renameVariables", "renameGlobals", "identifierGenerator", "controlFlowFlattening", "globalConcealing", "stringCompression", "stringConcealing", "stringEncoding", "stringSplitting", "duplicateLiteralsRemoval", "dispatcher", "rgf", "objectExtraction", "flatten", "deadCode", "calculator", "lock", "movedDeclarations", "opaquePredicates", "shuffle", "stack", "verbose", "globalVariables", "debugComments"]);
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const validProperties = new Set(["preset", "target", "indent", "compact", "hexadecimalNumbers", "minify", "es5", "renameVariables", "renameGlobals", "identifierGenerator", "controlFlowFlattening", "globalConcealing", "stringCompression", "stringConcealing", "stringEncoding", "stringSplitting", "duplicateLiteralsRemoval", "dispatcher", "rgf", "objectExtraction", "flatten", "deadCode", "calculator", "lock", "movedDeclarations", "opaquePredicates", "shuffle", "stack", "verbose", "globalVariables", "debugComments", "preserveFunctionLength"]);
|
|
16
12
|
const validOses = new Set(["windows", "linux", "osx", "ios", "android"]);
|
|
17
13
|
const validBrowsers = new Set(["firefox", "chrome", "iexplorer", "edge", "safari", "opera"]);
|
|
18
|
-
|
|
19
14
|
function validateOptions(options) {
|
|
20
15
|
if (!options || Object.keys(options).length <= 1) {
|
|
21
16
|
/**
|
|
22
17
|
* Give a welcoming introduction to those who skipped the documentation.
|
|
23
18
|
*/
|
|
24
|
-
var line =
|
|
25
|
-
throw new Error(
|
|
19
|
+
var line = `You provided zero obfuscation options. By default everything is disabled.\nYou can use a preset with:\n\n> {target: '${options.target || "node"}', preset: 'high' | 'medium' | 'low'}.\n\n\nView all settings here:\nhttps://github.com/MichaelXF/js-confuser#options`;
|
|
20
|
+
throw new Error(`\n\n` + line.split("\n").map(x => `\t${x}`).join("\n") + `\n\n`);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
(0, _assert.ok)(options, "options cannot be null");
|
|
29
23
|
(0, _assert.ok)(options.target, "Missing options.target option (required, must one the following: 'browser' or 'node')");
|
|
30
|
-
(0, _assert.ok)(["browser", "node"].includes(options.target),
|
|
24
|
+
(0, _assert.ok)(["browser", "node"].includes(options.target), `'${options.target}' is not a valid target mode`);
|
|
31
25
|
Object.keys(options).forEach(key => {
|
|
32
26
|
if (!validProperties.has(key)) {
|
|
33
27
|
throw new TypeError("Invalid option: '" + key + "'");
|
|
34
28
|
}
|
|
35
29
|
});
|
|
36
|
-
|
|
37
30
|
if (options.target === "node" && options.lock && options.lock.browserLock && options.lock.browserLock.length) {
|
|
38
31
|
throw new TypeError('browserLock can only be used when target="browser"');
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
if (options.lock) {
|
|
42
34
|
// Validate browser-lock option
|
|
43
35
|
if (options.lock.browserLock && typeof options.lock.browserLock !== "undefined") {
|
|
44
36
|
(0, _assert.ok)(Array.isArray(options.lock.browserLock), "browserLock must be an array");
|
|
45
37
|
(0, _assert.ok)(!options.lock.browserLock.find(browserName => !validBrowsers.has(browserName)), 'Invalid browser name. Allowed: "firefox", "chrome", "iexplorer", "edge", "safari", "opera"');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
}
|
|
39
|
+
// Validate os-lock option
|
|
49
40
|
if (options.lock.osLock && typeof options.lock.osLock !== "undefined") {
|
|
50
41
|
(0, _assert.ok)(Array.isArray(options.lock.osLock), "osLock must be an array");
|
|
51
42
|
(0, _assert.ok)(!options.lock.osLock.find(osName => !validOses.has(osName)), 'Invalid OS name. Allowed: "windows", "linux", "osx", "ios", "android"');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
}
|
|
44
|
+
// Validate domain-lock option
|
|
55
45
|
if (options.lock.domainLock && typeof options.lock.domainLock !== "undefined") {
|
|
56
46
|
(0, _assert.ok)(Array.isArray(options.lock.domainLock), "domainLock must be an array");
|
|
57
|
-
}
|
|
58
|
-
|
|
47
|
+
}
|
|
59
48
|
|
|
49
|
+
// Validate context option
|
|
60
50
|
if (options.lock.context && typeof options.lock.context !== "undefined") {
|
|
61
51
|
(0, _assert.ok)(Array.isArray(options.lock.context), "context must be an array");
|
|
62
|
-
}
|
|
63
|
-
|
|
52
|
+
}
|
|
64
53
|
|
|
54
|
+
// Validate start-date option
|
|
65
55
|
if (typeof options.lock.startDate !== "undefined" && options.lock.startDate) {
|
|
66
56
|
(0, _assert.ok)(typeof options.lock.startDate === "number" || options.lock.startDate instanceof Date, "startDate must be Date object or number");
|
|
67
|
-
}
|
|
68
|
-
|
|
57
|
+
}
|
|
69
58
|
|
|
59
|
+
// Validate end-date option
|
|
70
60
|
if (typeof options.lock.endDate !== "undefined" && options.lock.endDate) {
|
|
71
61
|
(0, _assert.ok)(typeof options.lock.endDate === "number" || options.lock.endDate instanceof Date, "endDate must be Date object or number");
|
|
72
62
|
}
|
|
73
63
|
}
|
|
74
|
-
|
|
75
64
|
if (options.preset) {
|
|
76
65
|
if (!_presets.default[options.preset]) {
|
|
77
66
|
throw new TypeError("Unknown preset of '" + options.preset + "'");
|
|
78
67
|
}
|
|
79
68
|
}
|
|
80
69
|
}
|
|
70
|
+
|
|
81
71
|
/**
|
|
82
72
|
* Corrects the user's options. Sets the default values and validates the configuration.
|
|
83
73
|
* @param options
|
|
84
74
|
* @returns
|
|
85
75
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
76
|
async function correctOptions(options) {
|
|
89
77
|
if (options.preset) {
|
|
90
78
|
// Clone and allow overriding
|
|
91
79
|
options = Object.assign({}, _presets.default[options.preset], options);
|
|
92
80
|
}
|
|
93
|
-
|
|
94
81
|
if (!options.hasOwnProperty("debugComments")) {
|
|
95
82
|
options.debugComments = false; // debugComments is off by default
|
|
96
83
|
}
|
|
97
|
-
|
|
98
84
|
if (!options.hasOwnProperty("compact")) {
|
|
99
85
|
options.compact = true; // Compact is on by default
|
|
100
86
|
}
|
|
101
|
-
|
|
102
87
|
if (!options.hasOwnProperty("renameGlobals")) {
|
|
103
88
|
options.renameGlobals = true; // RenameGlobals is on by default
|
|
104
89
|
}
|
|
105
|
-
|
|
90
|
+
if (!options.hasOwnProperty("preserveFunctionLength")) {
|
|
91
|
+
options.preserveFunctionLength = true; // preserveFunctionLength is on by default
|
|
92
|
+
}
|
|
106
93
|
if (options.globalVariables && !(options.globalVariables instanceof Set)) {
|
|
107
94
|
options.globalVariables = new Set(Object.keys(options.globalVariables));
|
|
108
95
|
}
|
|
109
|
-
|
|
110
96
|
if (options.lock && options.lock.selfDefending) {
|
|
111
97
|
options.compact = true; // self defending forcibly enables this
|
|
112
|
-
}
|
|
113
|
-
|
|
98
|
+
}
|
|
114
99
|
|
|
100
|
+
// options.globalVariables outlines generic globals that should be present in the execution context
|
|
115
101
|
if (!options.hasOwnProperty("globalVariables")) {
|
|
116
102
|
options.globalVariables = new Set([]);
|
|
117
|
-
|
|
118
103
|
if (options.target == "browser") {
|
|
119
104
|
// browser
|
|
120
105
|
["window", "document", "postMessage", "alert", "confirm", "location", "btoa", "atob", "unescape", "encodeURIComponent"].forEach(x => options.globalVariables.add(x));
|
|
@@ -122,9 +107,7 @@ async function correctOptions(options) {
|
|
|
122
107
|
// node
|
|
123
108
|
["global", "Buffer", "require", "process", "exports", "module", "__dirname", "__filename"].forEach(x => options.globalVariables.add(x));
|
|
124
109
|
}
|
|
125
|
-
|
|
126
110
|
["globalThis", "console", "parseInt", "parseFloat", "Math", "JSON", "Promise", "String", "Boolean", "Function", "Object", "Array", "Proxy", "Error", "TypeError", "ReferenceError", "RangeError", "EvalError", "setTimeout", "clearTimeout", "setInterval", "clearInterval", "setImmediate", "clearImmediate", "queueMicrotask", "isNaN", "isFinite", "Set", "Map", "WeakSet", "WeakMap", "Symbol"].forEach(x => options.globalVariables.add(x));
|
|
127
111
|
}
|
|
128
|
-
|
|
129
112
|
return options;
|
|
130
113
|
}
|