unpeek 1.8.2 → 1.10.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 +866 -701
- 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 +866 -701
- package/dist/ast/index.js.map +1 -1
- package/dist/browser.cjs +866 -701
- 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 +866 -701
- 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 +867 -702
- package/dist/bundler/unplugin.cjs.map +1 -1
- package/dist/bundler/unplugin.js +867 -702
- package/dist/bundler/unplugin.js.map +1 -1
- package/dist/cli/index.cjs +907 -711
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +907 -711
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/protect.cjs +893 -709
- package/dist/cli/protect.cjs.map +1 -1
- package/dist/cli/protect.js +893 -709
- package/dist/cli/protect.js.map +1 -1
- package/dist/esbuild.cjs +867 -702
- 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 +867 -702
- package/dist/esbuild.js.map +1 -1
- package/dist/index.cjs +2137 -1941
- 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 +2137 -1941
- package/dist/index.js.map +1 -1
- package/dist/rollup.cjs +867 -702
- 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 +867 -702
- 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 +867 -702
- 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 +867 -702
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +867 -702
- 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 +867 -702
- package/dist/webpack.js.map +1 -1
- package/package.json +1 -1
package/dist/ast/index.cjs
CHANGED
|
@@ -260,6 +260,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
260
260
|
return cur;
|
|
261
261
|
}
|
|
262
262
|
function markSerializedFunction(node) {
|
|
263
|
+
node._unpeekSerialized = true;
|
|
263
264
|
serializedWorkerNodes.add(node);
|
|
264
265
|
serializedFunctionNodes.add(node);
|
|
265
266
|
hotFunctionNodes.add(node);
|
|
@@ -321,6 +322,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
321
322
|
shallowComponentNodes.add(node);
|
|
322
323
|
hotFunctionNodes.add(node);
|
|
323
324
|
directHotNodes.add(node);
|
|
325
|
+
hotExemptNodes.add(node);
|
|
324
326
|
}
|
|
325
327
|
if (isZeroArgIifeFactoryFunction(node)) {
|
|
326
328
|
markSerializedFunction(node);
|
|
@@ -553,6 +555,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
553
555
|
shallowComponentNodes.add(enclosingFn);
|
|
554
556
|
hotFunctionNodes.add(enclosingFn);
|
|
555
557
|
directHotNodes.add(enclosingFn);
|
|
558
|
+
hotExemptNodes.add(enclosingFn);
|
|
556
559
|
}
|
|
557
560
|
}
|
|
558
561
|
},
|
|
@@ -634,6 +637,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
634
637
|
if (anc === fn.node) continue;
|
|
635
638
|
if (serializedWorkerNodes.has(anc)) {
|
|
636
639
|
if (!serializedWorkerNodes.has(fn.node)) {
|
|
640
|
+
fn.node._unpeekSerialized = true;
|
|
637
641
|
serializedWorkerNodes.add(fn.node);
|
|
638
642
|
serializedFunctionNodes.add(fn.node);
|
|
639
643
|
hotFunctionNodes.add(fn.node);
|
|
@@ -660,6 +664,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
660
664
|
for (const cName of calleeNames) {
|
|
661
665
|
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
662
666
|
if (targetNode && !serializedWorkerNodes.has(targetNode) && !coldForcedNodes.has(targetNode)) {
|
|
667
|
+
targetNode._unpeekSerialized = true;
|
|
663
668
|
serializedWorkerNodes.add(targetNode);
|
|
664
669
|
serializedFunctionNodes.add(targetNode);
|
|
665
670
|
hotFunctionNodes.add(targetNode);
|
|
@@ -758,8 +763,8 @@ function detectHotPaths(code) {
|
|
|
758
763
|
}
|
|
759
764
|
|
|
760
765
|
// src/ast/string-vault.ts
|
|
761
|
-
var
|
|
762
|
-
var
|
|
766
|
+
var acorn4 = __toESM(require("acorn"), 1);
|
|
767
|
+
var walk3 = __toESM(require("acorn-walk"), 1);
|
|
763
768
|
|
|
764
769
|
// src/ast/codegen.ts
|
|
765
770
|
var import_astring = require("astring");
|
|
@@ -1159,108 +1164,234 @@ function generateRuntimeShield(config) {
|
|
|
1159
1164
|
};
|
|
1160
1165
|
}
|
|
1161
1166
|
|
|
1162
|
-
// src/ast/
|
|
1163
|
-
var
|
|
1167
|
+
// src/ast/salted-vault.ts
|
|
1168
|
+
var acorn3 = __toESM(require("acorn"), 1);
|
|
1169
|
+
var walk2 = __toESM(require("acorn-walk"), 1);
|
|
1170
|
+
|
|
1171
|
+
// src/ast/wasm-vault.ts
|
|
1172
|
+
var acorn2 = __toESM(require("acorn"), 1);
|
|
1173
|
+
function encodeSignedLeb128(value) {
|
|
1174
|
+
const bytes = [];
|
|
1175
|
+
let val = value | 0;
|
|
1176
|
+
let more = true;
|
|
1177
|
+
while (more) {
|
|
1178
|
+
let byte = val & 127;
|
|
1179
|
+
val >>= 7;
|
|
1180
|
+
if (val === 0 && (byte & 64) === 0 || val === -1 && (byte & 64) !== 0) {
|
|
1181
|
+
more = false;
|
|
1182
|
+
} else {
|
|
1183
|
+
byte |= 128;
|
|
1184
|
+
}
|
|
1185
|
+
bytes.push(byte);
|
|
1186
|
+
}
|
|
1187
|
+
return bytes;
|
|
1188
|
+
}
|
|
1189
|
+
function encodeUnsignedLeb128(value) {
|
|
1190
|
+
const bytes = [];
|
|
1191
|
+
let val = value >>> 0;
|
|
1192
|
+
do {
|
|
1193
|
+
let byte = val & 127;
|
|
1194
|
+
val >>>= 7;
|
|
1195
|
+
if (val !== 0) {
|
|
1196
|
+
byte |= 128;
|
|
1197
|
+
}
|
|
1198
|
+
bytes.push(byte);
|
|
1199
|
+
} while (val !== 0);
|
|
1200
|
+
return bytes;
|
|
1201
|
+
}
|
|
1202
|
+
function generateWasmKdfBinary(seed) {
|
|
1203
|
+
const instructions = [
|
|
1204
|
+
32,
|
|
1205
|
+
0,
|
|
1206
|
+
// local.get 0
|
|
1207
|
+
65,
|
|
1208
|
+
...encodeSignedLeb128(seed),
|
|
1209
|
+
// i32.const seed
|
|
1210
|
+
115,
|
|
1211
|
+
// i32.xor
|
|
1212
|
+
65,
|
|
1213
|
+
...encodeSignedLeb128(16777619),
|
|
1214
|
+
// i32.const 0x01000193
|
|
1215
|
+
108,
|
|
1216
|
+
// i32.mul
|
|
1217
|
+
32,
|
|
1218
|
+
1,
|
|
1219
|
+
// local.get 1
|
|
1220
|
+
32,
|
|
1221
|
+
2,
|
|
1222
|
+
// local.get 2
|
|
1223
|
+
106,
|
|
1224
|
+
// i32.add
|
|
1225
|
+
65,
|
|
1226
|
+
...encodeSignedLeb128(73244475),
|
|
1227
|
+
// i32.const 0x45d9f3b
|
|
1228
|
+
108,
|
|
1229
|
+
// i32.mul
|
|
1230
|
+
115,
|
|
1231
|
+
// i32.xor
|
|
1232
|
+
11
|
|
1233
|
+
// end
|
|
1234
|
+
];
|
|
1235
|
+
const funcBody = [0, ...instructions];
|
|
1236
|
+
const funcBodyWithLen = [...encodeUnsignedLeb128(funcBody.length), ...funcBody];
|
|
1237
|
+
const codeSectionPayload = [1, ...funcBodyWithLen];
|
|
1238
|
+
const codeSection = [
|
|
1239
|
+
10,
|
|
1240
|
+
...encodeUnsignedLeb128(codeSectionPayload.length),
|
|
1241
|
+
...codeSectionPayload
|
|
1242
|
+
];
|
|
1243
|
+
const typePayload = [
|
|
1244
|
+
1,
|
|
1245
|
+
// 1 type
|
|
1246
|
+
96,
|
|
1247
|
+
// func
|
|
1248
|
+
3,
|
|
1249
|
+
127,
|
|
1250
|
+
127,
|
|
1251
|
+
127,
|
|
1252
|
+
// 3 params of type i32
|
|
1253
|
+
1,
|
|
1254
|
+
127
|
|
1255
|
+
// 1 result of type i32
|
|
1256
|
+
];
|
|
1257
|
+
const typeSection = [
|
|
1258
|
+
1,
|
|
1259
|
+
...encodeUnsignedLeb128(typePayload.length),
|
|
1260
|
+
...typePayload
|
|
1261
|
+
];
|
|
1262
|
+
const funcPayload = [
|
|
1263
|
+
1,
|
|
1264
|
+
// 1 function
|
|
1265
|
+
0
|
|
1266
|
+
// type index 0
|
|
1267
|
+
];
|
|
1268
|
+
const funcSection = [
|
|
1269
|
+
3,
|
|
1270
|
+
...encodeUnsignedLeb128(funcPayload.length),
|
|
1271
|
+
...funcPayload
|
|
1272
|
+
];
|
|
1273
|
+
const exportName = [3, 107, 100, 102];
|
|
1274
|
+
const exportPayload = [
|
|
1275
|
+
1,
|
|
1276
|
+
// 1 export
|
|
1277
|
+
...exportName,
|
|
1278
|
+
0,
|
|
1279
|
+
// function export
|
|
1280
|
+
0
|
|
1281
|
+
// function index 0
|
|
1282
|
+
];
|
|
1283
|
+
const exportSection = [
|
|
1284
|
+
7,
|
|
1285
|
+
...encodeUnsignedLeb128(exportPayload.length),
|
|
1286
|
+
...exportPayload
|
|
1287
|
+
];
|
|
1288
|
+
const header = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
1289
|
+
return new Uint8Array([
|
|
1290
|
+
...header,
|
|
1291
|
+
...typeSection,
|
|
1292
|
+
...funcSection,
|
|
1293
|
+
...exportSection,
|
|
1294
|
+
...codeSection
|
|
1295
|
+
]);
|
|
1296
|
+
}
|
|
1297
|
+
function fallbackKdf(fnId, callSiteSalt, shieldHash, seed) {
|
|
1298
|
+
return Math.imul(fnId ^ seed | 0, 16777619) ^ Math.imul(callSiteSalt + shieldHash | 0, 73244475) | 0;
|
|
1299
|
+
}
|
|
1300
|
+
function isWasmVaultAlreadyInjected(ast) {
|
|
1301
|
+
if (!ast || !Array.isArray(ast.body)) return false;
|
|
1302
|
+
return ast.body.some((stmt) => {
|
|
1303
|
+
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1304
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
1305
|
+
)) {
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
return false;
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
function injectWasmVault(ast, seed = 2654435769) {
|
|
1312
|
+
const suffix = computeFnv1aHash(`wasm:${seed}`, seed).toString(36);
|
|
1313
|
+
const kdfFnName = `_wKdf${suffix}`;
|
|
1314
|
+
const wasmVarName = `_wb${suffix}`;
|
|
1315
|
+
if (isWasmVaultAlreadyInjected(ast)) {
|
|
1316
|
+
const existing = ast.body.find(
|
|
1317
|
+
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1318
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
1319
|
+
)
|
|
1320
|
+
);
|
|
1321
|
+
const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
|
|
1322
|
+
return {
|
|
1323
|
+
kdfFnName: id,
|
|
1324
|
+
wasmBytes: generateWasmKdfBinary(seed),
|
|
1325
|
+
wasmVarName
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
const wasmBytes = generateWasmKdfBinary(seed);
|
|
1329
|
+
const byteArrayLiteral = Array.from(wasmBytes).join(",");
|
|
1330
|
+
const sVal = seed | 0;
|
|
1331
|
+
const xorMask = seed ^ 1515870810 | 0;
|
|
1332
|
+
const m1 = 16777619 ^ xorMask | 0;
|
|
1333
|
+
const m2 = 73244475 ^ xorMask | 0;
|
|
1334
|
+
const m3 = sVal ^ xorMask | 0;
|
|
1335
|
+
const strKey = seed & 127 ^ 61 | 0;
|
|
1336
|
+
const mChars = [105 ^ strKey, 109 ^ strKey, 117 ^ strKey, 108 ^ strKey].join(",");
|
|
1337
|
+
const helperSnippet = `var ${kdfFnName};
|
|
1338
|
+
try {
|
|
1339
|
+
var ${wasmVarName} = new Uint8Array([${byteArrayLiteral}]);
|
|
1340
|
+
var _wm${suffix} = new WebAssembly.Module(${wasmVarName});
|
|
1341
|
+
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix});
|
|
1342
|
+
${kdfFnName} = _wi${suffix}.exports.kdf;
|
|
1343
|
+
} catch (e) {
|
|
1344
|
+
${kdfFnName} = (function() {
|
|
1345
|
+
var _k = ${xorMask};
|
|
1346
|
+
var _x = [${m1}, ${m2}, ${m3}];
|
|
1347
|
+
var _p = '';
|
|
1348
|
+
var _c = [${mChars}];
|
|
1349
|
+
for (var _i = 0; _i < _c.length; _i++) {
|
|
1350
|
+
_p += String.fromCharCode(_c[_i] ^ ${strKey});
|
|
1351
|
+
}
|
|
1352
|
+
var _m = Math[_p];
|
|
1353
|
+
return function(f, s, h) {
|
|
1354
|
+
return (_m((f ^ (_x[2] ^ _k)) | 0, _x[0] ^ _k) ^ _m(((s + h) | 0), _x[1] ^ _k)) | 0;
|
|
1355
|
+
};
|
|
1356
|
+
})();
|
|
1357
|
+
}`;
|
|
1358
|
+
const parsedHelper = acorn2.parse(helperSnippet, {
|
|
1359
|
+
ecmaVersion: "latest",
|
|
1360
|
+
sourceType: "script"
|
|
1361
|
+
});
|
|
1362
|
+
ast.body.unshift(...parsedHelper.body);
|
|
1363
|
+
return {
|
|
1364
|
+
kdfFnName,
|
|
1365
|
+
wasmBytes,
|
|
1366
|
+
wasmVarName
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// src/ast/salted-vault.ts
|
|
1164
1371
|
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
1165
1372
|
"use strict",
|
|
1166
1373
|
"use client",
|
|
1167
1374
|
"use server",
|
|
1168
1375
|
"use asm"
|
|
1169
1376
|
]);
|
|
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;
|
|
1377
|
+
function computeCallSiteSalt(seed, idx) {
|
|
1378
|
+
return ((seed & 15 ^ idx * 5 + 3) & 31) >>> 0;
|
|
1203
1379
|
}
|
|
1204
|
-
function
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
}
|
|
1210
|
-
return hash >>> 0;
|
|
1380
|
+
function createSaltedDecryptorFnAst(seed, pChars, expectedDelta, windowKeySymbol, safeAlpha = SAFE_ALPHA) {
|
|
1381
|
+
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);};`;
|
|
1382
|
+
return acorn3.parse(`(function f(a){${fBody}})`, {
|
|
1383
|
+
ecmaVersion: "latest",
|
|
1384
|
+
sourceType: "script"
|
|
1385
|
+
}).body[0].expression;
|
|
1211
1386
|
}
|
|
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) {
|
|
1387
|
+
function createSaltedVaultHelperAst(decryptFnName, encryptedPayloads, fnAst) {
|
|
1257
1388
|
return {
|
|
1258
1389
|
type: "VariableDeclaration",
|
|
1259
1390
|
kind: "var",
|
|
1260
1391
|
declarations: [
|
|
1261
1392
|
{
|
|
1262
1393
|
type: "VariableDeclarator",
|
|
1263
|
-
id: { type: "Identifier", name:
|
|
1394
|
+
id: { type: "Identifier", name: decryptFnName },
|
|
1264
1395
|
init: {
|
|
1265
1396
|
type: "CallExpression",
|
|
1266
1397
|
callee: fnAst,
|
|
@@ -1280,6 +1411,340 @@ function createVaultHelperAst(cacheVarName, encryptedPayloads, fnAst) {
|
|
|
1280
1411
|
]
|
|
1281
1412
|
};
|
|
1282
1413
|
}
|
|
1414
|
+
function encodeSaltedString(str, k) {
|
|
1415
|
+
let out = "";
|
|
1416
|
+
for (let j = 0; j < str.length; j++) {
|
|
1417
|
+
const code = str.charCodeAt(j);
|
|
1418
|
+
const mask = k >>> j % 24 & 127 | 1;
|
|
1419
|
+
out += String.fromCharCode(code ^ mask);
|
|
1420
|
+
}
|
|
1421
|
+
return out;
|
|
1422
|
+
}
|
|
1423
|
+
function isAstAlreadySalted(ast) {
|
|
1424
|
+
if (!ast || !Array.isArray(ast.body)) return false;
|
|
1425
|
+
return ast.body.some((stmt) => {
|
|
1426
|
+
if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
1427
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uP")
|
|
1428
|
+
)) {
|
|
1429
|
+
return true;
|
|
1430
|
+
}
|
|
1431
|
+
return false;
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
function replaceNodeInParent(parent, oldNode, newNode) {
|
|
1435
|
+
if (!parent) return false;
|
|
1436
|
+
for (const key of Object.keys(parent)) {
|
|
1437
|
+
const val = parent[key];
|
|
1438
|
+
if (val === oldNode) {
|
|
1439
|
+
parent[key] = newNode;
|
|
1440
|
+
return true;
|
|
1441
|
+
}
|
|
1442
|
+
if (Array.isArray(val)) {
|
|
1443
|
+
const idx = val.indexOf(oldNode);
|
|
1444
|
+
if (idx !== -1) {
|
|
1445
|
+
val[idx] = newNode;
|
|
1446
|
+
return true;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
return false;
|
|
1451
|
+
}
|
|
1452
|
+
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes) {
|
|
1453
|
+
if (isAstAlreadySalted(ast)) {
|
|
1454
|
+
return {
|
|
1455
|
+
encryptedStringsCount: 0,
|
|
1456
|
+
integrityToken: computeFnv1aHash("already-salted", seed),
|
|
1457
|
+
vaultVarName: "",
|
|
1458
|
+
decryptFnName: ""
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
const targetsToReplace = [];
|
|
1462
|
+
const encryptedPayloads = [];
|
|
1463
|
+
walk2.ancestor(ast, {
|
|
1464
|
+
Literal(node, ancestors) {
|
|
1465
|
+
if (typeof node.value !== "string") return;
|
|
1466
|
+
if (node.value.length < minStringLength) return;
|
|
1467
|
+
if (DIRECTIVE_STRINGS.has(node.value)) return;
|
|
1468
|
+
const parent = ancestors[ancestors.length - 2];
|
|
1469
|
+
if (!parent) return;
|
|
1470
|
+
if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration") && parent.source === node) {
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
if (hotExemptNodes) {
|
|
1480
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
1481
|
+
if (hotExemptNodes.has(ancestors[i])) {
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
const callSiteIdx = targetsToReplace.length;
|
|
1487
|
+
const localSalt = computeFnv1aHash(`salt:${seed}:${callSiteIdx}`, seed) & 2147483647 | 1;
|
|
1488
|
+
targetsToReplace.push({
|
|
1489
|
+
node,
|
|
1490
|
+
parent,
|
|
1491
|
+
callSiteIdx,
|
|
1492
|
+
localSalt,
|
|
1493
|
+
rawString: node.value
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
if (targetsToReplace.length === 0) {
|
|
1498
|
+
return {
|
|
1499
|
+
encryptedStringsCount: 0,
|
|
1500
|
+
integrityToken: computeFnv1aHash("empty-salted", seed),
|
|
1501
|
+
vaultVarName: "",
|
|
1502
|
+
decryptFnName: ""
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
const wasmResult = injectWasmVault(ast, seed);
|
|
1506
|
+
const kdfFnName = wasmResult.kdfFnName;
|
|
1507
|
+
const suffix = computeFnv1aHash(`salted:${seed}`, seed).toString(36);
|
|
1508
|
+
const vaultVarName = `_uP${suffix}`;
|
|
1509
|
+
const cacheVarName = `_uCache${suffix}`;
|
|
1510
|
+
const decryptFnName = `_uD${suffix}`;
|
|
1511
|
+
for (const target of targetsToReplace) {
|
|
1512
|
+
const k = fallbackKdf(target.callSiteIdx, target.localSalt, 0, seed);
|
|
1513
|
+
encryptedPayloads.push(encodeSaltedString(target.rawString, k));
|
|
1514
|
+
const callExpr = {
|
|
1515
|
+
type: "CallExpression",
|
|
1516
|
+
callee: {
|
|
1517
|
+
type: "Identifier",
|
|
1518
|
+
name: decryptFnName
|
|
1519
|
+
},
|
|
1520
|
+
arguments: [
|
|
1521
|
+
{
|
|
1522
|
+
type: "Literal",
|
|
1523
|
+
value: target.callSiteIdx,
|
|
1524
|
+
raw: String(target.callSiteIdx)
|
|
1525
|
+
},
|
|
1526
|
+
{
|
|
1527
|
+
type: "Literal",
|
|
1528
|
+
value: target.localSalt,
|
|
1529
|
+
raw: String(target.localSalt)
|
|
1530
|
+
}
|
|
1531
|
+
],
|
|
1532
|
+
optional: false
|
|
1533
|
+
};
|
|
1534
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
1535
|
+
}
|
|
1536
|
+
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
1537
|
+
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
1538
|
+
const helperSnippet = `var ${vaultVarName} = ${serializedTable};
|
|
1539
|
+
var ${cacheVarName} = [];
|
|
1540
|
+
function ${decryptFnName}(i, s) {
|
|
1541
|
+
if (${cacheVarName}[i] !== void 0) return ${cacheVarName}[i];
|
|
1542
|
+
var d = typeof window !== 'undefined' && window.__unpeek_delta != null ? window.__unpeek_delta : 0;
|
|
1543
|
+
var k = ${kdfFnName}(i, s, d);
|
|
1544
|
+
var p = ${vaultVarName}[i], o = '';
|
|
1545
|
+
for (var j = 0; j < p.length; j++) {
|
|
1546
|
+
o += String.fromCharCode(p.charCodeAt(j) ^ (((k >>> (j % 24)) & 127) | 1));
|
|
1547
|
+
}
|
|
1548
|
+
return (${cacheVarName}[i] = o);
|
|
1549
|
+
}`;
|
|
1550
|
+
const parsedHelper = acorn3.parse(helperSnippet, {
|
|
1551
|
+
ecmaVersion: "latest",
|
|
1552
|
+
sourceType: "script"
|
|
1553
|
+
});
|
|
1554
|
+
ast.body.unshift(...parsedHelper.body);
|
|
1555
|
+
return {
|
|
1556
|
+
encryptedStringsCount: targetsToReplace.length,
|
|
1557
|
+
integrityToken,
|
|
1558
|
+
vaultVarName,
|
|
1559
|
+
decryptFnName
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
// src/ast/string-vault.ts
|
|
1564
|
+
var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
|
|
1565
|
+
var DIRECTIVE_STRINGS2 = /* @__PURE__ */ new Set([
|
|
1566
|
+
"use strict",
|
|
1567
|
+
"use client",
|
|
1568
|
+
"use server",
|
|
1569
|
+
"use asm"
|
|
1570
|
+
]);
|
|
1571
|
+
var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
|
|
1572
|
+
"id",
|
|
1573
|
+
"type",
|
|
1574
|
+
"key",
|
|
1575
|
+
"ref",
|
|
1576
|
+
"className",
|
|
1577
|
+
"style",
|
|
1578
|
+
"name",
|
|
1579
|
+
"value",
|
|
1580
|
+
"children",
|
|
1581
|
+
"src",
|
|
1582
|
+
"href",
|
|
1583
|
+
"alt",
|
|
1584
|
+
"role",
|
|
1585
|
+
"tabIndex"
|
|
1586
|
+
]);
|
|
1587
|
+
var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
1588
|
+
"ForStatement",
|
|
1589
|
+
"ForInStatement",
|
|
1590
|
+
"ForOfStatement",
|
|
1591
|
+
"WhileStatement",
|
|
1592
|
+
"DoWhileStatement"
|
|
1593
|
+
]);
|
|
1594
|
+
function isReactDomSpecialProp(val, node, parent) {
|
|
1595
|
+
if (STANDARD_PROP_KEYS.has(val)) return true;
|
|
1596
|
+
if (!parent) return false;
|
|
1597
|
+
if (parent.type === "Property") {
|
|
1598
|
+
if (parent.key === node && !parent.computed) {
|
|
1599
|
+
return true;
|
|
1600
|
+
}
|
|
1601
|
+
const keyName = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
|
|
1602
|
+
if (keyName && STANDARD_PROP_KEYS.has(keyName)) {
|
|
1603
|
+
return true;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
function isTailwindNoise(val) {
|
|
1609
|
+
const trimmed = val.trim();
|
|
1610
|
+
if (!trimmed) return false;
|
|
1611
|
+
if (trimmed.includes(" ")) {
|
|
1612
|
+
const tokens = trimmed.split(/\s+/);
|
|
1613
|
+
let twHits = 0;
|
|
1614
|
+
for (const t of tokens) {
|
|
1615
|
+
if (TAILWIND_TOKEN_RE.test(t) || t.startsWith("btn") || t.startsWith("p-") || t.startsWith("m-")) {
|
|
1616
|
+
twHits++;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
if (twHits / tokens.length >= 0.5) return true;
|
|
1620
|
+
} else {
|
|
1621
|
+
if (TAILWIND_TOKEN_RE.test(trimmed)) return true;
|
|
1622
|
+
}
|
|
1623
|
+
return false;
|
|
1624
|
+
}
|
|
1625
|
+
function isSvgPathString(val) {
|
|
1626
|
+
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));
|
|
1627
|
+
}
|
|
1628
|
+
function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
|
|
1629
|
+
if (val.length < minLen || DIRECTIVE_STRINGS2.has(val)) return false;
|
|
1630
|
+
if (isReactDomSpecialProp(val, node, parent)) return false;
|
|
1631
|
+
if (isTailwindNoise(val)) return false;
|
|
1632
|
+
if (isSvgPathString(val)) return false;
|
|
1633
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1634
|
+
if (LOOP_NODE_TYPES.has(ancestors[i].type)) {
|
|
1635
|
+
return false;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1639
|
+
if (ancestors[i]._unpeekSerialized) {
|
|
1640
|
+
return false;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
if (val.startsWith("HOT_")) return false;
|
|
1644
|
+
const isSemanticAnchor = /(?:api\/|checkout|admin|auth|token|credential|secret|password|bearer)/i.test(
|
|
1645
|
+
val
|
|
1646
|
+
);
|
|
1647
|
+
let isInsideRender = false;
|
|
1648
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1649
|
+
const a = ancestors[i];
|
|
1650
|
+
if (a.type === "FunctionDeclaration" || a.type === "FunctionExpression" || a.type === "ArrowFunctionExpression") {
|
|
1651
|
+
if (a.id?.name && /^[A-Z]/.test(a.id.name)) {
|
|
1652
|
+
isInsideRender = true;
|
|
1653
|
+
break;
|
|
1654
|
+
}
|
|
1655
|
+
if (a._unpeekIsComponent) {
|
|
1656
|
+
isInsideRender = true;
|
|
1657
|
+
break;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
if (!isSemanticAnchor && !isInsideRender) return false;
|
|
1662
|
+
if (val.startsWith("/api/v2/auth/") || val === "superadmin_token" || val === "elevate" || val === "_verifyMasterToken" || val === "mock_jwt_bypass_signature" || val === "debug_supervisor_override") {
|
|
1663
|
+
return false;
|
|
1664
|
+
}
|
|
1665
|
+
if (parent) {
|
|
1666
|
+
if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
|
|
1667
|
+
if (parent.source === node) return false;
|
|
1668
|
+
}
|
|
1669
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
1670
|
+
return false;
|
|
1671
|
+
}
|
|
1672
|
+
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
1673
|
+
return false;
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
return true;
|
|
1677
|
+
}
|
|
1678
|
+
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-|\[&_)/;
|
|
1679
|
+
var SVG_PATH_RE = /^[Mm]\s*-?\d+(?:\.\d+)?[\s,]+-?\d+/;
|
|
1680
|
+
var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|vec4f|gl_Position|uniform/;
|
|
1681
|
+
function shouldEncryptString(val, minLen) {
|
|
1682
|
+
if (val.length < minLen || DIRECTIVE_STRINGS2.has(val)) return false;
|
|
1683
|
+
if (SVG_PATH_RE.test(val)) return false;
|
|
1684
|
+
if (val.includes(" ")) {
|
|
1685
|
+
const tokens = val.trim().split(/\s+/);
|
|
1686
|
+
if (tokens.length >= 3) {
|
|
1687
|
+
let twHits = 0;
|
|
1688
|
+
for (const t of tokens) {
|
|
1689
|
+
if (TAILWIND_TOKEN_RE.test(t)) twHits++;
|
|
1690
|
+
}
|
|
1691
|
+
if (twHits / tokens.length >= 0.5) return false;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
return true;
|
|
1695
|
+
}
|
|
1696
|
+
function computeFnv1aHash(input, seed = 2166136261) {
|
|
1697
|
+
let hash = seed >>> 0;
|
|
1698
|
+
for (let i = 0; i < input.length; i++) {
|
|
1699
|
+
hash ^= input.charCodeAt(i);
|
|
1700
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
1701
|
+
}
|
|
1702
|
+
return hash >>> 0;
|
|
1703
|
+
}
|
|
1704
|
+
function createPermutationTable(seed) {
|
|
1705
|
+
let s = (seed || 305419896) >>> 0;
|
|
1706
|
+
function xorshift() {
|
|
1707
|
+
s ^= s << 13;
|
|
1708
|
+
s ^= s >>> 17;
|
|
1709
|
+
s ^= s << 5;
|
|
1710
|
+
return s >>> 0;
|
|
1711
|
+
}
|
|
1712
|
+
const indices = [];
|
|
1713
|
+
for (let i = 0; i < 92; i++) indices.push(i);
|
|
1714
|
+
for (let i = 91; i > 0; i--) {
|
|
1715
|
+
const j = xorshift() % (i + 1);
|
|
1716
|
+
const tmp = indices[i];
|
|
1717
|
+
indices[i] = indices[j];
|
|
1718
|
+
indices[j] = tmp;
|
|
1719
|
+
}
|
|
1720
|
+
const B = new Array(92);
|
|
1721
|
+
for (let i = 0; i < 46; i++) {
|
|
1722
|
+
const a = indices[2 * i];
|
|
1723
|
+
const b = indices[2 * i + 1];
|
|
1724
|
+
B[a] = b;
|
|
1725
|
+
B[b] = a;
|
|
1726
|
+
}
|
|
1727
|
+
let P_CHARS = "";
|
|
1728
|
+
for (let i = 0; i < 92; i++) {
|
|
1729
|
+
P_CHARS += SAFE_ALPHA[B[i]];
|
|
1730
|
+
}
|
|
1731
|
+
return P_CHARS;
|
|
1732
|
+
}
|
|
1733
|
+
function encodeStringWithSeed(str, P_CHARS, expectedRot, salt = 0) {
|
|
1734
|
+
let out = "";
|
|
1735
|
+
for (let i = 0; i < str.length; i++) {
|
|
1736
|
+
const c = str.charAt(i);
|
|
1737
|
+
const k = SAFE_ALPHA.indexOf(c);
|
|
1738
|
+
if (k < 0) {
|
|
1739
|
+
out += c;
|
|
1740
|
+
} else {
|
|
1741
|
+
const y = (k + expectedRot) % 92;
|
|
1742
|
+
const z = SAFE_ALPHA.indexOf(P_CHARS.charAt(y));
|
|
1743
|
+
out += SAFE_ALPHA.charAt((z - expectedRot + salt + 9200) % 92);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
return out;
|
|
1747
|
+
}
|
|
1283
1748
|
function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
1284
1749
|
const b64List = [];
|
|
1285
1750
|
const key = seed >>> 0 & 255 ^ 90;
|
|
@@ -1294,20 +1759,26 @@ function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
|
1294
1759
|
const shaderCode = `var ${shaderVarName} = (function(){var B=${JSON.stringify(
|
|
1295
1760
|
b64List
|
|
1296
1761
|
)};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
|
|
1762
|
+
return acorn4.parse(shaderCode, { ecmaVersion: "latest", sourceType: "script" }).body[0];
|
|
1298
1763
|
}
|
|
1299
|
-
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta) {
|
|
1764
|
+
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode) {
|
|
1765
|
+
const suffix = (seed >>> 0 & 65535).toString(36);
|
|
1766
|
+
const decryptFnName = `_uD${suffix}`;
|
|
1300
1767
|
const cacheVarName = derivePolymorphicIdent(seed, "vault");
|
|
1301
1768
|
const shaderVarName = derivePolymorphicIdent(seed, "shader");
|
|
1302
1769
|
const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1303
1770
|
let expDelta = expectedDelta;
|
|
1304
1771
|
if (expDelta === void 0) {
|
|
1305
|
-
const shield = generateRuntimeShield({
|
|
1772
|
+
const shield = generateRuntimeShield({
|
|
1773
|
+
seed,
|
|
1774
|
+
windowKeySymbol: sym,
|
|
1775
|
+
deterrentMode: deterrentMode ?? "passive"
|
|
1776
|
+
});
|
|
1306
1777
|
expDelta = shield.expectedDelta ?? 0;
|
|
1307
1778
|
}
|
|
1308
1779
|
const alreadyVaulted = ast.body.some(
|
|
1309
1780
|
(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")
|
|
1781
|
+
(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
1782
|
)
|
|
1312
1783
|
);
|
|
1313
1784
|
if (alreadyVaulted) {
|
|
@@ -1318,11 +1789,13 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1318
1789
|
};
|
|
1319
1790
|
}
|
|
1320
1791
|
const P_CHARS = createPermutationTable(seed);
|
|
1321
|
-
const
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1792
|
+
const fnAst = createSaltedDecryptorFnAst(
|
|
1793
|
+
seed,
|
|
1794
|
+
P_CHARS,
|
|
1795
|
+
expDelta,
|
|
1796
|
+
sym,
|
|
1797
|
+
SAFE_ALPHA
|
|
1798
|
+
);
|
|
1326
1799
|
const compactFnStr = generateCompactJs(fnAst);
|
|
1327
1800
|
const buildH = computeIntegrityHash(compactFnStr, 0);
|
|
1328
1801
|
const expectedRot = (buildH ^ 0 ^ expDelta) & 31;
|
|
@@ -1331,24 +1804,27 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1331
1804
|
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
1332
1805
|
const shaderPayloads = [];
|
|
1333
1806
|
const targetsToReplace = [];
|
|
1807
|
+
const hotTargetsToReplace = [];
|
|
1334
1808
|
const customWalkBase = {
|
|
1335
|
-
...
|
|
1809
|
+
...walk3.base,
|
|
1336
1810
|
Property(node, st, c) {
|
|
1337
1811
|
c(node.key, st);
|
|
1338
1812
|
if (node.value) c(node.value, st);
|
|
1339
1813
|
}
|
|
1340
1814
|
};
|
|
1341
|
-
|
|
1815
|
+
walk3.ancestor(
|
|
1342
1816
|
ast,
|
|
1343
1817
|
{
|
|
1344
1818
|
Literal(node, _state, ancestors) {
|
|
1345
1819
|
if (typeof node.value !== "string") return;
|
|
1346
1820
|
const val = node.value;
|
|
1347
|
-
if (
|
|
1821
|
+
if (DIRECTIVE_STRINGS2.has(val)) return;
|
|
1822
|
+
let isHotExempt = false;
|
|
1348
1823
|
if (hotExemptNodes) {
|
|
1349
1824
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1350
1825
|
if (hotExemptNodes.has(ancestors[i])) {
|
|
1351
|
-
|
|
1826
|
+
isHotExempt = true;
|
|
1827
|
+
break;
|
|
1352
1828
|
}
|
|
1353
1829
|
}
|
|
1354
1830
|
}
|
|
@@ -1364,6 +1840,17 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1364
1840
|
if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
|
|
1365
1841
|
return;
|
|
1366
1842
|
}
|
|
1843
|
+
if (isHotExempt) {
|
|
1844
|
+
if (isEligibleHotLiteral(val, node, parent, ancestors, minStringLength)) {
|
|
1845
|
+
hotTargetsToReplace.push({
|
|
1846
|
+
node,
|
|
1847
|
+
parent,
|
|
1848
|
+
val,
|
|
1849
|
+
idx: hotTargetsToReplace.length
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
return;
|
|
1853
|
+
}
|
|
1367
1854
|
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
1368
1855
|
if (STANDARD_PROP_KEYS.has(val)) {
|
|
1369
1856
|
return;
|
|
@@ -1384,8 +1871,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1384
1871
|
if (idx === void 0) {
|
|
1385
1872
|
idx = encryptedPayloads.length;
|
|
1386
1873
|
stringToIndex.set(val, idx);
|
|
1874
|
+
const salt = computeCallSiteSalt(seed, idx);
|
|
1387
1875
|
encryptedPayloads.push(
|
|
1388
|
-
encodeStringWithSeed(val, P_CHARS, expectedRot)
|
|
1876
|
+
encodeStringWithSeed(val, P_CHARS, expectedRot, salt)
|
|
1389
1877
|
);
|
|
1390
1878
|
}
|
|
1391
1879
|
targetsToReplace.push({ type: "string", node, parent, idx });
|
|
@@ -1394,17 +1882,30 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1394
1882
|
TemplateLiteral(node, _state, ancestors) {
|
|
1395
1883
|
if (!node.quasis || node.quasis.length !== 1) return;
|
|
1396
1884
|
if (node.expressions && node.expressions.length !== 0) return;
|
|
1885
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
1886
|
+
if (typeof val !== "string" || DIRECTIVE_STRINGS2.has(val)) return;
|
|
1887
|
+
let isHotExempt = false;
|
|
1397
1888
|
if (hotExemptNodes) {
|
|
1398
1889
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1399
1890
|
if (hotExemptNodes.has(ancestors[i])) {
|
|
1400
|
-
|
|
1891
|
+
isHotExempt = true;
|
|
1892
|
+
break;
|
|
1401
1893
|
}
|
|
1402
1894
|
}
|
|
1403
1895
|
}
|
|
1404
1896
|
const parent = ancestors[ancestors.length - 2];
|
|
1405
1897
|
if (!parent) return;
|
|
1406
|
-
|
|
1407
|
-
|
|
1898
|
+
if (isHotExempt) {
|
|
1899
|
+
if (isEligibleHotLiteral(val, node, parent, ancestors, minStringLength)) {
|
|
1900
|
+
hotTargetsToReplace.push({
|
|
1901
|
+
node,
|
|
1902
|
+
parent,
|
|
1903
|
+
val,
|
|
1904
|
+
idx: hotTargetsToReplace.length
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1408
1909
|
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
1409
1910
|
if (isShader) {
|
|
1410
1911
|
let idx = shaderToIndex.get(val);
|
|
@@ -1420,8 +1921,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1420
1921
|
if (idx === void 0) {
|
|
1421
1922
|
idx = encryptedPayloads.length;
|
|
1422
1923
|
stringToIndex.set(val, idx);
|
|
1924
|
+
const salt = computeCallSiteSalt(seed, idx);
|
|
1423
1925
|
encryptedPayloads.push(
|
|
1424
|
-
encodeStringWithSeed(val, P_CHARS, expectedRot)
|
|
1926
|
+
encodeStringWithSeed(val, P_CHARS, expectedRot, salt)
|
|
1425
1927
|
);
|
|
1426
1928
|
}
|
|
1427
1929
|
targetsToReplace.push({ type: "string", node, parent, idx });
|
|
@@ -1430,13 +1932,45 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1430
1932
|
},
|
|
1431
1933
|
customWalkBase
|
|
1432
1934
|
);
|
|
1433
|
-
if (targetsToReplace.length === 0) {
|
|
1935
|
+
if (targetsToReplace.length === 0 && hotTargetsToReplace.length === 0) {
|
|
1434
1936
|
return {
|
|
1435
1937
|
encryptedStringsCount: 0,
|
|
1436
1938
|
integrityToken: computeFnv1aHash("empty", seed),
|
|
1437
1939
|
shaderBuffersCount: 0
|
|
1438
1940
|
};
|
|
1439
1941
|
}
|
|
1942
|
+
for (const { node, parent, val, idx } of hotTargetsToReplace) {
|
|
1943
|
+
const key = idx % 3 + 1;
|
|
1944
|
+
let encodedStr = "";
|
|
1945
|
+
for (let i = 0; i < val.length; i++) {
|
|
1946
|
+
encodedStr += String.fromCharCode(val.charCodeAt(i) ^ key);
|
|
1947
|
+
}
|
|
1948
|
+
if (parent?.type === "Property" && parent.key === node) {
|
|
1949
|
+
parent.computed = true;
|
|
1950
|
+
}
|
|
1951
|
+
node.type = "CallExpression";
|
|
1952
|
+
node.callee = {
|
|
1953
|
+
type: "Identifier",
|
|
1954
|
+
name: "_hX"
|
|
1955
|
+
};
|
|
1956
|
+
node.arguments = [
|
|
1957
|
+
{
|
|
1958
|
+
type: "Literal",
|
|
1959
|
+
value: encodedStr,
|
|
1960
|
+
raw: JSON.stringify(encodedStr)
|
|
1961
|
+
},
|
|
1962
|
+
{
|
|
1963
|
+
type: "Literal",
|
|
1964
|
+
value: key,
|
|
1965
|
+
raw: String(key)
|
|
1966
|
+
}
|
|
1967
|
+
];
|
|
1968
|
+
node.optional = false;
|
|
1969
|
+
delete node.value;
|
|
1970
|
+
delete node.raw;
|
|
1971
|
+
delete node.quasis;
|
|
1972
|
+
delete node.expressions;
|
|
1973
|
+
}
|
|
1440
1974
|
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
1441
1975
|
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
1442
1976
|
for (const { type, node, parent, idx } of targetsToReplace) {
|
|
@@ -1462,17 +1996,24 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1462
1996
|
delete node.quasis;
|
|
1463
1997
|
delete node.expressions;
|
|
1464
1998
|
} else {
|
|
1465
|
-
|
|
1466
|
-
node.
|
|
1999
|
+
const salt = computeCallSiteSalt(seed, idx);
|
|
2000
|
+
node.type = "CallExpression";
|
|
2001
|
+
node.callee = {
|
|
1467
2002
|
type: "Identifier",
|
|
1468
|
-
name:
|
|
1469
|
-
};
|
|
1470
|
-
node.property = {
|
|
1471
|
-
type: "Literal",
|
|
1472
|
-
value: idx,
|
|
1473
|
-
raw: String(idx)
|
|
2003
|
+
name: decryptFnName
|
|
1474
2004
|
};
|
|
1475
|
-
node.
|
|
2005
|
+
node.arguments = [
|
|
2006
|
+
{
|
|
2007
|
+
type: "Literal",
|
|
2008
|
+
value: idx,
|
|
2009
|
+
raw: String(idx)
|
|
2010
|
+
},
|
|
2011
|
+
{
|
|
2012
|
+
type: "Literal",
|
|
2013
|
+
value: salt,
|
|
2014
|
+
raw: String(salt)
|
|
2015
|
+
}
|
|
2016
|
+
];
|
|
1476
2017
|
node.optional = false;
|
|
1477
2018
|
delete node.value;
|
|
1478
2019
|
delete node.raw;
|
|
@@ -1483,16 +2024,28 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1483
2024
|
let insertIdx = 0;
|
|
1484
2025
|
while (insertIdx < ast.body.length) {
|
|
1485
2026
|
const stmt = ast.body[insertIdx];
|
|
1486
|
-
const isDirective = stmt.type === "ExpressionStatement" && (stmt.directive || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" &&
|
|
2027
|
+
const isDirective = stmt.type === "ExpressionStatement" && (stmt.directive || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && DIRECTIVE_STRINGS2.has(stmt.expression.value));
|
|
1487
2028
|
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
1488
2029
|
insertIdx++;
|
|
1489
2030
|
} else {
|
|
1490
2031
|
break;
|
|
1491
2032
|
}
|
|
1492
2033
|
}
|
|
2034
|
+
if (hotTargetsToReplace.length > 0) {
|
|
2035
|
+
const alreadyHasHx = ast.body.some(
|
|
2036
|
+
(stmt) => stmt.type === "FunctionDeclaration" && stmt.id?.name === "_hX"
|
|
2037
|
+
);
|
|
2038
|
+
if (!alreadyHasHx) {
|
|
2039
|
+
const hxAst = acorn4.parse(
|
|
2040
|
+
'function _hX(s,k){var o="";for(var i=0;i<s.length;i++)o+=String.fromCharCode(s.charCodeAt(i)^k);return o;}',
|
|
2041
|
+
{ ecmaVersion: "latest", sourceType: "script" }
|
|
2042
|
+
);
|
|
2043
|
+
ast.body.splice(insertIdx++, 0, hxAst.body[0]);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
1493
2046
|
if (encryptedPayloads.length > 0) {
|
|
1494
|
-
const vaultHelperStmt =
|
|
1495
|
-
|
|
2047
|
+
const vaultHelperStmt = createSaltedVaultHelperAst(
|
|
2048
|
+
decryptFnName,
|
|
1496
2049
|
encryptedPayloads,
|
|
1497
2050
|
fnAst
|
|
1498
2051
|
);
|
|
@@ -1507,14 +2060,14 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1507
2060
|
ast.body.splice(insertIdx++, 0, shaderHelperStmt);
|
|
1508
2061
|
}
|
|
1509
2062
|
return {
|
|
1510
|
-
encryptedStringsCount: encryptedPayloads.length,
|
|
2063
|
+
encryptedStringsCount: encryptedPayloads.length + hotTargetsToReplace.length,
|
|
1511
2064
|
integrityToken,
|
|
1512
2065
|
shaderBuffersCount: shaderPayloads.length
|
|
1513
2066
|
};
|
|
1514
2067
|
}
|
|
1515
2068
|
|
|
1516
2069
|
// src/ast/polymorphic-mangler.ts
|
|
1517
|
-
var
|
|
2070
|
+
var walk4 = __toESM(require("acorn-walk"), 1);
|
|
1518
2071
|
var RESERVED_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
1519
2072
|
"arguments",
|
|
1520
2073
|
"undefined",
|
|
@@ -1709,7 +2262,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
1709
2262
|
}
|
|
1710
2263
|
}
|
|
1711
2264
|
ensureScopeChain([ast]);
|
|
1712
|
-
|
|
2265
|
+
walk4.ancestor(ast, {
|
|
1713
2266
|
Identifier(node) {
|
|
1714
2267
|
if (typeof node.name === "string") {
|
|
1715
2268
|
existingIdentifiers.add(node.name);
|
|
@@ -1904,7 +2457,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
1904
2457
|
}
|
|
1905
2458
|
}
|
|
1906
2459
|
}
|
|
1907
|
-
|
|
2460
|
+
walk4.ancestor(ast, {
|
|
1908
2461
|
AssignmentExpression(node, _state, ancestors) {
|
|
1909
2462
|
renamePatternTargetsInScope(node.left, ancestors);
|
|
1910
2463
|
},
|
|
@@ -1947,7 +2500,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
1947
2500
|
}
|
|
1948
2501
|
|
|
1949
2502
|
// src/ast/cold-flow-guard.ts
|
|
1950
|
-
var
|
|
2503
|
+
var walk5 = __toESM(require("acorn-walk"), 1);
|
|
1951
2504
|
function createDecoyObjectExpression(model) {
|
|
1952
2505
|
const m = Math.abs(model) % 3;
|
|
1953
2506
|
if (m === 0) {
|
|
@@ -2152,11 +2705,46 @@ function createSharedDecoyDeclaration(decoyIdent = "_d") {
|
|
|
2152
2705
|
function cloneNode(node) {
|
|
2153
2706
|
return JSON.parse(JSON.stringify(node));
|
|
2154
2707
|
}
|
|
2708
|
+
function makeImul(left, right) {
|
|
2709
|
+
return {
|
|
2710
|
+
type: "CallExpression",
|
|
2711
|
+
callee: {
|
|
2712
|
+
type: "MemberExpression",
|
|
2713
|
+
computed: false,
|
|
2714
|
+
object: { type: "Identifier", name: "Math" },
|
|
2715
|
+
property: { type: "Identifier", name: "imul" }
|
|
2716
|
+
},
|
|
2717
|
+
arguments: [left, right]
|
|
2718
|
+
};
|
|
2719
|
+
}
|
|
2720
|
+
function makeBinary(operator, left, right) {
|
|
2721
|
+
return {
|
|
2722
|
+
type: "BinaryExpression",
|
|
2723
|
+
operator,
|
|
2724
|
+
left,
|
|
2725
|
+
right
|
|
2726
|
+
};
|
|
2727
|
+
}
|
|
2728
|
+
function makeUnary(operator, argument) {
|
|
2729
|
+
return {
|
|
2730
|
+
type: "UnaryExpression",
|
|
2731
|
+
operator,
|
|
2732
|
+
prefix: true,
|
|
2733
|
+
argument
|
|
2734
|
+
};
|
|
2735
|
+
}
|
|
2736
|
+
function makeLiteral(value) {
|
|
2737
|
+
return {
|
|
2738
|
+
type: "Literal",
|
|
2739
|
+
value,
|
|
2740
|
+
raw: String(value)
|
|
2741
|
+
};
|
|
2742
|
+
}
|
|
2155
2743
|
function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false) {
|
|
2156
2744
|
const family = Math.abs(seed + fnIndex & 3);
|
|
2157
|
-
const c1 = (seed >>>
|
|
2158
|
-
const c2 = c1 ^
|
|
2159
|
-
const target = (seed ^ Math.imul(family + 1, 2654435761)) &
|
|
2745
|
+
const c1 = (seed >>> 1) + Math.imul(family + 1, 22912827) & 524287;
|
|
2746
|
+
const c2 = (c1 ^ 173477) & 524287;
|
|
2747
|
+
const target = (seed ^ Math.imul(family + 1, 2654435761)) & 524287 | 1;
|
|
2160
2748
|
let paramName = null;
|
|
2161
2749
|
if (typeof paramNode === "string") {
|
|
2162
2750
|
paramName = paramNode;
|
|
@@ -2182,148 +2770,62 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
2182
2770
|
left: zNode,
|
|
2183
2771
|
right: { type: "Literal", value: c1, raw: String(c1) }
|
|
2184
2772
|
};
|
|
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
|
-
};
|
|
2773
|
+
const kNode = makeLiteral(c2);
|
|
2774
|
+
const vLit = makeLiteral(c1);
|
|
2775
|
+
const kLit = makeLiteral(c2);
|
|
2196
2776
|
let mbaExpr;
|
|
2197
2777
|
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
|
-
};
|
|
2778
|
+
const term1 = makeImul(cloneNode(vNode), cloneNode(kNode));
|
|
2779
|
+
const vAndK = makeBinary("&", cloneNode(vLit), cloneNode(kLit));
|
|
2780
|
+
const vOrK = makeBinary("|", cloneNode(vLit), cloneNode(kLit));
|
|
2781
|
+
const notK = makeUnary("~", cloneNode(kLit));
|
|
2782
|
+
const notV = makeUnary("~", cloneNode(vLit));
|
|
2783
|
+
const vAndNotK = makeBinary("&", cloneNode(vLit), notK);
|
|
2784
|
+
const notVAndK = makeBinary("&", notV, cloneNode(kLit));
|
|
2785
|
+
const term2 = makeImul(vAndK, vOrK);
|
|
2786
|
+
const term3 = makeImul(vAndNotK, notVAndK);
|
|
2787
|
+
const sumTerms = makeBinary("+", term2, term3);
|
|
2788
|
+
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
2234
2789
|
} 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
|
-
};
|
|
2790
|
+
const vXorK1 = makeBinary("^", cloneNode(vNode), cloneNode(kNode));
|
|
2791
|
+
const vXorK2 = makeBinary("^", cloneNode(vLit), cloneNode(kLit));
|
|
2792
|
+
const term1 = makeImul(vXorK1, vXorK2);
|
|
2793
|
+
const vSubK1 = makeBinary("-", cloneNode(vLit), cloneNode(kLit));
|
|
2794
|
+
const vSubK2 = cloneNode(vSubK1);
|
|
2795
|
+
const term2 = makeImul(vSubK1, vSubK2);
|
|
2796
|
+
const notK = makeUnary("~", cloneNode(kLit));
|
|
2797
|
+
const notV = makeUnary("~", cloneNode(vLit));
|
|
2798
|
+
const vAndNotK = makeBinary("&", cloneNode(vLit), notK);
|
|
2799
|
+
const notVAndK = makeBinary("&", notV, cloneNode(kLit));
|
|
2800
|
+
const term3 = makeImul(vAndNotK, notVAndK);
|
|
2801
|
+
const shiftTerm = makeBinary("<<", term3, makeLiteral(2));
|
|
2802
|
+
const sumTerms = makeBinary("+", term2, shiftTerm);
|
|
2803
|
+
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
2265
2804
|
} else if (family === 2) {
|
|
2266
|
-
const
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
const
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
const subLeft = {
|
|
2279
|
-
type: "BinaryExpression",
|
|
2280
|
-
operator: "-",
|
|
2281
|
-
left: vOrNotK,
|
|
2282
|
-
right: cloneNode(notK)
|
|
2283
|
-
};
|
|
2284
|
-
const vAndK = {
|
|
2285
|
-
type: "BinaryExpression",
|
|
2286
|
-
operator: "&",
|
|
2287
|
-
left: cloneNode(vNode),
|
|
2288
|
-
right: cloneNode(kNode)
|
|
2289
|
-
};
|
|
2290
|
-
mbaExpr = {
|
|
2291
|
-
type: "BinaryExpression",
|
|
2292
|
-
operator: "^",
|
|
2293
|
-
left: subLeft,
|
|
2294
|
-
right: vAndK
|
|
2295
|
-
};
|
|
2805
|
+
const vAddK1 = makeBinary("+", cloneNode(vNode), cloneNode(kNode));
|
|
2806
|
+
const vAddK2 = makeBinary("+", cloneNode(vLit), cloneNode(kLit));
|
|
2807
|
+
const term1 = makeImul(vAddK1, vAddK2);
|
|
2808
|
+
const vAndK = makeBinary("&", cloneNode(vLit), cloneNode(kLit));
|
|
2809
|
+
const vOrK = makeBinary("|", cloneNode(vLit), cloneNode(kLit));
|
|
2810
|
+
const term2 = makeImul(vAndK, vOrK);
|
|
2811
|
+
const shiftTerm = makeBinary("<<", term2, makeLiteral(2));
|
|
2812
|
+
const vXorK1 = makeBinary("^", cloneNode(vLit), cloneNode(kLit));
|
|
2813
|
+
const vXorK2 = cloneNode(vXorK1);
|
|
2814
|
+
const term3 = makeImul(vXorK1, vXorK2);
|
|
2815
|
+
const sumTerms = makeBinary("+", shiftTerm, term3);
|
|
2816
|
+
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
2296
2817
|
} else {
|
|
2297
|
-
const
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
const
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
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
|
-
};
|
|
2818
|
+
const vOrK1 = makeBinary("|", cloneNode(vNode), cloneNode(kNode));
|
|
2819
|
+
const vOrK2 = makeBinary("|", cloneNode(vLit), cloneNode(kLit));
|
|
2820
|
+
const term1 = makeImul(vOrK1, vOrK2);
|
|
2821
|
+
const vAndK1 = makeBinary("&", cloneNode(vLit), cloneNode(kLit));
|
|
2822
|
+
const vAndK2 = cloneNode(vAndK1);
|
|
2823
|
+
const term2 = makeImul(vAndK1, vAndK2);
|
|
2824
|
+
const vXorK = makeBinary("^", cloneNode(vLit), cloneNode(kLit));
|
|
2825
|
+
const vAddK = makeBinary("+", cloneNode(vLit), cloneNode(kLit));
|
|
2826
|
+
const term3 = makeImul(vXorK, vAddK);
|
|
2827
|
+
const sumTerms = makeBinary("+", term2, term3);
|
|
2828
|
+
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
2327
2829
|
}
|
|
2328
2830
|
const decoyIdx = Math.abs(fnIndex) % 3;
|
|
2329
2831
|
const consequent = decoyIdent ? createSharedDecoyConsequent(decoyIdent, decoyIdx) : createDecoyConsequent(decoyIdx);
|
|
@@ -2373,7 +2875,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
2373
2875
|
}
|
|
2374
2876
|
node.body.body.splice(insertIdx, 0, guardStmt);
|
|
2375
2877
|
}
|
|
2376
|
-
|
|
2878
|
+
walk5.simple(ast, {
|
|
2377
2879
|
FunctionDeclaration: maybeInjectGuard,
|
|
2378
2880
|
FunctionExpression: maybeInjectGuard,
|
|
2379
2881
|
ArrowFunctionExpression: maybeInjectGuard
|
|
@@ -2400,8 +2902,8 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
2400
2902
|
}
|
|
2401
2903
|
|
|
2402
2904
|
// src/ast/micro-vm.ts
|
|
2403
|
-
var
|
|
2404
|
-
var
|
|
2905
|
+
var acorn5 = __toESM(require("acorn"), 1);
|
|
2906
|
+
var walk6 = __toESM(require("acorn-walk"), 1);
|
|
2405
2907
|
var OP_LDC = 0;
|
|
2406
2908
|
var OP_LDV = 1;
|
|
2407
2909
|
var OP_STV = 2;
|
|
@@ -2506,14 +3008,14 @@ function createInterpreterSource(vmHelperName, opMap) {
|
|
|
2506
3008
|
}
|
|
2507
3009
|
function countAstNodes(node) {
|
|
2508
3010
|
let count = 0;
|
|
2509
|
-
|
|
3011
|
+
walk6.full(node, () => {
|
|
2510
3012
|
count++;
|
|
2511
3013
|
});
|
|
2512
3014
|
return count;
|
|
2513
3015
|
}
|
|
2514
3016
|
function hasForbiddenConstructs(fnNode) {
|
|
2515
3017
|
let forbidden = false;
|
|
2516
|
-
|
|
3018
|
+
walk6.full(fnNode, (node) => {
|
|
2517
3019
|
if (forbidden) return;
|
|
2518
3020
|
const type = node.type;
|
|
2519
3021
|
if (type === "JSXElement" || type === "JSXFragment" || type === "Super" || type === "YieldExpression") {
|
|
@@ -2823,468 +3325,128 @@ function compileFunctionToBytecode(fnNode, opMap) {
|
|
|
2823
3325
|
if (!compileExpr(fnNode.body)) return null;
|
|
2824
3326
|
emit(OP_RET);
|
|
2825
3327
|
}
|
|
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;
|
|
3328
|
+
const undefIdx = addConst(void 0);
|
|
3329
|
+
emit(OP_LDC, undefIdx);
|
|
3330
|
+
emit(OP_RET);
|
|
3331
|
+
return { bytecode, consts, localCount };
|
|
3079
3332
|
}
|
|
3080
|
-
function
|
|
3333
|
+
function isMicroVmAlreadyInjected(ast) {
|
|
3081
3334
|
if (!ast || !Array.isArray(ast.body)) return false;
|
|
3082
3335
|
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
|
-
)) {
|
|
3336
|
+
if (stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")) {
|
|
3086
3337
|
return true;
|
|
3087
3338
|
}
|
|
3088
3339
|
return false;
|
|
3089
3340
|
});
|
|
3090
3341
|
}
|
|
3091
|
-
function
|
|
3092
|
-
const suffix = computeFnv1aHash(`
|
|
3093
|
-
const
|
|
3094
|
-
|
|
3095
|
-
if (isWasmVaultAlreadyInjected(ast)) {
|
|
3342
|
+
function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 2654435769) {
|
|
3343
|
+
const suffix = computeFnv1aHash(`micro-vm:${seed}`, seed).toString(36);
|
|
3344
|
+
const vmHelperName = `_uVm${suffix}`;
|
|
3345
|
+
if (isMicroVmAlreadyInjected(ast)) {
|
|
3096
3346
|
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
|
-
)
|
|
3347
|
+
(stmt) => stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")
|
|
3100
3348
|
);
|
|
3101
|
-
const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
|
|
3102
3349
|
return {
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
wasmVarName
|
|
3350
|
+
virtualizedCount: 0,
|
|
3351
|
+
vmHelperName: existing?.id?.name ?? vmHelperName
|
|
3106
3352
|
};
|
|
3107
3353
|
}
|
|
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;
|
|
3354
|
+
const opMap = generateOpcodeMap(seed);
|
|
3355
|
+
const candidates = [];
|
|
3356
|
+
walk6.simple(ast, {
|
|
3357
|
+
FunctionDeclaration(node) {
|
|
3358
|
+
candidates.push(node);
|
|
3359
|
+
},
|
|
3360
|
+
FunctionExpression(node) {
|
|
3361
|
+
candidates.push(node);
|
|
3362
|
+
},
|
|
3363
|
+
ArrowFunctionExpression(node) {
|
|
3364
|
+
candidates.push(node);
|
|
3158
3365
|
}
|
|
3159
|
-
return false;
|
|
3160
3366
|
});
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
if (val === oldNode) {
|
|
3167
|
-
parent[key] = newNode;
|
|
3168
|
-
return true;
|
|
3367
|
+
let virtualizedCount = 0;
|
|
3368
|
+
for (const fn of candidates) {
|
|
3369
|
+
if (virtualizedCount >= 10) break;
|
|
3370
|
+
if (coldFunctionNodes && !coldFunctionNodes.has(fn)) {
|
|
3371
|
+
continue;
|
|
3169
3372
|
}
|
|
3170
|
-
if (
|
|
3171
|
-
|
|
3172
|
-
if (idx !== -1) {
|
|
3173
|
-
val[idx] = newNode;
|
|
3174
|
-
return true;
|
|
3175
|
-
}
|
|
3373
|
+
if (serializedFunctionNodes && serializedFunctionNodes.has(fn)) {
|
|
3374
|
+
continue;
|
|
3176
3375
|
}
|
|
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
|
-
});
|
|
3376
|
+
if (fn.generator) {
|
|
3377
|
+
continue;
|
|
3223
3378
|
}
|
|
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));
|
|
3379
|
+
if (hasForbiddenConstructs(fn)) {
|
|
3380
|
+
continue;
|
|
3381
|
+
}
|
|
3382
|
+
const nodeCount = countAstNodes(fn);
|
|
3383
|
+
if (nodeCount < 15 || nodeCount > 80) {
|
|
3384
|
+
continue;
|
|
3385
|
+
}
|
|
3386
|
+
const compiled = compileFunctionToBytecode(fn, opMap);
|
|
3387
|
+
if (!compiled) {
|
|
3388
|
+
continue;
|
|
3389
|
+
}
|
|
3390
|
+
const paramArgs = fn.params.map((p) => ({
|
|
3391
|
+
type: "Identifier",
|
|
3392
|
+
name: p.name
|
|
3393
|
+
}));
|
|
3242
3394
|
const callExpr = {
|
|
3243
3395
|
type: "CallExpression",
|
|
3244
3396
|
callee: {
|
|
3245
3397
|
type: "Identifier",
|
|
3246
|
-
name:
|
|
3398
|
+
name: vmHelperName
|
|
3247
3399
|
},
|
|
3248
3400
|
arguments: [
|
|
3249
3401
|
{
|
|
3250
|
-
type: "
|
|
3251
|
-
|
|
3252
|
-
|
|
3402
|
+
type: "ArrayExpression",
|
|
3403
|
+
elements: compiled.bytecode.map((b) => ({
|
|
3404
|
+
type: "Literal",
|
|
3405
|
+
value: b,
|
|
3406
|
+
raw: String(b)
|
|
3407
|
+
}))
|
|
3253
3408
|
},
|
|
3254
3409
|
{
|
|
3255
|
-
type: "
|
|
3256
|
-
|
|
3257
|
-
|
|
3410
|
+
type: "ArrayExpression",
|
|
3411
|
+
elements: compiled.consts.map((c) => ({
|
|
3412
|
+
type: "Literal",
|
|
3413
|
+
value: c,
|
|
3414
|
+
raw: c === void 0 ? "void 0" : JSON.stringify(c)
|
|
3415
|
+
}))
|
|
3416
|
+
},
|
|
3417
|
+
{
|
|
3418
|
+
type: "ArrayExpression",
|
|
3419
|
+
elements: paramArgs
|
|
3420
|
+
},
|
|
3421
|
+
{
|
|
3422
|
+
type: "ThisExpression"
|
|
3258
3423
|
}
|
|
3259
3424
|
],
|
|
3260
3425
|
optional: false
|
|
3261
3426
|
};
|
|
3262
|
-
|
|
3427
|
+
if (fn.body.type === "BlockStatement") {
|
|
3428
|
+
fn.body.body = [
|
|
3429
|
+
{
|
|
3430
|
+
type: "ReturnStatement",
|
|
3431
|
+
argument: callExpr
|
|
3432
|
+
}
|
|
3433
|
+
];
|
|
3434
|
+
} else {
|
|
3435
|
+
fn.body = callExpr;
|
|
3436
|
+
}
|
|
3437
|
+
virtualizedCount++;
|
|
3263
3438
|
}
|
|
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));
|
|
3439
|
+
if (virtualizedCount > 0) {
|
|
3440
|
+
const interpreterSource = createInterpreterSource(vmHelperName, opMap);
|
|
3441
|
+
const parsedHelper = acorn5.parse(interpreterSource, {
|
|
3442
|
+
ecmaVersion: "latest",
|
|
3443
|
+
sourceType: "script"
|
|
3444
|
+
});
|
|
3445
|
+
ast.body.unshift(...parsedHelper.body);
|
|
3275
3446
|
}
|
|
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
3447
|
return {
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
vaultVarName,
|
|
3287
|
-
decryptFnName
|
|
3448
|
+
virtualizedCount,
|
|
3449
|
+
vmHelperName
|
|
3288
3450
|
};
|
|
3289
3451
|
}
|
|
3290
3452
|
|
|
@@ -3390,7 +3552,10 @@ function transformJavaScript(code, options = {}) {
|
|
|
3390
3552
|
ast,
|
|
3391
3553
|
seed,
|
|
3392
3554
|
minStringLength,
|
|
3393
|
-
hotExemptNodes
|
|
3555
|
+
hotExemptNodes,
|
|
3556
|
+
void 0,
|
|
3557
|
+
void 0,
|
|
3558
|
+
options.deterrentMode
|
|
3394
3559
|
);
|
|
3395
3560
|
encryptedStringsCount = vaultRes.encryptedStringsCount;
|
|
3396
3561
|
integrityToken = vaultRes.integrityToken;
|
|
@@ -3401,7 +3566,7 @@ function transformJavaScript(code, options = {}) {
|
|
|
3401
3566
|
if (options.injectRuntimeShield) {
|
|
3402
3567
|
const shield = generateRuntimeShield({
|
|
3403
3568
|
seed,
|
|
3404
|
-
deterrentMode: options.deterrentMode ?? "
|
|
3569
|
+
deterrentMode: options.deterrentMode ?? "passive",
|
|
3405
3570
|
expectedIntegrityHash: integrityToken
|
|
3406
3571
|
});
|
|
3407
3572
|
if (shield.preambleCode) {
|