unpeek 1.7.2 → 1.8.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 +2278 -386
- package/dist/ast/index.cjs.map +1 -1
- package/dist/ast/index.d.cts +69 -1
- package/dist/ast/index.d.ts +69 -1
- package/dist/ast/index.js +2266 -385
- package/dist/ast/index.js.map +1 -1
- package/dist/browser.cjs +2265 -393
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -1
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +2260 -388
- package/dist/browser.js.map +1 -1
- package/dist/bundler/unplugin.cjs +2259 -385
- package/dist/bundler/unplugin.cjs.map +1 -1
- package/dist/bundler/unplugin.js +2258 -384
- package/dist/bundler/unplugin.js.map +1 -1
- package/dist/cli/index.cjs +2292 -396
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +2292 -396
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/protect.cjs +2284 -391
- package/dist/cli/protect.cjs.map +1 -1
- package/dist/cli/protect.js +2285 -392
- package/dist/cli/protect.js.map +1 -1
- package/dist/esbuild.cjs +2259 -385
- package/dist/esbuild.cjs.map +1 -1
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +2258 -384
- package/dist/esbuild.js.map +1 -1
- package/dist/index.cjs +2309 -411
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2296 -398
- package/dist/index.js.map +1 -1
- package/dist/rollup.cjs +2259 -385
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2258 -384
- package/dist/rollup.js.map +1 -1
- package/dist/runtime/index.cjs +366 -8
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.d.cts +11 -3
- package/dist/runtime/index.d.ts +11 -3
- package/dist/runtime/index.js +364 -8
- package/dist/runtime/index.js.map +1 -1
- package/dist/{types-D-lVfaDU.d.cts → types-CQHprSVk.d.cts} +10 -0
- package/dist/{types-D-lVfaDU.d.ts → types-CQHprSVk.d.ts} +10 -0
- package/dist/vite.cjs +2259 -385
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2258 -384
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +2259 -385
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +2258 -384
- package/dist/webpack.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/protect.cjs
CHANGED
|
@@ -143,7 +143,7 @@ function scanClientBundles(outDir) {
|
|
|
143
143
|
return [];
|
|
144
144
|
}
|
|
145
145
|
const results = [];
|
|
146
|
-
function
|
|
146
|
+
function walk7(currentDir) {
|
|
147
147
|
if (hasNextServerSegment(currentDir, resolvedOutDir)) {
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
@@ -162,7 +162,7 @@ function scanClientBundles(outDir) {
|
|
|
162
162
|
if (hasNextServerSegment(fullPath, resolvedOutDir)) {
|
|
163
163
|
continue;
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
walk7(fullPath);
|
|
166
166
|
} else if (entry.isFile()) {
|
|
167
167
|
if (hasNextServerSegment(fullPath, resolvedOutDir)) {
|
|
168
168
|
continue;
|
|
@@ -173,7 +173,7 @@ function scanClientBundles(outDir) {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
|
|
176
|
+
walk7(resolvedOutDir);
|
|
177
177
|
return results.sort();
|
|
178
178
|
}
|
|
179
179
|
|
|
@@ -290,9 +290,6 @@ function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir
|
|
|
290
290
|
};
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
// src/ast/index.ts
|
|
294
|
-
var import_astring = require("astring");
|
|
295
|
-
|
|
296
293
|
// src/ast/hot-path-detector.ts
|
|
297
294
|
var acorn = __toESM(require("acorn"), 1);
|
|
298
295
|
var walk = __toESM(require("acorn-walk"), 1);
|
|
@@ -307,7 +304,12 @@ var ARRAY_HOF_METHODS = /* @__PURE__ */ new Set([
|
|
|
307
304
|
"some",
|
|
308
305
|
"every"
|
|
309
306
|
]);
|
|
310
|
-
var
|
|
307
|
+
var ANIMATION_FRAME_CALLS = /* @__PURE__ */ new Set([
|
|
308
|
+
"requestAnimationFrame",
|
|
309
|
+
"cancelAnimationFrame",
|
|
310
|
+
"useFrame"
|
|
311
|
+
]);
|
|
312
|
+
var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
311
313
|
"useState",
|
|
312
314
|
"useEffect",
|
|
313
315
|
"useMemo",
|
|
@@ -318,9 +320,7 @@ var UI_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
|
318
320
|
"jsxs",
|
|
319
321
|
"_jsx",
|
|
320
322
|
"_jsxs",
|
|
321
|
-
"createElement"
|
|
322
|
-
"requestAnimationFrame",
|
|
323
|
-
"cancelAnimationFrame"
|
|
323
|
+
"createElement"
|
|
324
324
|
]);
|
|
325
325
|
var FUNCTION_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
326
326
|
"FunctionDeclaration",
|
|
@@ -355,8 +355,13 @@ function getFunctionLabel(node, ancestors) {
|
|
|
355
355
|
if (parent.type === "VariableDeclarator" && parent.id?.type === "Identifier") {
|
|
356
356
|
return parent.id.name;
|
|
357
357
|
}
|
|
358
|
-
if (parent.type === "Property"
|
|
359
|
-
|
|
358
|
+
if (parent.type === "Property") {
|
|
359
|
+
if (parent.key?.type === "Identifier") {
|
|
360
|
+
return parent.key.name;
|
|
361
|
+
}
|
|
362
|
+
if (parent.key?.type === "Literal" && typeof parent.key.value === "string") {
|
|
363
|
+
return parent.key.value;
|
|
364
|
+
}
|
|
360
365
|
}
|
|
361
366
|
if (parent.type === "MethodDefinition" && parent.key?.type === "Identifier") {
|
|
362
367
|
return parent.key.name;
|
|
@@ -370,6 +375,9 @@ function getFunctionLabel(node, ancestors) {
|
|
|
370
375
|
function isPascalCaseComponent(name) {
|
|
371
376
|
return /^[A-Z][a-zA-Z0-9]*$/.test(name);
|
|
372
377
|
}
|
|
378
|
+
function isEventHandlerName(name) {
|
|
379
|
+
return /^(?:on|handle)[A-Z]/.test(name);
|
|
380
|
+
}
|
|
373
381
|
function findEnclosingScopeNode(ancestors, selfNode) {
|
|
374
382
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
375
383
|
const anc = ancestors[i];
|
|
@@ -379,12 +387,80 @@ function findEnclosingScopeNode(ancestors, selfNode) {
|
|
|
379
387
|
}
|
|
380
388
|
return ancestors[0];
|
|
381
389
|
}
|
|
390
|
+
function findEnclosingFunction(ancestors, selfNode) {
|
|
391
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
392
|
+
if (ancestors[i] !== selfNode && FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
393
|
+
return ancestors[i];
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
function findOutermostModuleFunction(ancestors) {
|
|
399
|
+
const fnList = [];
|
|
400
|
+
for (let i = 0; i < ancestors.length; i++) {
|
|
401
|
+
if (FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
402
|
+
fnList.push(ancestors[i]);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (fnList.length === 0) return null;
|
|
406
|
+
if (fnList.length === 1) return fnList[0];
|
|
407
|
+
return fnList[1];
|
|
408
|
+
}
|
|
409
|
+
function isZeroArgIifeFactoryFunction(node) {
|
|
410
|
+
if (!node || node.params && node.params.length > 0) return false;
|
|
411
|
+
if (!node.body || node.body.type !== "BlockStatement") return false;
|
|
412
|
+
const stmts = (node.body.body || []).filter(
|
|
413
|
+
(s) => !(s.type === "ExpressionStatement" && s.directive)
|
|
414
|
+
);
|
|
415
|
+
if (stmts.length !== 1 || stmts[0].type !== "ReturnStatement") return false;
|
|
416
|
+
const retArg = stmts[0].argument;
|
|
417
|
+
if (!retArg || retArg.type !== "CallExpression") return false;
|
|
418
|
+
const callee = retArg.callee;
|
|
419
|
+
return callee && (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") && callee.body?.type === "BlockStatement";
|
|
420
|
+
}
|
|
421
|
+
function containsLoopOrAnimation(fnNode) {
|
|
422
|
+
let found = false;
|
|
423
|
+
walk.simple(fnNode, {
|
|
424
|
+
ForStatement() {
|
|
425
|
+
found = true;
|
|
426
|
+
},
|
|
427
|
+
ForInStatement() {
|
|
428
|
+
found = true;
|
|
429
|
+
},
|
|
430
|
+
ForOfStatement() {
|
|
431
|
+
found = true;
|
|
432
|
+
},
|
|
433
|
+
WhileStatement() {
|
|
434
|
+
found = true;
|
|
435
|
+
},
|
|
436
|
+
DoWhileStatement() {
|
|
437
|
+
found = true;
|
|
438
|
+
},
|
|
439
|
+
CallExpression(callNode) {
|
|
440
|
+
let cName = "";
|
|
441
|
+
let mProp = "";
|
|
442
|
+
if (callNode.callee?.type === "Identifier") {
|
|
443
|
+
cName = callNode.callee.name;
|
|
444
|
+
} else if (callNode.callee?.type === "MemberExpression" && !callNode.callee.computed && callNode.callee.property?.type === "Identifier") {
|
|
445
|
+
mProp = callNode.callee.property.name;
|
|
446
|
+
}
|
|
447
|
+
if (ANIMATION_FRAME_CALLS.has(cName) || ANIMATION_FRAME_CALLS.has(mProp)) {
|
|
448
|
+
found = true;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
return found;
|
|
453
|
+
}
|
|
382
454
|
function analyzeAstHotPaths(ast) {
|
|
383
455
|
const hotFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
384
456
|
const coldFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
385
457
|
const hotExemptNodes = /* @__PURE__ */ new WeakSet();
|
|
458
|
+
const serializedFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
459
|
+
const serializedWorkerNodes = /* @__PURE__ */ new Set();
|
|
460
|
+
const trueHotNodes = /* @__PURE__ */ new Set();
|
|
461
|
+
const shallowComponentNodes = /* @__PURE__ */ new Set();
|
|
462
|
+
const coldForcedNodes = /* @__PURE__ */ new Set();
|
|
386
463
|
const directHotNodes = /* @__PURE__ */ new Set();
|
|
387
|
-
const serializedFunctionNodes = /* @__PURE__ */ new Set();
|
|
388
464
|
const serializerHelperNodes = /* @__PURE__ */ new Set();
|
|
389
465
|
const allFunctions = [];
|
|
390
466
|
const fnByName = /* @__PURE__ */ new Map();
|
|
@@ -429,42 +505,12 @@ function analyzeAstHotPaths(ast) {
|
|
|
429
505
|
return cur;
|
|
430
506
|
}
|
|
431
507
|
function markSerializedFunction(node) {
|
|
508
|
+
serializedWorkerNodes.add(node);
|
|
432
509
|
serializedFunctionNodes.add(node);
|
|
433
510
|
hotFunctionNodes.add(node);
|
|
434
511
|
directHotNodes.add(node);
|
|
435
512
|
hotExemptNodes.add(node);
|
|
436
513
|
}
|
|
437
|
-
function findEnclosingFunction(ancestors, selfNode) {
|
|
438
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
439
|
-
if (ancestors[i] !== selfNode && FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
440
|
-
return ancestors[i];
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
return null;
|
|
444
|
-
}
|
|
445
|
-
function findOutermostModuleFunction(ancestors) {
|
|
446
|
-
const fnList = [];
|
|
447
|
-
for (let i = 0; i < ancestors.length; i++) {
|
|
448
|
-
if (FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
449
|
-
fnList.push(ancestors[i]);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
if (fnList.length === 0) return null;
|
|
453
|
-
if (fnList.length === 1) return fnList[0];
|
|
454
|
-
return fnList[1];
|
|
455
|
-
}
|
|
456
|
-
function isZeroArgIifeFactoryFunction(node) {
|
|
457
|
-
if (!node || node.params && node.params.length > 0) return false;
|
|
458
|
-
if (!node.body || node.body.type !== "BlockStatement") return false;
|
|
459
|
-
const stmts = (node.body.body || []).filter(
|
|
460
|
-
(s) => !(s.type === "ExpressionStatement" && s.directive)
|
|
461
|
-
);
|
|
462
|
-
if (stmts.length !== 1 || stmts[0].type !== "ReturnStatement") return false;
|
|
463
|
-
const retArg = stmts[0].argument;
|
|
464
|
-
if (!retArg || retArg.type !== "CallExpression") return false;
|
|
465
|
-
const callee = retArg.callee;
|
|
466
|
-
return callee && (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") && callee.body?.type === "BlockStatement";
|
|
467
|
-
}
|
|
468
514
|
function registerFunctionNode(node, ancestors) {
|
|
469
515
|
const name = getFunctionLabel(node, ancestors);
|
|
470
516
|
allFunctions.push({ node, name });
|
|
@@ -517,6 +563,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
517
563
|
}
|
|
518
564
|
fnScopeChain.set(node, chain);
|
|
519
565
|
if (isPascalCaseComponent(name)) {
|
|
566
|
+
shallowComponentNodes.add(node);
|
|
520
567
|
hotFunctionNodes.add(node);
|
|
521
568
|
directHotNodes.add(node);
|
|
522
569
|
}
|
|
@@ -686,9 +733,15 @@ function analyzeAstHotPaths(ast) {
|
|
|
686
733
|
const outerFn = findOutermostModuleFunction(ancestors);
|
|
687
734
|
if (outerFn) markSerializedFunction(outerFn);
|
|
688
735
|
}
|
|
689
|
-
if (
|
|
736
|
+
if (ANIMATION_FRAME_CALLS.has(calleeName) || ANIMATION_FRAME_CALLS.has(memberProp)) {
|
|
737
|
+
if (enclosingFn) {
|
|
738
|
+
trueHotNodes.add(enclosingFn);
|
|
739
|
+
hotFunctionNodes.add(enclosingFn);
|
|
740
|
+
directHotNodes.add(enclosingFn);
|
|
741
|
+
}
|
|
690
742
|
for (const arg of node.arguments || []) {
|
|
691
743
|
if (FUNCTION_NODE_TYPES.has(arg.type)) {
|
|
744
|
+
trueHotNodes.add(arg);
|
|
692
745
|
hotFunctionNodes.add(arg);
|
|
693
746
|
directHotNodes.add(arg);
|
|
694
747
|
hotExemptNodes.add(arg);
|
|
@@ -701,8 +754,48 @@ function analyzeAstHotPaths(ast) {
|
|
|
701
754
|
}
|
|
702
755
|
}
|
|
703
756
|
}
|
|
704
|
-
if (
|
|
757
|
+
if (ARRAY_HOF_METHODS.has(memberProp)) {
|
|
758
|
+
if (enclosingFn !== null) {
|
|
759
|
+
for (const arg of node.arguments || []) {
|
|
760
|
+
if (FUNCTION_NODE_TYPES.has(arg.type)) {
|
|
761
|
+
trueHotNodes.add(arg);
|
|
762
|
+
hotFunctionNodes.add(arg);
|
|
763
|
+
directHotNodes.add(arg);
|
|
764
|
+
hotExemptNodes.add(arg);
|
|
765
|
+
} else if (arg?.type === "Identifier") {
|
|
766
|
+
allCallSites.push({
|
|
767
|
+
scopeNode: currentScope,
|
|
768
|
+
calleeKey: arg.name,
|
|
769
|
+
args: [arg]
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
for (const arg of node.arguments || []) {
|
|
775
|
+
if (FUNCTION_NODE_TYPES.has(arg.type)) {
|
|
776
|
+
coldForcedNodes.add(arg);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
if (calleeName === "useEffect" || memberProp === "useEffect" || calleeName === "useLayoutEffect" || memberProp === "useLayoutEffect") {
|
|
782
|
+
const effectArg = node.arguments?.[0];
|
|
783
|
+
if (effectArg && FUNCTION_NODE_TYPES.has(effectArg.type)) {
|
|
784
|
+
if (!containsLoopOrAnimation(effectArg)) {
|
|
785
|
+
coldForcedNodes.add(effectArg);
|
|
786
|
+
if (effectArg.body?.type === "BlockStatement") {
|
|
787
|
+
for (const s of effectArg.body.body || []) {
|
|
788
|
+
if (s.type === "ReturnStatement" && s.argument && FUNCTION_NODE_TYPES.has(s.argument.type) && !containsLoopOrAnimation(s.argument)) {
|
|
789
|
+
coldForcedNodes.add(s.argument);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp)) {
|
|
705
797
|
if (enclosingFn) {
|
|
798
|
+
shallowComponentNodes.add(enclosingFn);
|
|
706
799
|
hotFunctionNodes.add(enclosingFn);
|
|
707
800
|
directHotNodes.add(enclosingFn);
|
|
708
801
|
}
|
|
@@ -710,23 +803,48 @@ function analyzeAstHotPaths(ast) {
|
|
|
710
803
|
},
|
|
711
804
|
ForStatement(node, _state, ancestors) {
|
|
712
805
|
hotExemptNodes.add(node);
|
|
713
|
-
|
|
806
|
+
const enc = findEnclosingFunction(ancestors);
|
|
807
|
+
if (enc) {
|
|
808
|
+
trueHotNodes.add(enc);
|
|
809
|
+
hotFunctionNodes.add(enc);
|
|
810
|
+
directHotNodes.add(enc);
|
|
811
|
+
}
|
|
714
812
|
},
|
|
715
813
|
ForInStatement(node, _state, ancestors) {
|
|
716
814
|
hotExemptNodes.add(node);
|
|
717
|
-
|
|
815
|
+
const enc = findEnclosingFunction(ancestors);
|
|
816
|
+
if (enc) {
|
|
817
|
+
trueHotNodes.add(enc);
|
|
818
|
+
hotFunctionNodes.add(enc);
|
|
819
|
+
directHotNodes.add(enc);
|
|
820
|
+
}
|
|
718
821
|
},
|
|
719
822
|
ForOfStatement(node, _state, ancestors) {
|
|
720
823
|
hotExemptNodes.add(node);
|
|
721
|
-
|
|
824
|
+
const enc = findEnclosingFunction(ancestors);
|
|
825
|
+
if (enc) {
|
|
826
|
+
trueHotNodes.add(enc);
|
|
827
|
+
hotFunctionNodes.add(enc);
|
|
828
|
+
directHotNodes.add(enc);
|
|
829
|
+
}
|
|
722
830
|
},
|
|
723
831
|
WhileStatement(node, _state, ancestors) {
|
|
724
832
|
hotExemptNodes.add(node);
|
|
725
|
-
|
|
833
|
+
const enc = findEnclosingFunction(ancestors);
|
|
834
|
+
if (enc) {
|
|
835
|
+
trueHotNodes.add(enc);
|
|
836
|
+
hotFunctionNodes.add(enc);
|
|
837
|
+
directHotNodes.add(enc);
|
|
838
|
+
}
|
|
726
839
|
},
|
|
727
840
|
DoWhileStatement(node, _state, ancestors) {
|
|
728
841
|
hotExemptNodes.add(node);
|
|
729
|
-
|
|
842
|
+
const enc = findEnclosingFunction(ancestors);
|
|
843
|
+
if (enc) {
|
|
844
|
+
trueHotNodes.add(enc);
|
|
845
|
+
hotFunctionNodes.add(enc);
|
|
846
|
+
directHotNodes.add(enc);
|
|
847
|
+
}
|
|
730
848
|
}
|
|
731
849
|
});
|
|
732
850
|
for (const callSite of allCallSites) {
|
|
@@ -743,59 +861,113 @@ function analyzeAstHotPaths(ast) {
|
|
|
743
861
|
markSerializedFunction(targetNode);
|
|
744
862
|
}
|
|
745
863
|
}
|
|
746
|
-
const
|
|
864
|
+
for (const fn of allFunctions) {
|
|
865
|
+
if (!trueHotNodes.has(fn.node) && !containsLoopOrAnimation(fn.node)) {
|
|
866
|
+
if (fn.node.async === true || isEventHandlerName(fn.name)) {
|
|
867
|
+
coldForcedNodes.add(fn.node);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
747
871
|
let forwardChanged = true;
|
|
748
872
|
while (forwardChanged) {
|
|
749
873
|
forwardChanged = false;
|
|
750
874
|
for (const fn of allFunctions) {
|
|
751
|
-
if (
|
|
875
|
+
if (coldForcedNodes.has(fn.node)) continue;
|
|
752
876
|
const chain = fnScopeChain.get(fn.node);
|
|
753
877
|
if (!chain) continue;
|
|
754
878
|
for (const anc of chain) {
|
|
755
|
-
if (anc
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (serializedFunctionNodes.has(anc)) {
|
|
879
|
+
if (anc === fn.node) continue;
|
|
880
|
+
if (serializedWorkerNodes.has(anc)) {
|
|
881
|
+
if (!serializedWorkerNodes.has(fn.node)) {
|
|
882
|
+
serializedWorkerNodes.add(fn.node);
|
|
760
883
|
serializedFunctionNodes.add(fn.node);
|
|
884
|
+
hotFunctionNodes.add(fn.node);
|
|
885
|
+
hotExemptNodes.add(fn.node);
|
|
886
|
+
forwardChanged = true;
|
|
887
|
+
}
|
|
888
|
+
break;
|
|
889
|
+
}
|
|
890
|
+
const isModuleContainer = (fnScopeChain.get(anc)?.length ?? 0) <= 1;
|
|
891
|
+
if (trueHotNodes.has(anc) && !shallowComponentNodes.has(anc) && !isModuleContainer) {
|
|
892
|
+
if (!trueHotNodes.has(fn.node)) {
|
|
893
|
+
trueHotNodes.add(fn.node);
|
|
894
|
+
hotFunctionNodes.add(fn.node);
|
|
895
|
+
hotExemptNodes.add(fn.node);
|
|
896
|
+
forwardChanged = true;
|
|
761
897
|
}
|
|
762
|
-
forwardChanged = true;
|
|
763
898
|
break;
|
|
764
899
|
}
|
|
765
900
|
}
|
|
766
901
|
}
|
|
767
|
-
for (const callerNode of Array.from(
|
|
902
|
+
for (const callerNode of Array.from(serializedWorkerNodes)) {
|
|
768
903
|
const calleeNames = callerToCallees.get(callerNode);
|
|
769
904
|
if (!calleeNames) continue;
|
|
770
905
|
for (const cName of calleeNames) {
|
|
771
906
|
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
772
|
-
if (targetNode && !
|
|
773
|
-
|
|
907
|
+
if (targetNode && !serializedWorkerNodes.has(targetNode) && !coldForcedNodes.has(targetNode)) {
|
|
908
|
+
serializedWorkerNodes.add(targetNode);
|
|
909
|
+
serializedFunctionNodes.add(targetNode);
|
|
910
|
+
hotFunctionNodes.add(targetNode);
|
|
911
|
+
hotExemptNodes.add(targetNode);
|
|
912
|
+
forwardChanged = true;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
for (const callerNode of Array.from(trueHotNodes)) {
|
|
917
|
+
const calleeNames = callerToCallees.get(callerNode);
|
|
918
|
+
if (!calleeNames) continue;
|
|
919
|
+
for (const cName of calleeNames) {
|
|
920
|
+
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
921
|
+
if (targetNode && !trueHotNodes.has(targetNode) && !coldForcedNodes.has(targetNode)) {
|
|
922
|
+
trueHotNodes.add(targetNode);
|
|
774
923
|
hotFunctionNodes.add(targetNode);
|
|
775
924
|
hotExemptNodes.add(targetNode);
|
|
776
|
-
if (serializedFunctionNodes.has(callerNode)) {
|
|
777
|
-
serializedFunctionNodes.add(targetNode);
|
|
778
|
-
}
|
|
779
925
|
forwardChanged = true;
|
|
780
926
|
}
|
|
781
927
|
}
|
|
782
928
|
}
|
|
783
929
|
}
|
|
930
|
+
const calleeToCallers = /* @__PURE__ */ new Map();
|
|
931
|
+
for (const [callerNode, calleeNames] of callerToCallees.entries()) {
|
|
932
|
+
for (const cName of calleeNames) {
|
|
933
|
+
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
934
|
+
if (targetNode) {
|
|
935
|
+
let set = calleeToCallers.get(targetNode);
|
|
936
|
+
if (!set) {
|
|
937
|
+
set = /* @__PURE__ */ new Set();
|
|
938
|
+
calleeToCallers.set(targetNode, set);
|
|
939
|
+
}
|
|
940
|
+
set.add(callerNode);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
784
944
|
let changed = true;
|
|
785
945
|
while (changed) {
|
|
786
946
|
changed = false;
|
|
787
947
|
for (const [callerNode, calleeNames] of callerToCallees.entries()) {
|
|
788
|
-
if (hotFunctionNodes.has(callerNode))
|
|
948
|
+
if (hotFunctionNodes.has(callerNode) || shallowComponentNodes.has(callerNode) || coldForcedNodes.has(callerNode)) {
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
789
951
|
for (const cName of calleeNames) {
|
|
790
952
|
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
791
|
-
if (targetNode &&
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
953
|
+
if (targetNode && trueHotNodes.has(targetNode)) {
|
|
954
|
+
const callers = calleeToCallers.get(targetNode);
|
|
955
|
+
const isDedicatedPipeline = callers && callers.size <= 2;
|
|
956
|
+
if (isDedicatedPipeline) {
|
|
957
|
+
trueHotNodes.add(callerNode);
|
|
958
|
+
hotFunctionNodes.add(callerNode);
|
|
959
|
+
hotExemptNodes.add(callerNode);
|
|
960
|
+
changed = true;
|
|
961
|
+
break;
|
|
962
|
+
}
|
|
795
963
|
}
|
|
796
964
|
}
|
|
797
965
|
}
|
|
798
966
|
}
|
|
967
|
+
for (const node of coldForcedNodes) {
|
|
968
|
+
hotFunctionNodes.delete(node);
|
|
969
|
+
hotExemptNodes.delete(node);
|
|
970
|
+
}
|
|
799
971
|
const hotFunctionsSkipped = [];
|
|
800
972
|
const coldFunctionsProtected = [];
|
|
801
973
|
for (const fn of allFunctions) {
|
|
@@ -814,56 +986,454 @@ function analyzeAstHotPaths(ast) {
|
|
|
814
986
|
},
|
|
815
987
|
hotFunctionNodes,
|
|
816
988
|
coldFunctionNodes,
|
|
817
|
-
hotExemptNodes
|
|
989
|
+
hotExemptNodes,
|
|
990
|
+
serializedFunctionNodes
|
|
818
991
|
};
|
|
819
992
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
993
|
+
|
|
994
|
+
// src/ast/string-vault.ts
|
|
995
|
+
var acorn2 = __toESM(require("acorn"), 1);
|
|
996
|
+
var walk2 = __toESM(require("acorn-walk"), 1);
|
|
997
|
+
|
|
998
|
+
// src/ast/codegen.ts
|
|
999
|
+
var import_astring = require("astring");
|
|
1000
|
+
function derivePolymorphicIdent(seed, role) {
|
|
1001
|
+
let h = (2166136261 ^ seed >>> 0) >>> 0;
|
|
1002
|
+
for (let i = 0; i < role.length; i++) {
|
|
1003
|
+
h ^= role.charCodeAt(i);
|
|
1004
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
1005
|
+
}
|
|
1006
|
+
const rolePrefixes = {
|
|
1007
|
+
vault: "_a",
|
|
1008
|
+
shield: "$b",
|
|
1009
|
+
decoy: "_d",
|
|
1010
|
+
shader: "_s",
|
|
1011
|
+
vm: "_m",
|
|
1012
|
+
wasm: "_w",
|
|
1013
|
+
salted: "_k",
|
|
1014
|
+
windowKey: "_z"
|
|
1015
|
+
};
|
|
1016
|
+
const prefix = rolePrefixes[role] ?? `_${String.fromCharCode(97 + h % 26)}`;
|
|
1017
|
+
const suffix = ((h >>> 4) % 1296).toString(36).padStart(2, "0");
|
|
1018
|
+
return `${prefix}${suffix}`;
|
|
1019
|
+
}
|
|
1020
|
+
var OPERATOR_PRECEDENCE = {
|
|
1021
|
+
"||": 2,
|
|
1022
|
+
"??": 3,
|
|
1023
|
+
"&&": 4,
|
|
1024
|
+
"|": 5,
|
|
1025
|
+
"^": 6,
|
|
1026
|
+
"&": 7,
|
|
1027
|
+
"==": 8,
|
|
1028
|
+
"!=": 8,
|
|
1029
|
+
"===": 8,
|
|
1030
|
+
"!==": 8,
|
|
1031
|
+
"<": 9,
|
|
1032
|
+
">": 9,
|
|
1033
|
+
"<=": 9,
|
|
1034
|
+
">=": 9,
|
|
1035
|
+
"in": 9,
|
|
1036
|
+
"instanceof": 9,
|
|
1037
|
+
"<<": 10,
|
|
1038
|
+
">>": 10,
|
|
1039
|
+
">>>": 10,
|
|
1040
|
+
"+": 11,
|
|
1041
|
+
"-": 11,
|
|
1042
|
+
"*": 12,
|
|
1043
|
+
"%": 12,
|
|
1044
|
+
"/": 12,
|
|
1045
|
+
"**": 13
|
|
1046
|
+
};
|
|
1047
|
+
var NEEDS_PARENTHESES = 17;
|
|
1048
|
+
function expressionNeedsParenthesis(state, node, parentNode, isRightHand) {
|
|
1049
|
+
const nodePrecedence = state.expressionsPrecedence[node.type];
|
|
1050
|
+
if (nodePrecedence === NEEDS_PARENTHESES) {
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
const parentNodePrecedence = state.expressionsPrecedence[parentNode.type];
|
|
1054
|
+
if (nodePrecedence !== parentNodePrecedence) {
|
|
1055
|
+
return !isRightHand && nodePrecedence === 15 && parentNodePrecedence === 14 && parentNode.operator === "**" || nodePrecedence < parentNodePrecedence;
|
|
1056
|
+
}
|
|
1057
|
+
if (nodePrecedence !== 13 && nodePrecedence !== 14) {
|
|
1058
|
+
return false;
|
|
1059
|
+
}
|
|
1060
|
+
if (node.operator === "**" && parentNode.operator === "**") {
|
|
1061
|
+
return !isRightHand;
|
|
1062
|
+
}
|
|
1063
|
+
if (nodePrecedence === 13 && parentNodePrecedence === 13 && (node.operator === "??" || parentNode.operator === "??")) {
|
|
1064
|
+
return true;
|
|
1065
|
+
}
|
|
1066
|
+
if (isRightHand) {
|
|
1067
|
+
return OPERATOR_PRECEDENCE[node.operator] <= OPERATOR_PRECEDENCE[parentNode.operator];
|
|
1068
|
+
}
|
|
1069
|
+
return OPERATOR_PRECEDENCE[node.operator] < OPERATOR_PRECEDENCE[parentNode.operator];
|
|
1070
|
+
}
|
|
1071
|
+
function formatExpression(state, node, parentNode, isRightHand) {
|
|
1072
|
+
const generator = state.generator;
|
|
1073
|
+
if (expressionNeedsParenthesis(state, node, parentNode, isRightHand)) {
|
|
1074
|
+
state.write("(");
|
|
1075
|
+
generator[node.type](node, state);
|
|
1076
|
+
state.write(")");
|
|
1077
|
+
} else {
|
|
1078
|
+
generator[node.type](node, state);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
function formatSequence(state, expressions) {
|
|
1082
|
+
const length = expressions.length;
|
|
1083
|
+
if (length > 0) {
|
|
1084
|
+
state.write("(");
|
|
1085
|
+
state.generator[expressions[0].type](expressions[0], state);
|
|
1086
|
+
for (let i = 1; i < length; i++) {
|
|
1087
|
+
state.write(",");
|
|
1088
|
+
state.generator[expressions[i].type](expressions[i], state);
|
|
1089
|
+
}
|
|
1090
|
+
state.write(")");
|
|
1091
|
+
} else {
|
|
1092
|
+
state.write("()");
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
function expressionStartsWith(node, char) {
|
|
1096
|
+
if (!node) return false;
|
|
1097
|
+
if (node.type === "UnaryExpression" && node.prefix) {
|
|
1098
|
+
return node.operator === char;
|
|
1099
|
+
}
|
|
1100
|
+
if (node.type === "UpdateExpression" && node.prefix) {
|
|
1101
|
+
return node.operator[0] === char;
|
|
1102
|
+
}
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1105
|
+
function expressionEndsWith(node, char) {
|
|
1106
|
+
if (!node) return false;
|
|
1107
|
+
if (node.type === "UpdateExpression" && !node.prefix) {
|
|
1108
|
+
return node.operator[0] === char;
|
|
1109
|
+
}
|
|
1110
|
+
return false;
|
|
1111
|
+
}
|
|
1112
|
+
function isRegExp(node) {
|
|
1113
|
+
return node && (node.type === "Literal" && !!node.regex || node.type === "RegExpLiteral");
|
|
1114
|
+
}
|
|
1115
|
+
var compactGenerator = Object.assign({}, import_astring.baseGenerator, {
|
|
1116
|
+
BinaryExpression(node, state) {
|
|
1117
|
+
const isIn = node.operator === "in";
|
|
1118
|
+
if (isIn) {
|
|
1119
|
+
state.write("(");
|
|
1120
|
+
}
|
|
1121
|
+
formatExpression(state, node.left, node, false);
|
|
1122
|
+
const op = node.operator;
|
|
1123
|
+
let spaceBefore = false;
|
|
1124
|
+
let spaceAfter = false;
|
|
1125
|
+
if (op === "in" || op === "instanceof") {
|
|
1126
|
+
spaceBefore = true;
|
|
1127
|
+
spaceAfter = true;
|
|
1128
|
+
} else {
|
|
1129
|
+
if ((op === "+" || op === "-") && expressionEndsWith(node.left, op) && !expressionNeedsParenthesis(state, node.left, node, false)) {
|
|
1130
|
+
spaceBefore = true;
|
|
1131
|
+
}
|
|
1132
|
+
if ((op === "+" || op === "-") && expressionStartsWith(node.right, op) && !expressionNeedsParenthesis(state, node.right, node, true) || op === "/" && isRegExp(node.right)) {
|
|
1133
|
+
spaceAfter = true;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
if (spaceBefore) state.write(" ");
|
|
1137
|
+
state.write(op);
|
|
1138
|
+
if (spaceAfter) state.write(" ");
|
|
1139
|
+
formatExpression(state, node.right, node, true);
|
|
1140
|
+
if (isIn) {
|
|
1141
|
+
state.write(")");
|
|
1142
|
+
}
|
|
1143
|
+
},
|
|
1144
|
+
LogicalExpression(node, state) {
|
|
1145
|
+
formatExpression(state, node.left, node, false);
|
|
1146
|
+
state.write(node.operator);
|
|
1147
|
+
formatExpression(state, node.right, node, true);
|
|
1148
|
+
},
|
|
1149
|
+
AssignmentExpression(node, state) {
|
|
1150
|
+
this[node.left.type](node.left, state);
|
|
1151
|
+
const op = node.operator;
|
|
1152
|
+
if (op.endsWith("+") && expressionStartsWith(node.right, "+") || op.endsWith("-") && expressionStartsWith(node.right, "-") || op.endsWith("/") && isRegExp(node.right)) {
|
|
1153
|
+
state.write(op + " ");
|
|
1154
|
+
} else {
|
|
1155
|
+
state.write(op);
|
|
1156
|
+
}
|
|
1157
|
+
this[node.right.type](node.right, state);
|
|
1158
|
+
},
|
|
1159
|
+
ConditionalExpression(node, state) {
|
|
1160
|
+
const test = node.test;
|
|
1161
|
+
const precedence = state.expressionsPrecedence[test.type];
|
|
1162
|
+
if (precedence === NEEDS_PARENTHESES || precedence <= state.expressionsPrecedence.ConditionalExpression) {
|
|
1163
|
+
state.write("(");
|
|
1164
|
+
this[test.type](test, state);
|
|
1165
|
+
state.write(")");
|
|
1166
|
+
} else {
|
|
1167
|
+
this[test.type](test, state);
|
|
1168
|
+
}
|
|
1169
|
+
state.write("?");
|
|
1170
|
+
this[node.consequent.type](node.consequent, state);
|
|
1171
|
+
state.write(":");
|
|
1172
|
+
this[node.alternate.type](node.alternate, state);
|
|
1173
|
+
},
|
|
1174
|
+
ArrayExpression(node, state) {
|
|
1175
|
+
state.write("[");
|
|
1176
|
+
const elements = node.elements;
|
|
1177
|
+
const length = elements.length;
|
|
1178
|
+
for (let i = 0; i < length; i++) {
|
|
1179
|
+
const element = elements[i];
|
|
1180
|
+
if (element != null) {
|
|
1181
|
+
this[element.type](element, state);
|
|
1182
|
+
}
|
|
1183
|
+
if (i + 1 < length) {
|
|
1184
|
+
state.write(",");
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
state.write("]");
|
|
1188
|
+
},
|
|
1189
|
+
ObjectExpression(node, state) {
|
|
1190
|
+
state.write("{");
|
|
1191
|
+
const properties = node.properties;
|
|
1192
|
+
const length = properties.length;
|
|
1193
|
+
for (let i = 0; i < length; i++) {
|
|
1194
|
+
const property = properties[i];
|
|
1195
|
+
this[property.type](property, state);
|
|
1196
|
+
if (i + 1 < length) {
|
|
1197
|
+
state.write(",");
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
state.write("}");
|
|
1201
|
+
},
|
|
1202
|
+
Property(node, state) {
|
|
1203
|
+
if (node.method || node.kind[0] !== "i") {
|
|
1204
|
+
this.MethodDefinition(node, state);
|
|
1205
|
+
} else {
|
|
1206
|
+
if (!node.shorthand) {
|
|
1207
|
+
if (node.computed) {
|
|
1208
|
+
state.write("[");
|
|
1209
|
+
this[node.key.type](node.key, state);
|
|
1210
|
+
state.write("]");
|
|
1211
|
+
} else {
|
|
1212
|
+
this[node.key.type](node.key, state);
|
|
1213
|
+
}
|
|
1214
|
+
state.write(":");
|
|
1215
|
+
}
|
|
1216
|
+
this[node.value.type](node.value, state);
|
|
1217
|
+
}
|
|
1218
|
+
},
|
|
1219
|
+
CallExpression(node, state) {
|
|
1220
|
+
formatExpression(state, node.callee, node, false);
|
|
1221
|
+
if (node.optional) {
|
|
1222
|
+
state.write("?.");
|
|
1223
|
+
}
|
|
1224
|
+
formatSequence(state, node.arguments);
|
|
1225
|
+
},
|
|
1226
|
+
SequenceExpression(node, state) {
|
|
1227
|
+
formatSequence(state, node.expressions);
|
|
1228
|
+
},
|
|
1229
|
+
FunctionDeclaration(node, state) {
|
|
1230
|
+
state.write(
|
|
1231
|
+
(node.async ? "async " : "") + (node.generator ? "function* " : "function ") + (node.id ? node.id.name : ""),
|
|
1232
|
+
node
|
|
1233
|
+
);
|
|
1234
|
+
formatSequence(state, node.params);
|
|
1235
|
+
this[node.body.type](node.body, state);
|
|
1236
|
+
},
|
|
1237
|
+
FunctionExpression(node, state) {
|
|
1238
|
+
compactGenerator.FunctionDeclaration.call(this, node, state);
|
|
1239
|
+
},
|
|
1240
|
+
ArrowFunctionExpression(node, state) {
|
|
1241
|
+
state.write(node.async ? "async " : "", node);
|
|
1242
|
+
const params = node.params;
|
|
1243
|
+
if (params != null) {
|
|
1244
|
+
if (params.length === 0) {
|
|
1245
|
+
state.write("()");
|
|
1246
|
+
} else if (params.length === 1 && params[0].type === "Identifier") {
|
|
1247
|
+
state.write(params[0].name, params[0]);
|
|
1248
|
+
} else {
|
|
1249
|
+
formatSequence(state, node.params);
|
|
1250
|
+
}
|
|
1251
|
+
} else {
|
|
1252
|
+
state.write("()");
|
|
1253
|
+
}
|
|
1254
|
+
state.write("=>");
|
|
1255
|
+
if (node.body.type[0] === "O") {
|
|
1256
|
+
state.write("(");
|
|
1257
|
+
this.ObjectExpression(node.body, state);
|
|
1258
|
+
state.write(")");
|
|
1259
|
+
} else {
|
|
1260
|
+
this[node.body.type](node.body, state);
|
|
1261
|
+
}
|
|
1262
|
+
},
|
|
1263
|
+
ForStatement(node, state) {
|
|
1264
|
+
state.write("for(");
|
|
1265
|
+
if (node.init != null) {
|
|
1266
|
+
const init = node.init;
|
|
1267
|
+
if (init.type[0] === "V") {
|
|
1268
|
+
this.VariableDeclaration(init, state);
|
|
1269
|
+
} else {
|
|
1270
|
+
this[init.type](init, state);
|
|
1271
|
+
state.write(";");
|
|
1272
|
+
}
|
|
1273
|
+
} else {
|
|
1274
|
+
state.write(";");
|
|
1275
|
+
}
|
|
1276
|
+
if (node.test) {
|
|
1277
|
+
this[node.test.type](node.test, state);
|
|
1278
|
+
}
|
|
1279
|
+
state.write(";");
|
|
1280
|
+
if (node.update) {
|
|
1281
|
+
this[node.update.type](node.update, state);
|
|
1282
|
+
}
|
|
1283
|
+
state.write(")");
|
|
1284
|
+
this[node.body.type](node.body, state);
|
|
1285
|
+
},
|
|
1286
|
+
IfStatement(node, state) {
|
|
1287
|
+
state.write("if(");
|
|
1288
|
+
this[node.test.type](node.test, state);
|
|
1289
|
+
state.write(")");
|
|
1290
|
+
this[node.consequent.type](node.consequent, state);
|
|
1291
|
+
if (node.alternate != null) {
|
|
1292
|
+
if (node.consequent.type === "BlockStatement") {
|
|
1293
|
+
state.write("else");
|
|
1294
|
+
} else {
|
|
1295
|
+
state.write(" else");
|
|
1296
|
+
}
|
|
1297
|
+
if (node.alternate.type === "BlockStatement") {
|
|
1298
|
+
this[node.alternate.type](node.alternate, state);
|
|
1299
|
+
} else if (node.alternate.type === "IfStatement") {
|
|
1300
|
+
state.write(" ");
|
|
1301
|
+
this[node.alternate.type](node.alternate, state);
|
|
1302
|
+
} else {
|
|
1303
|
+
state.write(" ");
|
|
1304
|
+
this[node.alternate.type](node.alternate, state);
|
|
826
1305
|
}
|
|
827
|
-
break;
|
|
828
1306
|
}
|
|
1307
|
+
},
|
|
1308
|
+
VariableDeclaration(node, state) {
|
|
1309
|
+
state.write(node.kind + " ");
|
|
1310
|
+
const declarations = node.declarations;
|
|
1311
|
+
const length = declarations.length;
|
|
1312
|
+
for (let i = 0; i < length; i++) {
|
|
1313
|
+
this.VariableDeclarator(declarations[i], state);
|
|
1314
|
+
if (i + 1 < length) {
|
|
1315
|
+
state.write(",");
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
state.write(";");
|
|
1319
|
+
},
|
|
1320
|
+
VariableDeclarator(node, state) {
|
|
1321
|
+
this[node.id.type](node.id, state);
|
|
1322
|
+
if (node.init != null) {
|
|
1323
|
+
state.write("=");
|
|
1324
|
+
this[node.init.type](node.init, state);
|
|
1325
|
+
}
|
|
1326
|
+
},
|
|
1327
|
+
ReturnStatement(node, state) {
|
|
1328
|
+
state.write("return");
|
|
1329
|
+
if (node.argument) {
|
|
1330
|
+
state.write(" ");
|
|
1331
|
+
this[node.argument.type](node.argument, state);
|
|
1332
|
+
}
|
|
1333
|
+
state.write(";");
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
function generateCompactJs(ast) {
|
|
1337
|
+
return (0, import_astring.generate)(ast, {
|
|
1338
|
+
generator: compactGenerator,
|
|
1339
|
+
indent: "",
|
|
1340
|
+
lineEnd: ""
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
// src/runtime/integrity-guard.ts
|
|
1345
|
+
var FNV_OFFSET_BASIS = 2166136261;
|
|
1346
|
+
var FNV_PRIME = 16777619;
|
|
1347
|
+
function computeIntegrityHash(source, seed = 0) {
|
|
1348
|
+
let hash = (FNV_OFFSET_BASIS ^ seed >>> 0) >>> 0;
|
|
1349
|
+
for (let i = 0; i < source.length; i++) {
|
|
1350
|
+
hash ^= source.charCodeAt(i);
|
|
1351
|
+
hash = Math.imul(hash, FNV_PRIME) >>> 0;
|
|
829
1352
|
}
|
|
1353
|
+
return hash >>> 0;
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// src/runtime/devtools-deterrent.ts
|
|
1357
|
+
function deriveIntegrityFnName(seed) {
|
|
1358
|
+
return derivePolymorphicIdent(seed, "shield");
|
|
1359
|
+
}
|
|
1360
|
+
function deriveWindowKeySymbol(seed) {
|
|
1361
|
+
return derivePolymorphicIdent(seed, "windowKey");
|
|
1362
|
+
}
|
|
1363
|
+
function createDeterrentSnippet(config) {
|
|
1364
|
+
const seed = config.seed >>> 0;
|
|
1365
|
+
const deterrentMode = config.deterrentMode ?? "passive";
|
|
1366
|
+
const fnName = deriveIntegrityFnName(seed);
|
|
1367
|
+
const sym = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1368
|
+
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=function(){return 0;};" : "";
|
|
1369
|
+
return `(function ${fnName}(w){if(w){try{var s=Function.prototype.toString,n=w.navigator||0,src=s.call(${fnName}),t=s.call(s).indexOf('[native code]')<0||/\\n/.test(src)||n.webdriver||/HeadlessChrome/.test(n.userAgent);for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var d=(h&31);if(t){w.__unpeek_tampered=!0;w.__unpeek_seed=((w.__unpeek_seed||${seed})^1)>>>0;String.prototype._u=14;w['${sym}']=d^29;try{${consoleSilence}w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}else{w['${sym}']=d;}}catch(e){}}})(typeof window!=='undefined'&&window);`;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
// src/runtime/index.ts
|
|
1373
|
+
function generateRuntimeShield(config) {
|
|
1374
|
+
const seed = config.seed >>> 0;
|
|
1375
|
+
const windowKeySymbol = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1376
|
+
const integrityCheckFnName = deriveIntegrityFnName(seed);
|
|
1377
|
+
const preambleCode = createDeterrentSnippet({
|
|
1378
|
+
...config,
|
|
1379
|
+
windowKeySymbol
|
|
1380
|
+
});
|
|
1381
|
+
const fnStart = preambleCode.indexOf("function");
|
|
1382
|
+
const fnEnd = preambleCode.lastIndexOf("(") - 1;
|
|
1383
|
+
const fnDecl = preambleCode.slice(fnStart, fnEnd);
|
|
1384
|
+
const computedHash = computeIntegrityHash(fnDecl, 0);
|
|
1385
|
+
const expectedHash = config.expectedIntegrityHash !== void 0 ? config.expectedIntegrityHash >>> 0 : computedHash;
|
|
1386
|
+
const expectedDelta = config.expectedDelta !== void 0 ? config.expectedDelta & 31 : computedHash >>> 0 & 31;
|
|
1387
|
+
return {
|
|
1388
|
+
preambleCode,
|
|
1389
|
+
integrityCheckFnName,
|
|
1390
|
+
expectedHash,
|
|
1391
|
+
windowKeySymbol,
|
|
1392
|
+
expectedDelta
|
|
1393
|
+
};
|
|
830
1394
|
}
|
|
831
1395
|
|
|
832
1396
|
// src/ast/string-vault.ts
|
|
833
|
-
var
|
|
834
|
-
var walk2 = __toESM(require("acorn-walk"), 1);
|
|
1397
|
+
var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
|
|
835
1398
|
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
836
1399
|
"use strict",
|
|
837
1400
|
"use client",
|
|
838
1401
|
"use server",
|
|
839
1402
|
"use asm"
|
|
840
1403
|
]);
|
|
841
|
-
var
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
1404
|
+
var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
|
|
1405
|
+
"id",
|
|
1406
|
+
"type",
|
|
1407
|
+
"key",
|
|
1408
|
+
"ref",
|
|
1409
|
+
"className",
|
|
1410
|
+
"style",
|
|
1411
|
+
"name",
|
|
1412
|
+
"value",
|
|
1413
|
+
"children",
|
|
1414
|
+
"src",
|
|
1415
|
+
"href",
|
|
1416
|
+
"alt",
|
|
1417
|
+
"role",
|
|
1418
|
+
"tabIndex"
|
|
1419
|
+
]);
|
|
1420
|
+
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-|\[&_)/;
|
|
1421
|
+
var SVG_PATH_RE = /^[Mm]\s*-?\d+(?:\.\d+)?[\s,]+-?\d+/;
|
|
1422
|
+
var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|vec4f|gl_Position|uniform/;
|
|
1423
|
+
function shouldEncryptString(val, minLen) {
|
|
1424
|
+
if (val.length < minLen || DIRECTIVE_STRINGS.has(val)) return false;
|
|
1425
|
+
if (SVG_PATH_RE.test(val)) return false;
|
|
1426
|
+
if (val.includes(" ")) {
|
|
1427
|
+
const tokens = val.trim().split(/\s+/);
|
|
1428
|
+
if (tokens.length >= 3) {
|
|
1429
|
+
let twHits = 0;
|
|
1430
|
+
for (const t of tokens) {
|
|
1431
|
+
if (TAILWIND_TOKEN_RE.test(t)) twHits++;
|
|
1432
|
+
}
|
|
1433
|
+
if (twHits / tokens.length >= 0.5) return false;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
return true;
|
|
867
1437
|
}
|
|
868
1438
|
function computeFnv1aHash(input, seed = 2166136261) {
|
|
869
1439
|
let hash = seed >>> 0;
|
|
@@ -873,31 +1443,127 @@ function computeFnv1aHash(input, seed = 2166136261) {
|
|
|
873
1443
|
}
|
|
874
1444
|
return hash >>> 0;
|
|
875
1445
|
}
|
|
876
|
-
function
|
|
1446
|
+
function createPermutationTable(seed) {
|
|
1447
|
+
let s = (seed || 305419896) >>> 0;
|
|
1448
|
+
function xorshift() {
|
|
1449
|
+
s ^= s << 13;
|
|
1450
|
+
s ^= s >>> 17;
|
|
1451
|
+
s ^= s << 5;
|
|
1452
|
+
return s >>> 0;
|
|
1453
|
+
}
|
|
1454
|
+
const indices = [];
|
|
1455
|
+
for (let i = 0; i < 92; i++) indices.push(i);
|
|
1456
|
+
for (let i = 91; i > 0; i--) {
|
|
1457
|
+
const j = xorshift() % (i + 1);
|
|
1458
|
+
const tmp = indices[i];
|
|
1459
|
+
indices[i] = indices[j];
|
|
1460
|
+
indices[j] = tmp;
|
|
1461
|
+
}
|
|
1462
|
+
const B = new Array(92);
|
|
1463
|
+
for (let i = 0; i < 46; i++) {
|
|
1464
|
+
const a = indices[2 * i];
|
|
1465
|
+
const b = indices[2 * i + 1];
|
|
1466
|
+
B[a] = b;
|
|
1467
|
+
B[b] = a;
|
|
1468
|
+
}
|
|
1469
|
+
let P_CHARS = "";
|
|
1470
|
+
for (let i = 0; i < 92; i++) {
|
|
1471
|
+
P_CHARS += SAFE_ALPHA[B[i]];
|
|
1472
|
+
}
|
|
1473
|
+
return P_CHARS;
|
|
1474
|
+
}
|
|
1475
|
+
function encodeStringWithSeed(str, P_CHARS, expectedRot) {
|
|
877
1476
|
let out = "";
|
|
878
1477
|
for (let i = 0; i < str.length; i++) {
|
|
879
|
-
const
|
|
880
|
-
const k = (
|
|
881
|
-
|
|
1478
|
+
const c = str.charAt(i);
|
|
1479
|
+
const k = SAFE_ALPHA.indexOf(c);
|
|
1480
|
+
if (k < 0) {
|
|
1481
|
+
out += c;
|
|
1482
|
+
} else {
|
|
1483
|
+
const y = (k + expectedRot) % 92;
|
|
1484
|
+
const z = SAFE_ALPHA.indexOf(P_CHARS.charAt(y));
|
|
1485
|
+
out += SAFE_ALPHA.charAt((z - expectedRot + 92) % 92);
|
|
1486
|
+
}
|
|
882
1487
|
}
|
|
883
1488
|
return out;
|
|
884
1489
|
}
|
|
885
|
-
function
|
|
1490
|
+
function createVaultHelperAst(cacheVarName, encryptedPayloads, fnAst) {
|
|
1491
|
+
return {
|
|
1492
|
+
type: "VariableDeclaration",
|
|
1493
|
+
kind: "var",
|
|
1494
|
+
declarations: [
|
|
1495
|
+
{
|
|
1496
|
+
type: "VariableDeclarator",
|
|
1497
|
+
id: { type: "Identifier", name: cacheVarName },
|
|
1498
|
+
init: {
|
|
1499
|
+
type: "CallExpression",
|
|
1500
|
+
callee: fnAst,
|
|
1501
|
+
arguments: [
|
|
1502
|
+
{
|
|
1503
|
+
type: "ArrayExpression",
|
|
1504
|
+
elements: encryptedPayloads.map((str) => ({
|
|
1505
|
+
type: "Literal",
|
|
1506
|
+
value: str,
|
|
1507
|
+
raw: JSON.stringify(str)
|
|
1508
|
+
}))
|
|
1509
|
+
}
|
|
1510
|
+
],
|
|
1511
|
+
optional: false
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
]
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
1518
|
+
const b64List = [];
|
|
1519
|
+
const key = seed >>> 0 & 255 ^ 90;
|
|
1520
|
+
for (let idx = 0; idx < shaderPayloads.length; idx++) {
|
|
1521
|
+
const str = shaderPayloads[idx];
|
|
1522
|
+
const buf = Buffer.from(str, "utf8");
|
|
1523
|
+
for (let i = 0; i < buf.length; i++) {
|
|
1524
|
+
buf[i] ^= key;
|
|
1525
|
+
}
|
|
1526
|
+
b64List.push(buf.toString("base64"));
|
|
1527
|
+
}
|
|
1528
|
+
const shaderCode = `var ${shaderVarName} = (function(){var B=${JSON.stringify(
|
|
1529
|
+
b64List
|
|
1530
|
+
)};var k=${key};var b=B.map(function(s){var bin=typeof atob==='function'?atob(s):(typeof Buffer!=='undefined'?Buffer.from(s,'base64').toString('binary'):'');var u=new Uint8Array(bin.length);for(var i=0;i<bin.length;i++)u[i]=bin.charCodeAt(i);return u;});var d=typeof TextDecoder!=='undefined'?new TextDecoder():null;return function(i){var u=b[i];for(var j=0;j<u.length;j++)u[j]^=k;try{return d?d.decode(u):String.fromCharCode.apply(null,u);}finally{for(var j=0;j<u.length;j++)u[j]^=k;}};})();`;
|
|
1531
|
+
return acorn2.parse(shaderCode, { ecmaVersion: "latest", sourceType: "script" }).body[0];
|
|
1532
|
+
}
|
|
1533
|
+
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta) {
|
|
1534
|
+
const cacheVarName = derivePolymorphicIdent(seed, "vault");
|
|
1535
|
+
const shaderVarName = derivePolymorphicIdent(seed, "shader");
|
|
1536
|
+
const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1537
|
+
let expDelta = expectedDelta;
|
|
1538
|
+
if (expDelta === void 0) {
|
|
1539
|
+
const shield = generateRuntimeShield({ seed, windowKeySymbol: sym });
|
|
1540
|
+
expDelta = shield.expectedDelta ?? 0;
|
|
1541
|
+
}
|
|
886
1542
|
const alreadyVaulted = ast.body.some(
|
|
887
1543
|
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
888
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uC")
|
|
1544
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && (d.id.name.startsWith("_uC") || 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")
|
|
889
1545
|
)
|
|
890
1546
|
);
|
|
891
1547
|
if (alreadyVaulted) {
|
|
892
1548
|
return {
|
|
893
1549
|
encryptedStringsCount: 0,
|
|
894
|
-
integrityToken: computeFnv1aHash("already-vaulted", seed)
|
|
1550
|
+
integrityToken: computeFnv1aHash("already-vaulted", seed),
|
|
1551
|
+
shaderBuffersCount: 0
|
|
895
1552
|
};
|
|
896
1553
|
}
|
|
897
|
-
const
|
|
898
|
-
const
|
|
1554
|
+
const P_CHARS = createPermutationTable(seed);
|
|
1555
|
+
const fBody = `var s=Function.prototype.toString,w=typeof window!=='undefined'&&window,src=s.call(f);for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var rot=(h^(a._u||0)^(w&&w['${sym}']!=null?w['${sym}']:${expDelta}))&31;var A="${SAFE_ALPHA}";var P="${P_CHARS}";return a.map(function(s){var o="";for(var j=0;j<s.length;j++){var c=s.charAt(j),k=A.indexOf(c);if(k<0){o+=c;}else{var y=(k+rot)%92;var z=A.indexOf(P.charAt(y));o+=A.charAt((z-rot+92)%92);}}return o;});`;
|
|
1556
|
+
const fnAst = acorn2.parse(`(function f(a){${fBody}})`, {
|
|
1557
|
+
ecmaVersion: "latest",
|
|
1558
|
+
sourceType: "script"
|
|
1559
|
+
}).body[0].expression;
|
|
1560
|
+
const compactFnStr = generateCompactJs(fnAst);
|
|
1561
|
+
const buildH = computeIntegrityHash(compactFnStr, 0);
|
|
1562
|
+
const expectedRot = (buildH ^ 0 ^ expDelta) & 31;
|
|
899
1563
|
const stringToIndex = /* @__PURE__ */ new Map();
|
|
900
1564
|
const encryptedPayloads = [];
|
|
1565
|
+
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
1566
|
+
const shaderPayloads = [];
|
|
901
1567
|
const targetsToReplace = [];
|
|
902
1568
|
const customWalkBase = {
|
|
903
1569
|
...walk2.base,
|
|
@@ -912,7 +1578,6 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
912
1578
|
Literal(node, _state, ancestors) {
|
|
913
1579
|
if (typeof node.value !== "string") return;
|
|
914
1580
|
const val = node.value;
|
|
915
|
-
if (val.length < minStringLength) return;
|
|
916
1581
|
if (DIRECTIVE_STRINGS.has(val)) return;
|
|
917
1582
|
if (hotExemptNodes) {
|
|
918
1583
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
@@ -930,59 +1595,125 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
930
1595
|
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
931
1596
|
return;
|
|
932
1597
|
}
|
|
933
|
-
if (parent.type === "Property" && parent.key === node) {
|
|
934
|
-
parent.computed = true;
|
|
935
|
-
}
|
|
936
1598
|
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
937
1599
|
return;
|
|
938
1600
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1601
|
+
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
1602
|
+
if (STANDARD_PROP_KEYS.has(val)) {
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
1607
|
+
if (isShader) {
|
|
1608
|
+
let idx = shaderToIndex.get(val);
|
|
1609
|
+
if (idx === void 0) {
|
|
1610
|
+
idx = shaderPayloads.length;
|
|
1611
|
+
shaderToIndex.set(val, idx);
|
|
1612
|
+
shaderPayloads.push(val);
|
|
1613
|
+
}
|
|
1614
|
+
targetsToReplace.push({ type: "shader", node, parent, idx });
|
|
1615
|
+
} else {
|
|
1616
|
+
if (!shouldEncryptString(val, minStringLength)) return;
|
|
1617
|
+
let idx = stringToIndex.get(val);
|
|
1618
|
+
if (idx === void 0) {
|
|
1619
|
+
idx = encryptedPayloads.length;
|
|
1620
|
+
stringToIndex.set(val, idx);
|
|
1621
|
+
encryptedPayloads.push(
|
|
1622
|
+
encodeStringWithSeed(val, P_CHARS, expectedRot)
|
|
1623
|
+
);
|
|
1624
|
+
}
|
|
1625
|
+
targetsToReplace.push({ type: "string", node, parent, idx });
|
|
1626
|
+
}
|
|
1627
|
+
},
|
|
1628
|
+
TemplateLiteral(node, _state, ancestors) {
|
|
1629
|
+
if (!node.quasis || node.quasis.length !== 1) return;
|
|
1630
|
+
if (node.expressions && node.expressions.length !== 0) return;
|
|
1631
|
+
if (hotExemptNodes) {
|
|
1632
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1633
|
+
if (hotExemptNodes.has(ancestors[i])) {
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
const parent = ancestors[ancestors.length - 2];
|
|
1639
|
+
if (!parent) return;
|
|
1640
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
1641
|
+
if (typeof val !== "string" || DIRECTIVE_STRINGS.has(val)) return;
|
|
1642
|
+
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
1643
|
+
if (isShader) {
|
|
1644
|
+
let idx = shaderToIndex.get(val);
|
|
1645
|
+
if (idx === void 0) {
|
|
1646
|
+
idx = shaderPayloads.length;
|
|
1647
|
+
shaderToIndex.set(val, idx);
|
|
1648
|
+
shaderPayloads.push(val);
|
|
1649
|
+
}
|
|
1650
|
+
targetsToReplace.push({ type: "shader", node, parent, idx });
|
|
1651
|
+
} else {
|
|
1652
|
+
if (!shouldEncryptString(val, minStringLength)) return;
|
|
1653
|
+
let idx = stringToIndex.get(val);
|
|
1654
|
+
if (idx === void 0) {
|
|
1655
|
+
idx = encryptedPayloads.length;
|
|
1656
|
+
stringToIndex.set(val, idx);
|
|
1657
|
+
encryptedPayloads.push(
|
|
1658
|
+
encodeStringWithSeed(val, P_CHARS, expectedRot)
|
|
1659
|
+
);
|
|
1660
|
+
}
|
|
1661
|
+
targetsToReplace.push({ type: "string", node, parent, idx });
|
|
944
1662
|
}
|
|
945
|
-
targetsToReplace.push({ node, parent });
|
|
946
1663
|
}
|
|
947
1664
|
},
|
|
948
1665
|
customWalkBase
|
|
949
1666
|
);
|
|
950
|
-
if (targetsToReplace.length === 0
|
|
1667
|
+
if (targetsToReplace.length === 0) {
|
|
951
1668
|
return {
|
|
952
1669
|
encryptedStringsCount: 0,
|
|
953
|
-
integrityToken: computeFnv1aHash("empty", seed)
|
|
1670
|
+
integrityToken: computeFnv1aHash("empty", seed),
|
|
1671
|
+
shaderBuffersCount: 0
|
|
954
1672
|
};
|
|
955
1673
|
}
|
|
956
1674
|
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
957
1675
|
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
958
|
-
const
|
|
959
|
-
const cacheVarName = `_uC${suffix}`;
|
|
960
|
-
for (const { node, parent } of targetsToReplace) {
|
|
1676
|
+
for (const { type, node, parent, idx } of targetsToReplace) {
|
|
961
1677
|
if (parent?.type === "Property" && parent.key === node) {
|
|
962
1678
|
parent.computed = true;
|
|
963
1679
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1680
|
+
if (type === "shader") {
|
|
1681
|
+
node.type = "CallExpression";
|
|
1682
|
+
node.callee = {
|
|
1683
|
+
type: "Identifier",
|
|
1684
|
+
name: shaderVarName
|
|
1685
|
+
};
|
|
1686
|
+
node.arguments = [
|
|
1687
|
+
{
|
|
1688
|
+
type: "Literal",
|
|
1689
|
+
value: idx,
|
|
1690
|
+
raw: String(idx)
|
|
1691
|
+
}
|
|
1692
|
+
];
|
|
1693
|
+
node.optional = false;
|
|
1694
|
+
delete node.value;
|
|
1695
|
+
delete node.raw;
|
|
1696
|
+
delete node.quasis;
|
|
1697
|
+
delete node.expressions;
|
|
1698
|
+
} else {
|
|
1699
|
+
node.type = "MemberExpression";
|
|
1700
|
+
node.object = {
|
|
1701
|
+
type: "Identifier",
|
|
1702
|
+
name: cacheVarName
|
|
1703
|
+
};
|
|
1704
|
+
node.property = {
|
|
1705
|
+
type: "Literal",
|
|
1706
|
+
value: idx,
|
|
1707
|
+
raw: String(idx)
|
|
1708
|
+
};
|
|
1709
|
+
node.computed = true;
|
|
1710
|
+
node.optional = false;
|
|
1711
|
+
delete node.value;
|
|
1712
|
+
delete node.raw;
|
|
1713
|
+
delete node.quasis;
|
|
1714
|
+
delete node.expressions;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
986
1717
|
let insertIdx = 0;
|
|
987
1718
|
while (insertIdx < ast.body.length) {
|
|
988
1719
|
const stmt = ast.body[insertIdx];
|
|
@@ -993,10 +1724,26 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
993
1724
|
break;
|
|
994
1725
|
}
|
|
995
1726
|
}
|
|
996
|
-
|
|
1727
|
+
if (encryptedPayloads.length > 0) {
|
|
1728
|
+
const vaultHelperStmt = createVaultHelperAst(
|
|
1729
|
+
cacheVarName,
|
|
1730
|
+
encryptedPayloads,
|
|
1731
|
+
fnAst
|
|
1732
|
+
);
|
|
1733
|
+
ast.body.splice(insertIdx++, 0, vaultHelperStmt);
|
|
1734
|
+
}
|
|
1735
|
+
if (shaderPayloads.length > 0) {
|
|
1736
|
+
const shaderHelperStmt = createShaderVaultAst(
|
|
1737
|
+
shaderVarName,
|
|
1738
|
+
shaderPayloads,
|
|
1739
|
+
seed
|
|
1740
|
+
);
|
|
1741
|
+
ast.body.splice(insertIdx++, 0, shaderHelperStmt);
|
|
1742
|
+
}
|
|
997
1743
|
return {
|
|
998
1744
|
encryptedStringsCount: encryptedPayloads.length,
|
|
999
|
-
integrityToken
|
|
1745
|
+
integrityToken,
|
|
1746
|
+
shaderBuffersCount: shaderPayloads.length
|
|
1000
1747
|
};
|
|
1001
1748
|
}
|
|
1002
1749
|
|
|
@@ -1095,9 +1842,9 @@ function collectPatternTargets(pattern, out, shorthandProp) {
|
|
|
1095
1842
|
}
|
|
1096
1843
|
}
|
|
1097
1844
|
function isMangleableName(origName) {
|
|
1098
|
-
return !RESERVED_IDENTIFIERS.has(origName) && !origName.startsWith("_u") && !origName.startsWith("_0x");
|
|
1845
|
+
return origName.length > 2 && !RESERVED_IDENTIFIERS.has(origName) && !origName.startsWith("_u") && !origName.startsWith("_0x") && !origName.startsWith("$$");
|
|
1099
1846
|
}
|
|
1100
|
-
function applyPolymorphicMangler(ast, seed = 2654435769) {
|
|
1847
|
+
function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes) {
|
|
1101
1848
|
const scopeRecords = /* @__PURE__ */ new Map();
|
|
1102
1849
|
const existingIdentifiers = /* @__PURE__ */ new Set();
|
|
1103
1850
|
let counter = 0;
|
|
@@ -1143,11 +1890,16 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
|
|
|
1143
1890
|
}
|
|
1144
1891
|
return ancestors[0];
|
|
1145
1892
|
}
|
|
1146
|
-
function registerBindingTarget(scopeNode, target, shouldMangle) {
|
|
1893
|
+
function registerBindingTarget(scopeNode, target, shouldMangle, fnScope) {
|
|
1147
1894
|
const scope = scopeRecords.get(scopeNode);
|
|
1148
1895
|
if (!scope) return;
|
|
1149
1896
|
const origName = target.idNode.name;
|
|
1150
|
-
|
|
1897
|
+
let canMangle = shouldMangle && isMangleableName(origName);
|
|
1898
|
+
if (canMangle && fnScope) {
|
|
1899
|
+
if (serializedFunctionNodes && serializedFunctionNodes.has(fnScope)) {
|
|
1900
|
+
canMangle = false;
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1151
1903
|
let entry = scope.bindings.get(origName);
|
|
1152
1904
|
if (!entry) {
|
|
1153
1905
|
entry = {
|
|
@@ -1186,7 +1938,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
|
|
|
1186
1938
|
const targets = [];
|
|
1187
1939
|
collectPatternTargets(param, targets);
|
|
1188
1940
|
for (const target of targets) {
|
|
1189
|
-
registerBindingTarget(fnNode, target, true);
|
|
1941
|
+
registerBindingTarget(fnNode, target, true, fnNode);
|
|
1190
1942
|
}
|
|
1191
1943
|
}
|
|
1192
1944
|
}
|
|
@@ -1256,10 +2008,11 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
|
|
|
1256
2008
|
CatchClause(node, _state, ancestors) {
|
|
1257
2009
|
ensureScopeChain(ancestors);
|
|
1258
2010
|
if (node.param) {
|
|
2011
|
+
const fnScope = findEnclosingFunctionNode(ancestors);
|
|
1259
2012
|
const targets = [];
|
|
1260
2013
|
collectPatternTargets(node.param, targets);
|
|
1261
2014
|
for (const target of targets) {
|
|
1262
|
-
registerBindingTarget(node, target, true);
|
|
2015
|
+
registerBindingTarget(node, target, true, fnScope);
|
|
1263
2016
|
}
|
|
1264
2017
|
}
|
|
1265
2018
|
},
|
|
@@ -1294,7 +2047,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
|
|
|
1294
2047
|
}
|
|
1295
2048
|
}
|
|
1296
2049
|
}
|
|
1297
|
-
registerBindingTarget(targetScopeNode, target, true);
|
|
2050
|
+
registerBindingTarget(targetScopeNode, target, true, fnScope);
|
|
1298
2051
|
}
|
|
1299
2052
|
}
|
|
1300
2053
|
}
|
|
@@ -1310,12 +2063,16 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
|
|
|
1310
2063
|
}
|
|
1311
2064
|
return false;
|
|
1312
2065
|
}
|
|
2066
|
+
const ALPHABET = "abcdefghijklmnopqrstuvwxyz";
|
|
1313
2067
|
function makeScopedMangledName(scope, localIndex) {
|
|
1314
2068
|
counter++;
|
|
1315
2069
|
let salt = 0;
|
|
1316
2070
|
while (true) {
|
|
1317
2071
|
const h = computeFnv1aHash(`s${scope.depth}:i${localIndex}:${salt}`, seed);
|
|
1318
|
-
const
|
|
2072
|
+
const prefix = (h & 1) === 0 ? "_" : "$";
|
|
2073
|
+
const ch = ALPHABET[((h >>> 1) + localIndex) % ALPHABET.length];
|
|
2074
|
+
const num = (localIndex + salt).toString(36);
|
|
2075
|
+
const candidate = `${prefix}${ch}${num}`;
|
|
1319
2076
|
if (!isNameUsedInScopeOrAncestors(candidate, scope)) {
|
|
1320
2077
|
return candidate;
|
|
1321
2078
|
}
|
|
@@ -1425,227 +2182,420 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
|
|
|
1425
2182
|
|
|
1426
2183
|
// src/ast/cold-flow-guard.ts
|
|
1427
2184
|
var walk4 = __toESM(require("acorn-walk"), 1);
|
|
1428
|
-
function
|
|
1429
|
-
const
|
|
1430
|
-
if (
|
|
2185
|
+
function createDecoyObjectExpression(model) {
|
|
2186
|
+
const m = Math.abs(model) % 3;
|
|
2187
|
+
if (m === 0) {
|
|
1431
2188
|
return {
|
|
1432
|
-
type: "
|
|
1433
|
-
|
|
2189
|
+
type: "ObjectExpression",
|
|
2190
|
+
properties: [
|
|
1434
2191
|
{
|
|
1435
|
-
type: "
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
value: { type: "Literal", value: 1, raw: "1" },
|
|
1465
|
-
kind: "init",
|
|
1466
|
-
computed: false,
|
|
1467
|
-
method: false,
|
|
1468
|
-
shorthand: false
|
|
1469
|
-
}
|
|
1470
|
-
]
|
|
1471
|
-
}
|
|
2192
|
+
type: "Property",
|
|
2193
|
+
key: { type: "Identifier", name: "endpoint" },
|
|
2194
|
+
value: {
|
|
2195
|
+
type: "Literal",
|
|
2196
|
+
value: "/api/v2/auth/admin-bypass",
|
|
2197
|
+
raw: '"/api/v2/auth/admin-bypass"'
|
|
2198
|
+
},
|
|
2199
|
+
kind: "init",
|
|
2200
|
+
computed: false,
|
|
2201
|
+
method: false,
|
|
2202
|
+
shorthand: false
|
|
2203
|
+
},
|
|
2204
|
+
{
|
|
2205
|
+
type: "Property",
|
|
2206
|
+
key: { type: "Identifier", name: "superadmin_token" },
|
|
2207
|
+
value: { type: "Literal", value: 1, raw: "1" },
|
|
2208
|
+
kind: "init",
|
|
2209
|
+
computed: false,
|
|
2210
|
+
method: false,
|
|
2211
|
+
shorthand: false
|
|
2212
|
+
},
|
|
2213
|
+
{
|
|
2214
|
+
type: "Property",
|
|
2215
|
+
key: { type: "Identifier", name: "elevate" },
|
|
2216
|
+
value: { type: "Literal", value: 1, raw: "1" },
|
|
2217
|
+
kind: "init",
|
|
2218
|
+
computed: false,
|
|
2219
|
+
method: false,
|
|
2220
|
+
shorthand: false
|
|
1472
2221
|
}
|
|
1473
2222
|
]
|
|
1474
2223
|
};
|
|
1475
2224
|
}
|
|
1476
|
-
if (
|
|
2225
|
+
if (m === 1) {
|
|
1477
2226
|
return {
|
|
1478
|
-
type: "
|
|
1479
|
-
|
|
2227
|
+
type: "ObjectExpression",
|
|
2228
|
+
properties: [
|
|
1480
2229
|
{
|
|
1481
|
-
type: "
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
value: { type: "Literal", value: true, raw: "true" },
|
|
1524
|
-
kind: "init",
|
|
1525
|
-
computed: false,
|
|
1526
|
-
method: false,
|
|
1527
|
-
shorthand: false
|
|
1528
|
-
}
|
|
1529
|
-
]
|
|
1530
|
-
}
|
|
2230
|
+
type: "Property",
|
|
2231
|
+
key: { type: "Identifier", name: "endpoint" },
|
|
2232
|
+
value: {
|
|
2233
|
+
type: "Literal",
|
|
2234
|
+
value: "/api/v2/auth/verify-master",
|
|
2235
|
+
raw: '"/api/v2/auth/verify-master"'
|
|
2236
|
+
},
|
|
2237
|
+
kind: "init",
|
|
2238
|
+
computed: false,
|
|
2239
|
+
method: false,
|
|
2240
|
+
shorthand: false
|
|
2241
|
+
},
|
|
2242
|
+
{
|
|
2243
|
+
type: "Property",
|
|
2244
|
+
key: { type: "Identifier", name: "_verifyMasterToken" },
|
|
2245
|
+
value: { type: "Literal", value: true, raw: "true" },
|
|
2246
|
+
kind: "init",
|
|
2247
|
+
computed: false,
|
|
2248
|
+
method: false,
|
|
2249
|
+
shorthand: false
|
|
2250
|
+
},
|
|
2251
|
+
{
|
|
2252
|
+
type: "Property",
|
|
2253
|
+
key: { type: "Identifier", name: "_bypassToken" },
|
|
2254
|
+
value: {
|
|
2255
|
+
type: "Literal",
|
|
2256
|
+
value: "mock_jwt_bypass_signature",
|
|
2257
|
+
raw: '"mock_jwt_bypass_signature"'
|
|
2258
|
+
},
|
|
2259
|
+
kind: "init",
|
|
2260
|
+
computed: false,
|
|
2261
|
+
method: false,
|
|
2262
|
+
shorthand: false
|
|
2263
|
+
},
|
|
2264
|
+
{
|
|
2265
|
+
type: "Property",
|
|
2266
|
+
key: { type: "Identifier", name: "authorized" },
|
|
2267
|
+
value: { type: "Literal", value: true, raw: "true" },
|
|
2268
|
+
kind: "init",
|
|
2269
|
+
computed: false,
|
|
2270
|
+
method: false,
|
|
2271
|
+
shorthand: false
|
|
1531
2272
|
}
|
|
1532
2273
|
]
|
|
1533
2274
|
};
|
|
1534
2275
|
}
|
|
2276
|
+
return {
|
|
2277
|
+
type: "ObjectExpression",
|
|
2278
|
+
properties: [
|
|
2279
|
+
{
|
|
2280
|
+
type: "Property",
|
|
2281
|
+
key: { type: "Identifier", name: "endpoint" },
|
|
2282
|
+
value: {
|
|
2283
|
+
type: "Literal",
|
|
2284
|
+
value: "/api/v2/auth/debug-telemetry",
|
|
2285
|
+
raw: '"/api/v2/auth/debug-telemetry"'
|
|
2286
|
+
},
|
|
2287
|
+
kind: "init",
|
|
2288
|
+
computed: false,
|
|
2289
|
+
method: false,
|
|
2290
|
+
shorthand: false
|
|
2291
|
+
},
|
|
2292
|
+
{
|
|
2293
|
+
type: "Property",
|
|
2294
|
+
key: { type: "Identifier", name: "debug_supervisor_override" },
|
|
2295
|
+
value: { type: "Literal", value: true, raw: "true" },
|
|
2296
|
+
kind: "init",
|
|
2297
|
+
computed: false,
|
|
2298
|
+
method: false,
|
|
2299
|
+
shorthand: false
|
|
2300
|
+
},
|
|
2301
|
+
{
|
|
2302
|
+
type: "Property",
|
|
2303
|
+
key: { type: "Identifier", name: "_bypassToken" },
|
|
2304
|
+
value: {
|
|
2305
|
+
type: "Literal",
|
|
2306
|
+
value: "superadmin_token",
|
|
2307
|
+
raw: '"superadmin_token"'
|
|
2308
|
+
},
|
|
2309
|
+
kind: "init",
|
|
2310
|
+
computed: false,
|
|
2311
|
+
method: false,
|
|
2312
|
+
shorthand: false
|
|
2313
|
+
},
|
|
2314
|
+
{
|
|
2315
|
+
type: "Property",
|
|
2316
|
+
key: { type: "Identifier", name: "mfa_bypassed" },
|
|
2317
|
+
value: { type: "Literal", value: true, raw: "true" },
|
|
2318
|
+
kind: "init",
|
|
2319
|
+
computed: false,
|
|
2320
|
+
method: false,
|
|
2321
|
+
shorthand: false
|
|
2322
|
+
}
|
|
2323
|
+
]
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
function createDecoyConsequent(fnIndex) {
|
|
2327
|
+
return {
|
|
2328
|
+
type: "BlockStatement",
|
|
2329
|
+
body: [
|
|
2330
|
+
{
|
|
2331
|
+
type: "ReturnStatement",
|
|
2332
|
+
argument: createDecoyObjectExpression(fnIndex)
|
|
2333
|
+
}
|
|
2334
|
+
]
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
function createSharedDecoyConsequent(decoyIdent, fnIndex) {
|
|
2338
|
+
const model = Math.abs(fnIndex) % 3;
|
|
1535
2339
|
return {
|
|
1536
2340
|
type: "BlockStatement",
|
|
1537
2341
|
body: [
|
|
1538
2342
|
{
|
|
1539
2343
|
type: "ReturnStatement",
|
|
1540
2344
|
argument: {
|
|
1541
|
-
type: "
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
},
|
|
1551
|
-
kind: "init",
|
|
1552
|
-
computed: false,
|
|
1553
|
-
method: false,
|
|
1554
|
-
shorthand: false
|
|
1555
|
-
},
|
|
1556
|
-
{
|
|
1557
|
-
type: "Property",
|
|
1558
|
-
key: { type: "Identifier", name: "debug_supervisor_override" },
|
|
1559
|
-
value: { type: "Literal", value: true, raw: "true" },
|
|
1560
|
-
kind: "init",
|
|
1561
|
-
computed: false,
|
|
1562
|
-
method: false,
|
|
1563
|
-
shorthand: false
|
|
1564
|
-
},
|
|
1565
|
-
{
|
|
1566
|
-
type: "Property",
|
|
1567
|
-
key: { type: "Identifier", name: "_bypassToken" },
|
|
1568
|
-
value: {
|
|
1569
|
-
type: "Literal",
|
|
1570
|
-
value: "superadmin_token",
|
|
1571
|
-
raw: '"superadmin_token"'
|
|
1572
|
-
},
|
|
1573
|
-
kind: "init",
|
|
1574
|
-
computed: false,
|
|
1575
|
-
method: false,
|
|
1576
|
-
shorthand: false
|
|
1577
|
-
},
|
|
1578
|
-
{
|
|
1579
|
-
type: "Property",
|
|
1580
|
-
key: { type: "Identifier", name: "mfa_bypassed" },
|
|
1581
|
-
value: { type: "Literal", value: true, raw: "true" },
|
|
1582
|
-
kind: "init",
|
|
1583
|
-
computed: false,
|
|
1584
|
-
method: false,
|
|
1585
|
-
shorthand: false
|
|
2345
|
+
type: "CallExpression",
|
|
2346
|
+
callee: {
|
|
2347
|
+
type: "MemberExpression",
|
|
2348
|
+
computed: true,
|
|
2349
|
+
object: { type: "Identifier", name: decoyIdent },
|
|
2350
|
+
property: {
|
|
2351
|
+
type: "Literal",
|
|
2352
|
+
value: model,
|
|
2353
|
+
raw: String(model)
|
|
1586
2354
|
}
|
|
1587
|
-
|
|
2355
|
+
},
|
|
2356
|
+
arguments: []
|
|
1588
2357
|
}
|
|
1589
2358
|
}
|
|
1590
2359
|
]
|
|
1591
2360
|
};
|
|
1592
2361
|
}
|
|
1593
|
-
function
|
|
1594
|
-
|
|
1595
|
-
|
|
2362
|
+
function createSharedDecoyDeclaration(decoyIdent = "_d") {
|
|
2363
|
+
return {
|
|
2364
|
+
type: "VariableDeclaration",
|
|
2365
|
+
kind: "var",
|
|
2366
|
+
declarations: [
|
|
2367
|
+
{
|
|
2368
|
+
type: "VariableDeclarator",
|
|
2369
|
+
id: { type: "Identifier", name: decoyIdent },
|
|
2370
|
+
init: {
|
|
2371
|
+
type: "ArrayExpression",
|
|
2372
|
+
elements: [0, 1, 2].map((m) => ({
|
|
2373
|
+
type: "ArrowFunctionExpression",
|
|
2374
|
+
id: null,
|
|
2375
|
+
params: [],
|
|
2376
|
+
body: createDecoyObjectExpression(m),
|
|
2377
|
+
generator: false,
|
|
2378
|
+
async: false,
|
|
2379
|
+
expression: true
|
|
2380
|
+
}))
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
]
|
|
2384
|
+
};
|
|
2385
|
+
}
|
|
2386
|
+
function cloneNode(node) {
|
|
2387
|
+
return JSON.parse(JSON.stringify(node));
|
|
2388
|
+
}
|
|
2389
|
+
function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false) {
|
|
2390
|
+
const family = Math.abs(seed + fnIndex & 3);
|
|
2391
|
+
const c1 = (seed >>> 0) + Math.imul(family + 1, 73244475) | 0;
|
|
2392
|
+
const c2 = c1 ^ 1515870810 | 0;
|
|
2393
|
+
const target = (seed ^ Math.imul(family + 1, 2654435761)) & 8388607 | 1;
|
|
2394
|
+
let paramName = null;
|
|
2395
|
+
if (typeof paramNode === "string") {
|
|
2396
|
+
paramName = paramNode;
|
|
2397
|
+
} else if (paramNode?.type === "Identifier") {
|
|
2398
|
+
paramName = paramNode.name;
|
|
2399
|
+
} else if (paramNode?.type === "AssignmentPattern" && paramNode.left?.type === "Identifier") {
|
|
2400
|
+
paramName = paramNode.left.name;
|
|
2401
|
+
}
|
|
2402
|
+
const zNode = {
|
|
2403
|
+
type: "UnaryExpression",
|
|
2404
|
+
operator: "+",
|
|
2405
|
+
prefix: true,
|
|
2406
|
+
argument: {
|
|
2407
|
+
type: "UnaryExpression",
|
|
2408
|
+
operator: "!",
|
|
2409
|
+
prefix: true,
|
|
2410
|
+
argument: { type: "Identifier", name: "String" }
|
|
2411
|
+
}
|
|
2412
|
+
};
|
|
2413
|
+
const vNode = {
|
|
2414
|
+
type: "BinaryExpression",
|
|
2415
|
+
operator: "|",
|
|
2416
|
+
left: zNode,
|
|
2417
|
+
right: { type: "Literal", value: c1, raw: String(c1) }
|
|
2418
|
+
};
|
|
2419
|
+
const kNode = {
|
|
2420
|
+
type: "BinaryExpression",
|
|
2421
|
+
operator: "|",
|
|
2422
|
+
left: { type: "Literal", value: c2, raw: String(c2) },
|
|
2423
|
+
right: {
|
|
2424
|
+
type: "UnaryExpression",
|
|
2425
|
+
operator: "!",
|
|
2426
|
+
prefix: true,
|
|
2427
|
+
argument: { type: "Identifier", name: "String" }
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
let mbaExpr;
|
|
2431
|
+
if (family === 0) {
|
|
2432
|
+
const vXorK = {
|
|
2433
|
+
type: "BinaryExpression",
|
|
2434
|
+
operator: "^",
|
|
2435
|
+
left: cloneNode(vNode),
|
|
2436
|
+
right: cloneNode(kNode)
|
|
2437
|
+
};
|
|
2438
|
+
const vAndK = {
|
|
2439
|
+
type: "BinaryExpression",
|
|
2440
|
+
operator: "&",
|
|
2441
|
+
left: cloneNode(vNode),
|
|
2442
|
+
right: cloneNode(kNode)
|
|
2443
|
+
};
|
|
2444
|
+
const shift = {
|
|
2445
|
+
type: "BinaryExpression",
|
|
2446
|
+
operator: "<<",
|
|
2447
|
+
left: vAndK,
|
|
2448
|
+
right: { type: "Literal", value: 1, raw: "1" }
|
|
2449
|
+
};
|
|
2450
|
+
const addLeft = {
|
|
2451
|
+
type: "BinaryExpression",
|
|
2452
|
+
operator: "+",
|
|
2453
|
+
left: vXorK,
|
|
2454
|
+
right: shift
|
|
2455
|
+
};
|
|
2456
|
+
const vPlusK = {
|
|
2457
|
+
type: "BinaryExpression",
|
|
2458
|
+
operator: "+",
|
|
2459
|
+
left: cloneNode(vNode),
|
|
2460
|
+
right: cloneNode(kNode)
|
|
2461
|
+
};
|
|
2462
|
+
mbaExpr = {
|
|
2463
|
+
type: "BinaryExpression",
|
|
2464
|
+
operator: "-",
|
|
2465
|
+
left: addLeft,
|
|
2466
|
+
right: vPlusK
|
|
2467
|
+
};
|
|
2468
|
+
} else if (family === 1) {
|
|
2469
|
+
const vOrK = {
|
|
2470
|
+
type: "BinaryExpression",
|
|
2471
|
+
operator: "|",
|
|
2472
|
+
left: cloneNode(vNode),
|
|
2473
|
+
right: cloneNode(kNode)
|
|
2474
|
+
};
|
|
2475
|
+
const vAndK = {
|
|
2476
|
+
type: "BinaryExpression",
|
|
2477
|
+
operator: "&",
|
|
2478
|
+
left: cloneNode(vNode),
|
|
2479
|
+
right: cloneNode(kNode)
|
|
2480
|
+
};
|
|
2481
|
+
const addLeft = {
|
|
2482
|
+
type: "BinaryExpression",
|
|
2483
|
+
operator: "+",
|
|
2484
|
+
left: vOrK,
|
|
2485
|
+
right: vAndK
|
|
2486
|
+
};
|
|
2487
|
+
const vPlusK = {
|
|
2488
|
+
type: "BinaryExpression",
|
|
2489
|
+
operator: "+",
|
|
2490
|
+
left: cloneNode(vNode),
|
|
2491
|
+
right: cloneNode(kNode)
|
|
2492
|
+
};
|
|
2493
|
+
mbaExpr = {
|
|
2494
|
+
type: "BinaryExpression",
|
|
2495
|
+
operator: "^",
|
|
2496
|
+
left: addLeft,
|
|
2497
|
+
right: vPlusK
|
|
2498
|
+
};
|
|
2499
|
+
} else if (family === 2) {
|
|
2500
|
+
const notK = {
|
|
2501
|
+
type: "UnaryExpression",
|
|
2502
|
+
operator: "~",
|
|
2503
|
+
prefix: true,
|
|
2504
|
+
argument: cloneNode(kNode)
|
|
2505
|
+
};
|
|
2506
|
+
const vOrNotK = {
|
|
2507
|
+
type: "BinaryExpression",
|
|
2508
|
+
operator: "|",
|
|
2509
|
+
left: cloneNode(vNode),
|
|
2510
|
+
right: cloneNode(notK)
|
|
2511
|
+
};
|
|
2512
|
+
const subLeft = {
|
|
2513
|
+
type: "BinaryExpression",
|
|
2514
|
+
operator: "-",
|
|
2515
|
+
left: vOrNotK,
|
|
2516
|
+
right: cloneNode(notK)
|
|
2517
|
+
};
|
|
2518
|
+
const vAndK = {
|
|
2519
|
+
type: "BinaryExpression",
|
|
2520
|
+
operator: "&",
|
|
2521
|
+
left: cloneNode(vNode),
|
|
2522
|
+
right: cloneNode(kNode)
|
|
2523
|
+
};
|
|
2524
|
+
mbaExpr = {
|
|
2525
|
+
type: "BinaryExpression",
|
|
2526
|
+
operator: "^",
|
|
2527
|
+
left: subLeft,
|
|
2528
|
+
right: vAndK
|
|
2529
|
+
};
|
|
2530
|
+
} else {
|
|
2531
|
+
const notK = {
|
|
2532
|
+
type: "UnaryExpression",
|
|
2533
|
+
operator: "~",
|
|
2534
|
+
prefix: true,
|
|
2535
|
+
argument: cloneNode(kNode)
|
|
2536
|
+
};
|
|
2537
|
+
const vAndNotK = {
|
|
2538
|
+
type: "BinaryExpression",
|
|
2539
|
+
operator: "&",
|
|
2540
|
+
left: cloneNode(vNode),
|
|
2541
|
+
right: cloneNode(notK)
|
|
2542
|
+
};
|
|
2543
|
+
const vAndK = {
|
|
2544
|
+
type: "BinaryExpression",
|
|
2545
|
+
operator: "&",
|
|
2546
|
+
left: cloneNode(vNode),
|
|
2547
|
+
right: cloneNode(kNode)
|
|
2548
|
+
};
|
|
2549
|
+
const addLeft = {
|
|
2550
|
+
type: "BinaryExpression",
|
|
2551
|
+
operator: "+",
|
|
2552
|
+
left: vAndNotK,
|
|
2553
|
+
right: vAndK
|
|
2554
|
+
};
|
|
2555
|
+
mbaExpr = {
|
|
2556
|
+
type: "BinaryExpression",
|
|
2557
|
+
operator: "^",
|
|
2558
|
+
left: addLeft,
|
|
2559
|
+
right: cloneNode(vNode)
|
|
2560
|
+
};
|
|
2561
|
+
}
|
|
2562
|
+
const decoyIdx = Math.abs(fnIndex) % 3;
|
|
2563
|
+
const consequent = decoyIdent ? createSharedDecoyConsequent(decoyIdent, decoyIdx) : createDecoyConsequent(decoyIdx);
|
|
1596
2564
|
return {
|
|
1597
2565
|
type: "IfStatement",
|
|
1598
2566
|
test: {
|
|
1599
2567
|
type: "BinaryExpression",
|
|
1600
2568
|
operator: "===",
|
|
1601
|
-
left:
|
|
1602
|
-
|
|
1603
|
-
operator: "|",
|
|
1604
|
-
left: {
|
|
1605
|
-
type: "BinaryExpression",
|
|
1606
|
-
operator: "^",
|
|
1607
|
-
left: {
|
|
1608
|
-
type: "BinaryExpression",
|
|
1609
|
-
operator: "+",
|
|
1610
|
-
left: {
|
|
1611
|
-
type: "BinaryExpression",
|
|
1612
|
-
operator: "|",
|
|
1613
|
-
left: { type: "Literal", value: x, raw: String(x) },
|
|
1614
|
-
right: { type: "Literal", value: y, raw: String(y) }
|
|
1615
|
-
},
|
|
1616
|
-
right: {
|
|
1617
|
-
type: "BinaryExpression",
|
|
1618
|
-
operator: "&",
|
|
1619
|
-
left: { type: "Literal", value: x, raw: String(x) },
|
|
1620
|
-
right: { type: "Literal", value: y, raw: String(y) }
|
|
1621
|
-
}
|
|
1622
|
-
},
|
|
1623
|
-
right: {
|
|
1624
|
-
type: "BinaryExpression",
|
|
1625
|
-
operator: "+",
|
|
1626
|
-
left: { type: "Literal", value: x, raw: String(x) },
|
|
1627
|
-
right: { type: "Literal", value: y, raw: String(y) }
|
|
1628
|
-
}
|
|
1629
|
-
},
|
|
1630
|
-
right: {
|
|
1631
|
-
type: "UnaryExpression",
|
|
1632
|
-
operator: "!",
|
|
1633
|
-
prefix: true,
|
|
1634
|
-
argument: { type: "Identifier", name: "String" }
|
|
1635
|
-
}
|
|
1636
|
-
},
|
|
1637
|
-
right: { type: "Literal", value: 2147483647, raw: "0x7fffffff" }
|
|
2569
|
+
left: mbaExpr,
|
|
2570
|
+
right: { type: "Literal", value: target, raw: String(target) }
|
|
1638
2571
|
},
|
|
1639
|
-
consequent
|
|
2572
|
+
consequent,
|
|
1640
2573
|
alternate: null
|
|
1641
2574
|
};
|
|
1642
2575
|
}
|
|
1643
2576
|
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
|
|
2577
|
+
const decoyIdent = "_d";
|
|
2578
|
+
if (Array.isArray(ast.body)) {
|
|
2579
|
+
const alreadyGuarded = ast.body.some(
|
|
2580
|
+
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
2581
|
+
(d) => d.id?.type === "Identifier" && d.id.name === decoyIdent
|
|
2582
|
+
)
|
|
2583
|
+
);
|
|
2584
|
+
if (alreadyGuarded) return 0;
|
|
2585
|
+
}
|
|
1644
2586
|
let guardedCount = 0;
|
|
1645
2587
|
function maybeInjectGuard(node) {
|
|
1646
2588
|
if (!coldFunctionNodes.has(node)) return;
|
|
1647
2589
|
if (!node.body || node.body.type !== "BlockStatement") return;
|
|
1648
|
-
const
|
|
2590
|
+
const firstParam = node.params?.[0];
|
|
2591
|
+
const isArrow = node.type === "ArrowFunctionExpression";
|
|
2592
|
+
const guardStmt = createSotaMbaPredicate(
|
|
2593
|
+
seed,
|
|
2594
|
+
guardedCount,
|
|
2595
|
+
firstParam,
|
|
2596
|
+
decoyIdent,
|
|
2597
|
+
isArrow
|
|
2598
|
+
);
|
|
1649
2599
|
guardedCount++;
|
|
1650
2600
|
if (hotExemptNodes) {
|
|
1651
2601
|
hotExemptNodes.add(guardStmt);
|
|
@@ -1662,64 +2612,946 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
1662
2612
|
FunctionExpression: maybeInjectGuard,
|
|
1663
2613
|
ArrowFunctionExpression: maybeInjectGuard
|
|
1664
2614
|
});
|
|
2615
|
+
if (guardedCount > 0 && Array.isArray(ast.body)) {
|
|
2616
|
+
const sharedDecoyDecl = createSharedDecoyDeclaration(decoyIdent);
|
|
2617
|
+
if (hotExemptNodes) {
|
|
2618
|
+
hotExemptNodes.add(sharedDecoyDecl);
|
|
2619
|
+
for (const decl of sharedDecoyDecl.declarations || []) {
|
|
2620
|
+
if (decl.init?.elements) {
|
|
2621
|
+
for (const el of decl.init.elements) {
|
|
2622
|
+
hotExemptNodes.add(el);
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
let insertIdx = 0;
|
|
2628
|
+
while (insertIdx < ast.body.length && ast.body[insertIdx].type === "ExpressionStatement" && ast.body[insertIdx].directive) {
|
|
2629
|
+
insertIdx++;
|
|
2630
|
+
}
|
|
2631
|
+
ast.body.splice(insertIdx, 0, sharedDecoyDecl);
|
|
2632
|
+
}
|
|
1665
2633
|
return guardedCount;
|
|
1666
2634
|
}
|
|
1667
2635
|
|
|
1668
|
-
// src/
|
|
1669
|
-
var
|
|
1670
|
-
var
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
2636
|
+
// src/ast/micro-vm.ts
|
|
2637
|
+
var acorn3 = __toESM(require("acorn"), 1);
|
|
2638
|
+
var walk5 = __toESM(require("acorn-walk"), 1);
|
|
2639
|
+
var OP_LDC = 0;
|
|
2640
|
+
var OP_LDV = 1;
|
|
2641
|
+
var OP_STV = 2;
|
|
2642
|
+
var OP_LDG = 3;
|
|
2643
|
+
var OP_GETP = 4;
|
|
2644
|
+
var OP_SETP = 5;
|
|
2645
|
+
var OP_CALL = 6;
|
|
2646
|
+
var OP_MCALL = 7;
|
|
2647
|
+
var OP_ADD = 8;
|
|
2648
|
+
var OP_SUB = 9;
|
|
2649
|
+
var OP_MUL = 10;
|
|
2650
|
+
var OP_XOR = 11;
|
|
2651
|
+
var OP_AND = 12;
|
|
2652
|
+
var OP_OR = 13;
|
|
2653
|
+
var OP_SEQ = 14;
|
|
2654
|
+
var OP_LT = 15;
|
|
2655
|
+
var OP_NOT = 16;
|
|
2656
|
+
var OP_JMP = 17;
|
|
2657
|
+
var OP_JZ = 18;
|
|
2658
|
+
var OP_RET = 19;
|
|
2659
|
+
var OP_THROW = 20;
|
|
2660
|
+
var OP_AWAIT = 21;
|
|
2661
|
+
var OP_OBJ = 22;
|
|
2662
|
+
var OP_ARR = 23;
|
|
2663
|
+
function generateOpcodeMap(seed) {
|
|
2664
|
+
const pool = [];
|
|
2665
|
+
for (let i = 0; i < 256; i++) pool.push(i);
|
|
2666
|
+
let s = (seed ^ 2779096485) >>> 0;
|
|
2667
|
+
function rand() {
|
|
2668
|
+
s ^= s << 13;
|
|
2669
|
+
s ^= s >>> 17;
|
|
2670
|
+
s ^= s << 5;
|
|
2671
|
+
return (s >>> 0) / 4294967296;
|
|
1676
2672
|
}
|
|
1677
|
-
|
|
2673
|
+
for (let i = pool.length - 1; i > 0; i--) {
|
|
2674
|
+
const j = Math.floor(rand() * (i + 1));
|
|
2675
|
+
const tmp = pool[i];
|
|
2676
|
+
pool[i] = pool[j];
|
|
2677
|
+
pool[j] = tmp;
|
|
2678
|
+
}
|
|
2679
|
+
return pool.slice(0, 24);
|
|
1678
2680
|
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
2681
|
+
function createInterpreterSource(vmHelperName, opMap) {
|
|
2682
|
+
return `function ${vmHelperName}(c, k, s, t) {
|
|
2683
|
+
var p = 0, r = 0, q = [];
|
|
2684
|
+
var G = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : this);
|
|
2685
|
+
function x() {
|
|
2686
|
+
while (p < c.length) {
|
|
2687
|
+
var o = c[p++];
|
|
2688
|
+
switch (o) {
|
|
2689
|
+
case ${opMap[OP_LDC]}: q[r++] = k[c[p++]]; break;
|
|
2690
|
+
case ${opMap[OP_LDV]}: q[r++] = s[c[p++]]; break;
|
|
2691
|
+
case ${opMap[OP_STV]}: s[c[p++]] = q[--r]; break;
|
|
2692
|
+
case ${opMap[OP_LDG]}: q[r++] = G[k[c[p++]]]; break;
|
|
2693
|
+
case ${opMap[OP_GETP]}: { var b = q[--r], a = q[--r]; q[r++] = a[b]; break; }
|
|
2694
|
+
case ${opMap[OP_SETP]}: { var v = q[--r], b = q[--r], a = q[--r]; q[r++] = (a[b] = v); break; }
|
|
2695
|
+
case ${opMap[OP_CALL]}: {
|
|
2696
|
+
var n = c[p++], g = [];
|
|
2697
|
+
for (var i = n - 1; i >= 0; i--) g[i] = q[--r];
|
|
2698
|
+
var f = q[--r]; q[r++] = f.apply(null, g); break;
|
|
2699
|
+
}
|
|
2700
|
+
case ${opMap[OP_MCALL]}: {
|
|
2701
|
+
var n = c[p++], g = [];
|
|
2702
|
+
for (var i = n - 1; i >= 0; i--) g[i] = q[--r];
|
|
2703
|
+
var b = q[--r], a = q[--r]; q[r++] = a[b].apply(a, g); break;
|
|
2704
|
+
}
|
|
2705
|
+
case ${opMap[OP_ADD]}: { var b = q[--r], a = q[--r]; q[r++] = a + b; break; }
|
|
2706
|
+
case ${opMap[OP_SUB]}: { var b = q[--r], a = q[--r]; q[r++] = a - b; break; }
|
|
2707
|
+
case ${opMap[OP_MUL]}: { var b = q[--r], a = q[--r]; q[r++] = a * b; break; }
|
|
2708
|
+
case ${opMap[OP_XOR]}: { var b = q[--r], a = q[--r]; q[r++] = a ^ b; break; }
|
|
2709
|
+
case ${opMap[OP_AND]}: { var b = q[--r], a = q[--r]; q[r++] = a & b; break; }
|
|
2710
|
+
case ${opMap[OP_OR]}: { var b = q[--r], a = q[--r]; q[r++] = a | b; break; }
|
|
2711
|
+
case ${opMap[OP_SEQ]}: { var b = q[--r], a = q[--r]; q[r++] = a === b; break; }
|
|
2712
|
+
case ${opMap[OP_LT]}: { var b = q[--r], a = q[--r]; q[r++] = a < b; break; }
|
|
2713
|
+
case ${opMap[OP_NOT]}: { q[r - 1] = !q[r - 1]; break; }
|
|
2714
|
+
case ${opMap[OP_JMP]}: { p = c[p]; break; }
|
|
2715
|
+
case ${opMap[OP_JZ]}: { var j = c[p++]; if (!q[--r]) p = j; break; }
|
|
2716
|
+
case ${opMap[OP_RET]}: return q[--r];
|
|
2717
|
+
case ${opMap[OP_THROW]}: throw q[--r];
|
|
2718
|
+
case ${opMap[OP_AWAIT]}: {
|
|
2719
|
+
var v = q[--r];
|
|
2720
|
+
return Promise.resolve(v).then(function(w) { q[r++] = w; return x(); });
|
|
2721
|
+
}
|
|
2722
|
+
case ${opMap[OP_OBJ]}: {
|
|
2723
|
+
var n = c[p++], o = {}, e = [];
|
|
2724
|
+
for (var i = 0; i < n; i++) { var v = q[--r], k0 = q[--r]; e.push([k0, v]); }
|
|
2725
|
+
for (var i = e.length - 1; i >= 0; i--) { o[e[i][0]] = e[i][1]; }
|
|
2726
|
+
q[r++] = o;
|
|
2727
|
+
break;
|
|
2728
|
+
}
|
|
2729
|
+
case ${opMap[OP_ARR]}: {
|
|
2730
|
+
var n = c[p++], a = [];
|
|
2731
|
+
for (var i = n - 1; i >= 0; i--) a[i] = q[--r];
|
|
2732
|
+
q[r++] = a;
|
|
2733
|
+
break;
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
return x();
|
|
2739
|
+
}`;
|
|
1684
2740
|
}
|
|
1685
|
-
function
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
return
|
|
2741
|
+
function countAstNodes(node) {
|
|
2742
|
+
let count = 0;
|
|
2743
|
+
walk5.full(node, () => {
|
|
2744
|
+
count++;
|
|
2745
|
+
});
|
|
2746
|
+
return count;
|
|
2747
|
+
}
|
|
2748
|
+
function hasForbiddenConstructs(fnNode) {
|
|
2749
|
+
let forbidden = false;
|
|
2750
|
+
walk5.full(fnNode, (node) => {
|
|
2751
|
+
if (forbidden) return;
|
|
2752
|
+
const type = node.type;
|
|
2753
|
+
if (type === "JSXElement" || type === "JSXFragment" || type === "Super" || type === "YieldExpression") {
|
|
2754
|
+
forbidden = true;
|
|
2755
|
+
return;
|
|
2756
|
+
}
|
|
2757
|
+
if (type === "Identifier" && node.name === "arguments") {
|
|
2758
|
+
forbidden = true;
|
|
2759
|
+
return;
|
|
2760
|
+
}
|
|
2761
|
+
if (type === "MetaProperty" && node.meta?.name === "new" && node.property?.name === "target") {
|
|
2762
|
+
forbidden = true;
|
|
2763
|
+
return;
|
|
2764
|
+
}
|
|
2765
|
+
});
|
|
2766
|
+
return forbidden;
|
|
2767
|
+
}
|
|
2768
|
+
function compileFunctionToBytecode(fnNode, opMap) {
|
|
2769
|
+
const bytecode = [];
|
|
2770
|
+
const consts = [];
|
|
2771
|
+
const localMap = /* @__PURE__ */ new Map();
|
|
2772
|
+
let localCount = 0;
|
|
2773
|
+
for (const param of fnNode.params) {
|
|
2774
|
+
if (param.type !== "Identifier") return null;
|
|
2775
|
+
localMap.set(param.name, localCount++);
|
|
2776
|
+
}
|
|
2777
|
+
const bodyNodes = fnNode.body.type === "BlockStatement" ? fnNode.body.body : [fnNode.body];
|
|
2778
|
+
for (const stmt of bodyNodes) {
|
|
2779
|
+
if (stmt.type === "VariableDeclaration") {
|
|
2780
|
+
for (const decl of stmt.declarations) {
|
|
2781
|
+
if (decl.id.type === "Identifier") {
|
|
2782
|
+
if (!localMap.has(decl.id.name)) {
|
|
2783
|
+
localMap.set(decl.id.name, localCount++);
|
|
2784
|
+
}
|
|
2785
|
+
} else {
|
|
2786
|
+
return null;
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
function addConst(val) {
|
|
2792
|
+
for (let i = 0; i < consts.length; i++) {
|
|
2793
|
+
if (consts[i] === val) return i;
|
|
2794
|
+
}
|
|
2795
|
+
const idx = consts.length;
|
|
2796
|
+
consts.push(val);
|
|
2797
|
+
return idx;
|
|
2798
|
+
}
|
|
2799
|
+
function emit(op, ...args) {
|
|
2800
|
+
bytecode.push(opMap[op]);
|
|
2801
|
+
for (const a of args) bytecode.push(a);
|
|
2802
|
+
}
|
|
2803
|
+
function compileExpr(node) {
|
|
2804
|
+
if (!node) return false;
|
|
2805
|
+
switch (node.type) {
|
|
2806
|
+
case "Literal": {
|
|
2807
|
+
const idx = addConst(node.value);
|
|
2808
|
+
emit(OP_LDC, idx);
|
|
2809
|
+
return true;
|
|
2810
|
+
}
|
|
2811
|
+
case "Identifier": {
|
|
2812
|
+
if (node.name === "undefined") {
|
|
2813
|
+
const idx = addConst(void 0);
|
|
2814
|
+
emit(OP_LDC, idx);
|
|
2815
|
+
} else if (localMap.has(node.name)) {
|
|
2816
|
+
emit(OP_LDV, localMap.get(node.name));
|
|
2817
|
+
} else {
|
|
2818
|
+
const idx = addConst(node.name);
|
|
2819
|
+
emit(OP_LDG, idx);
|
|
2820
|
+
}
|
|
2821
|
+
return true;
|
|
2822
|
+
}
|
|
2823
|
+
case "BinaryExpression": {
|
|
2824
|
+
if (node.operator === ">") {
|
|
2825
|
+
if (!compileExpr(node.right)) return false;
|
|
2826
|
+
if (!compileExpr(node.left)) return false;
|
|
2827
|
+
emit(OP_LT);
|
|
2828
|
+
return true;
|
|
2829
|
+
}
|
|
2830
|
+
if (node.operator === "<=") {
|
|
2831
|
+
if (!compileExpr(node.right)) return false;
|
|
2832
|
+
if (!compileExpr(node.left)) return false;
|
|
2833
|
+
emit(OP_LT);
|
|
2834
|
+
emit(OP_NOT);
|
|
2835
|
+
return true;
|
|
2836
|
+
}
|
|
2837
|
+
if (node.operator === ">=") {
|
|
2838
|
+
if (!compileExpr(node.left)) return false;
|
|
2839
|
+
if (!compileExpr(node.right)) return false;
|
|
2840
|
+
emit(OP_LT);
|
|
2841
|
+
emit(OP_NOT);
|
|
2842
|
+
return true;
|
|
2843
|
+
}
|
|
2844
|
+
if (!compileExpr(node.left)) return false;
|
|
2845
|
+
if (!compileExpr(node.right)) return false;
|
|
2846
|
+
switch (node.operator) {
|
|
2847
|
+
case "+":
|
|
2848
|
+
emit(OP_ADD);
|
|
2849
|
+
break;
|
|
2850
|
+
case "-":
|
|
2851
|
+
emit(OP_SUB);
|
|
2852
|
+
break;
|
|
2853
|
+
case "*":
|
|
2854
|
+
emit(OP_MUL);
|
|
2855
|
+
break;
|
|
2856
|
+
case "^":
|
|
2857
|
+
emit(OP_XOR);
|
|
2858
|
+
break;
|
|
2859
|
+
case "&":
|
|
2860
|
+
emit(OP_AND);
|
|
2861
|
+
break;
|
|
2862
|
+
case "|":
|
|
2863
|
+
emit(OP_OR);
|
|
2864
|
+
break;
|
|
2865
|
+
case "==":
|
|
2866
|
+
case "===":
|
|
2867
|
+
emit(OP_SEQ);
|
|
2868
|
+
break;
|
|
2869
|
+
case "!=":
|
|
2870
|
+
case "!==":
|
|
2871
|
+
emit(OP_SEQ);
|
|
2872
|
+
emit(OP_NOT);
|
|
2873
|
+
break;
|
|
2874
|
+
case "<":
|
|
2875
|
+
emit(OP_LT);
|
|
2876
|
+
break;
|
|
2877
|
+
default:
|
|
2878
|
+
return false;
|
|
2879
|
+
}
|
|
2880
|
+
return true;
|
|
2881
|
+
}
|
|
2882
|
+
case "UnaryExpression": {
|
|
2883
|
+
if (!compileExpr(node.argument)) return false;
|
|
2884
|
+
switch (node.operator) {
|
|
2885
|
+
case "!":
|
|
2886
|
+
emit(OP_NOT);
|
|
2887
|
+
break;
|
|
2888
|
+
case "-": {
|
|
2889
|
+
const neg1Idx = addConst(-1);
|
|
2890
|
+
emit(OP_LDC, neg1Idx);
|
|
2891
|
+
emit(OP_MUL);
|
|
2892
|
+
break;
|
|
2893
|
+
}
|
|
2894
|
+
case "+": {
|
|
2895
|
+
const zeroIdx = addConst(0);
|
|
2896
|
+
emit(OP_LDC, zeroIdx);
|
|
2897
|
+
emit(OP_ADD);
|
|
2898
|
+
break;
|
|
2899
|
+
}
|
|
2900
|
+
case "~": {
|
|
2901
|
+
const neg1Idx = addConst(-1);
|
|
2902
|
+
emit(OP_LDC, neg1Idx);
|
|
2903
|
+
emit(OP_XOR);
|
|
2904
|
+
break;
|
|
2905
|
+
}
|
|
2906
|
+
case "void": {
|
|
2907
|
+
const undefIdx2 = addConst(void 0);
|
|
2908
|
+
emit(OP_LDC, undefIdx2);
|
|
2909
|
+
break;
|
|
2910
|
+
}
|
|
2911
|
+
default:
|
|
2912
|
+
return false;
|
|
2913
|
+
}
|
|
2914
|
+
return true;
|
|
2915
|
+
}
|
|
2916
|
+
case "MemberExpression": {
|
|
2917
|
+
if (!compileExpr(node.object)) return false;
|
|
2918
|
+
if (node.computed) {
|
|
2919
|
+
if (!compileExpr(node.property)) return false;
|
|
2920
|
+
} else {
|
|
2921
|
+
const idx = addConst(node.property.name);
|
|
2922
|
+
emit(OP_LDC, idx);
|
|
2923
|
+
}
|
|
2924
|
+
emit(OP_GETP);
|
|
2925
|
+
return true;
|
|
2926
|
+
}
|
|
2927
|
+
case "CallExpression": {
|
|
2928
|
+
if (node.callee.type === "MemberExpression") {
|
|
2929
|
+
if (!compileExpr(node.callee.object)) return false;
|
|
2930
|
+
if (node.callee.computed) {
|
|
2931
|
+
if (!compileExpr(node.callee.property)) return false;
|
|
2932
|
+
} else {
|
|
2933
|
+
const idx = addConst(node.callee.property.name);
|
|
2934
|
+
emit(OP_LDC, idx);
|
|
2935
|
+
}
|
|
2936
|
+
for (const arg of node.arguments) {
|
|
2937
|
+
if (!compileExpr(arg)) return false;
|
|
2938
|
+
}
|
|
2939
|
+
emit(OP_MCALL, node.arguments.length);
|
|
2940
|
+
} else {
|
|
2941
|
+
if (!compileExpr(node.callee)) return false;
|
|
2942
|
+
for (const arg of node.arguments) {
|
|
2943
|
+
if (!compileExpr(arg)) return false;
|
|
2944
|
+
}
|
|
2945
|
+
emit(OP_CALL, node.arguments.length);
|
|
2946
|
+
}
|
|
2947
|
+
return true;
|
|
2948
|
+
}
|
|
2949
|
+
case "AssignmentExpression": {
|
|
2950
|
+
if (node.operator !== "=") return false;
|
|
2951
|
+
if (node.left.type === "Identifier") {
|
|
2952
|
+
if (!localMap.has(node.left.name)) return false;
|
|
2953
|
+
if (!compileExpr(node.right)) return false;
|
|
2954
|
+
emit(OP_STV, localMap.get(node.left.name));
|
|
2955
|
+
return true;
|
|
2956
|
+
}
|
|
2957
|
+
if (node.left.type === "MemberExpression") {
|
|
2958
|
+
if (!compileExpr(node.left.object)) return false;
|
|
2959
|
+
if (node.left.computed) {
|
|
2960
|
+
if (!compileExpr(node.left.property)) return false;
|
|
2961
|
+
} else {
|
|
2962
|
+
const idx = addConst(node.left.property.name);
|
|
2963
|
+
emit(OP_LDC, idx);
|
|
2964
|
+
}
|
|
2965
|
+
if (!compileExpr(node.right)) return false;
|
|
2966
|
+
emit(OP_SETP);
|
|
2967
|
+
return true;
|
|
2968
|
+
}
|
|
2969
|
+
return false;
|
|
2970
|
+
}
|
|
2971
|
+
case "ObjectExpression": {
|
|
2972
|
+
for (const prop of node.properties) {
|
|
2973
|
+
if (prop.type !== "Property") return false;
|
|
2974
|
+
if (prop.computed) {
|
|
2975
|
+
if (!compileExpr(prop.key)) return false;
|
|
2976
|
+
} else {
|
|
2977
|
+
const keyName = prop.key.name ?? prop.key.value;
|
|
2978
|
+
const idx = addConst(keyName);
|
|
2979
|
+
emit(OP_LDC, idx);
|
|
2980
|
+
}
|
|
2981
|
+
if (!compileExpr(prop.value)) return false;
|
|
2982
|
+
}
|
|
2983
|
+
emit(OP_OBJ, node.properties.length);
|
|
2984
|
+
return true;
|
|
2985
|
+
}
|
|
2986
|
+
case "ArrayExpression": {
|
|
2987
|
+
for (const elem of node.elements) {
|
|
2988
|
+
if (!compileExpr(elem)) return false;
|
|
2989
|
+
}
|
|
2990
|
+
emit(OP_ARR, node.elements.length);
|
|
2991
|
+
return true;
|
|
2992
|
+
}
|
|
2993
|
+
case "AwaitExpression": {
|
|
2994
|
+
if (!compileExpr(node.argument)) return false;
|
|
2995
|
+
emit(OP_AWAIT);
|
|
2996
|
+
return true;
|
|
2997
|
+
}
|
|
2998
|
+
default:
|
|
2999
|
+
return false;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
function compileStmt(stmt) {
|
|
3003
|
+
if (!stmt) return false;
|
|
3004
|
+
switch (stmt.type) {
|
|
3005
|
+
case "ReturnStatement": {
|
|
3006
|
+
if (stmt.argument) {
|
|
3007
|
+
if (!compileExpr(stmt.argument)) return false;
|
|
3008
|
+
} else {
|
|
3009
|
+
const idx = addConst(void 0);
|
|
3010
|
+
emit(OP_LDC, idx);
|
|
3011
|
+
}
|
|
3012
|
+
emit(OP_RET);
|
|
3013
|
+
return true;
|
|
3014
|
+
}
|
|
3015
|
+
case "ExpressionStatement": {
|
|
3016
|
+
if (!compileExpr(stmt.expression)) return false;
|
|
3017
|
+
return true;
|
|
3018
|
+
}
|
|
3019
|
+
case "VariableDeclaration": {
|
|
3020
|
+
for (const decl of stmt.declarations) {
|
|
3021
|
+
if (decl.init) {
|
|
3022
|
+
if (!compileExpr(decl.init)) return false;
|
|
3023
|
+
emit(OP_STV, localMap.get(decl.id.name));
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
return true;
|
|
3027
|
+
}
|
|
3028
|
+
case "IfStatement": {
|
|
3029
|
+
if (!compileExpr(stmt.test)) return false;
|
|
3030
|
+
const jzPos = bytecode.length;
|
|
3031
|
+
emit(OP_JZ, 0);
|
|
3032
|
+
if (!compileStmt(stmt.consequent)) return false;
|
|
3033
|
+
if (stmt.alternate) {
|
|
3034
|
+
const jmpPos = bytecode.length;
|
|
3035
|
+
emit(OP_JMP, 0);
|
|
3036
|
+
bytecode[jzPos + 1] = bytecode.length;
|
|
3037
|
+
if (!compileStmt(stmt.alternate)) return false;
|
|
3038
|
+
bytecode[jmpPos + 1] = bytecode.length;
|
|
3039
|
+
} else {
|
|
3040
|
+
bytecode[jzPos + 1] = bytecode.length;
|
|
3041
|
+
}
|
|
3042
|
+
return true;
|
|
3043
|
+
}
|
|
3044
|
+
case "BlockStatement": {
|
|
3045
|
+
for (const s of stmt.body) {
|
|
3046
|
+
if (!compileStmt(s)) return false;
|
|
3047
|
+
}
|
|
3048
|
+
return true;
|
|
3049
|
+
}
|
|
3050
|
+
default:
|
|
3051
|
+
return false;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
if (fnNode.body.type === "BlockStatement") {
|
|
3055
|
+
if (!compileStmt(fnNode.body)) return null;
|
|
3056
|
+
} else {
|
|
3057
|
+
if (!compileExpr(fnNode.body)) return null;
|
|
3058
|
+
emit(OP_RET);
|
|
3059
|
+
}
|
|
3060
|
+
const undefIdx = addConst(void 0);
|
|
3061
|
+
emit(OP_LDC, undefIdx);
|
|
3062
|
+
emit(OP_RET);
|
|
3063
|
+
return { bytecode, consts, localCount };
|
|
3064
|
+
}
|
|
3065
|
+
function isMicroVmAlreadyInjected(ast) {
|
|
3066
|
+
if (!ast || !Array.isArray(ast.body)) return false;
|
|
3067
|
+
return ast.body.some((stmt) => {
|
|
3068
|
+
if (stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")) {
|
|
3069
|
+
return true;
|
|
3070
|
+
}
|
|
3071
|
+
return false;
|
|
3072
|
+
});
|
|
3073
|
+
}
|
|
3074
|
+
function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 2654435769) {
|
|
3075
|
+
const suffix = computeFnv1aHash(`micro-vm:${seed}`, seed).toString(36);
|
|
3076
|
+
const vmHelperName = `_uVm${suffix}`;
|
|
3077
|
+
if (isMicroVmAlreadyInjected(ast)) {
|
|
3078
|
+
const existing = ast.body.find(
|
|
3079
|
+
(stmt) => stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")
|
|
3080
|
+
);
|
|
3081
|
+
return {
|
|
3082
|
+
virtualizedCount: 0,
|
|
3083
|
+
vmHelperName: existing?.id?.name ?? vmHelperName
|
|
3084
|
+
};
|
|
3085
|
+
}
|
|
3086
|
+
const opMap = generateOpcodeMap(seed);
|
|
3087
|
+
const candidates = [];
|
|
3088
|
+
walk5.simple(ast, {
|
|
3089
|
+
FunctionDeclaration(node) {
|
|
3090
|
+
candidates.push(node);
|
|
3091
|
+
},
|
|
3092
|
+
FunctionExpression(node) {
|
|
3093
|
+
candidates.push(node);
|
|
3094
|
+
},
|
|
3095
|
+
ArrowFunctionExpression(node) {
|
|
3096
|
+
candidates.push(node);
|
|
3097
|
+
}
|
|
3098
|
+
});
|
|
3099
|
+
let virtualizedCount = 0;
|
|
3100
|
+
for (const fn of candidates) {
|
|
3101
|
+
if (virtualizedCount >= 10) break;
|
|
3102
|
+
if (coldFunctionNodes && !coldFunctionNodes.has(fn)) {
|
|
3103
|
+
continue;
|
|
3104
|
+
}
|
|
3105
|
+
if (serializedFunctionNodes && serializedFunctionNodes.has(fn)) {
|
|
3106
|
+
continue;
|
|
3107
|
+
}
|
|
3108
|
+
if (fn.generator) {
|
|
3109
|
+
continue;
|
|
3110
|
+
}
|
|
3111
|
+
if (hasForbiddenConstructs(fn)) {
|
|
3112
|
+
continue;
|
|
3113
|
+
}
|
|
3114
|
+
const nodeCount = countAstNodes(fn);
|
|
3115
|
+
if (nodeCount < 15 || nodeCount > 80) {
|
|
3116
|
+
continue;
|
|
3117
|
+
}
|
|
3118
|
+
const compiled = compileFunctionToBytecode(fn, opMap);
|
|
3119
|
+
if (!compiled) {
|
|
3120
|
+
continue;
|
|
3121
|
+
}
|
|
3122
|
+
const paramArgs = fn.params.map((p) => ({
|
|
3123
|
+
type: "Identifier",
|
|
3124
|
+
name: p.name
|
|
3125
|
+
}));
|
|
3126
|
+
const callExpr = {
|
|
3127
|
+
type: "CallExpression",
|
|
3128
|
+
callee: {
|
|
3129
|
+
type: "Identifier",
|
|
3130
|
+
name: vmHelperName
|
|
3131
|
+
},
|
|
3132
|
+
arguments: [
|
|
3133
|
+
{
|
|
3134
|
+
type: "ArrayExpression",
|
|
3135
|
+
elements: compiled.bytecode.map((b) => ({
|
|
3136
|
+
type: "Literal",
|
|
3137
|
+
value: b,
|
|
3138
|
+
raw: String(b)
|
|
3139
|
+
}))
|
|
3140
|
+
},
|
|
3141
|
+
{
|
|
3142
|
+
type: "ArrayExpression",
|
|
3143
|
+
elements: compiled.consts.map((c) => ({
|
|
3144
|
+
type: "Literal",
|
|
3145
|
+
value: c,
|
|
3146
|
+
raw: c === void 0 ? "void 0" : JSON.stringify(c)
|
|
3147
|
+
}))
|
|
3148
|
+
},
|
|
3149
|
+
{
|
|
3150
|
+
type: "ArrayExpression",
|
|
3151
|
+
elements: paramArgs
|
|
3152
|
+
},
|
|
3153
|
+
{
|
|
3154
|
+
type: "ThisExpression"
|
|
3155
|
+
}
|
|
3156
|
+
],
|
|
3157
|
+
optional: false
|
|
3158
|
+
};
|
|
3159
|
+
if (fn.body.type === "BlockStatement") {
|
|
3160
|
+
fn.body.body = [
|
|
3161
|
+
{
|
|
3162
|
+
type: "ReturnStatement",
|
|
3163
|
+
argument: callExpr
|
|
3164
|
+
}
|
|
3165
|
+
];
|
|
3166
|
+
} else {
|
|
3167
|
+
fn.body = callExpr;
|
|
3168
|
+
}
|
|
3169
|
+
virtualizedCount++;
|
|
3170
|
+
}
|
|
3171
|
+
if (virtualizedCount > 0) {
|
|
3172
|
+
const interpreterSource = createInterpreterSource(vmHelperName, opMap);
|
|
3173
|
+
const parsedHelper = acorn3.parse(interpreterSource, {
|
|
3174
|
+
ecmaVersion: "latest",
|
|
3175
|
+
sourceType: "script"
|
|
3176
|
+
});
|
|
3177
|
+
ast.body.unshift(...parsedHelper.body);
|
|
3178
|
+
}
|
|
3179
|
+
return {
|
|
3180
|
+
virtualizedCount,
|
|
3181
|
+
vmHelperName
|
|
3182
|
+
};
|
|
1691
3183
|
}
|
|
1692
3184
|
|
|
1693
|
-
// src/
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
const
|
|
1697
|
-
|
|
3185
|
+
// src/ast/wasm-vault.ts
|
|
3186
|
+
var acorn4 = __toESM(require("acorn"), 1);
|
|
3187
|
+
function encodeSignedLeb128(value) {
|
|
3188
|
+
const bytes = [];
|
|
3189
|
+
let val = value | 0;
|
|
3190
|
+
let more = true;
|
|
3191
|
+
while (more) {
|
|
3192
|
+
let byte = val & 127;
|
|
3193
|
+
val >>= 7;
|
|
3194
|
+
if (val === 0 && (byte & 64) === 0 || val === -1 && (byte & 64) !== 0) {
|
|
3195
|
+
more = false;
|
|
3196
|
+
} else {
|
|
3197
|
+
byte |= 128;
|
|
3198
|
+
}
|
|
3199
|
+
bytes.push(byte);
|
|
3200
|
+
}
|
|
3201
|
+
return bytes;
|
|
3202
|
+
}
|
|
3203
|
+
function encodeUnsignedLeb128(value) {
|
|
3204
|
+
const bytes = [];
|
|
3205
|
+
let val = value >>> 0;
|
|
3206
|
+
do {
|
|
3207
|
+
let byte = val & 127;
|
|
3208
|
+
val >>>= 7;
|
|
3209
|
+
if (val !== 0) {
|
|
3210
|
+
byte |= 128;
|
|
3211
|
+
}
|
|
3212
|
+
bytes.push(byte);
|
|
3213
|
+
} while (val !== 0);
|
|
3214
|
+
return bytes;
|
|
3215
|
+
}
|
|
3216
|
+
function generateWasmKdfBinary(seed) {
|
|
3217
|
+
const instructions = [
|
|
3218
|
+
32,
|
|
3219
|
+
0,
|
|
3220
|
+
// local.get 0
|
|
3221
|
+
65,
|
|
3222
|
+
...encodeSignedLeb128(seed),
|
|
3223
|
+
// i32.const seed
|
|
3224
|
+
115,
|
|
3225
|
+
// i32.xor
|
|
3226
|
+
65,
|
|
3227
|
+
...encodeSignedLeb128(16777619),
|
|
3228
|
+
// i32.const 0x01000193
|
|
3229
|
+
108,
|
|
3230
|
+
// i32.mul
|
|
3231
|
+
32,
|
|
3232
|
+
1,
|
|
3233
|
+
// local.get 1
|
|
3234
|
+
32,
|
|
3235
|
+
2,
|
|
3236
|
+
// local.get 2
|
|
3237
|
+
106,
|
|
3238
|
+
// i32.add
|
|
3239
|
+
65,
|
|
3240
|
+
...encodeSignedLeb128(73244475),
|
|
3241
|
+
// i32.const 0x45d9f3b
|
|
3242
|
+
108,
|
|
3243
|
+
// i32.mul
|
|
3244
|
+
115,
|
|
3245
|
+
// i32.xor
|
|
3246
|
+
11
|
|
3247
|
+
// end
|
|
3248
|
+
];
|
|
3249
|
+
const funcBody = [0, ...instructions];
|
|
3250
|
+
const funcBodyWithLen = [...encodeUnsignedLeb128(funcBody.length), ...funcBody];
|
|
3251
|
+
const codeSectionPayload = [1, ...funcBodyWithLen];
|
|
3252
|
+
const codeSection = [
|
|
3253
|
+
10,
|
|
3254
|
+
...encodeUnsignedLeb128(codeSectionPayload.length),
|
|
3255
|
+
...codeSectionPayload
|
|
3256
|
+
];
|
|
3257
|
+
const typePayload = [
|
|
3258
|
+
1,
|
|
3259
|
+
// 1 type
|
|
3260
|
+
96,
|
|
3261
|
+
// func
|
|
3262
|
+
3,
|
|
3263
|
+
127,
|
|
3264
|
+
127,
|
|
3265
|
+
127,
|
|
3266
|
+
// 3 params of type i32
|
|
3267
|
+
1,
|
|
3268
|
+
127
|
|
3269
|
+
// 1 result of type i32
|
|
3270
|
+
];
|
|
3271
|
+
const typeSection = [
|
|
3272
|
+
1,
|
|
3273
|
+
...encodeUnsignedLeb128(typePayload.length),
|
|
3274
|
+
...typePayload
|
|
3275
|
+
];
|
|
3276
|
+
const funcPayload = [
|
|
3277
|
+
1,
|
|
3278
|
+
// 1 function
|
|
3279
|
+
0
|
|
3280
|
+
// type index 0
|
|
3281
|
+
];
|
|
3282
|
+
const funcSection = [
|
|
3283
|
+
3,
|
|
3284
|
+
...encodeUnsignedLeb128(funcPayload.length),
|
|
3285
|
+
...funcPayload
|
|
3286
|
+
];
|
|
3287
|
+
const exportName = [3, 107, 100, 102];
|
|
3288
|
+
const exportPayload = [
|
|
3289
|
+
1,
|
|
3290
|
+
// 1 export
|
|
3291
|
+
...exportName,
|
|
3292
|
+
0,
|
|
3293
|
+
// function export
|
|
3294
|
+
0
|
|
3295
|
+
// function index 0
|
|
3296
|
+
];
|
|
3297
|
+
const exportSection = [
|
|
3298
|
+
7,
|
|
3299
|
+
...encodeUnsignedLeb128(exportPayload.length),
|
|
3300
|
+
...exportPayload
|
|
3301
|
+
];
|
|
3302
|
+
const header = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
3303
|
+
return new Uint8Array([
|
|
3304
|
+
...header,
|
|
3305
|
+
...typeSection,
|
|
3306
|
+
...funcSection,
|
|
3307
|
+
...exportSection,
|
|
3308
|
+
...codeSection
|
|
3309
|
+
]);
|
|
3310
|
+
}
|
|
3311
|
+
function fallbackKdf(fnId, callSiteSalt, shieldHash, seed) {
|
|
3312
|
+
return Math.imul(fnId ^ seed | 0, 16777619) ^ Math.imul(callSiteSalt + shieldHash | 0, 73244475) | 0;
|
|
3313
|
+
}
|
|
3314
|
+
function isWasmVaultAlreadyInjected(ast) {
|
|
3315
|
+
if (!ast || !Array.isArray(ast.body)) return false;
|
|
3316
|
+
return ast.body.some((stmt) => {
|
|
3317
|
+
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
3318
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
3319
|
+
)) {
|
|
3320
|
+
return true;
|
|
3321
|
+
}
|
|
3322
|
+
return false;
|
|
3323
|
+
});
|
|
3324
|
+
}
|
|
3325
|
+
function injectWasmVault(ast, seed = 2654435769) {
|
|
3326
|
+
const suffix = computeFnv1aHash(`wasm:${seed}`, seed).toString(36);
|
|
3327
|
+
const kdfFnName = `_wKdf${suffix}`;
|
|
3328
|
+
const wasmVarName = `_wb${suffix}`;
|
|
3329
|
+
if (isWasmVaultAlreadyInjected(ast)) {
|
|
3330
|
+
const existing = ast.body.find(
|
|
3331
|
+
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
3332
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
3333
|
+
)
|
|
3334
|
+
);
|
|
3335
|
+
const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
|
|
3336
|
+
return {
|
|
3337
|
+
kdfFnName: id,
|
|
3338
|
+
wasmBytes: generateWasmKdfBinary(seed),
|
|
3339
|
+
wasmVarName
|
|
3340
|
+
};
|
|
3341
|
+
}
|
|
3342
|
+
const wasmBytes = generateWasmKdfBinary(seed);
|
|
3343
|
+
const byteArrayLiteral = Array.from(wasmBytes).join(",");
|
|
3344
|
+
const helperSnippet = `var ${kdfFnName};
|
|
3345
|
+
try {
|
|
3346
|
+
var ${wasmVarName} = new Uint8Array([${byteArrayLiteral}]);
|
|
3347
|
+
var _wm${suffix} = new WebAssembly.Module(${wasmVarName});
|
|
3348
|
+
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix});
|
|
3349
|
+
${kdfFnName} = _wi${suffix}.exports.kdf;
|
|
3350
|
+
} catch (e) {
|
|
3351
|
+
${kdfFnName} = function(f, s, h) {
|
|
3352
|
+
return (Math.imul((f ^ ${seed | 0}) | 0, 16777619) ^ Math.imul(((s + h) | 0), 73244475)) | 0;
|
|
3353
|
+
};
|
|
3354
|
+
}`;
|
|
3355
|
+
const parsedHelper = acorn4.parse(helperSnippet, {
|
|
3356
|
+
ecmaVersion: "latest",
|
|
3357
|
+
sourceType: "script"
|
|
3358
|
+
});
|
|
3359
|
+
ast.body.unshift(...parsedHelper.body);
|
|
1698
3360
|
return {
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
3361
|
+
kdfFnName,
|
|
3362
|
+
wasmBytes,
|
|
3363
|
+
wasmVarName
|
|
1702
3364
|
};
|
|
1703
3365
|
}
|
|
1704
3366
|
|
|
1705
|
-
// src/ast/
|
|
1706
|
-
|
|
3367
|
+
// src/ast/salted-vault.ts
|
|
3368
|
+
var acorn5 = __toESM(require("acorn"), 1);
|
|
3369
|
+
var walk6 = __toESM(require("acorn-walk"), 1);
|
|
3370
|
+
var DIRECTIVE_STRINGS2 = /* @__PURE__ */ new Set([
|
|
3371
|
+
"use strict",
|
|
3372
|
+
"use client",
|
|
3373
|
+
"use server",
|
|
3374
|
+
"use asm"
|
|
3375
|
+
]);
|
|
3376
|
+
function encodeSaltedString(str, k) {
|
|
3377
|
+
let out = "";
|
|
3378
|
+
for (let j = 0; j < str.length; j++) {
|
|
3379
|
+
const code = str.charCodeAt(j);
|
|
3380
|
+
const mask = k >>> j % 24 & 127 | 1;
|
|
3381
|
+
out += String.fromCharCode(code ^ mask);
|
|
3382
|
+
}
|
|
3383
|
+
return out;
|
|
3384
|
+
}
|
|
3385
|
+
function isAstAlreadySalted(ast) {
|
|
1707
3386
|
if (!ast || !Array.isArray(ast.body)) return false;
|
|
1708
3387
|
return ast.body.some((stmt) => {
|
|
1709
3388
|
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1710
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("
|
|
3389
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uP")
|
|
1711
3390
|
)) {
|
|
1712
3391
|
return true;
|
|
1713
3392
|
}
|
|
1714
|
-
|
|
3393
|
+
return false;
|
|
3394
|
+
});
|
|
3395
|
+
}
|
|
3396
|
+
function replaceNodeInParent(parent, oldNode, newNode) {
|
|
3397
|
+
if (!parent) return false;
|
|
3398
|
+
for (const key of Object.keys(parent)) {
|
|
3399
|
+
const val = parent[key];
|
|
3400
|
+
if (val === oldNode) {
|
|
3401
|
+
parent[key] = newNode;
|
|
1715
3402
|
return true;
|
|
1716
3403
|
}
|
|
3404
|
+
if (Array.isArray(val)) {
|
|
3405
|
+
const idx = val.indexOf(oldNode);
|
|
3406
|
+
if (idx !== -1) {
|
|
3407
|
+
val[idx] = newNode;
|
|
3408
|
+
return true;
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
return false;
|
|
3413
|
+
}
|
|
3414
|
+
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes) {
|
|
3415
|
+
if (isAstAlreadySalted(ast)) {
|
|
3416
|
+
return {
|
|
3417
|
+
encryptedStringsCount: 0,
|
|
3418
|
+
integrityToken: computeFnv1aHash("already-salted", seed),
|
|
3419
|
+
vaultVarName: "",
|
|
3420
|
+
decryptFnName: ""
|
|
3421
|
+
};
|
|
3422
|
+
}
|
|
3423
|
+
const targetsToReplace = [];
|
|
3424
|
+
const encryptedPayloads = [];
|
|
3425
|
+
walk6.ancestor(ast, {
|
|
3426
|
+
Literal(node, ancestors) {
|
|
3427
|
+
if (typeof node.value !== "string") return;
|
|
3428
|
+
if (node.value.length < minStringLength) return;
|
|
3429
|
+
if (DIRECTIVE_STRINGS2.has(node.value)) return;
|
|
3430
|
+
const parent = ancestors[ancestors.length - 2];
|
|
3431
|
+
if (!parent) return;
|
|
3432
|
+
if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration") && parent.source === node) {
|
|
3433
|
+
return;
|
|
3434
|
+
}
|
|
3435
|
+
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
3436
|
+
return;
|
|
3437
|
+
}
|
|
3438
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
3439
|
+
return;
|
|
3440
|
+
}
|
|
3441
|
+
if (hotExemptNodes) {
|
|
3442
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
3443
|
+
if (hotExemptNodes.has(ancestors[i])) {
|
|
3444
|
+
return;
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
const callSiteIdx = targetsToReplace.length;
|
|
3449
|
+
const localSalt = computeFnv1aHash(`salt:${seed}:${callSiteIdx}`, seed) & 2147483647 | 1;
|
|
3450
|
+
targetsToReplace.push({
|
|
3451
|
+
node,
|
|
3452
|
+
parent,
|
|
3453
|
+
callSiteIdx,
|
|
3454
|
+
localSalt,
|
|
3455
|
+
rawString: node.value
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
});
|
|
3459
|
+
if (targetsToReplace.length === 0) {
|
|
3460
|
+
return {
|
|
3461
|
+
encryptedStringsCount: 0,
|
|
3462
|
+
integrityToken: computeFnv1aHash("empty-salted", seed),
|
|
3463
|
+
vaultVarName: "",
|
|
3464
|
+
decryptFnName: ""
|
|
3465
|
+
};
|
|
3466
|
+
}
|
|
3467
|
+
const wasmResult = injectWasmVault(ast, seed);
|
|
3468
|
+
const kdfFnName = wasmResult.kdfFnName;
|
|
3469
|
+
const suffix = computeFnv1aHash(`salted:${seed}`, seed).toString(36);
|
|
3470
|
+
const vaultVarName = `_uP${suffix}`;
|
|
3471
|
+
const cacheVarName = `_uCache${suffix}`;
|
|
3472
|
+
const decryptFnName = `_uD${suffix}`;
|
|
3473
|
+
for (const target of targetsToReplace) {
|
|
3474
|
+
const k = fallbackKdf(target.callSiteIdx, target.localSalt, 0, seed);
|
|
3475
|
+
encryptedPayloads.push(encodeSaltedString(target.rawString, k));
|
|
3476
|
+
const callExpr = {
|
|
3477
|
+
type: "CallExpression",
|
|
3478
|
+
callee: {
|
|
3479
|
+
type: "Identifier",
|
|
3480
|
+
name: decryptFnName
|
|
3481
|
+
},
|
|
3482
|
+
arguments: [
|
|
3483
|
+
{
|
|
3484
|
+
type: "Literal",
|
|
3485
|
+
value: target.callSiteIdx,
|
|
3486
|
+
raw: String(target.callSiteIdx)
|
|
3487
|
+
},
|
|
3488
|
+
{
|
|
3489
|
+
type: "Literal",
|
|
3490
|
+
value: target.localSalt,
|
|
3491
|
+
raw: String(target.localSalt)
|
|
3492
|
+
}
|
|
3493
|
+
],
|
|
3494
|
+
optional: false
|
|
3495
|
+
};
|
|
3496
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
3497
|
+
}
|
|
3498
|
+
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
3499
|
+
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
3500
|
+
const helperSnippet = `var ${vaultVarName} = ${serializedTable};
|
|
3501
|
+
var ${cacheVarName} = [];
|
|
3502
|
+
function ${decryptFnName}(i, s) {
|
|
3503
|
+
if (${cacheVarName}[i] !== void 0) return ${cacheVarName}[i];
|
|
3504
|
+
var d = typeof window !== 'undefined' && window.__unpeek_delta != null ? window.__unpeek_delta : 0;
|
|
3505
|
+
var k = ${kdfFnName}(i, s, d);
|
|
3506
|
+
var p = ${vaultVarName}[i], o = '';
|
|
3507
|
+
for (var j = 0; j < p.length; j++) {
|
|
3508
|
+
o += String.fromCharCode(p.charCodeAt(j) ^ (((k >>> (j % 24)) & 127) | 1));
|
|
3509
|
+
}
|
|
3510
|
+
return (${cacheVarName}[i] = o);
|
|
3511
|
+
}`;
|
|
3512
|
+
const parsedHelper = acorn5.parse(helperSnippet, {
|
|
3513
|
+
ecmaVersion: "latest",
|
|
3514
|
+
sourceType: "script"
|
|
3515
|
+
});
|
|
3516
|
+
ast.body.unshift(...parsedHelper.body);
|
|
3517
|
+
return {
|
|
3518
|
+
encryptedStringsCount: targetsToReplace.length,
|
|
3519
|
+
integrityToken,
|
|
3520
|
+
vaultVarName,
|
|
3521
|
+
decryptFnName
|
|
3522
|
+
};
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
// src/ast/index.ts
|
|
3526
|
+
function isAstAlreadyProtected(ast) {
|
|
3527
|
+
if (!ast || !Array.isArray(ast.body)) return false;
|
|
3528
|
+
return ast.body.some((stmt) => {
|
|
3529
|
+
if (stmt.type === "VariableDeclaration" && Array.isArray(stmt.declarations)) {
|
|
3530
|
+
for (const d of stmt.declarations) {
|
|
3531
|
+
const name = d.id?.name;
|
|
3532
|
+
if (typeof name === "string") {
|
|
3533
|
+
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") {
|
|
3534
|
+
return true;
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
if (stmt.type === "ExpressionStatement" && stmt.expression?.type === "CallExpression") {
|
|
3540
|
+
const callee = stmt.expression.callee;
|
|
3541
|
+
if (callee?.type === "FunctionExpression") {
|
|
3542
|
+
const name = callee.id?.name;
|
|
3543
|
+
if (typeof name === "string" && (name.startsWith("_u$") || name.startsWith("_$") || name.startsWith("_s") || name.startsWith("$b"))) {
|
|
3544
|
+
return true;
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
1717
3548
|
return false;
|
|
1718
3549
|
});
|
|
1719
3550
|
}
|
|
1720
3551
|
function transformJavaScript(code, options = {}) {
|
|
1721
3552
|
const seed = options.seed ?? 2654435769;
|
|
1722
3553
|
const minStringLength = options.minStringLength ?? 4;
|
|
3554
|
+
const isAggressive = options.aggressive ?? false;
|
|
1723
3555
|
if (!code || !code.trim()) {
|
|
1724
3556
|
return {
|
|
1725
3557
|
code,
|
|
@@ -1730,7 +3562,9 @@ function transformJavaScript(code, options = {}) {
|
|
|
1730
3562
|
hotFunctionsSkipped: [],
|
|
1731
3563
|
coldFunctionsProtected: []
|
|
1732
3564
|
},
|
|
1733
|
-
integrityToken: computeFnv1aHash("", seed)
|
|
3565
|
+
integrityToken: computeFnv1aHash("", seed),
|
|
3566
|
+
virtualizedFunctionsCount: 0,
|
|
3567
|
+
shaderBuffersCount: 0
|
|
1734
3568
|
};
|
|
1735
3569
|
}
|
|
1736
3570
|
const ast = parseJavaScriptAst(code);
|
|
@@ -1744,23 +3578,59 @@ function transformJavaScript(code, options = {}) {
|
|
|
1744
3578
|
hotFunctionsSkipped: [],
|
|
1745
3579
|
coldFunctionsProtected: []
|
|
1746
3580
|
},
|
|
1747
|
-
integrityToken: computeFnv1aHash(code, seed)
|
|
3581
|
+
integrityToken: computeFnv1aHash(code, seed),
|
|
3582
|
+
virtualizedFunctionsCount: 0,
|
|
3583
|
+
shaderBuffersCount: 0
|
|
1748
3584
|
};
|
|
1749
3585
|
}
|
|
1750
3586
|
const {
|
|
1751
3587
|
report: hotPathReport,
|
|
1752
3588
|
coldFunctionNodes,
|
|
1753
|
-
|
|
3589
|
+
hotFunctionNodes,
|
|
3590
|
+
hotExemptNodes,
|
|
3591
|
+
serializedFunctionNodes
|
|
1754
3592
|
} = analyzeAstHotPaths(ast);
|
|
3593
|
+
let virtualizedFunctionsCount = 0;
|
|
3594
|
+
if (isAggressive) {
|
|
3595
|
+
const vmRes = applyMicroVm(
|
|
3596
|
+
ast,
|
|
3597
|
+
coldFunctionNodes,
|
|
3598
|
+
serializedFunctionNodes,
|
|
3599
|
+
seed
|
|
3600
|
+
);
|
|
3601
|
+
virtualizedFunctionsCount = vmRes.virtualizedCount;
|
|
3602
|
+
}
|
|
1755
3603
|
applyColdFlowGuard(ast, coldFunctionNodes, seed, hotExemptNodes);
|
|
1756
|
-
const mangledSymbolsCount = applyPolymorphicMangler(
|
|
1757
|
-
const { encryptedStringsCount, integrityToken } = applyStringVault(
|
|
3604
|
+
const mangledSymbolsCount = applyPolymorphicMangler(
|
|
1758
3605
|
ast,
|
|
1759
3606
|
seed,
|
|
1760
|
-
|
|
1761
|
-
hotExemptNodes
|
|
3607
|
+
serializedFunctionNodes
|
|
1762
3608
|
);
|
|
1763
|
-
|
|
3609
|
+
let encryptedStringsCount = 0;
|
|
3610
|
+
let integrityToken = 0;
|
|
3611
|
+
let shaderBuffersCount = 0;
|
|
3612
|
+
if (isAggressive) {
|
|
3613
|
+
injectWasmVault(ast, seed);
|
|
3614
|
+
const saltedRes = applySaltedStringVault(
|
|
3615
|
+
ast,
|
|
3616
|
+
seed,
|
|
3617
|
+
minStringLength,
|
|
3618
|
+
hotExemptNodes
|
|
3619
|
+
);
|
|
3620
|
+
encryptedStringsCount = saltedRes.encryptedStringsCount;
|
|
3621
|
+
integrityToken = saltedRes.integrityToken;
|
|
3622
|
+
} else {
|
|
3623
|
+
const vaultRes = applyStringVault(
|
|
3624
|
+
ast,
|
|
3625
|
+
seed,
|
|
3626
|
+
minStringLength,
|
|
3627
|
+
hotExemptNodes
|
|
3628
|
+
);
|
|
3629
|
+
encryptedStringsCount = vaultRes.encryptedStringsCount;
|
|
3630
|
+
integrityToken = vaultRes.integrityToken;
|
|
3631
|
+
shaderBuffersCount = vaultRes.shaderBuffersCount ?? 0;
|
|
3632
|
+
}
|
|
3633
|
+
const outputCode = generateCompactJs(ast);
|
|
1764
3634
|
let finalCode = outputCode;
|
|
1765
3635
|
if (options.injectRuntimeShield) {
|
|
1766
3636
|
const shield = generateRuntimeShield({
|
|
@@ -1778,11 +3648,29 @@ ${finalCode}`;
|
|
|
1778
3648
|
encryptedStringsCount,
|
|
1779
3649
|
mangledSymbolsCount,
|
|
1780
3650
|
hotPathReport,
|
|
1781
|
-
integrityToken
|
|
3651
|
+
integrityToken,
|
|
3652
|
+
virtualizedFunctionsCount,
|
|
3653
|
+
shaderBuffersCount
|
|
1782
3654
|
};
|
|
1783
3655
|
}
|
|
1784
3656
|
|
|
1785
3657
|
// src/cli/protect.ts
|
|
3658
|
+
var ENTRY_PATTERN = /^(?:main|index|turbopack|webpack|runtime|app\/layout|app\/page|pages\/_app|pages\/index)[-._/]/i;
|
|
3659
|
+
function isEntryChunk(relPath, index, allRelPaths) {
|
|
3660
|
+
const norm = relPath.replace(/\\/g, "/");
|
|
3661
|
+
const base2 = import_node_path3.default.basename(norm);
|
|
3662
|
+
if (ENTRY_PATTERN.test(norm) || ENTRY_PATTERN.test(base2)) {
|
|
3663
|
+
return true;
|
|
3664
|
+
}
|
|
3665
|
+
const hasAnyPatternMatch = allRelPaths.some((p) => {
|
|
3666
|
+
const n = p.replace(/\\/g, "/");
|
|
3667
|
+
return ENTRY_PATTERN.test(n) || ENTRY_PATTERN.test(import_node_path3.default.basename(n));
|
|
3668
|
+
});
|
|
3669
|
+
if (!hasAnyPatternMatch && index === 0) {
|
|
3670
|
+
return true;
|
|
3671
|
+
}
|
|
3672
|
+
return false;
|
|
3673
|
+
}
|
|
1786
3674
|
async function protectProject(options = {}) {
|
|
1787
3675
|
const startTime = performance.now();
|
|
1788
3676
|
const cwd = import_node_path3.default.resolve(options.cwd ?? process.cwd());
|
|
@@ -1793,8 +3681,10 @@ async function protectProject(options = {}) {
|
|
|
1793
3681
|
const deterrentMode = options.deterrentMode ?? "passive";
|
|
1794
3682
|
const injectRuntimeShield = options.injectRuntimeShield ?? true;
|
|
1795
3683
|
const minStringLength = options.minStringLength ?? 4;
|
|
3684
|
+
const aggressive = options.aggressive ?? false;
|
|
1796
3685
|
const vaultResult = relocateSourceMaps(outDir, cwd, keepPrivateMaps, privateMapsDir, false);
|
|
1797
3686
|
const clientFiles = scanClientBundles(outDir);
|
|
3687
|
+
const allRelPaths = clientFiles.map((f) => import_node_path3.default.relative(outDir, f).replace(/\\/g, "/"));
|
|
1798
3688
|
let originalBytes = 0;
|
|
1799
3689
|
let protectedBytes = 0;
|
|
1800
3690
|
let totalHotFunctionsSkipped = 0;
|
|
@@ -1816,23 +3706,26 @@ async function protectProject(options = {}) {
|
|
|
1816
3706
|
const origBuf = Buffer.from(codeToTransform, "utf8");
|
|
1817
3707
|
originalBytes += origBuf.byteLength;
|
|
1818
3708
|
allOrigBufs.push(origBuf);
|
|
1819
|
-
const relPath =
|
|
3709
|
+
const relPath = allRelPaths[i];
|
|
3710
|
+
const isEntry = isEntryChunk(relPath, i, allRelPaths);
|
|
3711
|
+
const shouldInjectShield = injectRuntimeShield && isEntry;
|
|
1820
3712
|
const fileSeed = computeFnv1aHash(`${relPath}:${i}`, seed);
|
|
1821
3713
|
const result = transformJavaScript(codeToTransform, {
|
|
1822
3714
|
seed: fileSeed,
|
|
1823
3715
|
minStringLength,
|
|
1824
3716
|
filename: import_node_path3.default.basename(filePath),
|
|
1825
|
-
injectRuntimeShield,
|
|
1826
|
-
deterrentMode
|
|
3717
|
+
injectRuntimeShield: shouldInjectShield,
|
|
3718
|
+
deterrentMode,
|
|
3719
|
+
aggressive
|
|
1827
3720
|
});
|
|
1828
3721
|
let finalCode = result.code;
|
|
1829
|
-
if (
|
|
3722
|
+
if (shouldInjectShield && !finalCode.includes("__unpeek_tampered")) {
|
|
1830
3723
|
const shield = generateRuntimeShield({
|
|
1831
3724
|
seed: fileSeed,
|
|
1832
3725
|
deterrentMode,
|
|
1833
3726
|
expectedIntegrityHash: result.integrityToken
|
|
1834
3727
|
});
|
|
1835
|
-
if (shield.preambleCode && !finalCode.includes(
|
|
3728
|
+
if (shield.preambleCode && !finalCode.includes(shield.integrityCheckFnName) && !finalCode.startsWith(shield.preambleCode)) {
|
|
1836
3729
|
finalCode = `${shield.preambleCode}
|
|
1837
3730
|
${finalCode}`;
|
|
1838
3731
|
}
|