@delance/builder 0.2.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/LICENSE +15 -0
- package/README.md +93 -0
- package/dist/cli.js +119 -0
- package/dist/cli.js.map +18 -0
- package/dist/index.js +2577 -0
- package/dist/index.js.map +99 -0
- package/package.json +94 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2577 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, {
|
|
5
|
+
get: all[name],
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
set: (newValue) => all[name] = () => newValue
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// transform/webcrack/index.ts
|
|
13
|
+
import {getQuickJS, shouldInterruptAfterDeadline} from "quickjs-emscripten";
|
|
14
|
+
|
|
15
|
+
// node_modules/webcrack/src/deobfuscate/index.ts
|
|
16
|
+
import debug3 from "debug";
|
|
17
|
+
|
|
18
|
+
// node_modules/webcrack/src/ast-utils/ast.ts
|
|
19
|
+
import * as t from "@babel/types";
|
|
20
|
+
function getPropName(node) {
|
|
21
|
+
if (t.isIdentifier(node)) {
|
|
22
|
+
return node.name;
|
|
23
|
+
}
|
|
24
|
+
if (t.isStringLiteral(node)) {
|
|
25
|
+
return node.value;
|
|
26
|
+
}
|
|
27
|
+
if (t.isNumericLiteral(node)) {
|
|
28
|
+
return node.value.toString();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// node_modules/webcrack/src/ast-utils/generator.ts
|
|
32
|
+
import babelGenerate from "@babel/generator";
|
|
33
|
+
function generate(ast, options = defaultOptions) {
|
|
34
|
+
return babelGenerate(ast, options).code;
|
|
35
|
+
}
|
|
36
|
+
function codePreview(node) {
|
|
37
|
+
const code = generate(node, {
|
|
38
|
+
minified: true,
|
|
39
|
+
shouldPrintComment: () => false,
|
|
40
|
+
...defaultOptions
|
|
41
|
+
});
|
|
42
|
+
if (code.length > 100) {
|
|
43
|
+
return code.slice(0, 70) + " \u2026 " + code.slice(-30);
|
|
44
|
+
}
|
|
45
|
+
return code;
|
|
46
|
+
}
|
|
47
|
+
var defaultOptions = { jsescOption: { minimal: true } };
|
|
48
|
+
// node_modules/webcrack/src/ast-utils/inline.ts
|
|
49
|
+
import traverse2 from "@babel/traverse";
|
|
50
|
+
import * as t3 from "@babel/types";
|
|
51
|
+
import * as m2 from "@codemod/matchers";
|
|
52
|
+
|
|
53
|
+
// node_modules/webcrack/src/ast-utils/matcher.ts
|
|
54
|
+
import * as t2 from "@babel/types";
|
|
55
|
+
import * as m from "@codemod/matchers";
|
|
56
|
+
function infiniteLoop(body) {
|
|
57
|
+
return m.or(m.forStatement(undefined, null, undefined, body), m.forStatement(undefined, truthyMatcher, undefined, body), m.whileStatement(truthyMatcher, body));
|
|
58
|
+
}
|
|
59
|
+
function constKey(name) {
|
|
60
|
+
return m.or(m.identifier(name), m.stringLiteral(name));
|
|
61
|
+
}
|
|
62
|
+
function constObjectProperty(value) {
|
|
63
|
+
return m.or(m.objectProperty(m.identifier(), value, false), m.objectProperty(m.or(m.stringLiteral(), m.numericLiteral()), value));
|
|
64
|
+
}
|
|
65
|
+
function matchIife(body) {
|
|
66
|
+
return m.callExpression(m.functionExpression(null, [], body ? m.blockStatement(body) : undefined), []);
|
|
67
|
+
}
|
|
68
|
+
function constMemberExpression(object, property) {
|
|
69
|
+
if (typeof object === "string")
|
|
70
|
+
object = m.identifier(object);
|
|
71
|
+
return m.or(m.memberExpression(object, m.identifier(property), false), m.memberExpression(object, m.stringLiteral(property), true));
|
|
72
|
+
}
|
|
73
|
+
function findParent(path, matcher2) {
|
|
74
|
+
return path.findParent((path2) => matcher2.match(path2.node));
|
|
75
|
+
}
|
|
76
|
+
function createFunctionMatcher(params, body) {
|
|
77
|
+
const captures = Array.from({ length: params }, () => m.capture(m.anyString()));
|
|
78
|
+
return m.functionExpression(undefined, captures.map(m.identifier), m.blockStatement(body(...captures.map((c) => m.identifier(m.fromCapture(c))))));
|
|
79
|
+
}
|
|
80
|
+
function isReadonlyObject(binding, memberAccess) {
|
|
81
|
+
if (!binding.constant && binding.constantViolations[0] !== binding.path)
|
|
82
|
+
return false;
|
|
83
|
+
function isPatternAssignment(member) {
|
|
84
|
+
return member.parentPath?.isArrayPattern() || member.parentPath?.isAssignmentPattern() || member.parentPath?.parentPath?.isObjectPattern() || member.parentPath?.isAssignmentPattern();
|
|
85
|
+
}
|
|
86
|
+
return binding.referencePaths.every((path) => memberAccess.match(path.parent) && !path.parentPath?.parentPath?.isAssignmentExpression({
|
|
87
|
+
left: path.parent
|
|
88
|
+
}) && !path.parentPath?.parentPath?.isUpdateExpression({
|
|
89
|
+
argument: path.parent
|
|
90
|
+
}) && !path.parentPath?.parentPath?.isUnaryExpression({
|
|
91
|
+
argument: path.parent,
|
|
92
|
+
operator: "delete"
|
|
93
|
+
}) && !isPatternAssignment(path.parentPath));
|
|
94
|
+
}
|
|
95
|
+
function isTemporaryVariable(binding, references, kind = "var") {
|
|
96
|
+
return binding !== undefined && binding.references === references && binding.constantViolations.length === 1 && (kind === "var" ? binding.path.isVariableDeclarator() && binding.path.node.init === null : binding.path.listKey === "params" && binding.path.isIdentifier());
|
|
97
|
+
}
|
|
98
|
+
var anyLiteral = m.matcher((node) => t2.isLiteral(node) && (!t2.isTemplateLiteral(node) || node.expressions.length === 0));
|
|
99
|
+
var iife = matchIife();
|
|
100
|
+
var emptyIife = matchIife([]);
|
|
101
|
+
var trueMatcher = m.or(m.booleanLiteral(true), m.unaryExpression("!", m.numericLiteral(0)), m.unaryExpression("!", m.unaryExpression("!", m.numericLiteral(1))), m.unaryExpression("!", m.unaryExpression("!", m.arrayExpression([]))));
|
|
102
|
+
var falseMatcher = m.or(m.booleanLiteral(false), m.unaryExpression("!", m.arrayExpression([])));
|
|
103
|
+
var truthyMatcher = m.or(trueMatcher, m.arrayExpression([]));
|
|
104
|
+
|
|
105
|
+
// node_modules/webcrack/src/ast-utils/inline.ts
|
|
106
|
+
function inlineVariable(binding, value = m2.anyExpression(), unsafeAssignments = false) {
|
|
107
|
+
const varDeclarator = binding.path.node;
|
|
108
|
+
const varMatcher = m2.variableDeclarator(m2.identifier(binding.identifier.name), value);
|
|
109
|
+
const assignmentMatcher = m2.assignmentExpression("=", m2.identifier(binding.identifier.name), value);
|
|
110
|
+
if (binding.constant && varMatcher.match(varDeclarator)) {
|
|
111
|
+
binding.referencePaths.forEach((ref) => {
|
|
112
|
+
ref.replaceWith(varDeclarator.init);
|
|
113
|
+
});
|
|
114
|
+
binding.path.remove();
|
|
115
|
+
} else if (unsafeAssignments && binding.constantViolations.length === 1 && assignmentMatcher.match(binding.constantViolations[0]?.node)) {
|
|
116
|
+
const assignment = binding.constantViolations[0];
|
|
117
|
+
binding.referencePaths.forEach((ref) => {
|
|
118
|
+
ref.replaceWith(assignment.node.right);
|
|
119
|
+
});
|
|
120
|
+
assignment.remove();
|
|
121
|
+
binding.path.remove();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function inlineArrayElements(array, references) {
|
|
125
|
+
for (const reference of references) {
|
|
126
|
+
const memberPath = reference.parentPath;
|
|
127
|
+
const property = memberPath.node.property;
|
|
128
|
+
const index = property.value;
|
|
129
|
+
const replacement = array.elements[index];
|
|
130
|
+
memberPath.replaceWith(replacement);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function inlineObjectProperties(binding, property = m2.objectProperty()) {
|
|
134
|
+
const varDeclarator = binding.path.node;
|
|
135
|
+
const objectProperties = m2.capture(m2.arrayOf(property));
|
|
136
|
+
const varMatcher = m2.variableDeclarator(m2.identifier(binding.identifier.name), m2.objectExpression(objectProperties));
|
|
137
|
+
if (!varMatcher.match(varDeclarator))
|
|
138
|
+
return;
|
|
139
|
+
const propertyMap = new Map(objectProperties.current.map((p) => [getPropName(p.key), p.value]));
|
|
140
|
+
if (!binding.referencePaths.every((ref) => {
|
|
141
|
+
const member = ref.parent;
|
|
142
|
+
const propName = getPropName(member.property);
|
|
143
|
+
return propertyMap.has(propName);
|
|
144
|
+
}))
|
|
145
|
+
return;
|
|
146
|
+
binding.referencePaths.forEach((ref) => {
|
|
147
|
+
const memberPath = ref.parentPath;
|
|
148
|
+
const propName = getPropName(memberPath.node.property);
|
|
149
|
+
const value = propertyMap.get(propName);
|
|
150
|
+
memberPath.replaceWith(value);
|
|
151
|
+
});
|
|
152
|
+
binding.path.remove();
|
|
153
|
+
}
|
|
154
|
+
function inlineFunction(fn, caller) {
|
|
155
|
+
if (t3.isRestElement(fn.params[1])) {
|
|
156
|
+
caller.replaceWith(t3.callExpression(caller.node.arguments[0], caller.node.arguments.slice(1)));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const returnedValue = fn.body.body[0].argument;
|
|
160
|
+
const clone = t3.cloneNode(returnedValue, true);
|
|
161
|
+
traverse2(clone, {
|
|
162
|
+
Identifier(path) {
|
|
163
|
+
const paramIndex = fn.params.findIndex((p) => p.name === path.node.name);
|
|
164
|
+
if (paramIndex !== -1) {
|
|
165
|
+
path.replaceWith(caller.node.arguments[paramIndex]);
|
|
166
|
+
path.skip();
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
noScope: true
|
|
170
|
+
});
|
|
171
|
+
caller.replaceWith(clone);
|
|
172
|
+
}
|
|
173
|
+
function inlineFunctionAliases(binding) {
|
|
174
|
+
const state = { changes: 0 };
|
|
175
|
+
const refs = [...binding.referencePaths];
|
|
176
|
+
for (const ref of refs) {
|
|
177
|
+
const fn = findParent(ref, m2.functionDeclaration());
|
|
178
|
+
const fnName = m2.capture(m2.anyString());
|
|
179
|
+
const returnedCall = m2.capture(m2.callExpression(m2.identifier(binding.identifier.name), m2.anyList(m2.slice({ min: 2 }))));
|
|
180
|
+
const matcher3 = m2.functionDeclaration(m2.identifier(fnName), m2.anyList(m2.slice({ min: 2 })), m2.blockStatement([m2.returnStatement(returnedCall)]));
|
|
181
|
+
if (fn && matcher3.match(fn.node)) {
|
|
182
|
+
const paramUsedInDecodeCall = fn.node.params.some((param) => {
|
|
183
|
+
const binding2 = fn.scope.getBinding(param.name);
|
|
184
|
+
return binding2?.referencePaths.some((ref2) => ref2.findParent((p) => p.node === returnedCall.current));
|
|
185
|
+
});
|
|
186
|
+
if (!paramUsedInDecodeCall)
|
|
187
|
+
continue;
|
|
188
|
+
const fnBinding = fn.scope.parent.getBinding(fnName.current);
|
|
189
|
+
if (!fnBinding)
|
|
190
|
+
continue;
|
|
191
|
+
const fnRefs = fnBinding.referencePaths;
|
|
192
|
+
refs.push(...fnRefs);
|
|
193
|
+
const callRefs = fnRefs.filter((ref2) => t3.isCallExpression(ref2.parent) && t3.isIdentifier(ref2.parent.callee, { name: fnName.current })).map((ref2) => ref2.parentPath);
|
|
194
|
+
for (const callRef of callRefs) {
|
|
195
|
+
inlineFunction(fn.node, callRef);
|
|
196
|
+
state.changes++;
|
|
197
|
+
}
|
|
198
|
+
fn.remove();
|
|
199
|
+
state.changes++;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
binding.scope.crawl();
|
|
203
|
+
return state;
|
|
204
|
+
}
|
|
205
|
+
function inlineVariableAliases(binding, targetName = binding.identifier.name) {
|
|
206
|
+
const state = { changes: 0 };
|
|
207
|
+
const refs = [...binding.referencePaths];
|
|
208
|
+
const varName = m2.capture(m2.anyString());
|
|
209
|
+
const matcher3 = m2.or(m2.variableDeclarator(m2.identifier(varName), m2.identifier(binding.identifier.name)), m2.assignmentExpression("=", m2.identifier(varName), m2.identifier(binding.identifier.name)));
|
|
210
|
+
for (const ref of refs) {
|
|
211
|
+
if (matcher3.match(ref.parent)) {
|
|
212
|
+
const varScope = ref.scope;
|
|
213
|
+
const varBinding = varScope.getBinding(varName.current);
|
|
214
|
+
if (!varBinding)
|
|
215
|
+
continue;
|
|
216
|
+
state.changes += inlineVariableAliases(varBinding, targetName).changes;
|
|
217
|
+
if (ref.parentPath?.isAssignmentExpression()) {
|
|
218
|
+
varBinding.path.remove();
|
|
219
|
+
if (t3.isExpressionStatement(ref.parentPath.parent)) {
|
|
220
|
+
ref.parentPath.remove();
|
|
221
|
+
} else {
|
|
222
|
+
ref.parentPath.replaceWith(ref.parentPath.node.right);
|
|
223
|
+
}
|
|
224
|
+
} else if (ref.parentPath?.isVariableDeclarator()) {
|
|
225
|
+
ref.parentPath.remove();
|
|
226
|
+
}
|
|
227
|
+
state.changes++;
|
|
228
|
+
} else {
|
|
229
|
+
ref.replaceWith(t3.identifier(targetName));
|
|
230
|
+
state.changes++;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return state;
|
|
234
|
+
}
|
|
235
|
+
// node_modules/webcrack/src/ast-utils/rename.ts
|
|
236
|
+
import traverse4 from "@babel/traverse";
|
|
237
|
+
import * as t4 from "@babel/types";
|
|
238
|
+
import * as m3 from "@codemod/matchers";
|
|
239
|
+
function renameFast(binding, newName) {
|
|
240
|
+
binding.referencePaths.forEach((ref) => {
|
|
241
|
+
if (!ref.isIdentifier()) {
|
|
242
|
+
throw new Error(`Unexpected reference (${ref.type}): ${codePreview(ref.node)}`);
|
|
243
|
+
}
|
|
244
|
+
if (ref.scope.hasBinding(newName))
|
|
245
|
+
ref.scope.rename(newName);
|
|
246
|
+
ref.node.name = newName;
|
|
247
|
+
});
|
|
248
|
+
const patternMatcher = m3.assignmentExpression("=", m3.or(m3.arrayPattern(), m3.objectPattern()));
|
|
249
|
+
binding.constantViolations.forEach((ref) => {
|
|
250
|
+
if (ref.scope.hasBinding(newName))
|
|
251
|
+
ref.scope.rename(newName);
|
|
252
|
+
if (ref.isAssignmentExpression() && t4.isIdentifier(ref.node.left)) {
|
|
253
|
+
ref.node.left.name = newName;
|
|
254
|
+
} else if (ref.isUpdateExpression() && t4.isIdentifier(ref.node.argument)) {
|
|
255
|
+
ref.node.argument.name = newName;
|
|
256
|
+
} else if (ref.isVariableDeclarator() && t4.isIdentifier(ref.node.id)) {
|
|
257
|
+
ref.node.id.name = newName;
|
|
258
|
+
} else if (ref.isFor() || patternMatcher.match(ref.node)) {
|
|
259
|
+
traverse4(ref.node, {
|
|
260
|
+
Identifier(path) {
|
|
261
|
+
if (path.scope !== ref.scope)
|
|
262
|
+
return path.skip();
|
|
263
|
+
if (path.node.name === binding.identifier.name) {
|
|
264
|
+
path.node.name = newName;
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
noScope: true
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
throw new Error(`Unexpected constant violation (${ref.type}): ${codePreview(ref.node)}`);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
binding.scope.removeOwnBinding(binding.identifier.name);
|
|
274
|
+
binding.scope.bindings[newName] = binding;
|
|
275
|
+
binding.identifier.name = newName;
|
|
276
|
+
}
|
|
277
|
+
// node_modules/webcrack/src/ast-utils/transform.ts
|
|
278
|
+
import traverse6, {
|
|
279
|
+
visitors
|
|
280
|
+
} from "@babel/traverse";
|
|
281
|
+
import debug from "debug";
|
|
282
|
+
async function applyTransformAsync(ast, transform, options) {
|
|
283
|
+
logger(`${transform.name}: started`);
|
|
284
|
+
const state = { changes: 0 };
|
|
285
|
+
await transform.run?.(ast, state, options);
|
|
286
|
+
if (transform.visitor)
|
|
287
|
+
traverse6(ast, transform.visitor(options), undefined, state);
|
|
288
|
+
logger(`${transform.name}: finished with ${state.changes} changes`);
|
|
289
|
+
return state;
|
|
290
|
+
}
|
|
291
|
+
function applyTransform(ast, transform, options, noScopeOverride) {
|
|
292
|
+
logger(`${transform.name}: started`);
|
|
293
|
+
const state = { changes: 0 };
|
|
294
|
+
transform.run?.(ast, state, options);
|
|
295
|
+
if (transform.visitor) {
|
|
296
|
+
const visitor = transform.visitor(options);
|
|
297
|
+
visitor.noScope = noScopeOverride || !transform.scope;
|
|
298
|
+
traverse6(ast, visitor, undefined, state);
|
|
299
|
+
}
|
|
300
|
+
logger(`${transform.name}: finished with ${state.changes} changes`);
|
|
301
|
+
return state;
|
|
302
|
+
}
|
|
303
|
+
function applyTransforms(ast, transforms, options = {}) {
|
|
304
|
+
options.log ??= true;
|
|
305
|
+
const name = options.name ?? transforms.map((t5) => t5.name).join(", ");
|
|
306
|
+
if (options.log)
|
|
307
|
+
logger(`${name}: started`);
|
|
308
|
+
const state = { changes: 0 };
|
|
309
|
+
for (const transform of transforms) {
|
|
310
|
+
transform.run?.(ast, state);
|
|
311
|
+
}
|
|
312
|
+
const traverseOptions = transforms.flatMap((t5) => t5.visitor?.() ?? []);
|
|
313
|
+
if (traverseOptions.length > 0) {
|
|
314
|
+
const visitor = visitors.merge(traverseOptions);
|
|
315
|
+
visitor.noScope = options.noScope || transforms.every((t5) => !t5.scope);
|
|
316
|
+
traverse6(ast, visitor, undefined, state);
|
|
317
|
+
}
|
|
318
|
+
if (options.log)
|
|
319
|
+
logger(`${name}: finished with ${state.changes} changes`);
|
|
320
|
+
return state;
|
|
321
|
+
}
|
|
322
|
+
function mergeTransforms(options) {
|
|
323
|
+
return {
|
|
324
|
+
name: options.name,
|
|
325
|
+
tags: options.tags,
|
|
326
|
+
scope: options.transforms.some((t5) => t5.scope),
|
|
327
|
+
visitor() {
|
|
328
|
+
return visitors.merge(options.transforms.flatMap((t5) => t5.visitor?.() ?? []));
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
var logger = debug("webcrack:transforms");
|
|
333
|
+
// node_modules/webcrack/src/unminify/transforms/merge-strings.ts
|
|
334
|
+
import * as t5 from "@babel/types";
|
|
335
|
+
import * as m4 from "@codemod/matchers";
|
|
336
|
+
var merge_strings_default = {
|
|
337
|
+
name: "merge-strings",
|
|
338
|
+
tags: ["safe"],
|
|
339
|
+
visitor() {
|
|
340
|
+
const left = m4.capture(m4.stringLiteral(m4.anyString()));
|
|
341
|
+
const right = m4.capture(m4.stringLiteral(m4.anyString()));
|
|
342
|
+
const matcher4 = m4.binaryExpression("+", left, right);
|
|
343
|
+
const nestedMatcher = m4.binaryExpression("+", m4.binaryExpression("+", m4.anything(), left), right);
|
|
344
|
+
return {
|
|
345
|
+
BinaryExpression: {
|
|
346
|
+
exit(path) {
|
|
347
|
+
if (matcher4.match(path.node)) {
|
|
348
|
+
path.replaceWith(t5.stringLiteral(left.current.value + right.current.value));
|
|
349
|
+
this.changes++;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
StringLiteral: {
|
|
354
|
+
exit(path) {
|
|
355
|
+
if (nestedMatcher.match(path.parent)) {
|
|
356
|
+
left.current.value += right.current.value;
|
|
357
|
+
path.remove();
|
|
358
|
+
this.changes++;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// node_modules/webcrack/src/deobfuscate/array-rotator.ts
|
|
367
|
+
import * as m5 from "@codemod/matchers";
|
|
368
|
+
import {callExpression as callExpression5} from "@codemod/matchers";
|
|
369
|
+
function findArrayRotator(stringArray) {
|
|
370
|
+
const arrayIdentifier = m5.capture(m5.identifier());
|
|
371
|
+
const pushShift = m5.callExpression(constMemberExpression(arrayIdentifier, "push"), [
|
|
372
|
+
m5.callExpression(constMemberExpression(m5.fromCapture(arrayIdentifier), "shift"))
|
|
373
|
+
]);
|
|
374
|
+
const callMatcher = m5.callExpression(m5.functionExpression(null, m5.anything(), m5.blockStatement(m5.anyList(m5.zeroOrMore(), infiniteLoop(m5.matcher((node) => {
|
|
375
|
+
return m5.containerOf(callExpression5(m5.identifier("parseInt"))).match(node) && m5.blockStatement([
|
|
376
|
+
m5.tryStatement(m5.containerOf(pushShift), m5.containerOf(pushShift))
|
|
377
|
+
]).match(node);
|
|
378
|
+
}))))));
|
|
379
|
+
const matcher5 = m5.expressionStatement(m5.or(callMatcher, m5.unaryExpression("!", callMatcher)));
|
|
380
|
+
for (const ref of stringArray.references) {
|
|
381
|
+
const rotator = findParent(ref, matcher5);
|
|
382
|
+
if (rotator) {
|
|
383
|
+
return rotator;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// node_modules/webcrack/src/deobfuscate/control-flow-object.ts
|
|
389
|
+
import * as t6 from "@babel/types";
|
|
390
|
+
import * as m6 from "@codemod/matchers";
|
|
391
|
+
var control_flow_object_default = {
|
|
392
|
+
name: "control-flow-object",
|
|
393
|
+
tags: ["safe"],
|
|
394
|
+
scope: true,
|
|
395
|
+
visitor() {
|
|
396
|
+
const varId = m6.capture(m6.identifier());
|
|
397
|
+
const propertyName = m6.matcher((name) => /^[a-z]{5}$/i.test(name));
|
|
398
|
+
const propertyKey = constKey(propertyName);
|
|
399
|
+
const propertyValue = m6.or(m6.stringLiteral(), createFunctionMatcher(2, (left, right) => [
|
|
400
|
+
m6.returnStatement(m6.or(m6.binaryExpression(undefined, left, right), m6.logicalExpression(undefined, left, right), m6.binaryExpression(undefined, right, left), m6.logicalExpression(undefined, right, left)))
|
|
401
|
+
]), m6.matcher((node) => {
|
|
402
|
+
return t6.isFunctionExpression(node) && createFunctionMatcher(node.params.length, (...params) => [
|
|
403
|
+
m6.returnStatement(m6.callExpression(params[0], params.slice(1)))
|
|
404
|
+
]).match(node);
|
|
405
|
+
}), (() => {
|
|
406
|
+
const fnName = m6.capture(m6.identifier());
|
|
407
|
+
const restName = m6.capture(m6.identifier());
|
|
408
|
+
return m6.functionExpression(undefined, [fnName, m6.restElement(restName)], m6.blockStatement([
|
|
409
|
+
m6.returnStatement(m6.callExpression(m6.fromCapture(fnName), [
|
|
410
|
+
m6.spreadElement(m6.fromCapture(restName))
|
|
411
|
+
]))
|
|
412
|
+
]));
|
|
413
|
+
})());
|
|
414
|
+
const objectProperties = m6.capture(m6.arrayOf(m6.objectProperty(propertyKey, propertyValue)));
|
|
415
|
+
const aliasId = m6.capture(m6.identifier());
|
|
416
|
+
const aliasVar = m6.variableDeclaration(m6.anything(), [
|
|
417
|
+
m6.variableDeclarator(aliasId, m6.fromCapture(varId))
|
|
418
|
+
]);
|
|
419
|
+
const assignedKey = m6.capture(propertyName);
|
|
420
|
+
const assignedValue = m6.capture(propertyValue);
|
|
421
|
+
const assignment = m6.expressionStatement(m6.assignmentExpression("=", constMemberExpression(m6.fromCapture(varId), assignedKey), assignedValue));
|
|
422
|
+
const looseAssignment = m6.expressionStatement(m6.assignmentExpression("=", constMemberExpression(m6.fromCapture(varId), assignedKey)));
|
|
423
|
+
const memberAccess = constMemberExpression(m6.or(m6.fromCapture(varId), m6.fromCapture(aliasId)), propertyName);
|
|
424
|
+
const varMatcher = m6.variableDeclarator(varId, m6.capture(m6.objectExpression(objectProperties)));
|
|
425
|
+
function isConstantBinding(binding) {
|
|
426
|
+
return binding.constant || binding.constantViolations[0] === binding.path;
|
|
427
|
+
}
|
|
428
|
+
function transform2(path) {
|
|
429
|
+
let changes = 0;
|
|
430
|
+
if (varMatcher.match(path.node)) {
|
|
431
|
+
const binding = path.scope.getBinding(varId.current.name);
|
|
432
|
+
if (!binding)
|
|
433
|
+
return changes;
|
|
434
|
+
if (!isConstantBinding(binding))
|
|
435
|
+
return changes;
|
|
436
|
+
if (!transformObjectKeys(binding))
|
|
437
|
+
return changes;
|
|
438
|
+
if (!isReadonlyObject(binding, memberAccess))
|
|
439
|
+
return changes;
|
|
440
|
+
const props = new Map(objectProperties.current.map((p) => [
|
|
441
|
+
getPropName(p.key),
|
|
442
|
+
p.value
|
|
443
|
+
]));
|
|
444
|
+
if (!props.size)
|
|
445
|
+
return changes;
|
|
446
|
+
const oldRefs = [...binding.referencePaths];
|
|
447
|
+
[...binding.referencePaths].reverse().forEach((ref) => {
|
|
448
|
+
const memberPath = ref.parentPath;
|
|
449
|
+
const propName = getPropName(memberPath.node.property);
|
|
450
|
+
const value = props.get(propName);
|
|
451
|
+
if (t6.isStringLiteral(value)) {
|
|
452
|
+
memberPath.replaceWith(value);
|
|
453
|
+
} else {
|
|
454
|
+
inlineFunction(value, memberPath.parentPath);
|
|
455
|
+
}
|
|
456
|
+
changes++;
|
|
457
|
+
});
|
|
458
|
+
oldRefs.forEach((ref) => {
|
|
459
|
+
const varDeclarator = findParent(ref, m6.variableDeclarator());
|
|
460
|
+
if (varDeclarator)
|
|
461
|
+
changes += transform2(varDeclarator);
|
|
462
|
+
});
|
|
463
|
+
path.remove();
|
|
464
|
+
changes++;
|
|
465
|
+
}
|
|
466
|
+
return changes;
|
|
467
|
+
}
|
|
468
|
+
function transformObjectKeys(objBinding) {
|
|
469
|
+
const container = objBinding.path.parentPath.container;
|
|
470
|
+
const startIndex = objBinding.path.parentPath.key + 1;
|
|
471
|
+
const properties = [];
|
|
472
|
+
for (let i = startIndex;i < container.length; i++) {
|
|
473
|
+
const statement = container[i];
|
|
474
|
+
if (looseAssignment.match(statement)) {
|
|
475
|
+
applyTransform(statement, merge_strings_default);
|
|
476
|
+
}
|
|
477
|
+
if (assignment.match(statement)) {
|
|
478
|
+
properties.push(t6.objectProperty(t6.identifier(assignedKey.current), assignedValue.current));
|
|
479
|
+
} else {
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const aliasAssignment = container[startIndex + properties.length];
|
|
484
|
+
if (!aliasVar.match(aliasAssignment))
|
|
485
|
+
return true;
|
|
486
|
+
if (objBinding.references !== properties.length + 1)
|
|
487
|
+
return false;
|
|
488
|
+
const aliasBinding = objBinding.scope.getBinding(aliasId.current.name);
|
|
489
|
+
if (!isReadonlyObject(aliasBinding, memberAccess))
|
|
490
|
+
return false;
|
|
491
|
+
objectProperties.current.push(...properties);
|
|
492
|
+
container.splice(startIndex, properties.length);
|
|
493
|
+
objBinding.referencePaths = aliasBinding.referencePaths;
|
|
494
|
+
objBinding.references = aliasBinding.references;
|
|
495
|
+
objBinding.identifier.name = aliasBinding.identifier.name;
|
|
496
|
+
aliasBinding.path.remove();
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
return {
|
|
500
|
+
VariableDeclarator: {
|
|
501
|
+
exit(path) {
|
|
502
|
+
this.changes += transform2(path);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// node_modules/webcrack/src/deobfuscate/control-flow-switch.ts
|
|
510
|
+
import * as t7 from "@babel/types";
|
|
511
|
+
import * as m7 from "@codemod/matchers";
|
|
512
|
+
var control_flow_switch_default = {
|
|
513
|
+
name: "control-flow-switch",
|
|
514
|
+
tags: ["safe"],
|
|
515
|
+
visitor() {
|
|
516
|
+
const sequenceName = m7.capture(m7.identifier());
|
|
517
|
+
const sequenceString = m7.capture(m7.matcher((s) => /^\d+(\|\d+)*$/.test(s)));
|
|
518
|
+
const iterator = m7.capture(m7.identifier());
|
|
519
|
+
const cases = m7.capture(m7.arrayOf(m7.switchCase(m7.stringLiteral(m7.matcher((s) => /^\d+$/.test(s))), m7.anyList(m7.zeroOrMore(), m7.or(m7.continueStatement(), m7.returnStatement())))));
|
|
520
|
+
const matcher7 = m7.blockStatement(m7.anyList(m7.variableDeclaration(undefined, [
|
|
521
|
+
m7.variableDeclarator(sequenceName, m7.callExpression(constMemberExpression(m7.stringLiteral(sequenceString), "split"), [m7.stringLiteral("|")]))
|
|
522
|
+
]), m7.variableDeclaration(undefined, [m7.variableDeclarator(iterator)]), infiniteLoop(m7.blockStatement([
|
|
523
|
+
m7.switchStatement(m7.memberExpression(m7.fromCapture(sequenceName), m7.updateExpression("++", m7.fromCapture(iterator)), true), cases),
|
|
524
|
+
m7.breakStatement()
|
|
525
|
+
])), m7.zeroOrMore()));
|
|
526
|
+
return {
|
|
527
|
+
BlockStatement: {
|
|
528
|
+
exit(path) {
|
|
529
|
+
if (!matcher7.match(path.node))
|
|
530
|
+
return;
|
|
531
|
+
const caseStatements = new Map(cases.current.map((c) => [
|
|
532
|
+
c.test.value,
|
|
533
|
+
t7.isContinueStatement(c.consequent.at(-1)) ? c.consequent.slice(0, -1) : c.consequent
|
|
534
|
+
]));
|
|
535
|
+
const sequence = sequenceString.current.split("|");
|
|
536
|
+
const newStatements = sequence.flatMap((s) => caseStatements.get(s));
|
|
537
|
+
path.node.body.splice(0, 3, ...newStatements);
|
|
538
|
+
this.changes += newStatements.length + 3;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
// node_modules/webcrack/src/deobfuscate/dead-code.ts
|
|
546
|
+
import * as t8 from "@babel/types";
|
|
547
|
+
import * as m8 from "@codemod/matchers";
|
|
548
|
+
var replace = function(path, node) {
|
|
549
|
+
if (t8.isBlockStatement(node)) {
|
|
550
|
+
path.replaceWithMultiple(node.body);
|
|
551
|
+
} else {
|
|
552
|
+
path.replaceWith(node);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
var dead_code_default = {
|
|
556
|
+
name: "dead-code",
|
|
557
|
+
tags: ["unsafe"],
|
|
558
|
+
scope: true,
|
|
559
|
+
visitor() {
|
|
560
|
+
const stringComparison = m8.binaryExpression(m8.or("===", "==", "!==", "!="), m8.stringLiteral(), m8.stringLiteral());
|
|
561
|
+
const testMatcher = m8.or(stringComparison, m8.unaryExpression("!", stringComparison));
|
|
562
|
+
return {
|
|
563
|
+
"IfStatement|ConditionalExpression": {
|
|
564
|
+
exit(_path) {
|
|
565
|
+
const path = _path;
|
|
566
|
+
if (!testMatcher.match(path.node.test))
|
|
567
|
+
return;
|
|
568
|
+
const { scope } = path;
|
|
569
|
+
function renameShadowedVariables(localScope) {
|
|
570
|
+
if (localScope === scope)
|
|
571
|
+
return;
|
|
572
|
+
for (const name in localScope.bindings) {
|
|
573
|
+
if (scope.hasBinding(name)) {
|
|
574
|
+
renameFast(localScope.bindings[name], scope.generateUid(name));
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if (path.get("test").evaluateTruthy()) {
|
|
579
|
+
renameShadowedVariables(path.get("consequent").scope);
|
|
580
|
+
replace(path, path.node.consequent);
|
|
581
|
+
} else if (path.node.alternate) {
|
|
582
|
+
renameShadowedVariables(path.get("alternate").scope);
|
|
583
|
+
replace(path, path.node.alternate);
|
|
584
|
+
} else {
|
|
585
|
+
path.remove();
|
|
586
|
+
}
|
|
587
|
+
this.changes++;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// node_modules/webcrack/src/deobfuscate/decoder.ts
|
|
595
|
+
import {expression} from "@babel/template";
|
|
596
|
+
import * as m9 from "@codemod/matchers";
|
|
597
|
+
function findDecoders(stringArray) {
|
|
598
|
+
const decoders = [];
|
|
599
|
+
const functionName = m9.capture(m9.anyString());
|
|
600
|
+
const arrayIdentifier = m9.capture(m9.identifier());
|
|
601
|
+
const matcher8 = m9.functionDeclaration(m9.identifier(functionName), m9.anything(), m9.blockStatement(m9.anyList(m9.variableDeclaration(undefined, [
|
|
602
|
+
m9.variableDeclarator(arrayIdentifier, m9.callExpression(m9.identifier(stringArray.name)))
|
|
603
|
+
]), m9.zeroOrMore(), m9.containerOf(m9.memberExpression(m9.fromCapture(arrayIdentifier), undefined, true)), m9.zeroOrMore())));
|
|
604
|
+
for (const ref of stringArray.references) {
|
|
605
|
+
const decoderFn = findParent(ref, matcher8);
|
|
606
|
+
if (decoderFn) {
|
|
607
|
+
const oldName = functionName.current;
|
|
608
|
+
const newName = `__DECODE_${decoders.length}__`;
|
|
609
|
+
const binding = decoderFn.scope.getBinding(oldName);
|
|
610
|
+
renameFast(binding, newName);
|
|
611
|
+
decoders.push(new Decoder(newName, decoderFn));
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return decoders;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
class Decoder {
|
|
618
|
+
name;
|
|
619
|
+
path;
|
|
620
|
+
constructor(name, path) {
|
|
621
|
+
this.name = name;
|
|
622
|
+
this.path = path;
|
|
623
|
+
}
|
|
624
|
+
collectCalls() {
|
|
625
|
+
const calls = [];
|
|
626
|
+
const literalArgument = m9.or(m9.binaryExpression(m9.anything(), m9.matcher((node) => literalArgument.match(node)), m9.matcher((node) => literalArgument.match(node))), m9.unaryExpression("-", m9.matcher((node) => literalArgument.match(node))), m9.numericLiteral(), m9.stringLiteral());
|
|
627
|
+
const literalCall = m9.callExpression(m9.identifier(this.name), m9.arrayOf(literalArgument));
|
|
628
|
+
const expressionCall = m9.callExpression(m9.identifier(this.name), m9.arrayOf(m9.anyExpression()));
|
|
629
|
+
const conditional = m9.capture(m9.conditionalExpression());
|
|
630
|
+
const conditionalCall = m9.callExpression(m9.identifier(this.name), [
|
|
631
|
+
conditional
|
|
632
|
+
]);
|
|
633
|
+
const buildExtractedConditional = expression`TEST ? CALLEE(CONSEQUENT) : CALLEE(ALTERNATE)`;
|
|
634
|
+
const binding = this.path.scope.getBinding(this.name);
|
|
635
|
+
for (const ref of binding.referencePaths) {
|
|
636
|
+
if (conditionalCall.match(ref.parent)) {
|
|
637
|
+
const [replacement] = ref.parentPath.replaceWith(buildExtractedConditional({
|
|
638
|
+
TEST: conditional.current.test,
|
|
639
|
+
CALLEE: ref.parent.callee,
|
|
640
|
+
CONSEQUENT: conditional.current.consequent,
|
|
641
|
+
ALTERNATE: conditional.current.alternate
|
|
642
|
+
}));
|
|
643
|
+
replacement.scope.crawl();
|
|
644
|
+
} else if (literalCall.match(ref.parent)) {
|
|
645
|
+
calls.push(ref.parentPath);
|
|
646
|
+
} else if (expressionCall.match(ref.parent)) {
|
|
647
|
+
ref.parentPath.traverse({
|
|
648
|
+
ReferencedIdentifier(path) {
|
|
649
|
+
const varBinding = path.scope.getBinding(path.node.name);
|
|
650
|
+
if (!varBinding)
|
|
651
|
+
return;
|
|
652
|
+
inlineVariable(varBinding, literalArgument, true);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
if (literalCall.match(ref.parent)) {
|
|
656
|
+
calls.push(ref.parentPath);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
return calls;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// node_modules/webcrack/src/deobfuscate/inline-decoded-strings.ts
|
|
665
|
+
import * as t9 from "@babel/types";
|
|
666
|
+
var inline_decoded_strings_default = {
|
|
667
|
+
name: "inline-decoded-strings",
|
|
668
|
+
tags: ["unsafe"],
|
|
669
|
+
scope: true,
|
|
670
|
+
async run(ast2, state, options) {
|
|
671
|
+
if (!options)
|
|
672
|
+
return;
|
|
673
|
+
const calls = options.vm.decoders.flatMap((decoder) => decoder.collectCalls());
|
|
674
|
+
const decodedValues = await options.vm.decode(calls);
|
|
675
|
+
for (let i = 0;i < calls.length; i++) {
|
|
676
|
+
const call = calls[i];
|
|
677
|
+
const value = decodedValues[i];
|
|
678
|
+
call.replaceWith(t9.valueToNode(value));
|
|
679
|
+
if (typeof value !== "string")
|
|
680
|
+
call.addComment("leading", "webcrack:decode_error");
|
|
681
|
+
}
|
|
682
|
+
state.changes += calls.length;
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
// node_modules/webcrack/src/deobfuscate/inline-decoder-wrappers.ts
|
|
687
|
+
var inline_decoder_wrappers_default = {
|
|
688
|
+
name: "inline-decoder-wrappers",
|
|
689
|
+
tags: ["unsafe"],
|
|
690
|
+
scope: true,
|
|
691
|
+
run(ast2, state, decoder) {
|
|
692
|
+
if (!decoder?.node.id)
|
|
693
|
+
return;
|
|
694
|
+
const decoderName = decoder.node.id.name;
|
|
695
|
+
const decoderBinding = decoder.parentPath.scope.getBinding(decoderName);
|
|
696
|
+
if (decoderBinding) {
|
|
697
|
+
state.changes += inlineVariableAliases(decoderBinding).changes;
|
|
698
|
+
state.changes += inlineFunctionAliases(decoderBinding).changes;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
// node_modules/webcrack/src/deobfuscate/inline-object-props.ts
|
|
704
|
+
import * as m10 from "@codemod/matchers";
|
|
705
|
+
var inline_object_props_default = {
|
|
706
|
+
name: "inline-object-props",
|
|
707
|
+
tags: ["safe"],
|
|
708
|
+
scope: true,
|
|
709
|
+
visitor() {
|
|
710
|
+
const varId = m10.capture(m10.identifier());
|
|
711
|
+
const propertyName = m10.matcher((name) => /^[\w]+$/i.test(name));
|
|
712
|
+
const propertyKey = constKey(propertyName);
|
|
713
|
+
const objectProperties = m10.capture(m10.arrayOf(m10.objectProperty(propertyKey, m10.or(m10.stringLiteral(), m10.numericLiteral()))));
|
|
714
|
+
const memberAccess = constMemberExpression(m10.fromCapture(varId), propertyName);
|
|
715
|
+
const varMatcher = m10.variableDeclarator(varId, m10.objectExpression(objectProperties));
|
|
716
|
+
return {
|
|
717
|
+
VariableDeclarator(path) {
|
|
718
|
+
if (!varMatcher.match(path.node))
|
|
719
|
+
return;
|
|
720
|
+
if (objectProperties.current.length === 0)
|
|
721
|
+
return;
|
|
722
|
+
const binding = path.scope.getBinding(varId.current.name);
|
|
723
|
+
if (!binding || !isReadonlyObject(binding, memberAccess))
|
|
724
|
+
return;
|
|
725
|
+
inlineObjectProperties(binding, m10.objectProperty(propertyKey, m10.or(m10.stringLiteral(), m10.numericLiteral())));
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
// node_modules/webcrack/src/deobfuscate/string-array.ts
|
|
732
|
+
import traverse8 from "@babel/traverse";
|
|
733
|
+
import * as m11 from "@codemod/matchers";
|
|
734
|
+
function findStringArray(ast2) {
|
|
735
|
+
let result;
|
|
736
|
+
const functionName = m11.capture(m11.anyString());
|
|
737
|
+
const arrayIdentifier = m11.capture(m11.identifier());
|
|
738
|
+
const arrayExpression3 = m11.capture(m11.arrayExpression(m11.arrayOf(m11.stringLiteral())));
|
|
739
|
+
const functionAssignment = m11.assignmentExpression("=", m11.identifier(m11.fromCapture(functionName)), m11.functionExpression(undefined, [], m11.blockStatement([m11.returnStatement(m11.fromCapture(arrayIdentifier))])));
|
|
740
|
+
const variableDeclaration5 = m11.variableDeclaration(undefined, [
|
|
741
|
+
m11.variableDeclarator(arrayIdentifier, arrayExpression3)
|
|
742
|
+
]);
|
|
743
|
+
const matcher10 = m11.functionDeclaration(m11.identifier(functionName), [], m11.or(m11.blockStatement([
|
|
744
|
+
variableDeclaration5,
|
|
745
|
+
m11.returnStatement(m11.callExpression(functionAssignment))
|
|
746
|
+
]), m11.blockStatement([
|
|
747
|
+
variableDeclaration5,
|
|
748
|
+
m11.expressionStatement(functionAssignment),
|
|
749
|
+
m11.returnStatement(m11.callExpression(m11.identifier(functionName)))
|
|
750
|
+
])));
|
|
751
|
+
traverse8(ast2, {
|
|
752
|
+
FunctionDeclaration(path) {
|
|
753
|
+
if (matcher10.match(path.node)) {
|
|
754
|
+
const length = arrayExpression3.current.elements.length;
|
|
755
|
+
const name = functionName.current;
|
|
756
|
+
const binding = path.scope.getBinding(name);
|
|
757
|
+
renameFast(binding, "__STRING_ARRAY__");
|
|
758
|
+
result = {
|
|
759
|
+
path,
|
|
760
|
+
references: binding.referencePaths,
|
|
761
|
+
name: "__STRING_ARRAY__",
|
|
762
|
+
length
|
|
763
|
+
};
|
|
764
|
+
path.stop();
|
|
765
|
+
}
|
|
766
|
+
},
|
|
767
|
+
VariableDeclaration(path) {
|
|
768
|
+
if (!variableDeclaration5.match(path.node))
|
|
769
|
+
return;
|
|
770
|
+
const length = arrayExpression3.current.elements.length;
|
|
771
|
+
const binding = path.scope.getBinding(arrayIdentifier.current.name);
|
|
772
|
+
const memberAccess = m11.memberExpression(m11.fromCapture(arrayIdentifier), m11.numericLiteral(m11.matcher((value) => value < length)));
|
|
773
|
+
if (!isReadonlyObject(binding, memberAccess))
|
|
774
|
+
return;
|
|
775
|
+
inlineArrayElements(arrayExpression3.current, binding.referencePaths);
|
|
776
|
+
path.remove();
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
return result;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// node_modules/webcrack/src/deobfuscate/vm.ts
|
|
783
|
+
import debug2 from "debug";
|
|
784
|
+
class VMDecoder {
|
|
785
|
+
decoders;
|
|
786
|
+
setupCode;
|
|
787
|
+
sandbox;
|
|
788
|
+
constructor(sandbox, stringArray, decoders, rotator) {
|
|
789
|
+
this.sandbox = sandbox;
|
|
790
|
+
this.decoders = decoders;
|
|
791
|
+
const generateOptions = {
|
|
792
|
+
compact: true,
|
|
793
|
+
shouldPrintComment: () => false
|
|
794
|
+
};
|
|
795
|
+
const stringArrayCode = generate(stringArray.path.node, generateOptions);
|
|
796
|
+
const rotatorCode = rotator ? generate(rotator.node, generateOptions) : "";
|
|
797
|
+
const decoderCode = decoders.map((decoder) => generate(decoder.path.node, generateOptions)).join(";\n");
|
|
798
|
+
this.setupCode = [stringArrayCode, rotatorCode, decoderCode].join(";\n");
|
|
799
|
+
}
|
|
800
|
+
async decode(calls) {
|
|
801
|
+
const code = `(() => {
|
|
802
|
+
${this.setupCode}
|
|
803
|
+
return [${calls.join(",")}]
|
|
804
|
+
})()`;
|
|
805
|
+
try {
|
|
806
|
+
const result = await this.sandbox(code);
|
|
807
|
+
return result;
|
|
808
|
+
} catch (error) {
|
|
809
|
+
debug2("webcrack:deobfuscate")("vm code:", code);
|
|
810
|
+
if (error instanceof Error && (error.message.includes("undefined symbol") || error.message.includes("Segmentation fault"))) {
|
|
811
|
+
throw new Error("isolated-vm version mismatch. Check https://webcrack.netlify.app/docs/guide/common-errors.html#isolated-vm", { cause: error });
|
|
812
|
+
}
|
|
813
|
+
throw error;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// node_modules/webcrack/src/deobfuscate/index.ts
|
|
819
|
+
var deobfuscate_default = {
|
|
820
|
+
name: "deobfuscate",
|
|
821
|
+
tags: ["unsafe"],
|
|
822
|
+
scope: true,
|
|
823
|
+
async run(ast2, state, sandbox) {
|
|
824
|
+
if (!sandbox)
|
|
825
|
+
return;
|
|
826
|
+
const logger2 = debug3("webcrack:deobfuscate");
|
|
827
|
+
const stringArray = findStringArray(ast2);
|
|
828
|
+
logger2(stringArray ? `String Array: ${stringArray.length} strings` : "String Array: no");
|
|
829
|
+
if (!stringArray)
|
|
830
|
+
return;
|
|
831
|
+
const rotator = findArrayRotator(stringArray);
|
|
832
|
+
logger2(`String Array Rotate: ${rotator ? "yes" : "no"}`);
|
|
833
|
+
const decoders = findDecoders(stringArray);
|
|
834
|
+
logger2(`String Array Encodings: ${decoders.length}`);
|
|
835
|
+
state.changes += applyTransform(ast2, inline_object_props_default).changes;
|
|
836
|
+
for (const decoder2 of decoders) {
|
|
837
|
+
state.changes += applyTransform(ast2, inline_decoder_wrappers_default, decoder2.path).changes;
|
|
838
|
+
}
|
|
839
|
+
const vm2 = new VMDecoder(sandbox, stringArray, decoders, rotator);
|
|
840
|
+
state.changes += (await applyTransformAsync(ast2, inline_decoded_strings_default, { vm: vm2 })).changes;
|
|
841
|
+
stringArray.path.remove();
|
|
842
|
+
rotator?.remove();
|
|
843
|
+
decoders.forEach((decoder2) => decoder2.path.remove());
|
|
844
|
+
state.changes += 2 + decoders.length;
|
|
845
|
+
state.changes += applyTransforms(ast2, [merge_strings_default, dead_code_default, control_flow_object_default, control_flow_switch_default], { noScope: true }).changes;
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
// node_modules/webcrack/src/deobfuscate/var-functions.ts
|
|
850
|
+
import * as t10 from "@babel/types";
|
|
851
|
+
import * as m12 from "@codemod/matchers";
|
|
852
|
+
var var_functions_default = {
|
|
853
|
+
name: "var-functions",
|
|
854
|
+
tags: ["unsafe"],
|
|
855
|
+
visitor() {
|
|
856
|
+
const name = m12.capture(m12.identifier());
|
|
857
|
+
const fn = m12.capture(m12.functionExpression(null));
|
|
858
|
+
const matcher10 = m12.variableDeclaration("var", [
|
|
859
|
+
m12.variableDeclarator(name, fn)
|
|
860
|
+
]);
|
|
861
|
+
return {
|
|
862
|
+
VariableDeclaration: {
|
|
863
|
+
exit(path) {
|
|
864
|
+
if (matcher10.match(path.node) && path.key !== "init") {
|
|
865
|
+
path.replaceWith(t10.functionDeclaration(name.current, fn.current.params, fn.current.body, fn.current.generator, fn.current.async));
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
// node_modules/webcrack/src/deobfuscate/merge-object-assignments.ts
|
|
874
|
+
import * as t11 from "@babel/types";
|
|
875
|
+
import * as m13 from "@codemod/matchers";
|
|
876
|
+
var hasCircularReference = function(node, binding) {
|
|
877
|
+
return binding.referencePaths.some((path) => path.find((p) => p.node === node)) || m13.containerOf(m13.callExpression()).match(node);
|
|
878
|
+
};
|
|
879
|
+
var merge_object_assignments_default = {
|
|
880
|
+
name: "merge-object-assignments",
|
|
881
|
+
tags: ["safe"],
|
|
882
|
+
scope: true,
|
|
883
|
+
visitor: () => {
|
|
884
|
+
const id = m13.capture(m13.identifier());
|
|
885
|
+
const object = m13.capture(m13.objectExpression([]));
|
|
886
|
+
const varMatcher = m13.variableDeclaration(undefined, [
|
|
887
|
+
m13.variableDeclarator(id, object)
|
|
888
|
+
]);
|
|
889
|
+
const key = m13.capture(m13.anyExpression());
|
|
890
|
+
const computed = m13.capture(m13.anything());
|
|
891
|
+
const value = m13.capture(m13.anyExpression());
|
|
892
|
+
const assignmentMatcher = m13.expressionStatement(m13.assignmentExpression("=", m13.memberExpression(m13.fromCapture(id), key, computed), value));
|
|
893
|
+
return {
|
|
894
|
+
Program(path) {
|
|
895
|
+
path.scope.crawl();
|
|
896
|
+
},
|
|
897
|
+
VariableDeclaration: {
|
|
898
|
+
exit(path) {
|
|
899
|
+
if (!path.inList || !varMatcher.match(path.node))
|
|
900
|
+
return;
|
|
901
|
+
const binding = path.scope.getBinding(id.current.name);
|
|
902
|
+
const container = path.container;
|
|
903
|
+
const siblingIndex = path.key + 1;
|
|
904
|
+
while (siblingIndex < container.length) {
|
|
905
|
+
const sibling = path.getSibling(siblingIndex);
|
|
906
|
+
if (!assignmentMatcher.match(sibling.node) || hasCircularReference(value.current, binding))
|
|
907
|
+
return;
|
|
908
|
+
const isComputed = computed.current && key.current.type !== "NumericLiteral" && key.current.type !== "StringLiteral";
|
|
909
|
+
object.current.properties.push(t11.objectProperty(key.current, value.current, isComputed));
|
|
910
|
+
sibling.remove();
|
|
911
|
+
binding.dereference();
|
|
912
|
+
binding.referencePaths.shift();
|
|
913
|
+
if (binding.references === 1 && inlineableObject.match(object.current)) {
|
|
914
|
+
binding.referencePaths[0].replaceWith(object.current);
|
|
915
|
+
path.remove();
|
|
916
|
+
this.changes++;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
var inlineableObject = m13.matcher((node) => m13.or(anyLiteral, m13.arrayExpression(m13.arrayOf(inlineableObject)), m13.objectExpression(m13.arrayOf(constObjectProperty(inlineableObject)))).match(node));
|
|
925
|
+
|
|
926
|
+
// node_modules/webcrack/src/unminify/transforms/index.ts
|
|
927
|
+
var exports_transforms = {};
|
|
928
|
+
__export(exports_transforms, {
|
|
929
|
+
yoda: () => {
|
|
930
|
+
{
|
|
931
|
+
return yoda_default;
|
|
932
|
+
}
|
|
933
|
+
},
|
|
934
|
+
voidToUndefined: () => {
|
|
935
|
+
{
|
|
936
|
+
return void_to_undefined_default;
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
unminifyBooleans: () => {
|
|
940
|
+
{
|
|
941
|
+
return unminify_booleans_default;
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
unaryExpressions: () => {
|
|
945
|
+
{
|
|
946
|
+
return unary_expressions_default;
|
|
947
|
+
}
|
|
948
|
+
},
|
|
949
|
+
typeofUndefined: () => {
|
|
950
|
+
{
|
|
951
|
+
return typeof_undefined_default;
|
|
952
|
+
}
|
|
953
|
+
},
|
|
954
|
+
ternaryToIf: () => {
|
|
955
|
+
{
|
|
956
|
+
return ternary_to_if_default;
|
|
957
|
+
}
|
|
958
|
+
},
|
|
959
|
+
splitVariableDeclarations: () => {
|
|
960
|
+
{
|
|
961
|
+
return split_variable_declarations_default;
|
|
962
|
+
}
|
|
963
|
+
},
|
|
964
|
+
sequence: () => {
|
|
965
|
+
{
|
|
966
|
+
return sequence_default;
|
|
967
|
+
}
|
|
968
|
+
},
|
|
969
|
+
rawLiterals: () => {
|
|
970
|
+
{
|
|
971
|
+
return raw_literals_default;
|
|
972
|
+
}
|
|
973
|
+
},
|
|
974
|
+
numberExpressions: () => {
|
|
975
|
+
{
|
|
976
|
+
return number_expressions_default;
|
|
977
|
+
}
|
|
978
|
+
},
|
|
979
|
+
mergeStrings: () => {
|
|
980
|
+
{
|
|
981
|
+
return merge_strings_default;
|
|
982
|
+
}
|
|
983
|
+
},
|
|
984
|
+
mergeElseIf: () => {
|
|
985
|
+
{
|
|
986
|
+
return merge_else_if_default;
|
|
987
|
+
}
|
|
988
|
+
},
|
|
989
|
+
logicalToIf: () => {
|
|
990
|
+
{
|
|
991
|
+
return logical_to_if_default;
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
jsonParse: () => {
|
|
995
|
+
{
|
|
996
|
+
return json_parse_default;
|
|
997
|
+
}
|
|
998
|
+
},
|
|
999
|
+
invertBooleanLogic: () => {
|
|
1000
|
+
{
|
|
1001
|
+
return invert_boolean_logic_default;
|
|
1002
|
+
}
|
|
1003
|
+
},
|
|
1004
|
+
infinity: () => {
|
|
1005
|
+
{
|
|
1006
|
+
return infinity_default;
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
1009
|
+
forToWhile: () => {
|
|
1010
|
+
{
|
|
1011
|
+
return for_to_while_default;
|
|
1012
|
+
}
|
|
1013
|
+
},
|
|
1014
|
+
computedProperties: () => {
|
|
1015
|
+
{
|
|
1016
|
+
return computed_properties_default;
|
|
1017
|
+
}
|
|
1018
|
+
},
|
|
1019
|
+
blockStatements: () => {
|
|
1020
|
+
{
|
|
1021
|
+
return block_statements_default;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
// node_modules/webcrack/src/unminify/transforms/block-statements.ts
|
|
1027
|
+
import * as t12 from "@babel/types";
|
|
1028
|
+
var block_statements_default = {
|
|
1029
|
+
name: "block-statements",
|
|
1030
|
+
tags: ["safe"],
|
|
1031
|
+
visitor: () => ({
|
|
1032
|
+
IfStatement: {
|
|
1033
|
+
exit(path) {
|
|
1034
|
+
if (!t12.isBlockStatement(path.node.consequent) && !t12.isEmptyStatement(path.node.consequent)) {
|
|
1035
|
+
path.node.consequent = t12.blockStatement([path.node.consequent]);
|
|
1036
|
+
this.changes++;
|
|
1037
|
+
}
|
|
1038
|
+
if (path.node.alternate && !t12.isBlockStatement(path.node.alternate)) {
|
|
1039
|
+
path.node.alternate = t12.blockStatement([path.node.alternate]);
|
|
1040
|
+
this.changes++;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
},
|
|
1044
|
+
Loop: {
|
|
1045
|
+
exit(path) {
|
|
1046
|
+
if (!t12.isBlockStatement(path.node.body) && !t12.isEmptyStatement(path.node.body)) {
|
|
1047
|
+
path.node.body = t12.blockStatement([path.node.body]);
|
|
1048
|
+
this.changes++;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1052
|
+
ArrowFunctionExpression: {
|
|
1053
|
+
exit(path) {
|
|
1054
|
+
if (t12.isSequenceExpression(path.node.body)) {
|
|
1055
|
+
path.node.body = t12.blockStatement([
|
|
1056
|
+
t12.returnStatement(path.node.body)
|
|
1057
|
+
]);
|
|
1058
|
+
this.changes++;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
})
|
|
1063
|
+
};
|
|
1064
|
+
// node_modules/webcrack/src/unminify/transforms/computed-properties.ts
|
|
1065
|
+
import {isIdentifierName} from "@babel/helper-validator-identifier";
|
|
1066
|
+
import * as t13 from "@babel/types";
|
|
1067
|
+
import * as m14 from "@codemod/matchers";
|
|
1068
|
+
var computed_properties_default = {
|
|
1069
|
+
name: "computed-properties",
|
|
1070
|
+
tags: ["safe"],
|
|
1071
|
+
visitor() {
|
|
1072
|
+
const stringMatcher = m14.capture(m14.stringLiteral(m14.matcher((value) => isIdentifierName(value))));
|
|
1073
|
+
const propertyMatcher = m14.or(m14.memberExpression(m14.anything(), stringMatcher, true), m14.optionalMemberExpression(m14.anything(), stringMatcher, true));
|
|
1074
|
+
const keyMatcher = m14.or(m14.objectProperty(stringMatcher), m14.classProperty(stringMatcher), m14.objectMethod(undefined, stringMatcher), m14.classMethod(undefined, stringMatcher));
|
|
1075
|
+
return {
|
|
1076
|
+
"MemberExpression|OptionalMemberExpression": {
|
|
1077
|
+
exit(path) {
|
|
1078
|
+
if (!propertyMatcher.match(path.node))
|
|
1079
|
+
return;
|
|
1080
|
+
path.node.computed = false;
|
|
1081
|
+
path.node.property = t13.identifier(stringMatcher.current.value);
|
|
1082
|
+
this.changes++;
|
|
1083
|
+
}
|
|
1084
|
+
},
|
|
1085
|
+
"ObjectProperty|ClassProperty|ObjectMethod|ClassMethod": {
|
|
1086
|
+
exit(path) {
|
|
1087
|
+
if (!keyMatcher.match(path.node))
|
|
1088
|
+
return;
|
|
1089
|
+
if (path.type === "ClassMethod" && stringMatcher.current.value === "constructor" || path.type === "ObjectProperty" && stringMatcher.current.value === "__proto__")
|
|
1090
|
+
return;
|
|
1091
|
+
path.node.computed = false;
|
|
1092
|
+
path.node.key = t13.identifier(stringMatcher.current.value);
|
|
1093
|
+
this.changes++;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
// node_modules/webcrack/src/unminify/transforms/for-to-while.ts
|
|
1100
|
+
import * as t14 from "@babel/types";
|
|
1101
|
+
var for_to_while_default = {
|
|
1102
|
+
name: "for-to-while",
|
|
1103
|
+
tags: ["safe"],
|
|
1104
|
+
visitor() {
|
|
1105
|
+
return {
|
|
1106
|
+
ForStatement: {
|
|
1107
|
+
exit(path) {
|
|
1108
|
+
const { test, body, init, update } = path.node;
|
|
1109
|
+
if (init || update)
|
|
1110
|
+
return;
|
|
1111
|
+
path.replaceWith(test ? t14.whileStatement(test, body) : t14.whileStatement(t14.booleanLiteral(true), body));
|
|
1112
|
+
this.changes++;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
// node_modules/webcrack/src/unminify/transforms/infinity.ts
|
|
1119
|
+
import * as t15 from "@babel/types";
|
|
1120
|
+
import * as m15 from "@codemod/matchers";
|
|
1121
|
+
var infinity_default = {
|
|
1122
|
+
name: "infinity",
|
|
1123
|
+
tags: ["safe"],
|
|
1124
|
+
scope: true,
|
|
1125
|
+
visitor: () => {
|
|
1126
|
+
const infinityMatcher = m15.binaryExpression("/", m15.numericLiteral(1), m15.numericLiteral(0));
|
|
1127
|
+
const negativeInfinityMatcher = m15.binaryExpression("/", m15.unaryExpression("-", m15.numericLiteral(1)), m15.numericLiteral(0));
|
|
1128
|
+
return {
|
|
1129
|
+
BinaryExpression: {
|
|
1130
|
+
exit(path) {
|
|
1131
|
+
if (path.scope.hasBinding("Infinity", { noGlobals: true }))
|
|
1132
|
+
return;
|
|
1133
|
+
if (infinityMatcher.match(path.node)) {
|
|
1134
|
+
path.replaceWith(t15.identifier("Infinity"));
|
|
1135
|
+
this.changes++;
|
|
1136
|
+
} else if (negativeInfinityMatcher.match(path.node)) {
|
|
1137
|
+
path.replaceWith(t15.unaryExpression("-", t15.identifier("Infinity")));
|
|
1138
|
+
this.changes++;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
// node_modules/webcrack/src/unminify/transforms/invert-boolean-logic.ts
|
|
1146
|
+
import * as t16 from "@babel/types";
|
|
1147
|
+
import * as m16 from "@codemod/matchers";
|
|
1148
|
+
var INVERTED_BINARY_OPERATORS = {
|
|
1149
|
+
"==": "!=",
|
|
1150
|
+
"===": "!==",
|
|
1151
|
+
"!=": "==",
|
|
1152
|
+
"!==": "===",
|
|
1153
|
+
">": "<=",
|
|
1154
|
+
"<": ">=",
|
|
1155
|
+
">=": "<",
|
|
1156
|
+
"<=": ">"
|
|
1157
|
+
};
|
|
1158
|
+
var INVERTED_LOGICAL_OPERATORS = {
|
|
1159
|
+
"||": "&&",
|
|
1160
|
+
"&&": "||"
|
|
1161
|
+
};
|
|
1162
|
+
var invert_boolean_logic_default = {
|
|
1163
|
+
name: "invert-boolean-logic",
|
|
1164
|
+
tags: ["safe"],
|
|
1165
|
+
visitor: () => {
|
|
1166
|
+
const logicalExpression3 = m16.logicalExpression(m16.or(...Object.values(INVERTED_LOGICAL_OPERATORS)));
|
|
1167
|
+
const logicalMatcher = m16.unaryExpression("!", logicalExpression3);
|
|
1168
|
+
const binaryExpression7 = m16.capture(m16.binaryExpression(m16.or(...Object.values(INVERTED_BINARY_OPERATORS))));
|
|
1169
|
+
const binaryMatcher = m16.unaryExpression("!", binaryExpression7);
|
|
1170
|
+
return {
|
|
1171
|
+
UnaryExpression: {
|
|
1172
|
+
exit(path) {
|
|
1173
|
+
const { argument } = path.node;
|
|
1174
|
+
if (binaryMatcher.match(path.node)) {
|
|
1175
|
+
binaryExpression7.current.operator = INVERTED_BINARY_OPERATORS[binaryExpression7.current.operator];
|
|
1176
|
+
path.replaceWith(binaryExpression7.current);
|
|
1177
|
+
this.changes++;
|
|
1178
|
+
} else if (logicalMatcher.match(path.node)) {
|
|
1179
|
+
let current = argument;
|
|
1180
|
+
while (logicalExpression3.match(current)) {
|
|
1181
|
+
current.operator = INVERTED_LOGICAL_OPERATORS[current.operator];
|
|
1182
|
+
current.right = t16.unaryExpression("!", current.right);
|
|
1183
|
+
if (!logicalExpression3.match(current.left)) {
|
|
1184
|
+
current.left = t16.unaryExpression("!", current.left);
|
|
1185
|
+
}
|
|
1186
|
+
current = current.left;
|
|
1187
|
+
}
|
|
1188
|
+
path.replaceWith(argument);
|
|
1189
|
+
this.changes++;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
// node_modules/webcrack/src/unminify/transforms/json-parse.ts
|
|
1197
|
+
import {parseExpression} from "@babel/parser";
|
|
1198
|
+
import * as m17 from "@codemod/matchers";
|
|
1199
|
+
var json_parse_default = {
|
|
1200
|
+
name: "json-parse",
|
|
1201
|
+
tags: ["safe"],
|
|
1202
|
+
scope: true,
|
|
1203
|
+
visitor: () => {
|
|
1204
|
+
const string = m17.capture(m17.anyString());
|
|
1205
|
+
const matcher12 = m17.callExpression(constMemberExpression("JSON", "parse"), [
|
|
1206
|
+
m17.stringLiteral(string)
|
|
1207
|
+
]);
|
|
1208
|
+
return {
|
|
1209
|
+
CallExpression: {
|
|
1210
|
+
exit(path) {
|
|
1211
|
+
if (matcher12.match(path.node) && !path.scope.hasBinding("JSON", { noGlobals: true })) {
|
|
1212
|
+
try {
|
|
1213
|
+
JSON.parse(string.current);
|
|
1214
|
+
const parsed = parseExpression(string.current);
|
|
1215
|
+
path.replaceWith(parsed);
|
|
1216
|
+
this.changes++;
|
|
1217
|
+
} catch (error) {
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
// node_modules/webcrack/src/unminify/transforms/logical-to-if.ts
|
|
1226
|
+
import {statement} from "@babel/template";
|
|
1227
|
+
import * as m18 from "@codemod/matchers";
|
|
1228
|
+
var logical_to_if_default = {
|
|
1229
|
+
name: "logical-to-if",
|
|
1230
|
+
tags: ["safe"],
|
|
1231
|
+
visitor: () => {
|
|
1232
|
+
const andMatcher = m18.expressionStatement(m18.logicalExpression("&&"));
|
|
1233
|
+
const orMatcher = m18.expressionStatement(m18.logicalExpression("||"));
|
|
1234
|
+
const buildIf = statement`if (TEST) { BODY; }`;
|
|
1235
|
+
const buildIfNot = statement`if (!TEST) { BODY; }`;
|
|
1236
|
+
return {
|
|
1237
|
+
ExpressionStatement: {
|
|
1238
|
+
exit(path) {
|
|
1239
|
+
const expression2 = path.node.expression;
|
|
1240
|
+
if (andMatcher.match(path.node)) {
|
|
1241
|
+
path.replaceWith(buildIf({
|
|
1242
|
+
TEST: expression2.left,
|
|
1243
|
+
BODY: expression2.right
|
|
1244
|
+
}));
|
|
1245
|
+
this.changes++;
|
|
1246
|
+
} else if (orMatcher.match(path.node)) {
|
|
1247
|
+
path.replaceWith(buildIfNot({
|
|
1248
|
+
TEST: expression2.left,
|
|
1249
|
+
BODY: expression2.right
|
|
1250
|
+
}));
|
|
1251
|
+
this.changes++;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
// node_modules/webcrack/src/unminify/transforms/merge-else-if.ts
|
|
1259
|
+
import * as m19 from "@codemod/matchers";
|
|
1260
|
+
var merge_else_if_default = {
|
|
1261
|
+
name: "merge-else-if",
|
|
1262
|
+
tags: ["safe"],
|
|
1263
|
+
visitor() {
|
|
1264
|
+
const nestedIf = m19.capture(m19.ifStatement());
|
|
1265
|
+
const matcher12 = m19.ifStatement(m19.anything(), m19.anything(), m19.blockStatement([nestedIf]));
|
|
1266
|
+
return {
|
|
1267
|
+
IfStatement: {
|
|
1268
|
+
exit(path) {
|
|
1269
|
+
if (matcher12.match(path.node)) {
|
|
1270
|
+
path.node.alternate = nestedIf.current;
|
|
1271
|
+
this.changes++;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
// node_modules/webcrack/src/unminify/transforms/number-expressions.ts
|
|
1279
|
+
import * as t17 from "@babel/types";
|
|
1280
|
+
import * as m20 from "@codemod/matchers";
|
|
1281
|
+
var number_expressions_default = {
|
|
1282
|
+
name: "number-expressions",
|
|
1283
|
+
tags: ["safe"],
|
|
1284
|
+
visitor: () => ({
|
|
1285
|
+
"BinaryExpression|UnaryExpression": {
|
|
1286
|
+
exit(path) {
|
|
1287
|
+
if (matcher13.match(path.node)) {
|
|
1288
|
+
const evaluated = path.evaluate();
|
|
1289
|
+
if (evaluated.confident) {
|
|
1290
|
+
if (path.node.type === "BinaryExpression" && path.node.operator === "/" && !Number.isInteger(evaluated.value)) {
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
path.replaceWith(t17.valueToNode(evaluated.value));
|
|
1294
|
+
path.skip();
|
|
1295
|
+
this.changes++;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
})
|
|
1301
|
+
};
|
|
1302
|
+
var matcher13 = m20.or(m20.binaryExpression(m20.or("+", "-", "*", "/"), m20.matcher((node) => matcher13.match(node)), m20.matcher((node) => matcher13.match(node))), m20.binaryExpression("-", m20.or(m20.stringLiteral(), m20.matcher((node) => matcher13.match(node))), m20.or(m20.stringLiteral(), m20.matcher((node) => matcher13.match(node)))), m20.unaryExpression("-", m20.or(m20.stringLiteral(), m20.matcher((node) => matcher13.match(node)))), m20.numericLiteral());
|
|
1303
|
+
// node_modules/webcrack/src/unminify/transforms/raw-literals.ts
|
|
1304
|
+
var raw_literals_default = {
|
|
1305
|
+
name: "raw-literals",
|
|
1306
|
+
tags: ["safe"],
|
|
1307
|
+
visitor: () => ({
|
|
1308
|
+
StringLiteral(path) {
|
|
1309
|
+
if (path.node.extra) {
|
|
1310
|
+
path.node.extra = undefined;
|
|
1311
|
+
this.changes++;
|
|
1312
|
+
}
|
|
1313
|
+
},
|
|
1314
|
+
NumericLiteral(path) {
|
|
1315
|
+
if (path.node.extra) {
|
|
1316
|
+
path.node.extra = undefined;
|
|
1317
|
+
this.changes++;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
})
|
|
1321
|
+
};
|
|
1322
|
+
// node_modules/webcrack/src/unminify/transforms/sequence.ts
|
|
1323
|
+
import * as t18 from "@babel/types";
|
|
1324
|
+
import * as m21 from "@codemod/matchers";
|
|
1325
|
+
var sequence_default = {
|
|
1326
|
+
name: "sequence",
|
|
1327
|
+
tags: ["safe"],
|
|
1328
|
+
visitor() {
|
|
1329
|
+
const assignmentVariable = m21.or(m21.identifier(), m21.memberExpression(m21.identifier(), m21.identifier()));
|
|
1330
|
+
const assignedSequence = m21.capture(m21.sequenceExpression());
|
|
1331
|
+
const assignmentMatcher = m21.expressionStatement(m21.assignmentExpression(m21.or("=", "+=", "-=", "*=", "/=", "%=", "**=", "<<=", ">>=", ">>>=", "|=", "^=", "&="), assignmentVariable, assignedSequence));
|
|
1332
|
+
return {
|
|
1333
|
+
ExpressionStatement: {
|
|
1334
|
+
exit(path) {
|
|
1335
|
+
if (t18.isSequenceExpression(path.node.expression)) {
|
|
1336
|
+
const statements = path.node.expression.expressions.map((expr) => t18.expressionStatement(expr));
|
|
1337
|
+
path.replaceWithMultiple(statements);
|
|
1338
|
+
this.changes++;
|
|
1339
|
+
} else if (assignmentMatcher.match(path.node)) {
|
|
1340
|
+
const value = assignedSequence.current.expressions.pop();
|
|
1341
|
+
const statements = assignedSequence.current.expressions.map((expr) => t18.expressionStatement(expr));
|
|
1342
|
+
path.get("expression.right").replaceWith(value);
|
|
1343
|
+
path.insertBefore(statements);
|
|
1344
|
+
this.changes++;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
},
|
|
1348
|
+
ReturnStatement: {
|
|
1349
|
+
exit(path) {
|
|
1350
|
+
if (t18.isSequenceExpression(path.node.argument)) {
|
|
1351
|
+
const expressions = path.node.argument.expressions;
|
|
1352
|
+
path.node.argument = expressions.pop();
|
|
1353
|
+
const statements = expressions.map((expr) => t18.expressionStatement(expr));
|
|
1354
|
+
path.insertBefore(statements);
|
|
1355
|
+
this.changes++;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
},
|
|
1359
|
+
IfStatement: {
|
|
1360
|
+
exit(path) {
|
|
1361
|
+
if (t18.isSequenceExpression(path.node.test)) {
|
|
1362
|
+
const expressions = path.node.test.expressions;
|
|
1363
|
+
path.node.test = expressions.pop();
|
|
1364
|
+
const statements = expressions.map((expr) => t18.expressionStatement(expr));
|
|
1365
|
+
path.insertBefore(statements);
|
|
1366
|
+
this.changes++;
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
},
|
|
1370
|
+
SwitchStatement: {
|
|
1371
|
+
exit(path) {
|
|
1372
|
+
if (t18.isSequenceExpression(path.node.discriminant)) {
|
|
1373
|
+
const expressions = path.node.discriminant.expressions;
|
|
1374
|
+
path.node.discriminant = expressions.pop();
|
|
1375
|
+
const statements = expressions.map((expr) => t18.expressionStatement(expr));
|
|
1376
|
+
path.insertBefore(statements);
|
|
1377
|
+
this.changes++;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
},
|
|
1381
|
+
ThrowStatement: {
|
|
1382
|
+
exit(path) {
|
|
1383
|
+
if (t18.isSequenceExpression(path.node.argument)) {
|
|
1384
|
+
const expressions = path.node.argument.expressions;
|
|
1385
|
+
path.node.argument = expressions.pop();
|
|
1386
|
+
const statements = expressions.map((expr) => t18.expressionStatement(expr));
|
|
1387
|
+
path.insertBefore(statements);
|
|
1388
|
+
this.changes++;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
},
|
|
1392
|
+
ForInStatement: {
|
|
1393
|
+
exit(path) {
|
|
1394
|
+
const sequence = m21.capture(m21.sequenceExpression());
|
|
1395
|
+
const matcher14 = m21.forInStatement(m21.anything(), sequence);
|
|
1396
|
+
if (matcher14.match(path.node)) {
|
|
1397
|
+
const expressions = sequence.current.expressions;
|
|
1398
|
+
path.node.right = expressions.pop();
|
|
1399
|
+
const statements = expressions.map((expr) => t18.expressionStatement(expr));
|
|
1400
|
+
path.insertBefore(statements);
|
|
1401
|
+
this.changes++;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
},
|
|
1405
|
+
ForStatement: {
|
|
1406
|
+
exit(path) {
|
|
1407
|
+
if (t18.isSequenceExpression(path.node.init)) {
|
|
1408
|
+
const statements = path.node.init.expressions.map((expr) => t18.expressionStatement(expr));
|
|
1409
|
+
path.insertBefore(statements);
|
|
1410
|
+
path.node.init = null;
|
|
1411
|
+
this.changes++;
|
|
1412
|
+
}
|
|
1413
|
+
if (t18.isSequenceExpression(path.node.update) && path.node.body.type === "EmptyStatement") {
|
|
1414
|
+
const expressions = path.node.update.expressions;
|
|
1415
|
+
path.node.update = expressions.pop();
|
|
1416
|
+
const statements = expressions.map((expr) => t18.expressionStatement(expr));
|
|
1417
|
+
path.node.body = t18.blockStatement(statements);
|
|
1418
|
+
this.changes++;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
},
|
|
1422
|
+
WhileStatement: {
|
|
1423
|
+
exit(path) {
|
|
1424
|
+
if (t18.isSequenceExpression(path.node.test)) {
|
|
1425
|
+
const expressions = path.node.test.expressions;
|
|
1426
|
+
path.node.test = expressions.pop();
|
|
1427
|
+
const statements = expressions.map((expr) => t18.expressionStatement(expr));
|
|
1428
|
+
path.insertBefore(statements);
|
|
1429
|
+
this.changes++;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
},
|
|
1433
|
+
VariableDeclaration: {
|
|
1434
|
+
exit(path) {
|
|
1435
|
+
const sequence = m21.capture(m21.sequenceExpression());
|
|
1436
|
+
const matcher14 = m21.variableDeclaration(undefined, [
|
|
1437
|
+
m21.variableDeclarator(undefined, sequence)
|
|
1438
|
+
]);
|
|
1439
|
+
if (matcher14.match(path.node)) {
|
|
1440
|
+
const expressions = sequence.current.expressions;
|
|
1441
|
+
path.node.declarations[0].init = expressions.pop();
|
|
1442
|
+
const statements = expressions.map((expr) => t18.expressionStatement(expr));
|
|
1443
|
+
if (path.parentPath.isForStatement() && path.key === "init") {
|
|
1444
|
+
path.parentPath.insertBefore(statements);
|
|
1445
|
+
} else {
|
|
1446
|
+
path.insertBefore(statements);
|
|
1447
|
+
}
|
|
1448
|
+
this.changes++;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
};
|
|
1455
|
+
// node_modules/webcrack/src/unminify/transforms/split-variable-declarations.ts
|
|
1456
|
+
import * as t19 from "@babel/types";
|
|
1457
|
+
var split_variable_declarations_default = {
|
|
1458
|
+
name: "split-variable-declarations",
|
|
1459
|
+
tags: ["safe"],
|
|
1460
|
+
visitor: () => ({
|
|
1461
|
+
VariableDeclaration: {
|
|
1462
|
+
exit(path) {
|
|
1463
|
+
if (path.node.declarations.length > 1 && path.key !== "init") {
|
|
1464
|
+
if (path.parentPath.isExportNamedDeclaration()) {
|
|
1465
|
+
path.parentPath.replaceWithMultiple(path.node.declarations.map((declaration) => t19.exportNamedDeclaration(t19.variableDeclaration(path.node.kind, [declaration]))));
|
|
1466
|
+
} else {
|
|
1467
|
+
path.replaceWithMultiple(path.node.declarations.map((declaration) => t19.variableDeclaration(path.node.kind, [declaration])));
|
|
1468
|
+
}
|
|
1469
|
+
this.changes++;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
})
|
|
1474
|
+
};
|
|
1475
|
+
// node_modules/webcrack/src/unminify/transforms/ternary-to-if.ts
|
|
1476
|
+
import {statement as statement2} from "@babel/template";
|
|
1477
|
+
import * as m22 from "@codemod/matchers";
|
|
1478
|
+
var ternary_to_if_default = {
|
|
1479
|
+
name: "ternary-to-if",
|
|
1480
|
+
tags: ["safe"],
|
|
1481
|
+
visitor() {
|
|
1482
|
+
const test = m22.capture(m22.anyExpression());
|
|
1483
|
+
const consequent = m22.capture(m22.anyExpression());
|
|
1484
|
+
const alternate = m22.capture(m22.anyExpression());
|
|
1485
|
+
const conditional = m22.conditionalExpression(test, consequent, alternate);
|
|
1486
|
+
const buildIf = statement2`if (TEST) { CONSEQUENT; } else { ALTERNATE; }`;
|
|
1487
|
+
const buildIfReturn = statement2`if (TEST) { return CONSEQUENT; } else { return ALTERNATE; }`;
|
|
1488
|
+
return {
|
|
1489
|
+
ExpressionStatement: {
|
|
1490
|
+
exit(path) {
|
|
1491
|
+
if (conditional.match(path.node.expression)) {
|
|
1492
|
+
path.replaceWith(buildIf({
|
|
1493
|
+
TEST: test.current,
|
|
1494
|
+
CONSEQUENT: consequent.current,
|
|
1495
|
+
ALTERNATE: alternate.current
|
|
1496
|
+
}));
|
|
1497
|
+
this.changes++;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
},
|
|
1501
|
+
ReturnStatement: {
|
|
1502
|
+
exit(path) {
|
|
1503
|
+
if (conditional.match(path.node.argument)) {
|
|
1504
|
+
path.replaceWith(buildIfReturn({
|
|
1505
|
+
TEST: test.current,
|
|
1506
|
+
CONSEQUENT: consequent.current,
|
|
1507
|
+
ALTERNATE: alternate.current
|
|
1508
|
+
}));
|
|
1509
|
+
this.changes++;
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
// node_modules/webcrack/src/unminify/transforms/typeof-undefined.ts
|
|
1517
|
+
import * as t20 from "@babel/types";
|
|
1518
|
+
import * as m23 from "@codemod/matchers";
|
|
1519
|
+
var OPERATOR_MAP = {
|
|
1520
|
+
">": "===",
|
|
1521
|
+
"<": "!=="
|
|
1522
|
+
};
|
|
1523
|
+
var typeof_undefined_default = {
|
|
1524
|
+
name: "typeof-undefined",
|
|
1525
|
+
tags: ["safe"],
|
|
1526
|
+
visitor() {
|
|
1527
|
+
const operator = m23.capture(m23.or(">", "<"));
|
|
1528
|
+
const argument = m23.capture(m23.anyExpression());
|
|
1529
|
+
const matcher14 = m23.binaryExpression(operator, m23.unaryExpression("typeof", argument), m23.stringLiteral("u"));
|
|
1530
|
+
return {
|
|
1531
|
+
BinaryExpression: {
|
|
1532
|
+
exit(path) {
|
|
1533
|
+
if (!matcher14.match(path.node))
|
|
1534
|
+
return;
|
|
1535
|
+
path.replaceWith(t20.binaryExpression(OPERATOR_MAP[operator.current], t20.unaryExpression("typeof", argument.current), t20.stringLiteral("undefined")));
|
|
1536
|
+
this.changes++;
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
// node_modules/webcrack/src/unminify/transforms/unary-expressions.ts
|
|
1543
|
+
import * as t21 from "@babel/types";
|
|
1544
|
+
import * as m24 from "@codemod/matchers";
|
|
1545
|
+
var unary_expressions_default = {
|
|
1546
|
+
name: "unary-expressions",
|
|
1547
|
+
tags: ["safe"],
|
|
1548
|
+
visitor() {
|
|
1549
|
+
const argument = m24.capture(m24.anyExpression());
|
|
1550
|
+
const matcher14 = m24.expressionStatement(m24.unaryExpression(m24.or("void", "!", "typeof"), argument));
|
|
1551
|
+
const returnVoid = m24.returnStatement(m24.unaryExpression("void", argument));
|
|
1552
|
+
return {
|
|
1553
|
+
ExpressionStatement: {
|
|
1554
|
+
exit(path) {
|
|
1555
|
+
if (!matcher14.match(path.node))
|
|
1556
|
+
return;
|
|
1557
|
+
path.replaceWith(argument.current);
|
|
1558
|
+
this.changes++;
|
|
1559
|
+
}
|
|
1560
|
+
},
|
|
1561
|
+
ReturnStatement: {
|
|
1562
|
+
exit(path) {
|
|
1563
|
+
if (!returnVoid.match(path.node))
|
|
1564
|
+
return;
|
|
1565
|
+
path.replaceWith(argument.current);
|
|
1566
|
+
path.insertAfter(t21.returnStatement());
|
|
1567
|
+
this.changes++;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
// node_modules/webcrack/src/unminify/transforms/unminify-booleans.ts
|
|
1574
|
+
import * as t22 from "@babel/types";
|
|
1575
|
+
import * as m25 from "@codemod/matchers";
|
|
1576
|
+
var unminify_booleans_default = {
|
|
1577
|
+
name: "unminify-booleans",
|
|
1578
|
+
tags: ["safe"],
|
|
1579
|
+
visitor: () => ({
|
|
1580
|
+
UnaryExpression(path) {
|
|
1581
|
+
if (trueMatcher2.match(path.node)) {
|
|
1582
|
+
path.replaceWith(t22.booleanLiteral(true));
|
|
1583
|
+
this.changes++;
|
|
1584
|
+
} else if (falseMatcher2.match(path.node)) {
|
|
1585
|
+
path.replaceWith(t22.booleanLiteral(false));
|
|
1586
|
+
this.changes++;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
})
|
|
1590
|
+
};
|
|
1591
|
+
var trueMatcher2 = m25.or(m25.unaryExpression("!", m25.numericLiteral(0)), m25.unaryExpression("!", m25.unaryExpression("!", m25.numericLiteral(1))), m25.unaryExpression("!", m25.unaryExpression("!", m25.arrayExpression([]))));
|
|
1592
|
+
var falseMatcher2 = m25.or(m25.unaryExpression("!", m25.numericLiteral(1)), m25.unaryExpression("!", m25.arrayExpression([])));
|
|
1593
|
+
// node_modules/webcrack/src/unminify/transforms/void-to-undefined.ts
|
|
1594
|
+
import * as t23 from "@babel/types";
|
|
1595
|
+
import * as m26 from "@codemod/matchers";
|
|
1596
|
+
var void_to_undefined_default = {
|
|
1597
|
+
name: "void-to-undefined",
|
|
1598
|
+
tags: ["safe"],
|
|
1599
|
+
scope: true,
|
|
1600
|
+
visitor: () => {
|
|
1601
|
+
const matcher14 = m26.unaryExpression("void", m26.numericLiteral(0));
|
|
1602
|
+
return {
|
|
1603
|
+
UnaryExpression: {
|
|
1604
|
+
exit(path) {
|
|
1605
|
+
if (matcher14.match(path.node) && !path.scope.hasBinding("undefined", { noGlobals: true })) {
|
|
1606
|
+
path.replaceWith(t23.identifier("undefined"));
|
|
1607
|
+
this.changes++;
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
// node_modules/webcrack/src/unminify/transforms/yoda.ts
|
|
1615
|
+
import * as t24 from "@babel/types";
|
|
1616
|
+
import * as m27 from "@codemod/matchers";
|
|
1617
|
+
var FLIPPED_OPERATORS = {
|
|
1618
|
+
"==": "==",
|
|
1619
|
+
"===": "===",
|
|
1620
|
+
"!=": "!=",
|
|
1621
|
+
"!==": "!==",
|
|
1622
|
+
">": "<",
|
|
1623
|
+
"<": ">",
|
|
1624
|
+
">=": "<=",
|
|
1625
|
+
"<=": ">=",
|
|
1626
|
+
"*": "*",
|
|
1627
|
+
"^": "^",
|
|
1628
|
+
"&": "&",
|
|
1629
|
+
"|": "|"
|
|
1630
|
+
};
|
|
1631
|
+
var yoda_default = {
|
|
1632
|
+
name: "yoda",
|
|
1633
|
+
tags: ["safe"],
|
|
1634
|
+
visitor: () => {
|
|
1635
|
+
const matcher15 = m27.binaryExpression(m27.or(...Object.values(FLIPPED_OPERATORS)), m27.or(m27.stringLiteral(), m27.numericLiteral(), m27.unaryExpression("-", m27.or(m27.numericLiteral(), m27.identifier("Infinity"))), m27.booleanLiteral(), m27.nullLiteral(), m27.identifier("undefined"), m27.identifier("NaN"), m27.identifier("Infinity")), m27.matcher((node) => !t24.isLiteral(node)));
|
|
1636
|
+
return {
|
|
1637
|
+
BinaryExpression: {
|
|
1638
|
+
exit(path) {
|
|
1639
|
+
if (matcher15.match(path.node)) {
|
|
1640
|
+
path.replaceWith(t24.binaryExpression(FLIPPED_OPERATORS[path.node.operator], path.node.right, path.node.left));
|
|
1641
|
+
this.changes++;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
};
|
|
1648
|
+
// node_modules/webcrack/src/unminify/index.ts
|
|
1649
|
+
var unminify_default = mergeTransforms({
|
|
1650
|
+
name: "unminify",
|
|
1651
|
+
tags: ["safe"],
|
|
1652
|
+
transforms: Object.values(exports_transforms)
|
|
1653
|
+
});
|
|
1654
|
+
|
|
1655
|
+
// transform/webcrack/index.ts
|
|
1656
|
+
async function transform2(ast2) {
|
|
1657
|
+
applyTransforms(ast2, [block_statements_default, sequence_default, split_variable_declarations_default, var_functions_default], {
|
|
1658
|
+
name: "prepare"
|
|
1659
|
+
});
|
|
1660
|
+
const quickjs = await getQuickJS();
|
|
1661
|
+
await applyTransformAsync(ast2, deobfuscate_default, async (code) => quickjs.evalCode(code, {
|
|
1662
|
+
shouldInterrupt: shouldInterruptAfterDeadline(Date.now() + 2000),
|
|
1663
|
+
memoryLimitBytes: 1048576
|
|
1664
|
+
}));
|
|
1665
|
+
applyTransform(ast2, unminify_default);
|
|
1666
|
+
applyTransform(ast2, merge_object_assignments_default);
|
|
1667
|
+
return ast2;
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
// transform/esmodule/module-helper.ts
|
|
1671
|
+
import * as t25 from "@babel/types";
|
|
1672
|
+
import * as m34 from "@codemod/matchers";
|
|
1673
|
+
|
|
1674
|
+
// utils/matchers/chunk.ts
|
|
1675
|
+
import * as m28 from "@codemod/matchers";
|
|
1676
|
+
function chunk(id) {
|
|
1677
|
+
return m28.objectProperty(m28.numericLiteral(id), m28.or(functionExpr([]), functionExpr([mod]), functionExpr([mod, exp]), functionExpr([mod, exp, req])));
|
|
1678
|
+
}
|
|
1679
|
+
var mod = m28.capture(m28.identifier());
|
|
1680
|
+
var exp = m28.capture(m28.identifier());
|
|
1681
|
+
var req = m28.capture(m28.identifier());
|
|
1682
|
+
var functionExpr = (args) => m28.or(m28.functionExpression(null, args, m28.blockStatement(), false, false), m28.arrowFunctionExpression(args, m28.blockStatement(), false));
|
|
1683
|
+
var chunks = m28.objectExpression(m28.anyList(m28.oneOrMore(chunk())));
|
|
1684
|
+
var chunk_default = chunk();
|
|
1685
|
+
|
|
1686
|
+
// utils/matchers/createBinding.ts
|
|
1687
|
+
import * as m29 from "@codemod/matchers";
|
|
1688
|
+
import tmpl from "@babel/template";
|
|
1689
|
+
var __createBinding = tmpl.expression.ast`
|
|
1690
|
+
(this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
1691
|
+
if (k2 === undefined) k2 = k;
|
|
1692
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1693
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1694
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
1695
|
+
}
|
|
1696
|
+
Object.defineProperty(o, k2, desc);
|
|
1697
|
+
}) : (function(o, m, k, k2) {
|
|
1698
|
+
if (k2 === undefined) k2 = k;
|
|
1699
|
+
o[k2] = m[k];
|
|
1700
|
+
}))
|
|
1701
|
+
`;
|
|
1702
|
+
var obj = m29.capture(m29.identifier());
|
|
1703
|
+
var mod2 = m29.capture(m29.identifier());
|
|
1704
|
+
var k = m29.capture(m29.identifier());
|
|
1705
|
+
var k2 = m29.capture(m29.identifier());
|
|
1706
|
+
var desc = m29.capture(m29.identifier());
|
|
1707
|
+
var descObj = m29.objectExpression([
|
|
1708
|
+
m29.objectProperty(m29.identifier("enumerable"), m29.booleanLiteral(true)),
|
|
1709
|
+
m29.objectProperty(m29.identifier("get"), m29.functionExpression(null, [], m29.blockStatement([
|
|
1710
|
+
m29.returnStatement(m29.memberExpression(m29.fromCapture(mod2), m29.fromCapture(k), true))
|
|
1711
|
+
])))
|
|
1712
|
+
]);
|
|
1713
|
+
var cond = m29.conditionalExpression(m29.binaryExpression("in", m29.stringLiteral("get"), m29.fromCapture(desc)), m29.unaryExpression("!", m29.memberExpression(m29.fromCapture(mod2), m29.identifier("__esModule"), false)), m29.logicalExpression("||", m29.memberExpression(m29.fromCapture(desc), m29.identifier("writable"), false), m29.memberExpression(m29.fromCapture(desc), m29.identifier("configurable"), false)));
|
|
1714
|
+
var createBinding_default = m29.variableDeclaration("var", [
|
|
1715
|
+
m29.variableDeclarator(m29.identifier(), m29.logicalExpression("||", m29.logicalExpression("&&", m29.thisExpression(), m29.memberExpression(m29.thisExpression(), m29.identifier("__createBinding"))), m29.conditionalExpression(m29.memberExpression(m29.identifier("Object"), m29.identifier("create")), m29.functionExpression(null, [obj, mod2, k, k2], m29.or(m29.blockStatement([
|
|
1716
|
+
m29.ifStatement(m29.binaryExpression("===", k2, m29.identifier("undefined")), m29.containerOf(m29.expressionStatement(m29.assignmentExpression("=", m29.fromCapture(k2), m29.fromCapture(k)))), null),
|
|
1717
|
+
m29.variableDeclaration("var", [
|
|
1718
|
+
m29.variableDeclarator(desc, m29.callExpression(m29.memberExpression(m29.identifier("Object"), m29.identifier("getOwnPropertyDescriptor"), false), [
|
|
1719
|
+
m29.fromCapture(mod2),
|
|
1720
|
+
m29.fromCapture(k)
|
|
1721
|
+
]))
|
|
1722
|
+
]),
|
|
1723
|
+
m29.ifStatement(m29.logicalExpression("||", m29.unaryExpression("!", m29.fromCapture(desc), true), m29.or(cond, m29.unaryExpression("!", m29.unaryExpression("!", cond, true), true))), m29.blockStatement([
|
|
1724
|
+
m29.expressionStatement(m29.assignmentExpression("=", m29.fromCapture(desc), descObj))
|
|
1725
|
+
]), null),
|
|
1726
|
+
m29.expressionStatement(m29.callExpression(m29.memberExpression(m29.identifier("Object"), m29.identifier("defineProperty"), false), [
|
|
1727
|
+
m29.fromCapture(obj),
|
|
1728
|
+
m29.fromCapture(k2),
|
|
1729
|
+
m29.fromCapture(desc)
|
|
1730
|
+
]))
|
|
1731
|
+
]), m29.blockStatement([
|
|
1732
|
+
m29.ifStatement(m29.binaryExpression("===", k2, m29.identifier("undefined")), m29.containerOf(m29.expressionStatement(m29.assignmentExpression("=", m29.fromCapture(k2), m29.fromCapture(k)))), null),
|
|
1733
|
+
m29.expressionStatement(m29.callExpression(m29.memberExpression(m29.identifier("Object"), m29.identifier("defineProperty"), false), [
|
|
1734
|
+
m29.fromCapture(obj),
|
|
1735
|
+
m29.fromCapture(k2),
|
|
1736
|
+
descObj
|
|
1737
|
+
]))
|
|
1738
|
+
]))), m29.functionExpression(null, [obj, mod2, k, k2], m29.blockStatement([
|
|
1739
|
+
m29.ifStatement(m29.binaryExpression("===", k2, m29.identifier("undefined")), m29.containerOf(m29.expressionStatement(m29.assignmentExpression("=", m29.fromCapture(k2), m29.fromCapture(k)))), null),
|
|
1740
|
+
m29.expressionStatement(m29.assignmentExpression("=", m29.memberExpression(m29.fromCapture(obj), m29.fromCapture(k2), true), m29.memberExpression(m29.fromCapture(mod2), m29.fromCapture(k), true)))
|
|
1741
|
+
])))))
|
|
1742
|
+
]);
|
|
1743
|
+
|
|
1744
|
+
// utils/matchers/setModuleDefault.ts
|
|
1745
|
+
import * as m30 from "@codemod/matchers";
|
|
1746
|
+
import tmpl2 from "@babel/template";
|
|
1747
|
+
var __setModuleDefault = tmpl2.expression.ast`
|
|
1748
|
+
(this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
1749
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1750
|
+
}) : function(o, v) {
|
|
1751
|
+
o["default"] = v;
|
|
1752
|
+
})
|
|
1753
|
+
`;
|
|
1754
|
+
var leftParamObj = m30.capture(m30.identifier());
|
|
1755
|
+
var leftParamVal = m30.capture(m30.identifier());
|
|
1756
|
+
var leftObjIdentifier = m30.capture(m30.identifier());
|
|
1757
|
+
var leftObj = m30.objectExpression([
|
|
1758
|
+
m30.objectProperty(m30.identifier("enumerable"), m30.booleanLiteral(true)),
|
|
1759
|
+
m30.objectProperty(m30.identifier("value"), leftParamVal)
|
|
1760
|
+
]);
|
|
1761
|
+
var rightParamObj = m30.capture(m30.identifier());
|
|
1762
|
+
var rightParamVal = m30.capture(m30.identifier());
|
|
1763
|
+
var setModuleDefault_default = m30.variableDeclaration("var", [
|
|
1764
|
+
m30.variableDeclarator(m30.identifier(), m30.logicalExpression("||", m30.logicalExpression("&&", m30.thisExpression(), m30.memberExpression(m30.thisExpression(), m30.identifier("__setModuleDefault"))), m30.conditionalExpression(m30.memberExpression(m30.identifier("Object"), m30.identifier("create")), m30.functionExpression(null, [
|
|
1765
|
+
leftParamObj,
|
|
1766
|
+
leftParamVal
|
|
1767
|
+
], m30.or(m30.blockStatement([
|
|
1768
|
+
m30.variableDeclaration("const", [m30.variableDeclarator(leftObjIdentifier, leftObj)]),
|
|
1769
|
+
m30.expressionStatement(m30.callExpression(m30.memberExpression(m30.identifier("Object"), m30.identifier("defineProperty")), [
|
|
1770
|
+
leftParamObj,
|
|
1771
|
+
m30.stringLiteral("default"),
|
|
1772
|
+
leftObjIdentifier
|
|
1773
|
+
]))
|
|
1774
|
+
]), m30.blockStatement([
|
|
1775
|
+
m30.expressionStatement(m30.callExpression(m30.memberExpression(m30.identifier("Object"), m30.identifier("defineProperty")), [
|
|
1776
|
+
leftParamObj,
|
|
1777
|
+
m30.stringLiteral("default"),
|
|
1778
|
+
leftObj
|
|
1779
|
+
]))
|
|
1780
|
+
])), false, false), m30.functionExpression(null, [
|
|
1781
|
+
rightParamObj,
|
|
1782
|
+
rightParamVal
|
|
1783
|
+
], m30.blockStatement([
|
|
1784
|
+
m30.expressionStatement(m30.assignmentExpression("=", m30.memberExpression(rightParamObj, m30.identifier("default")), rightParamVal))
|
|
1785
|
+
])))))
|
|
1786
|
+
]);
|
|
1787
|
+
|
|
1788
|
+
// utils/matchers/importStar.ts
|
|
1789
|
+
import * as m31 from "@codemod/matchers";
|
|
1790
|
+
import tmpl3 from "@babel/template";
|
|
1791
|
+
var __importStar = tmpl3.expression.ast`
|
|
1792
|
+
(this && this.__importStar) || function (mod) {
|
|
1793
|
+
if (mod && mod.__esModule) return mod;
|
|
1794
|
+
var result = {};
|
|
1795
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
1796
|
+
__setModuleDefault(result, mod);
|
|
1797
|
+
return result;
|
|
1798
|
+
}
|
|
1799
|
+
`;
|
|
1800
|
+
var mod3 = m31.capture(m31.identifier());
|
|
1801
|
+
var k3 = m31.capture(m31.identifier());
|
|
1802
|
+
var result = m31.capture(m31.identifier());
|
|
1803
|
+
var importStar_default = m31.variableDeclaration("var", [
|
|
1804
|
+
m31.variableDeclarator(m31.identifier(), m31.logicalExpression("||", m31.logicalExpression("&&", m31.thisExpression(), m31.memberExpression(m31.thisExpression(), m31.identifier("__importStar"), false)), m31.functionExpression(null, [mod3], m31.or(m31.blockStatement([
|
|
1805
|
+
m31.ifStatement(m31.logicalExpression("&&", m31.fromCapture(mod3), m31.memberExpression(m31.fromCapture(mod3), m31.identifier("__esModule"))), m31.containerOf(m31.returnStatement(m31.fromCapture(mod3))), null),
|
|
1806
|
+
m31.variableDeclaration("var", [
|
|
1807
|
+
m31.variableDeclarator(result, m31.objectExpression([]))
|
|
1808
|
+
]),
|
|
1809
|
+
m31.ifStatement(m31.binaryExpression("!=", m31.fromCapture(mod3), m31.nullLiteral()), m31.containerOf(m31.forInStatement(m31.variableDeclaration("var", [
|
|
1810
|
+
m31.variableDeclarator(k3, null)
|
|
1811
|
+
]), m31.fromCapture(mod3), m31.containerOf(m31.ifStatement(m31.logicalExpression("&&", m31.binaryExpression("!==", m31.fromCapture(k3), m31.stringLiteral("default")), m31.callExpression(m31.memberExpression(m31.memberExpression(m31.memberExpression(m31.identifier("Object"), m31.identifier("prototype"), false), m31.identifier("hasOwnProperty"), false), m31.identifier("call"), false), [
|
|
1812
|
+
m31.fromCapture(mod3),
|
|
1813
|
+
m31.fromCapture(k3)
|
|
1814
|
+
])), m31.containerOf(m31.callExpression(m31.identifier(), [
|
|
1815
|
+
m31.fromCapture(result),
|
|
1816
|
+
m31.fromCapture(mod3),
|
|
1817
|
+
m31.fromCapture(k3)
|
|
1818
|
+
])))))), null),
|
|
1819
|
+
m31.expressionStatement(m31.callExpression(m31.identifier(), [
|
|
1820
|
+
m31.fromCapture(result),
|
|
1821
|
+
m31.fromCapture(mod3)
|
|
1822
|
+
])),
|
|
1823
|
+
m31.returnStatement(m31.fromCapture(result))
|
|
1824
|
+
])))))
|
|
1825
|
+
]);
|
|
1826
|
+
|
|
1827
|
+
// utils/matchers/importDefault.ts
|
|
1828
|
+
import * as m32 from "@codemod/matchers";
|
|
1829
|
+
import tmpl4 from "@babel/template";
|
|
1830
|
+
var __importDefault = tmpl4.expression.ast`
|
|
1831
|
+
(this && this.__importDefault) || function (mod) {
|
|
1832
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
1833
|
+
}
|
|
1834
|
+
`;
|
|
1835
|
+
var mod4 = m32.capture(m32.identifier());
|
|
1836
|
+
var isEsm = m32.logicalExpression("&&", m32.fromCapture(mod4), m32.memberExpression(m32.fromCapture(mod4), m32.identifier("__esModule"), false));
|
|
1837
|
+
var importDefault_default = m32.variableDeclaration("var", [
|
|
1838
|
+
m32.variableDeclarator(m32.identifier(), m32.logicalExpression("||", m32.logicalExpression("&&", m32.thisExpression(), m32.memberExpression(m32.thisExpression(), m32.identifier("__importDefault"))), m32.functionExpression(null, [mod4], m32.blockStatement([
|
|
1839
|
+
m32.or(m32.returnStatement(m32.conditionalExpression(isEsm, m32.fromCapture(mod4), m32.objectExpression([
|
|
1840
|
+
m32.objectProperty(m32.stringLiteral("default"), m32.fromCapture(mod4), false)
|
|
1841
|
+
]))), m32.ifStatement(isEsm, m32.containerOf(m32.returnStatement(m32.fromCapture(mod4))), m32.containerOf(m32.returnStatement(m32.objectExpression([
|
|
1842
|
+
m32.objectProperty(m32.identifier("default"), m32.fromCapture(mod4), false)
|
|
1843
|
+
])))))
|
|
1844
|
+
]))))
|
|
1845
|
+
]);
|
|
1846
|
+
|
|
1847
|
+
// utils/matchers/exportStar.ts
|
|
1848
|
+
import * as m33 from "@codemod/matchers";
|
|
1849
|
+
import tmpl5 from "@babel/template";
|
|
1850
|
+
var __exportStar = tmpl5.expression.ast`
|
|
1851
|
+
(this && this.__exportStar) || function(m, exports) {
|
|
1852
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1853
|
+
}
|
|
1854
|
+
`;
|
|
1855
|
+
var mod5 = m33.capture(m33.identifier());
|
|
1856
|
+
var exp2 = m33.capture(m33.identifier());
|
|
1857
|
+
var p = m33.capture(m33.identifier());
|
|
1858
|
+
var exportStar_default = m33.variableDeclaration("var", [
|
|
1859
|
+
m33.variableDeclarator(m33.identifier(), m33.logicalExpression("||", m33.logicalExpression("&&", m33.thisExpression(), m33.memberExpression(m33.thisExpression(), m33.identifier("__exportStar"), false)), m33.functionExpression(null, [mod5, exp2], m33.blockStatement([
|
|
1860
|
+
m33.forInStatement(m33.variableDeclaration("var", [
|
|
1861
|
+
m33.variableDeclarator(p)
|
|
1862
|
+
]), m33.fromCapture(mod5), m33.containerOf(m33.ifStatement(m33.logicalExpression("&&", m33.binaryExpression("!==", m33.fromCapture(p), m33.stringLiteral("default")), m33.unaryExpression("!", m33.callExpression(m33.memberExpression(m33.memberExpression(m33.memberExpression(m33.identifier("Object"), m33.identifier("prototype"), false), m33.identifier("hasOwnProperty"), false), m33.identifier("call"), false), [
|
|
1863
|
+
m33.fromCapture(exp2),
|
|
1864
|
+
m33.fromCapture(p)
|
|
1865
|
+
]), true)), m33.containerOf(m33.expressionStatement(m33.callExpression(m33.identifier(), [
|
|
1866
|
+
m33.fromCapture(exp2),
|
|
1867
|
+
m33.fromCapture(mod5),
|
|
1868
|
+
m33.fromCapture(p)
|
|
1869
|
+
]))))))
|
|
1870
|
+
]))))
|
|
1871
|
+
]);
|
|
1872
|
+
|
|
1873
|
+
// transform/esmodule/module-helper.ts
|
|
1874
|
+
var preExport = m34.assignmentExpression("=", m34.memberExpression(m34.identifier("exports"), m34.identifier(), false), m34.identifier("undefined"));
|
|
1875
|
+
var undefinedExpr = m34.expressionStatement(m34.identifier("undefined"));
|
|
1876
|
+
var module_helper_default = {
|
|
1877
|
+
name: "module-helper",
|
|
1878
|
+
tags: ["safe"],
|
|
1879
|
+
scope: true,
|
|
1880
|
+
visitor: () => ({
|
|
1881
|
+
ObjectExpression: {
|
|
1882
|
+
enter($) {
|
|
1883
|
+
if (!chunks.match($.node)) {
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
const $chunks = $.get("properties");
|
|
1887
|
+
for (const $chunk of $chunks) {
|
|
1888
|
+
$chunk.assertObjectProperty();
|
|
1889
|
+
const $func = $chunk.get("value");
|
|
1890
|
+
$func.assertFunction();
|
|
1891
|
+
const $p = $func.get("params");
|
|
1892
|
+
$p.forEach(($parameter, i) => {
|
|
1893
|
+
$parameter.assertIdentifier();
|
|
1894
|
+
switch (i) {
|
|
1895
|
+
case 0: {
|
|
1896
|
+
$func.scope.rename($parameter.node.name, "module");
|
|
1897
|
+
break;
|
|
1898
|
+
}
|
|
1899
|
+
case 1: {
|
|
1900
|
+
$func.scope.rename($parameter.node.name, "exports");
|
|
1901
|
+
break;
|
|
1902
|
+
}
|
|
1903
|
+
case 2: {
|
|
1904
|
+
$func.scope.rename($parameter.node.name, "require");
|
|
1905
|
+
break;
|
|
1906
|
+
}
|
|
1907
|
+
default: {
|
|
1908
|
+
throw new Error("Unexpected param");
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
});
|
|
1912
|
+
$func.traverse({
|
|
1913
|
+
VariableDeclaration: {
|
|
1914
|
+
exit(p2) {
|
|
1915
|
+
const $decl = p2.get("declarations.0");
|
|
1916
|
+
$decl.assertVariableDeclarator();
|
|
1917
|
+
const $id = $decl.get("id");
|
|
1918
|
+
if (!$id.isIdentifier()) {
|
|
1919
|
+
return;
|
|
1920
|
+
}
|
|
1921
|
+
if (importStar_default.match(t25.cloneNode(p2.node))) {
|
|
1922
|
+
$id.scope.rename($id.node.name, "__importStar");
|
|
1923
|
+
$decl.get("init").replaceWith(__importStar);
|
|
1924
|
+
} else if (setModuleDefault_default.match(t25.cloneNode(p2.node))) {
|
|
1925
|
+
$id.scope.rename($id.node.name, "__setModuleDefault");
|
|
1926
|
+
$decl.get("init").replaceWith(__setModuleDefault);
|
|
1927
|
+
} else if (importDefault_default.match(t25.cloneNode(p2.node))) {
|
|
1928
|
+
$id.scope.rename($id.node.name, "__importDefault");
|
|
1929
|
+
$decl.get("init").replaceWith(__importDefault);
|
|
1930
|
+
} else if (createBinding_default.match(t25.cloneNode(p2.node))) {
|
|
1931
|
+
$id.scope.rename($id.node.name, "__createBinding");
|
|
1932
|
+
$decl.get("init").replaceWith(__createBinding);
|
|
1933
|
+
} else if (exportStar_default.match(t25.cloneNode(p2.node))) {
|
|
1934
|
+
$id.scope.rename($id.node.name, "__exportStar");
|
|
1935
|
+
$decl.get("init").replaceWith(__exportStar);
|
|
1936
|
+
} else {
|
|
1937
|
+
return;
|
|
1938
|
+
}
|
|
1939
|
+
this.changes++;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
}, this);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
})
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
// transform/esmodule/indirect-call.ts
|
|
1950
|
+
import * as t26 from "@babel/types";
|
|
1951
|
+
var indirect_call_default = {
|
|
1952
|
+
name: "indirect-call",
|
|
1953
|
+
tags: ["unsafe"],
|
|
1954
|
+
visitor: () => ({
|
|
1955
|
+
CallExpression: {
|
|
1956
|
+
exit($) {
|
|
1957
|
+
const { callee, arguments: args } = $.node;
|
|
1958
|
+
if (!t26.isSequenceExpression(callee)) {
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1961
|
+
const exprs = [...callee.expressions];
|
|
1962
|
+
const func = exprs.pop();
|
|
1963
|
+
if (!t26.isMemberExpression(func)) {
|
|
1964
|
+
return;
|
|
1965
|
+
}
|
|
1966
|
+
if (exprs.every((expr) => t26.isPureish(expr))) {
|
|
1967
|
+
$.replaceWith(t26.callExpression(func, args));
|
|
1968
|
+
this.changes++;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
})
|
|
1973
|
+
};
|
|
1974
|
+
|
|
1975
|
+
// utils/ast.ts
|
|
1976
|
+
import {parse as babelParse} from "@babel/parser";
|
|
1977
|
+
import babelGenerate2 from "@babel/generator";
|
|
1978
|
+
import debug4 from "debug";
|
|
1979
|
+
import traverse10, {visitors as visitors2} from "@babel/traverse";
|
|
1980
|
+
function parse(code) {
|
|
1981
|
+
return babelParse(code, {
|
|
1982
|
+
sourceType: "script",
|
|
1983
|
+
allowReturnOutsideFunction: true
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
function generate2(ast2) {
|
|
1987
|
+
return babelGenerate2(ast2, { jsescOption: { minimal: true, quotes: "single" } }).code;
|
|
1988
|
+
}
|
|
1989
|
+
function applyTransform2(ast2, transform3, options, noScopeOverride) {
|
|
1990
|
+
logger2(`${transform3.name}: started`);
|
|
1991
|
+
const state = { changes: 0 };
|
|
1992
|
+
transform3.run?.(ast2, state, options);
|
|
1993
|
+
if (transform3.visitor) {
|
|
1994
|
+
const visitor = transform3.visitor(options);
|
|
1995
|
+
visitor.noScope = noScopeOverride ?? !transform3.scope;
|
|
1996
|
+
traverse10(ast2, visitor, undefined, state);
|
|
1997
|
+
}
|
|
1998
|
+
logger2(`${transform3.name}: finished with ${state.changes} changes`);
|
|
1999
|
+
return state;
|
|
2000
|
+
}
|
|
2001
|
+
var logger2 = debug4("delance:transforms");
|
|
2002
|
+
|
|
2003
|
+
// transform/esmodule/index.ts
|
|
2004
|
+
function transform3(ast2) {
|
|
2005
|
+
applyTransform2(ast2, module_helper_default);
|
|
2006
|
+
applyTransform2(ast2, indirect_call_default);
|
|
2007
|
+
return ast2;
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
// transform/syntactic/template-literal.ts
|
|
2011
|
+
import * as t27 from "@babel/types";
|
|
2012
|
+
import * as m35 from "@codemod/matchers";
|
|
2013
|
+
var escape = function(string) {
|
|
2014
|
+
return string.replaceAll("\\", "\\\\").replaceAll("`", "\\`").replaceAll("$", "\\$").replaceAll("\t", "\\t").replaceAll("\r", "\\r").replaceAll("\0", "\\0");
|
|
2015
|
+
};
|
|
2016
|
+
var template_literal_default = {
|
|
2017
|
+
name: "template-literal",
|
|
2018
|
+
tags: ["safe"],
|
|
2019
|
+
visitor() {
|
|
2020
|
+
const concatExpr = m35.binaryExpression("+", m35.or(m35.stringLiteral(), m35.templateLiteral()), m35.anyExpression());
|
|
2021
|
+
return {
|
|
2022
|
+
BinaryExpression: {
|
|
2023
|
+
exit($) {
|
|
2024
|
+
if (!concatExpr.match($.node)) {
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
const $left = $.get("left");
|
|
2028
|
+
const $right = $.get("right");
|
|
2029
|
+
if ($left.isTemplateLiteral()) {
|
|
2030
|
+
if ($right.isTemplateLiteral()) {
|
|
2031
|
+
const last = $left.node.quasis.pop();
|
|
2032
|
+
if (!last) {
|
|
2033
|
+
throw new Error("Unexpected empty template literal");
|
|
2034
|
+
}
|
|
2035
|
+
$left.node.quasis.push(t27.templateElement({
|
|
2036
|
+
raw: last.value.raw + $right.node.quasis[0].value.raw
|
|
2037
|
+
}, false), ...$right.node.quasis.slice(1));
|
|
2038
|
+
$.replaceWith(t27.templateLiteral([
|
|
2039
|
+
...$left.node.quasis
|
|
2040
|
+
], [
|
|
2041
|
+
...$left.node.expressions,
|
|
2042
|
+
...$right.node.expressions
|
|
2043
|
+
]));
|
|
2044
|
+
} else if ($right.isStringLiteral()) {
|
|
2045
|
+
const last = $left.node.quasis.pop();
|
|
2046
|
+
if (!last) {
|
|
2047
|
+
throw new Error("Unexpected empty template literal");
|
|
2048
|
+
}
|
|
2049
|
+
$left.node.quasis.push(t27.templateElement({
|
|
2050
|
+
raw: escape(last.value.raw + $right.node.value)
|
|
2051
|
+
}, true));
|
|
2052
|
+
$.replaceWith($left.node);
|
|
2053
|
+
} else {
|
|
2054
|
+
$.replaceWith(t27.templateLiteral([
|
|
2055
|
+
...$left.node.quasis.map((element) => {
|
|
2056
|
+
element.tail = false;
|
|
2057
|
+
return element;
|
|
2058
|
+
}),
|
|
2059
|
+
t27.templateElement({ raw: "" }, true)
|
|
2060
|
+
], [
|
|
2061
|
+
...$left.node.expressions,
|
|
2062
|
+
$right.node
|
|
2063
|
+
]));
|
|
2064
|
+
}
|
|
2065
|
+
} else if ($left.isStringLiteral()) {
|
|
2066
|
+
if ($right.isStringLiteral()) {
|
|
2067
|
+
$left.node.value += $right.node.value;
|
|
2068
|
+
$.replaceWith($left);
|
|
2069
|
+
} else {
|
|
2070
|
+
if ($right.isCallExpression() && $right.get("callee").isFunctionExpression()) {
|
|
2071
|
+
return;
|
|
2072
|
+
}
|
|
2073
|
+
$.replaceWith(t27.templateLiteral([
|
|
2074
|
+
t27.templateElement({ raw: escape($left.node.value) }, false),
|
|
2075
|
+
t27.templateElement({ raw: "" }, true)
|
|
2076
|
+
], [
|
|
2077
|
+
$right.node
|
|
2078
|
+
]));
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
this.changes++;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
};
|
|
2087
|
+
|
|
2088
|
+
// transform/syntactic/index.ts
|
|
2089
|
+
function transform4(ast2) {
|
|
2090
|
+
applyTransform2(ast2, template_literal_default);
|
|
2091
|
+
return ast2;
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
// node_modules/webcrack/src/transpile/transforms/index.ts
|
|
2095
|
+
var exports_transforms2 = {};
|
|
2096
|
+
__export(exports_transforms2, {
|
|
2097
|
+
templateLiterals: () => {
|
|
2098
|
+
{
|
|
2099
|
+
return template_literals_default;
|
|
2100
|
+
}
|
|
2101
|
+
},
|
|
2102
|
+
optionalChaining: () => {
|
|
2103
|
+
{
|
|
2104
|
+
return optional_chaining_default;
|
|
2105
|
+
}
|
|
2106
|
+
},
|
|
2107
|
+
nullishCoalescingAssignment: () => {
|
|
2108
|
+
{
|
|
2109
|
+
return nullish_coalescing_assignment_default;
|
|
2110
|
+
}
|
|
2111
|
+
},
|
|
2112
|
+
nullishCoalescing: () => {
|
|
2113
|
+
{
|
|
2114
|
+
return nullish_coalescing_default;
|
|
2115
|
+
}
|
|
2116
|
+
},
|
|
2117
|
+
logicalAssignments: () => {
|
|
2118
|
+
{
|
|
2119
|
+
return logical_assignments_default;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
});
|
|
2123
|
+
|
|
2124
|
+
// node_modules/webcrack/src/transpile/transforms/logical-assignments.ts
|
|
2125
|
+
import * as t28 from "@babel/types";
|
|
2126
|
+
import * as m36 from "@codemod/matchers";
|
|
2127
|
+
var logical_assignments_default = {
|
|
2128
|
+
name: "logical-assignments",
|
|
2129
|
+
tags: ["safe"],
|
|
2130
|
+
scope: true,
|
|
2131
|
+
visitor() {
|
|
2132
|
+
const operator = m36.capture(m36.or("||", "&&"));
|
|
2133
|
+
const left = m36.capture(m36.or(m36.identifier(), m36.memberExpression()));
|
|
2134
|
+
const right = m36.capture(m36.anyExpression());
|
|
2135
|
+
const idMatcher = m36.logicalExpression(operator, left, m36.assignmentExpression("=", m36.fromCapture(left), right));
|
|
2136
|
+
const object = m36.capture(m36.anyExpression());
|
|
2137
|
+
const property = m36.capture(m36.anyExpression());
|
|
2138
|
+
const tmpVar = m36.capture(m36.identifier());
|
|
2139
|
+
const member = m36.capture(m36.memberExpression(m36.fromCapture(tmpVar), m36.fromCapture(property)));
|
|
2140
|
+
const memberMatcher = m36.logicalExpression(operator, m36.memberExpression(m36.assignmentExpression("=", tmpVar, object), property), m36.assignmentExpression("=", member, right));
|
|
2141
|
+
const computedMemberMatcher = m36.logicalExpression(operator, m36.memberExpression(object, m36.assignmentExpression("=", tmpVar, property), true), m36.assignmentExpression("=", m36.memberExpression(m36.fromCapture(object), m36.fromCapture(tmpVar), true), right));
|
|
2142
|
+
const tmpVar2 = m36.capture(m36.identifier());
|
|
2143
|
+
const multiComputedMemberMatcher = m36.logicalExpression(operator, m36.memberExpression(m36.assignmentExpression("=", tmpVar, object), m36.assignmentExpression("=", tmpVar2, property), true), m36.assignmentExpression("=", m36.memberExpression(m36.fromCapture(tmpVar), m36.fromCapture(tmpVar2), true), right));
|
|
2144
|
+
return {
|
|
2145
|
+
LogicalExpression: {
|
|
2146
|
+
exit(path) {
|
|
2147
|
+
if (idMatcher.match(path.node)) {
|
|
2148
|
+
path.replaceWith(t28.assignmentExpression(operator.current + "=", left.current, right.current));
|
|
2149
|
+
this.changes++;
|
|
2150
|
+
} else if (memberMatcher.match(path.node)) {
|
|
2151
|
+
const binding = path.scope.getBinding(tmpVar.current.name);
|
|
2152
|
+
if (!isTemporaryVariable(binding, 1))
|
|
2153
|
+
return;
|
|
2154
|
+
binding.path.remove();
|
|
2155
|
+
member.current.object = object.current;
|
|
2156
|
+
path.replaceWith(t28.assignmentExpression(operator.current + "=", member.current, right.current));
|
|
2157
|
+
this.changes++;
|
|
2158
|
+
} else if (computedMemberMatcher.match(path.node)) {
|
|
2159
|
+
const binding = path.scope.getBinding(tmpVar.current.name);
|
|
2160
|
+
if (!isTemporaryVariable(binding, 1))
|
|
2161
|
+
return;
|
|
2162
|
+
binding.path.remove();
|
|
2163
|
+
path.replaceWith(t28.assignmentExpression(operator.current + "=", t28.memberExpression(object.current, property.current, true), right.current));
|
|
2164
|
+
this.changes++;
|
|
2165
|
+
} else if (multiComputedMemberMatcher.match(path.node)) {
|
|
2166
|
+
const binding = path.scope.getBinding(tmpVar.current.name);
|
|
2167
|
+
const binding2 = path.scope.getBinding(tmpVar2.current.name);
|
|
2168
|
+
if (!isTemporaryVariable(binding, 1) || !isTemporaryVariable(binding2, 1))
|
|
2169
|
+
return;
|
|
2170
|
+
binding.path.remove();
|
|
2171
|
+
binding2.path.remove();
|
|
2172
|
+
path.replaceWith(t28.assignmentExpression(operator.current + "=", t28.memberExpression(object.current, property.current, true), right.current));
|
|
2173
|
+
this.changes++;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
};
|
|
2178
|
+
}
|
|
2179
|
+
};
|
|
2180
|
+
// node_modules/webcrack/src/transpile/transforms/nullish-coalescing.ts
|
|
2181
|
+
import * as t29 from "@babel/types";
|
|
2182
|
+
import * as m37 from "@codemod/matchers";
|
|
2183
|
+
var nullish_coalescing_default = {
|
|
2184
|
+
name: "nullish-coalescing",
|
|
2185
|
+
tags: ["safe"],
|
|
2186
|
+
scope: true,
|
|
2187
|
+
visitor() {
|
|
2188
|
+
const tmpVar = m37.capture(m37.identifier());
|
|
2189
|
+
const left = m37.capture(m37.anyExpression());
|
|
2190
|
+
const right = m37.capture(m37.anyExpression());
|
|
2191
|
+
const idMatcher = m37.conditionalExpression(m37.logicalExpression("&&", m37.binaryExpression("!==", m37.assignmentExpression("=", tmpVar, left), m37.nullLiteral()), m37.binaryExpression("!==", m37.fromCapture(tmpVar), m37.identifier("undefined"))), m37.fromCapture(tmpVar), right);
|
|
2192
|
+
const idLooseMatcher = m37.conditionalExpression(m37.binaryExpression("!=", m37.assignmentExpression("=", tmpVar, left), m37.nullLiteral()), m37.fromCapture(tmpVar), right);
|
|
2193
|
+
const simpleIdMatcher = m37.conditionalExpression(m37.or(m37.logicalExpression("&&", m37.binaryExpression("!==", left, m37.nullLiteral()), m37.binaryExpression("!==", m37.fromCapture(left), m37.identifier("undefined"))), m37.binaryExpression("!=", left, m37.nullLiteral())), m37.fromCapture(left), right);
|
|
2194
|
+
const iifeMatcher = m37.callExpression(m37.arrowFunctionExpression([m37.fromCapture(tmpVar)], m37.anyExpression(), false), []);
|
|
2195
|
+
return {
|
|
2196
|
+
ConditionalExpression: {
|
|
2197
|
+
exit(path) {
|
|
2198
|
+
if (idMatcher.match(path.node)) {
|
|
2199
|
+
const binding = path.scope.getBinding(tmpVar.current.name);
|
|
2200
|
+
if (iifeMatcher.match(path.parentPath.parent) && isTemporaryVariable(binding, 2, "param")) {
|
|
2201
|
+
path.parentPath.parentPath.replaceWith(t29.logicalExpression("??", left.current, right.current));
|
|
2202
|
+
this.changes++;
|
|
2203
|
+
} else if (isTemporaryVariable(binding, 2, "var")) {
|
|
2204
|
+
binding.path.remove();
|
|
2205
|
+
path.replaceWith(t29.logicalExpression("??", left.current, right.current));
|
|
2206
|
+
this.changes++;
|
|
2207
|
+
}
|
|
2208
|
+
} else if (idLooseMatcher.match(path.node)) {
|
|
2209
|
+
const binding = path.scope.getBinding(tmpVar.current.name);
|
|
2210
|
+
if (!isTemporaryVariable(binding, 1))
|
|
2211
|
+
return;
|
|
2212
|
+
binding.path.remove();
|
|
2213
|
+
path.replaceWith(t29.logicalExpression("??", left.current, right.current));
|
|
2214
|
+
this.changes++;
|
|
2215
|
+
} else if (simpleIdMatcher.match(path.node)) {
|
|
2216
|
+
path.replaceWith(t29.logicalExpression("??", left.current, right.current));
|
|
2217
|
+
this.changes++;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
};
|
|
2224
|
+
// node_modules/webcrack/src/transpile/transforms/nullish-coalescing-assignment.ts
|
|
2225
|
+
import * as t30 from "@babel/types";
|
|
2226
|
+
import * as m38 from "@codemod/matchers";
|
|
2227
|
+
var nullish_coalescing_assignment_default = {
|
|
2228
|
+
name: "nullish-coalescing-assignment",
|
|
2229
|
+
tags: ["safe"],
|
|
2230
|
+
scope: true,
|
|
2231
|
+
visitor() {
|
|
2232
|
+
const tmpVar = m38.capture(m38.identifier());
|
|
2233
|
+
const leftId = m38.capture(m38.identifier());
|
|
2234
|
+
const property = m38.capture(m38.identifier());
|
|
2235
|
+
const right = m38.capture(m38.anyExpression());
|
|
2236
|
+
const computed = m38.capture(m38.anything());
|
|
2237
|
+
const memberMatcher = m38.logicalExpression("??", m38.memberExpression(m38.assignmentExpression("=", tmpVar, leftId), property, computed), m38.assignmentExpression("=", m38.memberExpression(m38.fromCapture(tmpVar), m38.fromCapture(property), computed), right));
|
|
2238
|
+
const left = m38.capture(m38.or(m38.identifier(), m38.memberExpression()));
|
|
2239
|
+
const simpleMatcher = m38.logicalExpression("??", left, m38.assignmentExpression("=", m38.fromCapture(left), right));
|
|
2240
|
+
return {
|
|
2241
|
+
LogicalExpression: {
|
|
2242
|
+
exit(path) {
|
|
2243
|
+
if (memberMatcher.match(path.node)) {
|
|
2244
|
+
const binding = path.scope.getBinding(tmpVar.current.name);
|
|
2245
|
+
if (!isTemporaryVariable(binding, 1))
|
|
2246
|
+
return;
|
|
2247
|
+
binding.path.remove();
|
|
2248
|
+
path.replaceWith(t30.assignmentExpression("??=", t30.memberExpression(leftId.current, property.current, computed.current), right.current));
|
|
2249
|
+
this.changes++;
|
|
2250
|
+
} else if (simpleMatcher.match(path.node)) {
|
|
2251
|
+
path.replaceWith(t30.assignmentExpression("??=", left.current, right.current));
|
|
2252
|
+
this.changes++;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
};
|
|
2257
|
+
}
|
|
2258
|
+
};
|
|
2259
|
+
// node_modules/webcrack/src/transpile/transforms/optional-chaining.ts
|
|
2260
|
+
import * as t31 from "@babel/types";
|
|
2261
|
+
import * as m39 from "@codemod/matchers";
|
|
2262
|
+
var optional_chaining_default = {
|
|
2263
|
+
name: "optional-chaining",
|
|
2264
|
+
tags: ["safe"],
|
|
2265
|
+
scope: true,
|
|
2266
|
+
visitor() {
|
|
2267
|
+
const object = m39.capture(m39.anyExpression());
|
|
2268
|
+
const member = m39.capture(m39.memberExpression(m39.fromCapture(object)));
|
|
2269
|
+
const simpleMatcher = m39.conditionalExpression(m39.logicalExpression("||", m39.binaryExpression("===", object, m39.nullLiteral()), m39.binaryExpression("===", m39.fromCapture(object), m39.identifier("undefined"))), m39.identifier("undefined"), member);
|
|
2270
|
+
const tmpVar = m39.capture(m39.identifier());
|
|
2271
|
+
const tmpMember = m39.capture(m39.memberExpression(m39.fromCapture(tmpVar)));
|
|
2272
|
+
const tmpMatcher = m39.conditionalExpression(m39.logicalExpression("||", m39.binaryExpression("===", m39.assignmentExpression("=", tmpVar, object), m39.nullLiteral()), m39.binaryExpression("===", m39.fromCapture(tmpVar), m39.identifier("undefined"))), m39.identifier("undefined"), tmpMember);
|
|
2273
|
+
return {
|
|
2274
|
+
ConditionalExpression: {
|
|
2275
|
+
exit(path) {
|
|
2276
|
+
if (simpleMatcher.match(path.node)) {
|
|
2277
|
+
member.current.optional = true;
|
|
2278
|
+
path.replaceWith(t31.optionalMemberExpression(object.current, member.current.property, member.current.computed, true));
|
|
2279
|
+
this.changes++;
|
|
2280
|
+
} else if (tmpMatcher.match(path.node)) {
|
|
2281
|
+
const binding = path.scope.getBinding(tmpVar.current.name);
|
|
2282
|
+
if (!isTemporaryVariable(binding, 2))
|
|
2283
|
+
return;
|
|
2284
|
+
binding.path.remove();
|
|
2285
|
+
tmpMember.current.optional = true;
|
|
2286
|
+
path.replaceWith(t31.optionalMemberExpression(object.current, tmpMember.current.property, tmpMember.current.computed, true));
|
|
2287
|
+
this.changes++;
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
};
|
|
2292
|
+
}
|
|
2293
|
+
};
|
|
2294
|
+
// node_modules/webcrack/src/transpile/transforms/template-literals.ts
|
|
2295
|
+
import * as t32 from "@babel/types";
|
|
2296
|
+
import * as m40 from "@codemod/matchers";
|
|
2297
|
+
var escape2 = function(str) {
|
|
2298
|
+
return str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$").replace(/\t/g, "\\t").replace(/\r/g, "\\r");
|
|
2299
|
+
};
|
|
2300
|
+
var push = function(template9, value) {
|
|
2301
|
+
if (value.type === "StringLiteral") {
|
|
2302
|
+
const lastQuasi = template9.quasis.at(-1);
|
|
2303
|
+
lastQuasi.value.raw += escape2(value.value);
|
|
2304
|
+
} else if (value.type === "TemplateLiteral") {
|
|
2305
|
+
const lastQuasi = template9.quasis.at(-1);
|
|
2306
|
+
const firstQuasi = value.quasis[0];
|
|
2307
|
+
lastQuasi.value.raw += firstQuasi.value.raw;
|
|
2308
|
+
template9.expressions.push(...value.expressions);
|
|
2309
|
+
template9.quasis.push(...value.quasis.slice(1));
|
|
2310
|
+
} else {
|
|
2311
|
+
template9.expressions.push(value);
|
|
2312
|
+
template9.quasis.push(t32.templateElement({ raw: "" }));
|
|
2313
|
+
}
|
|
2314
|
+
};
|
|
2315
|
+
var unshift = function(template9, value) {
|
|
2316
|
+
if (value.type === "StringLiteral") {
|
|
2317
|
+
const firstQuasi = template9.quasis[0];
|
|
2318
|
+
firstQuasi.value.raw = escape2(value.value) + firstQuasi.value.raw;
|
|
2319
|
+
} else if (value.type === "TemplateLiteral") {
|
|
2320
|
+
const firstQuasi = template9.quasis[0];
|
|
2321
|
+
firstQuasi.value.raw = value.quasis[0].value.raw + firstQuasi.value.raw;
|
|
2322
|
+
template9.expressions.unshift(...value.expressions);
|
|
2323
|
+
template9.quasis.unshift(...value.quasis.slice(0, -1));
|
|
2324
|
+
} else {
|
|
2325
|
+
template9.expressions.unshift(value);
|
|
2326
|
+
template9.quasis.unshift(t32.templateElement({ raw: "" }));
|
|
2327
|
+
}
|
|
2328
|
+
};
|
|
2329
|
+
var template_literals_default = {
|
|
2330
|
+
name: "template-literals",
|
|
2331
|
+
tags: ["unsafe"],
|
|
2332
|
+
visitor() {
|
|
2333
|
+
const concatMatcher = m40.or(m40.callExpression(constMemberExpression(m40.or(m40.stringLiteral(), m40.matcher((node) => concatMatcher.match(node))), "concat"), m40.arrayOf(m40.anyExpression())));
|
|
2334
|
+
return {
|
|
2335
|
+
BinaryExpression: {
|
|
2336
|
+
exit(path) {
|
|
2337
|
+
if (path.node.operator !== "+")
|
|
2338
|
+
return;
|
|
2339
|
+
if (t32.isTemplateLiteral(path.node.left)) {
|
|
2340
|
+
push(path.node.left, path.node.right);
|
|
2341
|
+
path.replaceWith(path.node.left);
|
|
2342
|
+
this.changes++;
|
|
2343
|
+
} else if (t32.isTemplateLiteral(path.node.right) && t32.isExpression(path.node.left)) {
|
|
2344
|
+
unshift(path.node.right, path.node.left);
|
|
2345
|
+
path.replaceWith(path.node.right);
|
|
2346
|
+
this.changes++;
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
},
|
|
2350
|
+
CallExpression: {
|
|
2351
|
+
exit(path) {
|
|
2352
|
+
if (concatMatcher.match(path.node) && !concatMatcher.match(path.parentPath.parent)) {
|
|
2353
|
+
const template9 = t32.templateLiteral([t32.templateElement({ raw: "" })], []);
|
|
2354
|
+
let current = path.node;
|
|
2355
|
+
while (current.type === "CallExpression") {
|
|
2356
|
+
for (const arg of current.arguments.reverse()) {
|
|
2357
|
+
unshift(template9, arg);
|
|
2358
|
+
}
|
|
2359
|
+
current = current.callee.object;
|
|
2360
|
+
}
|
|
2361
|
+
unshift(template9, current);
|
|
2362
|
+
path.replaceWith(template9);
|
|
2363
|
+
this.changes++;
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
};
|
|
2368
|
+
}
|
|
2369
|
+
};
|
|
2370
|
+
// node_modules/webcrack/src/transpile/index.ts
|
|
2371
|
+
var transpile_default = mergeTransforms({
|
|
2372
|
+
name: "transpile",
|
|
2373
|
+
tags: ["safe"],
|
|
2374
|
+
transforms: Object.values(exports_transforms2)
|
|
2375
|
+
});
|
|
2376
|
+
|
|
2377
|
+
// transform/delance/stringaes.ts
|
|
2378
|
+
import traverse12 from "@babel/traverse";
|
|
2379
|
+
import * as m41 from "@codemod/matchers";
|
|
2380
|
+
import * as t33 from "@babel/types";
|
|
2381
|
+
|
|
2382
|
+
// utils/crypto.ts
|
|
2383
|
+
import crypto from "node:crypto";
|
|
2384
|
+
import {Buffer} from "node:buffer";
|
|
2385
|
+
function salt(x = _salt) {
|
|
2386
|
+
_salt = x;
|
|
2387
|
+
return _salt;
|
|
2388
|
+
}
|
|
2389
|
+
function lic(x = _lic) {
|
|
2390
|
+
_lic = x;
|
|
2391
|
+
return _lic;
|
|
2392
|
+
}
|
|
2393
|
+
function decrypt(m41) {
|
|
2394
|
+
const c = crypto.createDecipheriv("aes-192-cbc", scrypt(), iv());
|
|
2395
|
+
let a = c.update(m41, "hex", "utf8");
|
|
2396
|
+
a += c.final("utf8");
|
|
2397
|
+
return a;
|
|
2398
|
+
}
|
|
2399
|
+
var _salt = "SEE LICENSE.txt";
|
|
2400
|
+
var _lic = [
|
|
2401
|
+
",oidutS lausiV tfosorciM htiw ylno erawtfos eht fo seipoc fo rebmun yna esu dna llatsni yam uoY",
|
|
2402
|
+
"stcudorp tfosorciM rosseccus dna ,revreS noitadnuoF maeT ,spOveD eruzA ,edoC oidutS lausiV ,caM rof oidutS lausiV",
|
|
2403
|
+
".snoitacilppa ruoy tset dna poleved ot )\u201DsecivreS dna stcudorP oidutS lausiV\u201C eht ,ylevitcelloc( secivres dna",
|
|
2404
|
+
".sthgir rehto lla sevreser tfosorciM .erawtfos eht esu ot sthgir emos uoy sevig ylno tnemeerga sihT .dlos ton ,desnecil si erawtfos ehT",
|
|
2405
|
+
":ton yam uoY",
|
|
2406
|
+
";syaw niatrec ni ti esu ot uoy wolla ylno taht erawtfos eht ni snoitatimil lacinhcet yna dnuora krow",
|
|
2407
|
+
",erawtfos eht rof edoc ecruos eht evired ot tpmetta esiwrehto ro ,erawtfos eht elbmessasid ro elipmoced ,reenigne esrever",
|
|
2408
|
+
";erawtfos eht ni dedulcni eb yam taht stnenopmoc ecruos nepo niatrec fo esu gninrevog smret gnisnecil ytrap driht yb deriuqer tnetxe eht ot dna tpecxe",
|
|
2409
|
+
";erawtfos eht ni sreilppus sti ro tfosorciM fo seciton yna yfidom ro ,kcolb ,eziminim ,evomer",
|
|
2410
|
+
"ro ;erawlam etagaporp ro etaerc ot ro wal eht tsniaga si taht yaw yna ni erawtfos eht esu",
|
|
2411
|
+
",)evoba smret eht ot tcejbus ,edoc elbatubirtsid yna rof tpecxe( erawtfos eht esael ro ,etubirtsid ,hsilbup ,erahs",
|
|
2412
|
+
".ytrap driht yna ot tnemeerga siht ro erawtfos eht refsnart ro ,esu ot srehto rof gnireffo enola-dnats a sa erawtfos eht edivorp"
|
|
2413
|
+
].map((x) => [...x].reverse().join("")).join(" ");
|
|
2414
|
+
var scrypt = () => crypto.scryptSync(lic(), salt(), 24);
|
|
2415
|
+
var iv = () => Buffer.from(salt());
|
|
2416
|
+
|
|
2417
|
+
// transform/delance/stringaes.ts
|
|
2418
|
+
var scrypt2 = m41.callExpression(m41.memberExpression(m41.identifier(), m41.identifier("scryptSync"), false), [
|
|
2419
|
+
m41.memberExpression(m41.identifier(), m41.identifier("licenseErrorText"), false),
|
|
2420
|
+
m41.identifier(),
|
|
2421
|
+
m41.numericLiteral(24)
|
|
2422
|
+
]);
|
|
2423
|
+
var licenseText = m41.assignmentExpression("=", m41.memberExpression(m41.identifier(), m41.identifier("licenseErrorText")), m41.callExpression(m41.memberExpression(m41.arrayExpression(m41.anyList(m41.oneOrMore(m41.stringLiteral()))), m41.identifier("join"), false), [m41.stringLiteral(" ")]));
|
|
2424
|
+
var newSalt;
|
|
2425
|
+
var newKey;
|
|
2426
|
+
var stringaes_default = {
|
|
2427
|
+
name: "string-aes",
|
|
2428
|
+
tags: ["safe"],
|
|
2429
|
+
run(ast2) {
|
|
2430
|
+
traverse12(ast2, {
|
|
2431
|
+
CallExpression: {
|
|
2432
|
+
exit($) {
|
|
2433
|
+
if (newSalt || !scrypt2.match($.node)) {
|
|
2434
|
+
return;
|
|
2435
|
+
}
|
|
2436
|
+
const $id = $.get("arguments.1");
|
|
2437
|
+
$id.assertIdentifier();
|
|
2438
|
+
const _decl = $.scope.getBinding($id.node.name)?.path;
|
|
2439
|
+
if (!_decl) {
|
|
2440
|
+
throw new Error("Could not find declaration");
|
|
2441
|
+
}
|
|
2442
|
+
const $decl = _decl;
|
|
2443
|
+
$decl.assertVariableDeclarator();
|
|
2444
|
+
const $salt = $decl.get("init");
|
|
2445
|
+
if (!$salt.isStringLiteral()) {
|
|
2446
|
+
throw new Error("Salt not initialized");
|
|
2447
|
+
}
|
|
2448
|
+
newSalt = $salt.node.value;
|
|
2449
|
+
}
|
|
2450
|
+
},
|
|
2451
|
+
AssignmentExpression: {
|
|
2452
|
+
exit($) {
|
|
2453
|
+
if (newKey || !licenseText.match($.node)) {
|
|
2454
|
+
return;
|
|
2455
|
+
}
|
|
2456
|
+
const $strs = $.get("right.callee.object.elements");
|
|
2457
|
+
newKey = $strs.map(($_) => {
|
|
2458
|
+
$_.assertStringLiteral();
|
|
2459
|
+
return $_.node.value;
|
|
2460
|
+
}).join(" ");
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
});
|
|
2464
|
+
if (newSalt && newKey) {
|
|
2465
|
+
salt(newSalt);
|
|
2466
|
+
lic(newKey);
|
|
2467
|
+
}
|
|
2468
|
+
},
|
|
2469
|
+
visitor() {
|
|
2470
|
+
const encryptedString = m41.callExpression(m41.memberExpression(m41.identifier(), m41.identifier("decrypt"), false), [m41.stringLiteral()]);
|
|
2471
|
+
return {
|
|
2472
|
+
CallExpression: {
|
|
2473
|
+
exit($) {
|
|
2474
|
+
if (!encryptedString.match($.node)) {
|
|
2475
|
+
return;
|
|
2476
|
+
}
|
|
2477
|
+
const $callee = $.get("callee");
|
|
2478
|
+
$callee.assertMemberExpression();
|
|
2479
|
+
const $id = $callee.get("object");
|
|
2480
|
+
$id.assertIdentifier();
|
|
2481
|
+
const $string = $.get("arguments")[0];
|
|
2482
|
+
$string.assertStringLiteral();
|
|
2483
|
+
$.replaceWith(t33.stringLiteral(decrypt($string.node.value)));
|
|
2484
|
+
this.changes++;
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
};
|
|
2490
|
+
|
|
2491
|
+
// transform/delance/antifeature.ts
|
|
2492
|
+
import * as t34 from "@babel/types";
|
|
2493
|
+
import * as m42 from "@codemod/matchers";
|
|
2494
|
+
import tmpl6 from "@babel/template";
|
|
2495
|
+
var entry = m42.capture(m42.numericLiteral());
|
|
2496
|
+
var main = m42.callExpression(m42.memberExpression(m42.callExpression(m42.identifier("require"), [entry]), m42.identifier("main"), false), [m42.booleanLiteral(true)]);
|
|
2497
|
+
var verifyClient = m42.assignmentExpression("=", m42.memberExpression(m42.identifier("exports"), m42.identifier("verifyClient")), m42.functionExpression(null, [m42.identifier()]));
|
|
2498
|
+
var vsda = m42.ifStatement(m42.containerOf(m42.stringLiteral("vsda")));
|
|
2499
|
+
var antifeature_default = {
|
|
2500
|
+
name: "anti-feature",
|
|
2501
|
+
tags: ["unsafe"],
|
|
2502
|
+
visitor: () => ({
|
|
2503
|
+
CallExpression: {
|
|
2504
|
+
exit($) {
|
|
2505
|
+
if (!main.match($.node)) {
|
|
2506
|
+
return;
|
|
2507
|
+
}
|
|
2508
|
+
t34.assertNumericLiteral(entry.current);
|
|
2509
|
+
const _target = $.find((p2) => chunk_default.match(p2.node));
|
|
2510
|
+
if (!_target) {
|
|
2511
|
+
throw new Error("Could not find module chunk");
|
|
2512
|
+
}
|
|
2513
|
+
const $target = _target;
|
|
2514
|
+
$target.assertObjectProperty();
|
|
2515
|
+
const $value = $target.get("value");
|
|
2516
|
+
$value.assertFunction();
|
|
2517
|
+
$value.get("body").replaceWith(tmpl6.statement.ast`{
|
|
2518
|
+
require(${entry.current}).main(false);
|
|
2519
|
+
}`);
|
|
2520
|
+
$.stop();
|
|
2521
|
+
this.changes++;
|
|
2522
|
+
}
|
|
2523
|
+
},
|
|
2524
|
+
AssignmentExpression: {
|
|
2525
|
+
exit($) {
|
|
2526
|
+
if (!verifyClient.match($.node)) {
|
|
2527
|
+
return;
|
|
2528
|
+
}
|
|
2529
|
+
const $value = $.get("right");
|
|
2530
|
+
$value.assertFunction();
|
|
2531
|
+
$value.get("body").replaceWith(tmpl6.statement.ast`{
|
|
2532
|
+
return;
|
|
2533
|
+
}`);
|
|
2534
|
+
this.changes++;
|
|
2535
|
+
}
|
|
2536
|
+
},
|
|
2537
|
+
IfStatement: {
|
|
2538
|
+
exit($) {
|
|
2539
|
+
if (!vsda.match($.node)) {
|
|
2540
|
+
return;
|
|
2541
|
+
}
|
|
2542
|
+
$.remove();
|
|
2543
|
+
this.changes++;
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
})
|
|
2547
|
+
};
|
|
2548
|
+
|
|
2549
|
+
// transform/delance/index.ts
|
|
2550
|
+
function transform5(ast2) {
|
|
2551
|
+
applyTransform2(ast2, stringaes_default);
|
|
2552
|
+
applyTransform2(ast2, antifeature_default);
|
|
2553
|
+
applyTransform(ast2, transpile_default);
|
|
2554
|
+
return ast2;
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
// transform/index.ts
|
|
2558
|
+
async function transform6(ast2) {
|
|
2559
|
+
await transform2(ast2);
|
|
2560
|
+
transform4(ast2);
|
|
2561
|
+
transform3(ast2);
|
|
2562
|
+
transform5(ast2);
|
|
2563
|
+
return ast2;
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
// index.ts
|
|
2567
|
+
async function delance_builder_default(code) {
|
|
2568
|
+
return generate2(await transform6(parse(code)));
|
|
2569
|
+
}
|
|
2570
|
+
export {
|
|
2571
|
+
transform6 as transform,
|
|
2572
|
+
delance_builder_default as default
|
|
2573
|
+
};
|
|
2574
|
+
|
|
2575
|
+
export { delance_builder_default };
|
|
2576
|
+
|
|
2577
|
+
//# debugId=623A8DAFD0C674AC64756e2164756e21
|