unpeek 1.8.2 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast/index.cjs +903 -706
- package/dist/ast/index.cjs.map +1 -1
- package/dist/ast/index.d.cts +2 -2
- package/dist/ast/index.d.ts +2 -2
- package/dist/ast/index.js +903 -706
- package/dist/ast/index.js.map +1 -1
- package/dist/browser.cjs +903 -706
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +903 -706
- package/dist/browser.js.map +1 -1
- package/dist/bundler/sourcemap-vault.cjs +23 -7
- package/dist/bundler/sourcemap-vault.cjs.map +1 -1
- package/dist/bundler/sourcemap-vault.js +23 -7
- package/dist/bundler/sourcemap-vault.js.map +1 -1
- package/dist/bundler/unplugin.cjs +904 -707
- package/dist/bundler/unplugin.cjs.map +1 -1
- package/dist/bundler/unplugin.js +904 -707
- package/dist/bundler/unplugin.js.map +1 -1
- package/dist/cli/index.cjs +940 -712
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +940 -712
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/protect.cjs +926 -710
- package/dist/cli/protect.cjs.map +1 -1
- package/dist/cli/protect.js +926 -710
- package/dist/cli/protect.js.map +1 -1
- package/dist/esbuild.cjs +904 -707
- 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 +904 -707
- package/dist/esbuild.js.map +1 -1
- package/dist/index.cjs +2171 -1943
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2171 -1943
- package/dist/index.js.map +1 -1
- package/dist/rollup.cjs +904 -707
- 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 +904 -707
- package/dist/rollup.js.map +1 -1
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.d.cts +5 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/{types-CQHprSVk.d.cts → types-DBNcJBCS.d.cts} +4 -0
- package/dist/{types-CQHprSVk.d.ts → types-DBNcJBCS.d.ts} +4 -0
- package/dist/vite.cjs +904 -707
- 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 +904 -707
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +904 -707
- 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 +904 -707
- package/dist/webpack.js.map +1 -1
- package/package.json +1 -1
package/dist/ast/index.cjs
CHANGED
|
@@ -62,7 +62,12 @@ var ARRAY_HOF_METHODS = /* @__PURE__ */ new Set([
|
|
|
62
62
|
var ANIMATION_FRAME_CALLS = /* @__PURE__ */ new Set([
|
|
63
63
|
"requestAnimationFrame",
|
|
64
64
|
"cancelAnimationFrame",
|
|
65
|
-
"useFrame"
|
|
65
|
+
"useFrame",
|
|
66
|
+
"useLenis",
|
|
67
|
+
"setAnimationLoop",
|
|
68
|
+
"onBeforeRender",
|
|
69
|
+
"updateMatrixWorld",
|
|
70
|
+
"raf"
|
|
66
71
|
]);
|
|
67
72
|
var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
68
73
|
"useState",
|
|
@@ -71,6 +76,9 @@ var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
|
71
76
|
"useCallback",
|
|
72
77
|
"useRef",
|
|
73
78
|
"useLayoutEffect",
|
|
79
|
+
"useActionState",
|
|
80
|
+
"useFormStatus",
|
|
81
|
+
"useOptimistic",
|
|
74
82
|
"jsx",
|
|
75
83
|
"jsxs",
|
|
76
84
|
"_jsx",
|
|
@@ -199,7 +207,8 @@ function containsLoopOrAnimation(fnNode) {
|
|
|
199
207
|
} else if (callNode.callee?.type === "MemberExpression" && !callNode.callee.computed && callNode.callee.property?.type === "Identifier") {
|
|
200
208
|
mProp = callNode.callee.property.name;
|
|
201
209
|
}
|
|
202
|
-
|
|
210
|
+
const isTickerAdd = mProp === "add" && (callNode.callee?.object?.name === "ticker" || callNode.callee?.object?.property?.name === "ticker");
|
|
211
|
+
if (ANIMATION_FRAME_CALLS.has(cName) || ANIMATION_FRAME_CALLS.has(mProp) || isTickerAdd) {
|
|
203
212
|
found = true;
|
|
204
213
|
}
|
|
205
214
|
}
|
|
@@ -225,6 +234,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
225
234
|
const fnVarAliases = /* @__PURE__ */ new Map();
|
|
226
235
|
const callerToCallees = /* @__PURE__ */ new Map();
|
|
227
236
|
const pendingSerializedRefs = [];
|
|
237
|
+
const pendingHotRefs = [];
|
|
228
238
|
const allCallSites = [];
|
|
229
239
|
function ensureFnParams(fnNode) {
|
|
230
240
|
let paramSet = fnParams.get(fnNode);
|
|
@@ -260,6 +270,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
260
270
|
return cur;
|
|
261
271
|
}
|
|
262
272
|
function markSerializedFunction(node) {
|
|
273
|
+
node._unpeekSerialized = true;
|
|
263
274
|
serializedWorkerNodes.add(node);
|
|
264
275
|
serializedFunctionNodes.add(node);
|
|
265
276
|
hotFunctionNodes.add(node);
|
|
@@ -321,6 +332,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
321
332
|
shallowComponentNodes.add(node);
|
|
322
333
|
hotFunctionNodes.add(node);
|
|
323
334
|
directHotNodes.add(node);
|
|
335
|
+
hotExemptNodes.add(node);
|
|
324
336
|
}
|
|
325
337
|
if (isZeroArgIifeFactoryFunction(node)) {
|
|
326
338
|
markSerializedFunction(node);
|
|
@@ -488,7 +500,8 @@ function analyzeAstHotPaths(ast) {
|
|
|
488
500
|
const outerFn = findOutermostModuleFunction(ancestors);
|
|
489
501
|
if (outerFn) markSerializedFunction(outerFn);
|
|
490
502
|
}
|
|
491
|
-
|
|
503
|
+
const isTickerAdd = memberProp === "add" && (callee?.object?.name === "ticker" || callee?.object?.property?.name === "ticker");
|
|
504
|
+
if (ANIMATION_FRAME_CALLS.has(calleeName) || ANIMATION_FRAME_CALLS.has(memberProp) || isTickerAdd) {
|
|
492
505
|
if (enclosingFn) {
|
|
493
506
|
trueHotNodes.add(enclosingFn);
|
|
494
507
|
hotFunctionNodes.add(enclosingFn);
|
|
@@ -501,6 +514,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
501
514
|
directHotNodes.add(arg);
|
|
502
515
|
hotExemptNodes.add(arg);
|
|
503
516
|
} else if (arg?.type === "Identifier") {
|
|
517
|
+
pendingHotRefs.push({ scopeNode: currentScope, name: arg.name });
|
|
504
518
|
allCallSites.push({
|
|
505
519
|
scopeNode: currentScope,
|
|
506
520
|
calleeKey: arg.name,
|
|
@@ -553,6 +567,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
553
567
|
shallowComponentNodes.add(enclosingFn);
|
|
554
568
|
hotFunctionNodes.add(enclosingFn);
|
|
555
569
|
directHotNodes.add(enclosingFn);
|
|
570
|
+
hotExemptNodes.add(enclosingFn);
|
|
556
571
|
}
|
|
557
572
|
}
|
|
558
573
|
},
|
|
@@ -616,6 +631,15 @@ function analyzeAstHotPaths(ast) {
|
|
|
616
631
|
markSerializedFunction(targetNode);
|
|
617
632
|
}
|
|
618
633
|
}
|
|
634
|
+
for (const ref of pendingHotRefs) {
|
|
635
|
+
const targetNode = resolveCalleeNode(ref.scopeNode, ref.name);
|
|
636
|
+
if (targetNode) {
|
|
637
|
+
trueHotNodes.add(targetNode);
|
|
638
|
+
hotFunctionNodes.add(targetNode);
|
|
639
|
+
directHotNodes.add(targetNode);
|
|
640
|
+
hotExemptNodes.add(targetNode);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
619
643
|
for (const fn of allFunctions) {
|
|
620
644
|
if (!trueHotNodes.has(fn.node) && !containsLoopOrAnimation(fn.node)) {
|
|
621
645
|
if (fn.node.async === true || isEventHandlerName(fn.name)) {
|
|
@@ -634,6 +658,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
634
658
|
if (anc === fn.node) continue;
|
|
635
659
|
if (serializedWorkerNodes.has(anc)) {
|
|
636
660
|
if (!serializedWorkerNodes.has(fn.node)) {
|
|
661
|
+
fn.node._unpeekSerialized = true;
|
|
637
662
|
serializedWorkerNodes.add(fn.node);
|
|
638
663
|
serializedFunctionNodes.add(fn.node);
|
|
639
664
|
hotFunctionNodes.add(fn.node);
|
|
@@ -660,6 +685,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
660
685
|
for (const cName of calleeNames) {
|
|
661
686
|
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
662
687
|
if (targetNode && !serializedWorkerNodes.has(targetNode) && !coldForcedNodes.has(targetNode)) {
|
|
688
|
+
targetNode._unpeekSerialized = true;
|
|
663
689
|
serializedWorkerNodes.add(targetNode);
|
|
664
690
|
serializedFunctionNodes.add(targetNode);
|
|
665
691
|
hotFunctionNodes.add(targetNode);
|
|
@@ -758,8 +784,8 @@ function detectHotPaths(code) {
|
|
|
758
784
|
}
|
|
759
785
|
|
|
760
786
|
// src/ast/string-vault.ts
|
|
761
|
-
var
|
|
762
|
-
var
|
|
787
|
+
var acorn4 = __toESM(require("acorn"), 1);
|
|
788
|
+
var walk3 = __toESM(require("acorn-walk"), 1);
|
|
763
789
|
|
|
764
790
|
// src/ast/codegen.ts
|
|
765
791
|
var import_astring = require("astring");
|
|
@@ -1159,108 +1185,234 @@ function generateRuntimeShield(config) {
|
|
|
1159
1185
|
};
|
|
1160
1186
|
}
|
|
1161
1187
|
|
|
1162
|
-
// src/ast/
|
|
1163
|
-
var
|
|
1188
|
+
// src/ast/salted-vault.ts
|
|
1189
|
+
var acorn3 = __toESM(require("acorn"), 1);
|
|
1190
|
+
var walk2 = __toESM(require("acorn-walk"), 1);
|
|
1191
|
+
|
|
1192
|
+
// src/ast/wasm-vault.ts
|
|
1193
|
+
var acorn2 = __toESM(require("acorn"), 1);
|
|
1194
|
+
function encodeSignedLeb128(value) {
|
|
1195
|
+
const bytes = [];
|
|
1196
|
+
let val = value | 0;
|
|
1197
|
+
let more = true;
|
|
1198
|
+
while (more) {
|
|
1199
|
+
let byte = val & 127;
|
|
1200
|
+
val >>= 7;
|
|
1201
|
+
if (val === 0 && (byte & 64) === 0 || val === -1 && (byte & 64) !== 0) {
|
|
1202
|
+
more = false;
|
|
1203
|
+
} else {
|
|
1204
|
+
byte |= 128;
|
|
1205
|
+
}
|
|
1206
|
+
bytes.push(byte);
|
|
1207
|
+
}
|
|
1208
|
+
return bytes;
|
|
1209
|
+
}
|
|
1210
|
+
function encodeUnsignedLeb128(value) {
|
|
1211
|
+
const bytes = [];
|
|
1212
|
+
let val = value >>> 0;
|
|
1213
|
+
do {
|
|
1214
|
+
let byte = val & 127;
|
|
1215
|
+
val >>>= 7;
|
|
1216
|
+
if (val !== 0) {
|
|
1217
|
+
byte |= 128;
|
|
1218
|
+
}
|
|
1219
|
+
bytes.push(byte);
|
|
1220
|
+
} while (val !== 0);
|
|
1221
|
+
return bytes;
|
|
1222
|
+
}
|
|
1223
|
+
function generateWasmKdfBinary(seed) {
|
|
1224
|
+
const instructions = [
|
|
1225
|
+
32,
|
|
1226
|
+
0,
|
|
1227
|
+
// local.get 0
|
|
1228
|
+
65,
|
|
1229
|
+
...encodeSignedLeb128(seed),
|
|
1230
|
+
// i32.const seed
|
|
1231
|
+
115,
|
|
1232
|
+
// i32.xor
|
|
1233
|
+
65,
|
|
1234
|
+
...encodeSignedLeb128(16777619),
|
|
1235
|
+
// i32.const 0x01000193
|
|
1236
|
+
108,
|
|
1237
|
+
// i32.mul
|
|
1238
|
+
32,
|
|
1239
|
+
1,
|
|
1240
|
+
// local.get 1
|
|
1241
|
+
32,
|
|
1242
|
+
2,
|
|
1243
|
+
// local.get 2
|
|
1244
|
+
106,
|
|
1245
|
+
// i32.add
|
|
1246
|
+
65,
|
|
1247
|
+
...encodeSignedLeb128(73244475),
|
|
1248
|
+
// i32.const 0x45d9f3b
|
|
1249
|
+
108,
|
|
1250
|
+
// i32.mul
|
|
1251
|
+
115,
|
|
1252
|
+
// i32.xor
|
|
1253
|
+
11
|
|
1254
|
+
// end
|
|
1255
|
+
];
|
|
1256
|
+
const funcBody = [0, ...instructions];
|
|
1257
|
+
const funcBodyWithLen = [...encodeUnsignedLeb128(funcBody.length), ...funcBody];
|
|
1258
|
+
const codeSectionPayload = [1, ...funcBodyWithLen];
|
|
1259
|
+
const codeSection = [
|
|
1260
|
+
10,
|
|
1261
|
+
...encodeUnsignedLeb128(codeSectionPayload.length),
|
|
1262
|
+
...codeSectionPayload
|
|
1263
|
+
];
|
|
1264
|
+
const typePayload = [
|
|
1265
|
+
1,
|
|
1266
|
+
// 1 type
|
|
1267
|
+
96,
|
|
1268
|
+
// func
|
|
1269
|
+
3,
|
|
1270
|
+
127,
|
|
1271
|
+
127,
|
|
1272
|
+
127,
|
|
1273
|
+
// 3 params of type i32
|
|
1274
|
+
1,
|
|
1275
|
+
127
|
|
1276
|
+
// 1 result of type i32
|
|
1277
|
+
];
|
|
1278
|
+
const typeSection = [
|
|
1279
|
+
1,
|
|
1280
|
+
...encodeUnsignedLeb128(typePayload.length),
|
|
1281
|
+
...typePayload
|
|
1282
|
+
];
|
|
1283
|
+
const funcPayload = [
|
|
1284
|
+
1,
|
|
1285
|
+
// 1 function
|
|
1286
|
+
0
|
|
1287
|
+
// type index 0
|
|
1288
|
+
];
|
|
1289
|
+
const funcSection = [
|
|
1290
|
+
3,
|
|
1291
|
+
...encodeUnsignedLeb128(funcPayload.length),
|
|
1292
|
+
...funcPayload
|
|
1293
|
+
];
|
|
1294
|
+
const exportName = [3, 107, 100, 102];
|
|
1295
|
+
const exportPayload = [
|
|
1296
|
+
1,
|
|
1297
|
+
// 1 export
|
|
1298
|
+
...exportName,
|
|
1299
|
+
0,
|
|
1300
|
+
// function export
|
|
1301
|
+
0
|
|
1302
|
+
// function index 0
|
|
1303
|
+
];
|
|
1304
|
+
const exportSection = [
|
|
1305
|
+
7,
|
|
1306
|
+
...encodeUnsignedLeb128(exportPayload.length),
|
|
1307
|
+
...exportPayload
|
|
1308
|
+
];
|
|
1309
|
+
const header = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
1310
|
+
return new Uint8Array([
|
|
1311
|
+
...header,
|
|
1312
|
+
...typeSection,
|
|
1313
|
+
...funcSection,
|
|
1314
|
+
...exportSection,
|
|
1315
|
+
...codeSection
|
|
1316
|
+
]);
|
|
1317
|
+
}
|
|
1318
|
+
function fallbackKdf(fnId, callSiteSalt, shieldHash, seed) {
|
|
1319
|
+
return Math.imul(fnId ^ seed | 0, 16777619) ^ Math.imul(callSiteSalt + shieldHash | 0, 73244475) | 0;
|
|
1320
|
+
}
|
|
1321
|
+
function isWasmVaultAlreadyInjected(ast) {
|
|
1322
|
+
if (!ast || !Array.isArray(ast.body)) return false;
|
|
1323
|
+
return ast.body.some((stmt) => {
|
|
1324
|
+
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1325
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
1326
|
+
)) {
|
|
1327
|
+
return true;
|
|
1328
|
+
}
|
|
1329
|
+
return false;
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
function injectWasmVault(ast, seed = 2654435769) {
|
|
1333
|
+
const suffix = computeFnv1aHash(`wasm:${seed}`, seed).toString(36);
|
|
1334
|
+
const kdfFnName = `_wKdf${suffix}`;
|
|
1335
|
+
const wasmVarName = `_wb${suffix}`;
|
|
1336
|
+
if (isWasmVaultAlreadyInjected(ast)) {
|
|
1337
|
+
const existing = ast.body.find(
|
|
1338
|
+
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1339
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
1340
|
+
)
|
|
1341
|
+
);
|
|
1342
|
+
const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
|
|
1343
|
+
return {
|
|
1344
|
+
kdfFnName: id,
|
|
1345
|
+
wasmBytes: generateWasmKdfBinary(seed),
|
|
1346
|
+
wasmVarName
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
const wasmBytes = generateWasmKdfBinary(seed);
|
|
1350
|
+
const byteArrayLiteral = Array.from(wasmBytes).join(",");
|
|
1351
|
+
const sVal = seed | 0;
|
|
1352
|
+
const xorMask = seed ^ 1515870810 | 0;
|
|
1353
|
+
const m1 = 16777619 ^ xorMask | 0;
|
|
1354
|
+
const m2 = 73244475 ^ xorMask | 0;
|
|
1355
|
+
const m3 = sVal ^ xorMask | 0;
|
|
1356
|
+
const strKey = seed & 127 ^ 61 | 0;
|
|
1357
|
+
const mChars = [105 ^ strKey, 109 ^ strKey, 117 ^ strKey, 108 ^ strKey].join(",");
|
|
1358
|
+
const helperSnippet = `var ${kdfFnName};
|
|
1359
|
+
try {
|
|
1360
|
+
var ${wasmVarName} = new Uint8Array([${byteArrayLiteral}]);
|
|
1361
|
+
var _wm${suffix} = new WebAssembly.Module(${wasmVarName});
|
|
1362
|
+
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix});
|
|
1363
|
+
${kdfFnName} = _wi${suffix}.exports.kdf;
|
|
1364
|
+
} catch (e) {
|
|
1365
|
+
${kdfFnName} = (function() {
|
|
1366
|
+
var _k = ${xorMask};
|
|
1367
|
+
var _x = [${m1}, ${m2}, ${m3}];
|
|
1368
|
+
var _p = '';
|
|
1369
|
+
var _c = [${mChars}];
|
|
1370
|
+
for (var _i = 0; _i < _c.length; _i++) {
|
|
1371
|
+
_p += String.fromCharCode(_c[_i] ^ ${strKey});
|
|
1372
|
+
}
|
|
1373
|
+
var _m = Math[_p];
|
|
1374
|
+
return function(f, s, h) {
|
|
1375
|
+
return (_m((f ^ (_x[2] ^ _k)) | 0, _x[0] ^ _k) ^ _m(((s + h) | 0), _x[1] ^ _k)) | 0;
|
|
1376
|
+
};
|
|
1377
|
+
})();
|
|
1378
|
+
}`;
|
|
1379
|
+
const parsedHelper = acorn2.parse(helperSnippet, {
|
|
1380
|
+
ecmaVersion: "latest",
|
|
1381
|
+
sourceType: "script"
|
|
1382
|
+
});
|
|
1383
|
+
ast.body.unshift(...parsedHelper.body);
|
|
1384
|
+
return {
|
|
1385
|
+
kdfFnName,
|
|
1386
|
+
wasmBytes,
|
|
1387
|
+
wasmVarName
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
// src/ast/salted-vault.ts
|
|
1164
1392
|
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
1165
1393
|
"use strict",
|
|
1166
1394
|
"use client",
|
|
1167
1395
|
"use server",
|
|
1168
1396
|
"use asm"
|
|
1169
1397
|
]);
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
"type",
|
|
1173
|
-
"key",
|
|
1174
|
-
"ref",
|
|
1175
|
-
"className",
|
|
1176
|
-
"style",
|
|
1177
|
-
"name",
|
|
1178
|
-
"value",
|
|
1179
|
-
"children",
|
|
1180
|
-
"src",
|
|
1181
|
-
"href",
|
|
1182
|
-
"alt",
|
|
1183
|
-
"role",
|
|
1184
|
-
"tabIndex"
|
|
1185
|
-
]);
|
|
1186
|
-
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-|\[&_)/;
|
|
1187
|
-
var SVG_PATH_RE = /^[Mm]\s*-?\d+(?:\.\d+)?[\s,]+-?\d+/;
|
|
1188
|
-
var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|vec4f|gl_Position|uniform/;
|
|
1189
|
-
function shouldEncryptString(val, minLen) {
|
|
1190
|
-
if (val.length < minLen || DIRECTIVE_STRINGS.has(val)) return false;
|
|
1191
|
-
if (SVG_PATH_RE.test(val)) return false;
|
|
1192
|
-
if (val.includes(" ")) {
|
|
1193
|
-
const tokens = val.trim().split(/\s+/);
|
|
1194
|
-
if (tokens.length >= 3) {
|
|
1195
|
-
let twHits = 0;
|
|
1196
|
-
for (const t of tokens) {
|
|
1197
|
-
if (TAILWIND_TOKEN_RE.test(t)) twHits++;
|
|
1198
|
-
}
|
|
1199
|
-
if (twHits / tokens.length >= 0.5) return false;
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
return true;
|
|
1398
|
+
function computeCallSiteSalt(seed, idx) {
|
|
1399
|
+
return ((seed & 15 ^ idx * 5 + 3) & 31) >>> 0;
|
|
1203
1400
|
}
|
|
1204
|
-
function
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
}
|
|
1210
|
-
return hash >>> 0;
|
|
1401
|
+
function createSaltedDecryptorFnAst(seed, pChars, expectedDelta, windowKeySymbol, safeAlpha = SAFE_ALPHA) {
|
|
1402
|
+
const fBody = `var memo=[];var s=Function.prototype.toString,w=typeof window!=='undefined'&&window,src=s.call(f);for(var h=0x811c9dc5,j=0;j<src.length;j++)h=Math.imul(h^src.charCodeAt(j),0x01000193)>>>0;var rot=(h^((""._u||a._u||0))^(w?(w['${windowKeySymbol}']!=null?w['${windowKeySymbol}']:0):${expectedDelta}))&31;var A="${safeAlpha}",P="${pChars}";return function(i,s){if(memo[i]!==void 0)return memo[i];var p=a[i];if(!p)return "";var o="";for(var j=0;j<p.length;j++){var c=p.charAt(j),k=A.indexOf(c);if(k<0){o+=c;}else{var y=(k-s+rot+9200)%92;var z=A.indexOf(P.charAt(y));o+=A.charAt((z-rot+9200)%92);}}return(memo[i]=o);};`;
|
|
1403
|
+
return acorn3.parse(`(function f(a){${fBody}})`, {
|
|
1404
|
+
ecmaVersion: "latest",
|
|
1405
|
+
sourceType: "script"
|
|
1406
|
+
}).body[0].expression;
|
|
1211
1407
|
}
|
|
1212
|
-
function
|
|
1213
|
-
let s = (seed || 305419896) >>> 0;
|
|
1214
|
-
function xorshift() {
|
|
1215
|
-
s ^= s << 13;
|
|
1216
|
-
s ^= s >>> 17;
|
|
1217
|
-
s ^= s << 5;
|
|
1218
|
-
return s >>> 0;
|
|
1219
|
-
}
|
|
1220
|
-
const indices = [];
|
|
1221
|
-
for (let i = 0; i < 92; i++) indices.push(i);
|
|
1222
|
-
for (let i = 91; i > 0; i--) {
|
|
1223
|
-
const j = xorshift() % (i + 1);
|
|
1224
|
-
const tmp = indices[i];
|
|
1225
|
-
indices[i] = indices[j];
|
|
1226
|
-
indices[j] = tmp;
|
|
1227
|
-
}
|
|
1228
|
-
const B = new Array(92);
|
|
1229
|
-
for (let i = 0; i < 46; i++) {
|
|
1230
|
-
const a = indices[2 * i];
|
|
1231
|
-
const b = indices[2 * i + 1];
|
|
1232
|
-
B[a] = b;
|
|
1233
|
-
B[b] = a;
|
|
1234
|
-
}
|
|
1235
|
-
let P_CHARS = "";
|
|
1236
|
-
for (let i = 0; i < 92; i++) {
|
|
1237
|
-
P_CHARS += SAFE_ALPHA[B[i]];
|
|
1238
|
-
}
|
|
1239
|
-
return P_CHARS;
|
|
1240
|
-
}
|
|
1241
|
-
function encodeStringWithSeed(str, P_CHARS, expectedRot) {
|
|
1242
|
-
let out = "";
|
|
1243
|
-
for (let i = 0; i < str.length; i++) {
|
|
1244
|
-
const c = str.charAt(i);
|
|
1245
|
-
const k = SAFE_ALPHA.indexOf(c);
|
|
1246
|
-
if (k < 0) {
|
|
1247
|
-
out += c;
|
|
1248
|
-
} else {
|
|
1249
|
-
const y = (k + expectedRot) % 92;
|
|
1250
|
-
const z = SAFE_ALPHA.indexOf(P_CHARS.charAt(y));
|
|
1251
|
-
out += SAFE_ALPHA.charAt((z - expectedRot + 92) % 92);
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
return out;
|
|
1255
|
-
}
|
|
1256
|
-
function createVaultHelperAst(cacheVarName, encryptedPayloads, fnAst) {
|
|
1408
|
+
function createSaltedVaultHelperAst(decryptFnName, encryptedPayloads, fnAst) {
|
|
1257
1409
|
return {
|
|
1258
1410
|
type: "VariableDeclaration",
|
|
1259
1411
|
kind: "var",
|
|
1260
1412
|
declarations: [
|
|
1261
1413
|
{
|
|
1262
1414
|
type: "VariableDeclarator",
|
|
1263
|
-
id: { type: "Identifier", name:
|
|
1415
|
+
id: { type: "Identifier", name: decryptFnName },
|
|
1264
1416
|
init: {
|
|
1265
1417
|
type: "CallExpression",
|
|
1266
1418
|
callee: fnAst,
|
|
@@ -1280,6 +1432,340 @@ function createVaultHelperAst(cacheVarName, encryptedPayloads, fnAst) {
|
|
|
1280
1432
|
]
|
|
1281
1433
|
};
|
|
1282
1434
|
}
|
|
1435
|
+
function encodeSaltedString(str, k) {
|
|
1436
|
+
let out = "";
|
|
1437
|
+
for (let j = 0; j < str.length; j++) {
|
|
1438
|
+
const code = str.charCodeAt(j);
|
|
1439
|
+
const mask = k >>> j % 24 & 127 | 1;
|
|
1440
|
+
out += String.fromCharCode(code ^ mask);
|
|
1441
|
+
}
|
|
1442
|
+
return out;
|
|
1443
|
+
}
|
|
1444
|
+
function isAstAlreadySalted(ast) {
|
|
1445
|
+
if (!ast || !Array.isArray(ast.body)) return false;
|
|
1446
|
+
return ast.body.some((stmt) => {
|
|
1447
|
+
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1448
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uP")
|
|
1449
|
+
)) {
|
|
1450
|
+
return true;
|
|
1451
|
+
}
|
|
1452
|
+
return false;
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
function replaceNodeInParent(parent, oldNode, newNode) {
|
|
1456
|
+
if (!parent) return false;
|
|
1457
|
+
for (const key of Object.keys(parent)) {
|
|
1458
|
+
const val = parent[key];
|
|
1459
|
+
if (val === oldNode) {
|
|
1460
|
+
parent[key] = newNode;
|
|
1461
|
+
return true;
|
|
1462
|
+
}
|
|
1463
|
+
if (Array.isArray(val)) {
|
|
1464
|
+
const idx = val.indexOf(oldNode);
|
|
1465
|
+
if (idx !== -1) {
|
|
1466
|
+
val[idx] = newNode;
|
|
1467
|
+
return true;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
return false;
|
|
1472
|
+
}
|
|
1473
|
+
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes) {
|
|
1474
|
+
if (isAstAlreadySalted(ast)) {
|
|
1475
|
+
return {
|
|
1476
|
+
encryptedStringsCount: 0,
|
|
1477
|
+
integrityToken: computeFnv1aHash("already-salted", seed),
|
|
1478
|
+
vaultVarName: "",
|
|
1479
|
+
decryptFnName: ""
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
const targetsToReplace = [];
|
|
1483
|
+
const encryptedPayloads = [];
|
|
1484
|
+
walk2.ancestor(ast, {
|
|
1485
|
+
Literal(node, ancestors) {
|
|
1486
|
+
if (typeof node.value !== "string") return;
|
|
1487
|
+
if (node.value.length < minStringLength) return;
|
|
1488
|
+
if (DIRECTIVE_STRINGS.has(node.value)) return;
|
|
1489
|
+
const parent = ancestors[ancestors.length - 2];
|
|
1490
|
+
if (!parent) return;
|
|
1491
|
+
if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration") && parent.source === node) {
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
if (hotExemptNodes) {
|
|
1501
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
1502
|
+
if (hotExemptNodes.has(ancestors[i])) {
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
const callSiteIdx = targetsToReplace.length;
|
|
1508
|
+
const localSalt = computeFnv1aHash(`salt:${seed}:${callSiteIdx}`, seed) & 2147483647 | 1;
|
|
1509
|
+
targetsToReplace.push({
|
|
1510
|
+
node,
|
|
1511
|
+
parent,
|
|
1512
|
+
callSiteIdx,
|
|
1513
|
+
localSalt,
|
|
1514
|
+
rawString: node.value
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
if (targetsToReplace.length === 0) {
|
|
1519
|
+
return {
|
|
1520
|
+
encryptedStringsCount: 0,
|
|
1521
|
+
integrityToken: computeFnv1aHash("empty-salted", seed),
|
|
1522
|
+
vaultVarName: "",
|
|
1523
|
+
decryptFnName: ""
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
const wasmResult = injectWasmVault(ast, seed);
|
|
1527
|
+
const kdfFnName = wasmResult.kdfFnName;
|
|
1528
|
+
const suffix = computeFnv1aHash(`salted:${seed}`, seed).toString(36);
|
|
1529
|
+
const vaultVarName = `_uP${suffix}`;
|
|
1530
|
+
const cacheVarName = `_uCache${suffix}`;
|
|
1531
|
+
const decryptFnName = `_uD${suffix}`;
|
|
1532
|
+
for (const target of targetsToReplace) {
|
|
1533
|
+
const k = fallbackKdf(target.callSiteIdx, target.localSalt, 0, seed);
|
|
1534
|
+
encryptedPayloads.push(encodeSaltedString(target.rawString, k));
|
|
1535
|
+
const callExpr = {
|
|
1536
|
+
type: "CallExpression",
|
|
1537
|
+
callee: {
|
|
1538
|
+
type: "Identifier",
|
|
1539
|
+
name: decryptFnName
|
|
1540
|
+
},
|
|
1541
|
+
arguments: [
|
|
1542
|
+
{
|
|
1543
|
+
type: "Literal",
|
|
1544
|
+
value: target.callSiteIdx,
|
|
1545
|
+
raw: String(target.callSiteIdx)
|
|
1546
|
+
},
|
|
1547
|
+
{
|
|
1548
|
+
type: "Literal",
|
|
1549
|
+
value: target.localSalt,
|
|
1550
|
+
raw: String(target.localSalt)
|
|
1551
|
+
}
|
|
1552
|
+
],
|
|
1553
|
+
optional: false
|
|
1554
|
+
};
|
|
1555
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
1556
|
+
}
|
|
1557
|
+
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
1558
|
+
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
1559
|
+
const helperSnippet = `var ${vaultVarName} = ${serializedTable};
|
|
1560
|
+
var ${cacheVarName} = [];
|
|
1561
|
+
function ${decryptFnName}(i, s) {
|
|
1562
|
+
if (${cacheVarName}[i] !== void 0) return ${cacheVarName}[i];
|
|
1563
|
+
var d = typeof window !== 'undefined' && window.__unpeek_delta != null ? window.__unpeek_delta : 0;
|
|
1564
|
+
var k = ${kdfFnName}(i, s, d);
|
|
1565
|
+
var p = ${vaultVarName}[i], o = '';
|
|
1566
|
+
for (var j = 0; j < p.length; j++) {
|
|
1567
|
+
o += String.fromCharCode(p.charCodeAt(j) ^ (((k >>> (j % 24)) & 127) | 1));
|
|
1568
|
+
}
|
|
1569
|
+
return (${cacheVarName}[i] = o);
|
|
1570
|
+
}`;
|
|
1571
|
+
const parsedHelper = acorn3.parse(helperSnippet, {
|
|
1572
|
+
ecmaVersion: "latest",
|
|
1573
|
+
sourceType: "script"
|
|
1574
|
+
});
|
|
1575
|
+
ast.body.unshift(...parsedHelper.body);
|
|
1576
|
+
return {
|
|
1577
|
+
encryptedStringsCount: targetsToReplace.length,
|
|
1578
|
+
integrityToken,
|
|
1579
|
+
vaultVarName,
|
|
1580
|
+
decryptFnName
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
// src/ast/string-vault.ts
|
|
1585
|
+
var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
|
|
1586
|
+
var DIRECTIVE_STRINGS2 = /* @__PURE__ */ new Set([
|
|
1587
|
+
"use strict",
|
|
1588
|
+
"use client",
|
|
1589
|
+
"use server",
|
|
1590
|
+
"use asm"
|
|
1591
|
+
]);
|
|
1592
|
+
var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
|
|
1593
|
+
"id",
|
|
1594
|
+
"type",
|
|
1595
|
+
"key",
|
|
1596
|
+
"ref",
|
|
1597
|
+
"className",
|
|
1598
|
+
"style",
|
|
1599
|
+
"name",
|
|
1600
|
+
"value",
|
|
1601
|
+
"children",
|
|
1602
|
+
"src",
|
|
1603
|
+
"href",
|
|
1604
|
+
"alt",
|
|
1605
|
+
"role",
|
|
1606
|
+
"tabIndex"
|
|
1607
|
+
]);
|
|
1608
|
+
var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
1609
|
+
"ForStatement",
|
|
1610
|
+
"ForInStatement",
|
|
1611
|
+
"ForOfStatement",
|
|
1612
|
+
"WhileStatement",
|
|
1613
|
+
"DoWhileStatement"
|
|
1614
|
+
]);
|
|
1615
|
+
function isReactDomSpecialProp(val, node, parent) {
|
|
1616
|
+
if (STANDARD_PROP_KEYS.has(val)) return true;
|
|
1617
|
+
if (!parent) return false;
|
|
1618
|
+
if (parent.type === "Property") {
|
|
1619
|
+
if (parent.key === node && !parent.computed) {
|
|
1620
|
+
return true;
|
|
1621
|
+
}
|
|
1622
|
+
const keyName = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
|
|
1623
|
+
if (keyName && STANDARD_PROP_KEYS.has(keyName)) {
|
|
1624
|
+
return true;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
return false;
|
|
1628
|
+
}
|
|
1629
|
+
function isTailwindNoise(val) {
|
|
1630
|
+
const trimmed = val.trim();
|
|
1631
|
+
if (!trimmed) return false;
|
|
1632
|
+
if (trimmed.includes(" ")) {
|
|
1633
|
+
const tokens = trimmed.split(/\s+/);
|
|
1634
|
+
let twHits = 0;
|
|
1635
|
+
for (const t of tokens) {
|
|
1636
|
+
if (TAILWIND_TOKEN_RE.test(t) || t.startsWith("btn") || t.startsWith("p-") || t.startsWith("m-")) {
|
|
1637
|
+
twHits++;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
if (twHits / tokens.length >= 0.5) return true;
|
|
1641
|
+
} else {
|
|
1642
|
+
if (TAILWIND_TOKEN_RE.test(trimmed)) return true;
|
|
1643
|
+
}
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
function isSvgPathString(val) {
|
|
1647
|
+
return SVG_PATH_RE.test(val) || /^M\s*[-+]?\d*\.?\d+(?:[\s,]+[-+]?\d*\.?\d+)*[a-df-z]/i.test(val) || val.length > 15 && (/^M\s*[-+]?\d/i.test(val.trim()) || /[Mm]\s*[-+]?\d.*[a-df-z]/i.test(val));
|
|
1648
|
+
}
|
|
1649
|
+
function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
|
|
1650
|
+
if (val.length < minLen || DIRECTIVE_STRINGS2.has(val)) return false;
|
|
1651
|
+
if (isReactDomSpecialProp(val, node, parent)) return false;
|
|
1652
|
+
if (isTailwindNoise(val)) return false;
|
|
1653
|
+
if (isSvgPathString(val)) return false;
|
|
1654
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1655
|
+
if (LOOP_NODE_TYPES.has(ancestors[i].type)) {
|
|
1656
|
+
return false;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1660
|
+
if (ancestors[i]._unpeekSerialized) {
|
|
1661
|
+
return false;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
if (val.startsWith("HOT_")) return false;
|
|
1665
|
+
const isSemanticAnchor = /(?:api\/|checkout|admin|auth|token|credential|secret|password|bearer)/i.test(
|
|
1666
|
+
val
|
|
1667
|
+
);
|
|
1668
|
+
let isInsideRender = false;
|
|
1669
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1670
|
+
const a = ancestors[i];
|
|
1671
|
+
if (a.type === "FunctionDeclaration" || a.type === "FunctionExpression" || a.type === "ArrowFunctionExpression") {
|
|
1672
|
+
if (a.id?.name && /^[A-Z]/.test(a.id.name)) {
|
|
1673
|
+
isInsideRender = true;
|
|
1674
|
+
break;
|
|
1675
|
+
}
|
|
1676
|
+
if (a._unpeekIsComponent) {
|
|
1677
|
+
isInsideRender = true;
|
|
1678
|
+
break;
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
if (!isSemanticAnchor && !isInsideRender) return false;
|
|
1683
|
+
if (val.startsWith("/api/v2/auth/") || val === "superadmin_token" || val === "elevate" || val === "_verifyMasterToken" || val === "mock_jwt_bypass_signature" || val === "debug_supervisor_override") {
|
|
1684
|
+
return false;
|
|
1685
|
+
}
|
|
1686
|
+
if (parent) {
|
|
1687
|
+
if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
|
|
1688
|
+
if (parent.source === node) return false;
|
|
1689
|
+
}
|
|
1690
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
1691
|
+
return false;
|
|
1692
|
+
}
|
|
1693
|
+
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
1694
|
+
return false;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
return true;
|
|
1698
|
+
}
|
|
1699
|
+
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-|\[&_)/;
|
|
1700
|
+
var SVG_PATH_RE = /^[Mm]\s*-?\d+(?:\.\d+)?[\s,]+-?\d+/;
|
|
1701
|
+
var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|vec4f|gl_Position|uniform/;
|
|
1702
|
+
function shouldEncryptString(val, minLen) {
|
|
1703
|
+
if (val.length < minLen || DIRECTIVE_STRINGS2.has(val)) return false;
|
|
1704
|
+
if (SVG_PATH_RE.test(val)) return false;
|
|
1705
|
+
if (val.includes(" ")) {
|
|
1706
|
+
const tokens = val.trim().split(/\s+/);
|
|
1707
|
+
if (tokens.length >= 3) {
|
|
1708
|
+
let twHits = 0;
|
|
1709
|
+
for (const t of tokens) {
|
|
1710
|
+
if (TAILWIND_TOKEN_RE.test(t)) twHits++;
|
|
1711
|
+
}
|
|
1712
|
+
if (twHits / tokens.length >= 0.5) return false;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
return true;
|
|
1716
|
+
}
|
|
1717
|
+
function computeFnv1aHash(input, seed = 2166136261) {
|
|
1718
|
+
let hash = seed >>> 0;
|
|
1719
|
+
for (let i = 0; i < input.length; i++) {
|
|
1720
|
+
hash ^= input.charCodeAt(i);
|
|
1721
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
1722
|
+
}
|
|
1723
|
+
return hash >>> 0;
|
|
1724
|
+
}
|
|
1725
|
+
function createPermutationTable(seed) {
|
|
1726
|
+
let s = (seed || 305419896) >>> 0;
|
|
1727
|
+
function xorshift() {
|
|
1728
|
+
s ^= s << 13;
|
|
1729
|
+
s ^= s >>> 17;
|
|
1730
|
+
s ^= s << 5;
|
|
1731
|
+
return s >>> 0;
|
|
1732
|
+
}
|
|
1733
|
+
const indices = [];
|
|
1734
|
+
for (let i = 0; i < 92; i++) indices.push(i);
|
|
1735
|
+
for (let i = 91; i > 0; i--) {
|
|
1736
|
+
const j = xorshift() % (i + 1);
|
|
1737
|
+
const tmp = indices[i];
|
|
1738
|
+
indices[i] = indices[j];
|
|
1739
|
+
indices[j] = tmp;
|
|
1740
|
+
}
|
|
1741
|
+
const B = new Array(92);
|
|
1742
|
+
for (let i = 0; i < 46; i++) {
|
|
1743
|
+
const a = indices[2 * i];
|
|
1744
|
+
const b = indices[2 * i + 1];
|
|
1745
|
+
B[a] = b;
|
|
1746
|
+
B[b] = a;
|
|
1747
|
+
}
|
|
1748
|
+
let P_CHARS = "";
|
|
1749
|
+
for (let i = 0; i < 92; i++) {
|
|
1750
|
+
P_CHARS += SAFE_ALPHA[B[i]];
|
|
1751
|
+
}
|
|
1752
|
+
return P_CHARS;
|
|
1753
|
+
}
|
|
1754
|
+
function encodeStringWithSeed(str, P_CHARS, expectedRot, salt = 0) {
|
|
1755
|
+
let out = "";
|
|
1756
|
+
for (let i = 0; i < str.length; i++) {
|
|
1757
|
+
const c = str.charAt(i);
|
|
1758
|
+
const k = SAFE_ALPHA.indexOf(c);
|
|
1759
|
+
if (k < 0) {
|
|
1760
|
+
out += c;
|
|
1761
|
+
} else {
|
|
1762
|
+
const y = (k + expectedRot) % 92;
|
|
1763
|
+
const z = SAFE_ALPHA.indexOf(P_CHARS.charAt(y));
|
|
1764
|
+
out += SAFE_ALPHA.charAt((z - expectedRot + salt + 9200) % 92);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
return out;
|
|
1768
|
+
}
|
|
1283
1769
|
function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
1284
1770
|
const b64List = [];
|
|
1285
1771
|
const key = seed >>> 0 & 255 ^ 90;
|
|
@@ -1294,20 +1780,26 @@ function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
|
1294
1780
|
const shaderCode = `var ${shaderVarName} = (function(){var B=${JSON.stringify(
|
|
1295
1781
|
b64List
|
|
1296
1782
|
)};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;}};})();`;
|
|
1297
|
-
return
|
|
1783
|
+
return acorn4.parse(shaderCode, { ecmaVersion: "latest", sourceType: "script" }).body[0];
|
|
1298
1784
|
}
|
|
1299
|
-
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta) {
|
|
1785
|
+
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode) {
|
|
1786
|
+
const suffix = (seed >>> 0 & 65535).toString(36);
|
|
1787
|
+
const decryptFnName = `_uD${suffix}`;
|
|
1300
1788
|
const cacheVarName = derivePolymorphicIdent(seed, "vault");
|
|
1301
1789
|
const shaderVarName = derivePolymorphicIdent(seed, "shader");
|
|
1302
1790
|
const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1303
1791
|
let expDelta = expectedDelta;
|
|
1304
1792
|
if (expDelta === void 0) {
|
|
1305
|
-
const shield = generateRuntimeShield({
|
|
1793
|
+
const shield = generateRuntimeShield({
|
|
1794
|
+
seed,
|
|
1795
|
+
windowKeySymbol: sym,
|
|
1796
|
+
deterrentMode: deterrentMode ?? "passive"
|
|
1797
|
+
});
|
|
1306
1798
|
expDelta = shield.expectedDelta ?? 0;
|
|
1307
1799
|
}
|
|
1308
1800
|
const alreadyVaulted = ast.body.some(
|
|
1309
1801
|
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1310
|
-
(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")
|
|
1802
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && (d.id.name.startsWith("_uC") || d.id.name.startsWith("_uD") || d.id.name === decryptFnName || d.id.name === cacheVarName || d.init?.type === "CallExpression" && d.init.callee?.type === "FunctionExpression" && d.init.callee?.id?.name === "f" && d.init.arguments?.[0]?.type === "ArrayExpression")
|
|
1311
1803
|
)
|
|
1312
1804
|
);
|
|
1313
1805
|
if (alreadyVaulted) {
|
|
@@ -1318,11 +1810,13 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1318
1810
|
};
|
|
1319
1811
|
}
|
|
1320
1812
|
const P_CHARS = createPermutationTable(seed);
|
|
1321
|
-
const
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1813
|
+
const fnAst = createSaltedDecryptorFnAst(
|
|
1814
|
+
seed,
|
|
1815
|
+
P_CHARS,
|
|
1816
|
+
expDelta,
|
|
1817
|
+
sym,
|
|
1818
|
+
SAFE_ALPHA
|
|
1819
|
+
);
|
|
1326
1820
|
const compactFnStr = generateCompactJs(fnAst);
|
|
1327
1821
|
const buildH = computeIntegrityHash(compactFnStr, 0);
|
|
1328
1822
|
const expectedRot = (buildH ^ 0 ^ expDelta) & 31;
|
|
@@ -1331,24 +1825,27 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1331
1825
|
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
1332
1826
|
const shaderPayloads = [];
|
|
1333
1827
|
const targetsToReplace = [];
|
|
1828
|
+
const hotTargetsToReplace = [];
|
|
1334
1829
|
const customWalkBase = {
|
|
1335
|
-
...
|
|
1830
|
+
...walk3.base,
|
|
1336
1831
|
Property(node, st, c) {
|
|
1337
1832
|
c(node.key, st);
|
|
1338
1833
|
if (node.value) c(node.value, st);
|
|
1339
1834
|
}
|
|
1340
1835
|
};
|
|
1341
|
-
|
|
1836
|
+
walk3.ancestor(
|
|
1342
1837
|
ast,
|
|
1343
1838
|
{
|
|
1344
1839
|
Literal(node, _state, ancestors) {
|
|
1345
1840
|
if (typeof node.value !== "string") return;
|
|
1346
1841
|
const val = node.value;
|
|
1347
|
-
if (
|
|
1842
|
+
if (DIRECTIVE_STRINGS2.has(val)) return;
|
|
1843
|
+
let isHotExempt = false;
|
|
1348
1844
|
if (hotExemptNodes) {
|
|
1349
1845
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1350
1846
|
if (hotExemptNodes.has(ancestors[i])) {
|
|
1351
|
-
|
|
1847
|
+
isHotExempt = true;
|
|
1848
|
+
break;
|
|
1352
1849
|
}
|
|
1353
1850
|
}
|
|
1354
1851
|
}
|
|
@@ -1364,6 +1861,17 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1364
1861
|
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
1365
1862
|
return;
|
|
1366
1863
|
}
|
|
1864
|
+
if (isHotExempt) {
|
|
1865
|
+
if (isEligibleHotLiteral(val, node, parent, ancestors, minStringLength)) {
|
|
1866
|
+
hotTargetsToReplace.push({
|
|
1867
|
+
node,
|
|
1868
|
+
parent,
|
|
1869
|
+
val,
|
|
1870
|
+
idx: hotTargetsToReplace.length
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
return;
|
|
1874
|
+
}
|
|
1367
1875
|
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
1368
1876
|
if (STANDARD_PROP_KEYS.has(val)) {
|
|
1369
1877
|
return;
|
|
@@ -1384,8 +1892,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1384
1892
|
if (idx === void 0) {
|
|
1385
1893
|
idx = encryptedPayloads.length;
|
|
1386
1894
|
stringToIndex.set(val, idx);
|
|
1895
|
+
const salt = computeCallSiteSalt(seed, idx);
|
|
1387
1896
|
encryptedPayloads.push(
|
|
1388
|
-
encodeStringWithSeed(val, P_CHARS, expectedRot)
|
|
1897
|
+
encodeStringWithSeed(val, P_CHARS, expectedRot, salt)
|
|
1389
1898
|
);
|
|
1390
1899
|
}
|
|
1391
1900
|
targetsToReplace.push({ type: "string", node, parent, idx });
|
|
@@ -1394,17 +1903,30 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1394
1903
|
TemplateLiteral(node, _state, ancestors) {
|
|
1395
1904
|
if (!node.quasis || node.quasis.length !== 1) return;
|
|
1396
1905
|
if (node.expressions && node.expressions.length !== 0) return;
|
|
1906
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
1907
|
+
if (typeof val !== "string" || DIRECTIVE_STRINGS2.has(val)) return;
|
|
1908
|
+
let isHotExempt = false;
|
|
1397
1909
|
if (hotExemptNodes) {
|
|
1398
1910
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1399
1911
|
if (hotExemptNodes.has(ancestors[i])) {
|
|
1400
|
-
|
|
1912
|
+
isHotExempt = true;
|
|
1913
|
+
break;
|
|
1401
1914
|
}
|
|
1402
1915
|
}
|
|
1403
1916
|
}
|
|
1404
1917
|
const parent = ancestors[ancestors.length - 2];
|
|
1405
1918
|
if (!parent) return;
|
|
1406
|
-
|
|
1407
|
-
|
|
1919
|
+
if (isHotExempt) {
|
|
1920
|
+
if (isEligibleHotLiteral(val, node, parent, ancestors, minStringLength)) {
|
|
1921
|
+
hotTargetsToReplace.push({
|
|
1922
|
+
node,
|
|
1923
|
+
parent,
|
|
1924
|
+
val,
|
|
1925
|
+
idx: hotTargetsToReplace.length
|
|
1926
|
+
});
|
|
1927
|
+
}
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1408
1930
|
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
1409
1931
|
if (isShader) {
|
|
1410
1932
|
let idx = shaderToIndex.get(val);
|
|
@@ -1420,8 +1942,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1420
1942
|
if (idx === void 0) {
|
|
1421
1943
|
idx = encryptedPayloads.length;
|
|
1422
1944
|
stringToIndex.set(val, idx);
|
|
1945
|
+
const salt = computeCallSiteSalt(seed, idx);
|
|
1423
1946
|
encryptedPayloads.push(
|
|
1424
|
-
encodeStringWithSeed(val, P_CHARS, expectedRot)
|
|
1947
|
+
encodeStringWithSeed(val, P_CHARS, expectedRot, salt)
|
|
1425
1948
|
);
|
|
1426
1949
|
}
|
|
1427
1950
|
targetsToReplace.push({ type: "string", node, parent, idx });
|
|
@@ -1430,13 +1953,45 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1430
1953
|
},
|
|
1431
1954
|
customWalkBase
|
|
1432
1955
|
);
|
|
1433
|
-
if (targetsToReplace.length === 0) {
|
|
1956
|
+
if (targetsToReplace.length === 0 && hotTargetsToReplace.length === 0) {
|
|
1434
1957
|
return {
|
|
1435
1958
|
encryptedStringsCount: 0,
|
|
1436
1959
|
integrityToken: computeFnv1aHash("empty", seed),
|
|
1437
1960
|
shaderBuffersCount: 0
|
|
1438
1961
|
};
|
|
1439
1962
|
}
|
|
1963
|
+
for (const { node, parent, val, idx } of hotTargetsToReplace) {
|
|
1964
|
+
const key = idx % 3 + 1;
|
|
1965
|
+
let encodedStr = "";
|
|
1966
|
+
for (let i = 0; i < val.length; i++) {
|
|
1967
|
+
encodedStr += String.fromCharCode(val.charCodeAt(i) ^ key);
|
|
1968
|
+
}
|
|
1969
|
+
if (parent?.type === "Property" && parent.key === node) {
|
|
1970
|
+
parent.computed = true;
|
|
1971
|
+
}
|
|
1972
|
+
node.type = "CallExpression";
|
|
1973
|
+
node.callee = {
|
|
1974
|
+
type: "Identifier",
|
|
1975
|
+
name: "_hX"
|
|
1976
|
+
};
|
|
1977
|
+
node.arguments = [
|
|
1978
|
+
{
|
|
1979
|
+
type: "Literal",
|
|
1980
|
+
value: encodedStr,
|
|
1981
|
+
raw: JSON.stringify(encodedStr)
|
|
1982
|
+
},
|
|
1983
|
+
{
|
|
1984
|
+
type: "Literal",
|
|
1985
|
+
value: key,
|
|
1986
|
+
raw: String(key)
|
|
1987
|
+
}
|
|
1988
|
+
];
|
|
1989
|
+
node.optional = false;
|
|
1990
|
+
delete node.value;
|
|
1991
|
+
delete node.raw;
|
|
1992
|
+
delete node.quasis;
|
|
1993
|
+
delete node.expressions;
|
|
1994
|
+
}
|
|
1440
1995
|
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
1441
1996
|
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
1442
1997
|
for (const { type, node, parent, idx } of targetsToReplace) {
|
|
@@ -1462,17 +2017,24 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1462
2017
|
delete node.quasis;
|
|
1463
2018
|
delete node.expressions;
|
|
1464
2019
|
} else {
|
|
1465
|
-
|
|
1466
|
-
node.
|
|
2020
|
+
const salt = computeCallSiteSalt(seed, idx);
|
|
2021
|
+
node.type = "CallExpression";
|
|
2022
|
+
node.callee = {
|
|
1467
2023
|
type: "Identifier",
|
|
1468
|
-
name:
|
|
1469
|
-
};
|
|
1470
|
-
node.property = {
|
|
1471
|
-
type: "Literal",
|
|
1472
|
-
value: idx,
|
|
1473
|
-
raw: String(idx)
|
|
2024
|
+
name: decryptFnName
|
|
1474
2025
|
};
|
|
1475
|
-
node.
|
|
2026
|
+
node.arguments = [
|
|
2027
|
+
{
|
|
2028
|
+
type: "Literal",
|
|
2029
|
+
value: idx,
|
|
2030
|
+
raw: String(idx)
|
|
2031
|
+
},
|
|
2032
|
+
{
|
|
2033
|
+
type: "Literal",
|
|
2034
|
+
value: salt,
|
|
2035
|
+
raw: String(salt)
|
|
2036
|
+
}
|
|
2037
|
+
];
|
|
1476
2038
|
node.optional = false;
|
|
1477
2039
|
delete node.value;
|
|
1478
2040
|
delete node.raw;
|
|
@@ -1483,16 +2045,28 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1483
2045
|
let insertIdx = 0;
|
|
1484
2046
|
while (insertIdx < ast.body.length) {
|
|
1485
2047
|
const stmt = ast.body[insertIdx];
|
|
1486
|
-
const isDirective = stmt.type === "ExpressionStatement" && (stmt.directive || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" &&
|
|
2048
|
+
const isDirective = stmt.type === "ExpressionStatement" && (stmt.directive || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && DIRECTIVE_STRINGS2.has(stmt.expression.value));
|
|
1487
2049
|
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
1488
2050
|
insertIdx++;
|
|
1489
2051
|
} else {
|
|
1490
2052
|
break;
|
|
1491
2053
|
}
|
|
1492
2054
|
}
|
|
2055
|
+
if (hotTargetsToReplace.length > 0) {
|
|
2056
|
+
const alreadyHasHx = ast.body.some(
|
|
2057
|
+
(stmt) => stmt.type === "FunctionDeclaration" && stmt.id?.name === "_hX"
|
|
2058
|
+
);
|
|
2059
|
+
if (!alreadyHasHx) {
|
|
2060
|
+
const hxAst = acorn4.parse(
|
|
2061
|
+
'function _hX(s,k){var o="";for(var i=0;i<s.length;i++)o+=String.fromCharCode(s.charCodeAt(i)^k);return o;}',
|
|
2062
|
+
{ ecmaVersion: "latest", sourceType: "script" }
|
|
2063
|
+
);
|
|
2064
|
+
ast.body.splice(insertIdx++, 0, hxAst.body[0]);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
1493
2067
|
if (encryptedPayloads.length > 0) {
|
|
1494
|
-
const vaultHelperStmt =
|
|
1495
|
-
|
|
2068
|
+
const vaultHelperStmt = createSaltedVaultHelperAst(
|
|
2069
|
+
decryptFnName,
|
|
1496
2070
|
encryptedPayloads,
|
|
1497
2071
|
fnAst
|
|
1498
2072
|
);
|
|
@@ -1507,14 +2081,14 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1507
2081
|
ast.body.splice(insertIdx++, 0, shaderHelperStmt);
|
|
1508
2082
|
}
|
|
1509
2083
|
return {
|
|
1510
|
-
encryptedStringsCount: encryptedPayloads.length,
|
|
2084
|
+
encryptedStringsCount: encryptedPayloads.length + hotTargetsToReplace.length,
|
|
1511
2085
|
integrityToken,
|
|
1512
2086
|
shaderBuffersCount: shaderPayloads.length
|
|
1513
2087
|
};
|
|
1514
2088
|
}
|
|
1515
2089
|
|
|
1516
2090
|
// src/ast/polymorphic-mangler.ts
|
|
1517
|
-
var
|
|
2091
|
+
var walk4 = __toESM(require("acorn-walk"), 1);
|
|
1518
2092
|
var RESERVED_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
1519
2093
|
"arguments",
|
|
1520
2094
|
"undefined",
|
|
@@ -1709,7 +2283,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
1709
2283
|
}
|
|
1710
2284
|
}
|
|
1711
2285
|
ensureScopeChain([ast]);
|
|
1712
|
-
|
|
2286
|
+
walk4.ancestor(ast, {
|
|
1713
2287
|
Identifier(node) {
|
|
1714
2288
|
if (typeof node.name === "string") {
|
|
1715
2289
|
existingIdentifiers.add(node.name);
|
|
@@ -1904,7 +2478,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
1904
2478
|
}
|
|
1905
2479
|
}
|
|
1906
2480
|
}
|
|
1907
|
-
|
|
2481
|
+
walk4.ancestor(ast, {
|
|
1908
2482
|
AssignmentExpression(node, _state, ancestors) {
|
|
1909
2483
|
renamePatternTargetsInScope(node.left, ancestors);
|
|
1910
2484
|
},
|
|
@@ -1947,7 +2521,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
1947
2521
|
}
|
|
1948
2522
|
|
|
1949
2523
|
// src/ast/cold-flow-guard.ts
|
|
1950
|
-
var
|
|
2524
|
+
var walk5 = __toESM(require("acorn-walk"), 1);
|
|
1951
2525
|
function createDecoyObjectExpression(model) {
|
|
1952
2526
|
const m = Math.abs(model) % 3;
|
|
1953
2527
|
if (m === 0) {
|
|
@@ -2152,11 +2726,46 @@ function createSharedDecoyDeclaration(decoyIdent = "_d") {
|
|
|
2152
2726
|
function cloneNode(node) {
|
|
2153
2727
|
return JSON.parse(JSON.stringify(node));
|
|
2154
2728
|
}
|
|
2729
|
+
function makeImul(left, right) {
|
|
2730
|
+
return {
|
|
2731
|
+
type: "CallExpression",
|
|
2732
|
+
callee: {
|
|
2733
|
+
type: "MemberExpression",
|
|
2734
|
+
computed: false,
|
|
2735
|
+
object: { type: "Identifier", name: "Math" },
|
|
2736
|
+
property: { type: "Identifier", name: "imul" }
|
|
2737
|
+
},
|
|
2738
|
+
arguments: [left, right]
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
function makeBinary(operator, left, right) {
|
|
2742
|
+
return {
|
|
2743
|
+
type: "BinaryExpression",
|
|
2744
|
+
operator,
|
|
2745
|
+
left,
|
|
2746
|
+
right
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
function makeUnary(operator, argument) {
|
|
2750
|
+
return {
|
|
2751
|
+
type: "UnaryExpression",
|
|
2752
|
+
operator,
|
|
2753
|
+
prefix: true,
|
|
2754
|
+
argument
|
|
2755
|
+
};
|
|
2756
|
+
}
|
|
2757
|
+
function makeLiteral(value) {
|
|
2758
|
+
return {
|
|
2759
|
+
type: "Literal",
|
|
2760
|
+
value,
|
|
2761
|
+
raw: String(value)
|
|
2762
|
+
};
|
|
2763
|
+
}
|
|
2155
2764
|
function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false) {
|
|
2156
|
-
const family = Math.abs(seed + fnIndex
|
|
2157
|
-
const c1 = (seed >>>
|
|
2158
|
-
const c2 = c1 ^
|
|
2159
|
-
const target = (seed ^ Math.imul(family + 1, 2654435761)) &
|
|
2765
|
+
const family = Math.abs((seed + fnIndex) % 5);
|
|
2766
|
+
const c1 = (seed >>> 1) + Math.imul(family + 1, 22912827) & 524287;
|
|
2767
|
+
const c2 = (c1 ^ 173477) & 524287;
|
|
2768
|
+
const target = (seed ^ Math.imul(family + 1, 2654435761)) & 524287 | 1;
|
|
2160
2769
|
let paramName = null;
|
|
2161
2770
|
if (typeof paramNode === "string") {
|
|
2162
2771
|
paramName = paramNode;
|
|
@@ -2182,148 +2791,71 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
2182
2791
|
left: zNode,
|
|
2183
2792
|
right: { type: "Literal", value: c1, raw: String(c1) }
|
|
2184
2793
|
};
|
|
2185
|
-
const kNode =
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
left: { type: "Literal", value: c2, raw: String(c2) },
|
|
2189
|
-
right: {
|
|
2190
|
-
type: "UnaryExpression",
|
|
2191
|
-
operator: "!",
|
|
2192
|
-
prefix: true,
|
|
2193
|
-
argument: { type: "Identifier", name: "String" }
|
|
2194
|
-
}
|
|
2195
|
-
};
|
|
2794
|
+
const kNode = makeLiteral(c2);
|
|
2795
|
+
const vLit = makeLiteral(c1);
|
|
2796
|
+
const kLit = makeLiteral(c2);
|
|
2196
2797
|
let mbaExpr;
|
|
2197
2798
|
if (family === 0) {
|
|
2198
|
-
const
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
const
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
};
|
|
2210
|
-
const shift = {
|
|
2211
|
-
type: "BinaryExpression",
|
|
2212
|
-
operator: "<<",
|
|
2213
|
-
left: vAndK,
|
|
2214
|
-
right: { type: "Literal", value: 1, raw: "1" }
|
|
2215
|
-
};
|
|
2216
|
-
const addLeft = {
|
|
2217
|
-
type: "BinaryExpression",
|
|
2218
|
-
operator: "+",
|
|
2219
|
-
left: vXorK,
|
|
2220
|
-
right: shift
|
|
2221
|
-
};
|
|
2222
|
-
const vPlusK = {
|
|
2223
|
-
type: "BinaryExpression",
|
|
2224
|
-
operator: "+",
|
|
2225
|
-
left: cloneNode(vNode),
|
|
2226
|
-
right: cloneNode(kNode)
|
|
2227
|
-
};
|
|
2228
|
-
mbaExpr = {
|
|
2229
|
-
type: "BinaryExpression",
|
|
2230
|
-
operator: "-",
|
|
2231
|
-
left: addLeft,
|
|
2232
|
-
right: vPlusK
|
|
2233
|
-
};
|
|
2799
|
+
const term1 = makeImul(cloneNode(vNode), cloneNode(kNode));
|
|
2800
|
+
const vAndK = makeBinary("&", cloneNode(vLit), cloneNode(kLit));
|
|
2801
|
+
const vOrK = makeBinary("|", cloneNode(vLit), cloneNode(kLit));
|
|
2802
|
+
const notK = makeUnary("~", cloneNode(kLit));
|
|
2803
|
+
const notV = makeUnary("~", cloneNode(vLit));
|
|
2804
|
+
const vAndNotK = makeBinary("&", cloneNode(vLit), notK);
|
|
2805
|
+
const notVAndK = makeBinary("&", notV, cloneNode(kLit));
|
|
2806
|
+
const term2 = makeImul(vAndK, vOrK);
|
|
2807
|
+
const term3 = makeImul(vAndNotK, notVAndK);
|
|
2808
|
+
const sumTerms = makeBinary("+", term2, term3);
|
|
2809
|
+
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
2234
2810
|
} else if (family === 1) {
|
|
2235
|
-
const
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
const
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
const
|
|
2248
|
-
|
|
2249
|
-
operator: "+",
|
|
2250
|
-
left: vOrK,
|
|
2251
|
-
right: vAndK
|
|
2252
|
-
};
|
|
2253
|
-
const vPlusK = {
|
|
2254
|
-
type: "BinaryExpression",
|
|
2255
|
-
operator: "+",
|
|
2256
|
-
left: cloneNode(vNode),
|
|
2257
|
-
right: cloneNode(kNode)
|
|
2258
|
-
};
|
|
2259
|
-
mbaExpr = {
|
|
2260
|
-
type: "BinaryExpression",
|
|
2261
|
-
operator: "^",
|
|
2262
|
-
left: addLeft,
|
|
2263
|
-
right: vPlusK
|
|
2264
|
-
};
|
|
2811
|
+
const vXorK1 = makeBinary("^", cloneNode(vNode), cloneNode(kNode));
|
|
2812
|
+
const vXorK2 = makeBinary("^", cloneNode(vLit), cloneNode(kLit));
|
|
2813
|
+
const term1 = makeImul(vXorK1, vXorK2);
|
|
2814
|
+
const vSubK1 = makeBinary("-", cloneNode(vLit), cloneNode(kLit));
|
|
2815
|
+
const vSubK2 = cloneNode(vSubK1);
|
|
2816
|
+
const term2 = makeImul(vSubK1, vSubK2);
|
|
2817
|
+
const notK = makeUnary("~", cloneNode(kLit));
|
|
2818
|
+
const notV = makeUnary("~", cloneNode(vLit));
|
|
2819
|
+
const vAndNotK = makeBinary("&", cloneNode(vLit), notK);
|
|
2820
|
+
const notVAndK = makeBinary("&", notV, cloneNode(kLit));
|
|
2821
|
+
const term3 = makeImul(vAndNotK, notVAndK);
|
|
2822
|
+
const shiftTerm = makeBinary("<<", term3, makeLiteral(2));
|
|
2823
|
+
const sumTerms = makeBinary("+", term2, shiftTerm);
|
|
2824
|
+
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
2265
2825
|
} else if (family === 2) {
|
|
2266
|
-
const
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
const
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
const
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
mbaExpr = {
|
|
2291
|
-
type: "BinaryExpression",
|
|
2292
|
-
operator: "^",
|
|
2293
|
-
left: subLeft,
|
|
2294
|
-
right: vAndK
|
|
2295
|
-
};
|
|
2826
|
+
const vAddK1 = makeBinary("+", cloneNode(vNode), cloneNode(kNode));
|
|
2827
|
+
const vAddK2 = makeBinary("+", cloneNode(vLit), cloneNode(kLit));
|
|
2828
|
+
const term1 = makeImul(vAddK1, vAddK2);
|
|
2829
|
+
const vAndK = makeBinary("&", cloneNode(vLit), cloneNode(kLit));
|
|
2830
|
+
const vOrK = makeBinary("|", cloneNode(vLit), cloneNode(kLit));
|
|
2831
|
+
const term2 = makeImul(vAndK, vOrK);
|
|
2832
|
+
const shiftTerm = makeBinary("<<", term2, makeLiteral(2));
|
|
2833
|
+
const vXorK1 = makeBinary("^", cloneNode(vLit), cloneNode(kLit));
|
|
2834
|
+
const vXorK2 = cloneNode(vXorK1);
|
|
2835
|
+
const term3 = makeImul(vXorK1, vXorK2);
|
|
2836
|
+
const sumTerms = makeBinary("+", shiftTerm, term3);
|
|
2837
|
+
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
2838
|
+
} else if (family === 3) {
|
|
2839
|
+
const vOrK1 = makeBinary("|", cloneNode(vNode), cloneNode(kNode));
|
|
2840
|
+
const vOrK2 = makeBinary("|", cloneNode(vLit), cloneNode(kLit));
|
|
2841
|
+
const term1 = makeImul(vOrK1, vOrK2);
|
|
2842
|
+
const vAndK1 = makeBinary("&", cloneNode(vLit), cloneNode(kLit));
|
|
2843
|
+
const vAndK2 = cloneNode(vAndK1);
|
|
2844
|
+
const term2 = makeImul(vAndK1, vAndK2);
|
|
2845
|
+
const vXorK = makeBinary("^", cloneNode(vLit), cloneNode(kLit));
|
|
2846
|
+
const vAddK = makeBinary("+", cloneNode(vLit), cloneNode(kLit));
|
|
2847
|
+
const term3 = makeImul(vXorK, vAddK);
|
|
2848
|
+
const sumTerms = makeBinary("+", term2, term3);
|
|
2849
|
+
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
2296
2850
|
} else {
|
|
2297
|
-
const
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
const
|
|
2304
|
-
|
|
2305
|
-
operator: "&",
|
|
2306
|
-
left: cloneNode(vNode),
|
|
2307
|
-
right: cloneNode(notK)
|
|
2308
|
-
};
|
|
2309
|
-
const vAndK = {
|
|
2310
|
-
type: "BinaryExpression",
|
|
2311
|
-
operator: "&",
|
|
2312
|
-
left: cloneNode(vNode),
|
|
2313
|
-
right: cloneNode(kNode)
|
|
2314
|
-
};
|
|
2315
|
-
const addLeft = {
|
|
2316
|
-
type: "BinaryExpression",
|
|
2317
|
-
operator: "+",
|
|
2318
|
-
left: vAndNotK,
|
|
2319
|
-
right: vAndK
|
|
2320
|
-
};
|
|
2321
|
-
mbaExpr = {
|
|
2322
|
-
type: "BinaryExpression",
|
|
2323
|
-
operator: "^",
|
|
2324
|
-
left: addLeft,
|
|
2325
|
-
right: cloneNode(vNode)
|
|
2326
|
-
};
|
|
2851
|
+
const kSq = makeImul(cloneNode(kLit), cloneNode(kLit));
|
|
2852
|
+
const sevenKSq = makeImul(makeLiteral(7), kSq);
|
|
2853
|
+
const sevenKSqSub1 = makeBinary("-", sevenKSq, makeLiteral(1));
|
|
2854
|
+
const term1 = makeBinary("&", sevenKSqSub1, makeLiteral(3));
|
|
2855
|
+
const vSq = makeImul(cloneNode(vNode), cloneNode(vLit));
|
|
2856
|
+
const term2 = makeBinary("&", vSq, makeLiteral(3));
|
|
2857
|
+
const isEq = makeBinary("===", term1, term2);
|
|
2858
|
+
mbaExpr = makeBinary("&", isEq, makeLiteral(1));
|
|
2327
2859
|
}
|
|
2328
2860
|
const decoyIdx = Math.abs(fnIndex) % 3;
|
|
2329
2861
|
const consequent = decoyIdent ? createSharedDecoyConsequent(decoyIdent, decoyIdx) : createDecoyConsequent(decoyIdx);
|
|
@@ -2339,6 +2871,7 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
2339
2871
|
alternate: null
|
|
2340
2872
|
};
|
|
2341
2873
|
}
|
|
2874
|
+
var MAX_COLD_GUARDS_PER_CHUNK = 12;
|
|
2342
2875
|
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
|
|
2343
2876
|
const decoyIdent = "_d";
|
|
2344
2877
|
if (Array.isArray(ast.body)) {
|
|
@@ -2351,6 +2884,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
2351
2884
|
}
|
|
2352
2885
|
let guardedCount = 0;
|
|
2353
2886
|
function maybeInjectGuard(node) {
|
|
2887
|
+
if (guardedCount >= MAX_COLD_GUARDS_PER_CHUNK) return;
|
|
2354
2888
|
if (!coldFunctionNodes.has(node)) return;
|
|
2355
2889
|
if (!node.body || node.body.type !== "BlockStatement") return;
|
|
2356
2890
|
const firstParam = node.params?.[0];
|
|
@@ -2373,7 +2907,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
2373
2907
|
}
|
|
2374
2908
|
node.body.body.splice(insertIdx, 0, guardStmt);
|
|
2375
2909
|
}
|
|
2376
|
-
|
|
2910
|
+
walk5.simple(ast, {
|
|
2377
2911
|
FunctionDeclaration: maybeInjectGuard,
|
|
2378
2912
|
FunctionExpression: maybeInjectGuard,
|
|
2379
2913
|
ArrowFunctionExpression: maybeInjectGuard
|
|
@@ -2400,8 +2934,8 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
2400
2934
|
}
|
|
2401
2935
|
|
|
2402
2936
|
// src/ast/micro-vm.ts
|
|
2403
|
-
var
|
|
2404
|
-
var
|
|
2937
|
+
var acorn5 = __toESM(require("acorn"), 1);
|
|
2938
|
+
var walk6 = __toESM(require("acorn-walk"), 1);
|
|
2405
2939
|
var OP_LDC = 0;
|
|
2406
2940
|
var OP_LDV = 1;
|
|
2407
2941
|
var OP_STV = 2;
|
|
@@ -2506,14 +3040,14 @@ function createInterpreterSource(vmHelperName, opMap) {
|
|
|
2506
3040
|
}
|
|
2507
3041
|
function countAstNodes(node) {
|
|
2508
3042
|
let count = 0;
|
|
2509
|
-
|
|
3043
|
+
walk6.full(node, () => {
|
|
2510
3044
|
count++;
|
|
2511
3045
|
});
|
|
2512
3046
|
return count;
|
|
2513
3047
|
}
|
|
2514
3048
|
function hasForbiddenConstructs(fnNode) {
|
|
2515
3049
|
let forbidden = false;
|
|
2516
|
-
|
|
3050
|
+
walk6.full(fnNode, (node) => {
|
|
2517
3051
|
if (forbidden) return;
|
|
2518
3052
|
const type = node.type;
|
|
2519
3053
|
if (type === "JSXElement" || type === "JSXFragment" || type === "Super" || type === "YieldExpression") {
|
|
@@ -2822,469 +3356,129 @@ function compileFunctionToBytecode(fnNode, opMap) {
|
|
|
2822
3356
|
} else {
|
|
2823
3357
|
if (!compileExpr(fnNode.body)) return null;
|
|
2824
3358
|
emit(OP_RET);
|
|
2825
|
-
}
|
|
2826
|
-
const undefIdx = addConst(void 0);
|
|
2827
|
-
emit(OP_LDC, undefIdx);
|
|
2828
|
-
emit(OP_RET);
|
|
2829
|
-
return { bytecode, consts, localCount };
|
|
2830
|
-
}
|
|
2831
|
-
function isMicroVmAlreadyInjected(ast) {
|
|
2832
|
-
if (!ast || !Array.isArray(ast.body)) return false;
|
|
2833
|
-
return ast.body.some((stmt) => {
|
|
2834
|
-
if (stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")) {
|
|
2835
|
-
return true;
|
|
2836
|
-
}
|
|
2837
|
-
return false;
|
|
2838
|
-
});
|
|
2839
|
-
}
|
|
2840
|
-
function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 2654435769) {
|
|
2841
|
-
const suffix = computeFnv1aHash(`micro-vm:${seed}`, seed).toString(36);
|
|
2842
|
-
const vmHelperName = `_uVm${suffix}`;
|
|
2843
|
-
if (isMicroVmAlreadyInjected(ast)) {
|
|
2844
|
-
const existing = ast.body.find(
|
|
2845
|
-
(stmt) => stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")
|
|
2846
|
-
);
|
|
2847
|
-
return {
|
|
2848
|
-
virtualizedCount: 0,
|
|
2849
|
-
vmHelperName: existing?.id?.name ?? vmHelperName
|
|
2850
|
-
};
|
|
2851
|
-
}
|
|
2852
|
-
const opMap = generateOpcodeMap(seed);
|
|
2853
|
-
const candidates = [];
|
|
2854
|
-
walk5.simple(ast, {
|
|
2855
|
-
FunctionDeclaration(node) {
|
|
2856
|
-
candidates.push(node);
|
|
2857
|
-
},
|
|
2858
|
-
FunctionExpression(node) {
|
|
2859
|
-
candidates.push(node);
|
|
2860
|
-
},
|
|
2861
|
-
ArrowFunctionExpression(node) {
|
|
2862
|
-
candidates.push(node);
|
|
2863
|
-
}
|
|
2864
|
-
});
|
|
2865
|
-
let virtualizedCount = 0;
|
|
2866
|
-
for (const fn of candidates) {
|
|
2867
|
-
if (virtualizedCount >= 10) break;
|
|
2868
|
-
if (coldFunctionNodes && !coldFunctionNodes.has(fn)) {
|
|
2869
|
-
continue;
|
|
2870
|
-
}
|
|
2871
|
-
if (serializedFunctionNodes && serializedFunctionNodes.has(fn)) {
|
|
2872
|
-
continue;
|
|
2873
|
-
}
|
|
2874
|
-
if (fn.generator) {
|
|
2875
|
-
continue;
|
|
2876
|
-
}
|
|
2877
|
-
if (hasForbiddenConstructs(fn)) {
|
|
2878
|
-
continue;
|
|
2879
|
-
}
|
|
2880
|
-
const nodeCount = countAstNodes(fn);
|
|
2881
|
-
if (nodeCount < 15 || nodeCount > 80) {
|
|
2882
|
-
continue;
|
|
2883
|
-
}
|
|
2884
|
-
const compiled = compileFunctionToBytecode(fn, opMap);
|
|
2885
|
-
if (!compiled) {
|
|
2886
|
-
continue;
|
|
2887
|
-
}
|
|
2888
|
-
const paramArgs = fn.params.map((p) => ({
|
|
2889
|
-
type: "Identifier",
|
|
2890
|
-
name: p.name
|
|
2891
|
-
}));
|
|
2892
|
-
const callExpr = {
|
|
2893
|
-
type: "CallExpression",
|
|
2894
|
-
callee: {
|
|
2895
|
-
type: "Identifier",
|
|
2896
|
-
name: vmHelperName
|
|
2897
|
-
},
|
|
2898
|
-
arguments: [
|
|
2899
|
-
{
|
|
2900
|
-
type: "ArrayExpression",
|
|
2901
|
-
elements: compiled.bytecode.map((b) => ({
|
|
2902
|
-
type: "Literal",
|
|
2903
|
-
value: b,
|
|
2904
|
-
raw: String(b)
|
|
2905
|
-
}))
|
|
2906
|
-
},
|
|
2907
|
-
{
|
|
2908
|
-
type: "ArrayExpression",
|
|
2909
|
-
elements: compiled.consts.map((c) => ({
|
|
2910
|
-
type: "Literal",
|
|
2911
|
-
value: c,
|
|
2912
|
-
raw: c === void 0 ? "void 0" : JSON.stringify(c)
|
|
2913
|
-
}))
|
|
2914
|
-
},
|
|
2915
|
-
{
|
|
2916
|
-
type: "ArrayExpression",
|
|
2917
|
-
elements: paramArgs
|
|
2918
|
-
},
|
|
2919
|
-
{
|
|
2920
|
-
type: "ThisExpression"
|
|
2921
|
-
}
|
|
2922
|
-
],
|
|
2923
|
-
optional: false
|
|
2924
|
-
};
|
|
2925
|
-
if (fn.body.type === "BlockStatement") {
|
|
2926
|
-
fn.body.body = [
|
|
2927
|
-
{
|
|
2928
|
-
type: "ReturnStatement",
|
|
2929
|
-
argument: callExpr
|
|
2930
|
-
}
|
|
2931
|
-
];
|
|
2932
|
-
} else {
|
|
2933
|
-
fn.body = callExpr;
|
|
2934
|
-
}
|
|
2935
|
-
virtualizedCount++;
|
|
2936
|
-
}
|
|
2937
|
-
if (virtualizedCount > 0) {
|
|
2938
|
-
const interpreterSource = createInterpreterSource(vmHelperName, opMap);
|
|
2939
|
-
const parsedHelper = acorn3.parse(interpreterSource, {
|
|
2940
|
-
ecmaVersion: "latest",
|
|
2941
|
-
sourceType: "script"
|
|
2942
|
-
});
|
|
2943
|
-
ast.body.unshift(...parsedHelper.body);
|
|
2944
|
-
}
|
|
2945
|
-
return {
|
|
2946
|
-
virtualizedCount,
|
|
2947
|
-
vmHelperName
|
|
2948
|
-
};
|
|
2949
|
-
}
|
|
2950
|
-
|
|
2951
|
-
// src/ast/wasm-vault.ts
|
|
2952
|
-
var acorn4 = __toESM(require("acorn"), 1);
|
|
2953
|
-
function encodeSignedLeb128(value) {
|
|
2954
|
-
const bytes = [];
|
|
2955
|
-
let val = value | 0;
|
|
2956
|
-
let more = true;
|
|
2957
|
-
while (more) {
|
|
2958
|
-
let byte = val & 127;
|
|
2959
|
-
val >>= 7;
|
|
2960
|
-
if (val === 0 && (byte & 64) === 0 || val === -1 && (byte & 64) !== 0) {
|
|
2961
|
-
more = false;
|
|
2962
|
-
} else {
|
|
2963
|
-
byte |= 128;
|
|
2964
|
-
}
|
|
2965
|
-
bytes.push(byte);
|
|
2966
|
-
}
|
|
2967
|
-
return bytes;
|
|
2968
|
-
}
|
|
2969
|
-
function encodeUnsignedLeb128(value) {
|
|
2970
|
-
const bytes = [];
|
|
2971
|
-
let val = value >>> 0;
|
|
2972
|
-
do {
|
|
2973
|
-
let byte = val & 127;
|
|
2974
|
-
val >>>= 7;
|
|
2975
|
-
if (val !== 0) {
|
|
2976
|
-
byte |= 128;
|
|
2977
|
-
}
|
|
2978
|
-
bytes.push(byte);
|
|
2979
|
-
} while (val !== 0);
|
|
2980
|
-
return bytes;
|
|
2981
|
-
}
|
|
2982
|
-
function generateWasmKdfBinary(seed) {
|
|
2983
|
-
const instructions = [
|
|
2984
|
-
32,
|
|
2985
|
-
0,
|
|
2986
|
-
// local.get 0
|
|
2987
|
-
65,
|
|
2988
|
-
...encodeSignedLeb128(seed),
|
|
2989
|
-
// i32.const seed
|
|
2990
|
-
115,
|
|
2991
|
-
// i32.xor
|
|
2992
|
-
65,
|
|
2993
|
-
...encodeSignedLeb128(16777619),
|
|
2994
|
-
// i32.const 0x01000193
|
|
2995
|
-
108,
|
|
2996
|
-
// i32.mul
|
|
2997
|
-
32,
|
|
2998
|
-
1,
|
|
2999
|
-
// local.get 1
|
|
3000
|
-
32,
|
|
3001
|
-
2,
|
|
3002
|
-
// local.get 2
|
|
3003
|
-
106,
|
|
3004
|
-
// i32.add
|
|
3005
|
-
65,
|
|
3006
|
-
...encodeSignedLeb128(73244475),
|
|
3007
|
-
// i32.const 0x45d9f3b
|
|
3008
|
-
108,
|
|
3009
|
-
// i32.mul
|
|
3010
|
-
115,
|
|
3011
|
-
// i32.xor
|
|
3012
|
-
11
|
|
3013
|
-
// end
|
|
3014
|
-
];
|
|
3015
|
-
const funcBody = [0, ...instructions];
|
|
3016
|
-
const funcBodyWithLen = [...encodeUnsignedLeb128(funcBody.length), ...funcBody];
|
|
3017
|
-
const codeSectionPayload = [1, ...funcBodyWithLen];
|
|
3018
|
-
const codeSection = [
|
|
3019
|
-
10,
|
|
3020
|
-
...encodeUnsignedLeb128(codeSectionPayload.length),
|
|
3021
|
-
...codeSectionPayload
|
|
3022
|
-
];
|
|
3023
|
-
const typePayload = [
|
|
3024
|
-
1,
|
|
3025
|
-
// 1 type
|
|
3026
|
-
96,
|
|
3027
|
-
// func
|
|
3028
|
-
3,
|
|
3029
|
-
127,
|
|
3030
|
-
127,
|
|
3031
|
-
127,
|
|
3032
|
-
// 3 params of type i32
|
|
3033
|
-
1,
|
|
3034
|
-
127
|
|
3035
|
-
// 1 result of type i32
|
|
3036
|
-
];
|
|
3037
|
-
const typeSection = [
|
|
3038
|
-
1,
|
|
3039
|
-
...encodeUnsignedLeb128(typePayload.length),
|
|
3040
|
-
...typePayload
|
|
3041
|
-
];
|
|
3042
|
-
const funcPayload = [
|
|
3043
|
-
1,
|
|
3044
|
-
// 1 function
|
|
3045
|
-
0
|
|
3046
|
-
// type index 0
|
|
3047
|
-
];
|
|
3048
|
-
const funcSection = [
|
|
3049
|
-
3,
|
|
3050
|
-
...encodeUnsignedLeb128(funcPayload.length),
|
|
3051
|
-
...funcPayload
|
|
3052
|
-
];
|
|
3053
|
-
const exportName = [3, 107, 100, 102];
|
|
3054
|
-
const exportPayload = [
|
|
3055
|
-
1,
|
|
3056
|
-
// 1 export
|
|
3057
|
-
...exportName,
|
|
3058
|
-
0,
|
|
3059
|
-
// function export
|
|
3060
|
-
0
|
|
3061
|
-
// function index 0
|
|
3062
|
-
];
|
|
3063
|
-
const exportSection = [
|
|
3064
|
-
7,
|
|
3065
|
-
...encodeUnsignedLeb128(exportPayload.length),
|
|
3066
|
-
...exportPayload
|
|
3067
|
-
];
|
|
3068
|
-
const header = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
3069
|
-
return new Uint8Array([
|
|
3070
|
-
...header,
|
|
3071
|
-
...typeSection,
|
|
3072
|
-
...funcSection,
|
|
3073
|
-
...exportSection,
|
|
3074
|
-
...codeSection
|
|
3075
|
-
]);
|
|
3076
|
-
}
|
|
3077
|
-
function fallbackKdf(fnId, callSiteSalt, shieldHash, seed) {
|
|
3078
|
-
return Math.imul(fnId ^ seed | 0, 16777619) ^ Math.imul(callSiteSalt + shieldHash | 0, 73244475) | 0;
|
|
3359
|
+
}
|
|
3360
|
+
const undefIdx = addConst(void 0);
|
|
3361
|
+
emit(OP_LDC, undefIdx);
|
|
3362
|
+
emit(OP_RET);
|
|
3363
|
+
return { bytecode, consts, localCount };
|
|
3079
3364
|
}
|
|
3080
|
-
function
|
|
3365
|
+
function isMicroVmAlreadyInjected(ast) {
|
|
3081
3366
|
if (!ast || !Array.isArray(ast.body)) return false;
|
|
3082
3367
|
return ast.body.some((stmt) => {
|
|
3083
|
-
if (stmt.type === "
|
|
3084
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
3085
|
-
)) {
|
|
3368
|
+
if (stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")) {
|
|
3086
3369
|
return true;
|
|
3087
3370
|
}
|
|
3088
3371
|
return false;
|
|
3089
3372
|
});
|
|
3090
3373
|
}
|
|
3091
|
-
function
|
|
3092
|
-
const suffix = computeFnv1aHash(`
|
|
3093
|
-
const
|
|
3094
|
-
|
|
3095
|
-
if (isWasmVaultAlreadyInjected(ast)) {
|
|
3374
|
+
function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 2654435769) {
|
|
3375
|
+
const suffix = computeFnv1aHash(`micro-vm:${seed}`, seed).toString(36);
|
|
3376
|
+
const vmHelperName = `_uVm${suffix}`;
|
|
3377
|
+
if (isMicroVmAlreadyInjected(ast)) {
|
|
3096
3378
|
const existing = ast.body.find(
|
|
3097
|
-
(stmt) => stmt.type === "
|
|
3098
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
3099
|
-
)
|
|
3379
|
+
(stmt) => stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")
|
|
3100
3380
|
);
|
|
3101
|
-
const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
|
|
3102
3381
|
return {
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
wasmVarName
|
|
3382
|
+
virtualizedCount: 0,
|
|
3383
|
+
vmHelperName: existing?.id?.name ?? vmHelperName
|
|
3106
3384
|
};
|
|
3107
3385
|
}
|
|
3108
|
-
const
|
|
3109
|
-
const
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
}
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
};
|
|
3120
|
-
}`;
|
|
3121
|
-
const parsedHelper = acorn4.parse(helperSnippet, {
|
|
3122
|
-
ecmaVersion: "latest",
|
|
3123
|
-
sourceType: "script"
|
|
3124
|
-
});
|
|
3125
|
-
ast.body.unshift(...parsedHelper.body);
|
|
3126
|
-
return {
|
|
3127
|
-
kdfFnName,
|
|
3128
|
-
wasmBytes,
|
|
3129
|
-
wasmVarName
|
|
3130
|
-
};
|
|
3131
|
-
}
|
|
3132
|
-
|
|
3133
|
-
// src/ast/salted-vault.ts
|
|
3134
|
-
var acorn5 = __toESM(require("acorn"), 1);
|
|
3135
|
-
var walk6 = __toESM(require("acorn-walk"), 1);
|
|
3136
|
-
var DIRECTIVE_STRINGS2 = /* @__PURE__ */ new Set([
|
|
3137
|
-
"use strict",
|
|
3138
|
-
"use client",
|
|
3139
|
-
"use server",
|
|
3140
|
-
"use asm"
|
|
3141
|
-
]);
|
|
3142
|
-
function encodeSaltedString(str, k) {
|
|
3143
|
-
let out = "";
|
|
3144
|
-
for (let j = 0; j < str.length; j++) {
|
|
3145
|
-
const code = str.charCodeAt(j);
|
|
3146
|
-
const mask = k >>> j % 24 & 127 | 1;
|
|
3147
|
-
out += String.fromCharCode(code ^ mask);
|
|
3148
|
-
}
|
|
3149
|
-
return out;
|
|
3150
|
-
}
|
|
3151
|
-
function isAstAlreadySalted(ast) {
|
|
3152
|
-
if (!ast || !Array.isArray(ast.body)) return false;
|
|
3153
|
-
return ast.body.some((stmt) => {
|
|
3154
|
-
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
3155
|
-
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uP")
|
|
3156
|
-
)) {
|
|
3157
|
-
return true;
|
|
3386
|
+
const opMap = generateOpcodeMap(seed);
|
|
3387
|
+
const candidates = [];
|
|
3388
|
+
walk6.simple(ast, {
|
|
3389
|
+
FunctionDeclaration(node) {
|
|
3390
|
+
candidates.push(node);
|
|
3391
|
+
},
|
|
3392
|
+
FunctionExpression(node) {
|
|
3393
|
+
candidates.push(node);
|
|
3394
|
+
},
|
|
3395
|
+
ArrowFunctionExpression(node) {
|
|
3396
|
+
candidates.push(node);
|
|
3158
3397
|
}
|
|
3159
|
-
return false;
|
|
3160
3398
|
});
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
if (val === oldNode) {
|
|
3167
|
-
parent[key] = newNode;
|
|
3168
|
-
return true;
|
|
3399
|
+
let virtualizedCount = 0;
|
|
3400
|
+
for (const fn of candidates) {
|
|
3401
|
+
if (virtualizedCount >= 5) break;
|
|
3402
|
+
if (coldFunctionNodes && !coldFunctionNodes.has(fn)) {
|
|
3403
|
+
continue;
|
|
3169
3404
|
}
|
|
3170
|
-
if (
|
|
3171
|
-
|
|
3172
|
-
if (idx !== -1) {
|
|
3173
|
-
val[idx] = newNode;
|
|
3174
|
-
return true;
|
|
3175
|
-
}
|
|
3405
|
+
if (serializedFunctionNodes && serializedFunctionNodes.has(fn)) {
|
|
3406
|
+
continue;
|
|
3176
3407
|
}
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
}
|
|
3180
|
-
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes) {
|
|
3181
|
-
if (isAstAlreadySalted(ast)) {
|
|
3182
|
-
return {
|
|
3183
|
-
encryptedStringsCount: 0,
|
|
3184
|
-
integrityToken: computeFnv1aHash("already-salted", seed),
|
|
3185
|
-
vaultVarName: "",
|
|
3186
|
-
decryptFnName: ""
|
|
3187
|
-
};
|
|
3188
|
-
}
|
|
3189
|
-
const targetsToReplace = [];
|
|
3190
|
-
const encryptedPayloads = [];
|
|
3191
|
-
walk6.ancestor(ast, {
|
|
3192
|
-
Literal(node, ancestors) {
|
|
3193
|
-
if (typeof node.value !== "string") return;
|
|
3194
|
-
if (node.value.length < minStringLength) return;
|
|
3195
|
-
if (DIRECTIVE_STRINGS2.has(node.value)) return;
|
|
3196
|
-
const parent = ancestors[ancestors.length - 2];
|
|
3197
|
-
if (!parent) return;
|
|
3198
|
-
if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration") && parent.source === node) {
|
|
3199
|
-
return;
|
|
3200
|
-
}
|
|
3201
|
-
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
3202
|
-
return;
|
|
3203
|
-
}
|
|
3204
|
-
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
3205
|
-
return;
|
|
3206
|
-
}
|
|
3207
|
-
if (hotExemptNodes) {
|
|
3208
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
3209
|
-
if (hotExemptNodes.has(ancestors[i])) {
|
|
3210
|
-
return;
|
|
3211
|
-
}
|
|
3212
|
-
}
|
|
3213
|
-
}
|
|
3214
|
-
const callSiteIdx = targetsToReplace.length;
|
|
3215
|
-
const localSalt = computeFnv1aHash(`salt:${seed}:${callSiteIdx}`, seed) & 2147483647 | 1;
|
|
3216
|
-
targetsToReplace.push({
|
|
3217
|
-
node,
|
|
3218
|
-
parent,
|
|
3219
|
-
callSiteIdx,
|
|
3220
|
-
localSalt,
|
|
3221
|
-
rawString: node.value
|
|
3222
|
-
});
|
|
3408
|
+
if (fn.generator) {
|
|
3409
|
+
continue;
|
|
3223
3410
|
}
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
for (const target of targetsToReplace) {
|
|
3240
|
-
const k = fallbackKdf(target.callSiteIdx, target.localSalt, 0, seed);
|
|
3241
|
-
encryptedPayloads.push(encodeSaltedString(target.rawString, k));
|
|
3411
|
+
if (hasForbiddenConstructs(fn)) {
|
|
3412
|
+
continue;
|
|
3413
|
+
}
|
|
3414
|
+
const nodeCount = countAstNodes(fn);
|
|
3415
|
+
if (nodeCount < 15 || nodeCount > 80) {
|
|
3416
|
+
continue;
|
|
3417
|
+
}
|
|
3418
|
+
const compiled = compileFunctionToBytecode(fn, opMap);
|
|
3419
|
+
if (!compiled) {
|
|
3420
|
+
continue;
|
|
3421
|
+
}
|
|
3422
|
+
const paramArgs = fn.params.map((p) => ({
|
|
3423
|
+
type: "Identifier",
|
|
3424
|
+
name: p.name
|
|
3425
|
+
}));
|
|
3242
3426
|
const callExpr = {
|
|
3243
3427
|
type: "CallExpression",
|
|
3244
3428
|
callee: {
|
|
3245
3429
|
type: "Identifier",
|
|
3246
|
-
name:
|
|
3430
|
+
name: vmHelperName
|
|
3247
3431
|
},
|
|
3248
3432
|
arguments: [
|
|
3249
3433
|
{
|
|
3250
|
-
type: "
|
|
3251
|
-
|
|
3252
|
-
|
|
3434
|
+
type: "ArrayExpression",
|
|
3435
|
+
elements: compiled.bytecode.map((b) => ({
|
|
3436
|
+
type: "Literal",
|
|
3437
|
+
value: b,
|
|
3438
|
+
raw: String(b)
|
|
3439
|
+
}))
|
|
3253
3440
|
},
|
|
3254
3441
|
{
|
|
3255
|
-
type: "
|
|
3256
|
-
|
|
3257
|
-
|
|
3442
|
+
type: "ArrayExpression",
|
|
3443
|
+
elements: compiled.consts.map((c) => ({
|
|
3444
|
+
type: "Literal",
|
|
3445
|
+
value: c,
|
|
3446
|
+
raw: c === void 0 ? "void 0" : JSON.stringify(c)
|
|
3447
|
+
}))
|
|
3448
|
+
},
|
|
3449
|
+
{
|
|
3450
|
+
type: "ArrayExpression",
|
|
3451
|
+
elements: paramArgs
|
|
3452
|
+
},
|
|
3453
|
+
{
|
|
3454
|
+
type: "ThisExpression"
|
|
3258
3455
|
}
|
|
3259
3456
|
],
|
|
3260
3457
|
optional: false
|
|
3261
3458
|
};
|
|
3262
|
-
|
|
3459
|
+
if (fn.body.type === "BlockStatement") {
|
|
3460
|
+
fn.body.body = [
|
|
3461
|
+
{
|
|
3462
|
+
type: "ReturnStatement",
|
|
3463
|
+
argument: callExpr
|
|
3464
|
+
}
|
|
3465
|
+
];
|
|
3466
|
+
} else {
|
|
3467
|
+
fn.body = callExpr;
|
|
3468
|
+
}
|
|
3469
|
+
virtualizedCount++;
|
|
3263
3470
|
}
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
var k = ${kdfFnName}(i, s, d);
|
|
3272
|
-
var p = ${vaultVarName}[i], o = '';
|
|
3273
|
-
for (var j = 0; j < p.length; j++) {
|
|
3274
|
-
o += String.fromCharCode(p.charCodeAt(j) ^ (((k >>> (j % 24)) & 127) | 1));
|
|
3471
|
+
if (virtualizedCount > 0) {
|
|
3472
|
+
const interpreterSource = createInterpreterSource(vmHelperName, opMap);
|
|
3473
|
+
const parsedHelper = acorn5.parse(interpreterSource, {
|
|
3474
|
+
ecmaVersion: "latest",
|
|
3475
|
+
sourceType: "script"
|
|
3476
|
+
});
|
|
3477
|
+
ast.body.unshift(...parsedHelper.body);
|
|
3275
3478
|
}
|
|
3276
|
-
return (${cacheVarName}[i] = o);
|
|
3277
|
-
}`;
|
|
3278
|
-
const parsedHelper = acorn5.parse(helperSnippet, {
|
|
3279
|
-
ecmaVersion: "latest",
|
|
3280
|
-
sourceType: "script"
|
|
3281
|
-
});
|
|
3282
|
-
ast.body.unshift(...parsedHelper.body);
|
|
3283
3479
|
return {
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
vaultVarName,
|
|
3287
|
-
decryptFnName
|
|
3480
|
+
virtualizedCount,
|
|
3481
|
+
vmHelperName
|
|
3288
3482
|
};
|
|
3289
3483
|
}
|
|
3290
3484
|
|
|
@@ -3390,7 +3584,10 @@ function transformJavaScript(code, options = {}) {
|
|
|
3390
3584
|
ast,
|
|
3391
3585
|
seed,
|
|
3392
3586
|
minStringLength,
|
|
3393
|
-
hotExemptNodes
|
|
3587
|
+
hotExemptNodes,
|
|
3588
|
+
void 0,
|
|
3589
|
+
void 0,
|
|
3590
|
+
options.deterrentMode
|
|
3394
3591
|
);
|
|
3395
3592
|
encryptedStringsCount = vaultRes.encryptedStringsCount;
|
|
3396
3593
|
integrityToken = vaultRes.integrityToken;
|
|
@@ -3401,7 +3598,7 @@ function transformJavaScript(code, options = {}) {
|
|
|
3401
3598
|
if (options.injectRuntimeShield) {
|
|
3402
3599
|
const shield = generateRuntimeShield({
|
|
3403
3600
|
seed,
|
|
3404
|
-
deterrentMode: options.deterrentMode ?? "
|
|
3601
|
+
deterrentMode: options.deterrentMode ?? "passive",
|
|
3405
3602
|
expectedIntegrityHash: integrityToken
|
|
3406
3603
|
});
|
|
3407
3604
|
if (shield.preambleCode) {
|