js-confuser 1.5.9 → 1.7.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/workflows/node.js.yml +2 -2
- package/CHANGELOG.md +55 -0
- package/README.md +346 -165
- package/dist/constants.js +6 -2
- package/dist/index.js +9 -21
- package/dist/obfuscator.js +19 -31
- package/dist/options.js +5 -5
- package/dist/order.js +1 -3
- package/dist/presets.js +6 -7
- package/dist/probability.js +2 -4
- package/dist/templates/bufferToString.js +13 -0
- package/dist/templates/crash.js +3 -3
- package/dist/templates/es5.js +18 -0
- package/dist/templates/functionLength.js +16 -0
- package/dist/transforms/calculator.js +77 -21
- package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +980 -367
- package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +4 -1
- package/dist/transforms/controlFlowFlattening/switchCaseObfuscation.js +25 -26
- package/dist/transforms/deadCode.js +33 -25
- package/dist/transforms/dispatcher.js +8 -4
- package/dist/transforms/es5/antiDestructuring.js +2 -0
- package/dist/transforms/es5/es5.js +31 -34
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +92 -58
- package/dist/transforms/finalizer.js +82 -0
- package/dist/transforms/flatten.js +229 -148
- package/dist/transforms/identifier/globalAnalysis.js +88 -0
- package/dist/transforms/identifier/globalConcealing.js +10 -83
- package/dist/transforms/identifier/movedDeclarations.js +35 -88
- package/dist/transforms/identifier/renameVariables.js +124 -59
- package/dist/transforms/identifier/variableAnalysis.js +58 -62
- package/dist/transforms/lock/lock.js +0 -37
- package/dist/transforms/minify.js +60 -57
- package/dist/transforms/opaquePredicates.js +1 -1
- package/dist/transforms/preparation/preparation.js +2 -2
- package/dist/transforms/preparation.js +231 -0
- package/dist/transforms/renameLabels.js +1 -1
- package/dist/transforms/rgf.js +139 -247
- package/dist/transforms/stack.js +128 -26
- package/dist/transforms/string/encoding.js +150 -179
- package/dist/transforms/string/stringCompression.js +14 -15
- package/dist/transforms/string/stringConcealing.js +25 -8
- package/dist/transforms/string/stringEncoding.js +13 -24
- package/dist/transforms/transform.js +12 -19
- package/dist/traverse.js +24 -10
- package/dist/util/gen.js +17 -1
- package/dist/util/identifiers.js +37 -3
- package/dist/util/insert.js +35 -4
- package/dist/util/random.js +15 -0
- package/docs/ControlFlowFlattening.md +595 -0
- package/{Countermeasures.md → docs/Countermeasures.md} +1 -15
- package/{Integrity.md → docs/Integrity.md} +2 -2
- package/docs/RGF.md +419 -0
- package/package.json +5 -5
- package/src/constants.ts +3 -0
- package/src/index.ts +2 -2
- package/src/obfuscator.ts +19 -31
- package/src/options.ts +14 -103
- package/src/order.ts +1 -5
- package/src/presets.ts +6 -7
- package/src/probability.ts +2 -3
- package/src/templates/bufferToString.ts +68 -0
- package/src/templates/crash.ts +15 -19
- package/src/templates/es5.ts +131 -0
- package/src/templates/functionLength.ts +14 -0
- package/src/transforms/calculator.ts +122 -59
- package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +1583 -571
- package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +4 -1
- package/src/transforms/deadCode.ts +383 -26
- package/src/transforms/dispatcher.ts +9 -4
- package/src/transforms/es5/antiDestructuring.ts +2 -0
- package/src/transforms/es5/es5.ts +32 -77
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +133 -129
- package/src/transforms/{hexadecimalNumbers.ts → finalizer.ts} +29 -13
- package/src/transforms/flatten.ts +357 -300
- package/src/transforms/identifier/globalAnalysis.ts +85 -0
- package/src/transforms/identifier/globalConcealing.ts +14 -103
- package/src/transforms/identifier/movedDeclarations.ts +49 -102
- package/src/transforms/identifier/renameVariables.ts +149 -78
- package/src/transforms/identifier/variableAnalysis.ts +66 -73
- package/src/transforms/lock/lock.ts +1 -42
- package/src/transforms/minify.ts +91 -75
- package/src/transforms/opaquePredicates.ts +2 -2
- package/src/transforms/preparation.ts +238 -0
- package/src/transforms/renameLabels.ts +2 -2
- package/src/transforms/rgf.ts +213 -405
- package/src/transforms/stack.ts +156 -36
- package/src/transforms/string/encoding.ts +115 -212
- package/src/transforms/string/stringCompression.ts +27 -18
- package/src/transforms/string/stringConcealing.ts +39 -9
- package/src/transforms/string/stringEncoding.ts +18 -18
- package/src/transforms/transform.ts +21 -23
- package/src/traverse.ts +23 -4
- package/src/types.ts +2 -1
- package/src/util/gen.ts +28 -3
- package/src/util/identifiers.ts +43 -2
- package/src/util/insert.ts +38 -3
- package/src/util/random.ts +13 -0
- package/test/code/Cash.test.ts +1 -1
- package/test/code/Dynamic.test.ts +12 -10
- package/test/code/ES6.src.js +146 -0
- package/test/code/ES6.test.ts +28 -2
- package/test/index.test.ts +2 -1
- package/test/probability.test.ts +44 -0
- package/test/templates/template.test.ts +1 -1
- package/test/transforms/antiTooling.test.ts +22 -0
- package/test/transforms/calculator.test.ts +40 -0
- package/test/transforms/controlFlowFlattening/controlFlowFlattening.test.ts +702 -160
- package/test/transforms/controlFlowFlattening/expressionObfuscation.test.ts +173 -0
- package/test/transforms/deadCode.test.ts +66 -15
- package/test/transforms/dispatcher.test.ts +20 -1
- package/test/transforms/es5/antiDestructuring.test.ts +16 -0
- package/test/transforms/flatten.test.ts +399 -86
- package/test/transforms/identifier/movedDeclarations.test.ts +63 -8
- package/test/transforms/identifier/renameVariables.test.ts +119 -0
- package/test/transforms/lock/antiDebug.test.ts +2 -2
- package/test/transforms/lock/lock.test.ts +1 -48
- package/test/transforms/minify.test.ts +104 -0
- package/test/transforms/preparation.test.ts +157 -0
- package/test/transforms/rgf.test.ts +261 -381
- package/test/transforms/stack.test.ts +143 -21
- package/test/transforms/string/stringCompression.test.ts +39 -0
- package/test/transforms/string/stringConcealing.test.ts +82 -0
- package/test/transforms/string/stringEncoding.test.ts +53 -2
- package/test/transforms/transform.test.ts +66 -0
- package/test/traverse.test.ts +139 -0
- package/test/util/identifiers.test.ts +113 -1
- package/test/util/insert.test.ts +57 -3
- package/src/transforms/controlFlowFlattening/choiceFlowObfuscation.ts +0 -87
- package/src/transforms/controlFlowFlattening/controlFlowObfuscation.ts +0 -203
- package/src/transforms/controlFlowFlattening/switchCaseObfuscation.ts +0 -130
- package/src/transforms/eval.ts +0 -89
- package/src/transforms/hideInitializingCode.ts +0 -432
- package/src/transforms/identifier/nameRecycling.ts +0 -280
- package/src/transforms/label.ts +0 -64
- package/src/transforms/preparation/nameConflicts.ts +0 -102
- package/src/transforms/preparation/preparation.ts +0 -176
- package/test/transforms/controlFlowFlattening/controlFlowObfuscation.test.ts +0 -101
- package/test/transforms/controlFlowFlattening/switchCaseObfuscation.test.ts +0 -120
- package/test/transforms/eval.test.ts +0 -131
- package/test/transforms/hideInitializingCode.test.ts +0 -336
- package/test/transforms/identifier/nameRecycling.test.ts +0 -205
- package/test/transforms/preparation/nameConflicts.test.ts +0 -52
- package/test/transforms/preparation/preparation.test.ts +0 -62
package/dist/transforms/stack.js
CHANGED
|
@@ -9,6 +9,8 @@ var _assert = require("assert");
|
|
|
9
9
|
|
|
10
10
|
var _order = require("../order");
|
|
11
11
|
|
|
12
|
+
var _probability = require("../probability");
|
|
13
|
+
|
|
12
14
|
var _template = _interopRequireDefault(require("../templates/template"));
|
|
13
15
|
|
|
14
16
|
var _traverse = require("../traverse");
|
|
@@ -23,6 +25,10 @@ var _random = require("../util/random");
|
|
|
23
25
|
|
|
24
26
|
var _transform = _interopRequireDefault(require("./transform"));
|
|
25
27
|
|
|
28
|
+
var _constants = require("../constants");
|
|
29
|
+
|
|
30
|
+
var _functionLength = require("../templates/functionLength");
|
|
31
|
+
|
|
26
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
33
|
|
|
28
34
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -31,9 +37,11 @@ class Stack extends _transform.default {
|
|
|
31
37
|
constructor(o) {
|
|
32
38
|
super(o, _order.ObfuscateOrder.Stack);
|
|
33
39
|
|
|
34
|
-
_defineProperty(this, "
|
|
40
|
+
_defineProperty(this, "mangledExpressionsMade", void 0);
|
|
41
|
+
|
|
42
|
+
_defineProperty(this, "functionLengthName", void 0);
|
|
35
43
|
|
|
36
|
-
this.
|
|
44
|
+
this.mangledExpressionsMade = 0;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
match(object, parents) {
|
|
@@ -41,7 +49,11 @@ class Stack extends _transform.default {
|
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
transform(object, parents) {
|
|
52
|
+
var _this = this;
|
|
53
|
+
|
|
44
54
|
return () => {
|
|
55
|
+
var _getBlockBody$;
|
|
56
|
+
|
|
45
57
|
// Uncaught SyntaxError: Getter must not have any formal parameters.
|
|
46
58
|
// Uncaught SyntaxError: Setter must have exactly one formal parameter
|
|
47
59
|
var propIndex = parents.findIndex(x => x.type === "Property" || x.type === "MethodDefinition");
|
|
@@ -52,13 +64,40 @@ class Stack extends _transform.default {
|
|
|
52
64
|
return;
|
|
53
65
|
}
|
|
54
66
|
}
|
|
67
|
+
} // Don't apply to functions with 'use strict' directive
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if ((_getBlockBody$ = (0, _insert.getBlockBody)(object.body)[0]) !== null && _getBlockBody$ !== void 0 && _getBlockBody$.directive) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!(0, _probability.ComputeProbabilityMap)(this.options.stack)) {
|
|
75
|
+
return;
|
|
55
76
|
}
|
|
56
77
|
|
|
57
78
|
var defined = new Set();
|
|
58
79
|
var referenced = new Set();
|
|
59
80
|
var illegal = new Set();
|
|
81
|
+
/**
|
|
82
|
+
* Maps old names to new indices
|
|
83
|
+
*/
|
|
84
|
+
|
|
60
85
|
var subscripts = new Map();
|
|
61
86
|
var deadValues = Object.create(null);
|
|
87
|
+
var propertyGen = this.getGenerator();
|
|
88
|
+
|
|
89
|
+
function isTransformableFunction(functionNode) {
|
|
90
|
+
if (functionNode.$requiresEval) return false; // Check for 'this'
|
|
91
|
+
|
|
92
|
+
var isIllegal = false;
|
|
93
|
+
(0, _traverse.walk)(functionNode.body, [], (o, p) => {
|
|
94
|
+
if (o.type === "ThisExpression") {
|
|
95
|
+
isIllegal = true;
|
|
96
|
+
return "EXIT";
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return !isIllegal;
|
|
100
|
+
}
|
|
62
101
|
|
|
63
102
|
function setSubscript(string, index) {
|
|
64
103
|
subscripts.set(string, index + "");
|
|
@@ -70,23 +109,35 @@ class Stack extends _transform.default {
|
|
|
70
109
|
setSubscript(param.name, subscripts.size);
|
|
71
110
|
});
|
|
72
111
|
var startingSize = subscripts.size;
|
|
112
|
+
var isIllegal = false;
|
|
73
113
|
(0, _traverse.walk)(object.body, [object, ...parents], (o, p) => {
|
|
114
|
+
if (o.type === "Identifier" && o.name === "arguments") {
|
|
115
|
+
isIllegal = true;
|
|
116
|
+
return "EXIT";
|
|
117
|
+
}
|
|
118
|
+
|
|
74
119
|
if (o.type == "Identifier") {
|
|
75
120
|
var info = (0, _identifiers.getIdentifierInfo)(o, p);
|
|
76
121
|
|
|
77
|
-
if (!info.spec.isReferenced) {
|
|
122
|
+
if (!info.spec.isReferenced || info.spec.isExported) {
|
|
78
123
|
return;
|
|
79
124
|
}
|
|
80
125
|
|
|
81
126
|
var c = info.spec.isDefined ? (0, _insert.getDefiningContext)(o, p) : (0, _insert.getReferencingContexts)(o, p).find(x => (0, _insert.isVarContext)(x));
|
|
82
127
|
|
|
83
128
|
if (c !== object) {
|
|
84
|
-
this.log(o.name + " is illegal due to different context");
|
|
129
|
+
// this.log(o.name + " is illegal due to different context");
|
|
130
|
+
illegal.add(o.name);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (o.name.startsWith(_constants.noRenameVariablePrefix)) {
|
|
85
134
|
illegal.add(o.name);
|
|
86
135
|
}
|
|
87
136
|
|
|
88
137
|
if (info.isClauseParameter || info.isFunctionParameter || (0, _insert.isForInitialize)(o, p)) {
|
|
89
|
-
this.log(
|
|
138
|
+
// this.log(
|
|
139
|
+
// o.name + " is illegal due to clause parameter/function parameter"
|
|
140
|
+
// );
|
|
90
141
|
illegal.add(o.name);
|
|
91
142
|
}
|
|
92
143
|
|
|
@@ -100,23 +151,52 @@ class Stack extends _transform.default {
|
|
|
100
151
|
}
|
|
101
152
|
|
|
102
153
|
if (info.isFunctionDeclaration) {
|
|
103
|
-
|
|
154
|
+
(0, _assert.ok)(p[0].type === "FunctionDeclaration");
|
|
155
|
+
|
|
156
|
+
if (p[0] !== object.body.body[0] || !isTransformableFunction(p[0])) {
|
|
104
157
|
illegal.add(o.name);
|
|
105
158
|
}
|
|
106
|
-
}
|
|
159
|
+
} // The new accessors will either be numbered: [index] or as a string .string
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
var newSubscript = (0, _random.choice)([subscripts.size, propertyGen.generate()]);
|
|
163
|
+
setSubscript(o.name, newSubscript);
|
|
164
|
+
defined.add(o.name); // Stack can only process single VariableDeclarations
|
|
107
165
|
|
|
108
|
-
setSubscript(o.name, subscripts.size);
|
|
109
|
-
defined.add(o.name);
|
|
110
166
|
var varIndex = p.findIndex(x => x.type == "VariableDeclaration");
|
|
111
167
|
|
|
112
|
-
if (varIndex !== -1
|
|
113
|
-
|
|
168
|
+
if (varIndex !== -1) {
|
|
169
|
+
// Invalid 'id' property (must be Identifier)
|
|
170
|
+
if (varIndex !== 2) {
|
|
171
|
+
illegal.add(o.name);
|
|
172
|
+
} else if (p[varIndex].declarations.length > 1) {
|
|
173
|
+
illegal.add(o.name);
|
|
174
|
+
} else {
|
|
175
|
+
var value = p[varIndex].declarations[0].init;
|
|
176
|
+
|
|
177
|
+
if (value && !isTransformableFunction(value)) {
|
|
178
|
+
illegal.add(o.name);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
114
181
|
}
|
|
115
182
|
} else if (info.spec.isReferenced) {
|
|
183
|
+
if (info.spec.isModified) {
|
|
184
|
+
var assignmentIndex = p.findIndex(x => x.type === "AssignmentExpression");
|
|
185
|
+
|
|
186
|
+
if (assignmentIndex !== -1) {
|
|
187
|
+
var value = p[assignmentIndex].right;
|
|
188
|
+
|
|
189
|
+
if (value && !isTransformableFunction(value)) {
|
|
190
|
+
illegal.add(o.name);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
116
195
|
referenced.add(o.name);
|
|
117
196
|
}
|
|
118
197
|
}
|
|
119
198
|
});
|
|
199
|
+
if (isIllegal) return;
|
|
120
200
|
illegal.forEach(name => {
|
|
121
201
|
defined.delete(name);
|
|
122
202
|
referenced.delete(name);
|
|
@@ -136,14 +216,15 @@ class Stack extends _transform.default {
|
|
|
136
216
|
return;
|
|
137
217
|
}
|
|
138
218
|
|
|
139
|
-
function
|
|
219
|
+
const numberLiteral = function (number) {
|
|
140
220
|
let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
141
221
|
(0, _assert.ok)(number === number);
|
|
142
222
|
|
|
143
|
-
if (typeof number !== "number" || !Object.keys(deadValues).length || depth >
|
|
223
|
+
if (typeof number !== "number" || !Object.keys(deadValues).length || depth > 4 || (0, _random.chance)(75 + depth * 15 + _this.mangledExpressionsMade / 25)) {
|
|
144
224
|
return (0, _gen.Literal)(number);
|
|
145
225
|
}
|
|
146
226
|
|
|
227
|
+
_this.mangledExpressionsMade++;
|
|
147
228
|
var opposingIndex = (0, _random.choice)(Object.keys(deadValues));
|
|
148
229
|
|
|
149
230
|
if (typeof opposingIndex === "undefined") {
|
|
@@ -153,15 +234,14 @@ class Stack extends _transform.default {
|
|
|
153
234
|
var actualValue = deadValues[opposingIndex];
|
|
154
235
|
(0, _assert.ok)(typeof actualValue === "number");
|
|
155
236
|
return (0, _gen.BinaryExpression)("-", (0, _gen.MemberExpression)((0, _gen.Identifier)(stackName), numberLiteral(isNaN(parseFloat(opposingIndex)) ? opposingIndex : parseFloat(opposingIndex), depth + 1), true), numberLiteral(actualValue - number, depth + 1));
|
|
156
|
-
}
|
|
237
|
+
};
|
|
157
238
|
|
|
158
239
|
function getMemberExpression(index) {
|
|
159
240
|
(0, _assert.ok)(typeof index === "string", typeof index);
|
|
160
241
|
return (0, _gen.MemberExpression)((0, _gen.Identifier)(stackName), numberLiteral(isNaN(parseFloat(index)) ? index : parseFloat(index)), true);
|
|
161
242
|
}
|
|
162
243
|
|
|
163
|
-
var stackName = this.getPlaceholder();
|
|
164
|
-
var made = 1;
|
|
244
|
+
var stackName = this.getPlaceholder() + "_stack";
|
|
165
245
|
|
|
166
246
|
const scan = (o, p) => {
|
|
167
247
|
if (o.type == "Identifier") {
|
|
@@ -216,8 +296,7 @@ class Stack extends _transform.default {
|
|
|
216
296
|
}
|
|
217
297
|
}
|
|
218
298
|
|
|
219
|
-
if (o.type == "Literal" && typeof o.value === "number" && Math.floor(o.value) === o.value && Math.abs(o.value) < 100000 &&
|
|
220
|
-
made++;
|
|
299
|
+
if (o.type == "Literal" && typeof o.value === "number" && Math.floor(o.value) === o.value && Math.abs(o.value) < 100000 && p.find(x => (0, _insert.isFunction)(x)) === object && (0, _random.chance)(50)) {
|
|
221
300
|
return () => {
|
|
222
301
|
this.replaceIdentifierOrLiteral(o, numberLiteral(o.value, 0), p);
|
|
223
302
|
};
|
|
@@ -228,9 +307,9 @@ class Stack extends _transform.default {
|
|
|
228
307
|
object.body.body.forEach((stmt, index) => {
|
|
229
308
|
var isFirst = index == 0;
|
|
230
309
|
|
|
231
|
-
if (isFirst ||
|
|
310
|
+
if (isFirst || (0, _random.chance)(50 - index * 10)) {
|
|
232
311
|
var exprs = [];
|
|
233
|
-
var changes = (0, _random.getRandomInteger)(
|
|
312
|
+
var changes = (0, _random.getRandomInteger)(1, 3);
|
|
234
313
|
|
|
235
314
|
for (var i = 0; i < changes; i++) {
|
|
236
315
|
var expr;
|
|
@@ -240,7 +319,7 @@ class Stack extends _transform.default {
|
|
|
240
319
|
var i = 0;
|
|
241
320
|
|
|
242
321
|
do {
|
|
243
|
-
newIndex = (0, _random.getRandomInteger)(0, 250 + subscripts.size + i * 1000) + "";
|
|
322
|
+
newIndex = (0, _random.choice)([propertyGen.generate(), (0, _random.getRandomInteger)(0, 250 + subscripts.size + i * 1000) + ""]);
|
|
244
323
|
i++;
|
|
245
324
|
} while (valueSet.has(newIndex));
|
|
246
325
|
|
|
@@ -254,9 +333,9 @@ class Stack extends _transform.default {
|
|
|
254
333
|
break;
|
|
255
334
|
|
|
256
335
|
case "deadValue":
|
|
257
|
-
var rand = (0, _random.getRandomInteger)(-
|
|
336
|
+
var rand = (0, _random.getRandomInteger)(-150, 150); // modify an already existing dead value index
|
|
258
337
|
|
|
259
|
-
if (
|
|
338
|
+
if ((0, _random.chance)(50)) {
|
|
260
339
|
var alreadyExisting = (0, _random.choice)(Object.keys(deadValues));
|
|
261
340
|
|
|
262
341
|
if (typeof alreadyExisting === "string") {
|
|
@@ -265,7 +344,6 @@ class Stack extends _transform.default {
|
|
|
265
344
|
}
|
|
266
345
|
|
|
267
346
|
expr = (0, _gen.AssignmentExpression)("=", getMemberExpression(newIndex), numberLiteral(rand));
|
|
268
|
-
(0, _assert.ok)(!subscripts.has(newIndex));
|
|
269
347
|
deadValues[newIndex] = rand;
|
|
270
348
|
break;
|
|
271
349
|
}
|
|
@@ -291,11 +369,35 @@ class Stack extends _transform.default {
|
|
|
291
369
|
|
|
292
370
|
Object.keys(rotateNodes).forEach((index, i) => {
|
|
293
371
|
object.body.body.splice(parseInt(index) + i, 0, rotateNodes[index]);
|
|
294
|
-
}); //
|
|
372
|
+
}); // Preserve function.length property
|
|
373
|
+
|
|
374
|
+
var originalFunctionLength = (0, _insert.computeFunctionLength)(object.params); // Set the params for this function to be the stack array
|
|
295
375
|
|
|
296
376
|
object.params = [(0, _gen.RestElement)((0, _gen.Identifier)(stackName))]; // Ensure the array is correct length
|
|
297
377
|
|
|
298
|
-
(0, _insert.prepend)(object.body, (0, _template.default)("".concat(stackName, "
|
|
378
|
+
(0, _insert.prepend)(object.body, (0, _template.default)("".concat(stackName, "[\"length\"] = ").concat(startingSize)).single());
|
|
379
|
+
|
|
380
|
+
if (originalFunctionLength !== 0) {
|
|
381
|
+
if (!this.functionLengthName) {
|
|
382
|
+
this.functionLengthName = this.getPlaceholder();
|
|
383
|
+
(0, _insert.prepend)(parents[parents.length - 1] || object, _functionLength.FunctionLengthTemplate.single({
|
|
384
|
+
name: this.functionLengthName
|
|
385
|
+
}));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (object.type === "FunctionDeclaration") {
|
|
389
|
+
var body = parents[0];
|
|
390
|
+
|
|
391
|
+
if (Array.isArray(body)) {
|
|
392
|
+
var index = body.indexOf(object);
|
|
393
|
+
body.splice(index, 0, (0, _gen.ExpressionStatement)((0, _gen.CallExpression)((0, _gen.Identifier)(this.functionLengthName), [(0, _gen.Identifier)(object.id.name), (0, _gen.Literal)(originalFunctionLength)])));
|
|
394
|
+
}
|
|
395
|
+
} else {
|
|
396
|
+
(0, _assert.ok)(object.type === "FunctionExpression" || object.type === "ArrowFunctionExpression");
|
|
397
|
+
this.replace(object, (0, _gen.CallExpression)((0, _gen.Identifier)(this.functionLengthName), [{ ...object
|
|
398
|
+
}, (0, _gen.Literal)(originalFunctionLength)]));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
299
401
|
};
|
|
300
402
|
}
|
|
301
403
|
|
|
@@ -10,200 +10,171 @@ var _template = _interopRequireDefault(require("../../templates/template"));
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
12
|
const Encoding = {
|
|
13
|
-
|
|
14
|
-
encode(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return function (a, b) {
|
|
41
|
-
for (var c = b; c > 0; c--) a.pop();
|
|
42
|
-
}(e, c[l]), h.fromCharCode.apply(h, e);
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
template: (0, _template.default)("\n function {name}(a, LL = [\"fromCharCode\", \"apply\"]) {\n var c, d, e, f, g, h = String, l = \"length\", w = 255, x = \"charCodeAt\", y = \"slice\", z = \"replace\";\n for (\"<~\" === a[y](0, 2) && \"~>\" === a[y](-2), a = a[y](2, -2)[z](/s/g, \"\")[z](\"z\", \"!!!!!\"), \n c = \"uuuuu\"[y](a[l] % 5 || 5), a += c, e = [], f = 0, g = a[l]; g > f; f += 5) d = 52200625 * (a[x](f) - 33) + 614125 * (a[x](f + 1) - 33) + 7225 * (a[x](f + 2) - 33) + 85 * (a[x](f + 3) - 33) + (a[x](f + 4) - 33), \n e.push(w & d >> 24, w & d >> 16, w & d >> 8, w & d);\n return function(a, b) {\n for (var c = b; c > 0; c--) a.pop();\n }(e, c[l]), h[LL[0]][LL[1]](h, e);\n }\n ")
|
|
46
|
-
},
|
|
47
|
-
base32: {
|
|
48
|
-
encode: function (s) {
|
|
49
|
-
var a = "!\"#$%&'()*+,-./0123456789:;<=>?@";
|
|
50
|
-
var len = s.length;
|
|
51
|
-
var o = "";
|
|
52
|
-
var w,
|
|
53
|
-
c,
|
|
54
|
-
r = 0,
|
|
55
|
-
sh = 0,
|
|
56
|
-
i;
|
|
57
|
-
|
|
58
|
-
for (i = 0; i < len; i += 5) {
|
|
59
|
-
// mask top 5 bits
|
|
60
|
-
c = s.charCodeAt(i);
|
|
61
|
-
w = 0xf8 & c;
|
|
62
|
-
o += a.charAt(w >> 3);
|
|
63
|
-
r = 0x07 & c;
|
|
64
|
-
sh = 2;
|
|
65
|
-
|
|
66
|
-
if (i + 1 < len) {
|
|
67
|
-
c = s.charCodeAt(i + 1); // mask top 2 bits
|
|
68
|
-
|
|
69
|
-
w = 0xc0 & c;
|
|
70
|
-
o += a.charAt((r << 2) + (w >> 6));
|
|
71
|
-
o += a.charAt((0x3e & c) >> 1);
|
|
72
|
-
r = c & 0x01;
|
|
73
|
-
sh = 4;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (i + 2 < len) {
|
|
77
|
-
c = s.charCodeAt(i + 2); // mask top 4 bits
|
|
78
|
-
|
|
79
|
-
w = 0xf0 & c;
|
|
80
|
-
o += a.charAt((r << 4) + (w >> 4));
|
|
81
|
-
r = 0x0f & c;
|
|
82
|
-
sh = 1;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (i + 3 < len) {
|
|
86
|
-
c = s.charCodeAt(i + 3); // mask top 1 bit
|
|
87
|
-
|
|
88
|
-
w = 0x80 & c;
|
|
89
|
-
o += a.charAt((r << 1) + (w >> 7));
|
|
90
|
-
o += a.charAt((0x7c & c) >> 2);
|
|
91
|
-
r = 0x03 & c;
|
|
92
|
-
sh = 3;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (i + 4 < len) {
|
|
96
|
-
c = s.charCodeAt(i + 4); // mask top 3 bits
|
|
97
|
-
|
|
98
|
-
w = 0xe0 & c;
|
|
99
|
-
o += a.charAt((r << 3) + (w >> 5));
|
|
100
|
-
o += a.charAt(0x1f & c);
|
|
101
|
-
r = 0;
|
|
102
|
-
sh = 0;
|
|
13
|
+
base91: {
|
|
14
|
+
encode(str) {
|
|
15
|
+
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~"';
|
|
16
|
+
const raw = Buffer.from(str, "utf-8");
|
|
17
|
+
const len = raw.length;
|
|
18
|
+
let ret = "";
|
|
19
|
+
let n = 0;
|
|
20
|
+
let b = 0;
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < len; i++) {
|
|
23
|
+
b |= raw[i] << n;
|
|
24
|
+
n += 8;
|
|
25
|
+
|
|
26
|
+
if (n > 13) {
|
|
27
|
+
let v = b & 8191;
|
|
28
|
+
|
|
29
|
+
if (v > 88) {
|
|
30
|
+
b >>= 13;
|
|
31
|
+
n -= 13;
|
|
32
|
+
} else {
|
|
33
|
+
v = b & 16383;
|
|
34
|
+
b >>= 14;
|
|
35
|
+
n -= 14;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
ret += table[v % 91] + table[v / 91 | 0];
|
|
103
39
|
}
|
|
104
|
-
} // Calculate length of pad by getting the
|
|
105
|
-
// number of words to reach an 8th octet.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (r != 0) {
|
|
109
|
-
o += a.charAt(r << sh);
|
|
110
40
|
}
|
|
111
41
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var v,
|
|
116
|
-
x,
|
|
117
|
-
bits = 0,
|
|
118
|
-
o = "",
|
|
119
|
-
len = s.length,
|
|
120
|
-
d = String,
|
|
121
|
-
e = "charCodeAt",
|
|
122
|
-
f = "fromCharCode",
|
|
123
|
-
i;
|
|
124
|
-
|
|
125
|
-
for (i = 0; i < len; i += 1) {
|
|
126
|
-
v = s[e](i) - 33, v >= 0 && v < 32 ? (bits += (x = x << 5 | v, 5), bits >= 8 ? bits -= (o += d[f](x >> bits - 8 & 0xff), 8) : 0) : 0;
|
|
42
|
+
if (n) {
|
|
43
|
+
ret += table[b % 91];
|
|
44
|
+
if (n > 7 || b > 90) ret += table[b / 91 | 0];
|
|
127
45
|
}
|
|
128
46
|
|
|
129
|
-
return
|
|
47
|
+
return ret;
|
|
130
48
|
},
|
|
131
|
-
template: (0, _template.default)("\n function {name}(s) {\n var v,\n x,\n b = 0,\n o = \"\",\n len = s.length,\n d = String,\n e = \"charCodeAt\",\n f = \"fromCharCode\", i;\n \n for (i = 0; i < len; i += 1) {\n (v = s[e](i) - 33),\n v >= 0 && v < 32\n ? ((b += ((x = (x << 5) | v), 5)),\n b >= 8\n ? (b -= ((o += d[f]((x >> (b - 8)) & 0xff)), 8))\n : 0)\n : 0;\n }\n return o;\n }\n ")
|
|
132
|
-
},
|
|
133
|
-
hexTable: {
|
|
134
|
-
encode: function (str) {
|
|
135
|
-
var output = "";
|
|
136
49
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
50
|
+
decode(str) {
|
|
51
|
+
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~"';
|
|
52
|
+
const raw = "" + (str || "");
|
|
53
|
+
const len = raw.length;
|
|
54
|
+
const ret = [];
|
|
55
|
+
let b = 0;
|
|
56
|
+
let n = 0;
|
|
57
|
+
let v = -1;
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < len; i++) {
|
|
60
|
+
const p = table.indexOf(raw[i]);
|
|
61
|
+
if (p === -1) continue;
|
|
62
|
+
|
|
63
|
+
if (v < 0) {
|
|
64
|
+
v = p;
|
|
65
|
+
} else {
|
|
66
|
+
v += p * 91;
|
|
67
|
+
b |= v << n;
|
|
68
|
+
n += (v & 8191) > 88 ? 13 : 14;
|
|
69
|
+
|
|
70
|
+
do {
|
|
71
|
+
ret.push(b & 0xff);
|
|
72
|
+
b >>= 8;
|
|
73
|
+
n -= 8;
|
|
74
|
+
} while (n > 7);
|
|
75
|
+
|
|
76
|
+
v = -1;
|
|
142
77
|
}
|
|
143
|
-
|
|
144
|
-
chunk = chunk + "~";
|
|
145
|
-
var uniqueChars = new Set([]);
|
|
146
|
-
|
|
147
|
-
for (var char of chunk) {
|
|
148
|
-
uniqueChars.add(char);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
var keys = Array.from(uniqueChars).sort();
|
|
152
|
-
var table = {},
|
|
153
|
-
i = 0;
|
|
154
|
-
|
|
155
|
-
for (var key of keys) {
|
|
156
|
-
table[key] = i++;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
var idx = [];
|
|
160
|
-
|
|
161
|
-
for (var char of chunk) {
|
|
162
|
-
idx.push(table[char]);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
var table64 = "0x";
|
|
166
|
-
|
|
167
|
-
for (var i = keys.length - 1; i >= 0; i--) {
|
|
168
|
-
table64 += keys[i].charCodeAt(0).toString(16).toUpperCase();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
var idxInt = 0;
|
|
172
|
-
|
|
173
|
-
for (var i = idx.length - 1; i >= 0; i--) {
|
|
174
|
-
idxInt = idxInt << 3 | idx[i];
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
var idx64 = "0x" + idxInt.toString(16).toUpperCase(); // console.log(chunk, table, idx, table64, idx64);
|
|
178
|
-
|
|
179
|
-
output += table64 + "," + idx64 + ",";
|
|
180
78
|
}
|
|
181
79
|
|
|
182
|
-
if (
|
|
183
|
-
|
|
80
|
+
if (v > -1) {
|
|
81
|
+
ret.push((b | v << n) & 0xff);
|
|
184
82
|
}
|
|
185
83
|
|
|
186
|
-
return "
|
|
84
|
+
return Buffer.from(ret).toString("utf-8");
|
|
187
85
|
},
|
|
188
|
-
decode: function (str) {
|
|
189
|
-
var output = "";
|
|
190
|
-
str = str.substring(1, str.length - 1);
|
|
191
|
-
var chunks = str.split(",");
|
|
192
|
-
|
|
193
|
-
for (var i = 0; i < chunks.length; i += 2) {
|
|
194
|
-
var arr = [chunks[i], chunks[i + 1]];
|
|
195
|
-
var [table, idx] = arr.map(Number); // console.log(table, idx);
|
|
196
|
-
|
|
197
|
-
while (idx) {
|
|
198
|
-
output += String.fromCharCode(table >> 8 * (idx & 7) & 0xff);
|
|
199
|
-
idx >>= 3;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
86
|
|
|
203
|
-
|
|
204
|
-
},
|
|
205
|
-
template: (0, _template.default)("\n function {name}(str){\n var output = \"\";\n \n str = str.substring(1, str.length - 1);\n var chunks = str.split(\",\");\n \n for (var i = 0; i < chunks.length; i += 2) {\n var arr = [chunks[i], chunks[i + 1]];\n \n var [table, idx] = arr.map(Number);\n \n // console.log(table, idx);\n while (idx) {\n output += String.fromCharCode((table >> (8 * (idx & 7))) & 0xff);\n idx >>= 3;\n }\n }\n \n return output.replace(/~/g, \"\");\n }\n \n ")
|
|
87
|
+
template: (0, _template.default)(" \n function {name}(str){\n const table =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~\"';\n\n const raw = \"\" + (str || \"\");\n const len = raw.length;\n const ret = [];\n\n let b = 0;\n let n = 0;\n let v = -1;\n\n for (let i = 0; i < len; i++) {\n const p = table.indexOf(raw[i]);\n if (p === -1) continue;\n if (v < 0) {\n v = p;\n } else {\n v += p * 91;\n b |= v << n;\n n += (v & 8191) > 88 ? 13 : 14;\n do {\n ret.push(b & 0xff);\n b >>= 8;\n n -= 8;\n } while (n > 7);\n v = -1;\n }\n }\n\n if (v > -1) {\n ret.push((b | (v << n)) & 0xff);\n }\n\n return {bufferToString}(ret);\n }\n ")
|
|
206
88
|
}
|
|
89
|
+
/* ascii85: { This implementation is flaky and causes decoding errors
|
|
90
|
+
encode(a) {
|
|
91
|
+
var b, c, d, e, f, g, h, i, j, k;
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
for (
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
!/[^\x00-\xFF]/.test(a),
|
|
96
|
+
b = "\x00\x00\x00\x00".slice(a.length % 4 || 4),
|
|
97
|
+
a += b,
|
|
98
|
+
c = [],
|
|
99
|
+
d = 0,
|
|
100
|
+
e = a.length;
|
|
101
|
+
e > d;
|
|
102
|
+
d += 4
|
|
103
|
+
)
|
|
104
|
+
(f =
|
|
105
|
+
(a.charCodeAt(d) << 24) +
|
|
106
|
+
(a.charCodeAt(d + 1) << 16) +
|
|
107
|
+
(a.charCodeAt(d + 2) << 8) +
|
|
108
|
+
a.charCodeAt(d + 3)),
|
|
109
|
+
0 !== f
|
|
110
|
+
? ((k = f % 85),
|
|
111
|
+
(f = (f - k) / 85),
|
|
112
|
+
(j = f % 85),
|
|
113
|
+
(f = (f - j) / 85),
|
|
114
|
+
(i = f % 85),
|
|
115
|
+
(f = (f - i) / 85),
|
|
116
|
+
(h = f % 85),
|
|
117
|
+
(f = (f - h) / 85),
|
|
118
|
+
(g = f % 85),
|
|
119
|
+
c.push(g + 33, h + 33, i + 33, j + 33, k + 33))
|
|
120
|
+
: c.push(122);
|
|
121
|
+
return (
|
|
122
|
+
(function (a, b) {
|
|
123
|
+
for (var c = b; c > 0; c--) a.pop();
|
|
124
|
+
})(c, b.length),
|
|
125
|
+
"<~" + String.fromCharCode.apply(String, c) + "~>"
|
|
126
|
+
);
|
|
127
|
+
},
|
|
128
|
+
decode(a) {
|
|
129
|
+
var c,
|
|
130
|
+
d,
|
|
131
|
+
e,
|
|
132
|
+
f,
|
|
133
|
+
g,
|
|
134
|
+
h = String,
|
|
135
|
+
l = "length",
|
|
136
|
+
w = 255,
|
|
137
|
+
x = "charCodeAt",
|
|
138
|
+
y = "slice",
|
|
139
|
+
z = "replace";
|
|
140
|
+
for (
|
|
141
|
+
"<~" === a[y](0, 2) && "~>" === a[y](-2),
|
|
142
|
+
a = a[y](2, -2)[z](/s/g, "")[z]("z", "!!!!!"),
|
|
143
|
+
c = "uuuuu"[y](a[l] % 5 || 5),
|
|
144
|
+
a += c,
|
|
145
|
+
e = [],
|
|
146
|
+
f = 0,
|
|
147
|
+
g = a[l];
|
|
148
|
+
g > f;
|
|
149
|
+
f += 5
|
|
150
|
+
)
|
|
151
|
+
(d =
|
|
152
|
+
52200625 * (a[x](f) - 33) +
|
|
153
|
+
614125 * (a[x](f + 1) - 33) +
|
|
154
|
+
7225 * (a[x](f + 2) - 33) +
|
|
155
|
+
85 * (a[x](f + 3) - 33) +
|
|
156
|
+
(a[x](f + 4) - 33)),
|
|
157
|
+
e.push(w & (d >> 24), w & (d >> 16), w & (d >> 8), w & d);
|
|
158
|
+
return (
|
|
159
|
+
(function (a, b) {
|
|
160
|
+
for (var c = b; c > 0; c--) a.pop();
|
|
161
|
+
})(e, c[l]),
|
|
162
|
+
h.fromCharCode.apply(h, e)
|
|
163
|
+
);
|
|
164
|
+
},
|
|
165
|
+
template: Template(`
|
|
166
|
+
function {name}(a, LL = ["fromCharCode", "apply"]) {
|
|
167
|
+
var c, d, e, f, g, h = String, l = "length", w = 255, x = "charCodeAt", y = "slice", z = "replace";
|
|
168
|
+
for ("<~" === a[y](0, 2) && "~>" === a[y](-2), a = a[y](2, -2)[z](/\s/g, "")[z]("z", "!!!!!"),
|
|
169
|
+
c = "uuuuu"[y](a[l] % 5 || 5), a += c, e = [], f = 0, g = a[l]; g > f; f += 5) d = 52200625 * (a[x](f) - 33) + 614125 * (a[x](f + 1) - 33) + 7225 * (a[x](f + 2) - 33) + 85 * (a[x](f + 3) - 33) + (a[x](f + 4) - 33),
|
|
170
|
+
e.push(w & d >> 24, w & d >> 16, w & d >> 8, w & d);
|
|
171
|
+
return function(a, b) {
|
|
172
|
+
for (var c = b; c > 0; c--) a.pop();
|
|
173
|
+
}(e, c[l]), h[LL[0]][LL[1]](h, e);
|
|
174
|
+
}
|
|
175
|
+
`),
|
|
176
|
+
}, */
|
|
177
|
+
|
|
207
178
|
};
|
|
208
179
|
var _default = Encoding;
|
|
209
180
|
exports.default = _default;
|