unpeek 1.6.1 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast/index.cjs +531 -99
- package/dist/ast/index.cjs.map +1 -1
- package/dist/ast/index.js +531 -99
- package/dist/ast/index.js.map +1 -1
- package/dist/browser.cjs +531 -99
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +531 -99
- package/dist/browser.js.map +1 -1
- package/dist/bundler/unplugin.cjs +531 -99
- package/dist/bundler/unplugin.cjs.map +1 -1
- package/dist/bundler/unplugin.js +531 -99
- package/dist/bundler/unplugin.js.map +1 -1
- package/dist/cli/index.cjs +532 -100
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +532 -100
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/protect.cjs +531 -99
- package/dist/cli/protect.cjs.map +1 -1
- package/dist/cli/protect.js +531 -99
- package/dist/cli/protect.js.map +1 -1
- package/dist/esbuild.cjs +531 -99
- package/dist/esbuild.cjs.map +1 -1
- package/dist/esbuild.js +531 -99
- package/dist/esbuild.js.map +1 -1
- package/dist/index.cjs +532 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +532 -100
- package/dist/index.js.map +1 -1
- package/dist/rollup.cjs +531 -99
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.js +531 -99
- package/dist/rollup.js.map +1 -1
- package/dist/runtime/index.cjs +2 -15
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +2 -15
- package/dist/runtime/index.js.map +1 -1
- package/dist/vite.cjs +531 -99
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js +531 -99
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +531 -99
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.js +531 -99
- package/dist/webpack.js.map +1 -1
- package/package.json +1 -1
package/dist/ast/index.cjs
CHANGED
|
@@ -128,15 +128,100 @@ function analyzeAstHotPaths(ast) {
|
|
|
128
128
|
const coldFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
129
129
|
const hotExemptNodes = /* @__PURE__ */ new WeakSet();
|
|
130
130
|
const directHotNodes = /* @__PURE__ */ new Set();
|
|
131
|
+
const serializedFunctionNodes = /* @__PURE__ */ new Set();
|
|
132
|
+
const serializerHelperNodes = /* @__PURE__ */ new Set();
|
|
131
133
|
const allFunctions = [];
|
|
132
134
|
const fnByName = /* @__PURE__ */ new Map();
|
|
133
135
|
const scopeFunctions = /* @__PURE__ */ new Map();
|
|
134
136
|
const fnScopeChain = /* @__PURE__ */ new Map();
|
|
137
|
+
const fnParams = /* @__PURE__ */ new Map();
|
|
138
|
+
const fnVarAliases = /* @__PURE__ */ new Map();
|
|
135
139
|
const callerToCallees = /* @__PURE__ */ new Map();
|
|
140
|
+
const pendingSerializedRefs = [];
|
|
141
|
+
const allCallSites = [];
|
|
142
|
+
function ensureFnParams(fnNode) {
|
|
143
|
+
let paramSet = fnParams.get(fnNode);
|
|
144
|
+
if (!paramSet) {
|
|
145
|
+
paramSet = /* @__PURE__ */ new Set();
|
|
146
|
+
for (const p of fnNode.params || []) {
|
|
147
|
+
if (p?.type === "Identifier") {
|
|
148
|
+
paramSet.add(p.name);
|
|
149
|
+
} else if (p?.type === "AssignmentPattern" && p.left?.type === "Identifier") {
|
|
150
|
+
paramSet.add(p.left.name);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
fnParams.set(fnNode, paramSet);
|
|
154
|
+
}
|
|
155
|
+
return paramSet;
|
|
156
|
+
}
|
|
157
|
+
function recordVarAlias(scopeNode, varName, rhsName) {
|
|
158
|
+
let map = fnVarAliases.get(scopeNode);
|
|
159
|
+
if (!map) {
|
|
160
|
+
map = /* @__PURE__ */ new Map();
|
|
161
|
+
fnVarAliases.set(scopeNode, map);
|
|
162
|
+
}
|
|
163
|
+
map.set(varName, rhsName);
|
|
164
|
+
}
|
|
165
|
+
function resolveAliasTarget(scopeNode, identName) {
|
|
166
|
+
const map = fnVarAliases.get(scopeNode);
|
|
167
|
+
let cur = identName;
|
|
168
|
+
const seen = /* @__PURE__ */ new Set();
|
|
169
|
+
while (map && map.has(cur) && !seen.has(cur)) {
|
|
170
|
+
seen.add(cur);
|
|
171
|
+
cur = map.get(cur);
|
|
172
|
+
}
|
|
173
|
+
return cur;
|
|
174
|
+
}
|
|
175
|
+
function markSerializedFunction(node) {
|
|
176
|
+
serializedFunctionNodes.add(node);
|
|
177
|
+
hotFunctionNodes.add(node);
|
|
178
|
+
directHotNodes.add(node);
|
|
179
|
+
hotExemptNodes.add(node);
|
|
180
|
+
}
|
|
181
|
+
function findEnclosingFunction(ancestors, selfNode) {
|
|
182
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
183
|
+
if (ancestors[i] !== selfNode && FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
184
|
+
return ancestors[i];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
function findOutermostModuleFunction(ancestors) {
|
|
190
|
+
const fnList = [];
|
|
191
|
+
for (let i = 0; i < ancestors.length; i++) {
|
|
192
|
+
if (FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
193
|
+
fnList.push(ancestors[i]);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (fnList.length === 0) return null;
|
|
197
|
+
if (fnList.length === 1) return fnList[0];
|
|
198
|
+
return fnList[1];
|
|
199
|
+
}
|
|
200
|
+
function isZeroArgIifeFactoryFunction(node) {
|
|
201
|
+
if (!node || node.params && node.params.length > 0) return false;
|
|
202
|
+
if (!node.body || node.body.type !== "BlockStatement") return false;
|
|
203
|
+
const stmts = (node.body.body || []).filter(
|
|
204
|
+
(s) => !(s.type === "ExpressionStatement" && s.directive)
|
|
205
|
+
);
|
|
206
|
+
if (stmts.length !== 1 || stmts[0].type !== "ReturnStatement") return false;
|
|
207
|
+
const retArg = stmts[0].argument;
|
|
208
|
+
if (!retArg || retArg.type !== "CallExpression") return false;
|
|
209
|
+
const callee = retArg.callee;
|
|
210
|
+
return callee && (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") && callee.body?.type === "BlockStatement";
|
|
211
|
+
}
|
|
136
212
|
function registerFunctionNode(node, ancestors) {
|
|
137
213
|
const name = getFunctionLabel(node, ancestors);
|
|
138
214
|
allFunctions.push({ node, name });
|
|
139
215
|
fnByName.set(name, node);
|
|
216
|
+
const paramSet = /* @__PURE__ */ new Set();
|
|
217
|
+
for (const p of node.params || []) {
|
|
218
|
+
if (p?.type === "Identifier") {
|
|
219
|
+
paramSet.add(p.name);
|
|
220
|
+
} else if (p?.type === "AssignmentPattern" && p.left?.type === "Identifier") {
|
|
221
|
+
paramSet.add(p.left.name);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
fnParams.set(node, paramSet);
|
|
140
225
|
const enclosingScope = findEnclosingScopeNode(ancestors, node);
|
|
141
226
|
let localMap = scopeFunctions.get(enclosingScope);
|
|
142
227
|
if (!localMap) {
|
|
@@ -145,6 +230,22 @@ function analyzeAstHotPaths(ast) {
|
|
|
145
230
|
}
|
|
146
231
|
localMap.set(name, node);
|
|
147
232
|
const parent = ancestors[ancestors.length - 2];
|
|
233
|
+
if (parent?.type === "VariableDeclarator" && parent.id?.type === "Identifier") {
|
|
234
|
+
fnByName.set(parent.id.name, node);
|
|
235
|
+
localMap.set(parent.id.name, node);
|
|
236
|
+
} else if (parent?.type === "AssignmentExpression" && parent.left?.type === "Identifier") {
|
|
237
|
+
fnByName.set(parent.left.name, node);
|
|
238
|
+
localMap.set(parent.left.name, node);
|
|
239
|
+
} else if (parent?.type === "AssignmentExpression" && parent.left?.type === "MemberExpression" && !parent.left.computed && parent.left.property?.type === "Identifier") {
|
|
240
|
+
const propName = parent.left.property.name;
|
|
241
|
+
fnByName.set(propName, node);
|
|
242
|
+
localMap.set(propName, node);
|
|
243
|
+
if (parent.left.object?.type === "Identifier") {
|
|
244
|
+
const qual = `${parent.left.object.name}.${propName}`;
|
|
245
|
+
fnByName.set(qual, node);
|
|
246
|
+
localMap.set(qual, node);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
148
249
|
const grandParent = ancestors[ancestors.length - 3];
|
|
149
250
|
const greatGrandParent = ancestors[ancestors.length - 4];
|
|
150
251
|
if (parent?.type === "Property" && parent.key?.type === "Identifier" && grandParent?.type === "ObjectExpression" && greatGrandParent?.type === "VariableDeclarator" && greatGrandParent.id?.type === "Identifier") {
|
|
@@ -154,7 +255,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
154
255
|
}
|
|
155
256
|
const chain = [];
|
|
156
257
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
157
|
-
if (FUNCTION_NODE_TYPES.has(ancestors[i].type) || ancestors[i].type === "Program") {
|
|
258
|
+
if (ancestors[i] !== node && (FUNCTION_NODE_TYPES.has(ancestors[i].type) || ancestors[i].type === "Program")) {
|
|
158
259
|
chain.push(ancestors[i]);
|
|
159
260
|
}
|
|
160
261
|
}
|
|
@@ -163,8 +264,13 @@ function analyzeAstHotPaths(ast) {
|
|
|
163
264
|
hotFunctionNodes.add(node);
|
|
164
265
|
directHotNodes.add(node);
|
|
165
266
|
}
|
|
267
|
+
if (isZeroArgIifeFactoryFunction(node)) {
|
|
268
|
+
markSerializedFunction(node);
|
|
269
|
+
}
|
|
166
270
|
}
|
|
167
271
|
function resolveCalleeNode(callerNode, calleeKey) {
|
|
272
|
+
const directLocal = scopeFunctions.get(callerNode)?.get(calleeKey);
|
|
273
|
+
if (directLocal) return directLocal;
|
|
168
274
|
const chain = fnScopeChain.get(callerNode);
|
|
169
275
|
if (chain) {
|
|
170
276
|
for (const scopeNode of chain) {
|
|
@@ -175,6 +281,25 @@ function analyzeAstHotPaths(ast) {
|
|
|
175
281
|
}
|
|
176
282
|
return fnByName.get(calleeKey);
|
|
177
283
|
}
|
|
284
|
+
function queueSerializedTarget(target, enclosingScope) {
|
|
285
|
+
if (!target) return;
|
|
286
|
+
if (FUNCTION_NODE_TYPES.has(target.type)) {
|
|
287
|
+
markSerializedFunction(target);
|
|
288
|
+
} else if (target.type === "Identifier") {
|
|
289
|
+
pendingSerializedRefs.push({ scopeNode: enclosingScope, name: target.name });
|
|
290
|
+
} else if (target.type === "MemberExpression" && !target.computed && target.property?.type === "Identifier") {
|
|
291
|
+
pendingSerializedRefs.push({
|
|
292
|
+
scopeNode: enclosingScope,
|
|
293
|
+
name: target.property.name
|
|
294
|
+
});
|
|
295
|
+
if (target.object?.type === "Identifier") {
|
|
296
|
+
pendingSerializedRefs.push({
|
|
297
|
+
scopeNode: enclosingScope,
|
|
298
|
+
name: `${target.object.name}.${target.property.name}`
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
178
303
|
walk.ancestor(ast, {
|
|
179
304
|
FunctionDeclaration(node, _state, ancestors) {
|
|
180
305
|
registerFunctionNode(node, ancestors);
|
|
@@ -185,6 +310,59 @@ function analyzeAstHotPaths(ast) {
|
|
|
185
310
|
ArrowFunctionExpression(node, _state, ancestors) {
|
|
186
311
|
registerFunctionNode(node, ancestors);
|
|
187
312
|
},
|
|
313
|
+
VariableDeclarator(node, _state, ancestors) {
|
|
314
|
+
if (node.id?.type === "Identifier" && node.init?.type === "Identifier") {
|
|
315
|
+
const scopeNode = findEnclosingFunction(ancestors) ?? ast;
|
|
316
|
+
recordVarAlias(scopeNode, node.id.name, node.init.name);
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
AssignmentExpression(node, _state, ancestors) {
|
|
320
|
+
const left = node.left;
|
|
321
|
+
if (left?.type === "Identifier" && node.right?.type === "Identifier") {
|
|
322
|
+
const scopeNode = findEnclosingFunction(ancestors) ?? ast;
|
|
323
|
+
recordVarAlias(scopeNode, left.name, node.right.name);
|
|
324
|
+
}
|
|
325
|
+
const isBareOnMessage = left?.type === "Identifier" && left.name === "onmessage";
|
|
326
|
+
const isSelfOnMessage = left?.type === "MemberExpression" && !left.computed && left.object?.type === "Identifier" && left.object.name === "self" && left.property?.type === "Identifier" && left.property.name === "onmessage";
|
|
327
|
+
if (isBareOnMessage || isSelfOnMessage) {
|
|
328
|
+
const enclosingFn = findEnclosingFunction(ancestors);
|
|
329
|
+
if (enclosingFn) {
|
|
330
|
+
markSerializedFunction(enclosingFn);
|
|
331
|
+
}
|
|
332
|
+
const outerFn = findOutermostModuleFunction(ancestors);
|
|
333
|
+
if (outerFn) {
|
|
334
|
+
markSerializedFunction(outerFn);
|
|
335
|
+
}
|
|
336
|
+
const scopeNode = enclosingFn ?? ast;
|
|
337
|
+
queueSerializedTarget(node.right, scopeNode);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
ObjectExpression(node, _state, ancestors) {
|
|
341
|
+
const props = node.properties || [];
|
|
342
|
+
const propMap = /* @__PURE__ */ new Map();
|
|
343
|
+
for (const p of props) {
|
|
344
|
+
if (p?.type === "Property" && !p.computed) {
|
|
345
|
+
const keyName = p.key?.type === "Identifier" ? p.key.name : p.key?.type === "Literal" ? String(p.key.value) : "";
|
|
346
|
+
if (keyName) {
|
|
347
|
+
propMap.set(keyName, p.value);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const hasWorkerDescriptorShape = propMap.has("init") && propMap.has("dependencies") || propMap.has("isWorkerModule") || propMap.has("getTransferables") && (propMap.has("init") || propMap.has("dependencies"));
|
|
352
|
+
if (hasWorkerDescriptorShape) {
|
|
353
|
+
const scopeNode = findEnclosingFunction(ancestors) ?? ast;
|
|
354
|
+
for (const key of ["init", "getTransferables", "worker"]) {
|
|
355
|
+
const val = propMap.get(key);
|
|
356
|
+
if (val) queueSerializedTarget(val, scopeNode);
|
|
357
|
+
}
|
|
358
|
+
const deps = propMap.get("dependencies");
|
|
359
|
+
if (deps?.type === "ArrayExpression") {
|
|
360
|
+
for (const el of deps.elements || []) {
|
|
361
|
+
if (el) queueSerializedTarget(el, scopeNode);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
},
|
|
188
366
|
CallExpression(node, _state, ancestors) {
|
|
189
367
|
const callee = node.callee;
|
|
190
368
|
let calleeName = "";
|
|
@@ -201,38 +379,76 @@ function analyzeAstHotPaths(ast) {
|
|
|
201
379
|
qualifiedCall = memberProp;
|
|
202
380
|
}
|
|
203
381
|
}
|
|
382
|
+
const enclosingFn = findEnclosingFunction(ancestors);
|
|
383
|
+
const currentScope = enclosingFn ?? ast;
|
|
204
384
|
if (qualifiedCall || memberProp) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
385
|
+
allCallSites.push({
|
|
386
|
+
scopeNode: currentScope,
|
|
387
|
+
calleeKey: qualifiedCall || memberProp,
|
|
388
|
+
args: node.arguments || []
|
|
389
|
+
});
|
|
390
|
+
if (enclosingFn) {
|
|
391
|
+
let set = callerToCallees.get(enclosingFn);
|
|
392
|
+
if (!set) {
|
|
393
|
+
set = /* @__PURE__ */ new Set();
|
|
394
|
+
callerToCallees.set(enclosingFn, set);
|
|
395
|
+
}
|
|
396
|
+
if (qualifiedCall) set.add(qualifiedCall);
|
|
397
|
+
if (memberProp && !ARRAY_HOF_METHODS.has(memberProp)) {
|
|
398
|
+
set.add(memberProp);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (memberProp === "toString" && (!node.arguments || node.arguments.length === 0) && callee?.type === "MemberExpression") {
|
|
403
|
+
const targetObj = callee.object;
|
|
404
|
+
queueSerializedTarget(targetObj, currentScope);
|
|
405
|
+
if (targetObj?.type === "Identifier" && enclosingFn) {
|
|
406
|
+
const resolvedName = resolveAliasTarget(enclosingFn, targetObj.name);
|
|
407
|
+
if (ensureFnParams(enclosingFn).has(resolvedName)) {
|
|
408
|
+
serializerHelperNodes.add(enclosingFn);
|
|
409
|
+
}
|
|
410
|
+
if (resolvedName !== targetObj.name) {
|
|
411
|
+
queueSerializedTarget({ type: "Identifier", name: resolvedName }, currentScope);
|
|
217
412
|
}
|
|
218
413
|
}
|
|
219
414
|
}
|
|
415
|
+
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) {
|
|
416
|
+
const firstArg = node.arguments[0];
|
|
417
|
+
queueSerializedTarget(firstArg, currentScope);
|
|
418
|
+
if (firstArg?.type === "Identifier" && enclosingFn) {
|
|
419
|
+
const resolvedName = resolveAliasTarget(enclosingFn, firstArg.name);
|
|
420
|
+
if (ensureFnParams(enclosingFn).has(resolvedName)) {
|
|
421
|
+
serializerHelperNodes.add(enclosingFn);
|
|
422
|
+
}
|
|
423
|
+
if (resolvedName !== firstArg.name) {
|
|
424
|
+
queueSerializedTarget({ type: "Identifier", name: resolvedName }, currentScope);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (calleeName === "importScripts" || memberProp === "importScripts" && callee?.object?.type === "Identifier" && callee.object.name === "self") {
|
|
429
|
+
if (enclosingFn) markSerializedFunction(enclosingFn);
|
|
430
|
+
const outerFn = findOutermostModuleFunction(ancestors);
|
|
431
|
+
if (outerFn) markSerializedFunction(outerFn);
|
|
432
|
+
}
|
|
220
433
|
if (ARRAY_HOF_METHODS.has(memberProp) || calleeName === "requestAnimationFrame" || memberProp === "requestAnimationFrame" || calleeName === "cancelAnimationFrame" || memberProp === "cancelAnimationFrame") {
|
|
221
434
|
for (const arg of node.arguments || []) {
|
|
222
435
|
if (FUNCTION_NODE_TYPES.has(arg.type)) {
|
|
223
436
|
hotFunctionNodes.add(arg);
|
|
224
437
|
directHotNodes.add(arg);
|
|
225
438
|
hotExemptNodes.add(arg);
|
|
439
|
+
} else if (arg?.type === "Identifier") {
|
|
440
|
+
allCallSites.push({
|
|
441
|
+
scopeNode: currentScope,
|
|
442
|
+
calleeKey: arg.name,
|
|
443
|
+
args: [arg]
|
|
444
|
+
});
|
|
226
445
|
}
|
|
227
446
|
}
|
|
228
447
|
}
|
|
229
448
|
if (UI_HOOK_OR_RENDER_CALLS.has(calleeName) || UI_HOOK_OR_RENDER_CALLS.has(memberProp)) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
directHotNodes.add(ancestors[i]);
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
449
|
+
if (enclosingFn) {
|
|
450
|
+
hotFunctionNodes.add(enclosingFn);
|
|
451
|
+
directHotNodes.add(enclosingFn);
|
|
236
452
|
}
|
|
237
453
|
}
|
|
238
454
|
},
|
|
@@ -257,10 +473,41 @@ function analyzeAstHotPaths(ast) {
|
|
|
257
473
|
markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
|
|
258
474
|
}
|
|
259
475
|
});
|
|
476
|
+
for (const callSite of allCallSites) {
|
|
477
|
+
const resolvedCallee = resolveCalleeNode(callSite.scopeNode, callSite.calleeKey);
|
|
478
|
+
if (resolvedCallee && serializerHelperNodes.has(resolvedCallee)) {
|
|
479
|
+
for (const arg of callSite.args) {
|
|
480
|
+
queueSerializedTarget(arg, callSite.scopeNode);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
for (const ref of pendingSerializedRefs) {
|
|
485
|
+
const targetNode = resolveCalleeNode(ref.scopeNode, ref.name);
|
|
486
|
+
if (targetNode) {
|
|
487
|
+
markSerializedFunction(targetNode);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
260
490
|
const forwardHotSet = new Set(directHotNodes);
|
|
261
491
|
let forwardChanged = true;
|
|
262
492
|
while (forwardChanged) {
|
|
263
493
|
forwardChanged = false;
|
|
494
|
+
for (const fn of allFunctions) {
|
|
495
|
+
if (forwardHotSet.has(fn.node)) continue;
|
|
496
|
+
const chain = fnScopeChain.get(fn.node);
|
|
497
|
+
if (!chain) continue;
|
|
498
|
+
for (const anc of chain) {
|
|
499
|
+
if (anc !== fn.node && (serializedFunctionNodes.has(anc) || forwardHotSet.has(anc))) {
|
|
500
|
+
forwardHotSet.add(fn.node);
|
|
501
|
+
hotFunctionNodes.add(fn.node);
|
|
502
|
+
hotExemptNodes.add(fn.node);
|
|
503
|
+
if (serializedFunctionNodes.has(anc)) {
|
|
504
|
+
serializedFunctionNodes.add(fn.node);
|
|
505
|
+
}
|
|
506
|
+
forwardChanged = true;
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
264
511
|
for (const callerNode of Array.from(forwardHotSet)) {
|
|
265
512
|
const calleeNames = callerToCallees.get(callerNode);
|
|
266
513
|
if (!calleeNames) continue;
|
|
@@ -270,6 +517,9 @@ function analyzeAstHotPaths(ast) {
|
|
|
270
517
|
forwardHotSet.add(targetNode);
|
|
271
518
|
hotFunctionNodes.add(targetNode);
|
|
272
519
|
hotExemptNodes.add(targetNode);
|
|
520
|
+
if (serializedFunctionNodes.has(callerNode)) {
|
|
521
|
+
serializedFunctionNodes.add(targetNode);
|
|
522
|
+
}
|
|
273
523
|
forwardChanged = true;
|
|
274
524
|
}
|
|
275
525
|
}
|
|
@@ -344,27 +594,25 @@ var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
|
344
594
|
"use asm"
|
|
345
595
|
]);
|
|
346
596
|
var HELPER_TEMPLATE = acorn2.parse(
|
|
347
|
-
`var _ =
|
|
348
|
-
var s = "";
|
|
349
|
-
for (var j = 0; j < a.length; j++) {
|
|
350
|
-
s += String.fromCharCode(a.charCodeAt(j) ^ (((0 ^ ((a._u || /\\n/.test(f) * 14) | ((j & 1) * 0))) & 30) | 1));
|
|
351
|
-
}
|
|
352
|
-
return s;
|
|
353
|
-
});`,
|
|
597
|
+
`var _ = (function f(a){return a.map(function(s){var o="";for(var j=0;j<s.length;j++)o+=String.fromCharCode(s.charCodeAt(j)^(((0^((a._u||/\\n/.test(f)*14)|((j&1)*0)))&30)|1));return o;});})([]);`,
|
|
354
598
|
{ ecmaVersion: "latest", sourceType: "script" }
|
|
355
599
|
).body[0];
|
|
356
600
|
function createVaultHelperAst(cacheVarName, encryptedPayloads, mask, step) {
|
|
357
601
|
const node = structuredClone(HELPER_TEMPLATE);
|
|
358
602
|
node.declarations[0].id.name = cacheVarName;
|
|
359
|
-
node.declarations[0].init.
|
|
603
|
+
node.declarations[0].init.arguments[0].elements = encryptedPayloads.map(
|
|
360
604
|
(str) => ({
|
|
361
605
|
type: "Literal",
|
|
362
606
|
value: str,
|
|
363
607
|
raw: JSON.stringify(str)
|
|
364
608
|
})
|
|
365
609
|
);
|
|
366
|
-
const
|
|
367
|
-
const
|
|
610
|
+
const outerFn = node.declarations[0].init.callee;
|
|
611
|
+
const returnStmt = outerFn.body.body[0];
|
|
612
|
+
const innerFn = returnStmt.argument.arguments[0];
|
|
613
|
+
const forStmt = innerFn.body.body[1];
|
|
614
|
+
const expr = forStmt.body.type === "BlockStatement" ? forStmt.body.body[0].expression : forStmt.body.expression;
|
|
615
|
+
const binaryXor = expr.right.arguments[0];
|
|
368
616
|
const innerLeft = binaryXor.right.left.left;
|
|
369
617
|
innerLeft.left.value = mask;
|
|
370
618
|
innerLeft.left.raw = String(mask);
|
|
@@ -402,44 +650,58 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
402
650
|
};
|
|
403
651
|
}
|
|
404
652
|
const mask = seed >>> 0 & 30 | 3;
|
|
405
|
-
const step =
|
|
653
|
+
const step = 1;
|
|
406
654
|
const stringToIndex = /* @__PURE__ */ new Map();
|
|
407
655
|
const encryptedPayloads = [];
|
|
408
656
|
const targetsToReplace = [];
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
657
|
+
const customWalkBase = {
|
|
658
|
+
...walk2.base,
|
|
659
|
+
Property(node, st, c) {
|
|
660
|
+
c(node.key, st);
|
|
661
|
+
if (node.value) c(node.value, st);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
walk2.ancestor(
|
|
665
|
+
ast,
|
|
666
|
+
{
|
|
667
|
+
Literal(node, _state, ancestors) {
|
|
668
|
+
if (typeof node.value !== "string") return;
|
|
669
|
+
const val = node.value;
|
|
670
|
+
if (val.length < minStringLength) return;
|
|
671
|
+
if (DIRECTIVE_STRINGS.has(val)) return;
|
|
672
|
+
if (hotExemptNodes) {
|
|
673
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
674
|
+
if (hotExemptNodes.has(ancestors[i])) {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
419
677
|
}
|
|
420
678
|
}
|
|
679
|
+
const parent = ancestors[ancestors.length - 2];
|
|
680
|
+
if (!parent) return;
|
|
681
|
+
if (parent.type === "ExpressionStatement" && parent.directive) return;
|
|
682
|
+
if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
|
|
683
|
+
if (parent.source === node) return;
|
|
684
|
+
}
|
|
685
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (parent.type === "Property" && parent.key === node) {
|
|
689
|
+
parent.computed = true;
|
|
690
|
+
}
|
|
691
|
+
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
let idx = stringToIndex.get(val);
|
|
695
|
+
if (idx === void 0) {
|
|
696
|
+
idx = encryptedPayloads.length;
|
|
697
|
+
stringToIndex.set(val, idx);
|
|
698
|
+
encryptedPayloads.push(encodeStringWithSeed(val, mask, step));
|
|
699
|
+
}
|
|
700
|
+
targetsToReplace.push({ node, parent });
|
|
421
701
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
|
|
426
|
-
if (parent.source === node) return;
|
|
427
|
-
}
|
|
428
|
-
if ((parent.type === "Property" || parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
let idx = stringToIndex.get(val);
|
|
435
|
-
if (idx === void 0) {
|
|
436
|
-
idx = encryptedPayloads.length;
|
|
437
|
-
stringToIndex.set(val, idx);
|
|
438
|
-
encryptedPayloads.push(encodeStringWithSeed(val, mask, step));
|
|
439
|
-
}
|
|
440
|
-
targetsToReplace.push({ node });
|
|
441
|
-
}
|
|
442
|
-
});
|
|
702
|
+
},
|
|
703
|
+
customWalkBase
|
|
704
|
+
);
|
|
443
705
|
if (targetsToReplace.length === 0 || encryptedPayloads.length === 0) {
|
|
444
706
|
return {
|
|
445
707
|
encryptedStringsCount: 0,
|
|
@@ -450,7 +712,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
450
712
|
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
451
713
|
const suffix = computeFnv1aHash(`vault:${seed}`, integrityToken).toString(36);
|
|
452
714
|
const cacheVarName = `_uC${suffix}`;
|
|
453
|
-
for (const { node } of targetsToReplace) {
|
|
715
|
+
for (const { node, parent } of targetsToReplace) {
|
|
716
|
+
if (parent?.type === "Property" && parent.key === node) {
|
|
717
|
+
parent.computed = true;
|
|
718
|
+
}
|
|
454
719
|
const idx = stringToIndex.get(node.value);
|
|
455
720
|
node.type = "MemberExpression";
|
|
456
721
|
node.object = {
|
|
@@ -915,10 +1180,174 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
|
|
|
915
1180
|
|
|
916
1181
|
// src/ast/cold-flow-guard.ts
|
|
917
1182
|
var walk4 = __toESM(require("acorn-walk"), 1);
|
|
918
|
-
function
|
|
919
|
-
const
|
|
920
|
-
|
|
921
|
-
|
|
1183
|
+
function createDecoyConsequent(fnIndex) {
|
|
1184
|
+
const model = Math.abs(fnIndex) % 3;
|
|
1185
|
+
if (model === 0) {
|
|
1186
|
+
return {
|
|
1187
|
+
type: "BlockStatement",
|
|
1188
|
+
body: [
|
|
1189
|
+
{
|
|
1190
|
+
type: "ReturnStatement",
|
|
1191
|
+
argument: {
|
|
1192
|
+
type: "ObjectExpression",
|
|
1193
|
+
properties: [
|
|
1194
|
+
{
|
|
1195
|
+
type: "Property",
|
|
1196
|
+
key: { type: "Identifier", name: "endpoint" },
|
|
1197
|
+
value: {
|
|
1198
|
+
type: "Literal",
|
|
1199
|
+
value: "/api/v2/auth/admin-bypass",
|
|
1200
|
+
raw: '"/api/v2/auth/admin-bypass"'
|
|
1201
|
+
},
|
|
1202
|
+
kind: "init",
|
|
1203
|
+
computed: false,
|
|
1204
|
+
method: false,
|
|
1205
|
+
shorthand: false
|
|
1206
|
+
},
|
|
1207
|
+
{
|
|
1208
|
+
type: "Property",
|
|
1209
|
+
key: { type: "Identifier", name: "superadmin_token" },
|
|
1210
|
+
value: { type: "Literal", value: 1, raw: "1" },
|
|
1211
|
+
kind: "init",
|
|
1212
|
+
computed: false,
|
|
1213
|
+
method: false,
|
|
1214
|
+
shorthand: false
|
|
1215
|
+
},
|
|
1216
|
+
{
|
|
1217
|
+
type: "Property",
|
|
1218
|
+
key: { type: "Identifier", name: "elevate" },
|
|
1219
|
+
value: { type: "Literal", value: 1, raw: "1" },
|
|
1220
|
+
kind: "init",
|
|
1221
|
+
computed: false,
|
|
1222
|
+
method: false,
|
|
1223
|
+
shorthand: false
|
|
1224
|
+
}
|
|
1225
|
+
]
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
]
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
if (model === 1) {
|
|
1232
|
+
return {
|
|
1233
|
+
type: "BlockStatement",
|
|
1234
|
+
body: [
|
|
1235
|
+
{
|
|
1236
|
+
type: "ReturnStatement",
|
|
1237
|
+
argument: {
|
|
1238
|
+
type: "ObjectExpression",
|
|
1239
|
+
properties: [
|
|
1240
|
+
{
|
|
1241
|
+
type: "Property",
|
|
1242
|
+
key: { type: "Identifier", name: "endpoint" },
|
|
1243
|
+
value: {
|
|
1244
|
+
type: "Literal",
|
|
1245
|
+
value: "/api/v2/auth/verify-master",
|
|
1246
|
+
raw: '"/api/v2/auth/verify-master"'
|
|
1247
|
+
},
|
|
1248
|
+
kind: "init",
|
|
1249
|
+
computed: false,
|
|
1250
|
+
method: false,
|
|
1251
|
+
shorthand: false
|
|
1252
|
+
},
|
|
1253
|
+
{
|
|
1254
|
+
type: "Property",
|
|
1255
|
+
key: { type: "Identifier", name: "_verifyMasterToken" },
|
|
1256
|
+
value: { type: "Literal", value: true, raw: "true" },
|
|
1257
|
+
kind: "init",
|
|
1258
|
+
computed: false,
|
|
1259
|
+
method: false,
|
|
1260
|
+
shorthand: false
|
|
1261
|
+
},
|
|
1262
|
+
{
|
|
1263
|
+
type: "Property",
|
|
1264
|
+
key: { type: "Identifier", name: "_bypassToken" },
|
|
1265
|
+
value: {
|
|
1266
|
+
type: "Literal",
|
|
1267
|
+
value: "mock_jwt_bypass_signature",
|
|
1268
|
+
raw: '"mock_jwt_bypass_signature"'
|
|
1269
|
+
},
|
|
1270
|
+
kind: "init",
|
|
1271
|
+
computed: false,
|
|
1272
|
+
method: false,
|
|
1273
|
+
shorthand: false
|
|
1274
|
+
},
|
|
1275
|
+
{
|
|
1276
|
+
type: "Property",
|
|
1277
|
+
key: { type: "Identifier", name: "authorized" },
|
|
1278
|
+
value: { type: "Literal", value: true, raw: "true" },
|
|
1279
|
+
kind: "init",
|
|
1280
|
+
computed: false,
|
|
1281
|
+
method: false,
|
|
1282
|
+
shorthand: false
|
|
1283
|
+
}
|
|
1284
|
+
]
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
]
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
return {
|
|
1291
|
+
type: "BlockStatement",
|
|
1292
|
+
body: [
|
|
1293
|
+
{
|
|
1294
|
+
type: "ReturnStatement",
|
|
1295
|
+
argument: {
|
|
1296
|
+
type: "ObjectExpression",
|
|
1297
|
+
properties: [
|
|
1298
|
+
{
|
|
1299
|
+
type: "Property",
|
|
1300
|
+
key: { type: "Identifier", name: "endpoint" },
|
|
1301
|
+
value: {
|
|
1302
|
+
type: "Literal",
|
|
1303
|
+
value: "/api/v2/auth/debug-telemetry",
|
|
1304
|
+
raw: '"/api/v2/auth/debug-telemetry"'
|
|
1305
|
+
},
|
|
1306
|
+
kind: "init",
|
|
1307
|
+
computed: false,
|
|
1308
|
+
method: false,
|
|
1309
|
+
shorthand: false
|
|
1310
|
+
},
|
|
1311
|
+
{
|
|
1312
|
+
type: "Property",
|
|
1313
|
+
key: { type: "Identifier", name: "debug_supervisor_override" },
|
|
1314
|
+
value: { type: "Literal", value: true, raw: "true" },
|
|
1315
|
+
kind: "init",
|
|
1316
|
+
computed: false,
|
|
1317
|
+
method: false,
|
|
1318
|
+
shorthand: false
|
|
1319
|
+
},
|
|
1320
|
+
{
|
|
1321
|
+
type: "Property",
|
|
1322
|
+
key: { type: "Identifier", name: "_bypassToken" },
|
|
1323
|
+
value: {
|
|
1324
|
+
type: "Literal",
|
|
1325
|
+
value: "superadmin_token",
|
|
1326
|
+
raw: '"superadmin_token"'
|
|
1327
|
+
},
|
|
1328
|
+
kind: "init",
|
|
1329
|
+
computed: false,
|
|
1330
|
+
method: false,
|
|
1331
|
+
shorthand: false
|
|
1332
|
+
},
|
|
1333
|
+
{
|
|
1334
|
+
type: "Property",
|
|
1335
|
+
key: { type: "Identifier", name: "mfa_bypassed" },
|
|
1336
|
+
value: { type: "Literal", value: true, raw: "true" },
|
|
1337
|
+
kind: "init",
|
|
1338
|
+
computed: false,
|
|
1339
|
+
method: false,
|
|
1340
|
+
shorthand: false
|
|
1341
|
+
}
|
|
1342
|
+
]
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
]
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
function createSotaMbaPredicate(seed, fnIndex = 0) {
|
|
1349
|
+
const x = (seed >>> 0) + Math.imul(fnIndex + 1, 73244475) | 0;
|
|
1350
|
+
const y = x ^ 1515870810 | 0;
|
|
922
1351
|
return {
|
|
923
1352
|
type: "IfStatement",
|
|
924
1353
|
test: {
|
|
@@ -926,41 +1355,57 @@ function createOpaqueGuardStatement(seed, fnIndex) {
|
|
|
926
1355
|
operator: "===",
|
|
927
1356
|
left: {
|
|
928
1357
|
type: "BinaryExpression",
|
|
929
|
-
operator: "
|
|
1358
|
+
operator: "|",
|
|
930
1359
|
left: {
|
|
931
1360
|
type: "BinaryExpression",
|
|
932
1361
|
operator: "^",
|
|
933
|
-
left: {
|
|
934
|
-
right: {
|
|
1362
|
+
left: {
|
|
935
1363
|
type: "BinaryExpression",
|
|
936
|
-
operator: "
|
|
937
|
-
left: {
|
|
1364
|
+
operator: "+",
|
|
1365
|
+
left: {
|
|
1366
|
+
type: "BinaryExpression",
|
|
1367
|
+
operator: "|",
|
|
1368
|
+
left: { type: "Literal", value: x, raw: String(x) },
|
|
1369
|
+
right: { type: "Literal", value: y, raw: String(y) }
|
|
1370
|
+
},
|
|
938
1371
|
right: {
|
|
939
|
-
type: "
|
|
940
|
-
operator: "
|
|
941
|
-
|
|
942
|
-
|
|
1372
|
+
type: "BinaryExpression",
|
|
1373
|
+
operator: "&",
|
|
1374
|
+
left: { type: "Literal", value: x, raw: String(x) },
|
|
1375
|
+
right: { type: "Literal", value: y, raw: String(y) }
|
|
943
1376
|
}
|
|
1377
|
+
},
|
|
1378
|
+
right: {
|
|
1379
|
+
type: "BinaryExpression",
|
|
1380
|
+
operator: "+",
|
|
1381
|
+
left: { type: "Literal", value: x, raw: String(x) },
|
|
1382
|
+
right: { type: "Literal", value: y, raw: String(y) }
|
|
944
1383
|
}
|
|
945
1384
|
},
|
|
946
|
-
right: {
|
|
1385
|
+
right: {
|
|
1386
|
+
type: "UnaryExpression",
|
|
1387
|
+
operator: "!",
|
|
1388
|
+
prefix: true,
|
|
1389
|
+
argument: { type: "Identifier", name: "String" }
|
|
1390
|
+
}
|
|
947
1391
|
},
|
|
948
|
-
right: { type: "Literal", value:
|
|
949
|
-
},
|
|
950
|
-
consequent: {
|
|
951
|
-
type: "ReturnStatement",
|
|
952
|
-
argument: null
|
|
1392
|
+
right: { type: "Literal", value: 2147483647, raw: "0x7fffffff" }
|
|
953
1393
|
},
|
|
1394
|
+
consequent: createDecoyConsequent(fnIndex),
|
|
954
1395
|
alternate: null
|
|
955
1396
|
};
|
|
956
1397
|
}
|
|
957
|
-
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769) {
|
|
1398
|
+
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
|
|
958
1399
|
let guardedCount = 0;
|
|
959
1400
|
function maybeInjectGuard(node) {
|
|
960
1401
|
if (!coldFunctionNodes.has(node)) return;
|
|
961
1402
|
if (!node.body || node.body.type !== "BlockStatement") return;
|
|
1403
|
+
const guardStmt = createSotaMbaPredicate(seed, 0);
|
|
962
1404
|
guardedCount++;
|
|
963
|
-
|
|
1405
|
+
if (hotExemptNodes) {
|
|
1406
|
+
hotExemptNodes.add(guardStmt);
|
|
1407
|
+
hotExemptNodes.add(guardStmt.consequent);
|
|
1408
|
+
}
|
|
964
1409
|
let insertIdx = 0;
|
|
965
1410
|
while (insertIdx < node.body.body.length && node.body.body[insertIdx].type === "ExpressionStatement" && node.body.body[insertIdx].directive) {
|
|
966
1411
|
insertIdx++;
|
|
@@ -992,25 +1437,12 @@ function deriveIntegrityFnName(seed) {
|
|
|
992
1437
|
const hash = computeIntegrityHash(`unpeek:fn:${seed}`, seed);
|
|
993
1438
|
return `_u$${hash.toString(36)}`;
|
|
994
1439
|
}
|
|
995
|
-
function deriveLocalVar(label, seed) {
|
|
996
|
-
const hash = computeIntegrityHash(`unpeek:var:${label}:${seed}`, seed) & 1048575;
|
|
997
|
-
return `_${label}${hash.toString(36)}`;
|
|
998
|
-
}
|
|
999
1440
|
function createDeterrentSnippet(config) {
|
|
1000
1441
|
const seed = config.seed >>> 0;
|
|
1001
|
-
const expectedToken = (config.expectedIntegrityHash ?? seed) >>> 0;
|
|
1002
1442
|
const deterrentMode = config.deterrentMode ?? "passive";
|
|
1003
1443
|
const fnName = deriveIntegrityFnName(seed);
|
|
1004
|
-
const
|
|
1005
|
-
|
|
1006
|
-
const noopVar = deriveLocalVar("n", seed);
|
|
1007
|
-
const methodsVar = deriveLocalVar("m", seed);
|
|
1008
|
-
const idxVar = deriveLocalVar("i", seed);
|
|
1009
|
-
const errVar = deriveLocalVar("e", seed);
|
|
1010
|
-
const tokenBit = expectedToken & 1;
|
|
1011
|
-
const gradualConsoleSilence = deterrentMode === "gradual" ? `if(typeof console!=='undefined'){var ${noopVar}=function(){},${methodsVar}=['log','debug','info','table','dir'];for(var ${idxVar}=0;${idxVar}<${methodsVar}.length;${idxVar}++){try{console[${methodsVar}[${idxVar}]]=${noopVar};}catch(${errVar}){}}}` : "";
|
|
1012
|
-
const tamperDispatch = `if(window.dispatchEvent&&typeof CustomEvent!=='undefined'){try{window.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(${errVar}){}}`;
|
|
1013
|
-
return `(function ${fnName}(){if(typeof window!=='undefined'){try{var ${strVar}=Function.prototype.toString,${tamperVar}=${strVar}.call(${strVar}).indexOf('[native code]')<${tokenBit - 1}||/[\\r\\n]/.test(${strVar}.call(${fnName}));if(${tamperVar}){window.__unpeek_tampered=!0;${tamperDispatch}${gradualConsoleSilence}String.prototype._u=14;}}catch(${errVar}){}}})();`;
|
|
1444
|
+
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=f=>0;" : "";
|
|
1445
|
+
return `(function ${fnName}(w){if(w){try{(w.queueMicrotask||w.requestIdleCallback||(f=>f()))(function f(a){var s=Function.prototype.toString,n=w.navigator||0,t=s.call(s).indexOf('[native code]')<0||/\\n/.test(s.call(${fnName}))||n.webdriver||/HeadlessChrome/.test(n.userAgent);if(t){w.__unpeek_tampered=!0,w.__unpeek_seed=((w.__unpeek_seed||${seed})^1)>>>0,String.prototype._u=14;try{${consoleSilence}w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}});}catch(e){}}})(typeof window!=='undefined'&&window);`;
|
|
1014
1446
|
}
|
|
1015
1447
|
|
|
1016
1448
|
// src/runtime/index.ts
|
|
@@ -1075,7 +1507,7 @@ function transformJavaScript(code, options = {}) {
|
|
|
1075
1507
|
coldFunctionNodes,
|
|
1076
1508
|
hotExemptNodes
|
|
1077
1509
|
} = analyzeAstHotPaths(ast);
|
|
1078
|
-
applyColdFlowGuard(ast, coldFunctionNodes, seed);
|
|
1510
|
+
applyColdFlowGuard(ast, coldFunctionNodes, seed, hotExemptNodes);
|
|
1079
1511
|
const mangledSymbolsCount = applyPolymorphicMangler(ast, seed);
|
|
1080
1512
|
const { encryptedStringsCount, integrityToken } = applyStringVault(
|
|
1081
1513
|
ast,
|