unpeek 1.15.0 → 2.0.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/README.md +68 -40
- package/README.tr.md +74 -46
- package/dist/ast/index.cjs +6 -4930
- package/dist/ast/index.d.cts +11 -72
- package/dist/ast/index.d.ts +11 -72
- package/dist/ast/index.js +12 -4888
- package/dist/browser.cjs +10 -4920
- package/dist/browser.d.cts +2 -3
- package/dist/browser.d.ts +2 -3
- package/dist/browser.js +16 -4883
- package/dist/bundler/unplugin.cjs +7 -4968
- package/dist/bundler/unplugin.d.cts +4 -2
- package/dist/bundler/unplugin.d.ts +1 -1
- package/dist/bundler/unplugin.js +12 -4934
- package/dist/chunk-24K5NDXH.cjs +370 -0
- package/dist/chunk-27HR647Q.js +190 -0
- package/dist/chunk-4TDLLEEU.cjs +15 -0
- package/dist/chunk-5LCMI2TL.js +575 -0
- package/dist/chunk-5M6Z7ZFT.cjs +83 -0
- package/dist/chunk-5QD6FZPB.js +197 -0
- package/dist/chunk-6N6S6WTQ.cjs +423 -0
- package/dist/chunk-7YVEHJVM.cjs +575 -0
- package/dist/chunk-GAVI2C44.cjs +197 -0
- package/dist/chunk-GZB7PFLY.js +370 -0
- package/dist/chunk-J5CGNZDM.cjs +190 -0
- package/dist/chunk-KQWNFKT2.js +423 -0
- package/dist/{cli/protect.cjs → chunk-LXP73HJC.cjs} +301 -1473
- package/dist/chunk-OOXSZTRV.js +18 -0
- package/dist/chunk-R6EBIR3T.cjs +14 -0
- package/dist/chunk-S4S2WXGC.js +14 -0
- package/dist/{cli/protect.js → chunk-UMPUYLLZ.js} +95 -1232
- package/dist/chunk-X5MKMFMX.js +83 -0
- package/dist/cli/index.cjs +169 -5956
- package/dist/cli/index.d.cts +20 -1
- package/dist/cli/index.d.ts +20 -1
- package/dist/cli/index.js +163 -5911
- package/dist/config.cjs +21 -342
- package/dist/config.d.cts +2 -2
- package/dist/config.d.ts +2 -2
- package/dist/config.js +12 -291
- package/dist/esbuild.cjs +10 -4972
- package/dist/esbuild.d.cts +2 -2
- package/dist/esbuild.d.ts +2 -2
- package/dist/esbuild.js +8 -4935
- package/dist/index.cjs +9 -6408
- package/dist/index.d.cts +26 -17
- package/dist/index.d.ts +26 -17
- package/dist/index.js +20 -6359
- package/dist/next/adapter.cjs +16 -5823
- package/dist/next/adapter.d.cts +6 -4
- package/dist/next/adapter.d.ts +3 -3
- package/dist/next/adapter.js +11 -5775
- package/dist/next/index.cjs +9 -5856
- package/dist/next/index.d.cts +24 -19
- package/dist/next/index.d.ts +24 -19
- package/dist/next/index.js +13 -5824
- package/dist/rollup.cjs +10 -4972
- package/dist/rollup.d.cts +2 -2
- package/dist/rollup.d.ts +2 -2
- package/dist/rollup.js +8 -4935
- package/dist/runtime/index.cjs +12 -435
- package/dist/runtime/index.d.cts +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +9 -400
- package/dist/{types-CQYBNQND.d.ts → types-BBSRUEab.d.cts} +3 -7
- package/dist/{types-CQYBNQND.d.cts → types-BBSRUEab.d.ts} +3 -7
- package/dist/vite.cjs +10 -4972
- package/dist/vite.d.cts +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +8 -4935
- package/dist/webpack.cjs +10 -4972
- package/dist/webpack.d.cts +2 -2
- package/dist/webpack.d.ts +2 -2
- package/dist/webpack.js +8 -4935
- package/package.json +54 -21
- package/dist/ast/index.cjs.map +0 -1
- package/dist/ast/index.js.map +0 -1
- package/dist/browser.cjs.map +0 -1
- package/dist/browser.js.map +0 -1
- package/dist/bundler/detector.cjs +0 -271
- package/dist/bundler/detector.cjs.map +0 -1
- package/dist/bundler/detector.d.cts +0 -13
- package/dist/bundler/detector.d.ts +0 -13
- package/dist/bundler/detector.js +0 -232
- package/dist/bundler/detector.js.map +0 -1
- package/dist/bundler/sourcemap-vault.cjs +0 -316
- package/dist/bundler/sourcemap-vault.cjs.map +0 -1
- package/dist/bundler/sourcemap-vault.d.cts +0 -7
- package/dist/bundler/sourcemap-vault.d.ts +0 -7
- package/dist/bundler/sourcemap-vault.js +0 -280
- package/dist/bundler/sourcemap-vault.js.map +0 -1
- package/dist/bundler/unplugin.cjs.map +0 -1
- package/dist/bundler/unplugin.js.map +0 -1
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/init.cjs +0 -342
- package/dist/cli/init.cjs.map +0 -1
- package/dist/cli/init.d.cts +0 -16
- package/dist/cli/init.d.ts +0 -16
- package/dist/cli/init.js +0 -306
- package/dist/cli/init.js.map +0 -1
- package/dist/cli/protect.cjs.map +0 -1
- package/dist/cli/protect.d.cts +0 -5
- package/dist/cli/protect.d.ts +0 -5
- package/dist/cli/protect.js.map +0 -1
- package/dist/config.cjs.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/esbuild.cjs.map +0 -1
- package/dist/esbuild.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/next/adapter.cjs.map +0 -1
- package/dist/next/adapter.js.map +0 -1
- package/dist/next/index.cjs.map +0 -1
- package/dist/next/index.js.map +0 -1
- package/dist/next/with-unpeek.cjs +0 -5865
- package/dist/next/with-unpeek.cjs.map +0 -1
- package/dist/next/with-unpeek.d.cts +0 -2
- package/dist/next/with-unpeek.d.ts +0 -2
- package/dist/next/with-unpeek.js +0 -5829
- package/dist/next/with-unpeek.js.map +0 -1
- package/dist/rollup.cjs.map +0 -1
- package/dist/rollup.js.map +0 -1
- package/dist/runtime/index.cjs.map +0 -1
- package/dist/runtime/index.js.map +0 -1
- package/dist/vite.cjs.map +0 -1
- package/dist/vite.js.map +0 -1
- package/dist/webpack.cjs.map +0 -1
- package/dist/webpack.js.map +0 -1
package/dist/ast/index.cjs
CHANGED
|
@@ -1,4941 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
29
2
|
|
|
30
|
-
// src/ast/index.ts
|
|
31
|
-
var ast_exports = {};
|
|
32
|
-
__export(ast_exports, {
|
|
33
|
-
analyzeAstHotPaths: () => analyzeAstHotPaths,
|
|
34
|
-
applyColdFlowGuard: () => applyColdFlowGuard,
|
|
35
|
-
applyMicroVm: () => applyMicroVm,
|
|
36
|
-
applyPolymorphicMangler: () => applyPolymorphicMangler,
|
|
37
|
-
applySaltedStringVault: () => applySaltedStringVault,
|
|
38
|
-
applyStringVault: () => applyStringVault,
|
|
39
|
-
computeFnv1aHash: () => computeFnv1aHash,
|
|
40
|
-
derivePolymorphicIdent: () => derivePolymorphicIdent,
|
|
41
|
-
detectHotPaths: () => detectHotPaths,
|
|
42
|
-
generateCompactJs: () => generateCompactJs,
|
|
43
|
-
injectWasmVault: () => injectWasmVault,
|
|
44
|
-
transformJavaScript: () => transformJavaScript
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(ast_exports);
|
|
47
3
|
|
|
48
|
-
|
|
49
|
-
var acorn = __toESM(require("acorn"), 1);
|
|
50
|
-
var walk = __toESM(require("acorn-walk"), 1);
|
|
51
|
-
var ARRAY_HOF_METHODS = /* @__PURE__ */ new Set([
|
|
52
|
-
"map",
|
|
53
|
-
"filter",
|
|
54
|
-
"reduce",
|
|
55
|
-
"forEach",
|
|
56
|
-
"flatMap",
|
|
57
|
-
"find",
|
|
58
|
-
"findIndex",
|
|
59
|
-
"some",
|
|
60
|
-
"every"
|
|
61
|
-
]);
|
|
62
|
-
var ANIMATION_FRAME_CALLS = /* @__PURE__ */ new Set([
|
|
63
|
-
"requestAnimationFrame",
|
|
64
|
-
"cancelAnimationFrame",
|
|
65
|
-
"useFrame",
|
|
66
|
-
"useLenis",
|
|
67
|
-
"setAnimationLoop",
|
|
68
|
-
"onBeforeRender",
|
|
69
|
-
"updateMatrixWorld",
|
|
70
|
-
"raf"
|
|
71
|
-
]);
|
|
72
|
-
var DEFAULT_IMPORT_SOURCES = {
|
|
73
|
-
"@react-three/fiber": ["useFrame"],
|
|
74
|
-
lenis: ["useLenis", "raf"],
|
|
75
|
-
"lenis/react": ["useLenis"],
|
|
76
|
-
three: ["onBeforeRender", "updateMatrixWorld", "useFrame"],
|
|
77
|
-
gsap: ["ticker"]
|
|
78
|
-
};
|
|
79
|
-
var DEFAULT_HOC_WRAPPERS = /* @__PURE__ */ new Set([
|
|
80
|
-
"memo",
|
|
81
|
-
"forwardRef",
|
|
82
|
-
"React.memo",
|
|
83
|
-
"React.forwardRef",
|
|
84
|
-
"observer",
|
|
85
|
-
"connect"
|
|
86
|
-
]);
|
|
87
|
-
var DEFAULT_EVENT_HANDLER_REGEX = /^(?:on|handle)(?!Tick|Render|Update|Frame|Animate|Physics)[A-Z]/;
|
|
88
|
-
var DEFAULT_HOOK_REGEX = /^use[A-Z0-9]/;
|
|
89
|
-
var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
90
|
-
"useState",
|
|
91
|
-
"useEffect",
|
|
92
|
-
"useMemo",
|
|
93
|
-
"useCallback",
|
|
94
|
-
"useRef",
|
|
95
|
-
"useLayoutEffect",
|
|
96
|
-
"useActionState",
|
|
97
|
-
"useFormStatus",
|
|
98
|
-
"useOptimistic",
|
|
99
|
-
"jsx",
|
|
100
|
-
"jsxs",
|
|
101
|
-
"_jsx",
|
|
102
|
-
"_jsxs",
|
|
103
|
-
"createElement"
|
|
104
|
-
]);
|
|
105
|
-
var FUNCTION_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
106
|
-
"FunctionDeclaration",
|
|
107
|
-
"FunctionExpression",
|
|
108
|
-
"ArrowFunctionExpression"
|
|
109
|
-
]);
|
|
110
|
-
function parseJavaScriptAst(code) {
|
|
111
|
-
try {
|
|
112
|
-
return acorn.parse(code, {
|
|
113
|
-
ecmaVersion: "latest",
|
|
114
|
-
sourceType: "module",
|
|
115
|
-
allowReturnOutsideFunction: true
|
|
116
|
-
});
|
|
117
|
-
} catch {
|
|
118
|
-
try {
|
|
119
|
-
return acorn.parse(code, {
|
|
120
|
-
ecmaVersion: "latest",
|
|
121
|
-
sourceType: "script",
|
|
122
|
-
allowReturnOutsideFunction: true
|
|
123
|
-
});
|
|
124
|
-
} catch {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function isHocCall(callNode, hocWrappers) {
|
|
130
|
-
if (!callNode || callNode.type !== "CallExpression") return false;
|
|
131
|
-
const callee = callNode.callee;
|
|
132
|
-
if (!callee) return false;
|
|
133
|
-
const wrappers = hocWrappers ?? DEFAULT_HOC_WRAPPERS;
|
|
134
|
-
if (callee.type === "Identifier") {
|
|
135
|
-
return wrappers.has(callee.name);
|
|
136
|
-
}
|
|
137
|
-
if (callee.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier") {
|
|
138
|
-
if (wrappers.has(callee.property.name)) return true;
|
|
139
|
-
if (callee.object?.type === "Identifier") {
|
|
140
|
-
const full2 = `${callee.object.name}.${callee.property.name}`;
|
|
141
|
-
if (wrappers.has(full2)) return true;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
function getFunctionLabel(node, ancestors, hocWrappers) {
|
|
147
|
-
if (node.id && typeof node.id.name === "string") {
|
|
148
|
-
return node.id.name;
|
|
149
|
-
}
|
|
150
|
-
const parent = ancestors[ancestors.length - 2];
|
|
151
|
-
if (parent) {
|
|
152
|
-
if (parent.type === "VariableDeclarator" && parent.id?.type === "Identifier") {
|
|
153
|
-
return parent.id.name;
|
|
154
|
-
}
|
|
155
|
-
if (parent.type === "Property") {
|
|
156
|
-
if (parent.key?.type === "Identifier") {
|
|
157
|
-
return parent.key.name;
|
|
158
|
-
}
|
|
159
|
-
if (parent.key?.type === "Literal" && typeof parent.key.value === "string") {
|
|
160
|
-
return parent.key.value;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (parent.type === "MethodDefinition" && parent.key?.type === "Identifier") {
|
|
164
|
-
return parent.key.name;
|
|
165
|
-
}
|
|
166
|
-
if (parent.type === "AssignmentExpression" && parent.left?.type === "Identifier") {
|
|
167
|
-
return parent.left.name;
|
|
168
|
-
}
|
|
169
|
-
if (parent.type === "CallExpression") {
|
|
170
|
-
let idx = ancestors.length - 2;
|
|
171
|
-
let matchedHoc = false;
|
|
172
|
-
while (idx >= 0 && ancestors[idx].type === "CallExpression") {
|
|
173
|
-
if (isHocCall(ancestors[idx], hocWrappers)) {
|
|
174
|
-
matchedHoc = true;
|
|
175
|
-
idx--;
|
|
176
|
-
} else {
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (matchedHoc && idx >= 0) {
|
|
181
|
-
const outer = ancestors[idx];
|
|
182
|
-
if (outer.type === "VariableDeclarator" && outer.id?.type === "Identifier") {
|
|
183
|
-
return outer.id.name;
|
|
184
|
-
}
|
|
185
|
-
if (outer.type === "AssignmentExpression" && outer.left?.type === "Identifier") {
|
|
186
|
-
return outer.left.name;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return `anonymous_${node.start}`;
|
|
192
|
-
}
|
|
193
|
-
function isPascalCaseComponent(name) {
|
|
194
|
-
return /^[A-Z][a-zA-Z0-9]*$/.test(name);
|
|
195
|
-
}
|
|
196
|
-
function isEventHandlerName(name, regex = DEFAULT_EVENT_HANDLER_REGEX) {
|
|
197
|
-
return regex.test(name);
|
|
198
|
-
}
|
|
199
|
-
function findEnclosingScopeNode(ancestors, selfNode) {
|
|
200
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
201
|
-
const anc = ancestors[i];
|
|
202
|
-
if (anc !== selfNode && (FUNCTION_NODE_TYPES.has(anc.type) || anc.type === "Program")) {
|
|
203
|
-
return anc;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return ancestors[0];
|
|
207
|
-
}
|
|
208
|
-
function findEnclosingFunction(ancestors, selfNode) {
|
|
209
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
210
|
-
if (ancestors[i] !== selfNode && FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
211
|
-
return ancestors[i];
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
function findOutermostModuleFunction(ancestors) {
|
|
217
|
-
const fnList = [];
|
|
218
|
-
for (let i = 0; i < ancestors.length; i++) {
|
|
219
|
-
if (FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
220
|
-
fnList.push(ancestors[i]);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (fnList.length === 0) return null;
|
|
224
|
-
if (fnList.length === 1) return fnList[0];
|
|
225
|
-
return fnList[1];
|
|
226
|
-
}
|
|
227
|
-
function isZeroArgIifeFactoryFunction(node) {
|
|
228
|
-
if (!node || node.params && node.params.length > 0) return false;
|
|
229
|
-
if (!node.body || node.body.type !== "BlockStatement") return false;
|
|
230
|
-
const stmts = (node.body.body || []).filter(
|
|
231
|
-
(s) => !(s.type === "ExpressionStatement" && s.directive)
|
|
232
|
-
);
|
|
233
|
-
if (stmts.length !== 1 || stmts[0].type !== "ReturnStatement") return false;
|
|
234
|
-
const retArg = stmts[0].argument;
|
|
235
|
-
if (!retArg || retArg.type !== "CallExpression") return false;
|
|
236
|
-
const callee = retArg.callee;
|
|
237
|
-
return callee && (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") && callee.body?.type === "BlockStatement";
|
|
238
|
-
}
|
|
239
|
-
function containsLoopOrAnimation(fnNode, animationCalls = ANIMATION_FRAME_CALLS) {
|
|
240
|
-
let found = false;
|
|
241
|
-
walk.simple(fnNode, {
|
|
242
|
-
ForStatement() {
|
|
243
|
-
found = true;
|
|
244
|
-
},
|
|
245
|
-
ForInStatement() {
|
|
246
|
-
found = true;
|
|
247
|
-
},
|
|
248
|
-
ForOfStatement() {
|
|
249
|
-
found = true;
|
|
250
|
-
},
|
|
251
|
-
WhileStatement() {
|
|
252
|
-
found = true;
|
|
253
|
-
},
|
|
254
|
-
DoWhileStatement() {
|
|
255
|
-
found = true;
|
|
256
|
-
},
|
|
257
|
-
CallExpression(callNode) {
|
|
258
|
-
let cName = "";
|
|
259
|
-
let mProp = "";
|
|
260
|
-
if (callNode.callee?.type === "Identifier") {
|
|
261
|
-
cName = callNode.callee.name;
|
|
262
|
-
} else if (callNode.callee?.type === "MemberExpression" && !callNode.callee.computed && callNode.callee.property?.type === "Identifier") {
|
|
263
|
-
mProp = callNode.callee.property.name;
|
|
264
|
-
}
|
|
265
|
-
const isTickerAdd = mProp === "add" && (callNode.callee?.object?.name === "ticker" || callNode.callee?.object?.property?.name === "ticker");
|
|
266
|
-
if (animationCalls.has(cName) || animationCalls.has(mProp) || isTickerAdd) {
|
|
267
|
-
found = true;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
return found;
|
|
272
|
-
}
|
|
273
|
-
function analyzeAstHotPaths(ast, config) {
|
|
274
|
-
const hotFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
275
|
-
const coldFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
276
|
-
const hotExemptNodes = /* @__PURE__ */ new WeakSet();
|
|
277
|
-
const serializedFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
278
|
-
const serializedWorkerNodes = /* @__PURE__ */ new Set();
|
|
279
|
-
const trueHotNodes = /* @__PURE__ */ new Set();
|
|
280
|
-
const shallowComponentNodes = /* @__PURE__ */ new Set();
|
|
281
|
-
const coldForcedNodes = /* @__PURE__ */ new Set();
|
|
282
|
-
const directHotNodes = /* @__PURE__ */ new Set();
|
|
283
|
-
const serializerHelperNodes = /* @__PURE__ */ new Set();
|
|
284
|
-
const allFunctions = [];
|
|
285
|
-
const fnByName = /* @__PURE__ */ new Map();
|
|
286
|
-
const scopeFunctions = /* @__PURE__ */ new Map();
|
|
287
|
-
const fnScopeChain = /* @__PURE__ */ new Map();
|
|
288
|
-
const fnParams = /* @__PURE__ */ new Map();
|
|
289
|
-
const fnVarAliases = /* @__PURE__ */ new Map();
|
|
290
|
-
const callerToCallees = /* @__PURE__ */ new Map();
|
|
291
|
-
const pendingSerializedRefs = [];
|
|
292
|
-
const pendingHotRefs = [];
|
|
293
|
-
const allCallSites = [];
|
|
294
|
-
const animationCalls = new Set(ANIMATION_FRAME_CALLS);
|
|
295
|
-
if (config?.hotPath?.customAnimationCalls) {
|
|
296
|
-
for (const c of config.hotPath.customAnimationCalls) {
|
|
297
|
-
animationCalls.add(c);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
const mergedImportSources = {
|
|
301
|
-
...DEFAULT_IMPORT_SOURCES,
|
|
302
|
-
...config?.hotPath?.importSources ?? {}
|
|
303
|
-
};
|
|
304
|
-
if (ast && Array.isArray(ast.body)) {
|
|
305
|
-
for (const stmt of ast.body) {
|
|
306
|
-
if (stmt.type === "ImportDeclaration" && stmt.source?.value) {
|
|
307
|
-
const sourcePkg = String(stmt.source.value);
|
|
308
|
-
const sourceMethods = mergedImportSources[sourcePkg];
|
|
309
|
-
for (const spec of stmt.specifiers || []) {
|
|
310
|
-
if (spec.type === "ImportSpecifier") {
|
|
311
|
-
const importedName = spec.imported?.name ?? spec.imported?.value;
|
|
312
|
-
const localName = spec.local?.name;
|
|
313
|
-
if (localName && importedName) {
|
|
314
|
-
const isKnownSource = sourceMethods !== void 0;
|
|
315
|
-
const isListedMethod = sourceMethods && (sourceMethods.includes(importedName) || sourceMethods.includes("*"));
|
|
316
|
-
const isKnownAnimCall = ANIMATION_FRAME_CALLS.has(importedName);
|
|
317
|
-
if (isKnownSource && isListedMethod || isKnownAnimCall) {
|
|
318
|
-
animationCalls.add(localName);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
const hocWrappers = new Set(DEFAULT_HOC_WRAPPERS);
|
|
327
|
-
if (config?.hotPath?.hocWrappers) {
|
|
328
|
-
for (const h of config.hotPath.hocWrappers) {
|
|
329
|
-
hocWrappers.add(h);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
const arrayHofMethods = new Set(ARRAY_HOF_METHODS);
|
|
333
|
-
if (config?.hotPath?.arrayHofMethods) {
|
|
334
|
-
for (const m of config.hotPath.arrayHofMethods) {
|
|
335
|
-
arrayHofMethods.add(m);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
const eventHandlerRegex = config?.hotPath?.eventHandlerRegex ?? DEFAULT_EVENT_HANDLER_REGEX;
|
|
339
|
-
const hookRegex = config?.hotPath?.hookPattern ?? DEFAULT_HOOK_REGEX;
|
|
340
|
-
const customHooksSet = new Set(config?.hotPath?.customHooks ?? []);
|
|
341
|
-
function isHookName(name) {
|
|
342
|
-
if (!name) return false;
|
|
343
|
-
return customHooksSet.has(name) || hookRegex.test(name);
|
|
344
|
-
}
|
|
345
|
-
const excludedComponents = new Set(config?.hotPath?.excludeComponents ?? []);
|
|
346
|
-
const maxPipelineCallers = config?.hotPath?.maxPipelineCallers ?? 2;
|
|
347
|
-
function ensureFnParams(fnNode) {
|
|
348
|
-
let paramSet = fnParams.get(fnNode);
|
|
349
|
-
if (!paramSet) {
|
|
350
|
-
paramSet = /* @__PURE__ */ new Set();
|
|
351
|
-
for (const p of fnNode.params || []) {
|
|
352
|
-
if (p?.type === "Identifier") {
|
|
353
|
-
paramSet.add(p.name);
|
|
354
|
-
} else if (p?.type === "AssignmentPattern" && p.left?.type === "Identifier") {
|
|
355
|
-
paramSet.add(p.left.name);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
fnParams.set(fnNode, paramSet);
|
|
359
|
-
}
|
|
360
|
-
return paramSet;
|
|
361
|
-
}
|
|
362
|
-
function recordVarAlias(scopeNode, varName, rhsName) {
|
|
363
|
-
let map = fnVarAliases.get(scopeNode);
|
|
364
|
-
if (!map) {
|
|
365
|
-
map = /* @__PURE__ */ new Map();
|
|
366
|
-
fnVarAliases.set(scopeNode, map);
|
|
367
|
-
}
|
|
368
|
-
map.set(varName, rhsName);
|
|
369
|
-
}
|
|
370
|
-
function resolveAliasTarget(scopeNode, identName) {
|
|
371
|
-
const map = fnVarAliases.get(scopeNode);
|
|
372
|
-
let cur = identName;
|
|
373
|
-
const seen = /* @__PURE__ */ new Set();
|
|
374
|
-
while (map && map.has(cur) && !seen.has(cur)) {
|
|
375
|
-
seen.add(cur);
|
|
376
|
-
cur = map.get(cur);
|
|
377
|
-
}
|
|
378
|
-
return cur;
|
|
379
|
-
}
|
|
380
|
-
function markSerializedFunction(node) {
|
|
381
|
-
node._unpeekSerialized = true;
|
|
382
|
-
serializedWorkerNodes.add(node);
|
|
383
|
-
serializedFunctionNodes.add(node);
|
|
384
|
-
hotFunctionNodes.add(node);
|
|
385
|
-
directHotNodes.add(node);
|
|
386
|
-
hotExemptNodes.add(node);
|
|
387
|
-
}
|
|
388
|
-
function registerFunctionNode(node, ancestors) {
|
|
389
|
-
const name = getFunctionLabel(node, ancestors, hocWrappers);
|
|
390
|
-
allFunctions.push({ node, name });
|
|
391
|
-
fnByName.set(name, node);
|
|
392
|
-
const paramSet = /* @__PURE__ */ new Set();
|
|
393
|
-
for (const p of node.params || []) {
|
|
394
|
-
if (p?.type === "Identifier") {
|
|
395
|
-
paramSet.add(p.name);
|
|
396
|
-
} else if (p?.type === "AssignmentPattern" && p.left?.type === "Identifier") {
|
|
397
|
-
paramSet.add(p.left.name);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
fnParams.set(node, paramSet);
|
|
401
|
-
const enclosingScope = findEnclosingScopeNode(ancestors, node);
|
|
402
|
-
let localMap = scopeFunctions.get(enclosingScope);
|
|
403
|
-
if (!localMap) {
|
|
404
|
-
localMap = /* @__PURE__ */ new Map();
|
|
405
|
-
scopeFunctions.set(enclosingScope, localMap);
|
|
406
|
-
}
|
|
407
|
-
localMap.set(name, node);
|
|
408
|
-
const parent = ancestors[ancestors.length - 2];
|
|
409
|
-
if (parent?.type === "VariableDeclarator" && parent.id?.type === "Identifier") {
|
|
410
|
-
fnByName.set(parent.id.name, node);
|
|
411
|
-
localMap.set(parent.id.name, node);
|
|
412
|
-
} else if (parent?.type === "AssignmentExpression" && parent.left?.type === "Identifier") {
|
|
413
|
-
fnByName.set(parent.left.name, node);
|
|
414
|
-
localMap.set(parent.left.name, node);
|
|
415
|
-
} else if (parent?.type === "AssignmentExpression" && parent.left?.type === "MemberExpression" && !parent.left.computed && parent.left.property?.type === "Identifier") {
|
|
416
|
-
const propName = parent.left.property.name;
|
|
417
|
-
fnByName.set(propName, node);
|
|
418
|
-
localMap.set(propName, node);
|
|
419
|
-
if (parent.left.object?.type === "Identifier") {
|
|
420
|
-
const qual = `${parent.left.object.name}.${propName}`;
|
|
421
|
-
fnByName.set(qual, node);
|
|
422
|
-
localMap.set(qual, node);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
const grandParent = ancestors[ancestors.length - 3];
|
|
426
|
-
const greatGrandParent = ancestors[ancestors.length - 4];
|
|
427
|
-
if (parent?.type === "Property" && parent.key?.type === "Identifier" && grandParent?.type === "ObjectExpression" && greatGrandParent?.type === "VariableDeclarator" && greatGrandParent.id?.type === "Identifier") {
|
|
428
|
-
const qualified = `${greatGrandParent.id.name}.${parent.key.name}`;
|
|
429
|
-
fnByName.set(qualified, node);
|
|
430
|
-
localMap.set(qualified, node);
|
|
431
|
-
}
|
|
432
|
-
const chain = [];
|
|
433
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
434
|
-
if (ancestors[i] !== node && (FUNCTION_NODE_TYPES.has(ancestors[i].type) || ancestors[i].type === "Program")) {
|
|
435
|
-
chain.push(ancestors[i]);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
fnScopeChain.set(node, chain);
|
|
439
|
-
if (isPascalCaseComponent(name) && !excludedComponents.has(name)) {
|
|
440
|
-
shallowComponentNodes.add(node);
|
|
441
|
-
hotFunctionNodes.add(node);
|
|
442
|
-
directHotNodes.add(node);
|
|
443
|
-
hotExemptNodes.add(node);
|
|
444
|
-
}
|
|
445
|
-
if (isHookName(name)) {
|
|
446
|
-
shallowComponentNodes.add(node);
|
|
447
|
-
hotFunctionNodes.add(node);
|
|
448
|
-
directHotNodes.add(node);
|
|
449
|
-
hotExemptNodes.add(node);
|
|
450
|
-
}
|
|
451
|
-
if (isZeroArgIifeFactoryFunction(node)) {
|
|
452
|
-
markSerializedFunction(node);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
function resolveCalleeNode(callerNode, calleeKey) {
|
|
456
|
-
const directLocal = scopeFunctions.get(callerNode)?.get(calleeKey);
|
|
457
|
-
if (directLocal) return directLocal;
|
|
458
|
-
const chain = fnScopeChain.get(callerNode);
|
|
459
|
-
if (chain) {
|
|
460
|
-
for (const scopeNode of chain) {
|
|
461
|
-
const localMap = scopeFunctions.get(scopeNode);
|
|
462
|
-
const found = localMap?.get(calleeKey);
|
|
463
|
-
if (found) return found;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
return fnByName.get(calleeKey);
|
|
467
|
-
}
|
|
468
|
-
function queueSerializedTarget(target, enclosingScope) {
|
|
469
|
-
if (!target) return;
|
|
470
|
-
if (FUNCTION_NODE_TYPES.has(target.type)) {
|
|
471
|
-
markSerializedFunction(target);
|
|
472
|
-
} else if (target.type === "Identifier") {
|
|
473
|
-
pendingSerializedRefs.push({ scopeNode: enclosingScope, name: target.name });
|
|
474
|
-
} else if (target.type === "MemberExpression" && !target.computed && target.property?.type === "Identifier") {
|
|
475
|
-
pendingSerializedRefs.push({
|
|
476
|
-
scopeNode: enclosingScope,
|
|
477
|
-
name: target.property.name
|
|
478
|
-
});
|
|
479
|
-
if (target.object?.type === "Identifier") {
|
|
480
|
-
pendingSerializedRefs.push({
|
|
481
|
-
scopeNode: enclosingScope,
|
|
482
|
-
name: `${target.object.name}.${target.property.name}`
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
walk.ancestor(ast, {
|
|
488
|
-
FunctionDeclaration(node, _state, ancestors) {
|
|
489
|
-
registerFunctionNode(node, ancestors);
|
|
490
|
-
},
|
|
491
|
-
FunctionExpression(node, _state, ancestors) {
|
|
492
|
-
registerFunctionNode(node, ancestors);
|
|
493
|
-
},
|
|
494
|
-
ArrowFunctionExpression(node, _state, ancestors) {
|
|
495
|
-
registerFunctionNode(node, ancestors);
|
|
496
|
-
},
|
|
497
|
-
VariableDeclarator(node, _state, ancestors) {
|
|
498
|
-
if (node.id?.type === "Identifier" && node.init?.type === "Identifier") {
|
|
499
|
-
const scopeNode = findEnclosingFunction(ancestors) ?? ast;
|
|
500
|
-
recordVarAlias(scopeNode, node.id.name, node.init.name);
|
|
501
|
-
}
|
|
502
|
-
},
|
|
503
|
-
AssignmentExpression(node, _state, ancestors) {
|
|
504
|
-
const left = node.left;
|
|
505
|
-
if (left?.type === "Identifier" && node.right?.type === "Identifier") {
|
|
506
|
-
const scopeNode = findEnclosingFunction(ancestors) ?? ast;
|
|
507
|
-
recordVarAlias(scopeNode, left.name, node.right.name);
|
|
508
|
-
}
|
|
509
|
-
const isBareOnMessage = left?.type === "Identifier" && left.name === "onmessage";
|
|
510
|
-
const isSelfOnMessage = left?.type === "MemberExpression" && !left.computed && left.object?.type === "Identifier" && left.object.name === "self" && left.property?.type === "Identifier" && left.property.name === "onmessage";
|
|
511
|
-
if (isBareOnMessage || isSelfOnMessage) {
|
|
512
|
-
const enclosingFn = findEnclosingFunction(ancestors);
|
|
513
|
-
if (enclosingFn) {
|
|
514
|
-
markSerializedFunction(enclosingFn);
|
|
515
|
-
}
|
|
516
|
-
const outerFn = findOutermostModuleFunction(ancestors);
|
|
517
|
-
if (outerFn) {
|
|
518
|
-
markSerializedFunction(outerFn);
|
|
519
|
-
}
|
|
520
|
-
const scopeNode = enclosingFn ?? ast;
|
|
521
|
-
queueSerializedTarget(node.right, scopeNode);
|
|
522
|
-
}
|
|
523
|
-
},
|
|
524
|
-
ObjectExpression(node, _state, ancestors) {
|
|
525
|
-
const props = node.properties || [];
|
|
526
|
-
const propMap = /* @__PURE__ */ new Map();
|
|
527
|
-
for (const p of props) {
|
|
528
|
-
if (p?.type === "Property" && !p.computed) {
|
|
529
|
-
const keyName = p.key?.type === "Identifier" ? p.key.name : p.key?.type === "Literal" ? String(p.key.value) : "";
|
|
530
|
-
if (keyName) {
|
|
531
|
-
propMap.set(keyName, p.value);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
const hasWorkerDescriptorShape = propMap.has("init") && propMap.has("dependencies") || propMap.has("isWorkerModule") || propMap.has("getTransferables") && (propMap.has("init") || propMap.has("dependencies"));
|
|
536
|
-
if (hasWorkerDescriptorShape) {
|
|
537
|
-
const scopeNode = findEnclosingFunction(ancestors) ?? ast;
|
|
538
|
-
for (const key of ["init", "getTransferables", "worker"]) {
|
|
539
|
-
const val = propMap.get(key);
|
|
540
|
-
if (val) queueSerializedTarget(val, scopeNode);
|
|
541
|
-
}
|
|
542
|
-
const deps = propMap.get("dependencies");
|
|
543
|
-
if (deps?.type === "ArrayExpression") {
|
|
544
|
-
for (const el of deps.elements || []) {
|
|
545
|
-
if (el) queueSerializedTarget(el, scopeNode);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
|
-
CallExpression(node, _state, ancestors) {
|
|
551
|
-
const callee = node.callee;
|
|
552
|
-
let calleeName = "";
|
|
553
|
-
let memberProp = "";
|
|
554
|
-
let qualifiedCall = "";
|
|
555
|
-
if (callee?.type === "Identifier") {
|
|
556
|
-
calleeName = callee.name;
|
|
557
|
-
qualifiedCall = calleeName;
|
|
558
|
-
} else if (callee?.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier") {
|
|
559
|
-
memberProp = callee.property.name;
|
|
560
|
-
if (callee.object?.type === "Identifier") {
|
|
561
|
-
qualifiedCall = `${callee.object.name}.${memberProp}`;
|
|
562
|
-
} else if (callee.object?.type === "ThisExpression") {
|
|
563
|
-
qualifiedCall = memberProp;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
const enclosingFn = findEnclosingFunction(ancestors);
|
|
567
|
-
const currentScope = enclosingFn ?? ast;
|
|
568
|
-
if (qualifiedCall || memberProp) {
|
|
569
|
-
allCallSites.push({
|
|
570
|
-
scopeNode: currentScope,
|
|
571
|
-
calleeKey: qualifiedCall || memberProp,
|
|
572
|
-
args: node.arguments || []
|
|
573
|
-
});
|
|
574
|
-
if (enclosingFn) {
|
|
575
|
-
let set = callerToCallees.get(enclosingFn);
|
|
576
|
-
if (!set) {
|
|
577
|
-
set = /* @__PURE__ */ new Set();
|
|
578
|
-
callerToCallees.set(enclosingFn, set);
|
|
579
|
-
}
|
|
580
|
-
if (qualifiedCall) set.add(qualifiedCall);
|
|
581
|
-
if (memberProp && !arrayHofMethods.has(memberProp)) {
|
|
582
|
-
set.add(memberProp);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
if (memberProp === "toString" && (!node.arguments || node.arguments.length === 0) && callee?.type === "MemberExpression") {
|
|
587
|
-
const targetObj = callee.object;
|
|
588
|
-
queueSerializedTarget(targetObj, currentScope);
|
|
589
|
-
if (targetObj?.type === "Identifier" && enclosingFn) {
|
|
590
|
-
const resolvedName = resolveAliasTarget(enclosingFn, targetObj.name);
|
|
591
|
-
if (ensureFnParams(enclosingFn).has(resolvedName)) {
|
|
592
|
-
serializerHelperNodes.add(enclosingFn);
|
|
593
|
-
}
|
|
594
|
-
if (resolvedName !== targetObj.name) {
|
|
595
|
-
queueSerializedTarget({ type: "Identifier", name: resolvedName }, currentScope);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
if ((memberProp === "call" || memberProp === "apply") && callee?.type === "MemberExpression" && callee.object?.type === "MemberExpression" && callee.object.property?.type === "Identifier" && callee.object.property.name === "toString" && node.arguments?.length > 0) {
|
|
600
|
-
const firstArg = node.arguments[0];
|
|
601
|
-
queueSerializedTarget(firstArg, currentScope);
|
|
602
|
-
if (firstArg?.type === "Identifier" && enclosingFn) {
|
|
603
|
-
const resolvedName = resolveAliasTarget(enclosingFn, firstArg.name);
|
|
604
|
-
if (ensureFnParams(enclosingFn).has(resolvedName)) {
|
|
605
|
-
serializerHelperNodes.add(enclosingFn);
|
|
606
|
-
}
|
|
607
|
-
if (resolvedName !== firstArg.name) {
|
|
608
|
-
queueSerializedTarget({ type: "Identifier", name: resolvedName }, currentScope);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
if (calleeName === "importScripts" || memberProp === "importScripts" && callee?.object?.type === "Identifier" && callee.object.name === "self") {
|
|
613
|
-
if (enclosingFn) markSerializedFunction(enclosingFn);
|
|
614
|
-
const outerFn = findOutermostModuleFunction(ancestors);
|
|
615
|
-
if (outerFn) markSerializedFunction(outerFn);
|
|
616
|
-
}
|
|
617
|
-
const isTickerAdd = memberProp === "add" && (callee?.object?.name === "ticker" || callee?.object?.property?.name === "ticker");
|
|
618
|
-
if (animationCalls.has(calleeName) || animationCalls.has(memberProp) || isTickerAdd) {
|
|
619
|
-
if (enclosingFn) {
|
|
620
|
-
trueHotNodes.add(enclosingFn);
|
|
621
|
-
hotFunctionNodes.add(enclosingFn);
|
|
622
|
-
directHotNodes.add(enclosingFn);
|
|
623
|
-
}
|
|
624
|
-
for (const arg of node.arguments || []) {
|
|
625
|
-
if (FUNCTION_NODE_TYPES.has(arg.type)) {
|
|
626
|
-
trueHotNodes.add(arg);
|
|
627
|
-
hotFunctionNodes.add(arg);
|
|
628
|
-
directHotNodes.add(arg);
|
|
629
|
-
hotExemptNodes.add(arg);
|
|
630
|
-
} else if (arg?.type === "Identifier") {
|
|
631
|
-
pendingHotRefs.push({ scopeNode: currentScope, name: arg.name });
|
|
632
|
-
allCallSites.push({
|
|
633
|
-
scopeNode: currentScope,
|
|
634
|
-
calleeKey: arg.name,
|
|
635
|
-
args: [arg]
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
if (arrayHofMethods.has(memberProp)) {
|
|
641
|
-
if (enclosingFn !== null) {
|
|
642
|
-
for (const arg of node.arguments || []) {
|
|
643
|
-
if (FUNCTION_NODE_TYPES.has(arg.type)) {
|
|
644
|
-
trueHotNodes.add(arg);
|
|
645
|
-
hotFunctionNodes.add(arg);
|
|
646
|
-
directHotNodes.add(arg);
|
|
647
|
-
hotExemptNodes.add(arg);
|
|
648
|
-
} else if (arg?.type === "Identifier") {
|
|
649
|
-
allCallSites.push({
|
|
650
|
-
scopeNode: currentScope,
|
|
651
|
-
calleeKey: arg.name,
|
|
652
|
-
args: [arg]
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
} else {
|
|
657
|
-
for (const arg of node.arguments || []) {
|
|
658
|
-
const isAnonymousFunction = arg.type === "FunctionExpression" && !arg.id || arg.type === "ArrowFunctionExpression";
|
|
659
|
-
if (isAnonymousFunction) {
|
|
660
|
-
coldForcedNodes.add(arg);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
if (calleeName === "useEffect" || memberProp === "useEffect" || calleeName === "useLayoutEffect" || memberProp === "useLayoutEffect") {
|
|
666
|
-
const effectArg = node.arguments?.[0];
|
|
667
|
-
if (effectArg && FUNCTION_NODE_TYPES.has(effectArg.type)) {
|
|
668
|
-
if (!containsLoopOrAnimation(effectArg, animationCalls)) {
|
|
669
|
-
coldForcedNodes.add(effectArg);
|
|
670
|
-
if (effectArg.body?.type === "BlockStatement") {
|
|
671
|
-
for (const s of effectArg.body.body || []) {
|
|
672
|
-
if (s.type === "ReturnStatement" && s.argument && FUNCTION_NODE_TYPES.has(s.argument.type) && !containsLoopOrAnimation(s.argument, animationCalls)) {
|
|
673
|
-
coldForcedNodes.add(s.argument);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
if (REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp) || isHookName(calleeName) || isHookName(memberProp)) {
|
|
681
|
-
if (enclosingFn) {
|
|
682
|
-
shallowComponentNodes.add(enclosingFn);
|
|
683
|
-
hotFunctionNodes.add(enclosingFn);
|
|
684
|
-
directHotNodes.add(enclosingFn);
|
|
685
|
-
hotExemptNodes.add(enclosingFn);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
},
|
|
689
|
-
ForStatement(node, _state, ancestors) {
|
|
690
|
-
hotExemptNodes.add(node);
|
|
691
|
-
const enc = findEnclosingFunction(ancestors);
|
|
692
|
-
if (enc) {
|
|
693
|
-
trueHotNodes.add(enc);
|
|
694
|
-
hotFunctionNodes.add(enc);
|
|
695
|
-
directHotNodes.add(enc);
|
|
696
|
-
}
|
|
697
|
-
},
|
|
698
|
-
ForInStatement(node, _state, ancestors) {
|
|
699
|
-
hotExemptNodes.add(node);
|
|
700
|
-
const enc = findEnclosingFunction(ancestors);
|
|
701
|
-
if (enc) {
|
|
702
|
-
trueHotNodes.add(enc);
|
|
703
|
-
hotFunctionNodes.add(enc);
|
|
704
|
-
directHotNodes.add(enc);
|
|
705
|
-
}
|
|
706
|
-
},
|
|
707
|
-
ForOfStatement(node, _state, ancestors) {
|
|
708
|
-
hotExemptNodes.add(node);
|
|
709
|
-
const enc = findEnclosingFunction(ancestors);
|
|
710
|
-
if (enc) {
|
|
711
|
-
trueHotNodes.add(enc);
|
|
712
|
-
hotFunctionNodes.add(enc);
|
|
713
|
-
directHotNodes.add(enc);
|
|
714
|
-
}
|
|
715
|
-
},
|
|
716
|
-
WhileStatement(node, _state, ancestors) {
|
|
717
|
-
hotExemptNodes.add(node);
|
|
718
|
-
const enc = findEnclosingFunction(ancestors);
|
|
719
|
-
if (enc) {
|
|
720
|
-
trueHotNodes.add(enc);
|
|
721
|
-
hotFunctionNodes.add(enc);
|
|
722
|
-
directHotNodes.add(enc);
|
|
723
|
-
}
|
|
724
|
-
},
|
|
725
|
-
DoWhileStatement(node, _state, ancestors) {
|
|
726
|
-
hotExemptNodes.add(node);
|
|
727
|
-
const enc = findEnclosingFunction(ancestors);
|
|
728
|
-
if (enc) {
|
|
729
|
-
trueHotNodes.add(enc);
|
|
730
|
-
hotFunctionNodes.add(enc);
|
|
731
|
-
directHotNodes.add(enc);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
});
|
|
735
|
-
for (const callSite of allCallSites) {
|
|
736
|
-
const resolvedCallee = resolveCalleeNode(callSite.scopeNode, callSite.calleeKey);
|
|
737
|
-
if (resolvedCallee && serializerHelperNodes.has(resolvedCallee)) {
|
|
738
|
-
for (const arg of callSite.args) {
|
|
739
|
-
queueSerializedTarget(arg, callSite.scopeNode);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
for (const ref of pendingSerializedRefs) {
|
|
744
|
-
const targetNode = resolveCalleeNode(ref.scopeNode, ref.name);
|
|
745
|
-
if (targetNode) {
|
|
746
|
-
markSerializedFunction(targetNode);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
for (const ref of pendingHotRefs) {
|
|
750
|
-
const targetNode = resolveCalleeNode(ref.scopeNode, ref.name);
|
|
751
|
-
if (targetNode) {
|
|
752
|
-
trueHotNodes.add(targetNode);
|
|
753
|
-
hotFunctionNodes.add(targetNode);
|
|
754
|
-
directHotNodes.add(targetNode);
|
|
755
|
-
hotExemptNodes.add(targetNode);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
for (const fn of allFunctions) {
|
|
759
|
-
if (!trueHotNodes.has(fn.node) && !containsLoopOrAnimation(fn.node, animationCalls)) {
|
|
760
|
-
if (!shallowComponentNodes.has(fn.node)) {
|
|
761
|
-
if (fn.node.async === true || isEventHandlerName(fn.name, eventHandlerRegex)) {
|
|
762
|
-
coldForcedNodes.add(fn.node);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
let forwardChanged = true;
|
|
768
|
-
while (forwardChanged) {
|
|
769
|
-
forwardChanged = false;
|
|
770
|
-
for (const fn of allFunctions) {
|
|
771
|
-
if (coldForcedNodes.has(fn.node)) continue;
|
|
772
|
-
const chain = fnScopeChain.get(fn.node);
|
|
773
|
-
if (!chain) continue;
|
|
774
|
-
for (const anc of chain) {
|
|
775
|
-
if (anc === fn.node) continue;
|
|
776
|
-
if (serializedWorkerNodes.has(anc)) {
|
|
777
|
-
if (!serializedWorkerNodes.has(fn.node)) {
|
|
778
|
-
fn.node._unpeekSerialized = true;
|
|
779
|
-
serializedWorkerNodes.add(fn.node);
|
|
780
|
-
serializedFunctionNodes.add(fn.node);
|
|
781
|
-
hotFunctionNodes.add(fn.node);
|
|
782
|
-
hotExemptNodes.add(fn.node);
|
|
783
|
-
forwardChanged = true;
|
|
784
|
-
}
|
|
785
|
-
break;
|
|
786
|
-
}
|
|
787
|
-
const isModuleContainer = (fnScopeChain.get(anc)?.length ?? 0) <= 1;
|
|
788
|
-
if (trueHotNodes.has(anc) && !shallowComponentNodes.has(anc) && !isModuleContainer) {
|
|
789
|
-
if (!trueHotNodes.has(fn.node)) {
|
|
790
|
-
trueHotNodes.add(fn.node);
|
|
791
|
-
hotFunctionNodes.add(fn.node);
|
|
792
|
-
hotExemptNodes.add(fn.node);
|
|
793
|
-
forwardChanged = true;
|
|
794
|
-
}
|
|
795
|
-
break;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
for (const callerNode of Array.from(serializedWorkerNodes)) {
|
|
800
|
-
const calleeNames = callerToCallees.get(callerNode);
|
|
801
|
-
if (!calleeNames) continue;
|
|
802
|
-
for (const cName of calleeNames) {
|
|
803
|
-
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
804
|
-
if (targetNode && !serializedWorkerNodes.has(targetNode) && !coldForcedNodes.has(targetNode)) {
|
|
805
|
-
targetNode._unpeekSerialized = true;
|
|
806
|
-
serializedWorkerNodes.add(targetNode);
|
|
807
|
-
serializedFunctionNodes.add(targetNode);
|
|
808
|
-
hotFunctionNodes.add(targetNode);
|
|
809
|
-
hotExemptNodes.add(targetNode);
|
|
810
|
-
forwardChanged = true;
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
for (const callerNode of Array.from(trueHotNodes)) {
|
|
815
|
-
const calleeNames = callerToCallees.get(callerNode);
|
|
816
|
-
if (!calleeNames) continue;
|
|
817
|
-
for (const cName of calleeNames) {
|
|
818
|
-
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
819
|
-
if (targetNode && !trueHotNodes.has(targetNode) && !coldForcedNodes.has(targetNode)) {
|
|
820
|
-
trueHotNodes.add(targetNode);
|
|
821
|
-
hotFunctionNodes.add(targetNode);
|
|
822
|
-
hotExemptNodes.add(targetNode);
|
|
823
|
-
forwardChanged = true;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
const calleeToCallers = /* @__PURE__ */ new Map();
|
|
829
|
-
for (const [callerNode, calleeNames] of callerToCallees.entries()) {
|
|
830
|
-
for (const cName of calleeNames) {
|
|
831
|
-
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
832
|
-
if (targetNode) {
|
|
833
|
-
let set = calleeToCallers.get(targetNode);
|
|
834
|
-
if (!set) {
|
|
835
|
-
set = /* @__PURE__ */ new Set();
|
|
836
|
-
calleeToCallers.set(targetNode, set);
|
|
837
|
-
}
|
|
838
|
-
set.add(callerNode);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
let changed = true;
|
|
843
|
-
while (changed) {
|
|
844
|
-
changed = false;
|
|
845
|
-
for (const [callerNode, calleeNames] of callerToCallees.entries()) {
|
|
846
|
-
if (hotFunctionNodes.has(callerNode) || shallowComponentNodes.has(callerNode) || coldForcedNodes.has(callerNode)) {
|
|
847
|
-
continue;
|
|
848
|
-
}
|
|
849
|
-
for (const cName of calleeNames) {
|
|
850
|
-
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
851
|
-
if (targetNode && trueHotNodes.has(targetNode)) {
|
|
852
|
-
const callers = calleeToCallers.get(targetNode);
|
|
853
|
-
const isDedicatedPipeline = callers && callers.size <= maxPipelineCallers;
|
|
854
|
-
if (isDedicatedPipeline) {
|
|
855
|
-
trueHotNodes.add(callerNode);
|
|
856
|
-
hotFunctionNodes.add(callerNode);
|
|
857
|
-
hotExemptNodes.add(callerNode);
|
|
858
|
-
changed = true;
|
|
859
|
-
break;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
for (const node of coldForcedNodes) {
|
|
866
|
-
hotFunctionNodes.delete(node);
|
|
867
|
-
hotExemptNodes.delete(node);
|
|
868
|
-
}
|
|
869
|
-
const hotFunctionsSkipped = [];
|
|
870
|
-
const coldFunctionsProtected = [];
|
|
871
|
-
for (const fn of allFunctions) {
|
|
872
|
-
if (hotFunctionNodes.has(fn.node)) {
|
|
873
|
-
hotFunctionsSkipped.push(fn.name);
|
|
874
|
-
} else {
|
|
875
|
-
coldFunctionNodes.add(fn.node);
|
|
876
|
-
coldFunctionsProtected.push(fn.name);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
return {
|
|
880
|
-
report: {
|
|
881
|
-
totalFunctions: allFunctions.length,
|
|
882
|
-
hotFunctionsSkipped,
|
|
883
|
-
coldFunctionsProtected
|
|
884
|
-
},
|
|
885
|
-
hotFunctionNodes,
|
|
886
|
-
coldFunctionNodes,
|
|
887
|
-
hotExemptNodes,
|
|
888
|
-
serializedFunctionNodes
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
function detectHotPaths(code, config) {
|
|
892
|
-
const ast = parseJavaScriptAst(code);
|
|
893
|
-
if (!ast) {
|
|
894
|
-
return {
|
|
895
|
-
totalFunctions: 0,
|
|
896
|
-
hotFunctionsSkipped: [],
|
|
897
|
-
coldFunctionsProtected: []
|
|
898
|
-
};
|
|
899
|
-
}
|
|
900
|
-
return analyzeAstHotPaths(ast, config).report;
|
|
901
|
-
}
|
|
4
|
+
var _chunkLXP73HJCcjs = require('../chunk-LXP73HJC.cjs');
|
|
902
5
|
|
|
903
|
-
// src/ast/string-vault.ts
|
|
904
|
-
var acorn4 = __toESM(require("acorn"), 1);
|
|
905
|
-
var walk3 = __toESM(require("acorn-walk"), 1);
|
|
906
6
|
|
|
907
|
-
|
|
908
|
-
var import_astring = require("astring");
|
|
909
|
-
function derivePolymorphicIdent(seed, role) {
|
|
910
|
-
let h = (2166136261 ^ seed >>> 0) >>> 0;
|
|
911
|
-
for (let i = 0; i < role.length; i++) {
|
|
912
|
-
h ^= role.charCodeAt(i);
|
|
913
|
-
h = Math.imul(h, 16777619) >>> 0;
|
|
914
|
-
}
|
|
915
|
-
const rolePrefixes = {
|
|
916
|
-
vault: "_a",
|
|
917
|
-
shield: "$b",
|
|
918
|
-
decoy: "_d",
|
|
919
|
-
shader: "_s",
|
|
920
|
-
vm: "_m",
|
|
921
|
-
wasm: "_w",
|
|
922
|
-
salted: "_k",
|
|
923
|
-
windowKey: "_z"
|
|
924
|
-
};
|
|
925
|
-
const prefix = rolePrefixes[role] ?? `_${String.fromCharCode(97 + h % 26)}`;
|
|
926
|
-
const suffix = ((h >>> 4) % 1296).toString(36).padStart(2, "0");
|
|
927
|
-
return `${prefix}${suffix}`;
|
|
928
|
-
}
|
|
929
|
-
var OPERATOR_PRECEDENCE = {
|
|
930
|
-
"||": 2,
|
|
931
|
-
"??": 3,
|
|
932
|
-
"&&": 4,
|
|
933
|
-
"|": 5,
|
|
934
|
-
"^": 6,
|
|
935
|
-
"&": 7,
|
|
936
|
-
"==": 8,
|
|
937
|
-
"!=": 8,
|
|
938
|
-
"===": 8,
|
|
939
|
-
"!==": 8,
|
|
940
|
-
"<": 9,
|
|
941
|
-
">": 9,
|
|
942
|
-
"<=": 9,
|
|
943
|
-
">=": 9,
|
|
944
|
-
"in": 9,
|
|
945
|
-
"instanceof": 9,
|
|
946
|
-
"<<": 10,
|
|
947
|
-
">>": 10,
|
|
948
|
-
">>>": 10,
|
|
949
|
-
"+": 11,
|
|
950
|
-
"-": 11,
|
|
951
|
-
"*": 12,
|
|
952
|
-
"%": 12,
|
|
953
|
-
"/": 12,
|
|
954
|
-
"**": 13
|
|
955
|
-
};
|
|
956
|
-
var NEEDS_PARENTHESES = 17;
|
|
957
|
-
function expressionNeedsParenthesis(state, node, parentNode, isRightHand) {
|
|
958
|
-
const nodePrecedence = state.expressionsPrecedence[node.type];
|
|
959
|
-
if (nodePrecedence === NEEDS_PARENTHESES) {
|
|
960
|
-
return true;
|
|
961
|
-
}
|
|
962
|
-
const parentNodePrecedence = state.expressionsPrecedence[parentNode.type];
|
|
963
|
-
if (nodePrecedence !== parentNodePrecedence) {
|
|
964
|
-
return !isRightHand && nodePrecedence === 15 && parentNodePrecedence === 14 && parentNode.operator === "**" || nodePrecedence < parentNodePrecedence;
|
|
965
|
-
}
|
|
966
|
-
if (nodePrecedence !== 13 && nodePrecedence !== 14) {
|
|
967
|
-
return false;
|
|
968
|
-
}
|
|
969
|
-
if (node.operator === "**" && parentNode.operator === "**") {
|
|
970
|
-
return !isRightHand;
|
|
971
|
-
}
|
|
972
|
-
if (nodePrecedence === 13 && parentNodePrecedence === 13 && (node.operator === "??" || parentNode.operator === "??")) {
|
|
973
|
-
return true;
|
|
974
|
-
}
|
|
975
|
-
if (isRightHand) {
|
|
976
|
-
return OPERATOR_PRECEDENCE[node.operator] <= OPERATOR_PRECEDENCE[parentNode.operator];
|
|
977
|
-
}
|
|
978
|
-
return OPERATOR_PRECEDENCE[node.operator] < OPERATOR_PRECEDENCE[parentNode.operator];
|
|
979
|
-
}
|
|
980
|
-
function formatExpression(state, node, parentNode, isRightHand) {
|
|
981
|
-
const generator = state.generator;
|
|
982
|
-
if (expressionNeedsParenthesis(state, node, parentNode, isRightHand)) {
|
|
983
|
-
state.write("(");
|
|
984
|
-
generator[node.type](node, state);
|
|
985
|
-
state.write(")");
|
|
986
|
-
} else {
|
|
987
|
-
generator[node.type](node, state);
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
function formatSequence(state, expressions) {
|
|
991
|
-
const length = expressions.length;
|
|
992
|
-
if (length > 0) {
|
|
993
|
-
state.write("(");
|
|
994
|
-
state.generator[expressions[0].type](expressions[0], state);
|
|
995
|
-
for (let i = 1; i < length; i++) {
|
|
996
|
-
state.write(",");
|
|
997
|
-
state.generator[expressions[i].type](expressions[i], state);
|
|
998
|
-
}
|
|
999
|
-
state.write(")");
|
|
1000
|
-
} else {
|
|
1001
|
-
state.write("()");
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
function expressionStartsWith(node, char) {
|
|
1005
|
-
if (!node) return false;
|
|
1006
|
-
if (node.type === "UnaryExpression" && node.prefix) {
|
|
1007
|
-
return node.operator === char;
|
|
1008
|
-
}
|
|
1009
|
-
if (node.type === "UpdateExpression" && node.prefix) {
|
|
1010
|
-
return node.operator[0] === char;
|
|
1011
|
-
}
|
|
1012
|
-
return false;
|
|
1013
|
-
}
|
|
1014
|
-
function expressionEndsWith(node, char) {
|
|
1015
|
-
if (!node) return false;
|
|
1016
|
-
if (node.type === "UpdateExpression" && !node.prefix) {
|
|
1017
|
-
return node.operator[0] === char;
|
|
1018
|
-
}
|
|
1019
|
-
return false;
|
|
1020
|
-
}
|
|
1021
|
-
function isRegExp(node) {
|
|
1022
|
-
return node && (node.type === "Literal" && !!node.regex || node.type === "RegExpLiteral");
|
|
1023
|
-
}
|
|
1024
|
-
var compactGenerator = Object.assign({}, import_astring.baseGenerator, {
|
|
1025
|
-
BinaryExpression(node, state) {
|
|
1026
|
-
const isIn = node.operator === "in";
|
|
1027
|
-
if (isIn) {
|
|
1028
|
-
state.write("(");
|
|
1029
|
-
}
|
|
1030
|
-
formatExpression(state, node.left, node, false);
|
|
1031
|
-
const op = node.operator;
|
|
1032
|
-
let spaceBefore = false;
|
|
1033
|
-
let spaceAfter = false;
|
|
1034
|
-
if (op === "in" || op === "instanceof") {
|
|
1035
|
-
spaceBefore = true;
|
|
1036
|
-
spaceAfter = true;
|
|
1037
|
-
} else {
|
|
1038
|
-
if ((op === "+" || op === "-") && expressionEndsWith(node.left, op) && !expressionNeedsParenthesis(state, node.left, node, false)) {
|
|
1039
|
-
spaceBefore = true;
|
|
1040
|
-
}
|
|
1041
|
-
if ((op === "+" || op === "-") && expressionStartsWith(node.right, op) && !expressionNeedsParenthesis(state, node.right, node, true) || op === "/" && isRegExp(node.right)) {
|
|
1042
|
-
spaceAfter = true;
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
if (spaceBefore) state.write(" ");
|
|
1046
|
-
state.write(op);
|
|
1047
|
-
if (spaceAfter) state.write(" ");
|
|
1048
|
-
formatExpression(state, node.right, node, true);
|
|
1049
|
-
if (isIn) {
|
|
1050
|
-
state.write(")");
|
|
1051
|
-
}
|
|
1052
|
-
},
|
|
1053
|
-
LogicalExpression(node, state) {
|
|
1054
|
-
formatExpression(state, node.left, node, false);
|
|
1055
|
-
state.write(node.operator);
|
|
1056
|
-
formatExpression(state, node.right, node, true);
|
|
1057
|
-
},
|
|
1058
|
-
AssignmentExpression(node, state) {
|
|
1059
|
-
this[node.left.type](node.left, state);
|
|
1060
|
-
const op = node.operator;
|
|
1061
|
-
if (op.endsWith("+") && expressionStartsWith(node.right, "+") || op.endsWith("-") && expressionStartsWith(node.right, "-") || op.endsWith("/") && isRegExp(node.right)) {
|
|
1062
|
-
state.write(op + " ");
|
|
1063
|
-
} else {
|
|
1064
|
-
state.write(op);
|
|
1065
|
-
}
|
|
1066
|
-
this[node.right.type](node.right, state);
|
|
1067
|
-
},
|
|
1068
|
-
ConditionalExpression(node, state) {
|
|
1069
|
-
const test = node.test;
|
|
1070
|
-
const precedence = state.expressionsPrecedence[test.type];
|
|
1071
|
-
if (precedence === NEEDS_PARENTHESES || precedence <= state.expressionsPrecedence.ConditionalExpression) {
|
|
1072
|
-
state.write("(");
|
|
1073
|
-
this[test.type](test, state);
|
|
1074
|
-
state.write(")");
|
|
1075
|
-
} else {
|
|
1076
|
-
this[test.type](test, state);
|
|
1077
|
-
}
|
|
1078
|
-
state.write("?");
|
|
1079
|
-
this[node.consequent.type](node.consequent, state);
|
|
1080
|
-
state.write(":");
|
|
1081
|
-
this[node.alternate.type](node.alternate, state);
|
|
1082
|
-
},
|
|
1083
|
-
ArrayExpression(node, state) {
|
|
1084
|
-
state.write("[");
|
|
1085
|
-
const elements = node.elements;
|
|
1086
|
-
const length = elements.length;
|
|
1087
|
-
for (let i = 0; i < length; i++) {
|
|
1088
|
-
const element = elements[i];
|
|
1089
|
-
if (element != null) {
|
|
1090
|
-
this[element.type](element, state);
|
|
1091
|
-
}
|
|
1092
|
-
if (i + 1 < length) {
|
|
1093
|
-
state.write(",");
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
state.write("]");
|
|
1097
|
-
},
|
|
1098
|
-
ObjectExpression(node, state) {
|
|
1099
|
-
state.write("{");
|
|
1100
|
-
const properties = node.properties;
|
|
1101
|
-
const length = properties.length;
|
|
1102
|
-
for (let i = 0; i < length; i++) {
|
|
1103
|
-
const property = properties[i];
|
|
1104
|
-
this[property.type](property, state);
|
|
1105
|
-
if (i + 1 < length) {
|
|
1106
|
-
state.write(",");
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
state.write("}");
|
|
1110
|
-
},
|
|
1111
|
-
Property(node, state) {
|
|
1112
|
-
if (node.method || node.kind[0] !== "i") {
|
|
1113
|
-
this.MethodDefinition(node, state);
|
|
1114
|
-
} else {
|
|
1115
|
-
if (!node.shorthand) {
|
|
1116
|
-
if (node.computed) {
|
|
1117
|
-
state.write("[");
|
|
1118
|
-
this[node.key.type](node.key, state);
|
|
1119
|
-
state.write("]");
|
|
1120
|
-
} else {
|
|
1121
|
-
this[node.key.type](node.key, state);
|
|
1122
|
-
}
|
|
1123
|
-
state.write(":");
|
|
1124
|
-
}
|
|
1125
|
-
this[node.value.type](node.value, state);
|
|
1126
|
-
}
|
|
1127
|
-
},
|
|
1128
|
-
CallExpression(node, state) {
|
|
1129
|
-
formatExpression(state, node.callee, node, false);
|
|
1130
|
-
if (node.optional) {
|
|
1131
|
-
state.write("?.");
|
|
1132
|
-
}
|
|
1133
|
-
formatSequence(state, node.arguments);
|
|
1134
|
-
},
|
|
1135
|
-
SequenceExpression(node, state) {
|
|
1136
|
-
formatSequence(state, node.expressions);
|
|
1137
|
-
},
|
|
1138
|
-
FunctionDeclaration(node, state) {
|
|
1139
|
-
state.write(
|
|
1140
|
-
(node.async ? "async " : "") + (node.generator ? "function* " : "function ") + (node.id ? node.id.name : ""),
|
|
1141
|
-
node
|
|
1142
|
-
);
|
|
1143
|
-
formatSequence(state, node.params);
|
|
1144
|
-
this[node.body.type](node.body, state);
|
|
1145
|
-
},
|
|
1146
|
-
FunctionExpression(node, state) {
|
|
1147
|
-
compactGenerator.FunctionDeclaration.call(this, node, state);
|
|
1148
|
-
},
|
|
1149
|
-
ArrowFunctionExpression(node, state) {
|
|
1150
|
-
state.write(node.async ? "async " : "", node);
|
|
1151
|
-
const params = node.params;
|
|
1152
|
-
if (params != null) {
|
|
1153
|
-
if (params.length === 0) {
|
|
1154
|
-
state.write("()");
|
|
1155
|
-
} else if (params.length === 1 && params[0].type === "Identifier") {
|
|
1156
|
-
state.write(params[0].name, params[0]);
|
|
1157
|
-
} else {
|
|
1158
|
-
formatSequence(state, node.params);
|
|
1159
|
-
}
|
|
1160
|
-
} else {
|
|
1161
|
-
state.write("()");
|
|
1162
|
-
}
|
|
1163
|
-
state.write("=>");
|
|
1164
|
-
if (node.body.type[0] === "O") {
|
|
1165
|
-
state.write("(");
|
|
1166
|
-
this.ObjectExpression(node.body, state);
|
|
1167
|
-
state.write(")");
|
|
1168
|
-
} else {
|
|
1169
|
-
this[node.body.type](node.body, state);
|
|
1170
|
-
}
|
|
1171
|
-
},
|
|
1172
|
-
ForStatement(node, state) {
|
|
1173
|
-
state.write("for(");
|
|
1174
|
-
if (node.init != null) {
|
|
1175
|
-
const init = node.init;
|
|
1176
|
-
if (init.type[0] === "V") {
|
|
1177
|
-
this.VariableDeclaration(init, state);
|
|
1178
|
-
} else {
|
|
1179
|
-
this[init.type](init, state);
|
|
1180
|
-
state.write(";");
|
|
1181
|
-
}
|
|
1182
|
-
} else {
|
|
1183
|
-
state.write(";");
|
|
1184
|
-
}
|
|
1185
|
-
if (node.test) {
|
|
1186
|
-
this[node.test.type](node.test, state);
|
|
1187
|
-
}
|
|
1188
|
-
state.write(";");
|
|
1189
|
-
if (node.update) {
|
|
1190
|
-
this[node.update.type](node.update, state);
|
|
1191
|
-
}
|
|
1192
|
-
state.write(")");
|
|
1193
|
-
this[node.body.type](node.body, state);
|
|
1194
|
-
},
|
|
1195
|
-
IfStatement(node, state) {
|
|
1196
|
-
state.write("if(");
|
|
1197
|
-
this[node.test.type](node.test, state);
|
|
1198
|
-
state.write(")");
|
|
1199
|
-
this[node.consequent.type](node.consequent, state);
|
|
1200
|
-
if (node.alternate != null) {
|
|
1201
|
-
if (node.consequent.type === "BlockStatement") {
|
|
1202
|
-
state.write("else");
|
|
1203
|
-
} else {
|
|
1204
|
-
state.write(" else");
|
|
1205
|
-
}
|
|
1206
|
-
if (node.alternate.type === "BlockStatement") {
|
|
1207
|
-
this[node.alternate.type](node.alternate, state);
|
|
1208
|
-
} else if (node.alternate.type === "IfStatement") {
|
|
1209
|
-
state.write(" ");
|
|
1210
|
-
this[node.alternate.type](node.alternate, state);
|
|
1211
|
-
} else {
|
|
1212
|
-
state.write(" ");
|
|
1213
|
-
this[node.alternate.type](node.alternate, state);
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
},
|
|
1217
|
-
VariableDeclaration(node, state) {
|
|
1218
|
-
state.write(node.kind + " ");
|
|
1219
|
-
const declarations = node.declarations;
|
|
1220
|
-
const length = declarations.length;
|
|
1221
|
-
for (let i = 0; i < length; i++) {
|
|
1222
|
-
this.VariableDeclarator(declarations[i], state);
|
|
1223
|
-
if (i + 1 < length) {
|
|
1224
|
-
state.write(",");
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
state.write(";");
|
|
1228
|
-
},
|
|
1229
|
-
VariableDeclarator(node, state) {
|
|
1230
|
-
this[node.id.type](node.id, state);
|
|
1231
|
-
if (node.init != null) {
|
|
1232
|
-
state.write("=");
|
|
1233
|
-
this[node.init.type](node.init, state);
|
|
1234
|
-
}
|
|
1235
|
-
},
|
|
1236
|
-
ReturnStatement(node, state) {
|
|
1237
|
-
state.write("return");
|
|
1238
|
-
if (node.argument) {
|
|
1239
|
-
state.write(" ");
|
|
1240
|
-
this[node.argument.type](node.argument, state);
|
|
1241
|
-
}
|
|
1242
|
-
state.write(";");
|
|
1243
|
-
}
|
|
1244
|
-
});
|
|
1245
|
-
function generateCompactJs(ast) {
|
|
1246
|
-
return (0, import_astring.generate)(ast, {
|
|
1247
|
-
generator: compactGenerator,
|
|
1248
|
-
indent: "",
|
|
1249
|
-
lineEnd: ""
|
|
1250
|
-
});
|
|
1251
|
-
}
|
|
7
|
+
var _chunk6N6S6WTQcjs = require('../chunk-6N6S6WTQ.cjs');
|
|
1252
8
|
|
|
1253
|
-
// src/runtime/integrity-guard.ts
|
|
1254
|
-
var FNV_OFFSET_BASIS = 2166136261;
|
|
1255
|
-
var FNV_PRIME = 16777619;
|
|
1256
|
-
function computeIntegrityHash(source, seed = 0) {
|
|
1257
|
-
let hash = (FNV_OFFSET_BASIS ^ seed >>> 0) >>> 0;
|
|
1258
|
-
for (let i = 0; i < source.length; i++) {
|
|
1259
|
-
hash ^= source.charCodeAt(i);
|
|
1260
|
-
hash = Math.imul(hash, FNV_PRIME) >>> 0;
|
|
1261
|
-
}
|
|
1262
|
-
return hash >>> 0;
|
|
1263
|
-
}
|
|
1264
9
|
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
return derivePolymorphicIdent(seed, "shield");
|
|
1268
|
-
}
|
|
1269
|
-
function deriveWindowKeySymbol(seed) {
|
|
1270
|
-
return derivePolymorphicIdent(seed, "windowKey");
|
|
1271
|
-
}
|
|
1272
|
-
function createDeterrentSnippet(config) {
|
|
1273
|
-
const seed = config.seed >>> 0;
|
|
1274
|
-
const deterrentMode = config.deterrentMode ?? "passive";
|
|
1275
|
-
const detectHeadless = config.detectHeadless ?? false;
|
|
1276
|
-
const fnName = deriveIntegrityFnName(seed);
|
|
1277
|
-
const sym = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1278
|
-
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=function(){return 0;};" : "";
|
|
1279
|
-
const symLit = JSON.stringify(sym);
|
|
1280
|
-
const headlessDecl = detectHeadless ? ",n=w.navigator||0" : "";
|
|
1281
|
-
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)" : "";
|
|
1282
|
-
return `(function ${fnName}(w){var G=typeof globalThis!=='undefined'?globalThis:w;if(w){var O=Object,P=O.getOwnPropertyDescriptor,GP=O.getPrototypeOf,T=function(o,k){try{while(o){var r=P&&P(o,k);if(r&&(r.set||!r.writable))return 1;o=GP?GP(o):0;}}catch(e){return 1;}},S=function(o,k,v){try{o[k]=v;}catch(e){}},s=Function.prototype.toString${headlessDecl},src='',t=0;try{src=s.call(${fnName});if('prototype' in s||s.name!=='toString'||s.length!==0||s.call(s).indexOf('[native code]')<0||/\\n/.test(src)${headlessCond})t=1;}catch(e){t=1;}try{s.call(0);t=1;}catch(e){}if(T(w,${symLit})||T(G,${symLit})||T(G,'__unpeek_tampered')||T(w,'__unpeek_tampered')||T(String.prototype,'_u'))t=1;for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var d=h&0xffff;if(t){var pd=(d^(((h>>>16)^0x5a5b)||1))&0xffff;if(!T(G,${symLit}))S(G,${symLit},pd);if(!T(w,${symLit}))S(w,${symLit},pd);S(G,'__unpeek_delta',pd);S(w,'__unpeek_delta',pd);try{String.prototype._u=14;}catch(e){}var ns=((w.__unpeek_seed||${seed})^1)>>>0;S(G,'__unpeek_seed',ns);S(w,'__unpeek_seed',ns);S(G,'__unpeek_tampered',!0);S(w,'__unpeek_tampered',!0);try{${consoleSilence}if(w.dispatchEvent)w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}else{S(G,${symLit},d);S(w,${symLit},d);}}})(typeof window!=='undefined'?window:(typeof self!=='undefined'?self:0));`;
|
|
1283
|
-
}
|
|
10
|
+
var _chunkR6EBIR3Tcjs = require('../chunk-R6EBIR3T.cjs');
|
|
11
|
+
require('../chunk-4TDLLEEU.cjs');
|
|
1284
12
|
|
|
1285
|
-
// src/runtime/index.ts
|
|
1286
|
-
function generateRuntimeShield(config) {
|
|
1287
|
-
const seed = config.seed >>> 0;
|
|
1288
|
-
const windowKeySymbol = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1289
|
-
const integrityCheckFnName = deriveIntegrityFnName(seed);
|
|
1290
|
-
const preambleCode = createDeterrentSnippet({
|
|
1291
|
-
...config,
|
|
1292
|
-
windowKeySymbol
|
|
1293
|
-
});
|
|
1294
|
-
const fnStart = preambleCode.indexOf("function");
|
|
1295
|
-
const endMarker = preambleCode.lastIndexOf("})(");
|
|
1296
|
-
const fnEnd = endMarker !== -1 ? endMarker + 1 : preambleCode.lastIndexOf("(") - 1;
|
|
1297
|
-
const fnDecl = preambleCode.slice(fnStart, fnEnd);
|
|
1298
|
-
const computedHash = computeIntegrityHash(fnDecl, 0);
|
|
1299
|
-
const expectedHash = config.expectedIntegrityHash !== void 0 ? config.expectedIntegrityHash >>> 0 : computedHash;
|
|
1300
|
-
const expectedDelta = config.expectedDelta !== void 0 ? config.expectedDelta & 65535 : computedHash >>> 0 & 65535;
|
|
1301
|
-
return {
|
|
1302
|
-
preambleCode,
|
|
1303
|
-
integrityCheckFnName,
|
|
1304
|
-
expectedHash,
|
|
1305
|
-
windowKeySymbol,
|
|
1306
|
-
expectedDelta
|
|
1307
|
-
};
|
|
1308
|
-
}
|
|
1309
13
|
|
|
1310
|
-
// src/ast/salted-vault.ts
|
|
1311
|
-
var acorn3 = __toESM(require("acorn"), 1);
|
|
1312
|
-
var walk2 = __toESM(require("acorn-walk"), 1);
|
|
1313
14
|
|
|
1314
|
-
// src/ast/wasm-vault.ts
|
|
1315
|
-
var acorn2 = __toESM(require("acorn"), 1);
|
|
1316
|
-
function encodeSignedLeb128(value) {
|
|
1317
|
-
const bytes = [];
|
|
1318
|
-
let val = value | 0;
|
|
1319
|
-
let more = true;
|
|
1320
|
-
while (more) {
|
|
1321
|
-
let byte = val & 127;
|
|
1322
|
-
val >>= 7;
|
|
1323
|
-
if (val === 0 && (byte & 64) === 0 || val === -1 && (byte & 64) !== 0) {
|
|
1324
|
-
more = false;
|
|
1325
|
-
} else {
|
|
1326
|
-
byte |= 128;
|
|
1327
|
-
}
|
|
1328
|
-
bytes.push(byte);
|
|
1329
|
-
}
|
|
1330
|
-
return bytes;
|
|
1331
|
-
}
|
|
1332
|
-
function encodeUnsignedLeb128(value) {
|
|
1333
|
-
const bytes = [];
|
|
1334
|
-
let val = value >>> 0;
|
|
1335
|
-
do {
|
|
1336
|
-
let byte = val & 127;
|
|
1337
|
-
val >>>= 7;
|
|
1338
|
-
if (val !== 0) {
|
|
1339
|
-
byte |= 128;
|
|
1340
|
-
}
|
|
1341
|
-
bytes.push(byte);
|
|
1342
|
-
} while (val !== 0);
|
|
1343
|
-
return bytes;
|
|
1344
|
-
}
|
|
1345
|
-
function rotl32(value, bits) {
|
|
1346
|
-
return value << bits | value >>> 32 - bits | 0;
|
|
1347
|
-
}
|
|
1348
|
-
function writeI32LE(value) {
|
|
1349
|
-
const v = value | 0;
|
|
1350
|
-
return [v & 255, v >>> 8 & 255, v >>> 16 & 255, v >>> 24 & 255];
|
|
1351
|
-
}
|
|
1352
|
-
function deriveKdfParams(seed) {
|
|
1353
|
-
const sVal = seed | 0;
|
|
1354
|
-
const c1 = computeFnv1aHash("wasm-c1", seed) ^ 2246822507 | 1;
|
|
1355
|
-
const c2 = computeFnv1aHash("wasm-c2", seed) ^ 3266489909 | 1;
|
|
1356
|
-
const k0 = computeFnv1aHash("wasm-k0", seed) | 0;
|
|
1357
|
-
const r1 = (seed >>> 0) % 19 + 7;
|
|
1358
|
-
const r2 = (seed >>> 5) % 17 + 5;
|
|
1359
|
-
return { sVal, c1, c2, k0, r1, r2 };
|
|
1360
|
-
}
|
|
1361
|
-
function generateWasmKdfBinary(seed) {
|
|
1362
|
-
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
1363
|
-
const memBase = (seed >>> 0 & 127) * 4;
|
|
1364
|
-
const r0 = computeFnv1aHash("wasm-r0", seed) | 0;
|
|
1365
|
-
const rotAmt = (seed >>> 0) % 27 + 3;
|
|
1366
|
-
const kMul = computeFnv1aHash("wasm-kmul", seed) | 1;
|
|
1367
|
-
const kA = kMul >>> 16 & 65535;
|
|
1368
|
-
const kB = kMul & 65535;
|
|
1369
|
-
const memMask = computeFnv1aHash("wasm-mem", seed) & 1023 | 1;
|
|
1370
|
-
const memA = memBase ^ memMask;
|
|
1371
|
-
const w0 = r0;
|
|
1372
|
-
const w1 = sVal ^ rotl32(r0, rotAmt) ^ Math.imul(r0 | 1, kMul) | 0;
|
|
1373
|
-
const w2 = c1 ^ (w0 + w1 | 0) | 0;
|
|
1374
|
-
const w3 = c2 - Math.imul(w1 | 1, w2 | 1) | 0;
|
|
1375
|
-
const w4 = k0 ^ rotl32(w2, 11) ^ w3 | 0;
|
|
1376
|
-
const instructions = [
|
|
1377
|
-
65,
|
|
1378
|
-
...encodeSignedLeb128(memA),
|
|
1379
|
-
// i32.const memA
|
|
1380
|
-
65,
|
|
1381
|
-
...encodeSignedLeb128(memMask),
|
|
1382
|
-
// i32.const memMask
|
|
1383
|
-
115,
|
|
1384
|
-
// i32.xor
|
|
1385
|
-
34,
|
|
1386
|
-
3,
|
|
1387
|
-
// local.tee 3 (ptr)
|
|
1388
|
-
40,
|
|
1389
|
-
2,
|
|
1390
|
-
0,
|
|
1391
|
-
// i32.load align=2 offset=0
|
|
1392
|
-
33,
|
|
1393
|
-
4,
|
|
1394
|
-
// local.set 4 (w0)
|
|
1395
|
-
32,
|
|
1396
|
-
3,
|
|
1397
|
-
// local.get 3
|
|
1398
|
-
40,
|
|
1399
|
-
2,
|
|
1400
|
-
4,
|
|
1401
|
-
// i32.load align=2 offset=4
|
|
1402
|
-
33,
|
|
1403
|
-
5,
|
|
1404
|
-
// local.set 5 (w1)
|
|
1405
|
-
32,
|
|
1406
|
-
3,
|
|
1407
|
-
// local.get 3
|
|
1408
|
-
40,
|
|
1409
|
-
2,
|
|
1410
|
-
8,
|
|
1411
|
-
// i32.load align=2 offset=8
|
|
1412
|
-
33,
|
|
1413
|
-
6,
|
|
1414
|
-
// local.set 6 (w2)
|
|
1415
|
-
32,
|
|
1416
|
-
3,
|
|
1417
|
-
// local.get 3
|
|
1418
|
-
40,
|
|
1419
|
-
2,
|
|
1420
|
-
12,
|
|
1421
|
-
// i32.load align=2 offset=12
|
|
1422
|
-
33,
|
|
1423
|
-
7,
|
|
1424
|
-
// local.set 7 (w3)
|
|
1425
|
-
// Reconstruct sVal -> local 8
|
|
1426
|
-
32,
|
|
1427
|
-
5,
|
|
1428
|
-
// local.get 5 (w1)
|
|
1429
|
-
32,
|
|
1430
|
-
4,
|
|
1431
|
-
// local.get 4 (w0)
|
|
1432
|
-
65,
|
|
1433
|
-
...encodeSignedLeb128(rotAmt),
|
|
1434
|
-
// i32.const rotAmt
|
|
1435
|
-
119,
|
|
1436
|
-
// i32.rotl
|
|
1437
|
-
115,
|
|
1438
|
-
// i32.xor
|
|
1439
|
-
32,
|
|
1440
|
-
4,
|
|
1441
|
-
// local.get 4 (w0)
|
|
1442
|
-
65,
|
|
1443
|
-
1,
|
|
1444
|
-
// i32.const 1
|
|
1445
|
-
114,
|
|
1446
|
-
// i32.or
|
|
1447
|
-
65,
|
|
1448
|
-
...encodeSignedLeb128(kA),
|
|
1449
|
-
// i32.const kA
|
|
1450
|
-
65,
|
|
1451
|
-
16,
|
|
1452
|
-
// i32.const 16
|
|
1453
|
-
116,
|
|
1454
|
-
// i32.shl
|
|
1455
|
-
65,
|
|
1456
|
-
...encodeSignedLeb128(kB),
|
|
1457
|
-
// i32.const kB
|
|
1458
|
-
114,
|
|
1459
|
-
// i32.or
|
|
1460
|
-
108,
|
|
1461
|
-
// i32.mul
|
|
1462
|
-
115,
|
|
1463
|
-
// i32.xor
|
|
1464
|
-
33,
|
|
1465
|
-
8,
|
|
1466
|
-
// local.set 8 (sVal)
|
|
1467
|
-
// Reconstruct c1 -> local 9
|
|
1468
|
-
32,
|
|
1469
|
-
6,
|
|
1470
|
-
// local.get 6 (w2)
|
|
1471
|
-
32,
|
|
1472
|
-
4,
|
|
1473
|
-
// local.get 4 (w0)
|
|
1474
|
-
32,
|
|
1475
|
-
5,
|
|
1476
|
-
// local.get 5 (w1)
|
|
1477
|
-
106,
|
|
1478
|
-
// i32.add
|
|
1479
|
-
115,
|
|
1480
|
-
// i32.xor
|
|
1481
|
-
33,
|
|
1482
|
-
9,
|
|
1483
|
-
// local.set 9 (c1)
|
|
1484
|
-
// Reconstruct k0 -> local 10
|
|
1485
|
-
32,
|
|
1486
|
-
3,
|
|
1487
|
-
// local.get 3 (ptr)
|
|
1488
|
-
40,
|
|
1489
|
-
2,
|
|
1490
|
-
16,
|
|
1491
|
-
// i32.load align=2 offset=16 (w4)
|
|
1492
|
-
32,
|
|
1493
|
-
6,
|
|
1494
|
-
// local.get 6 (w2)
|
|
1495
|
-
65,
|
|
1496
|
-
11,
|
|
1497
|
-
// i32.const 11
|
|
1498
|
-
119,
|
|
1499
|
-
// i32.rotl
|
|
1500
|
-
115,
|
|
1501
|
-
// i32.xor
|
|
1502
|
-
32,
|
|
1503
|
-
7,
|
|
1504
|
-
// local.get 7 (w3)
|
|
1505
|
-
115,
|
|
1506
|
-
// i32.xor
|
|
1507
|
-
33,
|
|
1508
|
-
10,
|
|
1509
|
-
// local.set 10 (k0)
|
|
1510
|
-
// x = f ^ sVal ^ k0
|
|
1511
|
-
32,
|
|
1512
|
-
0,
|
|
1513
|
-
// local.get 0 (fnId)
|
|
1514
|
-
32,
|
|
1515
|
-
8,
|
|
1516
|
-
// local.get 8 (sVal)
|
|
1517
|
-
115,
|
|
1518
|
-
// i32.xor
|
|
1519
|
-
32,
|
|
1520
|
-
10,
|
|
1521
|
-
// local.get 10 (k0)
|
|
1522
|
-
115,
|
|
1523
|
-
// i32.xor
|
|
1524
|
-
34,
|
|
1525
|
-
11,
|
|
1526
|
-
// local.tee 11 (x)
|
|
1527
|
-
// x ^= x >>> 16
|
|
1528
|
-
32,
|
|
1529
|
-
11,
|
|
1530
|
-
// local.get 11
|
|
1531
|
-
65,
|
|
1532
|
-
16,
|
|
1533
|
-
// i32.const 16
|
|
1534
|
-
118,
|
|
1535
|
-
// i32.shr_u
|
|
1536
|
-
115,
|
|
1537
|
-
// i32.xor
|
|
1538
|
-
// x = imul(x, c1)
|
|
1539
|
-
32,
|
|
1540
|
-
9,
|
|
1541
|
-
// local.get 9 (c1)
|
|
1542
|
-
108,
|
|
1543
|
-
// i32.mul
|
|
1544
|
-
// x = rotl(x ^ s, r1)
|
|
1545
|
-
32,
|
|
1546
|
-
1,
|
|
1547
|
-
// local.get 1 (callSiteSalt)
|
|
1548
|
-
115,
|
|
1549
|
-
// i32.xor
|
|
1550
|
-
65,
|
|
1551
|
-
...encodeSignedLeb128(r1),
|
|
1552
|
-
// i32.const r1
|
|
1553
|
-
119,
|
|
1554
|
-
// i32.rotl
|
|
1555
|
-
// x = imul(x ^ h ^ sVal, c2)
|
|
1556
|
-
32,
|
|
1557
|
-
2,
|
|
1558
|
-
// local.get 2 (shieldHash)
|
|
1559
|
-
115,
|
|
1560
|
-
// i32.xor
|
|
1561
|
-
32,
|
|
1562
|
-
8,
|
|
1563
|
-
// local.get 8 (sVal)
|
|
1564
|
-
115,
|
|
1565
|
-
// i32.xor
|
|
1566
|
-
32,
|
|
1567
|
-
7,
|
|
1568
|
-
// local.get 7 (w3)
|
|
1569
|
-
32,
|
|
1570
|
-
5,
|
|
1571
|
-
// local.get 5 (w1)
|
|
1572
|
-
65,
|
|
1573
|
-
1,
|
|
1574
|
-
// i32.const 1
|
|
1575
|
-
114,
|
|
1576
|
-
// i32.or
|
|
1577
|
-
32,
|
|
1578
|
-
6,
|
|
1579
|
-
// local.get 6 (w2)
|
|
1580
|
-
65,
|
|
1581
|
-
1,
|
|
1582
|
-
// i32.const 1
|
|
1583
|
-
114,
|
|
1584
|
-
// i32.or
|
|
1585
|
-
108,
|
|
1586
|
-
// i32.mul
|
|
1587
|
-
106,
|
|
1588
|
-
// i32.add (c2)
|
|
1589
|
-
108,
|
|
1590
|
-
// i32.mul
|
|
1591
|
-
34,
|
|
1592
|
-
11,
|
|
1593
|
-
// local.tee 11 (x)
|
|
1594
|
-
// x ^= x >>> 15
|
|
1595
|
-
32,
|
|
1596
|
-
11,
|
|
1597
|
-
// local.get 11
|
|
1598
|
-
65,
|
|
1599
|
-
15,
|
|
1600
|
-
// i32.const 15
|
|
1601
|
-
118,
|
|
1602
|
-
// i32.shr_u
|
|
1603
|
-
115,
|
|
1604
|
-
// i32.xor
|
|
1605
|
-
// x = (x + rotl(s ^ k0, r2))
|
|
1606
|
-
32,
|
|
1607
|
-
1,
|
|
1608
|
-
// local.get 1 (callSiteSalt)
|
|
1609
|
-
32,
|
|
1610
|
-
10,
|
|
1611
|
-
// local.get 10 (k0)
|
|
1612
|
-
115,
|
|
1613
|
-
// i32.xor
|
|
1614
|
-
65,
|
|
1615
|
-
...encodeSignedLeb128(r2),
|
|
1616
|
-
// i32.const r2
|
|
1617
|
-
119,
|
|
1618
|
-
// i32.rotl
|
|
1619
|
-
106,
|
|
1620
|
-
// i32.add
|
|
1621
|
-
// x = imul(x, c1)
|
|
1622
|
-
32,
|
|
1623
|
-
9,
|
|
1624
|
-
// local.get 9 (c1)
|
|
1625
|
-
108,
|
|
1626
|
-
// i32.mul
|
|
1627
|
-
34,
|
|
1628
|
-
11,
|
|
1629
|
-
// local.tee 11 (x)
|
|
1630
|
-
// x ^= x >>> 16
|
|
1631
|
-
32,
|
|
1632
|
-
11,
|
|
1633
|
-
// local.get 11
|
|
1634
|
-
65,
|
|
1635
|
-
16,
|
|
1636
|
-
// i32.const 16
|
|
1637
|
-
118,
|
|
1638
|
-
// i32.shr_u
|
|
1639
|
-
115,
|
|
1640
|
-
// i32.xor
|
|
1641
|
-
11
|
|
1642
|
-
// end
|
|
1643
|
-
];
|
|
1644
|
-
const funcBody = [1, 9, 127, ...instructions];
|
|
1645
|
-
const funcBodyWithLen = [...encodeUnsignedLeb128(funcBody.length), ...funcBody];
|
|
1646
|
-
const codeSectionPayload = [1, ...funcBodyWithLen];
|
|
1647
|
-
const codeSection = [
|
|
1648
|
-
10,
|
|
1649
|
-
...encodeUnsignedLeb128(codeSectionPayload.length),
|
|
1650
|
-
...codeSectionPayload
|
|
1651
|
-
];
|
|
1652
|
-
const typePayload = [
|
|
1653
|
-
1,
|
|
1654
|
-
// 1 type
|
|
1655
|
-
96,
|
|
1656
|
-
// func
|
|
1657
|
-
3,
|
|
1658
|
-
127,
|
|
1659
|
-
127,
|
|
1660
|
-
127,
|
|
1661
|
-
// 3 params of type i32
|
|
1662
|
-
1,
|
|
1663
|
-
127
|
|
1664
|
-
// 1 result of type i32
|
|
1665
|
-
];
|
|
1666
|
-
const typeSection = [
|
|
1667
|
-
1,
|
|
1668
|
-
...encodeUnsignedLeb128(typePayload.length),
|
|
1669
|
-
...typePayload
|
|
1670
|
-
];
|
|
1671
|
-
const funcPayload = [
|
|
1672
|
-
1,
|
|
1673
|
-
// 1 function
|
|
1674
|
-
0
|
|
1675
|
-
// type index 0
|
|
1676
|
-
];
|
|
1677
|
-
const funcSection = [
|
|
1678
|
-
3,
|
|
1679
|
-
...encodeUnsignedLeb128(funcPayload.length),
|
|
1680
|
-
...funcPayload
|
|
1681
|
-
];
|
|
1682
|
-
const memSection = [5, 3, 1, 0, 1];
|
|
1683
|
-
const exportName = [3, 107, 100, 102];
|
|
1684
|
-
const exportPayload = [
|
|
1685
|
-
1,
|
|
1686
|
-
// 1 export
|
|
1687
|
-
...exportName,
|
|
1688
|
-
0,
|
|
1689
|
-
// function export
|
|
1690
|
-
0
|
|
1691
|
-
// function index 0
|
|
1692
|
-
];
|
|
1693
|
-
const exportSection = [
|
|
1694
|
-
7,
|
|
1695
|
-
...encodeUnsignedLeb128(exportPayload.length),
|
|
1696
|
-
...exportPayload
|
|
1697
|
-
];
|
|
1698
|
-
const dataWords = [
|
|
1699
|
-
...writeI32LE(w0),
|
|
1700
|
-
...writeI32LE(w1),
|
|
1701
|
-
...writeI32LE(w2),
|
|
1702
|
-
...writeI32LE(w3),
|
|
1703
|
-
...writeI32LE(w4)
|
|
1704
|
-
];
|
|
1705
|
-
const dataPayload = [
|
|
1706
|
-
1,
|
|
1707
|
-
// 1 active segment
|
|
1708
|
-
0,
|
|
1709
|
-
// memory index 0
|
|
1710
|
-
65,
|
|
1711
|
-
...encodeSignedLeb128(memBase),
|
|
1712
|
-
11,
|
|
1713
|
-
// i32.const memBase; end
|
|
1714
|
-
...encodeUnsignedLeb128(dataWords.length),
|
|
1715
|
-
...dataWords
|
|
1716
|
-
];
|
|
1717
|
-
const dataSection = [
|
|
1718
|
-
11,
|
|
1719
|
-
...encodeUnsignedLeb128(dataPayload.length),
|
|
1720
|
-
...dataPayload
|
|
1721
|
-
];
|
|
1722
|
-
const header = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
1723
|
-
return new Uint8Array([
|
|
1724
|
-
...header,
|
|
1725
|
-
...typeSection,
|
|
1726
|
-
...funcSection,
|
|
1727
|
-
...memSection,
|
|
1728
|
-
...exportSection,
|
|
1729
|
-
...codeSection,
|
|
1730
|
-
...dataSection
|
|
1731
|
-
]);
|
|
1732
|
-
}
|
|
1733
|
-
function fallbackKdf(fnId, callSiteSalt, shieldHash, seed) {
|
|
1734
|
-
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
1735
|
-
let x = fnId ^ sVal ^ k0 | 0;
|
|
1736
|
-
x = x ^ x >>> 16 | 0;
|
|
1737
|
-
x = Math.imul(x, c1);
|
|
1738
|
-
x = rotl32(x ^ callSiteSalt | 0, r1);
|
|
1739
|
-
x = Math.imul(x ^ shieldHash ^ sVal | 0, c2);
|
|
1740
|
-
x = x ^ x >>> 15 | 0;
|
|
1741
|
-
x = x + rotl32(callSiteSalt ^ k0 | 0, r2) | 0;
|
|
1742
|
-
x = Math.imul(x, c1);
|
|
1743
|
-
x = x ^ x >>> 16 | 0;
|
|
1744
|
-
return x | 0;
|
|
1745
|
-
}
|
|
1746
|
-
function isWasmVaultAlreadyInjected(ast) {
|
|
1747
|
-
if (!ast || !Array.isArray(ast.body)) return false;
|
|
1748
|
-
return ast.body.some((stmt) => {
|
|
1749
|
-
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1750
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
1751
|
-
)) {
|
|
1752
|
-
return true;
|
|
1753
|
-
}
|
|
1754
|
-
return false;
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
function injectWasmVault(ast, seed = 2654435769) {
|
|
1758
|
-
const suffix = computeFnv1aHash(`wasm:${seed}`, seed).toString(36);
|
|
1759
|
-
const kdfFnName = `_wKdf${suffix}`;
|
|
1760
|
-
const wasmVarName = `_wb${suffix}`;
|
|
1761
|
-
if (isWasmVaultAlreadyInjected(ast)) {
|
|
1762
|
-
const existing = ast.body.find(
|
|
1763
|
-
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1764
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
1765
|
-
)
|
|
1766
|
-
);
|
|
1767
|
-
const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
|
|
1768
|
-
return {
|
|
1769
|
-
kdfFnName: id,
|
|
1770
|
-
wasmBytes: generateWasmKdfBinary(seed),
|
|
1771
|
-
wasmVarName
|
|
1772
|
-
};
|
|
1773
|
-
}
|
|
1774
|
-
const wasmBytes = generateWasmKdfBinary(seed);
|
|
1775
|
-
const byteArrayLiteral = Array.from(wasmBytes).join(",");
|
|
1776
|
-
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
1777
|
-
const targets = [c1, c2, sVal, k0, r1, r2];
|
|
1778
|
-
const aArr = [];
|
|
1779
|
-
const bArr = [];
|
|
1780
|
-
const mArr = [];
|
|
1781
|
-
for (let i = 0; i < targets.length; i++) {
|
|
1782
|
-
const aVal = computeFnv1aHash(`mba-a:${i}`, seed) | 0;
|
|
1783
|
-
const mVal = computeFnv1aHash(`mba-m:${i}`, seed) | 0;
|
|
1784
|
-
const bVal = (targets[i] ^ mVal) - aVal | 0;
|
|
1785
|
-
aArr.push(aVal);
|
|
1786
|
-
bArr.push(bVal);
|
|
1787
|
-
mArr.push(mVal);
|
|
1788
|
-
}
|
|
1789
|
-
const strKey = seed & 127 ^ 61 | 0;
|
|
1790
|
-
const mChars = [105 ^ strKey, 109 ^ strKey, 117 ^ strKey, 108 ^ strKey].join(",");
|
|
1791
|
-
const helperSnippet = `var ${kdfFnName};
|
|
1792
|
-
try {
|
|
1793
|
-
var ${wasmVarName} = new Uint8Array([${byteArrayLiteral}]);
|
|
1794
|
-
var _wm${suffix} = new WebAssembly.Module(${wasmVarName});
|
|
1795
|
-
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix});
|
|
1796
|
-
${kdfFnName} = _wi${suffix}.exports.kdf;
|
|
1797
|
-
} catch (e) {
|
|
1798
|
-
${kdfFnName} = (function() {
|
|
1799
|
-
var _z = +!String;
|
|
1800
|
-
var _a = [${aArr.join(",")}];
|
|
1801
|
-
var _b = [${bArr.join(",")}];
|
|
1802
|
-
var _m0 = [${mArr.join(",")}];
|
|
1803
|
-
var _k = [];
|
|
1804
|
-
for (var _j = 0; _j < ${targets.length}; _j++) {
|
|
1805
|
-
var _u = _a[_j] | _z, _v = _b[_j];
|
|
1806
|
-
var _t = ((_u | _v) + (_u & _v)) | 0;
|
|
1807
|
-
_k[_j] = ((_t + _m0[_j]) - ((_t & _m0[_j]) << 1)) | 0;
|
|
1808
|
-
}
|
|
1809
|
-
var _p = '';
|
|
1810
|
-
var _c = [${mChars}];
|
|
1811
|
-
for (var _i = 0; _i < _c.length; _i++) {
|
|
1812
|
-
_p += String.fromCharCode(_c[_i] ^ ${strKey});
|
|
1813
|
-
}
|
|
1814
|
-
var _m = Math[_p];
|
|
1815
|
-
return function(f, s, h) {
|
|
1816
|
-
var _x = (f ^ _k[2] ^ _k[3]) | 0;
|
|
1817
|
-
_x = (_x ^ (_x >>> 16)) | 0;
|
|
1818
|
-
_x = _m(_x, _k[0]);
|
|
1819
|
-
var _t0 = _x ^ s, _r1 = _k[4];
|
|
1820
|
-
_x = (_t0 << _r1) | (_t0 >>> (32 - _r1));
|
|
1821
|
-
_x = _m(_x ^ h ^ _k[2], _k[1]);
|
|
1822
|
-
_x = (_x ^ (_x >>> 15)) | 0;
|
|
1823
|
-
var _u0 = s ^ _k[3], _r2 = _k[5];
|
|
1824
|
-
_x = (_x + ((_u0 << _r2) | (_u0 >>> (32 - _r2)))) | 0;
|
|
1825
|
-
_x = _m(_x, _k[0]);
|
|
1826
|
-
return (_x ^ (_x >>> 16)) | 0;
|
|
1827
|
-
};
|
|
1828
|
-
})();
|
|
1829
|
-
}`;
|
|
1830
|
-
const parsedHelper = acorn2.parse(helperSnippet, {
|
|
1831
|
-
ecmaVersion: "latest",
|
|
1832
|
-
sourceType: "script"
|
|
1833
|
-
});
|
|
1834
|
-
let insertIdx = 0;
|
|
1835
|
-
while (insertIdx < ast.body.length) {
|
|
1836
|
-
const stmt = ast.body[insertIdx];
|
|
1837
|
-
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim()));
|
|
1838
|
-
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
1839
|
-
insertIdx++;
|
|
1840
|
-
} else {
|
|
1841
|
-
break;
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
ast.body.splice(insertIdx, 0, ...parsedHelper.body);
|
|
1845
|
-
return {
|
|
1846
|
-
kdfFnName,
|
|
1847
|
-
wasmBytes,
|
|
1848
|
-
wasmVarName
|
|
1849
|
-
};
|
|
1850
|
-
}
|
|
1851
15
|
|
|
1852
|
-
// src/ast/salted-vault.ts
|
|
1853
|
-
function computeCallSiteSalt(seed, idx) {
|
|
1854
|
-
return ((Math.imul((seed ^ idx) >>> 0, 2654435761) ^ Math.imul(idx + 1 >>> 0, 73244475)) & 31) >>> 0;
|
|
1855
|
-
}
|
|
1856
|
-
function createSaltedDecryptorFnAst(seed, pChars, expectedDelta, windowKeySymbol, safeAlpha = SAFE_ALPHA, shieldCoupled = true, browserOnly = false) {
|
|
1857
|
-
const propAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(windowKeySymbol) ? `.${windowKeySymbol}` : `[${JSON.stringify(windowKeySymbol)}]`;
|
|
1858
|
-
let fBody;
|
|
1859
|
-
if (!shieldCoupled) {
|
|
1860
|
-
fBody = `var m=[],c=Function.prototype.toString.call(f);for(var h=0x811c9dc5,j=0;j<c.length;j++)h=Math.imul(h^c.charCodeAt(j),0x01000193)>>>0;var q=(h^(""._u||a._u||0))>>>0,A="${safeAlpha}",P="${pChars}";return function(i,s){if(i in m)return m[i];var p=a[i],o="";if(p)for(var t=q^s^Math.imul(i+1,0x01000193),j=0;j<p.length;j++){t=Math.imul(t^j+1,0x01000193)^0x811c9dc5;var c=p[j],k=A.indexOf(c);o+=k<0?c:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];}return m[i]=o;};`;
|
|
1861
|
-
} else if (browserOnly) {
|
|
1862
|
-
fBody = `var m=[],c=Function.prototype.toString.call(f);for(var h=0x811c9dc5,j=0;j<c.length;j++)h=Math.imul(h^c.charCodeAt(j),0x01000193)>>>0;var q,A="${safeAlpha}",P="${pChars}";return function(i,s){if(q===void 0){var w=typeof window<"u"?window:typeof self<"u"?self:0,G=typeof globalThis<"u"?globalThis:w||this,d=G&&G${propAccess}!=null?G${propAccess}:w&&w${propAccess}!=null?w${propAccess}:w?-1:0;q=(h^(""._u||a._u||0)^d)>>>0;}if(i in m)return m[i];var p=a[i],o="";if(p)for(var t=q^s^Math.imul(i+1,0x01000193),j=0;j<p.length;j++){t=Math.imul(t^j+1,0x01000193)^0x811c9dc5;var c=p[j],k=A.indexOf(c);o+=k<0?c:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];}return m[i]=o;};`;
|
|
1863
|
-
} else {
|
|
1864
|
-
const maskA = computeFnv1aHash("delta-a", seed) & 65535 | 1;
|
|
1865
|
-
const maskB = (expectedDelta & 65535 ^ maskA) & 65535;
|
|
1866
|
-
fBody = `var m=[],c=Function.prototype.toString.call(f);for(var h=0x811c9dc5,j=0;j<c.length;j++)h=Math.imul(h^c.charCodeAt(j),0x01000193)>>>0;var q,A="${safeAlpha}",P="${pChars}";return function(i,s){if(q===void 0){var w=typeof window<"u"?window:typeof self<"u"?self:0,G=typeof globalThis<"u"?globalThis:w||this,d=G&&G${propAccess}!=null?G${propAccess}:w&&w${propAccess}!=null?w${propAccess}:w?-1:(${maskA}^${maskB});q=(h^(""._u||a._u||0)^d)>>>0;}if(i in m)return m[i];var p=a[i],o="";if(p)for(var t=q^s^Math.imul(i+1,0x01000193),j=0;j<p.length;j++){t=Math.imul(t^j+1,0x01000193)^0x811c9dc5;var c=p[j],k=A.indexOf(c);o+=k<0?c:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];}return m[i]=o;};`;
|
|
1867
|
-
}
|
|
1868
|
-
return acorn3.parse(`(function f(a){${fBody}})`, {
|
|
1869
|
-
ecmaVersion: "latest",
|
|
1870
|
-
sourceType: "script"
|
|
1871
|
-
}).body[0].expression;
|
|
1872
|
-
}
|
|
1873
|
-
function createSaltedVaultHelperAst(decryptFnName, encryptedPayloads, fnAst) {
|
|
1874
|
-
return {
|
|
1875
|
-
type: "VariableDeclaration",
|
|
1876
|
-
kind: "var",
|
|
1877
|
-
declarations: [
|
|
1878
|
-
{
|
|
1879
|
-
type: "VariableDeclarator",
|
|
1880
|
-
id: { type: "Identifier", name: decryptFnName },
|
|
1881
|
-
init: {
|
|
1882
|
-
type: "CallExpression",
|
|
1883
|
-
callee: fnAst,
|
|
1884
|
-
arguments: [
|
|
1885
|
-
{
|
|
1886
|
-
type: "ArrayExpression",
|
|
1887
|
-
elements: encryptedPayloads.map((str) => ({
|
|
1888
|
-
type: "Literal",
|
|
1889
|
-
value: str,
|
|
1890
|
-
raw: JSON.stringify(str)
|
|
1891
|
-
}))
|
|
1892
|
-
}
|
|
1893
|
-
],
|
|
1894
|
-
optional: false
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
]
|
|
1898
|
-
};
|
|
1899
|
-
}
|
|
1900
|
-
function encodeSaltedString(str, k) {
|
|
1901
|
-
let out = "";
|
|
1902
|
-
let rk = k | 0;
|
|
1903
|
-
for (let j = 0; j < str.length; j++) {
|
|
1904
|
-
rk = Math.imul(rk ^ j + 1, 73244475) + 2654435769 | 0;
|
|
1905
|
-
const code = str.charCodeAt(j);
|
|
1906
|
-
const mask = rk >>> 16 & 127 | 1;
|
|
1907
|
-
out += String.fromCharCode(code ^ mask);
|
|
1908
|
-
}
|
|
1909
|
-
return out;
|
|
1910
|
-
}
|
|
1911
|
-
function isAstAlreadySalted(ast) {
|
|
1912
|
-
if (!ast || !Array.isArray(ast.body)) return false;
|
|
1913
|
-
return ast.body.some((stmt) => {
|
|
1914
|
-
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1915
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uP")
|
|
1916
|
-
)) {
|
|
1917
|
-
return true;
|
|
1918
|
-
}
|
|
1919
|
-
return false;
|
|
1920
|
-
});
|
|
1921
|
-
}
|
|
1922
|
-
function replaceNodeInParent(parent, oldNode, newNode) {
|
|
1923
|
-
if (!parent) return false;
|
|
1924
|
-
for (const key of Object.keys(parent)) {
|
|
1925
|
-
const val = parent[key];
|
|
1926
|
-
if (val === oldNode) {
|
|
1927
|
-
parent[key] = newNode;
|
|
1928
|
-
return true;
|
|
1929
|
-
}
|
|
1930
|
-
if (Array.isArray(val)) {
|
|
1931
|
-
const idx = val.indexOf(oldNode);
|
|
1932
|
-
if (idx !== -1) {
|
|
1933
|
-
val[idx] = newNode;
|
|
1934
|
-
return true;
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
return false;
|
|
1939
|
-
}
|
|
1940
|
-
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, config, windowKeySymbol, expectedDelta, deterrentMode, shieldCoupled = true, detectHeadless = false) {
|
|
1941
|
-
if (isAstAlreadySalted(ast)) {
|
|
1942
|
-
return {
|
|
1943
|
-
encryptedStringsCount: 0,
|
|
1944
|
-
integrityToken: computeFnv1aHash("already-salted", seed),
|
|
1945
|
-
vaultVarName: "",
|
|
1946
|
-
decryptFnName: ""
|
|
1947
|
-
};
|
|
1948
|
-
}
|
|
1949
|
-
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
1950
|
-
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
1951
|
-
if (config?.vault?.customDirectives) {
|
|
1952
|
-
for (const dir of config.vault.customDirectives) {
|
|
1953
|
-
activeDirectives.add(dir);
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
|
|
1957
|
-
const targetsToReplace = [];
|
|
1958
|
-
const encryptedPayloads = [];
|
|
1959
|
-
walk2.ancestor(ast, {
|
|
1960
|
-
Literal(node, ancestors) {
|
|
1961
|
-
if (typeof node.value !== "string") return;
|
|
1962
|
-
if (node.value.length < minLen) return;
|
|
1963
|
-
if (activeDirectives.has(node.value)) return;
|
|
1964
|
-
const parent = ancestors[ancestors.length - 2];
|
|
1965
|
-
if (!parent) return;
|
|
1966
|
-
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(node.value))) {
|
|
1967
|
-
return;
|
|
1968
|
-
}
|
|
1969
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1970
|
-
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
1971
|
-
return;
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") && parent.source === node) {
|
|
1975
|
-
return;
|
|
1976
|
-
}
|
|
1977
|
-
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
1978
|
-
return;
|
|
1979
|
-
}
|
|
1980
|
-
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
1981
|
-
return;
|
|
1982
|
-
}
|
|
1983
|
-
if (hotExemptNodes) {
|
|
1984
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
1985
|
-
if (hotExemptNodes.has(ancestors[i])) {
|
|
1986
|
-
return;
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
if (isReservedProp(node.value, customReserved)) return;
|
|
1991
|
-
if (isTailwindNoise(node.value)) return;
|
|
1992
|
-
if (isSvgPathString(node.value, parent)) return;
|
|
1993
|
-
const callSiteIdx = targetsToReplace.length;
|
|
1994
|
-
const localSalt = computeFnv1aHash(`salt:${seed}:${callSiteIdx}`, seed) & 2147483647 | 1;
|
|
1995
|
-
targetsToReplace.push({
|
|
1996
|
-
node,
|
|
1997
|
-
parent,
|
|
1998
|
-
callSiteIdx,
|
|
1999
|
-
localSalt,
|
|
2000
|
-
rawString: node.value
|
|
2001
|
-
});
|
|
2002
|
-
}
|
|
2003
|
-
});
|
|
2004
|
-
if (targetsToReplace.length === 0) {
|
|
2005
|
-
return {
|
|
2006
|
-
encryptedStringsCount: 0,
|
|
2007
|
-
integrityToken: computeFnv1aHash("empty-salted", seed),
|
|
2008
|
-
vaultVarName: "",
|
|
2009
|
-
decryptFnName: ""
|
|
2010
|
-
};
|
|
2011
|
-
}
|
|
2012
|
-
const wasmResult = injectWasmVault(ast, seed);
|
|
2013
|
-
const kdfFnName = wasmResult.kdfFnName;
|
|
2014
|
-
const suffix = computeFnv1aHash(`salted:${seed}`, seed).toString(36);
|
|
2015
|
-
const vaultVarName = `_uP${suffix}`;
|
|
2016
|
-
const cacheVarName = `_uCache${suffix}`;
|
|
2017
|
-
const dCacheVarName = `_uDc${suffix}`;
|
|
2018
|
-
const decryptFnName = `_uD${suffix}`;
|
|
2019
|
-
const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
2020
|
-
const browserOnly = config?.target === "browser";
|
|
2021
|
-
let expDelta = expectedDelta;
|
|
2022
|
-
if (shieldCoupled && expDelta === void 0) {
|
|
2023
|
-
const shield = generateRuntimeShield({
|
|
2024
|
-
seed,
|
|
2025
|
-
windowKeySymbol: sym,
|
|
2026
|
-
deterrentMode: deterrentMode ?? "passive",
|
|
2027
|
-
detectHeadless
|
|
2028
|
-
});
|
|
2029
|
-
expDelta = shield.expectedDelta ?? 0;
|
|
2030
|
-
}
|
|
2031
|
-
const propAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(sym) ? `.${sym}` : `[${JSON.stringify(sym)}]`;
|
|
2032
|
-
let shieldDeltaExpr;
|
|
2033
|
-
if (!shieldCoupled) {
|
|
2034
|
-
shieldDeltaExpr = `var dv=(G&&G.__unpeek_delta!=null?G.__unpeek_delta:0)|0;${dCacheVarName}=((h|0)^dv)|0;`;
|
|
2035
|
-
} else {
|
|
2036
|
-
const fallbackExpr = browserOnly ? "0" : `(${computeFnv1aHash("salted-a", seed) & 65535 | 1}^${((expDelta ?? 0) & 65535 ^ (computeFnv1aHash("salted-a", seed) & 65535 | 1)) & 65535})`;
|
|
2037
|
-
shieldDeltaExpr = `var w=typeof window<"u"?window:typeof self<"u"?self:0;var sv=G&&G${propAccess}!=null?G${propAccess}:w&&w${propAccess}!=null?w${propAccess}:w?-1:${fallbackExpr};var dv=(G&&G.__unpeek_delta!=null?G.__unpeek_delta:w&&w.__unpeek_delta!=null?w.__unpeek_delta:0)|0;${dCacheVarName}=((h|0)^(sv|0)^dv)|0;`;
|
|
2038
|
-
}
|
|
2039
|
-
const helperFnSnippet = `function ${decryptFnName}(i,s){if(${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${shieldDeltaExpr}}var k=${kdfFnName}(i,s,${dCacheVarName});var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}return (${cacheVarName}[i]=o);}`;
|
|
2040
|
-
const parsedFn = acorn3.parse(helperFnSnippet, {
|
|
2041
|
-
ecmaVersion: "latest",
|
|
2042
|
-
sourceType: "script"
|
|
2043
|
-
});
|
|
2044
|
-
const fnDeclAst = parsedFn.body[0];
|
|
2045
|
-
const selfHash = computeFnv1aHash(generateCompactJs(fnDeclAst)) | 0;
|
|
2046
|
-
const buildD = shieldCoupled ? selfHash ^ (expDelta ?? 0) & 65535 | 0 : selfHash | 0;
|
|
2047
|
-
for (const target of targetsToReplace) {
|
|
2048
|
-
const k = fallbackKdf(target.callSiteIdx, target.localSalt, buildD, seed);
|
|
2049
|
-
encryptedPayloads.push(encodeSaltedString(target.rawString, k));
|
|
2050
|
-
const callExpr = {
|
|
2051
|
-
type: "CallExpression",
|
|
2052
|
-
callee: {
|
|
2053
|
-
type: "Identifier",
|
|
2054
|
-
name: decryptFnName
|
|
2055
|
-
},
|
|
2056
|
-
arguments: [
|
|
2057
|
-
{
|
|
2058
|
-
type: "Literal",
|
|
2059
|
-
value: target.callSiteIdx,
|
|
2060
|
-
raw: String(target.callSiteIdx)
|
|
2061
|
-
},
|
|
2062
|
-
{
|
|
2063
|
-
type: "Literal",
|
|
2064
|
-
value: target.localSalt,
|
|
2065
|
-
raw: String(target.localSalt)
|
|
2066
|
-
}
|
|
2067
|
-
],
|
|
2068
|
-
optional: false
|
|
2069
|
-
};
|
|
2070
|
-
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
2071
|
-
}
|
|
2072
|
-
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
2073
|
-
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
2074
|
-
const varsSnippet = `var ${vaultVarName}=${serializedTable};var ${cacheVarName}=[];var ${dCacheVarName};`;
|
|
2075
|
-
const parsedVars = acorn3.parse(varsSnippet, {
|
|
2076
|
-
ecmaVersion: "latest",
|
|
2077
|
-
sourceType: "script"
|
|
2078
|
-
});
|
|
2079
|
-
let insertIdx = 0;
|
|
2080
|
-
while (insertIdx < ast.body.length) {
|
|
2081
|
-
const stmt = ast.body[insertIdx];
|
|
2082
|
-
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
|
|
2083
|
-
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
2084
|
-
insertIdx++;
|
|
2085
|
-
} else {
|
|
2086
|
-
break;
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
ast.body.splice(insertIdx, 0, ...parsedVars.body, fnDeclAst);
|
|
2090
|
-
return {
|
|
2091
|
-
encryptedStringsCount: targetsToReplace.length,
|
|
2092
|
-
integrityToken,
|
|
2093
|
-
vaultVarName,
|
|
2094
|
-
decryptFnName
|
|
2095
|
-
};
|
|
2096
|
-
}
|
|
2097
16
|
|
|
2098
|
-
|
|
2099
|
-
var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
|
|
2100
|
-
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
2101
|
-
"use strict",
|
|
2102
|
-
"use client",
|
|
2103
|
-
"use server",
|
|
2104
|
-
"use asm",
|
|
2105
|
-
"use cache",
|
|
2106
|
-
"use worklet",
|
|
2107
|
-
"use worker",
|
|
2108
|
-
"use memo"
|
|
2109
|
-
]);
|
|
2110
|
-
var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
|
|
2111
|
-
"id",
|
|
2112
|
-
"type",
|
|
2113
|
-
"key",
|
|
2114
|
-
"ref",
|
|
2115
|
-
"className",
|
|
2116
|
-
"style",
|
|
2117
|
-
"name",
|
|
2118
|
-
"value",
|
|
2119
|
-
"children",
|
|
2120
|
-
"src",
|
|
2121
|
-
"href",
|
|
2122
|
-
"alt",
|
|
2123
|
-
"role",
|
|
2124
|
-
"tabIndex",
|
|
2125
|
-
"class",
|
|
2126
|
-
"part",
|
|
2127
|
-
"slot",
|
|
2128
|
-
"is",
|
|
2129
|
-
"innerHTML",
|
|
2130
|
-
"disabled",
|
|
2131
|
-
"title"
|
|
2132
|
-
]);
|
|
2133
|
-
var STANDARD_PROP_PREFIX_RE = /^(?:data-|aria-|on[A-Z]|v-|bind:)/;
|
|
2134
|
-
function isReservedProp(propName, customReserved) {
|
|
2135
|
-
if (STANDARD_PROP_KEYS.has(propName)) return true;
|
|
2136
|
-
if (customReserved && customReserved.has(propName)) return true;
|
|
2137
|
-
if (STANDARD_PROP_PREFIX_RE.test(propName)) return true;
|
|
2138
|
-
return false;
|
|
2139
|
-
}
|
|
2140
|
-
var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
2141
|
-
"ForStatement",
|
|
2142
|
-
"ForInStatement",
|
|
2143
|
-
"ForOfStatement",
|
|
2144
|
-
"WhileStatement",
|
|
2145
|
-
"DoWhileStatement"
|
|
2146
|
-
]);
|
|
2147
|
-
function isReactDomSpecialProp(val, node, parent, customReserved) {
|
|
2148
|
-
if (isReservedProp(val, customReserved)) return true;
|
|
2149
|
-
if (!parent) return false;
|
|
2150
|
-
if (parent.type === "Property") {
|
|
2151
|
-
if (parent.key === node && !parent.computed) {
|
|
2152
|
-
return true;
|
|
2153
|
-
}
|
|
2154
|
-
const keyName = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
|
|
2155
|
-
if (keyName && isReservedProp(keyName, customReserved)) {
|
|
2156
|
-
return true;
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
return false;
|
|
2160
|
-
}
|
|
2161
|
-
var TAILWIND_TOKEN_RE = /^(?:flex|grid|block|inline|hidden|relative|absolute|fixed|w-|h-|min-|max-|p[xytrbl]?-|m[xytrbl]?-|space-[xy]-|text-|font-|bg-|border|rounded|shadow|ring|outline|transition|duration|opacity|cursor|pointer-events|select-|items-|justify-|gap-|overflow-|z-|inset-|top-|left-|right-|bottom-|hover:|focus:|focus-visible:|disabled:|dark:|data-\[|aria-|\[&_)/;
|
|
2162
|
-
var TAILWIND_VARIANT_PREFIX_RE = /^(?:[a-zA-Z0-9_@-]+:)+/;
|
|
2163
|
-
function stripTailwindVariants(token) {
|
|
2164
|
-
return token.replace(TAILWIND_VARIANT_PREFIX_RE, "");
|
|
2165
|
-
}
|
|
2166
|
-
function isTailwindNoise(val) {
|
|
2167
|
-
const trimmed = val.trim();
|
|
2168
|
-
if (!trimmed) return false;
|
|
2169
|
-
const isMatch = (t) => {
|
|
2170
|
-
const stripped = stripTailwindVariants(t);
|
|
2171
|
-
return TAILWIND_TOKEN_RE.test(stripped) || stripped.startsWith("btn") || stripped.startsWith("p-") || stripped.startsWith("m-");
|
|
2172
|
-
};
|
|
2173
|
-
if (trimmed.includes(" ")) {
|
|
2174
|
-
const tokens = trimmed.split(/\s+/);
|
|
2175
|
-
let twHits = 0;
|
|
2176
|
-
for (const t of tokens) {
|
|
2177
|
-
if (isMatch(t)) {
|
|
2178
|
-
twHits++;
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
if (twHits / tokens.length >= 0.5) return true;
|
|
2182
|
-
} else {
|
|
2183
|
-
if (isMatch(trimmed)) return true;
|
|
2184
|
-
}
|
|
2185
|
-
return false;
|
|
2186
|
-
}
|
|
2187
|
-
function isParentSvgPathProperty(parent) {
|
|
2188
|
-
if (!parent) return false;
|
|
2189
|
-
if (parent.type === "Property") {
|
|
2190
|
-
const keyName = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
|
|
2191
|
-
if (keyName === "d" || keyName === "path") return true;
|
|
2192
|
-
}
|
|
2193
|
-
if (parent.type === "JSXAttribute") {
|
|
2194
|
-
const attrName = parent.name?.name;
|
|
2195
|
-
if (attrName === "d" || attrName === "path") return true;
|
|
2196
|
-
}
|
|
2197
|
-
return false;
|
|
2198
|
-
}
|
|
2199
|
-
function isSvgPathString(val, parent) {
|
|
2200
|
-
if (typeof val !== "string" || val.length < 4) return false;
|
|
2201
|
-
const trimmed = val.trim();
|
|
2202
|
-
if (!/^[Mm]\s*[-+]?(?:\d*\.\d+|\d+)/.test(trimmed)) {
|
|
2203
|
-
return false;
|
|
2204
|
-
}
|
|
2205
|
-
if (parent && isParentSvgPathProperty(parent)) {
|
|
2206
|
-
return true;
|
|
2207
|
-
}
|
|
2208
|
-
return /[zZ]$/.test(trimmed) || /[Mm]\s*[-+]?\d.*[a-df-zA-DF-Z]\s*[-+]?\d/.test(trimmed) || /^[Mm]\s*[-+]?\d+(?:\.\d+)?[\s,]+-?\d+(?:\.\d+)?(?:\s+[a-zA-Z][-+]?\d+.*)?$/.test(
|
|
2209
|
-
trimmed
|
|
2210
|
-
);
|
|
2211
|
-
}
|
|
2212
|
-
var DEFAULT_SEMANTIC_ANCHOR_RE = /(?:\bapi\/|\bcheckout\b|\badmin\b|\bauth\b|\btoken\b|\bcredential\b|\bsecret\b|\bpassword\b|\bbearer\b)/i;
|
|
2213
|
-
function isUiClassName(val, parent) {
|
|
2214
|
-
if (parent) {
|
|
2215
|
-
if (parent.type === "Property") {
|
|
2216
|
-
const k = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
|
|
2217
|
-
if (k === "className" || k === "class" || k === "classList") return true;
|
|
2218
|
-
}
|
|
2219
|
-
if (parent.type === "JSXAttribute") {
|
|
2220
|
-
const name = parent.name?.name;
|
|
2221
|
-
if (name === "className" || name === "class") return true;
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
if (isTailwindNoise(val)) return true;
|
|
2225
|
-
if (/^[a-z0-9_-]+(?:\s+[a-z0-9_-]+)+$/i.test(val.trim())) {
|
|
2226
|
-
return true;
|
|
2227
|
-
}
|
|
2228
|
-
return false;
|
|
2229
|
-
}
|
|
2230
|
-
function isAdversaryDecoy(val, seed) {
|
|
2231
|
-
if (val.startsWith("/api/v2/auth/") || val === "superadmin_token" || val === "elevate" || val === "_verifyMasterToken" || val === "mock_jwt_bypass_signature" || val === "debug_supervisor_override" || val.startsWith("_decoy_") || val.startsWith("_auth_bypass_")) {
|
|
2232
|
-
return true;
|
|
2233
|
-
}
|
|
2234
|
-
const s = (seed >>> 0 & 65535).toString(36);
|
|
2235
|
-
if (val.includes(s) && (val.includes("auth") || val.includes("token") || val.includes("decoy") || val.includes("elevate"))) {
|
|
2236
|
-
return true;
|
|
2237
|
-
}
|
|
2238
|
-
return false;
|
|
2239
|
-
}
|
|
2240
|
-
function isEligibleHotLiteral(val, node, parent, ancestors, minLen, seed = 2654435769, customReserved, activeDirectives = DIRECTIVE_STRINGS, semanticAnchorPatterns, excludeUiClasses = true) {
|
|
2241
|
-
if (val.length < minLen || activeDirectives.has(val)) return false;
|
|
2242
|
-
if (isReactDomSpecialProp(val, node, parent, customReserved)) return false;
|
|
2243
|
-
if (isTailwindNoise(val)) return false;
|
|
2244
|
-
if (isSvgPathString(val, parent)) return false;
|
|
2245
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2246
|
-
if (LOOP_NODE_TYPES.has(ancestors[i].type)) {
|
|
2247
|
-
return false;
|
|
2248
|
-
}
|
|
2249
|
-
}
|
|
2250
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2251
|
-
if (ancestors[i]._unpeekSerialized) {
|
|
2252
|
-
return false;
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
|
-
if (val.startsWith("HOT_")) return false;
|
|
2256
|
-
let isSemanticAnchor = false;
|
|
2257
|
-
if (semanticAnchorPatterns && semanticAnchorPatterns.length > 0) {
|
|
2258
|
-
isSemanticAnchor = semanticAnchorPatterns.some((re) => re.test(val));
|
|
2259
|
-
} else {
|
|
2260
|
-
isSemanticAnchor = DEFAULT_SEMANTIC_ANCHOR_RE.test(val);
|
|
2261
|
-
}
|
|
2262
|
-
if (isSemanticAnchor && excludeUiClasses && isUiClassName(val, parent)) {
|
|
2263
|
-
isSemanticAnchor = false;
|
|
2264
|
-
}
|
|
2265
|
-
let isInsideRender = false;
|
|
2266
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2267
|
-
const a = ancestors[i];
|
|
2268
|
-
if (a.type === "FunctionDeclaration" || a.type === "FunctionExpression" || a.type === "ArrowFunctionExpression") {
|
|
2269
|
-
if (a.id?.name && /^[A-Z]/.test(a.id.name)) {
|
|
2270
|
-
isInsideRender = true;
|
|
2271
|
-
break;
|
|
2272
|
-
}
|
|
2273
|
-
if (a._unpeekIsComponent) {
|
|
2274
|
-
isInsideRender = true;
|
|
2275
|
-
break;
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
if (!isSemanticAnchor && !isInsideRender) return false;
|
|
2280
|
-
if (isAdversaryDecoy(val, seed)) {
|
|
2281
|
-
return false;
|
|
2282
|
-
}
|
|
2283
|
-
if (parent) {
|
|
2284
|
-
if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
|
|
2285
|
-
if (parent.source === node) return false;
|
|
2286
|
-
}
|
|
2287
|
-
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
2288
|
-
return false;
|
|
2289
|
-
}
|
|
2290
|
-
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
2291
|
-
return false;
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
return true;
|
|
2295
|
-
}
|
|
2296
|
-
var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|vec4f|gl_Position|uniform/;
|
|
2297
|
-
function shouldEncryptString(val, minLen, parent, activeDirectives = DIRECTIVE_STRINGS, customReserved) {
|
|
2298
|
-
if (val.length < minLen || activeDirectives.has(val)) return false;
|
|
2299
|
-
if (isReservedProp(val, customReserved)) return false;
|
|
2300
|
-
if (isSvgPathString(val, parent)) return false;
|
|
2301
|
-
if (isTailwindNoise(val)) return false;
|
|
2302
|
-
return true;
|
|
2303
|
-
}
|
|
2304
|
-
function computeFnv1aHash(input, seed = 2166136261) {
|
|
2305
|
-
let hash = seed >>> 0;
|
|
2306
|
-
for (let i = 0; i < input.length; i++) {
|
|
2307
|
-
hash ^= input.charCodeAt(i);
|
|
2308
|
-
hash = Math.imul(hash, 16777619) >>> 0;
|
|
2309
|
-
}
|
|
2310
|
-
return hash >>> 0;
|
|
2311
|
-
}
|
|
2312
|
-
function createPermutationTable(seed) {
|
|
2313
|
-
let s = (seed || 305419896) >>> 0;
|
|
2314
|
-
function xorshift() {
|
|
2315
|
-
s ^= s << 13;
|
|
2316
|
-
s ^= s >>> 17;
|
|
2317
|
-
s ^= s << 5;
|
|
2318
|
-
return s >>> 0;
|
|
2319
|
-
}
|
|
2320
|
-
const indices = [];
|
|
2321
|
-
for (let i = 0; i < 92; i++) indices.push(i);
|
|
2322
|
-
for (let i = 91; i > 0; i--) {
|
|
2323
|
-
const j = xorshift() % (i + 1);
|
|
2324
|
-
const tmp = indices[i];
|
|
2325
|
-
indices[i] = indices[j];
|
|
2326
|
-
indices[j] = tmp;
|
|
2327
|
-
}
|
|
2328
|
-
const B = new Array(92);
|
|
2329
|
-
for (let i = 0; i < 46; i++) {
|
|
2330
|
-
const a = indices[2 * i];
|
|
2331
|
-
const b = indices[2 * i + 1];
|
|
2332
|
-
B[a] = b;
|
|
2333
|
-
B[b] = a;
|
|
2334
|
-
}
|
|
2335
|
-
let P_CHARS = "";
|
|
2336
|
-
for (let i = 0; i < 92; i++) {
|
|
2337
|
-
P_CHARS += SAFE_ALPHA[B[i]];
|
|
2338
|
-
}
|
|
2339
|
-
return P_CHARS;
|
|
2340
|
-
}
|
|
2341
|
-
function encodeStringWithSeed(str, P_CHARS, expectedKey, salt = 0, idx = 0) {
|
|
2342
|
-
let out = "";
|
|
2343
|
-
let st = (expectedKey >>> 0 ^ salt >>> 0 ^ Math.imul(idx + 1, 16777619)) >>> 0;
|
|
2344
|
-
for (let j = 0; j < str.length; j++) {
|
|
2345
|
-
st = Math.imul(st ^ j + 1, 16777619) ^ 2166136261 | 0;
|
|
2346
|
-
const r1 = (st >>> 16) % 92;
|
|
2347
|
-
const r2 = (st & 65535) % 92;
|
|
2348
|
-
const c = str.charAt(j);
|
|
2349
|
-
const k = SAFE_ALPHA.indexOf(c);
|
|
2350
|
-
if (k < 0) {
|
|
2351
|
-
out += c;
|
|
2352
|
-
} else {
|
|
2353
|
-
const y = (k + r1) % 92;
|
|
2354
|
-
const z = SAFE_ALPHA.indexOf(P_CHARS.charAt(y));
|
|
2355
|
-
out += SAFE_ALPHA.charAt((z + r2) % 92);
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
return out;
|
|
2359
|
-
}
|
|
2360
|
-
function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
2361
|
-
const sSeed = seed >>> 0;
|
|
2362
|
-
const fnCode = `(function f(B){var c=Function.prototype.toString.call(f),h=0x811c9dc5;for(var i=0;i<c.length;i++)h=Math.imul(h^c.charCodeAt(i),0x01000193)>>>0;var S=h^${sSeed},b=B.map(function(s){var n=typeof atob=="function"?atob(s):typeof Buffer<"u"?Buffer.from(s,"base64").toString("binary"):"",u=new Uint8Array(n.length);for(var i=0;i<n.length;i++)u[i]=n.charCodeAt(i);return u;}),d=typeof TextDecoder<"u"?new TextDecoder():null;function x(u,i){for(var r=(S^Math.imul(i+1,0x9e3779b1))|0,j=0;j<u.length;j++){r=(Math.imul(r^(j+1),0x45d9f3b)+0x85ebca6b)|0;u[j]^=(r>>>16)&255;}}return function(i){var u=b[i];x(u,i);try{return d?d.decode(u):String.fromCharCode.apply(null,u);}finally{x(u,i);}};})`;
|
|
2363
|
-
const fnAst = acorn4.parse(fnCode, { ecmaVersion: "latest", sourceType: "script" }).body[0].expression;
|
|
2364
|
-
const buildH = computeIntegrityHash(generateCompactJs(fnAst), 0);
|
|
2365
|
-
const S = (buildH ^ sSeed) >>> 0;
|
|
2366
|
-
const b64List = [];
|
|
2367
|
-
for (let idx = 0; idx < shaderPayloads.length; idx++) {
|
|
2368
|
-
const str = shaderPayloads[idx];
|
|
2369
|
-
const buf = Buffer.from(str, "utf8");
|
|
2370
|
-
let r = S ^ Math.imul(idx + 1, 2654435761) | 0;
|
|
2371
|
-
for (let j = 0; j < buf.length; j++) {
|
|
2372
|
-
r = Math.imul(r ^ j + 1, 73244475) + 2246822507 | 0;
|
|
2373
|
-
buf[j] ^= r >>> 16 & 255;
|
|
2374
|
-
}
|
|
2375
|
-
b64List.push(buf.toString("base64"));
|
|
2376
|
-
}
|
|
2377
|
-
return createSaltedVaultHelperAst(shaderVarName, b64List, fnAst);
|
|
2378
|
-
}
|
|
2379
|
-
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode, config, shieldCoupled = true, detectHeadless = false) {
|
|
2380
|
-
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
2381
|
-
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
2382
|
-
if (config?.vault?.customDirectives) {
|
|
2383
|
-
for (const dir of config.vault.customDirectives) {
|
|
2384
|
-
activeDirectives.add(dir);
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
|
|
2388
|
-
const semanticPatterns = config?.vault?.semanticAnchors?.patterns;
|
|
2389
|
-
const excludeUi = config?.vault?.semanticAnchors?.excludeUiClasses !== false;
|
|
2390
|
-
const suffix = (seed >>> 0 & 65535).toString(36);
|
|
2391
|
-
const decryptFnName = `_uD${suffix}`;
|
|
2392
|
-
const cacheVarName = derivePolymorphicIdent(seed, "vault");
|
|
2393
|
-
const shaderVarName = derivePolymorphicIdent(seed, "shader");
|
|
2394
|
-
const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
2395
|
-
const browserOnly = config?.target === "browser";
|
|
2396
|
-
let expDelta = shieldCoupled ? expectedDelta : 0;
|
|
2397
|
-
if (shieldCoupled && expDelta === void 0) {
|
|
2398
|
-
const shield = generateRuntimeShield({
|
|
2399
|
-
seed,
|
|
2400
|
-
windowKeySymbol: sym,
|
|
2401
|
-
deterrentMode: deterrentMode ?? "passive",
|
|
2402
|
-
detectHeadless
|
|
2403
|
-
});
|
|
2404
|
-
expDelta = shield.expectedDelta ?? 0;
|
|
2405
|
-
}
|
|
2406
|
-
const alreadyVaulted = ast.body.some(
|
|
2407
|
-
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
2408
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && (d.id.name.startsWith("_uC") || d.id.name.startsWith("_uD") || d.id.name === decryptFnName || d.id.name === cacheVarName || d.init?.type === "CallExpression" && d.init.callee?.type === "FunctionExpression" && d.init.callee?.id?.name === "f" && d.init.arguments?.[0]?.type === "ArrayExpression")
|
|
2409
|
-
)
|
|
2410
|
-
);
|
|
2411
|
-
if (alreadyVaulted) {
|
|
2412
|
-
return {
|
|
2413
|
-
encryptedStringsCount: 0,
|
|
2414
|
-
integrityToken: computeFnv1aHash("already-vaulted", seed),
|
|
2415
|
-
shaderBuffersCount: 0
|
|
2416
|
-
};
|
|
2417
|
-
}
|
|
2418
|
-
const P_CHARS = createPermutationTable(seed);
|
|
2419
|
-
const fnAst = createSaltedDecryptorFnAst(
|
|
2420
|
-
seed,
|
|
2421
|
-
P_CHARS,
|
|
2422
|
-
expDelta ?? 0,
|
|
2423
|
-
sym,
|
|
2424
|
-
SAFE_ALPHA,
|
|
2425
|
-
shieldCoupled,
|
|
2426
|
-
browserOnly
|
|
2427
|
-
);
|
|
2428
|
-
const compactFnStr = generateCompactJs(fnAst);
|
|
2429
|
-
const buildH = computeIntegrityHash(compactFnStr, 0);
|
|
2430
|
-
const expectedKey = (buildH ^ 0 ^ (shieldCoupled ? (expDelta ?? 0) & 65535 : 0)) >>> 0;
|
|
2431
|
-
const stringToIndex = /* @__PURE__ */ new Map();
|
|
2432
|
-
const encryptedPayloads = [];
|
|
2433
|
-
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
2434
|
-
const shaderPayloads = [];
|
|
2435
|
-
const targetsToReplace = [];
|
|
2436
|
-
const hotTargetsToReplace = [];
|
|
2437
|
-
const customWalkBase = {
|
|
2438
|
-
...walk3.base,
|
|
2439
|
-
Property(node, st, c) {
|
|
2440
|
-
c(node.key, st);
|
|
2441
|
-
if (node.value) c(node.value, st);
|
|
2442
|
-
}
|
|
2443
|
-
};
|
|
2444
|
-
walk3.ancestor(
|
|
2445
|
-
ast,
|
|
2446
|
-
{
|
|
2447
|
-
Literal(node, _state, ancestors) {
|
|
2448
|
-
if (typeof node.value !== "string") return;
|
|
2449
|
-
const val = node.value;
|
|
2450
|
-
if (activeDirectives.has(val)) return;
|
|
2451
|
-
let isHotExempt = false;
|
|
2452
|
-
if (hotExemptNodes) {
|
|
2453
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2454
|
-
if (hotExemptNodes.has(ancestors[i])) {
|
|
2455
|
-
isHotExempt = true;
|
|
2456
|
-
break;
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
}
|
|
2460
|
-
const parent = ancestors[ancestors.length - 2];
|
|
2461
|
-
if (!parent) return;
|
|
2462
|
-
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
2463
|
-
return;
|
|
2464
|
-
}
|
|
2465
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2466
|
-
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
2467
|
-
return;
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
|
-
if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
|
|
2471
|
-
if (parent.source === node) return;
|
|
2472
|
-
}
|
|
2473
|
-
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
2474
|
-
return;
|
|
2475
|
-
}
|
|
2476
|
-
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
2477
|
-
return;
|
|
2478
|
-
}
|
|
2479
|
-
if (isHotExempt) {
|
|
2480
|
-
if (isEligibleHotLiteral(
|
|
2481
|
-
val,
|
|
2482
|
-
node,
|
|
2483
|
-
parent,
|
|
2484
|
-
ancestors,
|
|
2485
|
-
minLen,
|
|
2486
|
-
seed,
|
|
2487
|
-
customReserved,
|
|
2488
|
-
activeDirectives,
|
|
2489
|
-
semanticPatterns,
|
|
2490
|
-
excludeUi
|
|
2491
|
-
)) {
|
|
2492
|
-
hotTargetsToReplace.push({
|
|
2493
|
-
node,
|
|
2494
|
-
parent,
|
|
2495
|
-
val,
|
|
2496
|
-
idx: hotTargetsToReplace.length
|
|
2497
|
-
});
|
|
2498
|
-
}
|
|
2499
|
-
return;
|
|
2500
|
-
}
|
|
2501
|
-
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
2502
|
-
if (isReservedProp(val, customReserved)) {
|
|
2503
|
-
return;
|
|
2504
|
-
}
|
|
2505
|
-
}
|
|
2506
|
-
if (isReservedProp(val, customReserved)) return;
|
|
2507
|
-
if (isTailwindNoise(val)) return;
|
|
2508
|
-
if (isSvgPathString(val, parent)) return;
|
|
2509
|
-
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
2510
|
-
if (isShader) {
|
|
2511
|
-
let idx = shaderToIndex.get(val);
|
|
2512
|
-
if (idx === void 0) {
|
|
2513
|
-
idx = shaderPayloads.length;
|
|
2514
|
-
shaderToIndex.set(val, idx);
|
|
2515
|
-
shaderPayloads.push(val);
|
|
2516
|
-
}
|
|
2517
|
-
targetsToReplace.push({ type: "shader", node, parent, idx });
|
|
2518
|
-
} else {
|
|
2519
|
-
if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
|
|
2520
|
-
let idx = stringToIndex.get(val);
|
|
2521
|
-
if (idx === void 0) {
|
|
2522
|
-
idx = encryptedPayloads.length;
|
|
2523
|
-
stringToIndex.set(val, idx);
|
|
2524
|
-
const salt = computeCallSiteSalt(seed, idx);
|
|
2525
|
-
encryptedPayloads.push(
|
|
2526
|
-
encodeStringWithSeed(val, P_CHARS, expectedKey, salt, idx)
|
|
2527
|
-
);
|
|
2528
|
-
}
|
|
2529
|
-
targetsToReplace.push({ type: "string", node, parent, idx });
|
|
2530
|
-
}
|
|
2531
|
-
},
|
|
2532
|
-
TemplateLiteral(node, _state, ancestors) {
|
|
2533
|
-
if (!node.quasis || node.quasis.length !== 1) return;
|
|
2534
|
-
if (node.expressions && node.expressions.length !== 0) return;
|
|
2535
|
-
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
2536
|
-
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
2537
|
-
let isHotExempt = false;
|
|
2538
|
-
if (hotExemptNodes) {
|
|
2539
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2540
|
-
if (hotExemptNodes.has(ancestors[i])) {
|
|
2541
|
-
isHotExempt = true;
|
|
2542
|
-
break;
|
|
2543
|
-
}
|
|
2544
|
-
}
|
|
2545
|
-
}
|
|
2546
|
-
const parent = ancestors[ancestors.length - 2];
|
|
2547
|
-
if (!parent) return;
|
|
2548
|
-
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
2549
|
-
return;
|
|
2550
|
-
}
|
|
2551
|
-
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2552
|
-
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
2553
|
-
return;
|
|
2554
|
-
}
|
|
2555
|
-
}
|
|
2556
|
-
if (isHotExempt) {
|
|
2557
|
-
if (isEligibleHotLiteral(
|
|
2558
|
-
val,
|
|
2559
|
-
node,
|
|
2560
|
-
parent,
|
|
2561
|
-
ancestors,
|
|
2562
|
-
minLen,
|
|
2563
|
-
seed,
|
|
2564
|
-
customReserved,
|
|
2565
|
-
activeDirectives,
|
|
2566
|
-
semanticPatterns,
|
|
2567
|
-
excludeUi
|
|
2568
|
-
)) {
|
|
2569
|
-
hotTargetsToReplace.push({
|
|
2570
|
-
node,
|
|
2571
|
-
parent,
|
|
2572
|
-
val,
|
|
2573
|
-
idx: hotTargetsToReplace.length
|
|
2574
|
-
});
|
|
2575
|
-
}
|
|
2576
|
-
return;
|
|
2577
|
-
}
|
|
2578
|
-
if (isReservedProp(val, customReserved)) return;
|
|
2579
|
-
if (isTailwindNoise(val)) return;
|
|
2580
|
-
if (isSvgPathString(val, parent)) return;
|
|
2581
|
-
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
2582
|
-
if (isShader) {
|
|
2583
|
-
let idx = shaderToIndex.get(val);
|
|
2584
|
-
if (idx === void 0) {
|
|
2585
|
-
idx = shaderPayloads.length;
|
|
2586
|
-
shaderToIndex.set(val, idx);
|
|
2587
|
-
shaderPayloads.push(val);
|
|
2588
|
-
}
|
|
2589
|
-
targetsToReplace.push({ type: "shader", node, parent, idx });
|
|
2590
|
-
} else {
|
|
2591
|
-
if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
|
|
2592
|
-
let idx = stringToIndex.get(val);
|
|
2593
|
-
if (idx === void 0) {
|
|
2594
|
-
idx = encryptedPayloads.length;
|
|
2595
|
-
stringToIndex.set(val, idx);
|
|
2596
|
-
const salt = computeCallSiteSalt(seed, idx);
|
|
2597
|
-
encryptedPayloads.push(
|
|
2598
|
-
encodeStringWithSeed(val, P_CHARS, expectedKey, salt, idx)
|
|
2599
|
-
);
|
|
2600
|
-
}
|
|
2601
|
-
targetsToReplace.push({ type: "string", node, parent, idx });
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
},
|
|
2605
|
-
customWalkBase
|
|
2606
|
-
);
|
|
2607
|
-
if (targetsToReplace.length === 0 && hotTargetsToReplace.length === 0) {
|
|
2608
|
-
return {
|
|
2609
|
-
encryptedStringsCount: 0,
|
|
2610
|
-
integrityToken: computeFnv1aHash("empty", seed),
|
|
2611
|
-
shaderBuffersCount: 0
|
|
2612
|
-
};
|
|
2613
|
-
}
|
|
2614
|
-
for (const { node, parent, val, idx } of hotTargetsToReplace) {
|
|
2615
|
-
const key = idx % 3 + 1;
|
|
2616
|
-
let encodedStr = "";
|
|
2617
|
-
for (let i = 0; i < val.length; i++) {
|
|
2618
|
-
encodedStr += String.fromCharCode(val.charCodeAt(i) ^ key);
|
|
2619
|
-
}
|
|
2620
|
-
if (parent?.type === "Property" && parent.key === node) {
|
|
2621
|
-
parent.computed = true;
|
|
2622
|
-
}
|
|
2623
|
-
node.type = "CallExpression";
|
|
2624
|
-
node.callee = {
|
|
2625
|
-
type: "Identifier",
|
|
2626
|
-
name: "_hX"
|
|
2627
|
-
};
|
|
2628
|
-
node.arguments = [
|
|
2629
|
-
{
|
|
2630
|
-
type: "Literal",
|
|
2631
|
-
value: encodedStr,
|
|
2632
|
-
raw: JSON.stringify(encodedStr)
|
|
2633
|
-
},
|
|
2634
|
-
{
|
|
2635
|
-
type: "Literal",
|
|
2636
|
-
value: key,
|
|
2637
|
-
raw: String(key)
|
|
2638
|
-
}
|
|
2639
|
-
];
|
|
2640
|
-
node.optional = false;
|
|
2641
|
-
delete node.value;
|
|
2642
|
-
delete node.raw;
|
|
2643
|
-
delete node.quasis;
|
|
2644
|
-
delete node.expressions;
|
|
2645
|
-
}
|
|
2646
|
-
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
2647
|
-
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
2648
|
-
for (const { type, node, parent, idx } of targetsToReplace) {
|
|
2649
|
-
if (parent?.type === "Property" && parent.key === node) {
|
|
2650
|
-
parent.computed = true;
|
|
2651
|
-
}
|
|
2652
|
-
if (type === "shader") {
|
|
2653
|
-
node.type = "CallExpression";
|
|
2654
|
-
node.callee = {
|
|
2655
|
-
type: "Identifier",
|
|
2656
|
-
name: shaderVarName
|
|
2657
|
-
};
|
|
2658
|
-
node.arguments = [
|
|
2659
|
-
{
|
|
2660
|
-
type: "Literal",
|
|
2661
|
-
value: idx,
|
|
2662
|
-
raw: String(idx)
|
|
2663
|
-
}
|
|
2664
|
-
];
|
|
2665
|
-
node.optional = false;
|
|
2666
|
-
delete node.value;
|
|
2667
|
-
delete node.raw;
|
|
2668
|
-
delete node.quasis;
|
|
2669
|
-
delete node.expressions;
|
|
2670
|
-
} else {
|
|
2671
|
-
const salt = computeCallSiteSalt(seed, idx);
|
|
2672
|
-
node.type = "CallExpression";
|
|
2673
|
-
node.callee = {
|
|
2674
|
-
type: "Identifier",
|
|
2675
|
-
name: decryptFnName
|
|
2676
|
-
};
|
|
2677
|
-
node.arguments = [
|
|
2678
|
-
{
|
|
2679
|
-
type: "Literal",
|
|
2680
|
-
value: idx,
|
|
2681
|
-
raw: String(idx)
|
|
2682
|
-
},
|
|
2683
|
-
{
|
|
2684
|
-
type: "Literal",
|
|
2685
|
-
value: salt,
|
|
2686
|
-
raw: String(salt)
|
|
2687
|
-
}
|
|
2688
|
-
];
|
|
2689
|
-
node.optional = false;
|
|
2690
|
-
delete node.value;
|
|
2691
|
-
delete node.raw;
|
|
2692
|
-
delete node.quasis;
|
|
2693
|
-
delete node.expressions;
|
|
2694
|
-
}
|
|
2695
|
-
}
|
|
2696
|
-
let insertIdx = 0;
|
|
2697
|
-
while (insertIdx < ast.body.length) {
|
|
2698
|
-
const stmt = ast.body[insertIdx];
|
|
2699
|
-
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
|
|
2700
|
-
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
2701
|
-
insertIdx++;
|
|
2702
|
-
} else {
|
|
2703
|
-
break;
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2706
|
-
if (hotTargetsToReplace.length > 0) {
|
|
2707
|
-
const alreadyHasHx = ast.body.some(
|
|
2708
|
-
(stmt) => stmt.type === "FunctionDeclaration" && stmt.id?.name === "_hX"
|
|
2709
|
-
);
|
|
2710
|
-
if (!alreadyHasHx) {
|
|
2711
|
-
const hxAst = acorn4.parse(
|
|
2712
|
-
'function _hX(s,k){var o="";for(var i=0;i<s.length;i++)o+=String.fromCharCode(s.charCodeAt(i)^k);return o;}',
|
|
2713
|
-
{ ecmaVersion: "latest", sourceType: "script" }
|
|
2714
|
-
);
|
|
2715
|
-
ast.body.splice(insertIdx++, 0, hxAst.body[0]);
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2718
|
-
if (encryptedPayloads.length > 0) {
|
|
2719
|
-
const vaultHelperStmt = createSaltedVaultHelperAst(
|
|
2720
|
-
decryptFnName,
|
|
2721
|
-
encryptedPayloads,
|
|
2722
|
-
fnAst
|
|
2723
|
-
);
|
|
2724
|
-
ast.body.splice(insertIdx++, 0, vaultHelperStmt);
|
|
2725
|
-
}
|
|
2726
|
-
if (shaderPayloads.length > 0) {
|
|
2727
|
-
const shaderHelperStmt = createShaderVaultAst(
|
|
2728
|
-
shaderVarName,
|
|
2729
|
-
shaderPayloads,
|
|
2730
|
-
seed
|
|
2731
|
-
);
|
|
2732
|
-
ast.body.splice(insertIdx++, 0, shaderHelperStmt);
|
|
2733
|
-
}
|
|
2734
|
-
return {
|
|
2735
|
-
encryptedStringsCount: encryptedPayloads.length + hotTargetsToReplace.length,
|
|
2736
|
-
integrityToken,
|
|
2737
|
-
shaderBuffersCount: shaderPayloads.length
|
|
2738
|
-
};
|
|
2739
|
-
}
|
|
2740
|
-
|
|
2741
|
-
// src/ast/polymorphic-mangler.ts
|
|
2742
|
-
var walk4 = __toESM(require("acorn-walk"), 1);
|
|
2743
|
-
var RESERVED_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
2744
|
-
"arguments",
|
|
2745
|
-
"undefined",
|
|
2746
|
-
"NaN",
|
|
2747
|
-
"Infinity",
|
|
2748
|
-
"window",
|
|
2749
|
-
"document",
|
|
2750
|
-
"globalThis",
|
|
2751
|
-
"self",
|
|
2752
|
-
"console",
|
|
2753
|
-
"Math",
|
|
2754
|
-
"JSON",
|
|
2755
|
-
"Object",
|
|
2756
|
-
"Array",
|
|
2757
|
-
"String",
|
|
2758
|
-
"Number",
|
|
2759
|
-
"Boolean",
|
|
2760
|
-
"Symbol",
|
|
2761
|
-
"BigInt",
|
|
2762
|
-
"Promise",
|
|
2763
|
-
"Map",
|
|
2764
|
-
"Set",
|
|
2765
|
-
"WeakMap",
|
|
2766
|
-
"WeakSet",
|
|
2767
|
-
"Error",
|
|
2768
|
-
"TypeError",
|
|
2769
|
-
"RangeError",
|
|
2770
|
-
"SyntaxError",
|
|
2771
|
-
"RegExp",
|
|
2772
|
-
"Date",
|
|
2773
|
-
"Reflect",
|
|
2774
|
-
"Proxy",
|
|
2775
|
-
"Intl",
|
|
2776
|
-
"eval",
|
|
2777
|
-
"process",
|
|
2778
|
-
"Buffer",
|
|
2779
|
-
"require",
|
|
2780
|
-
"module",
|
|
2781
|
-
"exports",
|
|
2782
|
-
"React",
|
|
2783
|
-
"navigator",
|
|
2784
|
-
"crypto",
|
|
2785
|
-
"location",
|
|
2786
|
-
"history",
|
|
2787
|
-
"indexedDB",
|
|
2788
|
-
"fetch",
|
|
2789
|
-
"WebSocket",
|
|
2790
|
-
"Worker",
|
|
2791
|
-
"AudioContext",
|
|
2792
|
-
"performance"
|
|
2793
|
-
]);
|
|
2794
|
-
var JS_KEYWORDS = /* @__PURE__ */ new Set([
|
|
2795
|
-
"as",
|
|
2796
|
-
"await",
|
|
2797
|
-
"break",
|
|
2798
|
-
"case",
|
|
2799
|
-
"catch",
|
|
2800
|
-
"class",
|
|
2801
|
-
"const",
|
|
2802
|
-
"continue",
|
|
2803
|
-
"debugger",
|
|
2804
|
-
"default",
|
|
2805
|
-
"delete",
|
|
2806
|
-
"do",
|
|
2807
|
-
"else",
|
|
2808
|
-
"enum",
|
|
2809
|
-
"export",
|
|
2810
|
-
"extends",
|
|
2811
|
-
"false",
|
|
2812
|
-
"finally",
|
|
2813
|
-
"for",
|
|
2814
|
-
"function",
|
|
2815
|
-
"if",
|
|
2816
|
-
"implements",
|
|
2817
|
-
"import",
|
|
2818
|
-
"in",
|
|
2819
|
-
"instanceof",
|
|
2820
|
-
"interface",
|
|
2821
|
-
"let",
|
|
2822
|
-
"new",
|
|
2823
|
-
"null",
|
|
2824
|
-
"of",
|
|
2825
|
-
"package",
|
|
2826
|
-
"private",
|
|
2827
|
-
"protected",
|
|
2828
|
-
"public",
|
|
2829
|
-
"return",
|
|
2830
|
-
"static",
|
|
2831
|
-
"super",
|
|
2832
|
-
"switch",
|
|
2833
|
-
"this",
|
|
2834
|
-
"throw",
|
|
2835
|
-
"true",
|
|
2836
|
-
"try",
|
|
2837
|
-
"typeof",
|
|
2838
|
-
"var",
|
|
2839
|
-
"void",
|
|
2840
|
-
"while",
|
|
2841
|
-
"with",
|
|
2842
|
-
"yield"
|
|
2843
|
-
]);
|
|
2844
|
-
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
2845
|
-
"FunctionDeclaration",
|
|
2846
|
-
"FunctionExpression",
|
|
2847
|
-
"ArrowFunctionExpression"
|
|
2848
|
-
]);
|
|
2849
|
-
var LEXICAL_SCOPE_TYPES = /* @__PURE__ */ new Set([
|
|
2850
|
-
"Program",
|
|
2851
|
-
"FunctionDeclaration",
|
|
2852
|
-
"FunctionExpression",
|
|
2853
|
-
"ArrowFunctionExpression",
|
|
2854
|
-
"BlockStatement",
|
|
2855
|
-
"ForStatement",
|
|
2856
|
-
"ForInStatement",
|
|
2857
|
-
"ForOfStatement",
|
|
2858
|
-
"SwitchStatement",
|
|
2859
|
-
"CatchClause",
|
|
2860
|
-
"ClassDeclaration",
|
|
2861
|
-
"ClassExpression"
|
|
2862
|
-
]);
|
|
2863
|
-
function collectPatternTargets(pattern, out, shorthandProp) {
|
|
2864
|
-
if (!pattern) return;
|
|
2865
|
-
switch (pattern.type) {
|
|
2866
|
-
case "Identifier":
|
|
2867
|
-
out.push({ idNode: pattern, shorthandProp });
|
|
2868
|
-
break;
|
|
2869
|
-
case "AssignmentPattern":
|
|
2870
|
-
collectPatternTargets(pattern.left, out, shorthandProp);
|
|
2871
|
-
break;
|
|
2872
|
-
case "RestElement":
|
|
2873
|
-
collectPatternTargets(pattern.argument, out);
|
|
2874
|
-
break;
|
|
2875
|
-
case "ArrayPattern":
|
|
2876
|
-
for (const el of pattern.elements || []) {
|
|
2877
|
-
if (el) collectPatternTargets(el, out);
|
|
2878
|
-
}
|
|
2879
|
-
break;
|
|
2880
|
-
case "ObjectPattern":
|
|
2881
|
-
for (const prop of pattern.properties || []) {
|
|
2882
|
-
if (prop.type === "Property") {
|
|
2883
|
-
collectPatternTargets(
|
|
2884
|
-
prop.value,
|
|
2885
|
-
out,
|
|
2886
|
-
prop.shorthand ? prop : void 0
|
|
2887
|
-
);
|
|
2888
|
-
} else if (prop.type === "RestElement") {
|
|
2889
|
-
collectPatternTargets(prop.argument, out);
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
|
-
break;
|
|
2893
|
-
}
|
|
2894
|
-
}
|
|
2895
|
-
function isMangleableName(origName, reservedSet = RESERVED_IDENTIFIERS, manglerConfig) {
|
|
2896
|
-
const minLength = manglerConfig?.minLength ?? 3;
|
|
2897
|
-
return origName.length >= minLength && !reservedSet.has(origName) && !JS_KEYWORDS.has(origName) && !origName.startsWith("$") && !origName.startsWith("__") && !origName.startsWith("_u") && !origName.startsWith("_0x") && (!manglerConfig?.excludePrefixes || !manglerConfig.excludePrefixes.some((p) => origName.startsWith(p))) && (!manglerConfig?.excludePatterns || !manglerConfig.excludePatterns.some((re) => re.test(origName)));
|
|
2898
|
-
}
|
|
2899
|
-
function shuffleAlphabet(chars, seed) {
|
|
2900
|
-
const arr = chars.split("");
|
|
2901
|
-
let s = (seed || 324478056) >>> 0;
|
|
2902
|
-
for (let i = arr.length - 1; i > 0; i--) {
|
|
2903
|
-
s ^= s << 13;
|
|
2904
|
-
s ^= s >>> 17;
|
|
2905
|
-
s ^= s << 5;
|
|
2906
|
-
const j = (s >>> 0) % (i + 1);
|
|
2907
|
-
const tmp = arr[i];
|
|
2908
|
-
arr[i] = arr[j];
|
|
2909
|
-
arr[j] = tmp;
|
|
2910
|
-
}
|
|
2911
|
-
return arr;
|
|
2912
|
-
}
|
|
2913
|
-
function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes, config) {
|
|
2914
|
-
const activeReserved = new Set(RESERVED_IDENTIFIERS);
|
|
2915
|
-
if (config?.mangler?.reservedIdentifiers) {
|
|
2916
|
-
for (const id of config.mangler.reservedIdentifiers) {
|
|
2917
|
-
activeReserved.add(id);
|
|
2918
|
-
}
|
|
2919
|
-
}
|
|
2920
|
-
const manglerConfig = config?.mangler;
|
|
2921
|
-
const scopeRecords = /* @__PURE__ */ new Map();
|
|
2922
|
-
const barrierOrFreeIds = /* @__PURE__ */ new Set();
|
|
2923
|
-
const renamedTargetNodes = /* @__PURE__ */ new WeakSet();
|
|
2924
|
-
let counter = 0;
|
|
2925
|
-
function ensureScopeChain(ancestors) {
|
|
2926
|
-
let prevScope = null;
|
|
2927
|
-
for (let i = 0; i < ancestors.length; i++) {
|
|
2928
|
-
const node = ancestors[i];
|
|
2929
|
-
if (!LEXICAL_SCOPE_TYPES.has(node.type)) continue;
|
|
2930
|
-
let record = scopeRecords.get(node);
|
|
2931
|
-
if (!record) {
|
|
2932
|
-
const isFn = FUNCTION_TYPES.has(node.type);
|
|
2933
|
-
const depth = prevScope ? prevScope.depth + (isFn ? 1 : 0) : 0;
|
|
2934
|
-
record = {
|
|
2935
|
-
node,
|
|
2936
|
-
parent: prevScope,
|
|
2937
|
-
children: [],
|
|
2938
|
-
depth: Math.max(1, depth),
|
|
2939
|
-
bindings: /* @__PURE__ */ new Map(),
|
|
2940
|
-
usedNames: /* @__PURE__ */ new Set()
|
|
2941
|
-
};
|
|
2942
|
-
scopeRecords.set(node, record);
|
|
2943
|
-
if (prevScope) {
|
|
2944
|
-
prevScope.children.push(record);
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
prevScope = record;
|
|
2948
|
-
}
|
|
2949
|
-
return prevScope;
|
|
2950
|
-
}
|
|
2951
|
-
function findEnclosingFunctionNode(ancestors) {
|
|
2952
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
2953
|
-
if (FUNCTION_TYPES.has(ancestors[i].type)) {
|
|
2954
|
-
return ancestors[i];
|
|
2955
|
-
}
|
|
2956
|
-
}
|
|
2957
|
-
return null;
|
|
2958
|
-
}
|
|
2959
|
-
function findEnclosingLexicalNode(ancestors) {
|
|
2960
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
2961
|
-
if (LEXICAL_SCOPE_TYPES.has(ancestors[i].type)) {
|
|
2962
|
-
return ancestors[i];
|
|
2963
|
-
}
|
|
2964
|
-
}
|
|
2965
|
-
return ancestors[0];
|
|
2966
|
-
}
|
|
2967
|
-
function registerBindingTarget(scopeNode, target, shouldMangle, fnScope) {
|
|
2968
|
-
const scope = scopeRecords.get(scopeNode);
|
|
2969
|
-
if (!scope) return;
|
|
2970
|
-
const origName = target.idNode.name;
|
|
2971
|
-
let canMangle = shouldMangle && isMangleableName(origName, activeReserved, manglerConfig);
|
|
2972
|
-
if (canMangle && fnScope) {
|
|
2973
|
-
if (serializedFunctionNodes && serializedFunctionNodes.has(fnScope)) {
|
|
2974
|
-
canMangle = false;
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
renamedTargetNodes.add(target.idNode);
|
|
2978
|
-
let entry = scope.bindings.get(origName);
|
|
2979
|
-
if (!entry) {
|
|
2980
|
-
entry = {
|
|
2981
|
-
origName,
|
|
2982
|
-
shouldMangle: canMangle,
|
|
2983
|
-
targets: [target],
|
|
2984
|
-
mangledName: origName
|
|
2985
|
-
};
|
|
2986
|
-
scope.bindings.set(origName, entry);
|
|
2987
|
-
} else {
|
|
2988
|
-
if (!canMangle) {
|
|
2989
|
-
entry.shouldMangle = false;
|
|
2990
|
-
}
|
|
2991
|
-
entry.targets.push(target);
|
|
2992
|
-
}
|
|
2993
|
-
if (!entry.shouldMangle) {
|
|
2994
|
-
barrierOrFreeIds.add(origName);
|
|
2995
|
-
}
|
|
2996
|
-
}
|
|
2997
|
-
function registerBarrierName(scopeNode, origName) {
|
|
2998
|
-
barrierOrFreeIds.add(origName);
|
|
2999
|
-
const scope = scopeRecords.get(scopeNode);
|
|
3000
|
-
if (!scope) return;
|
|
3001
|
-
let entry = scope.bindings.get(origName);
|
|
3002
|
-
if (!entry) {
|
|
3003
|
-
entry = {
|
|
3004
|
-
origName,
|
|
3005
|
-
shouldMangle: false,
|
|
3006
|
-
targets: [],
|
|
3007
|
-
mangledName: origName
|
|
3008
|
-
};
|
|
3009
|
-
scope.bindings.set(origName, entry);
|
|
3010
|
-
} else {
|
|
3011
|
-
entry.shouldMangle = false;
|
|
3012
|
-
}
|
|
3013
|
-
}
|
|
3014
|
-
function registerFunctionParams(fnNode, ancestors) {
|
|
3015
|
-
ensureScopeChain(ancestors);
|
|
3016
|
-
for (const param of fnNode.params || []) {
|
|
3017
|
-
const targets = [];
|
|
3018
|
-
collectPatternTargets(param, targets);
|
|
3019
|
-
for (const target of targets) {
|
|
3020
|
-
registerBindingTarget(fnNode, target, true, fnNode);
|
|
3021
|
-
}
|
|
3022
|
-
}
|
|
3023
|
-
}
|
|
3024
|
-
ensureScopeChain([ast]);
|
|
3025
|
-
walk4.ancestor(ast, {
|
|
3026
|
-
BlockStatement(_node, _state, ancestors) {
|
|
3027
|
-
ensureScopeChain(ancestors);
|
|
3028
|
-
},
|
|
3029
|
-
ForStatement(_node, _state, ancestors) {
|
|
3030
|
-
ensureScopeChain(ancestors);
|
|
3031
|
-
},
|
|
3032
|
-
ForInStatement(_node, _state, ancestors) {
|
|
3033
|
-
ensureScopeChain(ancestors);
|
|
3034
|
-
},
|
|
3035
|
-
ForOfStatement(_node, _state, ancestors) {
|
|
3036
|
-
ensureScopeChain(ancestors);
|
|
3037
|
-
},
|
|
3038
|
-
SwitchStatement(_node, _state, ancestors) {
|
|
3039
|
-
ensureScopeChain(ancestors);
|
|
3040
|
-
},
|
|
3041
|
-
ImportSpecifier(node) {
|
|
3042
|
-
if (node.local?.name) barrierOrFreeIds.add(node.local.name);
|
|
3043
|
-
},
|
|
3044
|
-
ImportDefaultSpecifier(node) {
|
|
3045
|
-
if (node.local?.name) barrierOrFreeIds.add(node.local.name);
|
|
3046
|
-
},
|
|
3047
|
-
ImportNamespaceSpecifier(node) {
|
|
3048
|
-
if (node.local?.name) barrierOrFreeIds.add(node.local.name);
|
|
3049
|
-
},
|
|
3050
|
-
FunctionDeclaration(node, _state, ancestors) {
|
|
3051
|
-
registerFunctionParams(node, ancestors);
|
|
3052
|
-
if (node.id?.type === "Identifier") {
|
|
3053
|
-
const parentAncestors = ancestors.slice(0, -1);
|
|
3054
|
-
const lexNode = findEnclosingLexicalNode(parentAncestors);
|
|
3055
|
-
const fnNode = findEnclosingFunctionNode(parentAncestors) ?? ast;
|
|
3056
|
-
registerBarrierName(lexNode, node.id.name);
|
|
3057
|
-
if (lexNode === fnNode.body || fnNode === ast) {
|
|
3058
|
-
registerBarrierName(fnNode, node.id.name);
|
|
3059
|
-
}
|
|
3060
|
-
if (!scopeRecords.get(node)?.bindings.has(node.id.name)) {
|
|
3061
|
-
registerBarrierName(node, node.id.name);
|
|
3062
|
-
}
|
|
3063
|
-
}
|
|
3064
|
-
},
|
|
3065
|
-
FunctionExpression(node, _state, ancestors) {
|
|
3066
|
-
registerFunctionParams(node, ancestors);
|
|
3067
|
-
if (node.id?.type === "Identifier") {
|
|
3068
|
-
if (!scopeRecords.get(node)?.bindings.has(node.id.name)) {
|
|
3069
|
-
registerBarrierName(node, node.id.name);
|
|
3070
|
-
}
|
|
3071
|
-
}
|
|
3072
|
-
},
|
|
3073
|
-
ArrowFunctionExpression(node, _state, ancestors) {
|
|
3074
|
-
registerFunctionParams(node, ancestors);
|
|
3075
|
-
},
|
|
3076
|
-
ClassDeclaration(node, _state, ancestors) {
|
|
3077
|
-
ensureScopeChain(ancestors);
|
|
3078
|
-
if (node.id?.type === "Identifier") {
|
|
3079
|
-
const parentAncestors = ancestors.slice(0, -1);
|
|
3080
|
-
const lexNode = findEnclosingLexicalNode(parentAncestors);
|
|
3081
|
-
registerBarrierName(lexNode, node.id.name);
|
|
3082
|
-
registerBarrierName(node, node.id.name);
|
|
3083
|
-
}
|
|
3084
|
-
},
|
|
3085
|
-
ClassExpression(node, _state, ancestors) {
|
|
3086
|
-
ensureScopeChain(ancestors);
|
|
3087
|
-
if (node.id?.type === "Identifier") {
|
|
3088
|
-
registerBarrierName(node, node.id.name);
|
|
3089
|
-
}
|
|
3090
|
-
},
|
|
3091
|
-
CatchClause(node, _state, ancestors) {
|
|
3092
|
-
ensureScopeChain(ancestors);
|
|
3093
|
-
if (node.param) {
|
|
3094
|
-
const fnScope = findEnclosingFunctionNode(ancestors);
|
|
3095
|
-
const targets = [];
|
|
3096
|
-
collectPatternTargets(node.param, targets);
|
|
3097
|
-
for (const target of targets) {
|
|
3098
|
-
registerBindingTarget(node, target, true, fnScope);
|
|
3099
|
-
}
|
|
3100
|
-
}
|
|
3101
|
-
},
|
|
3102
|
-
VariableDeclaration(node, _state, ancestors) {
|
|
3103
|
-
ensureScopeChain(ancestors);
|
|
3104
|
-
const fnScope = findEnclosingFunctionNode(ancestors);
|
|
3105
|
-
if (!fnScope) {
|
|
3106
|
-
for (const decl of node.declarations || []) {
|
|
3107
|
-
const targets = [];
|
|
3108
|
-
collectPatternTargets(decl.id, targets);
|
|
3109
|
-
for (const target of targets) {
|
|
3110
|
-
registerBarrierName(ast, target.idNode.name);
|
|
3111
|
-
}
|
|
3112
|
-
}
|
|
3113
|
-
return;
|
|
3114
|
-
}
|
|
3115
|
-
const targetScopeNode = node.kind === "var" ? fnScope : findEnclosingLexicalNode(ancestors);
|
|
3116
|
-
for (const decl of node.declarations || []) {
|
|
3117
|
-
const targets = [];
|
|
3118
|
-
collectPatternTargets(decl.id, targets);
|
|
3119
|
-
for (const target of targets) {
|
|
3120
|
-
const origName = target.idNode.name;
|
|
3121
|
-
if (node.kind === "var") {
|
|
3122
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
3123
|
-
if (ancestors[i] === fnScope) break;
|
|
3124
|
-
if (ancestors[i].type === "CatchClause") {
|
|
3125
|
-
const catchScope = scopeRecords.get(ancestors[i]);
|
|
3126
|
-
if (catchScope?.bindings.has(origName)) {
|
|
3127
|
-
registerBarrierName(ancestors[i], origName);
|
|
3128
|
-
registerBarrierName(fnScope, origName);
|
|
3129
|
-
}
|
|
3130
|
-
}
|
|
3131
|
-
}
|
|
3132
|
-
}
|
|
3133
|
-
registerBindingTarget(targetScopeNode, target, true, fnScope);
|
|
3134
|
-
}
|
|
3135
|
-
}
|
|
3136
|
-
}
|
|
3137
|
-
});
|
|
3138
|
-
function resolveBinding(name, ancestors) {
|
|
3139
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
3140
|
-
const scope = scopeRecords.get(ancestors[i]);
|
|
3141
|
-
if (scope && scope.bindings.has(name)) {
|
|
3142
|
-
return scope.bindings.get(name);
|
|
3143
|
-
}
|
|
3144
|
-
}
|
|
3145
|
-
return null;
|
|
3146
|
-
}
|
|
3147
|
-
function isNonVarIdentifierPosition(node, parent) {
|
|
3148
|
-
if (!parent) return true;
|
|
3149
|
-
if ((parent.type === "FunctionDeclaration" || parent.type === "FunctionExpression" || parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.id === node) {
|
|
3150
|
-
return true;
|
|
3151
|
-
}
|
|
3152
|
-
if (parent.type === "MemberExpression" && parent.property === node && !parent.computed) {
|
|
3153
|
-
return true;
|
|
3154
|
-
}
|
|
3155
|
-
if ((parent.type === "Property" || parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
3156
|
-
return true;
|
|
3157
|
-
}
|
|
3158
|
-
if (parent.type === "LabeledStatement" || parent.type === "BreakStatement" || parent.type === "ContinueStatement" || parent.type === "ImportSpecifier" || parent.type === "ImportDefaultSpecifier" || parent.type === "ImportNamespaceSpecifier" || parent.type === "ExportSpecifier" || parent.type === "MetaProperty") {
|
|
3159
|
-
return true;
|
|
3160
|
-
}
|
|
3161
|
-
return false;
|
|
3162
|
-
}
|
|
3163
|
-
walk4.ancestor(ast, {
|
|
3164
|
-
Identifier(node, _state, ancestors) {
|
|
3165
|
-
if (renamedTargetNodes.has(node)) return;
|
|
3166
|
-
const parent = ancestors[ancestors.length - 2];
|
|
3167
|
-
if (isNonVarIdentifierPosition(node, parent)) return;
|
|
3168
|
-
const entry = resolveBinding(node.name, ancestors);
|
|
3169
|
-
if (!entry || !entry.shouldMangle) {
|
|
3170
|
-
barrierOrFreeIds.add(node.name);
|
|
3171
|
-
}
|
|
3172
|
-
}
|
|
3173
|
-
});
|
|
3174
|
-
function isNameUsedInScopeOrAncestors(candidate, scope) {
|
|
3175
|
-
if (JS_KEYWORDS.has(candidate) || activeReserved.has(candidate) || barrierOrFreeIds.has(candidate)) {
|
|
3176
|
-
return true;
|
|
3177
|
-
}
|
|
3178
|
-
let curr = scope;
|
|
3179
|
-
while (curr) {
|
|
3180
|
-
if (curr.usedNames.has(candidate)) {
|
|
3181
|
-
return true;
|
|
3182
|
-
}
|
|
3183
|
-
curr = curr.parent;
|
|
3184
|
-
}
|
|
3185
|
-
return false;
|
|
3186
|
-
}
|
|
3187
|
-
const p1 = shuffleAlphabet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", seed);
|
|
3188
|
-
const p2a = shuffleAlphabet(
|
|
3189
|
-
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
3190
|
-
(seed ^ 1367130551) >>> 0
|
|
3191
|
-
);
|
|
3192
|
-
const p2b = shuffleAlphabet(
|
|
3193
|
-
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_",
|
|
3194
|
-
(seed ^ 2654435769) >>> 0
|
|
3195
|
-
);
|
|
3196
|
-
function candidateAtSlot(slot) {
|
|
3197
|
-
if (slot < p1.length) {
|
|
3198
|
-
return p1[slot];
|
|
3199
|
-
}
|
|
3200
|
-
const rem = slot - p1.length;
|
|
3201
|
-
const twoCharSpace = p2a.length * p2b.length;
|
|
3202
|
-
if (rem < twoCharSpace) {
|
|
3203
|
-
return `${p2a[rem % p2a.length]}${p2b[Math.floor(rem / p2a.length)]}`;
|
|
3204
|
-
}
|
|
3205
|
-
const rem3 = rem - twoCharSpace;
|
|
3206
|
-
return `${p2a[rem3 % p2a.length]}${p2b[Math.floor(rem3 / p2a.length) % p2b.length]}${p2b[Math.floor(rem3 / twoCharSpace) % p2b.length]}`;
|
|
3207
|
-
}
|
|
3208
|
-
function makeScopedMangledName(scope, origName) {
|
|
3209
|
-
let slot = 0;
|
|
3210
|
-
while (true) {
|
|
3211
|
-
const candidate = candidateAtSlot(slot);
|
|
3212
|
-
slot++;
|
|
3213
|
-
if (candidate === origName) continue;
|
|
3214
|
-
if (!isNameUsedInScopeOrAncestors(candidate, scope)) {
|
|
3215
|
-
return candidate;
|
|
3216
|
-
}
|
|
3217
|
-
}
|
|
3218
|
-
}
|
|
3219
|
-
function assignScopeNamesTopDown(scope) {
|
|
3220
|
-
for (const entry of scope.bindings.values()) {
|
|
3221
|
-
if (!entry.shouldMangle) {
|
|
3222
|
-
entry.mangledName = entry.origName;
|
|
3223
|
-
scope.usedNames.add(entry.origName);
|
|
3224
|
-
continue;
|
|
3225
|
-
}
|
|
3226
|
-
const mangled = makeScopedMangledName(scope, entry.origName);
|
|
3227
|
-
counter++;
|
|
3228
|
-
entry.mangledName = mangled;
|
|
3229
|
-
scope.usedNames.add(mangled);
|
|
3230
|
-
for (const target of entry.targets) {
|
|
3231
|
-
if (target.shorthandProp && target.shorthandProp.shorthand) {
|
|
3232
|
-
target.shorthandProp.shorthand = false;
|
|
3233
|
-
target.shorthandProp.key = {
|
|
3234
|
-
type: "Identifier",
|
|
3235
|
-
name: entry.origName
|
|
3236
|
-
};
|
|
3237
|
-
}
|
|
3238
|
-
target.idNode.name = mangled;
|
|
3239
|
-
}
|
|
3240
|
-
}
|
|
3241
|
-
for (const child of scope.children) {
|
|
3242
|
-
assignScopeNamesTopDown(child);
|
|
3243
|
-
}
|
|
3244
|
-
}
|
|
3245
|
-
const rootScope = scopeRecords.get(ast);
|
|
3246
|
-
if (rootScope) {
|
|
3247
|
-
assignScopeNamesTopDown(rootScope);
|
|
3248
|
-
}
|
|
3249
|
-
if (counter === 0) return 0;
|
|
3250
|
-
function renamePatternTargetsInScope(pattern, ancestors) {
|
|
3251
|
-
const targets = [];
|
|
3252
|
-
collectPatternTargets(pattern, targets);
|
|
3253
|
-
for (const target of targets) {
|
|
3254
|
-
if (renamedTargetNodes.has(target.idNode)) continue;
|
|
3255
|
-
const origName = target.idNode.name;
|
|
3256
|
-
const entry = resolveBinding(origName, ancestors);
|
|
3257
|
-
if (entry && entry.shouldMangle && entry.mangledName !== origName) {
|
|
3258
|
-
if (target.shorthandProp && target.shorthandProp.shorthand) {
|
|
3259
|
-
target.shorthandProp.shorthand = false;
|
|
3260
|
-
target.shorthandProp.key = {
|
|
3261
|
-
type: "Identifier",
|
|
3262
|
-
name: origName
|
|
3263
|
-
};
|
|
3264
|
-
}
|
|
3265
|
-
target.idNode.name = entry.mangledName;
|
|
3266
|
-
renamedTargetNodes.add(target.idNode);
|
|
3267
|
-
}
|
|
3268
|
-
}
|
|
3269
|
-
}
|
|
3270
|
-
walk4.ancestor(ast, {
|
|
3271
|
-
AssignmentExpression(node, _state, ancestors) {
|
|
3272
|
-
renamePatternTargetsInScope(node.left, ancestors);
|
|
3273
|
-
},
|
|
3274
|
-
ForInStatement(node, _state, ancestors) {
|
|
3275
|
-
if (node.left && node.left.type !== "VariableDeclaration") {
|
|
3276
|
-
renamePatternTargetsInScope(node.left, ancestors);
|
|
3277
|
-
}
|
|
3278
|
-
},
|
|
3279
|
-
ForOfStatement(node, _state, ancestors) {
|
|
3280
|
-
if (node.left && node.left.type !== "VariableDeclaration") {
|
|
3281
|
-
renamePatternTargetsInScope(node.left, ancestors);
|
|
3282
|
-
}
|
|
3283
|
-
},
|
|
3284
|
-
Identifier(node, _state, ancestors) {
|
|
3285
|
-
if (renamedTargetNodes.has(node)) return;
|
|
3286
|
-
const parent = ancestors[ancestors.length - 2];
|
|
3287
|
-
if (isNonVarIdentifierPosition(node, parent)) return;
|
|
3288
|
-
const entry = resolveBinding(node.name, ancestors);
|
|
3289
|
-
if (entry && entry.shouldMangle && entry.mangledName !== node.name) {
|
|
3290
|
-
if (parent.type === "Property" && parent.shorthand && parent.value === node) {
|
|
3291
|
-
parent.shorthand = false;
|
|
3292
|
-
parent.key = { type: "Identifier", name: node.name };
|
|
3293
|
-
}
|
|
3294
|
-
node.name = entry.mangledName;
|
|
3295
|
-
}
|
|
3296
|
-
}
|
|
3297
|
-
});
|
|
3298
|
-
return counter;
|
|
3299
|
-
}
|
|
3300
|
-
|
|
3301
|
-
// src/ast/cold-flow-guard.ts
|
|
3302
|
-
var walk5 = __toESM(require("acorn-walk"), 1);
|
|
3303
|
-
function createDecoyObjectExpression(model) {
|
|
3304
|
-
const m = Math.abs(model) % 3;
|
|
3305
|
-
if (m === 0) {
|
|
3306
|
-
return {
|
|
3307
|
-
type: "ObjectExpression",
|
|
3308
|
-
properties: [
|
|
3309
|
-
{
|
|
3310
|
-
type: "Property",
|
|
3311
|
-
key: { type: "Identifier", name: "endpoint" },
|
|
3312
|
-
value: {
|
|
3313
|
-
type: "Literal",
|
|
3314
|
-
value: "/api/v2/auth/admin-bypass",
|
|
3315
|
-
raw: '"/api/v2/auth/admin-bypass"'
|
|
3316
|
-
},
|
|
3317
|
-
kind: "init",
|
|
3318
|
-
computed: false,
|
|
3319
|
-
method: false,
|
|
3320
|
-
shorthand: false
|
|
3321
|
-
},
|
|
3322
|
-
{
|
|
3323
|
-
type: "Property",
|
|
3324
|
-
key: { type: "Identifier", name: "superadmin_token" },
|
|
3325
|
-
value: { type: "Literal", value: 1, raw: "1" },
|
|
3326
|
-
kind: "init",
|
|
3327
|
-
computed: false,
|
|
3328
|
-
method: false,
|
|
3329
|
-
shorthand: false
|
|
3330
|
-
},
|
|
3331
|
-
{
|
|
3332
|
-
type: "Property",
|
|
3333
|
-
key: { type: "Identifier", name: "elevate" },
|
|
3334
|
-
value: { type: "Literal", value: 1, raw: "1" },
|
|
3335
|
-
kind: "init",
|
|
3336
|
-
computed: false,
|
|
3337
|
-
method: false,
|
|
3338
|
-
shorthand: false
|
|
3339
|
-
}
|
|
3340
|
-
]
|
|
3341
|
-
};
|
|
3342
|
-
}
|
|
3343
|
-
if (m === 1) {
|
|
3344
|
-
return {
|
|
3345
|
-
type: "ObjectExpression",
|
|
3346
|
-
properties: [
|
|
3347
|
-
{
|
|
3348
|
-
type: "Property",
|
|
3349
|
-
key: { type: "Identifier", name: "endpoint" },
|
|
3350
|
-
value: {
|
|
3351
|
-
type: "Literal",
|
|
3352
|
-
value: "/api/v2/auth/verify-master",
|
|
3353
|
-
raw: '"/api/v2/auth/verify-master"'
|
|
3354
|
-
},
|
|
3355
|
-
kind: "init",
|
|
3356
|
-
computed: false,
|
|
3357
|
-
method: false,
|
|
3358
|
-
shorthand: false
|
|
3359
|
-
},
|
|
3360
|
-
{
|
|
3361
|
-
type: "Property",
|
|
3362
|
-
key: { type: "Identifier", name: "_verifyMasterToken" },
|
|
3363
|
-
value: { type: "Literal", value: true, raw: "true" },
|
|
3364
|
-
kind: "init",
|
|
3365
|
-
computed: false,
|
|
3366
|
-
method: false,
|
|
3367
|
-
shorthand: false
|
|
3368
|
-
},
|
|
3369
|
-
{
|
|
3370
|
-
type: "Property",
|
|
3371
|
-
key: { type: "Identifier", name: "_bypassToken" },
|
|
3372
|
-
value: {
|
|
3373
|
-
type: "Literal",
|
|
3374
|
-
value: "mock_jwt_bypass_signature",
|
|
3375
|
-
raw: '"mock_jwt_bypass_signature"'
|
|
3376
|
-
},
|
|
3377
|
-
kind: "init",
|
|
3378
|
-
computed: false,
|
|
3379
|
-
method: false,
|
|
3380
|
-
shorthand: false
|
|
3381
|
-
},
|
|
3382
|
-
{
|
|
3383
|
-
type: "Property",
|
|
3384
|
-
key: { type: "Identifier", name: "authorized" },
|
|
3385
|
-
value: { type: "Literal", value: true, raw: "true" },
|
|
3386
|
-
kind: "init",
|
|
3387
|
-
computed: false,
|
|
3388
|
-
method: false,
|
|
3389
|
-
shorthand: false
|
|
3390
|
-
}
|
|
3391
|
-
]
|
|
3392
|
-
};
|
|
3393
|
-
}
|
|
3394
|
-
return {
|
|
3395
|
-
type: "ObjectExpression",
|
|
3396
|
-
properties: [
|
|
3397
|
-
{
|
|
3398
|
-
type: "Property",
|
|
3399
|
-
key: { type: "Identifier", name: "endpoint" },
|
|
3400
|
-
value: {
|
|
3401
|
-
type: "Literal",
|
|
3402
|
-
value: "/api/v2/auth/debug-telemetry",
|
|
3403
|
-
raw: '"/api/v2/auth/debug-telemetry"'
|
|
3404
|
-
},
|
|
3405
|
-
kind: "init",
|
|
3406
|
-
computed: false,
|
|
3407
|
-
method: false,
|
|
3408
|
-
shorthand: false
|
|
3409
|
-
},
|
|
3410
|
-
{
|
|
3411
|
-
type: "Property",
|
|
3412
|
-
key: { type: "Identifier", name: "debug_supervisor_override" },
|
|
3413
|
-
value: { type: "Literal", value: true, raw: "true" },
|
|
3414
|
-
kind: "init",
|
|
3415
|
-
computed: false,
|
|
3416
|
-
method: false,
|
|
3417
|
-
shorthand: false
|
|
3418
|
-
},
|
|
3419
|
-
{
|
|
3420
|
-
type: "Property",
|
|
3421
|
-
key: { type: "Identifier", name: "_bypassToken" },
|
|
3422
|
-
value: {
|
|
3423
|
-
type: "Literal",
|
|
3424
|
-
value: "superadmin_token",
|
|
3425
|
-
raw: '"superadmin_token"'
|
|
3426
|
-
},
|
|
3427
|
-
kind: "init",
|
|
3428
|
-
computed: false,
|
|
3429
|
-
method: false,
|
|
3430
|
-
shorthand: false
|
|
3431
|
-
},
|
|
3432
|
-
{
|
|
3433
|
-
type: "Property",
|
|
3434
|
-
key: { type: "Identifier", name: "mfa_bypassed" },
|
|
3435
|
-
value: { type: "Literal", value: true, raw: "true" },
|
|
3436
|
-
kind: "init",
|
|
3437
|
-
computed: false,
|
|
3438
|
-
method: false,
|
|
3439
|
-
shorthand: false
|
|
3440
|
-
}
|
|
3441
|
-
]
|
|
3442
|
-
};
|
|
3443
|
-
}
|
|
3444
|
-
function createDecoyConsequent(fnIndex) {
|
|
3445
|
-
return {
|
|
3446
|
-
type: "BlockStatement",
|
|
3447
|
-
body: [
|
|
3448
|
-
{
|
|
3449
|
-
type: "ReturnStatement",
|
|
3450
|
-
argument: createDecoyObjectExpression(fnIndex)
|
|
3451
|
-
}
|
|
3452
|
-
]
|
|
3453
|
-
};
|
|
3454
|
-
}
|
|
3455
|
-
function createSharedDecoyConsequent(decoyIdent, fnIndex) {
|
|
3456
|
-
const model = Math.abs(fnIndex) % 3;
|
|
3457
|
-
return {
|
|
3458
|
-
type: "BlockStatement",
|
|
3459
|
-
body: [
|
|
3460
|
-
{
|
|
3461
|
-
type: "ReturnStatement",
|
|
3462
|
-
argument: {
|
|
3463
|
-
type: "CallExpression",
|
|
3464
|
-
callee: {
|
|
3465
|
-
type: "MemberExpression",
|
|
3466
|
-
computed: true,
|
|
3467
|
-
object: { type: "Identifier", name: decoyIdent },
|
|
3468
|
-
property: {
|
|
3469
|
-
type: "Literal",
|
|
3470
|
-
value: model,
|
|
3471
|
-
raw: String(model)
|
|
3472
|
-
}
|
|
3473
|
-
},
|
|
3474
|
-
arguments: []
|
|
3475
|
-
}
|
|
3476
|
-
}
|
|
3477
|
-
]
|
|
3478
|
-
};
|
|
3479
|
-
}
|
|
3480
|
-
function createSharedDecoyDeclaration(decoyIdent = "_d", maxModels = 3) {
|
|
3481
|
-
const count = Math.max(1, Math.min(3, maxModels));
|
|
3482
|
-
const indices = [];
|
|
3483
|
-
for (let i = 0; i < count; i++) indices.push(i);
|
|
3484
|
-
return {
|
|
3485
|
-
type: "VariableDeclaration",
|
|
3486
|
-
kind: "var",
|
|
3487
|
-
declarations: [
|
|
3488
|
-
{
|
|
3489
|
-
type: "VariableDeclarator",
|
|
3490
|
-
id: { type: "Identifier", name: decoyIdent },
|
|
3491
|
-
init: {
|
|
3492
|
-
type: "ArrayExpression",
|
|
3493
|
-
elements: indices.map((m) => ({
|
|
3494
|
-
type: "ArrowFunctionExpression",
|
|
3495
|
-
id: null,
|
|
3496
|
-
params: [],
|
|
3497
|
-
body: createDecoyObjectExpression(m),
|
|
3498
|
-
generator: false,
|
|
3499
|
-
async: false,
|
|
3500
|
-
expression: true
|
|
3501
|
-
}))
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
]
|
|
3505
|
-
};
|
|
3506
|
-
}
|
|
3507
|
-
function cloneNode(node) {
|
|
3508
|
-
return JSON.parse(JSON.stringify(node));
|
|
3509
|
-
}
|
|
3510
|
-
function makeImul(left, right) {
|
|
3511
|
-
return {
|
|
3512
|
-
type: "CallExpression",
|
|
3513
|
-
callee: {
|
|
3514
|
-
type: "MemberExpression",
|
|
3515
|
-
computed: false,
|
|
3516
|
-
object: { type: "Identifier", name: "Math" },
|
|
3517
|
-
property: { type: "Identifier", name: "imul" }
|
|
3518
|
-
},
|
|
3519
|
-
arguments: [left, right]
|
|
3520
|
-
};
|
|
3521
|
-
}
|
|
3522
|
-
function makeBinary(operator, left, right) {
|
|
3523
|
-
return {
|
|
3524
|
-
type: "BinaryExpression",
|
|
3525
|
-
operator,
|
|
3526
|
-
left,
|
|
3527
|
-
right
|
|
3528
|
-
};
|
|
3529
|
-
}
|
|
3530
|
-
function makeUnary(operator, argument) {
|
|
3531
|
-
return {
|
|
3532
|
-
type: "UnaryExpression",
|
|
3533
|
-
operator,
|
|
3534
|
-
prefix: true,
|
|
3535
|
-
argument
|
|
3536
|
-
};
|
|
3537
|
-
}
|
|
3538
|
-
function makeLiteral(value) {
|
|
3539
|
-
return {
|
|
3540
|
-
type: "Literal",
|
|
3541
|
-
value,
|
|
3542
|
-
raw: String(value)
|
|
3543
|
-
};
|
|
3544
|
-
}
|
|
3545
|
-
function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false) {
|
|
3546
|
-
const family = Math.abs((seed + fnIndex) % 5);
|
|
3547
|
-
const c1 = (seed >>> 1) + Math.imul(family + 1, 22912827) & 32767;
|
|
3548
|
-
const c2 = (c1 ^ 173477) & 32767;
|
|
3549
|
-
const target = (seed ^ Math.imul(family + 1, 2654435761)) & 65535 | 1;
|
|
3550
|
-
let paramName = null;
|
|
3551
|
-
if (typeof paramNode === "string") {
|
|
3552
|
-
paramName = paramNode;
|
|
3553
|
-
} else if (paramNode?.type === "Identifier") {
|
|
3554
|
-
paramName = paramNode.name;
|
|
3555
|
-
} else if (paramNode?.type === "AssignmentPattern" && paramNode.left?.type === "Identifier") {
|
|
3556
|
-
paramName = paramNode.left.name;
|
|
3557
|
-
} else if (paramNode?.type === "RestElement" && paramNode.argument?.type === "Identifier") {
|
|
3558
|
-
paramName = paramNode.argument.name;
|
|
3559
|
-
}
|
|
3560
|
-
let vBitNode;
|
|
3561
|
-
let vIntNode;
|
|
3562
|
-
if (paramName && paramName !== "arguments" && paramName !== "eval") {
|
|
3563
|
-
vBitNode = { type: "Identifier", name: paramName };
|
|
3564
|
-
vIntNode = makeBinary("|", { type: "Identifier", name: paramName }, makeLiteral(0));
|
|
3565
|
-
} else if (!isArrowFn) {
|
|
3566
|
-
vBitNode = {
|
|
3567
|
-
type: "MemberExpression",
|
|
3568
|
-
computed: false,
|
|
3569
|
-
object: { type: "Identifier", name: "arguments" },
|
|
3570
|
-
property: { type: "Identifier", name: "length" }
|
|
3571
|
-
};
|
|
3572
|
-
vIntNode = cloneNode(vBitNode);
|
|
3573
|
-
} else {
|
|
3574
|
-
vBitNode = {
|
|
3575
|
-
type: "MemberExpression",
|
|
3576
|
-
computed: false,
|
|
3577
|
-
object: makeUnary("typeof", { type: "Identifier", name: "globalThis" }),
|
|
3578
|
-
property: { type: "Identifier", name: "length" }
|
|
3579
|
-
};
|
|
3580
|
-
vIntNode = cloneNode(vBitNode);
|
|
3581
|
-
}
|
|
3582
|
-
const kLit = makeLiteral(c2);
|
|
3583
|
-
let mbaExpr;
|
|
3584
|
-
if (family === 0) {
|
|
3585
|
-
const term1 = makeImul(cloneNode(vIntNode), cloneNode(kLit));
|
|
3586
|
-
const vAndK = makeBinary("&", cloneNode(vBitNode), cloneNode(kLit));
|
|
3587
|
-
const vOrK = makeBinary("|", cloneNode(vBitNode), cloneNode(kLit));
|
|
3588
|
-
const notK = makeUnary("~", cloneNode(kLit));
|
|
3589
|
-
const notV = makeUnary("~", cloneNode(vBitNode));
|
|
3590
|
-
const vAndNotK = makeBinary("&", cloneNode(vBitNode), notK);
|
|
3591
|
-
const notVAndK = makeBinary("&", notV, cloneNode(kLit));
|
|
3592
|
-
const term2 = makeImul(vAndK, vOrK);
|
|
3593
|
-
const term3 = makeImul(vAndNotK, notVAndK);
|
|
3594
|
-
const sumTerms = makeBinary("+", term2, term3);
|
|
3595
|
-
mbaExpr = makeBinary("|", makeBinary("-", term1, sumTerms), makeLiteral(0));
|
|
3596
|
-
} else if (family === 1) {
|
|
3597
|
-
const vXorK1 = makeBinary("^", cloneNode(vBitNode), cloneNode(kLit));
|
|
3598
|
-
const vXorK2 = makeBinary("^", cloneNode(vBitNode), cloneNode(kLit));
|
|
3599
|
-
const term1 = makeImul(vXorK1, vXorK2);
|
|
3600
|
-
const vSubK1 = makeBinary("-", cloneNode(vIntNode), cloneNode(kLit));
|
|
3601
|
-
const vSubK2 = makeBinary("-", cloneNode(vIntNode), cloneNode(kLit));
|
|
3602
|
-
const term2 = makeImul(vSubK1, vSubK2);
|
|
3603
|
-
const notK = makeUnary("~", cloneNode(kLit));
|
|
3604
|
-
const notV = makeUnary("~", cloneNode(vBitNode));
|
|
3605
|
-
const vAndNotK = makeBinary("&", cloneNode(vBitNode), notK);
|
|
3606
|
-
const notVAndK = makeBinary("&", notV, cloneNode(kLit));
|
|
3607
|
-
const term3 = makeImul(vAndNotK, notVAndK);
|
|
3608
|
-
const shiftTerm = makeBinary("<<", term3, makeLiteral(2));
|
|
3609
|
-
const sumTerms = makeBinary("+", term2, shiftTerm);
|
|
3610
|
-
mbaExpr = makeBinary("|", makeBinary("-", term1, sumTerms), makeLiteral(0));
|
|
3611
|
-
} else if (family === 2) {
|
|
3612
|
-
const vAddK1 = makeBinary("+", cloneNode(vIntNode), cloneNode(kLit));
|
|
3613
|
-
const vAddK2 = makeBinary("+", cloneNode(vIntNode), cloneNode(kLit));
|
|
3614
|
-
const term1 = makeImul(vAddK1, vAddK2);
|
|
3615
|
-
const vAndK = makeBinary("&", cloneNode(vBitNode), cloneNode(kLit));
|
|
3616
|
-
const vOrK = makeBinary("|", cloneNode(vBitNode), cloneNode(kLit));
|
|
3617
|
-
const term2 = makeImul(vAndK, vOrK);
|
|
3618
|
-
const shiftTerm = makeBinary("<<", term2, makeLiteral(2));
|
|
3619
|
-
const vXorK1 = makeBinary("^", cloneNode(vBitNode), cloneNode(kLit));
|
|
3620
|
-
const vXorK2 = makeBinary("^", cloneNode(vBitNode), cloneNode(kLit));
|
|
3621
|
-
const term3 = makeImul(vXorK1, vXorK2);
|
|
3622
|
-
const sumTerms = makeBinary("+", shiftTerm, term3);
|
|
3623
|
-
mbaExpr = makeBinary("|", makeBinary("-", term1, sumTerms), makeLiteral(0));
|
|
3624
|
-
} else if (family === 3) {
|
|
3625
|
-
const vOrK1 = makeBinary("|", cloneNode(vBitNode), cloneNode(kLit));
|
|
3626
|
-
const vOrK2 = makeBinary("|", cloneNode(vBitNode), cloneNode(kLit));
|
|
3627
|
-
const term1 = makeImul(vOrK1, vOrK2);
|
|
3628
|
-
const vAndK1 = makeBinary("&", cloneNode(vBitNode), cloneNode(kLit));
|
|
3629
|
-
const vAndK2 = makeBinary("&", cloneNode(vBitNode), cloneNode(kLit));
|
|
3630
|
-
const term2 = makeImul(vAndK1, vAndK2);
|
|
3631
|
-
const vXorK = makeBinary("^", cloneNode(vBitNode), cloneNode(kLit));
|
|
3632
|
-
const vAddK = makeBinary("+", cloneNode(vIntNode), cloneNode(kLit));
|
|
3633
|
-
const term3 = makeImul(vXorK, vAddK);
|
|
3634
|
-
const sumTerms = makeBinary("+", term2, term3);
|
|
3635
|
-
mbaExpr = makeBinary("|", makeBinary("-", term1, sumTerms), makeLiteral(0));
|
|
3636
|
-
} else {
|
|
3637
|
-
const vk = makeBinary("^", cloneNode(vBitNode), cloneNode(kLit));
|
|
3638
|
-
const vkSq = makeImul(vk, cloneNode(vk));
|
|
3639
|
-
const sevenVkSqSub1 = makeBinary("-", makeImul(makeLiteral(7), vkSq), makeLiteral(1));
|
|
3640
|
-
const vSq = makeImul(cloneNode(vBitNode), cloneNode(vBitNode));
|
|
3641
|
-
const quadDiff = makeBinary("^", makeBinary("&", makeBinary("^", sevenVkSqSub1, vSq), makeLiteral(2)), makeLiteral(2));
|
|
3642
|
-
const parityTerm = makeBinary("&", makeBinary("+", makeImul(cloneNode(vBitNode), cloneNode(vBitNode)), cloneNode(vIntNode)), makeLiteral(1));
|
|
3643
|
-
mbaExpr = makeBinary("|", quadDiff, parityTerm);
|
|
3644
|
-
}
|
|
3645
|
-
const decoyIdx = Math.abs(fnIndex) % 3;
|
|
3646
|
-
const consequent = decoyIdent ? createSharedDecoyConsequent(decoyIdent, decoyIdx) : createDecoyConsequent(decoyIdx);
|
|
3647
|
-
return {
|
|
3648
|
-
type: "IfStatement",
|
|
3649
|
-
test: {
|
|
3650
|
-
type: "BinaryExpression",
|
|
3651
|
-
operator: "===",
|
|
3652
|
-
left: mbaExpr,
|
|
3653
|
-
right: { type: "Literal", value: target, raw: String(target) }
|
|
3654
|
-
},
|
|
3655
|
-
consequent,
|
|
3656
|
-
alternate: null
|
|
3657
|
-
};
|
|
3658
|
-
}
|
|
3659
|
-
var MAX_COLD_GUARDS_PER_CHUNK = 12;
|
|
3660
|
-
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
|
|
3661
|
-
const decoyIdent = "_d";
|
|
3662
|
-
if (Array.isArray(ast.body)) {
|
|
3663
|
-
const alreadyGuarded = ast.body.some(
|
|
3664
|
-
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
3665
|
-
(d) => d.id?.type === "Identifier" && d.id.name === decoyIdent
|
|
3666
|
-
)
|
|
3667
|
-
);
|
|
3668
|
-
if (alreadyGuarded) return 0;
|
|
3669
|
-
}
|
|
3670
|
-
let guardedCount = 0;
|
|
3671
|
-
function maybeInjectGuard(node) {
|
|
3672
|
-
if (guardedCount >= MAX_COLD_GUARDS_PER_CHUNK) return;
|
|
3673
|
-
if (!coldFunctionNodes.has(node)) return;
|
|
3674
|
-
if (!node.body || node.body.type !== "BlockStatement") return;
|
|
3675
|
-
const firstParam = node.params?.[0];
|
|
3676
|
-
const isArrow = node.type === "ArrowFunctionExpression";
|
|
3677
|
-
const guardStmt = createSotaMbaPredicate(
|
|
3678
|
-
seed,
|
|
3679
|
-
guardedCount,
|
|
3680
|
-
firstParam,
|
|
3681
|
-
decoyIdent,
|
|
3682
|
-
isArrow
|
|
3683
|
-
);
|
|
3684
|
-
guardedCount++;
|
|
3685
|
-
if (hotExemptNodes) {
|
|
3686
|
-
hotExemptNodes.add(guardStmt);
|
|
3687
|
-
hotExemptNodes.add(guardStmt.consequent);
|
|
3688
|
-
}
|
|
3689
|
-
let insertIdx = 0;
|
|
3690
|
-
while (insertIdx < node.body.body.length && node.body.body[insertIdx].type === "ExpressionStatement" && node.body.body[insertIdx].directive) {
|
|
3691
|
-
insertIdx++;
|
|
3692
|
-
}
|
|
3693
|
-
node.body.body.splice(insertIdx, 0, guardStmt);
|
|
3694
|
-
}
|
|
3695
|
-
walk5.simple(ast, {
|
|
3696
|
-
FunctionDeclaration: maybeInjectGuard,
|
|
3697
|
-
FunctionExpression: maybeInjectGuard,
|
|
3698
|
-
ArrowFunctionExpression: maybeInjectGuard
|
|
3699
|
-
});
|
|
3700
|
-
if (guardedCount > 0 && Array.isArray(ast.body)) {
|
|
3701
|
-
const sharedDecoyDecl = createSharedDecoyDeclaration(decoyIdent, guardedCount);
|
|
3702
|
-
if (hotExemptNodes) {
|
|
3703
|
-
hotExemptNodes.add(sharedDecoyDecl);
|
|
3704
|
-
for (const decl of sharedDecoyDecl.declarations || []) {
|
|
3705
|
-
if (decl.init?.elements) {
|
|
3706
|
-
for (const el of decl.init.elements) {
|
|
3707
|
-
hotExemptNodes.add(el);
|
|
3708
|
-
}
|
|
3709
|
-
}
|
|
3710
|
-
}
|
|
3711
|
-
}
|
|
3712
|
-
let insertIdx = 0;
|
|
3713
|
-
while (insertIdx < ast.body.length && ast.body[insertIdx].type === "ExpressionStatement" && ast.body[insertIdx].directive) {
|
|
3714
|
-
insertIdx++;
|
|
3715
|
-
}
|
|
3716
|
-
ast.body.splice(insertIdx, 0, sharedDecoyDecl);
|
|
3717
|
-
}
|
|
3718
|
-
return guardedCount;
|
|
3719
|
-
}
|
|
3720
|
-
|
|
3721
|
-
// src/ast/micro-vm.ts
|
|
3722
|
-
var acorn5 = __toESM(require("acorn"), 1);
|
|
3723
|
-
var walk6 = __toESM(require("acorn-walk"), 1);
|
|
3724
|
-
var OP_LDC = 0;
|
|
3725
|
-
var OP_LDV = 1;
|
|
3726
|
-
var OP_STV = 2;
|
|
3727
|
-
var OP_LDG = 3;
|
|
3728
|
-
var OP_GETP = 4;
|
|
3729
|
-
var OP_SETP = 5;
|
|
3730
|
-
var OP_CALL = 6;
|
|
3731
|
-
var OP_MCALL = 7;
|
|
3732
|
-
var OP_ADD = 8;
|
|
3733
|
-
var OP_SUB = 9;
|
|
3734
|
-
var OP_MUL = 10;
|
|
3735
|
-
var OP_XOR = 11;
|
|
3736
|
-
var OP_AND = 12;
|
|
3737
|
-
var OP_OR = 13;
|
|
3738
|
-
var OP_SEQ = 14;
|
|
3739
|
-
var OP_LT = 15;
|
|
3740
|
-
var OP_NOT = 16;
|
|
3741
|
-
var OP_JMP = 17;
|
|
3742
|
-
var OP_JZ = 18;
|
|
3743
|
-
var OP_RET = 19;
|
|
3744
|
-
var OP_THROW = 20;
|
|
3745
|
-
var OP_AWAIT = 21;
|
|
3746
|
-
var OP_OBJ = 22;
|
|
3747
|
-
var OP_ARR = 23;
|
|
3748
|
-
var OP_LDU = 24;
|
|
3749
|
-
var OP_STU = 25;
|
|
3750
|
-
var OPCODE_COUNT = 26;
|
|
3751
|
-
function shuffleRange(n, seed) {
|
|
3752
|
-
const arr = [];
|
|
3753
|
-
for (let i = 0; i < n; i++) arr.push(i);
|
|
3754
|
-
let s = (seed || 324478056) >>> 0;
|
|
3755
|
-
function rand() {
|
|
3756
|
-
s ^= s << 13;
|
|
3757
|
-
s ^= s >>> 17;
|
|
3758
|
-
s ^= s << 5;
|
|
3759
|
-
return (s >>> 0) / 4294967296;
|
|
3760
|
-
}
|
|
3761
|
-
for (let i = arr.length - 1; i > 0; i--) {
|
|
3762
|
-
const j = Math.floor(rand() * (i + 1));
|
|
3763
|
-
const tmp = arr[i];
|
|
3764
|
-
arr[i] = arr[j];
|
|
3765
|
-
arr[j] = tmp;
|
|
3766
|
-
}
|
|
3767
|
-
return arr;
|
|
3768
|
-
}
|
|
3769
|
-
function deriveVmKey(seed) {
|
|
3770
|
-
return computeFnv1aHash("vm-key", seed) | 0;
|
|
3771
|
-
}
|
|
3772
|
-
function encryptBytecodeStream(plainBytecode, fnSalt, vmKey, stateSlots) {
|
|
3773
|
-
const len = plainBytecode.length;
|
|
3774
|
-
const enc = new Array(len);
|
|
3775
|
-
const stateBefore = new Array(len + 1);
|
|
3776
|
-
const stAtSlot = /* @__PURE__ */ new Map();
|
|
3777
|
-
let st = vmKey ^ fnSalt | 0;
|
|
3778
|
-
for (let p = 0; p < len; p++) {
|
|
3779
|
-
stateBefore[p] = st;
|
|
3780
|
-
if (stateSlots && stateSlots.has(p)) {
|
|
3781
|
-
stAtSlot.set(p, st);
|
|
3782
|
-
enc[p] = 0;
|
|
3783
|
-
} else {
|
|
3784
|
-
st = Math.imul(st ^ p + 1, 73244475) + 2654435769 | 0;
|
|
3785
|
-
const raw = plainBytecode[p] ^ st >>> 16 & 65535;
|
|
3786
|
-
enc[p] = raw;
|
|
3787
|
-
st = st ^ Math.imul(raw + 1, 2246822507) | 0;
|
|
3788
|
-
}
|
|
3789
|
-
}
|
|
3790
|
-
stateBefore[len] = st;
|
|
3791
|
-
if (stateSlots) {
|
|
3792
|
-
for (const slot of stateSlots) {
|
|
3793
|
-
const targetPc = plainBytecode[slot - 1];
|
|
3794
|
-
const sBefore = stAtSlot.get(slot) ?? 0;
|
|
3795
|
-
enc[slot] = stateBefore[targetPc] ^ sBefore | 0;
|
|
3796
|
-
}
|
|
3797
|
-
}
|
|
3798
|
-
return enc;
|
|
3799
|
-
}
|
|
3800
|
-
function generateOpcodeMap(seed, count = OPCODE_COUNT) {
|
|
3801
|
-
const pool = [];
|
|
3802
|
-
for (let i = 0; i < 256; i++) pool.push(i);
|
|
3803
|
-
let s = (seed ^ 2779096485) >>> 0;
|
|
3804
|
-
function rand() {
|
|
3805
|
-
s ^= s << 13;
|
|
3806
|
-
s ^= s >>> 17;
|
|
3807
|
-
s ^= s << 5;
|
|
3808
|
-
return (s >>> 0) / 4294967296;
|
|
3809
|
-
}
|
|
3810
|
-
for (let i = pool.length - 1; i > 0; i--) {
|
|
3811
|
-
const j = Math.floor(rand() * (i + 1));
|
|
3812
|
-
const tmp = pool[i];
|
|
3813
|
-
pool[i] = pool[j];
|
|
3814
|
-
pool[j] = tmp;
|
|
3815
|
-
}
|
|
3816
|
-
return pool.slice(0, count);
|
|
3817
|
-
}
|
|
3818
|
-
function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowKeySymbol, expectedDelta) {
|
|
3819
|
-
const opCount = opMap.length;
|
|
3820
|
-
const slotMap = shuffleRange(opCount, (seed ^ 1367130551) >>> 0);
|
|
3821
|
-
const pairOrder = shuffleRange(opCount, (seed ^ 1013904242) >>> 0);
|
|
3822
|
-
const opMask = computeFnv1aHash("vm-opmask", seed) & 255 | 1;
|
|
3823
|
-
const slotMask = computeFnv1aHash("vm-slotmask", seed) & 127 | 32;
|
|
3824
|
-
const vmKey = deriveVmKey(seed);
|
|
3825
|
-
const pairs = [];
|
|
3826
|
-
for (const op of pairOrder) {
|
|
3827
|
-
pairs.push(opMap[op] ^ opMask, slotMap[op] ^ slotMask);
|
|
3828
|
-
}
|
|
3829
|
-
const handlerMap = {
|
|
3830
|
-
[OP_LDC]: "function($f){$f.q[$f.r++]=$f.k[$rd($f)];}",
|
|
3831
|
-
[OP_LDV]: "function($f){$f.q[$f.r++]=$f.s[$rd($f)];}",
|
|
3832
|
-
[OP_STV]: "function($f){$f.s[$rd($f)]=$f.q[--$f.r];}",
|
|
3833
|
-
[OP_LDG]: "function($f){$f.q[$f.r++]=$G[$f.k[$rd($f)]];}",
|
|
3834
|
-
[OP_GETP]: "function($f){var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a[$b];}",
|
|
3835
|
-
[OP_SETP]: "function($f){var $v=$f.q[--$f.r],$b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=($a[$b]=$v);}",
|
|
3836
|
-
[OP_CALL]: "function($f){var $n=$rd($f),$g=[];for(var $i=$n-1;$i>=0;$i--)$g[$i]=$f.q[--$f.r];var $fn=$f.q[--$f.r];$f.q[$f.r++]=$fn.apply(void 0,$g);}",
|
|
3837
|
-
[OP_MCALL]: "function($f){var $n=$rd($f),$g=[];for(var $i=$n-1;$i>=0;$i--)$g[$i]=$f.q[--$f.r];var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a[$b].apply($a,$g);}",
|
|
3838
|
-
[OP_ADD]: "function($f){var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a+$b;}",
|
|
3839
|
-
[OP_SUB]: "function($f){var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a-$b;}",
|
|
3840
|
-
[OP_MUL]: "function($f){var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a*$b;}",
|
|
3841
|
-
[OP_XOR]: "function($f){var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a^$b;}",
|
|
3842
|
-
[OP_AND]: "function($f){var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a&$b;}",
|
|
3843
|
-
[OP_OR]: "function($f){var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a|$b;}",
|
|
3844
|
-
[OP_SEQ]: "function($f){var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a===$b;}",
|
|
3845
|
-
[OP_LT]: "function($f){var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a<$b;}",
|
|
3846
|
-
[OP_NOT]: "function($f){$f.q[$f.r-1]=!$f.q[$f.r-1];}",
|
|
3847
|
-
[OP_JMP]: "function($f){var $j=$rd($f),$ts=$f.c[$f.p++]^$f.st;$f.p=$j;$f.st=$ts;}",
|
|
3848
|
-
[OP_JZ]: "function($f){var $j=$rd($f),$ts=$f.c[$f.p++]^$f.st;if(!$f.q[--$f.r]){$f.p=$j;$f.st=$ts;}}",
|
|
3849
|
-
[OP_RET]: "function($f){$f.d=1;$f.v=$f.q[--$f.r];}",
|
|
3850
|
-
[OP_THROW]: "function($f){throw $f.q[--$f.r];}",
|
|
3851
|
-
[OP_AWAIT]: "function($f){var $v=$f.q[--$f.r];$f.d=2;$f.v=Promise.resolve($v).then(function($w){$f.d=0;$f.q[$f.r++]=$w;return $x($f);});}",
|
|
3852
|
-
[OP_OBJ]: "function($f){var $n=$rd($f),$o={},$e=[];for(var $i=0;$i<$n;$i++){var $v=$f.q[--$f.r],$k0=$f.q[--$f.r];$e.push([$k0,$v]);}for(var $i=$e.length-1;$i>=0;$i--){$o[$e[$i][0]]=$e[$i][1];}$f.q[$f.r++]=$o;}",
|
|
3853
|
-
[OP_ARR]: "function($f){var $n=$rd($f),$a=[];for(var $i=$n-1;$i>=0;$i--)$a[$i]=$f.q[--$f.r];$f.q[$f.r++]=$a;}",
|
|
3854
|
-
[OP_LDU]: "function($f){$f.q[$f.r++]=$f.u[$rd($f)][0]();}",
|
|
3855
|
-
[OP_STU]: "function($f){$f.u[$rd($f)][1]($f.q[--$f.r]);}"
|
|
3856
|
-
};
|
|
3857
|
-
const handlers = new Array(opCount);
|
|
3858
|
-
for (let op = 0; op < opCount; op++) {
|
|
3859
|
-
handlers[slotMap[op]] = handlerMap[op];
|
|
3860
|
-
}
|
|
3861
|
-
const hasSym = Boolean(windowKeySymbol && expectedDelta !== void 0);
|
|
3862
|
-
const symPropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(windowKeySymbol) ? `.${windowKeySymbol}` : `[${JSON.stringify(windowKeySymbol)}]` : "";
|
|
3863
|
-
const dDecl = hasSym ? `var $d=$G${symPropAccess}!=null?$G${symPropAccess}:($W?-1:(($h^$D)&0xffff));` : "";
|
|
3864
|
-
const okExpr = hasSym ? `(($h&255)^$A^($d&255))&255` : `(($h&255)^$A)&255`;
|
|
3865
|
-
const skExpr = hasSym ? `((($h>>>8)&255)^$B^(($d>>>8)&255))&255` : `((($h>>>8)&255)^$B)&255`;
|
|
3866
|
-
const vkExpr = hasSym ? `($h^$C^Math.imul($d|0,0x9e3779b1))|0` : `($h^$C)|0`;
|
|
3867
|
-
const paramsList = hasSym ? "$P,$A,$B,$C,$D" : "$P,$A,$B,$C";
|
|
3868
|
-
const factoryRaw = `(function $I(${paramsList}){var $G=typeof globalThis<"u"?globalThis:(typeof window<"u"?window:this);${hasSym ? 'var $W=typeof window<"u"||typeof self<"u";' : ""}var $ts=Function.prototype.toString,$s=$ts.call($I);for(var $h=0x811c9dc5,$i=0;$i<$s.length;$i++)$h=Math.imul($h^$s.charCodeAt($i),0x01000193)>>>0;try{$ts.call(0);$h^=1;}catch($e){}var $M,$ok,$sk,$vk,$in=0;function $init(){$in=1;${dDecl}$ok=${okExpr};$sk=${skExpr};$vk=${vkExpr};$M=[];for(var $j=0;$j<$P.length;$j+=2)$M[$P[$j]]=$P[$j+1];}function $rd($f){var $p=$f.p++;var $x0=$f.st=(Math.imul($f.st^($p+1),0x45d9f3b)+0x9e3779b9)|0;var $w=$f.c[$p],$v=$w^(($x0>>>16)&0xffff);$f.st=($f.st^Math.imul($w+1,0x85ebca6b))|0;return $v;}var $H;function $x($f){while($f.p<$f.c.length){var $o=$rd($f),$m=$M[$o^$ok];if($m!==void 0){var $h0=$H[$m^$sk];if($h0)$h0($f);}if($f.d)return $f.v;}}$H=[${handlers.join(
|
|
3869
|
-
","
|
|
3870
|
-
)}];return function($c,$k,$s0,$t,$a,$u){if(!$in)$init();return $x({c:$c,k:$k,s:$s0,t:$t,u:$u||[],q:[],r:0,p:0,st:($vk^$a)|0,d:0,v:void 0});};})`;
|
|
3871
|
-
const parsedFactory = acorn5.parse(factoryRaw, {
|
|
3872
|
-
ecmaVersion: "latest",
|
|
3873
|
-
sourceType: "script"
|
|
3874
|
-
});
|
|
3875
|
-
const factoryExpr = parsedFactory.body[0].expression;
|
|
3876
|
-
const compactFactory = generateCompactJs(factoryExpr);
|
|
3877
|
-
const buildH = computeFnv1aHash(compactFactory);
|
|
3878
|
-
const expD = hasSym ? expectedDelta & 65535 : 0;
|
|
3879
|
-
const argA = (opMask ^ buildH & 255 ^ expD & 255) & 255;
|
|
3880
|
-
const argB = (slotMask ^ buildH >>> 8 & 255 ^ expD >>> 8 & 255) & 255;
|
|
3881
|
-
const argC = vmKey ^ buildH ^ (hasSym ? Math.imul(expD | 0, 2654435761) : 0) | 0;
|
|
3882
|
-
const argD = hasSym ? (buildH ^ expD) & 65535 : 0;
|
|
3883
|
-
return `var ${vmHelperName}=(${compactFactory})([${pairs.join(",")}],${argA},${argB},${argC}${hasSym ? `,${argD}` : ""});`;
|
|
3884
|
-
}
|
|
3885
|
-
function countAstNodes(node) {
|
|
3886
|
-
let count = 0;
|
|
3887
|
-
walk6.full(node, () => {
|
|
3888
|
-
count++;
|
|
3889
|
-
});
|
|
3890
|
-
return count;
|
|
3891
|
-
}
|
|
3892
|
-
function hasForbiddenConstructs(fnNode) {
|
|
3893
|
-
let forbidden = false;
|
|
3894
|
-
walk6.full(fnNode, (node) => {
|
|
3895
|
-
if (forbidden) return;
|
|
3896
|
-
const type = node.type;
|
|
3897
|
-
if (type === "JSXElement" || type === "JSXFragment" || type === "Super" || type === "YieldExpression" || type === "WithStatement") {
|
|
3898
|
-
forbidden = true;
|
|
3899
|
-
return;
|
|
3900
|
-
}
|
|
3901
|
-
if (type === "Identifier" && (node.name === "arguments" || node.name === "eval")) {
|
|
3902
|
-
forbidden = true;
|
|
3903
|
-
return;
|
|
3904
|
-
}
|
|
3905
|
-
if (type === "MetaProperty") {
|
|
3906
|
-
forbidden = true;
|
|
3907
|
-
return;
|
|
3908
|
-
}
|
|
3909
|
-
});
|
|
3910
|
-
return forbidden;
|
|
3911
|
-
}
|
|
3912
|
-
var FUNCTION_NODE_TYPES2 = /* @__PURE__ */ new Set([
|
|
3913
|
-
"FunctionDeclaration",
|
|
3914
|
-
"FunctionExpression",
|
|
3915
|
-
"ArrowFunctionExpression"
|
|
3916
|
-
]);
|
|
3917
|
-
var LEXICAL_SCOPE_TYPES2 = /* @__PURE__ */ new Set([
|
|
3918
|
-
"Program",
|
|
3919
|
-
"FunctionDeclaration",
|
|
3920
|
-
"FunctionExpression",
|
|
3921
|
-
"ArrowFunctionExpression",
|
|
3922
|
-
"BlockStatement",
|
|
3923
|
-
"ForStatement",
|
|
3924
|
-
"ForInStatement",
|
|
3925
|
-
"ForOfStatement",
|
|
3926
|
-
"SwitchStatement",
|
|
3927
|
-
"CatchClause",
|
|
3928
|
-
"ClassDeclaration",
|
|
3929
|
-
"ClassExpression"
|
|
3930
|
-
]);
|
|
3931
|
-
function collectPatternNames(pattern, out) {
|
|
3932
|
-
if (!pattern) return;
|
|
3933
|
-
switch (pattern.type) {
|
|
3934
|
-
case "Identifier":
|
|
3935
|
-
out.add(pattern.name);
|
|
3936
|
-
break;
|
|
3937
|
-
case "AssignmentPattern":
|
|
3938
|
-
collectPatternNames(pattern.left, out);
|
|
3939
|
-
break;
|
|
3940
|
-
case "RestElement":
|
|
3941
|
-
collectPatternNames(pattern.argument, out);
|
|
3942
|
-
break;
|
|
3943
|
-
case "ArrayPattern":
|
|
3944
|
-
for (const el of pattern.elements || []) {
|
|
3945
|
-
if (el) collectPatternNames(el, out);
|
|
3946
|
-
}
|
|
3947
|
-
break;
|
|
3948
|
-
case "ObjectPattern":
|
|
3949
|
-
for (const prop of pattern.properties || []) {
|
|
3950
|
-
if (prop.type === "Property") {
|
|
3951
|
-
collectPatternNames(prop.value, out);
|
|
3952
|
-
} else if (prop.type === "RestElement") {
|
|
3953
|
-
collectPatternNames(prop.argument, out);
|
|
3954
|
-
}
|
|
3955
|
-
}
|
|
3956
|
-
break;
|
|
3957
|
-
}
|
|
3958
|
-
}
|
|
3959
|
-
function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
|
|
3960
|
-
const bytecode = [];
|
|
3961
|
-
const consts = [];
|
|
3962
|
-
const stateSlots = /* @__PURE__ */ new Set();
|
|
3963
|
-
const fnScope = /* @__PURE__ */ new Map();
|
|
3964
|
-
const scopeStack = [fnScope];
|
|
3965
|
-
const upvalues = [];
|
|
3966
|
-
const upvalueMap = /* @__PURE__ */ new Map();
|
|
3967
|
-
let localCount = 0;
|
|
3968
|
-
for (const param of fnNode.params) {
|
|
3969
|
-
if (param.type !== "Identifier") return null;
|
|
3970
|
-
if (fnScope.has(param.name)) return null;
|
|
3971
|
-
fnScope.set(param.name, localCount++);
|
|
3972
|
-
}
|
|
3973
|
-
let invalidDecl = false;
|
|
3974
|
-
function scanVarDecls(node, isTopBody) {
|
|
3975
|
-
if (!node || invalidDecl) return;
|
|
3976
|
-
if (Array.isArray(node)) {
|
|
3977
|
-
for (const item of node) scanVarDecls(item, isTopBody);
|
|
3978
|
-
return;
|
|
3979
|
-
}
|
|
3980
|
-
if (typeof node !== "object" || !node.type) return;
|
|
3981
|
-
if (FUNCTION_NODE_TYPES2.has(node.type)) return;
|
|
3982
|
-
if (node.type === "VariableDeclaration") {
|
|
3983
|
-
const isVar = node.kind === "var";
|
|
3984
|
-
if (isVar || isTopBody) {
|
|
3985
|
-
for (const decl of node.declarations || []) {
|
|
3986
|
-
if (decl.id?.type !== "Identifier") {
|
|
3987
|
-
invalidDecl = true;
|
|
3988
|
-
return;
|
|
3989
|
-
}
|
|
3990
|
-
if (!fnScope.has(decl.id.name)) {
|
|
3991
|
-
fnScope.set(decl.id.name, localCount++);
|
|
3992
|
-
}
|
|
3993
|
-
}
|
|
3994
|
-
}
|
|
3995
|
-
return;
|
|
3996
|
-
}
|
|
3997
|
-
if (node.type === "BlockStatement") {
|
|
3998
|
-
for (const s of node.body || []) {
|
|
3999
|
-
scanVarDecls(s, false);
|
|
4000
|
-
}
|
|
4001
|
-
return;
|
|
4002
|
-
}
|
|
4003
|
-
if (node.type === "IfStatement") {
|
|
4004
|
-
scanVarDecls(node.consequent, false);
|
|
4005
|
-
if (node.alternate) scanVarDecls(node.alternate, false);
|
|
4006
|
-
}
|
|
4007
|
-
}
|
|
4008
|
-
if (fnNode.body.type === "BlockStatement") {
|
|
4009
|
-
for (const stmt of fnNode.body.body || []) {
|
|
4010
|
-
scanVarDecls(stmt, true);
|
|
4011
|
-
if (invalidDecl) return null;
|
|
4012
|
-
}
|
|
4013
|
-
}
|
|
4014
|
-
function resolveLocal(name) {
|
|
4015
|
-
for (let i = scopeStack.length - 1; i >= 0; i--) {
|
|
4016
|
-
const slot = scopeStack[i].get(name);
|
|
4017
|
-
if (slot !== void 0) return slot;
|
|
4018
|
-
}
|
|
4019
|
-
return void 0;
|
|
4020
|
-
}
|
|
4021
|
-
function getOrCreateUpvalue(name, isWritten) {
|
|
4022
|
-
let idx = upvalueMap.get(name);
|
|
4023
|
-
if (idx === void 0) {
|
|
4024
|
-
idx = upvalues.length;
|
|
4025
|
-
upvalueMap.set(name, idx);
|
|
4026
|
-
upvalues.push({ name, isWritten });
|
|
4027
|
-
} else if (isWritten) {
|
|
4028
|
-
upvalues[idx].isWritten = true;
|
|
4029
|
-
}
|
|
4030
|
-
return idx;
|
|
4031
|
-
}
|
|
4032
|
-
function emitLoadVar(name) {
|
|
4033
|
-
const localSlot = resolveLocal(name);
|
|
4034
|
-
if (localSlot !== void 0) {
|
|
4035
|
-
emit(OP_LDV, localSlot);
|
|
4036
|
-
return;
|
|
4037
|
-
}
|
|
4038
|
-
if (enclosingBindings && enclosingBindings.has(name)) {
|
|
4039
|
-
emit(OP_LDU, getOrCreateUpvalue(name, false));
|
|
4040
|
-
return;
|
|
4041
|
-
}
|
|
4042
|
-
const idx = addConst(name);
|
|
4043
|
-
emit(OP_LDG, idx);
|
|
4044
|
-
}
|
|
4045
|
-
function canWriteVar(name) {
|
|
4046
|
-
if (resolveLocal(name) !== void 0) return true;
|
|
4047
|
-
return Boolean(enclosingBindings && enclosingBindings.has(name));
|
|
4048
|
-
}
|
|
4049
|
-
function emitStoreVar(name) {
|
|
4050
|
-
const localSlot = resolveLocal(name);
|
|
4051
|
-
if (localSlot !== void 0) {
|
|
4052
|
-
emit(OP_STV, localSlot);
|
|
4053
|
-
return true;
|
|
4054
|
-
}
|
|
4055
|
-
if (enclosingBindings && enclosingBindings.has(name)) {
|
|
4056
|
-
emit(OP_STU, getOrCreateUpvalue(name, true));
|
|
4057
|
-
return true;
|
|
4058
|
-
}
|
|
4059
|
-
return false;
|
|
4060
|
-
}
|
|
4061
|
-
function addConst(val) {
|
|
4062
|
-
for (let i = 0; i < consts.length; i++) {
|
|
4063
|
-
if (Object.is(consts[i], val)) return i;
|
|
4064
|
-
}
|
|
4065
|
-
const idx = consts.length;
|
|
4066
|
-
consts.push(val);
|
|
4067
|
-
return idx;
|
|
4068
|
-
}
|
|
4069
|
-
function emit(op, ...args) {
|
|
4070
|
-
bytecode.push(opMap[op]);
|
|
4071
|
-
for (const a of args) bytecode.push(a);
|
|
4072
|
-
}
|
|
4073
|
-
function compileExpr(node, inValuePos = true) {
|
|
4074
|
-
if (!node) return false;
|
|
4075
|
-
switch (node.type) {
|
|
4076
|
-
case "Literal": {
|
|
4077
|
-
if (node.regex || typeof node.value === "bigint") return false;
|
|
4078
|
-
const idx = addConst(node.value);
|
|
4079
|
-
emit(OP_LDC, idx);
|
|
4080
|
-
return true;
|
|
4081
|
-
}
|
|
4082
|
-
case "Identifier": {
|
|
4083
|
-
if (node.name === "undefined") {
|
|
4084
|
-
const localSlot = resolveLocal("undefined");
|
|
4085
|
-
if (localSlot !== void 0) {
|
|
4086
|
-
emit(OP_LDV, localSlot);
|
|
4087
|
-
} else if (enclosingBindings && enclosingBindings.has("undefined")) {
|
|
4088
|
-
emit(OP_LDU, getOrCreateUpvalue("undefined", false));
|
|
4089
|
-
} else {
|
|
4090
|
-
const idx = addConst(void 0);
|
|
4091
|
-
emit(OP_LDC, idx);
|
|
4092
|
-
}
|
|
4093
|
-
return true;
|
|
4094
|
-
}
|
|
4095
|
-
emitLoadVar(node.name);
|
|
4096
|
-
return true;
|
|
4097
|
-
}
|
|
4098
|
-
case "BinaryExpression": {
|
|
4099
|
-
if (node.operator === ">") {
|
|
4100
|
-
if (!compileExpr(node.right, true)) return false;
|
|
4101
|
-
if (!compileExpr(node.left, true)) return false;
|
|
4102
|
-
emit(OP_LT);
|
|
4103
|
-
return true;
|
|
4104
|
-
}
|
|
4105
|
-
if (node.operator === "<=") {
|
|
4106
|
-
if (!compileExpr(node.right, true)) return false;
|
|
4107
|
-
if (!compileExpr(node.left, true)) return false;
|
|
4108
|
-
emit(OP_LT);
|
|
4109
|
-
emit(OP_NOT);
|
|
4110
|
-
return true;
|
|
4111
|
-
}
|
|
4112
|
-
if (node.operator === ">=") {
|
|
4113
|
-
if (!compileExpr(node.left, true)) return false;
|
|
4114
|
-
if (!compileExpr(node.right, true)) return false;
|
|
4115
|
-
emit(OP_LT);
|
|
4116
|
-
emit(OP_NOT);
|
|
4117
|
-
return true;
|
|
4118
|
-
}
|
|
4119
|
-
if (!compileExpr(node.left, true)) return false;
|
|
4120
|
-
if (!compileExpr(node.right, true)) return false;
|
|
4121
|
-
switch (node.operator) {
|
|
4122
|
-
case "+":
|
|
4123
|
-
emit(OP_ADD);
|
|
4124
|
-
break;
|
|
4125
|
-
case "-":
|
|
4126
|
-
emit(OP_SUB);
|
|
4127
|
-
break;
|
|
4128
|
-
case "*":
|
|
4129
|
-
emit(OP_MUL);
|
|
4130
|
-
break;
|
|
4131
|
-
case "^":
|
|
4132
|
-
emit(OP_XOR);
|
|
4133
|
-
break;
|
|
4134
|
-
case "&":
|
|
4135
|
-
emit(OP_AND);
|
|
4136
|
-
break;
|
|
4137
|
-
case "|":
|
|
4138
|
-
emit(OP_OR);
|
|
4139
|
-
break;
|
|
4140
|
-
case "==":
|
|
4141
|
-
case "===":
|
|
4142
|
-
emit(OP_SEQ);
|
|
4143
|
-
break;
|
|
4144
|
-
case "!=":
|
|
4145
|
-
case "!==":
|
|
4146
|
-
emit(OP_SEQ);
|
|
4147
|
-
emit(OP_NOT);
|
|
4148
|
-
break;
|
|
4149
|
-
case "<":
|
|
4150
|
-
emit(OP_LT);
|
|
4151
|
-
break;
|
|
4152
|
-
default:
|
|
4153
|
-
return false;
|
|
4154
|
-
}
|
|
4155
|
-
return true;
|
|
4156
|
-
}
|
|
4157
|
-
case "UnaryExpression": {
|
|
4158
|
-
if (node.operator === "void") {
|
|
4159
|
-
if (node.argument?.type !== "Literal" || node.argument.regex) return false;
|
|
4160
|
-
const undefIdx2 = addConst(void 0);
|
|
4161
|
-
emit(OP_LDC, undefIdx2);
|
|
4162
|
-
return true;
|
|
4163
|
-
}
|
|
4164
|
-
if (!compileExpr(node.argument, true)) return false;
|
|
4165
|
-
switch (node.operator) {
|
|
4166
|
-
case "!":
|
|
4167
|
-
emit(OP_NOT);
|
|
4168
|
-
break;
|
|
4169
|
-
case "-": {
|
|
4170
|
-
const neg1Idx = addConst(-1);
|
|
4171
|
-
emit(OP_LDC, neg1Idx);
|
|
4172
|
-
emit(OP_MUL);
|
|
4173
|
-
break;
|
|
4174
|
-
}
|
|
4175
|
-
case "+": {
|
|
4176
|
-
const zeroIdx = addConst(0);
|
|
4177
|
-
emit(OP_LDC, zeroIdx);
|
|
4178
|
-
emit(OP_ADD);
|
|
4179
|
-
break;
|
|
4180
|
-
}
|
|
4181
|
-
case "~": {
|
|
4182
|
-
const neg1Idx = addConst(-1);
|
|
4183
|
-
emit(OP_LDC, neg1Idx);
|
|
4184
|
-
emit(OP_XOR);
|
|
4185
|
-
break;
|
|
4186
|
-
}
|
|
4187
|
-
default:
|
|
4188
|
-
return false;
|
|
4189
|
-
}
|
|
4190
|
-
return true;
|
|
4191
|
-
}
|
|
4192
|
-
case "MemberExpression": {
|
|
4193
|
-
if (node.optional) return false;
|
|
4194
|
-
if (!compileExpr(node.object, true)) return false;
|
|
4195
|
-
if (node.computed) {
|
|
4196
|
-
if (!compileExpr(node.property, true)) return false;
|
|
4197
|
-
} else {
|
|
4198
|
-
if (node.property?.type !== "Identifier") return false;
|
|
4199
|
-
const idx = addConst(node.property.name);
|
|
4200
|
-
emit(OP_LDC, idx);
|
|
4201
|
-
}
|
|
4202
|
-
emit(OP_GETP);
|
|
4203
|
-
return true;
|
|
4204
|
-
}
|
|
4205
|
-
case "CallExpression": {
|
|
4206
|
-
if (node.optional) return false;
|
|
4207
|
-
if (node.callee.type === "MemberExpression") {
|
|
4208
|
-
if (node.callee.optional) return false;
|
|
4209
|
-
if (!compileExpr(node.callee.object, true)) return false;
|
|
4210
|
-
if (node.callee.computed) {
|
|
4211
|
-
if (!compileExpr(node.callee.property, true)) return false;
|
|
4212
|
-
} else {
|
|
4213
|
-
if (node.callee.property?.type !== "Identifier") return false;
|
|
4214
|
-
const idx = addConst(node.callee.property.name);
|
|
4215
|
-
emit(OP_LDC, idx);
|
|
4216
|
-
}
|
|
4217
|
-
for (const arg of node.arguments) {
|
|
4218
|
-
if (!compileExpr(arg, true)) return false;
|
|
4219
|
-
}
|
|
4220
|
-
emit(OP_MCALL, node.arguments.length);
|
|
4221
|
-
} else {
|
|
4222
|
-
if (!compileExpr(node.callee, true)) return false;
|
|
4223
|
-
for (const arg of node.arguments) {
|
|
4224
|
-
if (!compileExpr(arg, true)) return false;
|
|
4225
|
-
}
|
|
4226
|
-
emit(OP_CALL, node.arguments.length);
|
|
4227
|
-
}
|
|
4228
|
-
return true;
|
|
4229
|
-
}
|
|
4230
|
-
case "AssignmentExpression": {
|
|
4231
|
-
if (node.left.type === "Identifier") {
|
|
4232
|
-
const name = node.left.name;
|
|
4233
|
-
if (!canWriteVar(name)) return false;
|
|
4234
|
-
if (node.operator === "=") {
|
|
4235
|
-
if (!compileExpr(node.right, true)) return false;
|
|
4236
|
-
} else {
|
|
4237
|
-
let binOp = null;
|
|
4238
|
-
switch (node.operator) {
|
|
4239
|
-
case "+=":
|
|
4240
|
-
binOp = OP_ADD;
|
|
4241
|
-
break;
|
|
4242
|
-
case "-=":
|
|
4243
|
-
binOp = OP_SUB;
|
|
4244
|
-
break;
|
|
4245
|
-
case "*=":
|
|
4246
|
-
binOp = OP_MUL;
|
|
4247
|
-
break;
|
|
4248
|
-
case "^=":
|
|
4249
|
-
binOp = OP_XOR;
|
|
4250
|
-
break;
|
|
4251
|
-
case "&=":
|
|
4252
|
-
binOp = OP_AND;
|
|
4253
|
-
break;
|
|
4254
|
-
case "|=":
|
|
4255
|
-
binOp = OP_OR;
|
|
4256
|
-
break;
|
|
4257
|
-
default:
|
|
4258
|
-
return false;
|
|
4259
|
-
}
|
|
4260
|
-
emitLoadVar(name);
|
|
4261
|
-
if (!compileExpr(node.right, true)) return false;
|
|
4262
|
-
emit(binOp);
|
|
4263
|
-
}
|
|
4264
|
-
if (!emitStoreVar(name)) return false;
|
|
4265
|
-
if (inValuePos) {
|
|
4266
|
-
emitLoadVar(name);
|
|
4267
|
-
}
|
|
4268
|
-
return true;
|
|
4269
|
-
}
|
|
4270
|
-
if (node.left.type === "MemberExpression") {
|
|
4271
|
-
if (node.operator !== "=" || node.left.optional) return false;
|
|
4272
|
-
if (!compileExpr(node.left.object, true)) return false;
|
|
4273
|
-
if (node.left.computed) {
|
|
4274
|
-
if (!compileExpr(node.left.property, true)) return false;
|
|
4275
|
-
} else {
|
|
4276
|
-
if (node.left.property?.type !== "Identifier") return false;
|
|
4277
|
-
const idx = addConst(node.left.property.name);
|
|
4278
|
-
emit(OP_LDC, idx);
|
|
4279
|
-
}
|
|
4280
|
-
if (!compileExpr(node.right, true)) return false;
|
|
4281
|
-
emit(OP_SETP);
|
|
4282
|
-
return true;
|
|
4283
|
-
}
|
|
4284
|
-
return false;
|
|
4285
|
-
}
|
|
4286
|
-
case "UpdateExpression": {
|
|
4287
|
-
if (node.argument?.type !== "Identifier") return false;
|
|
4288
|
-
const name = node.argument.name;
|
|
4289
|
-
if (!canWriteVar(name)) return false;
|
|
4290
|
-
const oneIdx = addConst(1);
|
|
4291
|
-
const stepOp = node.operator === "++" ? OP_ADD : OP_SUB;
|
|
4292
|
-
if (node.prefix) {
|
|
4293
|
-
emitLoadVar(name);
|
|
4294
|
-
emit(OP_LDC, oneIdx);
|
|
4295
|
-
emit(OP_MUL);
|
|
4296
|
-
emit(OP_LDC, oneIdx);
|
|
4297
|
-
emit(stepOp);
|
|
4298
|
-
if (!emitStoreVar(name)) return false;
|
|
4299
|
-
if (inValuePos) {
|
|
4300
|
-
emitLoadVar(name);
|
|
4301
|
-
}
|
|
4302
|
-
} else {
|
|
4303
|
-
if (inValuePos) {
|
|
4304
|
-
emitLoadVar(name);
|
|
4305
|
-
emit(OP_LDC, oneIdx);
|
|
4306
|
-
emit(OP_MUL);
|
|
4307
|
-
}
|
|
4308
|
-
emitLoadVar(name);
|
|
4309
|
-
emit(OP_LDC, oneIdx);
|
|
4310
|
-
emit(OP_MUL);
|
|
4311
|
-
emit(OP_LDC, oneIdx);
|
|
4312
|
-
emit(stepOp);
|
|
4313
|
-
if (!emitStoreVar(name)) return false;
|
|
4314
|
-
}
|
|
4315
|
-
return true;
|
|
4316
|
-
}
|
|
4317
|
-
case "ObjectExpression": {
|
|
4318
|
-
for (const prop of node.properties) {
|
|
4319
|
-
if (prop.type !== "Property" || prop.kind !== "init") return false;
|
|
4320
|
-
if (prop.computed) {
|
|
4321
|
-
if (!compileExpr(prop.key, true)) return false;
|
|
4322
|
-
} else {
|
|
4323
|
-
const keyName = prop.key?.name ?? prop.key?.value;
|
|
4324
|
-
if (keyName === void 0) return false;
|
|
4325
|
-
const idx = addConst(keyName);
|
|
4326
|
-
emit(OP_LDC, idx);
|
|
4327
|
-
}
|
|
4328
|
-
if (!compileExpr(prop.value, true)) return false;
|
|
4329
|
-
}
|
|
4330
|
-
emit(OP_OBJ, node.properties.length);
|
|
4331
|
-
return true;
|
|
4332
|
-
}
|
|
4333
|
-
case "ArrayExpression": {
|
|
4334
|
-
for (const elem of node.elements) {
|
|
4335
|
-
if (!elem || !compileExpr(elem, true)) return false;
|
|
4336
|
-
}
|
|
4337
|
-
emit(OP_ARR, node.elements.length);
|
|
4338
|
-
return true;
|
|
4339
|
-
}
|
|
4340
|
-
case "AwaitExpression": {
|
|
4341
|
-
if (!compileExpr(node.argument, true)) return false;
|
|
4342
|
-
emit(OP_AWAIT);
|
|
4343
|
-
return true;
|
|
4344
|
-
}
|
|
4345
|
-
default:
|
|
4346
|
-
return false;
|
|
4347
|
-
}
|
|
4348
|
-
}
|
|
4349
|
-
function compileStmt(stmt, isFnBody = false) {
|
|
4350
|
-
if (!stmt) return false;
|
|
4351
|
-
switch (stmt.type) {
|
|
4352
|
-
case "ReturnStatement": {
|
|
4353
|
-
if (stmt.argument) {
|
|
4354
|
-
if (!compileExpr(stmt.argument, true)) return false;
|
|
4355
|
-
} else {
|
|
4356
|
-
const idx = addConst(void 0);
|
|
4357
|
-
emit(OP_LDC, idx);
|
|
4358
|
-
}
|
|
4359
|
-
emit(OP_RET);
|
|
4360
|
-
return true;
|
|
4361
|
-
}
|
|
4362
|
-
case "ExpressionStatement": {
|
|
4363
|
-
if (!compileExpr(stmt.expression, false)) return false;
|
|
4364
|
-
return true;
|
|
4365
|
-
}
|
|
4366
|
-
case "VariableDeclaration": {
|
|
4367
|
-
for (const decl of stmt.declarations) {
|
|
4368
|
-
if (decl.id?.type !== "Identifier") return false;
|
|
4369
|
-
const slot = resolveLocal(decl.id.name);
|
|
4370
|
-
if (slot === void 0) return false;
|
|
4371
|
-
if (decl.init) {
|
|
4372
|
-
if (!compileExpr(decl.init, true)) return false;
|
|
4373
|
-
emit(OP_STV, slot);
|
|
4374
|
-
}
|
|
4375
|
-
}
|
|
4376
|
-
return true;
|
|
4377
|
-
}
|
|
4378
|
-
case "IfStatement": {
|
|
4379
|
-
if (!compileExpr(stmt.test, true)) return false;
|
|
4380
|
-
const jzPos = bytecode.length;
|
|
4381
|
-
emit(OP_JZ, 0, 0);
|
|
4382
|
-
stateSlots.add(jzPos + 2);
|
|
4383
|
-
if (!compileStmt(stmt.consequent, false)) return false;
|
|
4384
|
-
if (stmt.alternate) {
|
|
4385
|
-
const jmpPos = bytecode.length;
|
|
4386
|
-
emit(OP_JMP, 0, 0);
|
|
4387
|
-
stateSlots.add(jmpPos + 2);
|
|
4388
|
-
bytecode[jzPos + 1] = bytecode.length;
|
|
4389
|
-
if (!compileStmt(stmt.alternate, false)) return false;
|
|
4390
|
-
bytecode[jmpPos + 1] = bytecode.length;
|
|
4391
|
-
} else {
|
|
4392
|
-
bytecode[jzPos + 1] = bytecode.length;
|
|
4393
|
-
}
|
|
4394
|
-
return true;
|
|
4395
|
-
}
|
|
4396
|
-
case "BlockStatement": {
|
|
4397
|
-
let pushedBlock = false;
|
|
4398
|
-
if (!isFnBody) {
|
|
4399
|
-
const blockScope = /* @__PURE__ */ new Map();
|
|
4400
|
-
for (const s of stmt.body || []) {
|
|
4401
|
-
if (s.type === "VariableDeclaration" && s.kind !== "var") {
|
|
4402
|
-
for (const decl of s.declarations || []) {
|
|
4403
|
-
if (decl.id?.type !== "Identifier") return false;
|
|
4404
|
-
if (!blockScope.has(decl.id.name)) {
|
|
4405
|
-
blockScope.set(decl.id.name, localCount++);
|
|
4406
|
-
}
|
|
4407
|
-
}
|
|
4408
|
-
}
|
|
4409
|
-
}
|
|
4410
|
-
if (blockScope.size > 0) {
|
|
4411
|
-
scopeStack.push(blockScope);
|
|
4412
|
-
pushedBlock = true;
|
|
4413
|
-
}
|
|
4414
|
-
}
|
|
4415
|
-
for (const s of stmt.body) {
|
|
4416
|
-
if (!compileStmt(s, false)) {
|
|
4417
|
-
if (pushedBlock) scopeStack.pop();
|
|
4418
|
-
return false;
|
|
4419
|
-
}
|
|
4420
|
-
}
|
|
4421
|
-
if (pushedBlock) scopeStack.pop();
|
|
4422
|
-
return true;
|
|
4423
|
-
}
|
|
4424
|
-
default:
|
|
4425
|
-
return false;
|
|
4426
|
-
}
|
|
4427
|
-
}
|
|
4428
|
-
if (fnNode.body.type === "BlockStatement") {
|
|
4429
|
-
if (!compileStmt(fnNode.body, true)) return null;
|
|
4430
|
-
} else {
|
|
4431
|
-
if (!compileExpr(fnNode.body, true)) return null;
|
|
4432
|
-
emit(OP_RET);
|
|
4433
|
-
}
|
|
4434
|
-
const undefIdx = addConst(void 0);
|
|
4435
|
-
emit(OP_LDC, undefIdx);
|
|
4436
|
-
emit(OP_RET);
|
|
4437
|
-
return { bytecode, consts, localCount, stateSlots, upvalues };
|
|
4438
|
-
}
|
|
4439
|
-
function findInjectedVmHelperName(ast) {
|
|
4440
|
-
if (!ast || !Array.isArray(ast.body)) return null;
|
|
4441
|
-
for (const stmt of ast.body) {
|
|
4442
|
-
if (stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")) {
|
|
4443
|
-
return stmt.id.name;
|
|
4444
|
-
}
|
|
4445
|
-
if (stmt.type === "VariableDeclaration" && Array.isArray(stmt.declarations)) {
|
|
4446
|
-
for (const d of stmt.declarations) {
|
|
4447
|
-
if (d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uVm")) {
|
|
4448
|
-
return d.id.name;
|
|
4449
|
-
}
|
|
4450
|
-
}
|
|
4451
|
-
}
|
|
4452
|
-
}
|
|
4453
|
-
return null;
|
|
4454
|
-
}
|
|
4455
|
-
function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 2654435769, windowKeySymbol, expectedDelta) {
|
|
4456
|
-
const suffix = computeFnv1aHash(`micro-vm:${seed}`, seed).toString(36);
|
|
4457
|
-
const vmHelperName = `_uVm${suffix}`;
|
|
4458
|
-
const existingName = findInjectedVmHelperName(ast);
|
|
4459
|
-
if (existingName) {
|
|
4460
|
-
return {
|
|
4461
|
-
virtualizedCount: 0,
|
|
4462
|
-
vmHelperName: existingName
|
|
4463
|
-
};
|
|
4464
|
-
}
|
|
4465
|
-
const opMap = generateOpcodeMap(seed, OPCODE_COUNT);
|
|
4466
|
-
const vmKey = deriveVmKey(seed);
|
|
4467
|
-
const scopeBindings = /* @__PURE__ */ new Map();
|
|
4468
|
-
function addScopeBinding(scopeNode, name) {
|
|
4469
|
-
if (!scopeNode || !name) return;
|
|
4470
|
-
let set = scopeBindings.get(scopeNode);
|
|
4471
|
-
if (!set) {
|
|
4472
|
-
set = /* @__PURE__ */ new Set();
|
|
4473
|
-
scopeBindings.set(scopeNode, set);
|
|
4474
|
-
}
|
|
4475
|
-
set.add(name);
|
|
4476
|
-
}
|
|
4477
|
-
function findNearestFunctionOrProgram(ancestors) {
|
|
4478
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
4479
|
-
if (FUNCTION_NODE_TYPES2.has(ancestors[i].type) || ancestors[i].type === "Program") {
|
|
4480
|
-
return ancestors[i];
|
|
4481
|
-
}
|
|
4482
|
-
}
|
|
4483
|
-
return ast;
|
|
4484
|
-
}
|
|
4485
|
-
function findNearestLexicalScope(ancestors) {
|
|
4486
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
4487
|
-
if (LEXICAL_SCOPE_TYPES2.has(ancestors[i].type)) {
|
|
4488
|
-
return ancestors[i];
|
|
4489
|
-
}
|
|
4490
|
-
}
|
|
4491
|
-
return ast;
|
|
4492
|
-
}
|
|
4493
|
-
const candidates = [];
|
|
4494
|
-
walk6.ancestor(ast, {
|
|
4495
|
-
ImportDeclaration(node) {
|
|
4496
|
-
for (const spec of node.specifiers || []) {
|
|
4497
|
-
if (spec.local?.type === "Identifier") {
|
|
4498
|
-
addScopeBinding(ast, spec.local.name);
|
|
4499
|
-
}
|
|
4500
|
-
}
|
|
4501
|
-
},
|
|
4502
|
-
VariableDeclaration(node, _state, ancestors) {
|
|
4503
|
-
const targetScope = node.kind === "var" ? findNearestFunctionOrProgram(ancestors) : findNearestLexicalScope(ancestors);
|
|
4504
|
-
const names = /* @__PURE__ */ new Set();
|
|
4505
|
-
for (const decl of node.declarations || []) {
|
|
4506
|
-
collectPatternNames(decl.id, names);
|
|
4507
|
-
}
|
|
4508
|
-
for (const name of names) {
|
|
4509
|
-
addScopeBinding(targetScope, name);
|
|
4510
|
-
}
|
|
4511
|
-
},
|
|
4512
|
-
FunctionDeclaration(node, _state, ancestors) {
|
|
4513
|
-
const parentAncestors = ancestors.slice(0, -1);
|
|
4514
|
-
if (node.id?.type === "Identifier") {
|
|
4515
|
-
addScopeBinding(findNearestLexicalScope(parentAncestors), node.id.name);
|
|
4516
|
-
addScopeBinding(findNearestFunctionOrProgram(parentAncestors), node.id.name);
|
|
4517
|
-
}
|
|
4518
|
-
const paramNames = /* @__PURE__ */ new Set();
|
|
4519
|
-
for (const p of node.params || []) {
|
|
4520
|
-
collectPatternNames(p, paramNames);
|
|
4521
|
-
}
|
|
4522
|
-
for (const name of paramNames) {
|
|
4523
|
-
addScopeBinding(node, name);
|
|
4524
|
-
}
|
|
4525
|
-
candidates.push({ fn: node, ancestors: ancestors.slice() });
|
|
4526
|
-
},
|
|
4527
|
-
FunctionExpression(node, _state, ancestors) {
|
|
4528
|
-
if (node.id?.type === "Identifier") {
|
|
4529
|
-
addScopeBinding(node, node.id.name);
|
|
4530
|
-
}
|
|
4531
|
-
const paramNames = /* @__PURE__ */ new Set();
|
|
4532
|
-
for (const p of node.params || []) {
|
|
4533
|
-
collectPatternNames(p, paramNames);
|
|
4534
|
-
}
|
|
4535
|
-
for (const name of paramNames) {
|
|
4536
|
-
addScopeBinding(node, name);
|
|
4537
|
-
}
|
|
4538
|
-
candidates.push({ fn: node, ancestors: ancestors.slice() });
|
|
4539
|
-
},
|
|
4540
|
-
ArrowFunctionExpression(node, _state, ancestors) {
|
|
4541
|
-
const paramNames = /* @__PURE__ */ new Set();
|
|
4542
|
-
for (const p of node.params || []) {
|
|
4543
|
-
collectPatternNames(p, paramNames);
|
|
4544
|
-
}
|
|
4545
|
-
for (const name of paramNames) {
|
|
4546
|
-
addScopeBinding(node, name);
|
|
4547
|
-
}
|
|
4548
|
-
candidates.push({ fn: node, ancestors: ancestors.slice() });
|
|
4549
|
-
},
|
|
4550
|
-
ClassDeclaration(node, _state, ancestors) {
|
|
4551
|
-
if (node.id?.type === "Identifier") {
|
|
4552
|
-
addScopeBinding(findNearestLexicalScope(ancestors.slice(0, -1)), node.id.name);
|
|
4553
|
-
addScopeBinding(node, node.id.name);
|
|
4554
|
-
}
|
|
4555
|
-
},
|
|
4556
|
-
ClassExpression(node) {
|
|
4557
|
-
if (node.id?.type === "Identifier") {
|
|
4558
|
-
addScopeBinding(node, node.id.name);
|
|
4559
|
-
}
|
|
4560
|
-
},
|
|
4561
|
-
CatchClause(node) {
|
|
4562
|
-
if (node.param) {
|
|
4563
|
-
const names = /* @__PURE__ */ new Set();
|
|
4564
|
-
collectPatternNames(node.param, names);
|
|
4565
|
-
for (const name of names) {
|
|
4566
|
-
addScopeBinding(node, name);
|
|
4567
|
-
}
|
|
4568
|
-
}
|
|
4569
|
-
}
|
|
4570
|
-
});
|
|
4571
|
-
let virtualizedCount = 0;
|
|
4572
|
-
for (const { fn, ancestors } of candidates) {
|
|
4573
|
-
if (virtualizedCount >= 5) break;
|
|
4574
|
-
if (coldFunctionNodes && !coldFunctionNodes.has(fn)) {
|
|
4575
|
-
continue;
|
|
4576
|
-
}
|
|
4577
|
-
if (serializedFunctionNodes && serializedFunctionNodes.has(fn)) {
|
|
4578
|
-
continue;
|
|
4579
|
-
}
|
|
4580
|
-
if (fn.generator) {
|
|
4581
|
-
continue;
|
|
4582
|
-
}
|
|
4583
|
-
const parentNode = ancestors.length >= 2 ? ancestors[ancestors.length - 2] : null;
|
|
4584
|
-
if (parentNode?.type === "MethodDefinition" && parentNode.kind === "constructor") {
|
|
4585
|
-
continue;
|
|
4586
|
-
}
|
|
4587
|
-
if (ancestors.some((a) => a.type === "WithStatement")) {
|
|
4588
|
-
continue;
|
|
4589
|
-
}
|
|
4590
|
-
if (hasForbiddenConstructs(fn)) {
|
|
4591
|
-
continue;
|
|
4592
|
-
}
|
|
4593
|
-
const nodeCount = countAstNodes(fn);
|
|
4594
|
-
if (nodeCount < 15 || nodeCount > 80) {
|
|
4595
|
-
continue;
|
|
4596
|
-
}
|
|
4597
|
-
const enclosingBindings = /* @__PURE__ */ new Set();
|
|
4598
|
-
for (let i = 0; i < ancestors.length - 1; i++) {
|
|
4599
|
-
const bound = scopeBindings.get(ancestors[i]);
|
|
4600
|
-
if (bound) {
|
|
4601
|
-
for (const name of bound) {
|
|
4602
|
-
enclosingBindings.add(name);
|
|
4603
|
-
}
|
|
4604
|
-
}
|
|
4605
|
-
}
|
|
4606
|
-
if (fn.type === "FunctionExpression" && fn.id?.type === "Identifier") {
|
|
4607
|
-
enclosingBindings.add(fn.id.name);
|
|
4608
|
-
}
|
|
4609
|
-
const compiled = compileFunctionToBytecode(fn, opMap, enclosingBindings);
|
|
4610
|
-
if (!compiled) {
|
|
4611
|
-
continue;
|
|
4612
|
-
}
|
|
4613
|
-
const fnSalt = computeFnv1aHash(`vm-fn:${virtualizedCount}`, seed) >>> 0;
|
|
4614
|
-
const encBytecode = encryptBytecodeStream(
|
|
4615
|
-
compiled.bytecode,
|
|
4616
|
-
fnSalt,
|
|
4617
|
-
vmKey,
|
|
4618
|
-
compiled.stateSlots
|
|
4619
|
-
);
|
|
4620
|
-
const paramArgs = fn.params.map((p) => ({
|
|
4621
|
-
type: "Identifier",
|
|
4622
|
-
name: p.name
|
|
4623
|
-
}));
|
|
4624
|
-
const constElements = compiled.consts.map((c) => {
|
|
4625
|
-
if (c === void 0) {
|
|
4626
|
-
return {
|
|
4627
|
-
type: "UnaryExpression",
|
|
4628
|
-
operator: "void",
|
|
4629
|
-
prefix: true,
|
|
4630
|
-
argument: { type: "Literal", value: 0, raw: "0" }
|
|
4631
|
-
};
|
|
4632
|
-
}
|
|
4633
|
-
return {
|
|
4634
|
-
type: "Literal",
|
|
4635
|
-
value: c,
|
|
4636
|
-
raw: JSON.stringify(c)
|
|
4637
|
-
};
|
|
4638
|
-
});
|
|
4639
|
-
const callArgs = [
|
|
4640
|
-
{
|
|
4641
|
-
type: "ArrayExpression",
|
|
4642
|
-
elements: encBytecode.map((b) => ({
|
|
4643
|
-
type: "Literal",
|
|
4644
|
-
value: b >>> 0,
|
|
4645
|
-
raw: String(b >>> 0)
|
|
4646
|
-
}))
|
|
4647
|
-
},
|
|
4648
|
-
{
|
|
4649
|
-
type: "ArrayExpression",
|
|
4650
|
-
elements: constElements
|
|
4651
|
-
},
|
|
4652
|
-
{
|
|
4653
|
-
type: "ArrayExpression",
|
|
4654
|
-
elements: paramArgs
|
|
4655
|
-
},
|
|
4656
|
-
{
|
|
4657
|
-
type: "ThisExpression"
|
|
4658
|
-
},
|
|
4659
|
-
{
|
|
4660
|
-
type: "Literal",
|
|
4661
|
-
value: fnSalt,
|
|
4662
|
-
raw: String(fnSalt)
|
|
4663
|
-
}
|
|
4664
|
-
];
|
|
4665
|
-
if (compiled.upvalues && compiled.upvalues.length > 0) {
|
|
4666
|
-
const usedParamNames = new Set(enclosingBindings);
|
|
4667
|
-
const upvalueElements = compiled.upvalues.map((uv, uIdx) => {
|
|
4668
|
-
const getterFn = {
|
|
4669
|
-
type: "ArrowFunctionExpression",
|
|
4670
|
-
id: null,
|
|
4671
|
-
params: [],
|
|
4672
|
-
body: { type: "Identifier", name: uv.name },
|
|
4673
|
-
generator: false,
|
|
4674
|
-
async: false,
|
|
4675
|
-
expression: true
|
|
4676
|
-
};
|
|
4677
|
-
if (!uv.isWritten) {
|
|
4678
|
-
return {
|
|
4679
|
-
type: "ArrayExpression",
|
|
4680
|
-
elements: [getterFn]
|
|
4681
|
-
};
|
|
4682
|
-
}
|
|
4683
|
-
let paramName = `_uv${uIdx}`;
|
|
4684
|
-
let suffixIdx = 0;
|
|
4685
|
-
while (usedParamNames.has(paramName) || paramName === uv.name) {
|
|
4686
|
-
paramName = `_uv${uIdx}_${suffixIdx++}`;
|
|
4687
|
-
}
|
|
4688
|
-
usedParamNames.add(paramName);
|
|
4689
|
-
const setterFn = {
|
|
4690
|
-
type: "ArrowFunctionExpression",
|
|
4691
|
-
id: null,
|
|
4692
|
-
params: [{ type: "Identifier", name: paramName }],
|
|
4693
|
-
body: {
|
|
4694
|
-
type: "AssignmentExpression",
|
|
4695
|
-
operator: "=",
|
|
4696
|
-
left: { type: "Identifier", name: uv.name },
|
|
4697
|
-
right: { type: "Identifier", name: paramName }
|
|
4698
|
-
},
|
|
4699
|
-
generator: false,
|
|
4700
|
-
async: false,
|
|
4701
|
-
expression: true
|
|
4702
|
-
};
|
|
4703
|
-
return {
|
|
4704
|
-
type: "ArrayExpression",
|
|
4705
|
-
elements: [getterFn, setterFn]
|
|
4706
|
-
};
|
|
4707
|
-
});
|
|
4708
|
-
callArgs.push({
|
|
4709
|
-
type: "ArrayExpression",
|
|
4710
|
-
elements: upvalueElements
|
|
4711
|
-
});
|
|
4712
|
-
}
|
|
4713
|
-
const callExpr = {
|
|
4714
|
-
type: "CallExpression",
|
|
4715
|
-
callee: {
|
|
4716
|
-
type: "Identifier",
|
|
4717
|
-
name: vmHelperName
|
|
4718
|
-
},
|
|
4719
|
-
arguments: callArgs,
|
|
4720
|
-
optional: false
|
|
4721
|
-
};
|
|
4722
|
-
if (fn.body.type === "BlockStatement") {
|
|
4723
|
-
fn.body.body = [
|
|
4724
|
-
{
|
|
4725
|
-
type: "ReturnStatement",
|
|
4726
|
-
argument: callExpr
|
|
4727
|
-
}
|
|
4728
|
-
];
|
|
4729
|
-
} else {
|
|
4730
|
-
fn.body = callExpr;
|
|
4731
|
-
}
|
|
4732
|
-
virtualizedCount++;
|
|
4733
|
-
}
|
|
4734
|
-
if (virtualizedCount > 0) {
|
|
4735
|
-
const interpreterSource = createInterpreterSource(
|
|
4736
|
-
vmHelperName,
|
|
4737
|
-
opMap,
|
|
4738
|
-
seed,
|
|
4739
|
-
windowKeySymbol,
|
|
4740
|
-
expectedDelta
|
|
4741
|
-
);
|
|
4742
|
-
const parsedHelper = acorn5.parse(interpreterSource, {
|
|
4743
|
-
ecmaVersion: "latest",
|
|
4744
|
-
sourceType: "script"
|
|
4745
|
-
});
|
|
4746
|
-
let insertIdx = 0;
|
|
4747
|
-
while (insertIdx < ast.body.length) {
|
|
4748
|
-
const stmt = ast.body[insertIdx];
|
|
4749
|
-
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim()));
|
|
4750
|
-
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
4751
|
-
insertIdx++;
|
|
4752
|
-
} else {
|
|
4753
|
-
break;
|
|
4754
|
-
}
|
|
4755
|
-
}
|
|
4756
|
-
ast.body.splice(insertIdx, 0, ...parsedHelper.body);
|
|
4757
|
-
}
|
|
4758
|
-
return {
|
|
4759
|
-
virtualizedCount,
|
|
4760
|
-
vmHelperName
|
|
4761
|
-
};
|
|
4762
|
-
}
|
|
4763
|
-
|
|
4764
|
-
// src/ast/index.ts
|
|
4765
|
-
function isAstAlreadyProtected(ast) {
|
|
4766
|
-
if (!ast || !Array.isArray(ast.body)) return false;
|
|
4767
|
-
return ast.body.some((stmt) => {
|
|
4768
|
-
if (stmt.type === "VariableDeclaration" && Array.isArray(stmt.declarations)) {
|
|
4769
|
-
for (const d of stmt.declarations) {
|
|
4770
|
-
const name = d.id?.name;
|
|
4771
|
-
if (typeof name === "string") {
|
|
4772
|
-
if (name === "_d" || name.startsWith("_uC") || name.startsWith("_uD") || name.startsWith("_uS") || name.startsWith("_uVm") || name.startsWith("_wKdf") || name.startsWith("_m") || name.startsWith("_w") || name.startsWith("_k") || name.startsWith("_a") && d.init?.type === "CallExpression" && d.init.callee?.type === "FunctionExpression" && d.init.callee?.id?.name === "f") {
|
|
4773
|
-
return true;
|
|
4774
|
-
}
|
|
4775
|
-
}
|
|
4776
|
-
}
|
|
4777
|
-
}
|
|
4778
|
-
if (stmt.type === "ExpressionStatement" && stmt.expression?.type === "CallExpression") {
|
|
4779
|
-
const callee = stmt.expression.callee;
|
|
4780
|
-
if (callee?.type === "FunctionExpression") {
|
|
4781
|
-
const name = callee.id?.name;
|
|
4782
|
-
if (typeof name === "string" && (name.startsWith("_u$") || name.startsWith("_$") || name.startsWith("_s") || name.startsWith("$b"))) {
|
|
4783
|
-
return true;
|
|
4784
|
-
}
|
|
4785
|
-
}
|
|
4786
|
-
}
|
|
4787
|
-
return false;
|
|
4788
|
-
});
|
|
4789
|
-
}
|
|
4790
|
-
function transformJavaScript(code, options = {}) {
|
|
4791
|
-
const seed = options.seed ?? 2654435769;
|
|
4792
|
-
const minStringLength = options.minStringLength ?? options.config?.vault?.minStringLength ?? 4;
|
|
4793
|
-
const isAggressive = options.aggressive ?? false;
|
|
4794
|
-
if (!code || !code.trim()) {
|
|
4795
|
-
return {
|
|
4796
|
-
code,
|
|
4797
|
-
encryptedStringsCount: 0,
|
|
4798
|
-
mangledSymbolsCount: 0,
|
|
4799
|
-
hotPathReport: {
|
|
4800
|
-
totalFunctions: 0,
|
|
4801
|
-
hotFunctionsSkipped: [],
|
|
4802
|
-
coldFunctionsProtected: []
|
|
4803
|
-
},
|
|
4804
|
-
integrityToken: computeFnv1aHash("", seed),
|
|
4805
|
-
virtualizedFunctionsCount: 0,
|
|
4806
|
-
shaderBuffersCount: 0
|
|
4807
|
-
};
|
|
4808
|
-
}
|
|
4809
|
-
const ast = parseJavaScriptAst(code);
|
|
4810
|
-
if (!ast || isAstAlreadyProtected(ast)) {
|
|
4811
|
-
return {
|
|
4812
|
-
code,
|
|
4813
|
-
encryptedStringsCount: 0,
|
|
4814
|
-
mangledSymbolsCount: 0,
|
|
4815
|
-
hotPathReport: {
|
|
4816
|
-
totalFunctions: 0,
|
|
4817
|
-
hotFunctionsSkipped: [],
|
|
4818
|
-
coldFunctionsProtected: []
|
|
4819
|
-
},
|
|
4820
|
-
integrityToken: computeFnv1aHash(code, seed),
|
|
4821
|
-
virtualizedFunctionsCount: 0,
|
|
4822
|
-
shaderBuffersCount: 0
|
|
4823
|
-
};
|
|
4824
|
-
}
|
|
4825
|
-
const {
|
|
4826
|
-
report: hotPathReport,
|
|
4827
|
-
coldFunctionNodes,
|
|
4828
|
-
hotFunctionNodes,
|
|
4829
|
-
hotExemptNodes,
|
|
4830
|
-
serializedFunctionNodes
|
|
4831
|
-
} = analyzeAstHotPaths(ast, options.config);
|
|
4832
|
-
const shieldCoupled = options.shieldCoupled ?? Boolean(options.injectRuntimeShield);
|
|
4833
|
-
const deterrentMode = options.deterrentMode ?? options.config?.shield?.deterrentMode ?? "passive";
|
|
4834
|
-
const detectHeadless = options.detectHeadless ?? options.config?.shield?.detectHeadless ?? false;
|
|
4835
|
-
const sym = shieldCoupled ? options.windowKeySymbol ?? deriveWindowKeySymbol(seed) : void 0;
|
|
4836
|
-
let shieldDelta = shieldCoupled ? options.expectedDelta : void 0;
|
|
4837
|
-
if (shieldCoupled && shieldDelta === void 0) {
|
|
4838
|
-
const shieldInfo = generateRuntimeShield({
|
|
4839
|
-
seed,
|
|
4840
|
-
windowKeySymbol: sym,
|
|
4841
|
-
deterrentMode,
|
|
4842
|
-
detectHeadless
|
|
4843
|
-
});
|
|
4844
|
-
shieldDelta = shieldInfo.expectedDelta ?? 0;
|
|
4845
|
-
}
|
|
4846
|
-
let virtualizedFunctionsCount = 0;
|
|
4847
|
-
if (isAggressive) {
|
|
4848
|
-
const vmRes = applyMicroVm(
|
|
4849
|
-
ast,
|
|
4850
|
-
coldFunctionNodes,
|
|
4851
|
-
serializedFunctionNodes,
|
|
4852
|
-
seed,
|
|
4853
|
-
sym,
|
|
4854
|
-
shieldDelta
|
|
4855
|
-
);
|
|
4856
|
-
virtualizedFunctionsCount = vmRes.virtualizedCount;
|
|
4857
|
-
}
|
|
4858
|
-
applyColdFlowGuard(ast, coldFunctionNodes, seed, hotExemptNodes);
|
|
4859
|
-
const mangledSymbolsCount = applyPolymorphicMangler(
|
|
4860
|
-
ast,
|
|
4861
|
-
seed,
|
|
4862
|
-
serializedFunctionNodes,
|
|
4863
|
-
options.config
|
|
4864
|
-
);
|
|
4865
|
-
let encryptedStringsCount = 0;
|
|
4866
|
-
let integrityToken = 0;
|
|
4867
|
-
let shaderBuffersCount = 0;
|
|
4868
|
-
if (isAggressive) {
|
|
4869
|
-
const saltedRes = applySaltedStringVault(
|
|
4870
|
-
ast,
|
|
4871
|
-
seed,
|
|
4872
|
-
minStringLength,
|
|
4873
|
-
hotExemptNodes,
|
|
4874
|
-
options.config,
|
|
4875
|
-
sym,
|
|
4876
|
-
shieldDelta,
|
|
4877
|
-
deterrentMode,
|
|
4878
|
-
shieldCoupled,
|
|
4879
|
-
detectHeadless
|
|
4880
|
-
);
|
|
4881
|
-
encryptedStringsCount = saltedRes.encryptedStringsCount;
|
|
4882
|
-
integrityToken = saltedRes.integrityToken;
|
|
4883
|
-
} else {
|
|
4884
|
-
const vaultRes = applyStringVault(
|
|
4885
|
-
ast,
|
|
4886
|
-
seed,
|
|
4887
|
-
minStringLength,
|
|
4888
|
-
hotExemptNodes,
|
|
4889
|
-
sym,
|
|
4890
|
-
shieldDelta,
|
|
4891
|
-
deterrentMode,
|
|
4892
|
-
options.config,
|
|
4893
|
-
shieldCoupled,
|
|
4894
|
-
detectHeadless
|
|
4895
|
-
);
|
|
4896
|
-
encryptedStringsCount = vaultRes.encryptedStringsCount;
|
|
4897
|
-
integrityToken = vaultRes.integrityToken;
|
|
4898
|
-
shaderBuffersCount = vaultRes.shaderBuffersCount ?? 0;
|
|
4899
|
-
}
|
|
4900
|
-
const outputCode = generateCompactJs(ast);
|
|
4901
|
-
let finalCode = outputCode;
|
|
4902
|
-
if (options.injectRuntimeShield && !options.skipShieldPreamble) {
|
|
4903
|
-
const shield = generateRuntimeShield({
|
|
4904
|
-
seed,
|
|
4905
|
-
windowKeySymbol: sym,
|
|
4906
|
-
expectedDelta: shieldDelta,
|
|
4907
|
-
deterrentMode,
|
|
4908
|
-
detectHeadless,
|
|
4909
|
-
expectedIntegrityHash: integrityToken
|
|
4910
|
-
});
|
|
4911
|
-
if (shield.preambleCode) {
|
|
4912
|
-
finalCode = `${shield.preambleCode}
|
|
4913
|
-
${finalCode}`;
|
|
4914
|
-
}
|
|
4915
|
-
}
|
|
4916
|
-
return {
|
|
4917
|
-
code: finalCode,
|
|
4918
|
-
encryptedStringsCount,
|
|
4919
|
-
mangledSymbolsCount,
|
|
4920
|
-
hotPathReport,
|
|
4921
|
-
integrityToken,
|
|
4922
|
-
virtualizedFunctionsCount,
|
|
4923
|
-
shaderBuffersCount
|
|
4924
|
-
};
|
|
4925
|
-
}
|
|
4926
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
4927
|
-
0 && (module.exports = {
|
|
4928
|
-
analyzeAstHotPaths,
|
|
4929
|
-
applyColdFlowGuard,
|
|
4930
|
-
applyMicroVm,
|
|
4931
|
-
applyPolymorphicMangler,
|
|
4932
|
-
applySaltedStringVault,
|
|
4933
|
-
applyStringVault,
|
|
4934
|
-
computeFnv1aHash,
|
|
4935
|
-
derivePolymorphicIdent,
|
|
4936
|
-
detectHotPaths,
|
|
4937
|
-
generateCompactJs,
|
|
4938
|
-
injectWasmVault,
|
|
4939
|
-
transformJavaScript
|
|
4940
|
-
});
|
|
4941
|
-
//# sourceMappingURL=index.cjs.map
|
|
17
|
+
exports.UnpeekError = _chunkR6EBIR3Tcjs.UnpeekError; exports.computeFnv1aHash = _chunk6N6S6WTQcjs.computeFnv1aHash; exports.detectHotPaths = _chunkLXP73HJCcjs.detectHotPaths; exports.transformJavaScript = _chunkLXP73HJCcjs.transformJavaScript;
|