unpeek 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -13
- package/README.tr.md +21 -13
- package/dist/adapters/esbuild.cjs +5 -5
- package/dist/adapters/esbuild.d.cts +1 -1
- package/dist/adapters/esbuild.d.ts +1 -1
- package/dist/adapters/esbuild.js +3 -3
- package/dist/adapters/next/adapter.cjs +6 -6
- package/dist/adapters/next/adapter.d.cts +1 -1
- package/dist/adapters/next/adapter.d.ts +1 -1
- package/dist/adapters/next/adapter.js +5 -5
- package/dist/adapters/next/index.cjs +6 -6
- package/dist/adapters/next/index.js +5 -5
- package/dist/adapters/rollup.cjs +5 -5
- package/dist/adapters/rollup.d.cts +1 -1
- package/dist/adapters/rollup.d.ts +1 -1
- package/dist/adapters/rollup.js +3 -3
- package/dist/adapters/rspack.cjs +5 -5
- package/dist/adapters/rspack.d.cts +1 -1
- package/dist/adapters/rspack.d.ts +1 -1
- package/dist/adapters/rspack.js +3 -3
- package/dist/adapters/vite.cjs +5 -5
- package/dist/adapters/vite.d.cts +1 -1
- package/dist/adapters/vite.d.ts +1 -1
- package/dist/adapters/vite.js +3 -3
- package/dist/adapters/webpack.cjs +5 -5
- package/dist/adapters/webpack.d.cts +1 -1
- package/dist/adapters/webpack.d.ts +1 -1
- package/dist/adapters/webpack.js +3 -3
- package/dist/browser.cjs +2 -2
- package/dist/browser.d.cts +7 -6
- package/dist/browser.d.ts +7 -6
- package/dist/browser.js +1 -1
- package/dist/{chunk-TYL32LUK.js → chunk-32GLSJAW.js} +91 -569
- package/dist/{chunk-W77DAC3H.js → chunk-6EWFL4LQ.js} +16 -0
- package/dist/{chunk-3GDHYBVH.cjs → chunk-AD6UFBPA.cjs} +96 -574
- package/dist/{chunk-XYN5NYSD.js → chunk-APQOBFRO.js} +21 -15
- package/dist/{chunk-LGTXAAZH.js → chunk-BL2UXZGD.js} +3155 -481
- package/dist/{chunk-X6EETCO6.cjs → chunk-BQ2O6HM5.cjs} +16 -0
- package/dist/{chunk-4G2HCME5.js → chunk-GCWXTWTN.js} +30 -13
- package/dist/{chunk-4SOS3LRV.js → chunk-K77WRITN.js} +6 -6
- package/dist/{chunk-7ZEVJ4OR.cjs → chunk-KIAYVIC5.cjs} +40 -34
- package/dist/{chunk-M46SFJE7.cjs → chunk-MSECP2P4.cjs} +3351 -677
- package/dist/{chunk-NNAAPDUS.cjs → chunk-SJK45WAU.cjs} +8 -8
- package/dist/{chunk-OTA75YI6.cjs → chunk-UUJLTW7O.cjs} +53 -36
- package/dist/cli/index.js +2808 -528
- package/dist/{config-Y6JwVGwX.d.cts → config-BFAZrfjQ.d.cts} +2 -0
- package/dist/{config-Y6JwVGwX.d.ts → config-BFAZrfjQ.d.ts} +2 -0
- package/dist/config.cjs +2 -2
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/{index-COVHErnx.d.cts → index-Bo4S_VVM.d.cts} +1 -1
- package/dist/{index-0O1WSfVP.d.ts → index-CKdYVt_L.d.ts} +1 -1
- package/dist/index.cjs +171 -31
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +156 -16
- package/dist/plugins/unplugin.cjs +4 -4
- package/dist/plugins/unplugin.js +3 -3
- package/dist/{types-CMtZnV8C.d.ts → types-BDpFfokR.d.ts} +6 -3
- package/dist/{types-D93PuOOl.d.cts → types-WIoud53X.d.cts} +6 -3
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -234,6 +234,84 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
|
|
|
234
234
|
}
|
|
235
235
|
return { framework, outDir };
|
|
236
236
|
}
|
|
237
|
+
function globBodyToRegex(pat) {
|
|
238
|
+
let out = "";
|
|
239
|
+
let i = 0;
|
|
240
|
+
while (i < pat.length) {
|
|
241
|
+
const ch = pat[i];
|
|
242
|
+
if (ch === "/" && pat.slice(i, i + 4) === "/**/") {
|
|
243
|
+
out += "(?:/.+/|/)";
|
|
244
|
+
i += 4;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (ch === "/" && pat.slice(i) === "/**") {
|
|
248
|
+
out += "/.*";
|
|
249
|
+
i = pat.length;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (ch === "*" && pat[i + 1] === "*") {
|
|
253
|
+
if ((i === 0 || pat[i - 1] === "/") && pat[i + 2] === "/") {
|
|
254
|
+
out += "(?:.*/)?";
|
|
255
|
+
i += 3;
|
|
256
|
+
} else {
|
|
257
|
+
out += ".*";
|
|
258
|
+
i += 2;
|
|
259
|
+
}
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
if (ch === "*") {
|
|
263
|
+
out += "[^/]*";
|
|
264
|
+
i += 1;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (ch === "?") {
|
|
268
|
+
out += "[^/]";
|
|
269
|
+
i += 1;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (ch === "{") {
|
|
273
|
+
let depth = 1;
|
|
274
|
+
let j = i + 1;
|
|
275
|
+
const alts = [];
|
|
276
|
+
let segStart = j;
|
|
277
|
+
while (j < pat.length && depth > 0) {
|
|
278
|
+
if (pat[j] === "{") depth++;
|
|
279
|
+
else if (pat[j] === "}") {
|
|
280
|
+
depth--;
|
|
281
|
+
if (depth === 0) {
|
|
282
|
+
alts.push(pat.slice(segStart, j));
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
} else if (pat[j] === "," && depth === 1) {
|
|
286
|
+
alts.push(pat.slice(segStart, j));
|
|
287
|
+
segStart = j + 1;
|
|
288
|
+
}
|
|
289
|
+
j++;
|
|
290
|
+
}
|
|
291
|
+
if (depth === 0 && alts.length > 0) {
|
|
292
|
+
out += `(?:${alts.map(globBodyToRegex).join("|")})`;
|
|
293
|
+
i = j + 1;
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
out += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
298
|
+
i += 1;
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
function matchesGlobPattern(relPath, pattern) {
|
|
303
|
+
const normPattern = pattern.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\/+/, "").trim();
|
|
304
|
+
if (!normPattern) return false;
|
|
305
|
+
const normPath = relPath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\/+/, "");
|
|
306
|
+
const regex = new RegExp(`^${globBodyToRegex(normPattern)}$`);
|
|
307
|
+
if (regex.test(normPath)) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
if (!normPattern.includes("/")) {
|
|
311
|
+
return regex.test(path.posix.basename(normPath));
|
|
312
|
+
}
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
237
315
|
function scanClientBundles(outDir, config) {
|
|
238
316
|
const resolvedOutDir = path.resolve(outDir);
|
|
239
317
|
if (!fs.existsSync(resolvedOutDir)) {
|
|
@@ -280,6 +358,17 @@ function scanClientBundles(outDir, config) {
|
|
|
280
358
|
if (config?.target !== "worker" && isWorkerOrServiceWorkerFile(fullPath, resolvedOutDir)) {
|
|
281
359
|
continue;
|
|
282
360
|
}
|
|
361
|
+
const relPath = path.relative(resolvedOutDir, fullPath).replace(/\\/g, "/");
|
|
362
|
+
if (config?.filter?.include && config.filter.include.length > 0) {
|
|
363
|
+
if (!config.filter.include.some((pattern) => matchesGlobPattern(relPath, pattern))) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (config?.filter?.exclude && config.filter.exclude.length > 0) {
|
|
368
|
+
if (config.filter.exclude.some((pattern) => matchesGlobPattern(relPath, pattern))) {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
283
372
|
results.push(fullPath);
|
|
284
373
|
}
|
|
285
374
|
}
|
|
@@ -667,11 +756,24 @@ function toRegExpArray(val) {
|
|
|
667
756
|
function clonePatterns(patterns) {
|
|
668
757
|
return patterns ? [...patterns] : void 0;
|
|
669
758
|
}
|
|
759
|
+
function validateSeed(val) {
|
|
760
|
+
if (val === void 0) return void 0;
|
|
761
|
+
if (typeof val !== "number" || !Number.isFinite(val)) {
|
|
762
|
+
throw new UnpeekError(
|
|
763
|
+
"ERR_CONFIG_INVALID",
|
|
764
|
+
'Configuration "seed" must be a finite number.'
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
return val;
|
|
768
|
+
}
|
|
670
769
|
function normalizeConfig(raw) {
|
|
671
770
|
if (!isRecord(raw)) {
|
|
672
771
|
return {};
|
|
673
772
|
}
|
|
674
773
|
const result = { ...raw };
|
|
774
|
+
if ("seed" in raw && raw.seed !== void 0) {
|
|
775
|
+
result.seed = validateSeed(raw.seed);
|
|
776
|
+
}
|
|
675
777
|
if (isRecord(raw.hotPath)) {
|
|
676
778
|
result.hotPath = {
|
|
677
779
|
...raw.hotPath,
|
|
@@ -709,6 +811,7 @@ function mergeTwoConfigs(base2, override) {
|
|
|
709
811
|
target: override.target ?? base2.target,
|
|
710
812
|
profile: override.profile ?? base2.profile,
|
|
711
813
|
tier: override.tier ?? base2.tier,
|
|
814
|
+
seed: override.seed ?? base2.seed,
|
|
712
815
|
coldFlow: override.coldFlow ?? base2.coldFlow,
|
|
713
816
|
outDir: override.outDir ?? base2.outDir,
|
|
714
817
|
scrubPaths: override.scrubPaths ?? base2.scrubPaths,
|
|
@@ -802,9 +905,11 @@ function mergeTwoConfigs(base2, override) {
|
|
|
802
905
|
};
|
|
803
906
|
}
|
|
804
907
|
function mergeUnpeekConfig(base2, override) {
|
|
908
|
+
validateSeed(base2.seed);
|
|
805
909
|
if (!override) {
|
|
806
910
|
return { ...base2 };
|
|
807
911
|
}
|
|
912
|
+
validateSeed(override.seed);
|
|
808
913
|
const effectiveBase = override.profile ? mergeTwoConfigs(base2, PRESETS[override.profile]) : base2;
|
|
809
914
|
return mergeTwoConfigs(effectiveBase, override);
|
|
810
915
|
}
|
|
@@ -1756,6 +1861,294 @@ function invertRivestPoly32(y, a0, a1Odd, a2Even, a3Even) {
|
|
|
1756
1861
|
// src/ast/hot-path-detector.ts
|
|
1757
1862
|
import * as acorn from "acorn";
|
|
1758
1863
|
import * as walk from "acorn-walk";
|
|
1864
|
+
|
|
1865
|
+
// src/ast/sourcemap-critical.ts
|
|
1866
|
+
function contentMightMatchInclude(content, rawPatterns) {
|
|
1867
|
+
for (const pat of rawPatterns) {
|
|
1868
|
+
if (typeof pat === "string" && pat.length > 0) {
|
|
1869
|
+
if (content.includes(pat)) return true;
|
|
1870
|
+
try {
|
|
1871
|
+
const stripped = pat.replace(/^\^|\$$/g, "");
|
|
1872
|
+
if (stripped && new RegExp(stripped).test(content)) return true;
|
|
1873
|
+
} catch {
|
|
1874
|
+
}
|
|
1875
|
+
} else if (pat instanceof RegExp) {
|
|
1876
|
+
try {
|
|
1877
|
+
const stripped = pat.source.replace(/^\^|\$$/g, "");
|
|
1878
|
+
const flags = pat.flags.replace(/[gy]/g, "");
|
|
1879
|
+
if (new RegExp(stripped, flags).test(content)) return true;
|
|
1880
|
+
} catch {
|
|
1881
|
+
return true;
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
return false;
|
|
1886
|
+
}
|
|
1887
|
+
function mightContainCriticalMatches(rawMap, options) {
|
|
1888
|
+
if (!rawMap || typeof rawMap !== "object") return false;
|
|
1889
|
+
if (Array.isArray(rawMap.sections)) {
|
|
1890
|
+
return rawMap.sections.some(
|
|
1891
|
+
(sec) => sec?.map && mightContainCriticalMatches(sec.map, options)
|
|
1892
|
+
);
|
|
1893
|
+
}
|
|
1894
|
+
if (options.criticalIncludeMatchers.length > 0 && Array.isArray(rawMap.names) && rawMap.names.some(
|
|
1895
|
+
(n) => typeof n === "string" && options.criticalIncludeMatchers.some((match) => match(n))
|
|
1896
|
+
)) {
|
|
1897
|
+
return true;
|
|
1898
|
+
}
|
|
1899
|
+
if (Array.isArray(rawMap.sourcesContent)) {
|
|
1900
|
+
for (const content of rawMap.sourcesContent) {
|
|
1901
|
+
if (typeof content !== "string" || content.length === 0) continue;
|
|
1902
|
+
if (content.includes(options.criticalAnnotation)) return true;
|
|
1903
|
+
if (options.rawIncludePatterns.length > 0 && contentMightMatchInclude(content, options.rawIncludePatterns)) {
|
|
1904
|
+
return true;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
return false;
|
|
1909
|
+
}
|
|
1910
|
+
function decodeMappingsByLine(mappingsStr, maxGenLine) {
|
|
1911
|
+
const byLine = /* @__PURE__ */ new Map();
|
|
1912
|
+
if (!mappingsStr || maxGenLine < 0) return byLine;
|
|
1913
|
+
let sourceIndex = 0;
|
|
1914
|
+
let originalLine = 0;
|
|
1915
|
+
let originalColumn = 0;
|
|
1916
|
+
let nameIndex = 0;
|
|
1917
|
+
let genLine = 0;
|
|
1918
|
+
let pos = 0;
|
|
1919
|
+
const len = mappingsStr.length;
|
|
1920
|
+
while (pos <= len && genLine <= maxGenLine) {
|
|
1921
|
+
let semi = mappingsStr.indexOf(";", pos);
|
|
1922
|
+
if (semi === -1) semi = len;
|
|
1923
|
+
if (semi > pos) {
|
|
1924
|
+
const lineStr = mappingsStr.slice(pos, semi);
|
|
1925
|
+
let genCol = 0;
|
|
1926
|
+
const lineSegs = [];
|
|
1927
|
+
const segments = lineStr.split(",");
|
|
1928
|
+
for (const seg of segments) {
|
|
1929
|
+
if (!seg) continue;
|
|
1930
|
+
const values = [];
|
|
1931
|
+
let idx = 0;
|
|
1932
|
+
let valid = true;
|
|
1933
|
+
while (idx < seg.length) {
|
|
1934
|
+
const decoded = decodeVlq(seg, idx);
|
|
1935
|
+
if (!decoded) {
|
|
1936
|
+
valid = false;
|
|
1937
|
+
break;
|
|
1938
|
+
}
|
|
1939
|
+
values.push(decoded.value);
|
|
1940
|
+
idx = decoded.nextIndex;
|
|
1941
|
+
}
|
|
1942
|
+
if (!valid || values.length !== 1 && values.length !== 4 && values.length !== 5) {
|
|
1943
|
+
continue;
|
|
1944
|
+
}
|
|
1945
|
+
genCol += values[0];
|
|
1946
|
+
if (values.length >= 4) {
|
|
1947
|
+
sourceIndex += values[1];
|
|
1948
|
+
originalLine += values[2];
|
|
1949
|
+
originalColumn += values[3];
|
|
1950
|
+
const mapping = {
|
|
1951
|
+
generatedLine: genLine,
|
|
1952
|
+
generatedColumn: genCol,
|
|
1953
|
+
sourceIndex,
|
|
1954
|
+
originalLine,
|
|
1955
|
+
originalColumn
|
|
1956
|
+
};
|
|
1957
|
+
if (values.length === 5) {
|
|
1958
|
+
nameIndex += values[4];
|
|
1959
|
+
mapping.nameIndex = nameIndex;
|
|
1960
|
+
}
|
|
1961
|
+
lineSegs.push(mapping);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
if (lineSegs.length > 0) {
|
|
1965
|
+
for (let i = 1; i < lineSegs.length; i++) {
|
|
1966
|
+
if (lineSegs[i].generatedColumn < lineSegs[i - 1].generatedColumn) {
|
|
1967
|
+
lineSegs.sort((a, b) => a.generatedColumn - b.generatedColumn);
|
|
1968
|
+
break;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
byLine.set(genLine, lineSegs);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
if (semi === len) break;
|
|
1975
|
+
pos = semi + 1;
|
|
1976
|
+
genLine++;
|
|
1977
|
+
}
|
|
1978
|
+
return byLine;
|
|
1979
|
+
}
|
|
1980
|
+
function findNearestSegmentOnLine(lineSegs, genCol, maxForwardCol) {
|
|
1981
|
+
if (!lineSegs || lineSegs.length === 0) return void 0;
|
|
1982
|
+
let lo = 0;
|
|
1983
|
+
let hi = lineSegs.length - 1;
|
|
1984
|
+
let best;
|
|
1985
|
+
while (lo <= hi) {
|
|
1986
|
+
const mid = lo + hi >> 1;
|
|
1987
|
+
const m = lineSegs[mid];
|
|
1988
|
+
if (m.generatedColumn <= genCol) {
|
|
1989
|
+
best = m;
|
|
1990
|
+
lo = mid + 1;
|
|
1991
|
+
} else {
|
|
1992
|
+
hi = mid - 1;
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
if (best) return best;
|
|
1996
|
+
const first = lineSegs[0];
|
|
1997
|
+
if (maxForwardCol === void 0 || first.generatedColumn <= maxForwardCol) {
|
|
1998
|
+
return first;
|
|
1999
|
+
}
|
|
2000
|
+
return void 0;
|
|
2001
|
+
}
|
|
2002
|
+
function hasCriticalAnnotationNearLine(lines, origLine, annotation) {
|
|
2003
|
+
if (origLine < 0 || origLine >= lines.length) return false;
|
|
2004
|
+
if (lines[origLine].includes(annotation)) return true;
|
|
2005
|
+
const minLine = Math.max(0, origLine - 5);
|
|
2006
|
+
let inBlockComment = false;
|
|
2007
|
+
for (let l = origLine - 1; l >= minLine; l--) {
|
|
2008
|
+
const line = lines[l];
|
|
2009
|
+
if (line.includes(annotation)) return true;
|
|
2010
|
+
const trimmed = line.trim();
|
|
2011
|
+
if (!inBlockComment && trimmed.endsWith("*/") && !trimmed.includes("/*")) {
|
|
2012
|
+
inBlockComment = true;
|
|
2013
|
+
continue;
|
|
2014
|
+
}
|
|
2015
|
+
if (inBlockComment) {
|
|
2016
|
+
if (trimmed.includes("/*")) {
|
|
2017
|
+
inBlockComment = false;
|
|
2018
|
+
}
|
|
2019
|
+
continue;
|
|
2020
|
+
}
|
|
2021
|
+
if (trimmed === "" || trimmed.startsWith("//") || trimmed.startsWith("/*") && trimmed.endsWith("*/")) {
|
|
2022
|
+
continue;
|
|
2023
|
+
}
|
|
2024
|
+
break;
|
|
2025
|
+
}
|
|
2026
|
+
return false;
|
|
2027
|
+
}
|
|
2028
|
+
var IDENT_CHAR_RE = /[A-Za-z0-9_$]/;
|
|
2029
|
+
var DECL_IDENT_RES = [
|
|
2030
|
+
/\bfunction\s*\*?\s*([A-Za-z_$][A-Za-z0-9_$]*)/g,
|
|
2031
|
+
/\b(?:const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=/g,
|
|
2032
|
+
/([A-Za-z_$][A-Za-z0-9_$]*)\s*[:=]\s*(?:async\s+)?(?:function\b|\()/g
|
|
2033
|
+
];
|
|
2034
|
+
function hasCriticalNameOnSourceLine(line, origCol, matchers) {
|
|
2035
|
+
if (!line || matchers.length === 0) return false;
|
|
2036
|
+
if (origCol >= 0 && origCol < line.length) {
|
|
2037
|
+
let start = origCol;
|
|
2038
|
+
while (start > 0 && IDENT_CHAR_RE.test(line[start - 1])) start--;
|
|
2039
|
+
let end = origCol;
|
|
2040
|
+
while (end < line.length && IDENT_CHAR_RE.test(line[end])) end++;
|
|
2041
|
+
if (end > start) {
|
|
2042
|
+
const token = line.slice(start, end);
|
|
2043
|
+
if (matchers.some((m) => m(token))) return true;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
for (const re of DECL_IDENT_RES) {
|
|
2047
|
+
re.lastIndex = 0;
|
|
2048
|
+
let m;
|
|
2049
|
+
while ((m = re.exec(line)) !== null) {
|
|
2050
|
+
if (m[1] && matchers.some((match) => match(m[1]))) {
|
|
2051
|
+
return true;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
return false;
|
|
2056
|
+
}
|
|
2057
|
+
function resolveSourceMapCriticalNodes(functions, originalSourceMap, options) {
|
|
2058
|
+
const matched = /* @__PURE__ */ new Set();
|
|
2059
|
+
if (!originalSourceMap || functions.length === 0) {
|
|
2060
|
+
return matched;
|
|
2061
|
+
}
|
|
2062
|
+
if (!mightContainCriticalMatches(originalSourceMap, options)) {
|
|
2063
|
+
return matched;
|
|
2064
|
+
}
|
|
2065
|
+
const flatMap = flattenSourceMapSections(originalSourceMap);
|
|
2066
|
+
if (!flatMap.mappings) {
|
|
2067
|
+
return matched;
|
|
2068
|
+
}
|
|
2069
|
+
let maxGenLine = -1;
|
|
2070
|
+
for (const fn of functions) {
|
|
2071
|
+
const nLine = fn.node.loc?.start?.line;
|
|
2072
|
+
if (typeof nLine === "number") {
|
|
2073
|
+
maxGenLine = Math.max(maxGenLine, nLine - 1);
|
|
2074
|
+
}
|
|
2075
|
+
const idLine = fn.idNode?.loc?.start?.line;
|
|
2076
|
+
if (typeof idLine === "number") {
|
|
2077
|
+
maxGenLine = Math.max(maxGenLine, idLine - 1);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
if (maxGenLine < 0) {
|
|
2081
|
+
return matched;
|
|
2082
|
+
}
|
|
2083
|
+
const lineMappings = decodeMappingsByLine(flatMap.mappings, maxGenLine);
|
|
2084
|
+
if (lineMappings.size === 0) {
|
|
2085
|
+
return matched;
|
|
2086
|
+
}
|
|
2087
|
+
const linesCache = /* @__PURE__ */ new Map();
|
|
2088
|
+
const getSourceLines = (sourceIdx) => {
|
|
2089
|
+
if (linesCache.has(sourceIdx)) return linesCache.get(sourceIdx);
|
|
2090
|
+
const content = flatMap.sourcesContent?.[sourceIdx];
|
|
2091
|
+
if (typeof content !== "string") return void 0;
|
|
2092
|
+
const split = content.split(/\r?\n/);
|
|
2093
|
+
linesCache.set(sourceIdx, split);
|
|
2094
|
+
return split;
|
|
2095
|
+
};
|
|
2096
|
+
const segmentIsCritical = (seg) => {
|
|
2097
|
+
if (seg.nameIndex !== void 0 && options.criticalIncludeMatchers.length > 0) {
|
|
2098
|
+
const mappedName = flatMap.names[seg.nameIndex];
|
|
2099
|
+
if (typeof mappedName === "string" && options.criticalIncludeMatchers.some((m) => m(mappedName))) {
|
|
2100
|
+
return true;
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
const lines = getSourceLines(seg.sourceIndex);
|
|
2104
|
+
if (!lines) return false;
|
|
2105
|
+
if (hasCriticalAnnotationNearLine(
|
|
2106
|
+
lines,
|
|
2107
|
+
seg.originalLine,
|
|
2108
|
+
options.criticalAnnotation
|
|
2109
|
+
)) {
|
|
2110
|
+
return true;
|
|
2111
|
+
}
|
|
2112
|
+
if (options.criticalIncludeMatchers.length > 0 && seg.originalLine >= 0 && seg.originalLine < lines.length && hasCriticalNameOnSourceLine(
|
|
2113
|
+
lines[seg.originalLine],
|
|
2114
|
+
seg.originalColumn,
|
|
2115
|
+
options.criticalIncludeMatchers
|
|
2116
|
+
)) {
|
|
2117
|
+
return true;
|
|
2118
|
+
}
|
|
2119
|
+
return false;
|
|
2120
|
+
};
|
|
2121
|
+
for (const fn of functions) {
|
|
2122
|
+
const candidates = [];
|
|
2123
|
+
const idLoc = fn.idNode?.loc?.start;
|
|
2124
|
+
if (idLoc) {
|
|
2125
|
+
const seg = findNearestSegmentOnLine(
|
|
2126
|
+
lineMappings.get(idLoc.line - 1),
|
|
2127
|
+
idLoc.column
|
|
2128
|
+
);
|
|
2129
|
+
if (seg) candidates.push(seg);
|
|
2130
|
+
}
|
|
2131
|
+
const nodeStart = fn.node.loc?.start;
|
|
2132
|
+
if (nodeStart) {
|
|
2133
|
+
const nodeEnd = fn.node.loc?.end;
|
|
2134
|
+
const maxForwardCol = nodeEnd && nodeEnd.line === nodeStart.line ? nodeEnd.column : void 0;
|
|
2135
|
+
const seg = findNearestSegmentOnLine(
|
|
2136
|
+
lineMappings.get(nodeStart.line - 1),
|
|
2137
|
+
nodeStart.column,
|
|
2138
|
+
maxForwardCol
|
|
2139
|
+
);
|
|
2140
|
+
if (seg && !candidates.includes(seg)) {
|
|
2141
|
+
candidates.push(seg);
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
if (candidates.some(segmentIsCritical)) {
|
|
2145
|
+
matched.add(fn.node);
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
return matched;
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
// src/ast/hot-path-detector.ts
|
|
1759
2152
|
var ARRAY_HOF_METHODS = /* @__PURE__ */ new Set([
|
|
1760
2153
|
"map",
|
|
1761
2154
|
"filter",
|
|
@@ -1796,6 +2189,16 @@ var DEFAULT_EVENT_HANDLER_REGEX = /^(?:on|handle)(?!Tick|Render|Update|Frame|Ani
|
|
|
1796
2189
|
var CRITICAL_COLD_HANDLER_REGEX = /^(?:onSubmit|handleSubmit|submit[A-Z0-9_]*|validate[A-Z0-9_]*|login|signIn|register|checkout)$/i;
|
|
1797
2190
|
var CRITICAL_COLD_CALLEE_REGEX = /^(?:onSubmit|handleSubmit|submit[A-Z0-9_]*|validate[A-Z0-9_]*|login|signIn|register|checkout|createServerReference|fetch)$/i;
|
|
1798
2191
|
var DEFAULT_HOOK_REGEX = /^use[A-Z0-9]/;
|
|
2192
|
+
var JSX_FACTORY_CALLS = /* @__PURE__ */ new Set([
|
|
2193
|
+
"jsx",
|
|
2194
|
+
"jsxs",
|
|
2195
|
+
"_jsx",
|
|
2196
|
+
"_jsxs",
|
|
2197
|
+
"jsxDEV",
|
|
2198
|
+
"_jsxDEV",
|
|
2199
|
+
"createElement",
|
|
2200
|
+
"cloneElement"
|
|
2201
|
+
]);
|
|
1799
2202
|
var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
1800
2203
|
"useState",
|
|
1801
2204
|
"useEffect",
|
|
@@ -1810,7 +2213,10 @@ var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
|
1810
2213
|
"jsxs",
|
|
1811
2214
|
"_jsx",
|
|
1812
2215
|
"_jsxs",
|
|
1813
|
-
"
|
|
2216
|
+
"jsxDEV",
|
|
2217
|
+
"_jsxDEV",
|
|
2218
|
+
"createElement",
|
|
2219
|
+
"cloneElement"
|
|
1814
2220
|
]);
|
|
1815
2221
|
var FUNCTION_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
1816
2222
|
"FunctionDeclaration",
|
|
@@ -1852,9 +2258,16 @@ function parseJavaScriptAst(code, comments, opts) {
|
|
|
1852
2258
|
}
|
|
1853
2259
|
return ast;
|
|
1854
2260
|
}
|
|
1855
|
-
function
|
|
1856
|
-
|
|
1857
|
-
|
|
2261
|
+
function unwrapCallee(callee) {
|
|
2262
|
+
let cur = callee;
|
|
2263
|
+
while (cur?.type === "SequenceExpression" && Array.isArray(cur.expressions) && cur.expressions.length > 0) {
|
|
2264
|
+
cur = cur.expressions[cur.expressions.length - 1];
|
|
2265
|
+
}
|
|
2266
|
+
return cur;
|
|
2267
|
+
}
|
|
2268
|
+
function isHocCall(callNode, hocWrappers, depth = 0) {
|
|
2269
|
+
if (!callNode || callNode.type !== "CallExpression" || depth > 4) return false;
|
|
2270
|
+
const callee = unwrapCallee(callNode.callee);
|
|
1858
2271
|
if (!callee) return false;
|
|
1859
2272
|
const wrappers = hocWrappers ?? DEFAULT_HOC_WRAPPERS;
|
|
1860
2273
|
if (callee.type === "Identifier") {
|
|
@@ -1867,6 +2280,9 @@ function isHocCall(callNode, hocWrappers) {
|
|
|
1867
2280
|
if (wrappers.has(full2)) return true;
|
|
1868
2281
|
}
|
|
1869
2282
|
}
|
|
2283
|
+
if (callee.type === "CallExpression") {
|
|
2284
|
+
return isHocCall(callee, wrappers, depth + 1);
|
|
2285
|
+
}
|
|
1870
2286
|
return false;
|
|
1871
2287
|
}
|
|
1872
2288
|
function getFunctionLabel(node, ancestors, hocWrappers) {
|
|
@@ -1916,8 +2332,73 @@ function getFunctionLabel(node, ancestors, hocWrappers) {
|
|
|
1916
2332
|
}
|
|
1917
2333
|
return `anonymous_${node.start}`;
|
|
1918
2334
|
}
|
|
1919
|
-
function
|
|
1920
|
-
|
|
2335
|
+
function hasUiComponentSignal(node, ancestors, hocWrappers, isHookFn) {
|
|
2336
|
+
if (!node) return false;
|
|
2337
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2338
|
+
const anc = ancestors[i];
|
|
2339
|
+
if (anc.type === "CallExpression") {
|
|
2340
|
+
if (isHocCall(anc, hocWrappers)) {
|
|
2341
|
+
return true;
|
|
2342
|
+
}
|
|
2343
|
+
} else {
|
|
2344
|
+
break;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
if (!node.body) return false;
|
|
2348
|
+
const stack = [node.body];
|
|
2349
|
+
while (stack.length > 0) {
|
|
2350
|
+
const cur = stack.pop();
|
|
2351
|
+
if (!cur || typeof cur !== "object") continue;
|
|
2352
|
+
if (cur.type === "JSXElement" || cur.type === "JSXFragment") {
|
|
2353
|
+
return true;
|
|
2354
|
+
}
|
|
2355
|
+
if (cur.type === "CallExpression") {
|
|
2356
|
+
const callee = unwrapCallee(cur.callee);
|
|
2357
|
+
let calleeName = "";
|
|
2358
|
+
let memberProp = "";
|
|
2359
|
+
let qualifiedCall = "";
|
|
2360
|
+
if (callee?.type === "Identifier") {
|
|
2361
|
+
calleeName = callee.name;
|
|
2362
|
+
qualifiedCall = calleeName;
|
|
2363
|
+
} else if (callee?.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier") {
|
|
2364
|
+
memberProp = callee.property.name;
|
|
2365
|
+
if (callee.object?.type === "Identifier") {
|
|
2366
|
+
qualifiedCall = `${callee.object.name}.${memberProp}`;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
if (JSX_FACTORY_CALLS.has(calleeName) || JSX_FACTORY_CALLS.has(memberProp) || qualifiedCall === "React.createElement" || qualifiedCall === "React.cloneElement" || REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp) || isHookFn(calleeName) || isHookFn(memberProp)) {
|
|
2370
|
+
return true;
|
|
2371
|
+
}
|
|
2372
|
+
if (calleeName === "h" && Array.isArray(cur.arguments) && (cur.arguments.length >= 2 || cur.arguments.length === 1 && cur.arguments[0]?.type === "Literal" && typeof cur.arguments[0].value === "string")) {
|
|
2373
|
+
return true;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
for (const key of Object.keys(cur)) {
|
|
2377
|
+
if (key === "loc" || key === "start" || key === "end") continue;
|
|
2378
|
+
const val = cur[key];
|
|
2379
|
+
if (Array.isArray(val)) {
|
|
2380
|
+
for (let i = val.length - 1; i >= 0; i--) {
|
|
2381
|
+
const item = val[i];
|
|
2382
|
+
if (item && typeof item === "object" && typeof item.type === "string" && !FUNCTION_NODE_TYPES.has(item.type)) {
|
|
2383
|
+
stack.push(item);
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
} else if (val && typeof val === "object" && typeof val.type === "string" && !FUNCTION_NODE_TYPES.has(val.type)) {
|
|
2387
|
+
stack.push(val);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
return false;
|
|
2392
|
+
}
|
|
2393
|
+
function isPascalCaseComponent(name, node, ancestors, hocWrappers, isHookFn) {
|
|
2394
|
+
if (!/^[A-Z][a-zA-Z0-9]*$/.test(name)) return false;
|
|
2395
|
+
if (!node || !ancestors) return false;
|
|
2396
|
+
return hasUiComponentSignal(
|
|
2397
|
+
node,
|
|
2398
|
+
ancestors,
|
|
2399
|
+
hocWrappers ?? DEFAULT_HOC_WRAPPERS,
|
|
2400
|
+
isHookFn ?? ((n) => DEFAULT_HOOK_REGEX.test(n))
|
|
2401
|
+
);
|
|
1921
2402
|
}
|
|
1922
2403
|
function isEventHandlerName(name, regex = DEFAULT_EVENT_HANDLER_REGEX) {
|
|
1923
2404
|
return regex.test(name);
|
|
@@ -1996,7 +2477,7 @@ function containsLoopOrAnimation(fnNode, animationCalls = ANIMATION_FRAME_CALLS)
|
|
|
1996
2477
|
});
|
|
1997
2478
|
return found;
|
|
1998
2479
|
}
|
|
1999
|
-
function analyzeAstHotPaths(ast, config) {
|
|
2480
|
+
function analyzeAstHotPaths(ast, config, originalSourceMap) {
|
|
2000
2481
|
const hotFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
2001
2482
|
const coldFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
2002
2483
|
const hotExemptNodes = /* @__PURE__ */ new WeakSet();
|
|
@@ -2138,9 +2619,50 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2138
2619
|
}
|
|
2139
2620
|
return anchorStart;
|
|
2140
2621
|
}
|
|
2622
|
+
function getFunctionIdNode(node, ancestors) {
|
|
2623
|
+
if (node.id) return node.id;
|
|
2624
|
+
const parent = ancestors[ancestors.length - 2];
|
|
2625
|
+
if (!parent) return null;
|
|
2626
|
+
if (parent.type === "VariableDeclarator" && parent.id?.type === "Identifier") {
|
|
2627
|
+
return parent.id;
|
|
2628
|
+
}
|
|
2629
|
+
if (parent.type === "AssignmentExpression" && parent.left?.type === "Identifier") {
|
|
2630
|
+
return parent.left;
|
|
2631
|
+
}
|
|
2632
|
+
if ((parent.type === "Property" || parent.type === "MethodDefinition") && parent.key?.type === "Identifier") {
|
|
2633
|
+
return parent.key;
|
|
2634
|
+
}
|
|
2635
|
+
if (parent.type === "CallExpression") {
|
|
2636
|
+
let idx = ancestors.length - 2;
|
|
2637
|
+
let matchedHoc = false;
|
|
2638
|
+
while (idx >= 0 && ancestors[idx].type === "CallExpression") {
|
|
2639
|
+
if (isHocCall(ancestors[idx], hocWrappers)) {
|
|
2640
|
+
matchedHoc = true;
|
|
2641
|
+
idx--;
|
|
2642
|
+
} else {
|
|
2643
|
+
break;
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
if (matchedHoc && idx >= 0) {
|
|
2647
|
+
const outer = ancestors[idx];
|
|
2648
|
+
if (outer.type === "VariableDeclarator" && outer.id?.type === "Identifier") {
|
|
2649
|
+
return outer.id;
|
|
2650
|
+
}
|
|
2651
|
+
if (outer.type === "AssignmentExpression" && outer.left?.type === "Identifier") {
|
|
2652
|
+
return outer.left;
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
return null;
|
|
2657
|
+
}
|
|
2141
2658
|
function registerFunctionNode(node, ancestors) {
|
|
2142
2659
|
const name = getFunctionLabel(node, ancestors, hocWrappers);
|
|
2143
|
-
allFunctions.push({
|
|
2660
|
+
allFunctions.push({
|
|
2661
|
+
node,
|
|
2662
|
+
name,
|
|
2663
|
+
anchorStart: computeFunctionAnchorStart(node, ancestors),
|
|
2664
|
+
idNode: getFunctionIdNode(node, ancestors)
|
|
2665
|
+
});
|
|
2144
2666
|
fnByName.set(name, node);
|
|
2145
2667
|
const paramSet = /* @__PURE__ */ new Set();
|
|
2146
2668
|
for (const p of node.params || []) {
|
|
@@ -2189,7 +2711,8 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2189
2711
|
}
|
|
2190
2712
|
}
|
|
2191
2713
|
fnScopeChain.set(node, chain);
|
|
2192
|
-
if (isPascalCaseComponent(name) && !excludedComponents.has(name)) {
|
|
2714
|
+
if (isPascalCaseComponent(name, node, ancestors, hocWrappers, isHookName) && !excludedComponents.has(name)) {
|
|
2715
|
+
node._unpeekIsComponent = true;
|
|
2193
2716
|
shallowComponentNodes.add(node);
|
|
2194
2717
|
hotFunctionNodes.add(node);
|
|
2195
2718
|
directHotNodes.add(node);
|
|
@@ -2301,7 +2824,7 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2301
2824
|
}
|
|
2302
2825
|
},
|
|
2303
2826
|
CallExpression(node, _state, ancestors) {
|
|
2304
|
-
const callee = node.callee;
|
|
2827
|
+
const callee = unwrapCallee(node.callee);
|
|
2305
2828
|
let calleeName = "";
|
|
2306
2829
|
let memberProp = "";
|
|
2307
2830
|
let qualifiedCall = "";
|
|
@@ -2432,6 +2955,9 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2432
2955
|
}
|
|
2433
2956
|
if (REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp) || isHookName(calleeName) || isHookName(memberProp)) {
|
|
2434
2957
|
if (enclosingFn) {
|
|
2958
|
+
if (JSX_FACTORY_CALLS.has(calleeName) || JSX_FACTORY_CALLS.has(memberProp) || REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp)) {
|
|
2959
|
+
enclosingFn._unpeekIsComponent = true;
|
|
2960
|
+
}
|
|
2435
2961
|
shallowComponentNodes.add(enclosingFn);
|
|
2436
2962
|
hotFunctionNodes.add(enclosingFn);
|
|
2437
2963
|
directHotNodes.add(enclosingFn);
|
|
@@ -2600,47 +3126,6 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2600
3126
|
}
|
|
2601
3127
|
}
|
|
2602
3128
|
}
|
|
2603
|
-
const calleeToCallers = /* @__PURE__ */ new Map();
|
|
2604
|
-
for (const [callerNode, calleeNames] of callerToCallees.entries()) {
|
|
2605
|
-
for (const cName of calleeNames) {
|
|
2606
|
-
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
2607
|
-
if (targetNode) {
|
|
2608
|
-
let set = calleeToCallers.get(targetNode);
|
|
2609
|
-
if (!set) {
|
|
2610
|
-
set = /* @__PURE__ */ new Set();
|
|
2611
|
-
calleeToCallers.set(targetNode, set);
|
|
2612
|
-
}
|
|
2613
|
-
set.add(callerNode);
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2617
|
-
let changed = true;
|
|
2618
|
-
while (changed) {
|
|
2619
|
-
changed = false;
|
|
2620
|
-
for (const [callerNode, calleeNames] of callerToCallees.entries()) {
|
|
2621
|
-
if (hotFunctionNodes.has(callerNode) || shallowComponentNodes.has(callerNode) || coldForcedNodes.has(callerNode)) {
|
|
2622
|
-
continue;
|
|
2623
|
-
}
|
|
2624
|
-
for (const cName of calleeNames) {
|
|
2625
|
-
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
2626
|
-
if (targetNode && trueHotNodes.has(targetNode)) {
|
|
2627
|
-
const callers = calleeToCallers.get(targetNode);
|
|
2628
|
-
const isDedicatedPipeline = callers && callers.size <= maxPipelineCallers;
|
|
2629
|
-
if (isDedicatedPipeline) {
|
|
2630
|
-
trueHotNodes.add(callerNode);
|
|
2631
|
-
hotFunctionNodes.add(callerNode);
|
|
2632
|
-
hotExemptNodes.add(callerNode);
|
|
2633
|
-
changed = true;
|
|
2634
|
-
break;
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
for (const node of coldForcedNodes) {
|
|
2641
|
-
hotFunctionNodes.delete(node);
|
|
2642
|
-
hotExemptNodes.delete(node);
|
|
2643
|
-
}
|
|
2644
3129
|
const criticalAnnotation = typeof config?.critical?.annotation === "string" && config.critical.annotation.length > 0 ? config.critical.annotation : "@unpeek-critical";
|
|
2645
3130
|
const astComments = ast?.__unpeekComments ?? ast?.comments ?? [];
|
|
2646
3131
|
const criticalComments = astComments.filter(
|
|
@@ -2650,7 +3135,7 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2650
3135
|
if (criticalComments.length > 0 && allFunctions.length > 0) {
|
|
2651
3136
|
const stmtRanges = [];
|
|
2652
3137
|
walk.full(ast, (n) => {
|
|
2653
|
-
if (n && typeof n.start === "number" && typeof n.end === "number" && n.type !== "Program" && n.type !== "BlockStatement" && (n.type.endsWith("Statement") || n.type === "VariableDeclaration" || n.type === "FunctionDeclaration" || n.type === "ClassDeclaration" || n.type === "ImportDeclaration" || n.type === "ExportNamedDeclaration" || n.type === "ExportDefaultDeclaration")) {
|
|
3138
|
+
if (n && typeof n.start === "number" && typeof n.end === "number" && n.type !== "Program" && n.type !== "BlockStatement" && n.type !== "EmptyStatement" && (n.type.endsWith("Statement") || n.type === "VariableDeclaration" || n.type === "FunctionDeclaration" || n.type === "ClassDeclaration" || n.type === "ImportDeclaration" || n.type === "ExportNamedDeclaration" || n.type === "ExportDefaultDeclaration")) {
|
|
2654
3139
|
stmtRanges.push({ start: n.start, end: n.end });
|
|
2655
3140
|
}
|
|
2656
3141
|
});
|
|
@@ -2658,18 +3143,41 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2658
3143
|
(a, b) => (a.node.start ?? 0) - (b.node.start ?? 0)
|
|
2659
3144
|
);
|
|
2660
3145
|
for (const c of criticalComments) {
|
|
3146
|
+
const cStart = typeof c.start === "number" ? c.start : 0;
|
|
2661
3147
|
const cEnd = typeof c.end === "number" ? c.end : 0;
|
|
3148
|
+
let enclosingFnEntry;
|
|
3149
|
+
for (const fn of sortedFns) {
|
|
3150
|
+
const s = fn.node.start;
|
|
3151
|
+
const e = fn.node.end;
|
|
3152
|
+
if (typeof s === "number" && typeof e === "number" && s <= cStart && cEnd <= e) {
|
|
3153
|
+
enclosingFnEntry = fn;
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
2662
3156
|
const target = sortedFns.find(
|
|
2663
3157
|
(fn) => typeof fn.node.start === "number" && fn.node.start >= cEnd
|
|
2664
3158
|
);
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
3159
|
+
const enclosingEnd = enclosingFnEntry ? enclosingFnEntry.node.end : Infinity;
|
|
3160
|
+
if (target && target.node.end <= enclosingEnd) {
|
|
3161
|
+
const fnStart = target.node.start;
|
|
3162
|
+
const fnEnd = target.node.end;
|
|
3163
|
+
const blockedByStmt = stmtRanges.some(
|
|
3164
|
+
(s) => !(s.start <= fnStart && fnEnd <= s.end) && s.end > cEnd && s.end <= target.anchorStart
|
|
3165
|
+
);
|
|
3166
|
+
if (!blockedByStmt) {
|
|
3167
|
+
criticalCommentNodes.add(target.node);
|
|
3168
|
+
continue;
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
if (enclosingFnEntry) {
|
|
3172
|
+
const body = enclosingFnEntry.node.body;
|
|
3173
|
+
if (body && typeof body.start === "number" && cStart >= body.start) {
|
|
3174
|
+
const hasPriorStmtInBody = stmtRanges.some(
|
|
3175
|
+
(s) => s.start >= body.start && s.end <= cStart
|
|
3176
|
+
);
|
|
3177
|
+
if (!hasPriorStmtInBody) {
|
|
3178
|
+
criticalCommentNodes.add(enclosingFnEntry.node);
|
|
3179
|
+
}
|
|
3180
|
+
}
|
|
2673
3181
|
}
|
|
2674
3182
|
}
|
|
2675
3183
|
}
|
|
@@ -2688,6 +3196,71 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2688
3196
|
}
|
|
2689
3197
|
}
|
|
2690
3198
|
}
|
|
3199
|
+
const sourceMapCriticalNodes = resolveSourceMapCriticalNodes(
|
|
3200
|
+
allFunctions,
|
|
3201
|
+
originalSourceMap,
|
|
3202
|
+
{
|
|
3203
|
+
criticalAnnotation,
|
|
3204
|
+
criticalIncludeMatchers,
|
|
3205
|
+
rawIncludePatterns: criticalIncludeList
|
|
3206
|
+
}
|
|
3207
|
+
);
|
|
3208
|
+
const matchedCriticalNodes = /* @__PURE__ */ new Set();
|
|
3209
|
+
for (const fn of allFunctions) {
|
|
3210
|
+
if (criticalCommentNodes.has(fn.node) || sourceMapCriticalNodes.has(fn.node) || criticalIncludeMatchers.some((match) => match(fn.name))) {
|
|
3211
|
+
matchedCriticalNodes.add(fn.node);
|
|
3212
|
+
if (!trueHotNodes.has(fn.node) && !serializedWorkerNodes.has(fn.node)) {
|
|
3213
|
+
shallowComponentNodes.delete(fn.node);
|
|
3214
|
+
hotFunctionNodes.delete(fn.node);
|
|
3215
|
+
directHotNodes.delete(fn.node);
|
|
3216
|
+
hotExemptNodes.delete(fn.node);
|
|
3217
|
+
delete fn.node._unpeekIsComponent;
|
|
3218
|
+
coldForcedNodes.add(fn.node);
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
const calleeToCallers = /* @__PURE__ */ new Map();
|
|
3223
|
+
for (const [callerNode, calleeNames] of callerToCallees.entries()) {
|
|
3224
|
+
for (const cName of calleeNames) {
|
|
3225
|
+
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
3226
|
+
if (targetNode) {
|
|
3227
|
+
let set = calleeToCallers.get(targetNode);
|
|
3228
|
+
if (!set) {
|
|
3229
|
+
set = /* @__PURE__ */ new Set();
|
|
3230
|
+
calleeToCallers.set(targetNode, set);
|
|
3231
|
+
}
|
|
3232
|
+
set.add(callerNode);
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
let changed = true;
|
|
3237
|
+
while (changed) {
|
|
3238
|
+
changed = false;
|
|
3239
|
+
for (const [callerNode, calleeNames] of callerToCallees.entries()) {
|
|
3240
|
+
if (hotFunctionNodes.has(callerNode) || shallowComponentNodes.has(callerNode) || coldForcedNodes.has(callerNode)) {
|
|
3241
|
+
continue;
|
|
3242
|
+
}
|
|
3243
|
+
for (const cName of calleeNames) {
|
|
3244
|
+
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
3245
|
+
if (targetNode && trueHotNodes.has(targetNode)) {
|
|
3246
|
+
const callers = calleeToCallers.get(targetNode);
|
|
3247
|
+
const isDedicatedPipeline = callers && callers.size <= maxPipelineCallers;
|
|
3248
|
+
if (isDedicatedPipeline) {
|
|
3249
|
+
trueHotNodes.add(callerNode);
|
|
3250
|
+
hotFunctionNodes.add(callerNode);
|
|
3251
|
+
hotExemptNodes.add(callerNode);
|
|
3252
|
+
changed = true;
|
|
3253
|
+
break;
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
for (const node of coldForcedNodes) {
|
|
3260
|
+
shallowComponentNodes.delete(node);
|
|
3261
|
+
hotFunctionNodes.delete(node);
|
|
3262
|
+
hotExemptNodes.delete(node);
|
|
3263
|
+
}
|
|
2691
3264
|
const hotFunctionsSkipped = [];
|
|
2692
3265
|
const coldFunctionsProtected = [];
|
|
2693
3266
|
for (const fn of allFunctions) {
|
|
@@ -2696,7 +3269,7 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
2696
3269
|
} else {
|
|
2697
3270
|
coldFunctionNodes.add(fn.node);
|
|
2698
3271
|
coldFunctionsProtected.push(fn.name);
|
|
2699
|
-
if (
|
|
3272
|
+
if (matchedCriticalNodes.has(fn.node) && !trueHotNodes.has(fn.node) && !serializedWorkerNodes.has(fn.node)) {
|
|
2700
3273
|
criticalFunctionNodes.add(fn.node);
|
|
2701
3274
|
}
|
|
2702
3275
|
}
|
|
@@ -3418,9 +3991,9 @@ function createDeterrentSnippet(config) {
|
|
|
3418
3991
|
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=()=>0;" : "";
|
|
3419
3992
|
const symLit = JSON.stringify(sym);
|
|
3420
3993
|
const headlessDecl = detectHeadless ? ",n=w.navigator||0" : "";
|
|
3421
|
-
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)" : "";
|
|
3994
|
+
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)||['__playwright','__puppeteer_evaluation_script__','__nightmare','frida','_frida_'].some(k=>w[k]||G[k])" : "";
|
|
3422
3995
|
const k1Mul = (seed | 1) >>> 0;
|
|
3423
|
-
return `(function ${fnName}(w){var G=globalThis||w;if(w){var O=Object,P=O.getOwnPropertyDescriptor,RF=G.Reflect,R=RF&&RF.apply,FP=Function.prototype,SP=String.prototype,Q='__unpeek_',y=${symLit},z=y+'_s',U='__unpeek_tampered',K=Q+'seed',T=(o,k)=>{try{for(var r;o;o=O.getPrototypeOf(o))if((r=P(o,k))&&(r.set||!r.writable))return 1;}catch(e){return 1;}},D=k=>T(w,k)|T(G,k),B=(k,v,c,W)=>{W=o=>{try{if(!c||!T(o,k))o[k]=v;}catch(e){}};W(G);W(w);},s=FP.toString${headlessDecl},src='',t=+((G[z]||w[z])?.[0]==2)
|
|
3996
|
+
return `(function ${fnName}(w){var G=globalThis||w;if(w){var O=Object,P=O.getOwnPropertyDescriptor,RF=G.Reflect,R=RF&&RF.apply,FP=Function.prototype,SP=String.prototype,ER=Error,EP=ER.prototype,Q='__unpeek_',y=${symLit},z=y+'_s',U='__unpeek_tampered',K=Q+'seed',ST='stack',PS='prepareStackTrace',A='\\n at ',T=(o,k)=>{try{for(var r;o;o=O.getPrototypeOf(o))if((r=P(o,k))&&(r.set||!r.writable))return 1;}catch(e){return 1;}},D=k=>T(w,k)|T(G,k),B=(k,v,c,W)=>{W=o=>{try{if(!c||!T(o,k))o[k]=v;}catch(e){}};W(G);W(w);},s=FP.toString${headlessDecl},src='',t=+((G[z]||w[z])?.[0]==2),sd=P(EP,ST),ep=ER[PS],M=/^function (?:get )?(\\w*)\\(\\)\\s*\\x7b\\s*\\[native code\\]\\s*\\}$/;try{var ps,rf=P(new ER(),ST),Z=()=>{if(ER[PS]!==void 0){if(typeof process>'u')t=1;ER[PS]=void 0;}},F=(f,n,l)=>typeof f!='function'||'prototype'in f||(l>=0&&(f.name!=n||f.length!=l))||M.exec(R(R,null,[s,f,[]]))?.[1]!=n,E=(f,a,b)=>{try{R(f,a,b);t=1;}catch(e){Z();var ed=P(e,ST),st=sd&&sd.get?R(sd.get,e,[]):ed&&ed.get?R(ed.get,e,[]):e[ST];if(ed&&(!rf||F(ed.get,'',0)))t=1;t|=e?.name!='TypeError'||!st||st.indexOf(A)<0||/(?:Object|Proxy)\\.apply\\b|\\n at (?!.* \\(<anonymous>\\)$)/m.test(st.split(A+'E (')[0]);}};Z();try{E(P,null,[]);E(s,{toString(){}},[]);E(R,s,[null,s,[]]);}finally{if(ep!==void 0)ER[PS]=ep;}src=R(s,${fnName},[]);t|=(sd&&F(sd.get,ST,-1))|F(R,'apply',3)|F(s,'toString',0)|s.call(T)!==(ps=R(s,T,[]))|FP.call.call(s,T)!==ps|/\\n/.test(src)${headlessCond};}catch(e){t=1;}t|=D(y)|D(z)|D(U)|T(SP,'_u')|T(FP,'toString')|T(FP,'call')|T(RF,'apply')|T(ER,PS)|(sd?T(O.getPrototypeOf(EP),ST):T(EP,ST));for(var h=2166136261,i=0;i<src.length;)h=Math.imul(h^src.charCodeAt(i++),16777619);var d=h&65535,pd=t?d^((h>>>16^23131)||1):d;B(z,[t+1,h^${seed}^t,h^${k1Mul}^t,1,d^h>>>16],t);B(y,pd,t);if(t){B(y+'_t',!0);B(Q+'delta',pd);try{SP._u=14;}catch(e){}B(K,((w[K]||${seed})^1)>>>0);B(U,!0);try{${consoleSilence}w.dispatchEvent?.(new CustomEvent('unpeek:tamper'));}catch(e){}}}})(typeof window!=='undefined'?window:typeof self<'u'?self:typeof globalThis<'u'?globalThis:0);`;
|
|
3424
3997
|
}
|
|
3425
3998
|
|
|
3426
3999
|
// src/runtime/index.ts
|
|
@@ -3439,13 +4012,15 @@ function generateRuntimeShield(config) {
|
|
|
3439
4012
|
const computedHash = computeIntegrityHash(fnDecl, 0);
|
|
3440
4013
|
const expectedHash = config.expectedIntegrityHash !== void 0 ? config.expectedIntegrityHash >>> 0 : computedHash;
|
|
3441
4014
|
const expectedDelta = config.expectedDelta !== void 0 ? config.expectedDelta & 65535 : computedHash >>> 0 & 65535;
|
|
4015
|
+
const expectedStateHash = computedHash ^ seed | 0;
|
|
3442
4016
|
const payload = {
|
|
3443
4017
|
preambleCode,
|
|
3444
4018
|
integrityCheckFnName,
|
|
3445
4019
|
expectedHash,
|
|
3446
4020
|
windowKeySymbol,
|
|
3447
4021
|
expectedDelta,
|
|
3448
|
-
stateKeySymbol: `${windowKeySymbol}_s
|
|
4022
|
+
stateKeySymbol: `${windowKeySymbol}_s`,
|
|
4023
|
+
expectedStateHash
|
|
3449
4024
|
};
|
|
3450
4025
|
return payload;
|
|
3451
4026
|
}
|
|
@@ -3513,10 +4088,94 @@ function deriveWasmHostParams(seed) {
|
|
|
3513
4088
|
const rA1 = computeFnv1aHash("wasm-ra1", seed) | 1;
|
|
3514
4089
|
const rA2 = computeFnv1aHash("wasm-ra2", seed) & ~1;
|
|
3515
4090
|
const rA3 = computeFnv1aHash("wasm-ra3", seed) & ~1;
|
|
3516
|
-
|
|
4091
|
+
const gMask = computeFnv1aHash("wasm-gmask", seed) | 1 | 0;
|
|
4092
|
+
const pcMask = computeFnv1aHash("wasm-pcmask", seed) | 1 | 0;
|
|
4093
|
+
return { gArr, sOff, rA0, rA1, rA2, rA3, gMask, pcMask };
|
|
4094
|
+
}
|
|
4095
|
+
var ABI_START_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
|
4096
|
+
var ABI_CONT_CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
|
4097
|
+
var FORBIDDEN_ABI_NAMES = /* @__PURE__ */ new Set([
|
|
4098
|
+
"env",
|
|
4099
|
+
"g",
|
|
4100
|
+
"m",
|
|
4101
|
+
"kdf",
|
|
4102
|
+
"bulkmix",
|
|
4103
|
+
"mem",
|
|
4104
|
+
"as",
|
|
4105
|
+
"do",
|
|
4106
|
+
"if",
|
|
4107
|
+
"in",
|
|
4108
|
+
"of",
|
|
4109
|
+
"for",
|
|
4110
|
+
"int",
|
|
4111
|
+
"let",
|
|
4112
|
+
"new",
|
|
4113
|
+
"try",
|
|
4114
|
+
"var",
|
|
4115
|
+
"nan",
|
|
4116
|
+
"map",
|
|
4117
|
+
"set",
|
|
4118
|
+
"url",
|
|
4119
|
+
"top",
|
|
4120
|
+
"get",
|
|
4121
|
+
"set"
|
|
4122
|
+
]);
|
|
4123
|
+
function avalancheMix32(h) {
|
|
4124
|
+
let x = h >>> 0;
|
|
4125
|
+
x = Math.imul(x ^ x >>> 16, 2246822507) >>> 0;
|
|
4126
|
+
x = Math.imul(x ^ x >>> 13, 3266489909) >>> 0;
|
|
4127
|
+
return (x ^ x >>> 16) >>> 0;
|
|
4128
|
+
}
|
|
4129
|
+
function encodeWasmName(name) {
|
|
4130
|
+
const utf8 = new TextEncoder().encode(name);
|
|
4131
|
+
return [...encodeUnsignedLeb128(utf8.length), ...utf8];
|
|
4132
|
+
}
|
|
4133
|
+
function deriveWasmAbiNames(seed) {
|
|
4134
|
+
const s = seed >>> 0;
|
|
4135
|
+
const used = new Set(FORBIDDEN_ABI_NAMES);
|
|
4136
|
+
const pickName = (role) => {
|
|
4137
|
+
for (let attempt = 0; attempt < 64; attempt++) {
|
|
4138
|
+
const h = avalancheMix32(computeFnv1aHash(`wasm-abi:${role}:${attempt}`, s));
|
|
4139
|
+
const len = h >>> 18 & 1 ? 3 : 2;
|
|
4140
|
+
const c0 = ABI_START_CHARS[h % ABI_START_CHARS.length];
|
|
4141
|
+
const c1 = ABI_CONT_CHARS[(h >>> 6) % ABI_CONT_CHARS.length];
|
|
4142
|
+
const c2 = len === 3 ? ABI_CONT_CHARS[(h >>> 12) % ABI_CONT_CHARS.length] : "";
|
|
4143
|
+
const candidate = `${c0}${c1}${c2}`;
|
|
4144
|
+
const lower = candidate.toLowerCase();
|
|
4145
|
+
if (!candidate.startsWith("__") && !used.has(lower)) {
|
|
4146
|
+
used.add(lower);
|
|
4147
|
+
return candidate;
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
const fallback = `w${s.toString(36).slice(0, 2).padStart(2, "0")}`;
|
|
4151
|
+
used.add(fallback.toLowerCase());
|
|
4152
|
+
return fallback;
|
|
4153
|
+
};
|
|
4154
|
+
const envMod = pickName("envMod");
|
|
4155
|
+
const gImport = pickName("gImport");
|
|
4156
|
+
const mImport = pickName("mImport");
|
|
4157
|
+
const kdfExport = pickName("kdfExport");
|
|
4158
|
+
const bulkMixExport = pickName("bulkMixExport");
|
|
4159
|
+
const memExport = pickName("memExport");
|
|
4160
|
+
const exportOrder = [0, 1, 2];
|
|
4161
|
+
const orderHash = avalancheMix32(computeFnv1aHash("wasm-abi:order", s));
|
|
4162
|
+
const j2 = orderHash % 3;
|
|
4163
|
+
[exportOrder[2], exportOrder[j2]] = [exportOrder[j2], exportOrder[2]];
|
|
4164
|
+
const j1 = (orderHash >>> 8) % 2;
|
|
4165
|
+
[exportOrder[1], exportOrder[j1]] = [exportOrder[j1], exportOrder[1]];
|
|
4166
|
+
return {
|
|
4167
|
+
envMod,
|
|
4168
|
+
gImport,
|
|
4169
|
+
mImport,
|
|
4170
|
+
kdfExport,
|
|
4171
|
+
bulkMixExport,
|
|
4172
|
+
memExport,
|
|
4173
|
+
exportOrder
|
|
4174
|
+
};
|
|
3517
4175
|
}
|
|
3518
|
-
function generateWasmKdfBinary(seed) {
|
|
4176
|
+
function generateWasmKdfBinary(seed, options) {
|
|
3519
4177
|
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
4178
|
+
const { gMask, pcMask } = deriveWasmHostParams(seed);
|
|
3520
4179
|
const memBase = (seed >>> 0 & 127) * 4;
|
|
3521
4180
|
const r0 = computeFnv1aHash("wasm-r0", seed) | 0;
|
|
3522
4181
|
const rotAmt = (seed >>> 0) % 27 + 3;
|
|
@@ -3530,6 +4189,8 @@ function generateWasmKdfBinary(seed) {
|
|
|
3530
4189
|
const w2 = c1 ^ (w0 + w1 | 0) | 0;
|
|
3531
4190
|
const w3 = c2 - Math.imul(w1 | 1, w2 | 1) | 0;
|
|
3532
4191
|
const w4 = k0 ^ rotl32(w2, 11) ^ w3 | 0;
|
|
4192
|
+
const w5 = gMask ^ rotl32(w3, 7) ^ w0 | 0;
|
|
4193
|
+
const w6 = pcMask ^ rotl32(w4, 13) ^ w1 | 0;
|
|
3533
4194
|
const kdfInstructions = [
|
|
3534
4195
|
65,
|
|
3535
4196
|
...encodeSignedLeb128(memA),
|
|
@@ -3664,7 +4325,63 @@ function generateWasmKdfBinary(seed) {
|
|
|
3664
4325
|
33,
|
|
3665
4326
|
10,
|
|
3666
4327
|
// local.set 10 (k0)
|
|
3667
|
-
//
|
|
4328
|
+
// Reconstruct gMask -> local 12
|
|
4329
|
+
32,
|
|
4330
|
+
3,
|
|
4331
|
+
// local.get 3 (ptr)
|
|
4332
|
+
40,
|
|
4333
|
+
2,
|
|
4334
|
+
20,
|
|
4335
|
+
// i32.load align=2 offset=20 (w5)
|
|
4336
|
+
32,
|
|
4337
|
+
7,
|
|
4338
|
+
// local.get 7 (w3)
|
|
4339
|
+
65,
|
|
4340
|
+
7,
|
|
4341
|
+
// i32.const 7
|
|
4342
|
+
119,
|
|
4343
|
+
// i32.rotl
|
|
4344
|
+
115,
|
|
4345
|
+
// i32.xor
|
|
4346
|
+
32,
|
|
4347
|
+
4,
|
|
4348
|
+
// local.get 4 (w0)
|
|
4349
|
+
115,
|
|
4350
|
+
// i32.xor
|
|
4351
|
+
33,
|
|
4352
|
+
12,
|
|
4353
|
+
// local.set 12 (gMask)
|
|
4354
|
+
// Reconstruct pcMask -> local 13
|
|
4355
|
+
32,
|
|
4356
|
+
3,
|
|
4357
|
+
// local.get 3 (ptr)
|
|
4358
|
+
40,
|
|
4359
|
+
2,
|
|
4360
|
+
24,
|
|
4361
|
+
// i32.load align=2 offset=24 (w6)
|
|
4362
|
+
32,
|
|
4363
|
+
3,
|
|
4364
|
+
// local.get 3 (ptr)
|
|
4365
|
+
40,
|
|
4366
|
+
2,
|
|
4367
|
+
16,
|
|
4368
|
+
// i32.load align=2 offset=16 (w4)
|
|
4369
|
+
65,
|
|
4370
|
+
13,
|
|
4371
|
+
// i32.const 13
|
|
4372
|
+
119,
|
|
4373
|
+
// i32.rotl
|
|
4374
|
+
115,
|
|
4375
|
+
// i32.xor
|
|
4376
|
+
32,
|
|
4377
|
+
5,
|
|
4378
|
+
// local.get 5 (w1)
|
|
4379
|
+
115,
|
|
4380
|
+
// i32.xor
|
|
4381
|
+
33,
|
|
4382
|
+
13,
|
|
4383
|
+
// local.set 13 (pcMask)
|
|
4384
|
+
// x = f ^ sVal ^ k0 ^ (env.g(0) ^ gMask)
|
|
3668
4385
|
32,
|
|
3669
4386
|
0,
|
|
3670
4387
|
// local.get 0 (fnId)
|
|
@@ -3684,6 +4401,11 @@ function generateWasmKdfBinary(seed) {
|
|
|
3684
4401
|
16,
|
|
3685
4402
|
0,
|
|
3686
4403
|
// call 0 (env.g(0))
|
|
4404
|
+
32,
|
|
4405
|
+
12,
|
|
4406
|
+
// local.get 12 (gMask)
|
|
4407
|
+
115,
|
|
4408
|
+
// i32.xor
|
|
3687
4409
|
115,
|
|
3688
4410
|
// i32.xor
|
|
3689
4411
|
34,
|
|
@@ -3717,14 +4439,19 @@ function generateWasmKdfBinary(seed) {
|
|
|
3717
4439
|
// i32.const r1
|
|
3718
4440
|
119,
|
|
3719
4441
|
// i32.rotl
|
|
3720
|
-
// x = env.m(x, shieldHash)
|
|
4442
|
+
// x = env.m(x, shieldHash ^ pcMask)
|
|
3721
4443
|
32,
|
|
3722
4444
|
2,
|
|
3723
4445
|
// local.get 2 (shieldHash)
|
|
4446
|
+
32,
|
|
4447
|
+
13,
|
|
4448
|
+
// local.get 13 (pcMask)
|
|
4449
|
+
115,
|
|
4450
|
+
// i32.xor
|
|
3724
4451
|
16,
|
|
3725
4452
|
1,
|
|
3726
|
-
// call 1 (env.m(x,
|
|
3727
|
-
// x = imul(x ^ h ^ sVal ^ env.g(1), c2)
|
|
4453
|
+
// call 1 (env.m(x, maskedPc))
|
|
4454
|
+
// x = imul(x ^ h ^ sVal ^ (env.g(1) ^ gMask), c2)
|
|
3728
4455
|
32,
|
|
3729
4456
|
2,
|
|
3730
4457
|
// local.get 2 (shieldHash)
|
|
@@ -3741,6 +4468,11 @@ function generateWasmKdfBinary(seed) {
|
|
|
3741
4468
|
16,
|
|
3742
4469
|
0,
|
|
3743
4470
|
// call 0 (env.g(1))
|
|
4471
|
+
32,
|
|
4472
|
+
12,
|
|
4473
|
+
// local.get 12 (gMask)
|
|
4474
|
+
115,
|
|
4475
|
+
// i32.xor
|
|
3744
4476
|
115,
|
|
3745
4477
|
// i32.xor
|
|
3746
4478
|
32,
|
|
@@ -3877,6 +4609,11 @@ function generateWasmKdfBinary(seed) {
|
|
|
3877
4609
|
16,
|
|
3878
4610
|
0,
|
|
3879
4611
|
// call 0 (env.g)
|
|
4612
|
+
65,
|
|
4613
|
+
...encodeSignedLeb128(gMask),
|
|
4614
|
+
// i32.const gMask
|
|
4615
|
+
115,
|
|
4616
|
+
// i32.xor
|
|
3880
4617
|
106,
|
|
3881
4618
|
// i32.add
|
|
3882
4619
|
16,
|
|
@@ -3928,7 +4665,7 @@ function generateWasmKdfBinary(seed) {
|
|
|
3928
4665
|
11
|
|
3929
4666
|
// end func
|
|
3930
4667
|
];
|
|
3931
|
-
const kdfBody = [1,
|
|
4668
|
+
const kdfBody = [1, 11, 127, ...kdfInstructions];
|
|
3932
4669
|
const kdfBodyWithLen = [...encodeUnsignedLeb128(kdfBody.length), ...kdfBody];
|
|
3933
4670
|
const bulkBody = [1, 2, 127, ...bulkMixInstructions];
|
|
3934
4671
|
const bulkBodyWithLen = [...encodeUnsignedLeb128(bulkBody.length), ...bulkBody];
|
|
@@ -3962,27 +4699,23 @@ function generateWasmKdfBinary(seed) {
|
|
|
3962
4699
|
...encodeUnsignedLeb128(typePayload.length),
|
|
3963
4700
|
...typePayload
|
|
3964
4701
|
];
|
|
4702
|
+
const abi = options?.polymorphicAbi ? deriveWasmAbiNames(seed) : null;
|
|
4703
|
+
const envModName = abi ? abi.envMod : "env";
|
|
4704
|
+
const gImportName = abi ? abi.gImport : "g";
|
|
4705
|
+
const mImportName = abi ? abi.mImport : "m";
|
|
3965
4706
|
const importPayload = [
|
|
3966
4707
|
2,
|
|
3967
4708
|
// 2 imports
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
110,
|
|
3971
|
-
118,
|
|
3972
|
-
1,
|
|
3973
|
-
103,
|
|
4709
|
+
...encodeWasmName(envModName),
|
|
4710
|
+
...encodeWasmName(gImportName),
|
|
3974
4711
|
0,
|
|
3975
4712
|
0,
|
|
3976
|
-
//
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
110,
|
|
3980
|
-
118,
|
|
3981
|
-
1,
|
|
3982
|
-
109,
|
|
4713
|
+
// g: func type 0
|
|
4714
|
+
...encodeWasmName(envModName),
|
|
4715
|
+
...encodeWasmName(mImportName),
|
|
3983
4716
|
0,
|
|
3984
4717
|
1
|
|
3985
|
-
//
|
|
4718
|
+
// m: func type 1
|
|
3986
4719
|
];
|
|
3987
4720
|
const importSection = [
|
|
3988
4721
|
2,
|
|
@@ -3996,35 +4729,21 @@ function generateWasmKdfBinary(seed) {
|
|
|
3996
4729
|
...funcPayload
|
|
3997
4730
|
];
|
|
3998
4731
|
const memSection = [5, 3, 1, 0, 1];
|
|
3999
|
-
const
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
0
|
|
4007
|
-
2,
|
|
4008
|
-
// "kdf" -> func 2
|
|
4009
|
-
7,
|
|
4010
|
-
98,
|
|
4011
|
-
117,
|
|
4012
|
-
108,
|
|
4013
|
-
107,
|
|
4014
|
-
77,
|
|
4015
|
-
105,
|
|
4016
|
-
120,
|
|
4017
|
-
0,
|
|
4018
|
-
3,
|
|
4019
|
-
// "bulkMix" -> func 3
|
|
4020
|
-
3,
|
|
4021
|
-
109,
|
|
4022
|
-
101,
|
|
4023
|
-
109,
|
|
4024
|
-
2,
|
|
4025
|
-
0
|
|
4026
|
-
// "mem" -> memory 0
|
|
4732
|
+
const exportSpecs = abi ? [
|
|
4733
|
+
[abi.kdfExport, 0, 2],
|
|
4734
|
+
[abi.bulkMixExport, 0, 3],
|
|
4735
|
+
[abi.memExport, 2, 0]
|
|
4736
|
+
] : [
|
|
4737
|
+
["kdf", 0, 2],
|
|
4738
|
+
["bulkMix", 0, 3],
|
|
4739
|
+
["mem", 2, 0]
|
|
4027
4740
|
];
|
|
4741
|
+
const exportOrder = abi ? abi.exportOrder : [0, 1, 2];
|
|
4742
|
+
const exportPayload = [3];
|
|
4743
|
+
for (const idx of exportOrder) {
|
|
4744
|
+
const [name, kind, targetIdx] = exportSpecs[idx];
|
|
4745
|
+
exportPayload.push(...encodeWasmName(name), kind, targetIdx);
|
|
4746
|
+
}
|
|
4028
4747
|
const exportSection = [
|
|
4029
4748
|
7,
|
|
4030
4749
|
...encodeUnsignedLeb128(exportPayload.length),
|
|
@@ -4041,7 +4760,9 @@ function generateWasmKdfBinary(seed) {
|
|
|
4041
4760
|
...writeI32LE(w1),
|
|
4042
4761
|
...writeI32LE(w2),
|
|
4043
4762
|
...writeI32LE(w3),
|
|
4044
|
-
...writeI32LE(w4)
|
|
4763
|
+
...writeI32LE(w4),
|
|
4764
|
+
...writeI32LE(w5),
|
|
4765
|
+
...writeI32LE(w6)
|
|
4045
4766
|
];
|
|
4046
4767
|
const dataPayload = [
|
|
4047
4768
|
1,
|
|
@@ -4074,20 +4795,22 @@ function generateWasmKdfBinary(seed) {
|
|
|
4074
4795
|
}
|
|
4075
4796
|
function fallbackKdf(fnId, callSiteSalt, shieldHash, seed) {
|
|
4076
4797
|
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
4077
|
-
const { gArr, sOff, rA0, rA1, rA2, rA3 } = deriveWasmHostParams(seed);
|
|
4798
|
+
const { gArr, sOff, rA0, rA1, rA2, rA3, gMask, pcMask } = deriveWasmHostParams(seed);
|
|
4799
|
+
const envG = (slot) => gArr[slot & 3] ^ gMask | 0;
|
|
4078
4800
|
const envM = (acc, pc) => {
|
|
4079
4801
|
const sb0 = Math.imul(167, acc & 255) + sOff & 255;
|
|
4080
4802
|
const sb1 = Math.imul(167, acc >>> 8 & 255) + sOff & 255;
|
|
4081
4803
|
const sb = sb0 ^ sb1 << 8;
|
|
4082
|
-
const
|
|
4804
|
+
const unmaskedPc = pc ^ pcMask | 0;
|
|
4805
|
+
const riv = evalRivestPoly32(acc ^ sb ^ unmaskedPc | 0, rA0, rA1, rA2, rA3) | 0;
|
|
4083
4806
|
return riv ^ gArr[2] | 0;
|
|
4084
4807
|
};
|
|
4085
|
-
let x = fnId ^ sVal ^ k0 ^
|
|
4808
|
+
let x = fnId ^ sVal ^ k0 ^ (envG(0) ^ gMask) | 0;
|
|
4086
4809
|
x = x ^ x >>> 16 | 0;
|
|
4087
4810
|
x = Math.imul(x, c1);
|
|
4088
4811
|
x = rotl32(x ^ callSiteSalt | 0, r1);
|
|
4089
|
-
x = envM(x, shieldHash | 0);
|
|
4090
|
-
x = Math.imul(x ^ shieldHash ^ sVal ^
|
|
4812
|
+
x = envM(x, shieldHash ^ pcMask | 0);
|
|
4813
|
+
x = Math.imul(x ^ shieldHash ^ sVal ^ (envG(1) ^ gMask) | 0, c2);
|
|
4091
4814
|
x = x ^ x >>> 15 | 0;
|
|
4092
4815
|
x = x + rotl32(callSiteSalt ^ k0 | 0, r2) | 0;
|
|
4093
4816
|
x = Math.imul(x, c1);
|
|
@@ -4118,15 +4841,16 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
4118
4841
|
const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
|
|
4119
4842
|
return {
|
|
4120
4843
|
kdfFnName: id,
|
|
4121
|
-
wasmBytes: generateWasmKdfBinary(seed),
|
|
4844
|
+
wasmBytes: generateWasmKdfBinary(seed, { polymorphicAbi: true }),
|
|
4122
4845
|
wasmVarName,
|
|
4123
4846
|
kdfParityVerified: true
|
|
4124
4847
|
};
|
|
4125
4848
|
}
|
|
4126
|
-
const
|
|
4849
|
+
const abi = deriveWasmAbiNames(seed);
|
|
4850
|
+
const wasmBytes = generateWasmKdfBinary(seed, { polymorphicAbi: true });
|
|
4127
4851
|
const byteArrayLiteral = Array.from(wasmBytes).join(",");
|
|
4128
4852
|
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
4129
|
-
const { gArr, sOff, rA0, rA1, rA2, rA3 } = deriveWasmHostParams(seed);
|
|
4853
|
+
const { gArr, sOff, rA0, rA1, rA2, rA3, gMask, pcMask } = deriveWasmHostParams(seed);
|
|
4130
4854
|
const targets = [c1, c2, sVal, k0, r1, r2];
|
|
4131
4855
|
const rivEncodedTargets = targets.map(
|
|
4132
4856
|
(t, j) => invertRivestPoly32((t ^ gArr[j & 3]) >>> 0, rA0, rA1, rA2, rA3) | 0
|
|
@@ -4151,17 +4875,17 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
4151
4875
|
var _tk = ['__','unp','eek_t','ampered'].join('');
|
|
4152
4876
|
var _eG = function(sl) {
|
|
4153
4877
|
var tp = (_G && _G[_tk] === !0) ? 0x5a5b : 0;
|
|
4154
|
-
return (_g[sl & 3] ^ tp) | 0;
|
|
4878
|
+
return (_g[sl & 3] ^ ${gMask} ^ tp) | 0;
|
|
4155
4879
|
};
|
|
4156
4880
|
var _eM = function(acc, pc) {
|
|
4157
4881
|
var sb = _sb(acc) ^ (_sb(acc >>> 8) << 8);
|
|
4158
|
-
return (_evR((acc ^ sb ^ pc) | 0) ^ _g[2]) | 0;
|
|
4882
|
+
return (_evR((acc ^ sb ^ (pc ^ ${pcMask})) | 0) ^ _g[2]) | 0;
|
|
4159
4883
|
};
|
|
4160
4884
|
try {
|
|
4161
4885
|
var ${wasmVarName} = new Uint8Array([${byteArrayLiteral}]);
|
|
4162
4886
|
var _wm${suffix} = new WebAssembly.Module(${wasmVarName});
|
|
4163
|
-
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix}, {
|
|
4164
|
-
${kdfFnName} = _wi${suffix}.exports.
|
|
4887
|
+
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix}, { ${abi.envMod}: { ${abi.gImport}: _eG, ${abi.mImport}: _eM } });
|
|
4888
|
+
${kdfFnName} = _wi${suffix}.exports[${JSON.stringify(abi.kdfExport)}];
|
|
4165
4889
|
} catch (e) {
|
|
4166
4890
|
var _kx = [${rivEncodedTargets.join(",")}];
|
|
4167
4891
|
var _k = [];
|
|
@@ -4175,13 +4899,13 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
4175
4899
|
}
|
|
4176
4900
|
var _m = Math[_p];
|
|
4177
4901
|
${kdfFnName} = function(f, s, h) {
|
|
4178
|
-
var _x = (f ^ _k[2] ^ _k[3] ^ _eG(0)) | 0;
|
|
4902
|
+
var _x = (f ^ _k[2] ^ _k[3] ^ (_eG(0) ^ ${gMask})) | 0;
|
|
4179
4903
|
_x = (_x ^ (_x >>> 16)) | 0;
|
|
4180
4904
|
_x = _m(_x, _k[0]);
|
|
4181
4905
|
var _t0 = _x ^ s, _r1 = _k[4];
|
|
4182
4906
|
_x = (_t0 << _r1) | (_t0 >>> (32 - _r1));
|
|
4183
|
-
_x = _eM(_x, h | 0);
|
|
4184
|
-
_x = _m(_x ^ h ^ _k[2] ^ _eG(1), _k[1]);
|
|
4907
|
+
_x = _eM(_x, (h ^ ${pcMask}) | 0);
|
|
4908
|
+
_x = _m(_x ^ h ^ _k[2] ^ (_eG(1) ^ ${gMask}), _k[1]);
|
|
4185
4909
|
_x = (_x ^ (_x >>> 15)) | 0;
|
|
4186
4910
|
var _u0 = s ^ _k[3], _r2 = _k[5];
|
|
4187
4911
|
_x = (_x + ((_u0 << _r2) | (_u0 >>> (32 - _r2)))) | 0;
|
|
@@ -4447,6 +5171,7 @@ function computeCallSiteSalt(seed, idx) {
|
|
|
4447
5171
|
const [lo, hi] = computeCallSiteSalt64(seed >>> 0, idx >>> 0, seed >>> 0);
|
|
4448
5172
|
return ((lo ^ hi) & 2147483647 | 1) >>> 0;
|
|
4449
5173
|
}
|
|
5174
|
+
var NARROWED_ASYNC_BR_DECL = `var _br=(typeof window<'u'&&typeof document<'u'&&window.document===document&&document.nodeType===9&&document.scripts&&document.scripts.length>0&&document.readyState!=='complete')||(typeof self<'u'&&typeof self.importScripts==='function');`;
|
|
4450
5175
|
function buildRivestDeltaExpr(seed, expectedDelta, varName = "_ed") {
|
|
4451
5176
|
const s = seed >>> 0;
|
|
4452
5177
|
const rA0 = computeFnv1aHash(`riv-a0:${s}`, s) | 0;
|
|
@@ -4473,7 +5198,7 @@ function createSaltedDecryptorFnAst(seed, pChars, expectedDelta, windowKeySymbol
|
|
|
4473
5198
|
} else {
|
|
4474
5199
|
const edInit = buildRivestDeltaExpr(seed, expectedDelta, "_ed");
|
|
4475
5200
|
const hasWindowKey = Boolean(windowKeySymbol);
|
|
4476
|
-
const brDecl = hasWindowKey ?
|
|
5201
|
+
const brDecl = hasWindowKey ? NARROWED_ASYNC_BR_DECL : "";
|
|
4477
5202
|
const svCheck = hasWindowKey ? `(sv===void 0?!_br:sv!==_ed)` : `(sv!==void 0&&sv!==_ed)`;
|
|
4478
5203
|
fBody = `var m=[],c=Function.prototype.toString.call(f),_tk=${tkExpr};for(var h=0x811c9dc5,j=0;j<c.length;j++)h=Math.imul(h^c.charCodeAt(j),0x01000193)>>>0;var A="${safeAlpha}",P="${pChars}";${edInit}return function(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0;` + brDecl + `var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||a._u||0)!==0)||${svCheck};if(!tm&&sv===_ed&&(i in m))return m[i];var d=tm?((_ed^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))&65535):_ed;var q=(h^(""._u||a._u||0)^d)>>>0,p=a[i],o="";if(p)for(var t=q^s^Math.imul(i+1,0x01000193),j=0;j<p.length;j++){t=Math.imul(t^j+1,0x01000193)^0x811c9dc5;var ch=p[j],k=A.indexOf(ch);o+=k<0?ch:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];}if(!tm&&sv===_ed)m[i]=o;return o;};`;
|
|
4479
5204
|
}
|
|
@@ -4572,16 +5297,39 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4572
5297
|
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
4573
5298
|
const shaderPayloads = [];
|
|
4574
5299
|
const shaderTargets = [];
|
|
4575
|
-
|
|
5300
|
+
const interpolatedTemplates = [];
|
|
5301
|
+
let regExpShadowedScopes;
|
|
5302
|
+
const getRegExpShadowedScopes = () => {
|
|
5303
|
+
regExpShadowedScopes ??= collectIdentifierShadowedScopes(ast, "RegExp");
|
|
5304
|
+
return regExpShadowedScopes;
|
|
5305
|
+
};
|
|
5306
|
+
function pushSaltedTarget(rawString, node, parent, extra) {
|
|
5307
|
+
const callSiteIdx = targetsToReplace.length;
|
|
5308
|
+
const [saltLo, saltHi] = computeCallSiteSalt64(
|
|
5309
|
+
seed >>> 0,
|
|
5310
|
+
callSiteIdx >>> 0,
|
|
5311
|
+
seed >>> 0
|
|
5312
|
+
);
|
|
5313
|
+
const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
|
|
5314
|
+
targetsToReplace.push({
|
|
5315
|
+
node,
|
|
5316
|
+
parent,
|
|
5317
|
+
callSiteIdx,
|
|
5318
|
+
localSalt,
|
|
5319
|
+
rawString,
|
|
5320
|
+
...extra
|
|
5321
|
+
});
|
|
5322
|
+
}
|
|
5323
|
+
function processSaltedCandidate(val, node, parent, ancestors, onReplace) {
|
|
4576
5324
|
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
4577
|
-
return;
|
|
5325
|
+
return false;
|
|
4578
5326
|
}
|
|
4579
5327
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
4580
|
-
return;
|
|
5328
|
+
return false;
|
|
4581
5329
|
}
|
|
4582
5330
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
4583
5331
|
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
4584
|
-
return;
|
|
5332
|
+
return false;
|
|
4585
5333
|
}
|
|
4586
5334
|
}
|
|
4587
5335
|
let isHotExempt = false;
|
|
@@ -4608,11 +5356,11 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4608
5356
|
shaderToIndex.set(val, idx);
|
|
4609
5357
|
shaderPayloads.push(val);
|
|
4610
5358
|
}
|
|
4611
|
-
shaderTargets.push({ node, parent, idx });
|
|
4612
|
-
return;
|
|
5359
|
+
shaderTargets.push({ node, parent, idx, ...onReplace ? { onReplace } : {} });
|
|
5360
|
+
return true;
|
|
4613
5361
|
}
|
|
4614
5362
|
if (isHotExempt) {
|
|
4615
|
-
return;
|
|
5363
|
+
return false;
|
|
4616
5364
|
}
|
|
4617
5365
|
if (!shouldEncryptString(
|
|
4618
5366
|
val,
|
|
@@ -4621,25 +5369,33 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4621
5369
|
activeDirectives,
|
|
4622
5370
|
customReserved
|
|
4623
5371
|
)) {
|
|
4624
|
-
return;
|
|
5372
|
+
return false;
|
|
4625
5373
|
}
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
seed >>> 0,
|
|
4629
|
-
callSiteIdx >>> 0,
|
|
4630
|
-
seed >>> 0
|
|
4631
|
-
);
|
|
4632
|
-
const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
|
|
4633
|
-
targetsToReplace.push({
|
|
4634
|
-
node,
|
|
4635
|
-
parent,
|
|
4636
|
-
callSiteIdx,
|
|
4637
|
-
localSalt,
|
|
4638
|
-
rawString: val
|
|
4639
|
-
});
|
|
5374
|
+
pushSaltedTarget(val, node, parent, onReplace ? { onReplace } : void 0);
|
|
5375
|
+
return true;
|
|
4640
5376
|
}
|
|
4641
5377
|
walk3.ancestor(ast, {
|
|
4642
5378
|
Literal(node, ancestors) {
|
|
5379
|
+
if (node.regex) {
|
|
5380
|
+
if (isEligibleSecretRegExp(
|
|
5381
|
+
node,
|
|
5382
|
+
ancestors,
|
|
5383
|
+
hotExemptNodes,
|
|
5384
|
+
exemptSubtreeRoots,
|
|
5385
|
+
getRegExpShadowedScopes
|
|
5386
|
+
)) {
|
|
5387
|
+
pushSaltedTarget(
|
|
5388
|
+
node.regex.pattern,
|
|
5389
|
+
node,
|
|
5390
|
+
ancestors[ancestors.length - 2],
|
|
5391
|
+
{
|
|
5392
|
+
replaceMode: "regexp",
|
|
5393
|
+
flags: node.regex.flags ?? ""
|
|
5394
|
+
}
|
|
5395
|
+
);
|
|
5396
|
+
}
|
|
5397
|
+
return;
|
|
5398
|
+
}
|
|
4643
5399
|
if (typeof node.value !== "string") return;
|
|
4644
5400
|
const val = node.value;
|
|
4645
5401
|
if (activeDirectives.has(val)) return;
|
|
@@ -4660,19 +5416,42 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4660
5416
|
processSaltedCandidate(val, node, parent, ancestors);
|
|
4661
5417
|
},
|
|
4662
5418
|
TemplateLiteral(node, ancestors) {
|
|
4663
|
-
if (!node.quasis || node.quasis.length
|
|
4664
|
-
if (node.expressions && node.expressions.length !== 0) return;
|
|
4665
|
-
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
4666
|
-
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
5419
|
+
if (!Array.isArray(node.quasis) || node.quasis.length === 0) return;
|
|
4667
5420
|
const parent = ancestors[ancestors.length - 2];
|
|
4668
|
-
if (
|
|
4669
|
-
|
|
5421
|
+
if (isExemptTemplateLiteral(node, parent)) return;
|
|
5422
|
+
const exprCount = Array.isArray(node.expressions) ? node.expressions.length : 0;
|
|
5423
|
+
if (exprCount === 0) {
|
|
5424
|
+
if (node.quasis.length !== 1) return;
|
|
5425
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
5426
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
5427
|
+
processSaltedCandidate(val, node, parent, ancestors);
|
|
4670
5428
|
return;
|
|
4671
5429
|
}
|
|
4672
|
-
if (
|
|
5430
|
+
if (node.quasis.length !== exprCount + 1) return;
|
|
5431
|
+
if (node.quasis.some((q) => typeof q?.value?.cooked !== "string")) {
|
|
4673
5432
|
return;
|
|
4674
5433
|
}
|
|
4675
|
-
|
|
5434
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
5435
|
+
let queuedCount = 0;
|
|
5436
|
+
for (let qIdx = 0; qIdx < node.quasis.length; qIdx++) {
|
|
5437
|
+
const val = node.quasis[qIdx].value.cooked;
|
|
5438
|
+
if (activeDirectives.has(val)) continue;
|
|
5439
|
+
const queued = processSaltedCandidate(
|
|
5440
|
+
val,
|
|
5441
|
+
node,
|
|
5442
|
+
parent,
|
|
5443
|
+
ancestors,
|
|
5444
|
+
(exprAst) => {
|
|
5445
|
+
replacements.set(qIdx, exprAst);
|
|
5446
|
+
}
|
|
5447
|
+
);
|
|
5448
|
+
if (queued) {
|
|
5449
|
+
queuedCount++;
|
|
5450
|
+
}
|
|
5451
|
+
}
|
|
5452
|
+
if (queuedCount > 0) {
|
|
5453
|
+
interpolatedTemplates.push({ node, replacements });
|
|
5454
|
+
}
|
|
4676
5455
|
}
|
|
4677
5456
|
});
|
|
4678
5457
|
if (targetsToReplace.length === 0 && shaderTargets.length === 0) {
|
|
@@ -4687,6 +5466,17 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4687
5466
|
let vaultVarName = "";
|
|
4688
5467
|
let decryptFnName = "";
|
|
4689
5468
|
let integrityToken = computeFnv1aHash("empty-salted", seed);
|
|
5469
|
+
const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
5470
|
+
let expDelta = expectedDelta;
|
|
5471
|
+
if (shieldCoupled && expDelta === void 0) {
|
|
5472
|
+
const shield = generateRuntimeShield({
|
|
5473
|
+
seed,
|
|
5474
|
+
windowKeySymbol: sym,
|
|
5475
|
+
deterrentMode: deterrentMode ?? "passive",
|
|
5476
|
+
detectHeadless
|
|
5477
|
+
});
|
|
5478
|
+
expDelta = shield.expectedDelta ?? 0;
|
|
5479
|
+
}
|
|
4690
5480
|
if (targetsToReplace.length > 0) {
|
|
4691
5481
|
const wasmResult = injectWasmVault(ast, seed);
|
|
4692
5482
|
const kdfFnName = wasmResult.kdfFnName;
|
|
@@ -4695,17 +5485,6 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4695
5485
|
const cacheVarName = `_uCache${suffix}`;
|
|
4696
5486
|
const dCacheVarName = `_uDc${suffix}`;
|
|
4697
5487
|
decryptFnName = `_uD${suffix}`;
|
|
4698
|
-
const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
4699
|
-
let expDelta = expectedDelta;
|
|
4700
|
-
if (shieldCoupled && expDelta === void 0) {
|
|
4701
|
-
const shield = generateRuntimeShield({
|
|
4702
|
-
seed,
|
|
4703
|
-
windowKeySymbol: sym,
|
|
4704
|
-
deterrentMode: deterrentMode ?? "passive",
|
|
4705
|
-
detectHeadless
|
|
4706
|
-
});
|
|
4707
|
-
expDelta = shield.expectedDelta ?? 0;
|
|
4708
|
-
}
|
|
4709
5488
|
const propAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(sym) ? `.${sym}` : `[${JSON.stringify(sym)}]`;
|
|
4710
5489
|
const stateSym = `${sym}_s`;
|
|
4711
5490
|
const stateAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(stateSym) ? `.${stateSym}` : `[${JSON.stringify(stateSym)}]`;
|
|
@@ -4719,7 +5498,7 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4719
5498
|
} else {
|
|
4720
5499
|
const edInit = buildRivestDeltaExpr(seed, (expDelta ?? 0) & 65535, "_ed");
|
|
4721
5500
|
const hasWindowKey = Boolean(sym);
|
|
4722
|
-
const brDecl = hasWindowKey ?
|
|
5501
|
+
const brDecl = hasWindowKey ? NARROWED_ASYNC_BR_DECL : "";
|
|
4723
5502
|
const svCheck = hasWindowKey ? `(sv===void 0?!_br:sv!==_ed)` : `(sv!==void 0&&sv!==_ed)`;
|
|
4724
5503
|
helperFnSnippet = `function ${decryptFnName}(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0,_tk=${tkExpr},_dk=${dkExpr};${edInit}` + brDecl + `var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var dv=(G&&G[_dk]!=null?G[_dk]:w&&w[_dk]!=null?w[_dk]:0)|0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||0)!==0)||(dv!==0)||${svCheck};if(!tm&&sv===_ed&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${dCacheVarName}=((h|0)^_ed)|0;}var effD=tm?((${dCacheVarName}^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))|0):${dCacheVarName};var k=${kdfFnName}(i,s,effD);var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}if(!tm&&sv===_ed)${cacheVarName}[i]=o;return o;}`;
|
|
4725
5504
|
}
|
|
@@ -4753,7 +5532,17 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4753
5532
|
],
|
|
4754
5533
|
optional: false
|
|
4755
5534
|
};
|
|
4756
|
-
|
|
5535
|
+
if (target.onReplace) {
|
|
5536
|
+
target.onReplace(callExpr);
|
|
5537
|
+
} else if (target.replaceMode === "regexp") {
|
|
5538
|
+
replaceNodeInParent(
|
|
5539
|
+
target.parent,
|
|
5540
|
+
target.node,
|
|
5541
|
+
createNewRegExpAst(callExpr, target.flags ?? "")
|
|
5542
|
+
);
|
|
5543
|
+
} else {
|
|
5544
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
5545
|
+
}
|
|
4757
5546
|
}
|
|
4758
5547
|
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
4759
5548
|
integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
@@ -4783,12 +5572,19 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4783
5572
|
],
|
|
4784
5573
|
optional: false
|
|
4785
5574
|
};
|
|
4786
|
-
|
|
5575
|
+
if (target.onReplace) {
|
|
5576
|
+
target.onReplace(callExpr);
|
|
5577
|
+
} else {
|
|
5578
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
5579
|
+
}
|
|
4787
5580
|
}
|
|
4788
5581
|
const shaderHelperStmt = createShaderVaultAst(
|
|
4789
5582
|
shaderVarName,
|
|
4790
5583
|
shaderPayloads,
|
|
4791
|
-
seed
|
|
5584
|
+
seed,
|
|
5585
|
+
sym,
|
|
5586
|
+
expDelta,
|
|
5587
|
+
shieldCoupled
|
|
4792
5588
|
);
|
|
4793
5589
|
const shaderInsertIdx = findVaultInsertIndex(ast, activeDirectives);
|
|
4794
5590
|
ast.body.splice(shaderInsertIdx, 0, shaderHelperStmt);
|
|
@@ -4796,6 +5592,7 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4796
5592
|
integrityToken = computeFnv1aHash(JSON.stringify(shaderPayloads), seed);
|
|
4797
5593
|
}
|
|
4798
5594
|
}
|
|
5595
|
+
rebuildInterpolatedTemplates(interpolatedTemplates);
|
|
4799
5596
|
return {
|
|
4800
5597
|
encryptedStringsCount: targetsToReplace.length,
|
|
4801
5598
|
integrityToken,
|
|
@@ -4805,18 +5602,145 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4805
5602
|
};
|
|
4806
5603
|
}
|
|
4807
5604
|
|
|
4808
|
-
// src/ast/
|
|
4809
|
-
var
|
|
4810
|
-
var
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
5605
|
+
// src/ast/secret-patterns.ts
|
|
5606
|
+
var PEM_HEADER_RE = /-----BEGIN\s+[A-Z0-9 ]+-----/;
|
|
5607
|
+
var PEM_REGEX_HEADER_RE = /-----BEGIN(?:\s|\\s[+*?]?)+(?:[A-Z0-9 ]|\\s[+*?]?)+-----/;
|
|
5608
|
+
var TOKEN_PREFIX_RE = /\b(?:sk_live_|sk_test_|pk_live_|ghp_|gho_|github_pat_|xox[baprs]-|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z_-]{35}|FLAG\{[^}]{4,}\}|eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,})/;
|
|
5609
|
+
var ESCAPED_FLAG_REGEX_RE = /\bFLAG\\\{[^}]{4,}\\\}/;
|
|
5610
|
+
var HEX_RE = /^[0-9a-fA-F]+$/;
|
|
5611
|
+
var BASE64_RE = /^[A-Za-z0-9+/]+=*$/;
|
|
5612
|
+
var TOKEN_CHARSET_RE = /^[A-Za-z0-9_\-+/=.~:@!#$%^&*]+$/;
|
|
5613
|
+
var PATH_LIKE_RE = /^(?:\.{1,2}\/|@[\w.-]+\/)|\.(?:[cm]?[jt]sx?|json|css|map|wasm|html?|node|svg|png|jpe?g|gif|woff2?|ttf|md|txt|ya?ml|toml|lock)$/i;
|
|
5614
|
+
var REGEX_CHAR_CLASS_RE = /\[(?:\\[\s\S]|[^\]\\])*\]/g;
|
|
5615
|
+
var REGEX_META_SPLIT_RE = /\(\?(?:<[=!]|<[^>]+>|[:=!])?|\\[\s\S]|[\s^$.*+?()[\]{}|/]+/;
|
|
5616
|
+
var COMMON_BIGRAMS = new Set(
|
|
5617
|
+
"th he in er an re on at en nd ti es or te of ed is it al ar st to nt ng se ha as ou io le ve co me de hi ri ro ic ne ea ra ce li ch ll be ma si om ur ca el ta la ns ge ec ct pe ol un il us ss ac em tr pr po fi ad lo ut id pa so mo wi no di ee ul et ai rs oo ex".split(" ")
|
|
5618
|
+
);
|
|
5619
|
+
var COMMON_BIGRAM_CHANCE = COMMON_BIGRAMS.size / 676;
|
|
5620
|
+
var NATURAL_TEXT_Z = 3.5;
|
|
5621
|
+
function isAsciiLetter(code) {
|
|
5622
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
5623
|
+
}
|
|
5624
|
+
function isBinaryOrWasmPrefix(value) {
|
|
5625
|
+
return value.startsWith("AGFzbQE") || /^data:/i.test(value);
|
|
5626
|
+
}
|
|
5627
|
+
function countBase64MarkerRatio(value) {
|
|
5628
|
+
let hits = 0;
|
|
5629
|
+
for (let i = 0; i < value.length; i++) {
|
|
5630
|
+
const code = value.charCodeAt(i);
|
|
5631
|
+
if (code >= 48 && code <= 57 || // 0-9
|
|
5632
|
+
code === 43 || // +
|
|
5633
|
+
code === 47 || // /
|
|
5634
|
+
code === 61) {
|
|
5635
|
+
hits += 1;
|
|
5636
|
+
}
|
|
5637
|
+
}
|
|
5638
|
+
return hits / value.length;
|
|
5639
|
+
}
|
|
5640
|
+
function shannonEntropy(value) {
|
|
5641
|
+
if (value.length === 0) return 0;
|
|
5642
|
+
const counts = /* @__PURE__ */ new Map();
|
|
5643
|
+
for (let i = 0; i < value.length; i++) {
|
|
5644
|
+
const code = value.charCodeAt(i);
|
|
5645
|
+
counts.set(code, (counts.get(code) ?? 0) + 1);
|
|
5646
|
+
}
|
|
5647
|
+
let h = 0;
|
|
5648
|
+
for (const count of counts.values()) {
|
|
5649
|
+
const p = count / value.length;
|
|
5650
|
+
h -= p * Math.log2(p);
|
|
5651
|
+
}
|
|
5652
|
+
return h;
|
|
5653
|
+
}
|
|
5654
|
+
function isSequentialAlphabet(value) {
|
|
5655
|
+
if (value.length < 8) return false;
|
|
5656
|
+
let ascending = 0;
|
|
5657
|
+
for (let i = 1; i < value.length; i++) {
|
|
5658
|
+
if (value.charCodeAt(i) - value.charCodeAt(i - 1) === 1) {
|
|
5659
|
+
ascending += 1;
|
|
5660
|
+
}
|
|
5661
|
+
}
|
|
5662
|
+
return ascending / (value.length - 1) >= 0.6;
|
|
5663
|
+
}
|
|
5664
|
+
function looksLikeNaturalText(value) {
|
|
5665
|
+
let pairs = 0;
|
|
5666
|
+
let hits = 0;
|
|
5667
|
+
const lower = value.toLowerCase();
|
|
5668
|
+
for (let i = 1; i < value.length; i++) {
|
|
5669
|
+
const a = value.charCodeAt(i - 1);
|
|
5670
|
+
const b = value.charCodeAt(i);
|
|
5671
|
+
if (!isAsciiLetter(a) || !isAsciiLetter(b)) continue;
|
|
5672
|
+
pairs += 1;
|
|
5673
|
+
if (a >= 97 && b <= 90) continue;
|
|
5674
|
+
if (COMMON_BIGRAMS.has(lower[i - 1] + lower[i])) {
|
|
5675
|
+
hits += 1;
|
|
5676
|
+
}
|
|
5677
|
+
}
|
|
5678
|
+
if (pairs < 4) return false;
|
|
5679
|
+
const expected = COMMON_BIGRAM_CHANCE * pairs;
|
|
5680
|
+
const deviation = Math.sqrt(
|
|
5681
|
+
pairs * COMMON_BIGRAM_CHANCE * (1 - COMMON_BIGRAM_CHANCE)
|
|
5682
|
+
);
|
|
5683
|
+
return (hits - expected) / deviation >= NATURAL_TEXT_Z;
|
|
5684
|
+
}
|
|
5685
|
+
function classifyPlaintextSecret(value) {
|
|
5686
|
+
if (typeof value !== "string" || value.length < 8) return null;
|
|
5687
|
+
if (isBinaryOrWasmPrefix(value)) return null;
|
|
5688
|
+
if (PATH_LIKE_RE.test(value)) return null;
|
|
5689
|
+
const entropy = shannonEntropy(value);
|
|
5690
|
+
if (PEM_HEADER_RE.test(value)) {
|
|
5691
|
+
return { category: "pem-header", entropy };
|
|
5692
|
+
}
|
|
5693
|
+
if (TOKEN_PREFIX_RE.test(value)) {
|
|
5694
|
+
return { category: "token-prefix", entropy };
|
|
5695
|
+
}
|
|
5696
|
+
if (isSequentialAlphabet(value)) {
|
|
5697
|
+
return null;
|
|
5698
|
+
}
|
|
5699
|
+
const isHex = value.length >= 24 && value.length % 2 === 0 && HEX_RE.test(value) && entropy >= 3.2;
|
|
5700
|
+
if (isHex) {
|
|
5701
|
+
return { category: "hex-or-base64", entropy };
|
|
5702
|
+
}
|
|
5703
|
+
const isBase64Like = value.length >= 28 && BASE64_RE.test(value) && countBase64MarkerRatio(value) >= 0.15 && !looksLikeNaturalText(value) && entropy >= 4;
|
|
5704
|
+
if (isBase64Like) {
|
|
5705
|
+
return { category: "hex-or-base64", entropy };
|
|
5706
|
+
}
|
|
5707
|
+
if (value.length >= 20 && value.length <= 512 && TOKEN_CHARSET_RE.test(value) && !looksLikeNaturalText(value) && entropy >= 4.1) {
|
|
5708
|
+
return { category: "high-entropy", entropy };
|
|
5709
|
+
}
|
|
5710
|
+
return null;
|
|
5711
|
+
}
|
|
5712
|
+
function isLikelySecretLiteral(value) {
|
|
5713
|
+
return classifyPlaintextSecret(value) !== null;
|
|
5714
|
+
}
|
|
5715
|
+
function hasRegexSecretRun(pattern) {
|
|
5716
|
+
if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 4096) {
|
|
5717
|
+
return false;
|
|
5718
|
+
}
|
|
5719
|
+
if (PEM_HEADER_RE.test(pattern) || PEM_REGEX_HEADER_RE.test(pattern) || TOKEN_PREFIX_RE.test(pattern) || ESCAPED_FLAG_REGEX_RE.test(pattern)) {
|
|
5720
|
+
return true;
|
|
5721
|
+
}
|
|
5722
|
+
const outsideClasses = pattern.replace(REGEX_CHAR_CLASS_RE, " ");
|
|
5723
|
+
const parts = outsideClasses.split(REGEX_META_SPLIT_RE);
|
|
5724
|
+
for (const part of parts) {
|
|
5725
|
+
if (part.length >= 20 && isLikelySecretLiteral(part)) {
|
|
5726
|
+
return true;
|
|
5727
|
+
}
|
|
5728
|
+
}
|
|
5729
|
+
return false;
|
|
5730
|
+
}
|
|
5731
|
+
|
|
5732
|
+
// src/ast/string-vault.ts
|
|
5733
|
+
var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
|
|
5734
|
+
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
5735
|
+
"use strict",
|
|
5736
|
+
"use client",
|
|
5737
|
+
"use server",
|
|
5738
|
+
"use asm",
|
|
5739
|
+
"use cache",
|
|
5740
|
+
"use worklet",
|
|
5741
|
+
"use worker",
|
|
5742
|
+
"use memo"
|
|
5743
|
+
]);
|
|
4820
5744
|
var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
|
|
4821
5745
|
"id",
|
|
4822
5746
|
"type",
|
|
@@ -4950,6 +5874,7 @@ function isAdversaryDecoy(val, seed) {
|
|
|
4950
5874
|
}
|
|
4951
5875
|
function isEligibleHotLiteral(val, node, parent, ancestors, minLen, seed = 2654435769, customReserved, activeDirectives = DIRECTIVE_STRINGS, semanticAnchorPatterns, excludeUiClasses = true) {
|
|
4952
5876
|
if (val.length < minLen || activeDirectives.has(val)) return false;
|
|
5877
|
+
if (isBinaryOrBase64Payload(val)) return false;
|
|
4953
5878
|
if (isReactDomSpecialProp(val, node, parent, customReserved)) return false;
|
|
4954
5879
|
if (isTailwindNoise(val)) return false;
|
|
4955
5880
|
if (isSvgPathString(val, parent)) return false;
|
|
@@ -4977,11 +5902,7 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen, seed = 26544
|
|
|
4977
5902
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
4978
5903
|
const a = ancestors[i];
|
|
4979
5904
|
if (a.type === "FunctionDeclaration" || a.type === "FunctionExpression" || a.type === "ArrowFunctionExpression") {
|
|
4980
|
-
if (
|
|
4981
|
-
isInsideRender = true;
|
|
4982
|
-
break;
|
|
4983
|
-
}
|
|
4984
|
-
if (a._unpeekIsComponent) {
|
|
5905
|
+
if (Boolean(a._unpeekIsComponent)) {
|
|
4985
5906
|
isInsideRender = true;
|
|
4986
5907
|
break;
|
|
4987
5908
|
}
|
|
@@ -5014,7 +5935,18 @@ function isInsideLoopOrSerialized(ancestors) {
|
|
|
5014
5935
|
}
|
|
5015
5936
|
return false;
|
|
5016
5937
|
}
|
|
5938
|
+
var BINARY_DATA_URI_RE = /^data:(?:application\/(?:wasm|octet-stream|pdf|zip|gzip|font-[a-z0-9-]+)|image\/|font\/|audio\/|video\/)/i;
|
|
5939
|
+
var PURE_BASE64_RE = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
5940
|
+
function isBinaryOrBase64Payload(val) {
|
|
5941
|
+
if (val.startsWith("AGFzbQE")) return true;
|
|
5942
|
+
if (BINARY_DATA_URI_RE.test(val)) return true;
|
|
5943
|
+
if (val.length >= 4096 && !/\s/.test(val) && PURE_BASE64_RE.test(val)) {
|
|
5944
|
+
return true;
|
|
5945
|
+
}
|
|
5946
|
+
return false;
|
|
5947
|
+
}
|
|
5017
5948
|
function isShaderPayload(val, node, parent, ancestors, seed, isHotExempt, customReserved) {
|
|
5949
|
+
if (isBinaryOrBase64Payload(val)) return false;
|
|
5018
5950
|
if (isInsideLoopOrSerialized(ancestors)) return false;
|
|
5019
5951
|
if (parent?.type === "Property" && parent.key === node && !parent.computed) return false;
|
|
5020
5952
|
if (isReservedProp(val, customReserved)) return false;
|
|
@@ -5044,6 +5976,7 @@ function findVaultInsertIndex(ast, activeDirectives = DIRECTIVE_STRINGS) {
|
|
|
5044
5976
|
}
|
|
5045
5977
|
function shouldEncryptString(val, minLen, parent, activeDirectives = DIRECTIVE_STRINGS, customReserved) {
|
|
5046
5978
|
if (val.length < minLen || activeDirectives.has(val)) return false;
|
|
5979
|
+
if (isBinaryOrBase64Payload(val)) return false;
|
|
5047
5980
|
if (isReservedProp(val, customReserved)) return false;
|
|
5048
5981
|
if (isSvgPathString(val, parent)) return false;
|
|
5049
5982
|
if (isTailwindNoise(val)) return false;
|
|
@@ -5111,9 +6044,31 @@ function uint8ArrayToBase64(bytes) {
|
|
|
5111
6044
|
}
|
|
5112
6045
|
throw new Error("No base64 encoder available in this environment");
|
|
5113
6046
|
}
|
|
5114
|
-
function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
6047
|
+
function createShaderVaultAst(shaderVarName, shaderPayloads, seed, windowKeySymbol, expectedDelta, shieldCoupled = false) {
|
|
5115
6048
|
const sSeed = seed >>> 0;
|
|
5116
|
-
|
|
6049
|
+
let fnCode;
|
|
6050
|
+
let ed = 0;
|
|
6051
|
+
if (!shieldCoupled) {
|
|
6052
|
+
fnCode = `(function f(B){var c=Function.prototype.toString.call(f),h=0x811c9dc5;for(var i=0;i<c.length;i++)h=Math.imul(h^c.charCodeAt(i),0x01000193)>>>0;var S=h^${sSeed},b=B.map(function(s){var n=typeof atob=="function"?atob(s):typeof Buffer<"u"?Buffer.from(s,"base64").toString("binary"):"",u=new Uint8Array(n.length);for(var i=0;i<n.length;i++)u[i]=n.charCodeAt(i);return u;}),d=typeof TextDecoder<"u"?new TextDecoder():null;function x(u,i){for(var r=(S^Math.imul(i+1,0x9e3779b1))|0,j=0;j<u.length;j++){r=(Math.imul(r^(j+1),0x45d9f3b)+0x85ebca6b)|0;u[j]^=(r>>>16)&255;}}return function(i){var u=b[i];x(u,i);try{return d?d.decode(u):String.fromCharCode.apply(null,u);}finally{x(u,i);}};})`;
|
|
6053
|
+
} else {
|
|
6054
|
+
const sym = windowKeySymbol ?? deriveWindowKeySymbol(sSeed);
|
|
6055
|
+
let expDelta = expectedDelta;
|
|
6056
|
+
if (expDelta === void 0) {
|
|
6057
|
+
expDelta = generateRuntimeShield({
|
|
6058
|
+
seed: sSeed,
|
|
6059
|
+
windowKeySymbol: sym
|
|
6060
|
+
}).expectedDelta ?? 0;
|
|
6061
|
+
}
|
|
6062
|
+
ed = expDelta & 65535;
|
|
6063
|
+
const edInit = buildRivestDeltaExpr(sSeed, ed, "_ed");
|
|
6064
|
+
const propAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(sym) ? `.${sym}` : `[${JSON.stringify(sym)}]`;
|
|
6065
|
+
const stateSym = `${sym}_s`;
|
|
6066
|
+
const stateAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(stateSym) ? `.${stateSym}` : `[${JSON.stringify(stateSym)}]`;
|
|
6067
|
+
const flagSym = `${sym}_t`;
|
|
6068
|
+
const flagAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(flagSym) ? `.${flagSym}` : `[${JSON.stringify(flagSym)}]`;
|
|
6069
|
+
const tkExpr = `['__','unp','eek_t','ampered'].join('')`;
|
|
6070
|
+
fnCode = `(function f(B){var c=Function.prototype.toString.call(f),h=0x811c9dc5;for(var i=0;i<c.length;i++)h=Math.imul(h^c.charCodeAt(i),0x01000193)>>>0;${edInit}var _tk=${tkExpr},_sc=[],b=B.map(function(s){var n=typeof atob=="function"?atob(s):typeof Buffer<"u"?Buffer.from(s,"base64").toString("binary"):"",u=new Uint8Array(n.length);for(var i=0;i<n.length;i++)u[i]=n.charCodeAt(i);return u;}),d=typeof TextDecoder<"u"?new TextDecoder():null;function x(u,i,S){for(var r=(S^Math.imul(i+1,0x9e3779b1))|0,j=0;j<u.length;j++){r=(Math.imul(r^(j+1),0x45d9f3b)+0x85ebca6b)|0;u[j]^=(r>>>16)&255;}}return function(i){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0;${NARROWED_ASYNC_BR_DECL}var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||0)!==0)||(sv===void 0?!_br:sv!==_ed);if(!tm&&sv===_ed&&(i in _sc))return _sc[i];var S=(h^${sSeed}^_ed^(tm?(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1):0))>>>0;var u=b[i];x(u,i,S);try{var o=d?d.decode(u):String.fromCharCode.apply(null,u);if(!tm&&sv===_ed)_sc[i]=o;return o;}finally{x(u,i,S);}};})`;
|
|
6071
|
+
}
|
|
5117
6072
|
const parsedProgram = acorn4.parse(fnCode, {
|
|
5118
6073
|
ecmaVersion: "latest",
|
|
5119
6074
|
sourceType: "script"
|
|
@@ -5121,7 +6076,7 @@ function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
|
5121
6076
|
const firstStmt = parsedProgram.body[0];
|
|
5122
6077
|
const fnAst = firstStmt.expression;
|
|
5123
6078
|
const buildH = computeIntegrityHash(generateCompactJs(fnAst), 0);
|
|
5124
|
-
const S = (buildH ^ sSeed) >>> 0;
|
|
6079
|
+
const S = (buildH ^ sSeed ^ (shieldCoupled ? ed : 0)) >>> 0;
|
|
5125
6080
|
const textEncoder = new TextEncoder();
|
|
5126
6081
|
const b64List = [];
|
|
5127
6082
|
for (let idx = 0; idx < shaderPayloads.length; idx++) {
|
|
@@ -5161,6 +6116,222 @@ function findLowestCommonScope(ast, chains) {
|
|
|
5161
6116
|
}
|
|
5162
6117
|
return lca[lca.length - 1] ?? ast;
|
|
5163
6118
|
}
|
|
6119
|
+
function isExemptTemplateLiteral(node, parent) {
|
|
6120
|
+
if (!parent) return true;
|
|
6121
|
+
if (parent.type === "TaggedTemplateExpression" && parent.quasi === node) {
|
|
6122
|
+
return true;
|
|
6123
|
+
}
|
|
6124
|
+
if (parent.type === "ImportExpression" && parent.source === node) {
|
|
6125
|
+
return true;
|
|
6126
|
+
}
|
|
6127
|
+
return false;
|
|
6128
|
+
}
|
|
6129
|
+
function rebuildInterpolatedTemplates(plans) {
|
|
6130
|
+
for (const { node, replacements } of plans) {
|
|
6131
|
+
if (replacements.size === 0) continue;
|
|
6132
|
+
const origQuasis = node.quasis;
|
|
6133
|
+
const origExprs = node.expressions;
|
|
6134
|
+
const nextQuasis = [];
|
|
6135
|
+
const nextExprs = [];
|
|
6136
|
+
let pendingRaw = "";
|
|
6137
|
+
let pendingCooked = "";
|
|
6138
|
+
const flushQuasi = (tail) => {
|
|
6139
|
+
nextQuasis.push({
|
|
6140
|
+
type: "TemplateElement",
|
|
6141
|
+
value: { raw: pendingRaw, cooked: pendingCooked },
|
|
6142
|
+
tail
|
|
6143
|
+
});
|
|
6144
|
+
pendingRaw = "";
|
|
6145
|
+
pendingCooked = "";
|
|
6146
|
+
};
|
|
6147
|
+
for (let i = 0; i < origQuasis.length; i++) {
|
|
6148
|
+
const quasi = origQuasis[i];
|
|
6149
|
+
const replacement = replacements.get(i);
|
|
6150
|
+
if (replacement !== void 0) {
|
|
6151
|
+
flushQuasi(false);
|
|
6152
|
+
nextExprs.push(replacement);
|
|
6153
|
+
} else {
|
|
6154
|
+
pendingRaw += quasi.value?.raw ?? "";
|
|
6155
|
+
pendingCooked += quasi.value?.cooked ?? "";
|
|
6156
|
+
}
|
|
6157
|
+
if (i < origExprs.length) {
|
|
6158
|
+
flushQuasi(false);
|
|
6159
|
+
nextExprs.push(origExprs[i]);
|
|
6160
|
+
}
|
|
6161
|
+
}
|
|
6162
|
+
flushQuasi(true);
|
|
6163
|
+
node.quasis = nextQuasis;
|
|
6164
|
+
node.expressions = nextExprs;
|
|
6165
|
+
}
|
|
6166
|
+
}
|
|
6167
|
+
function createNewRegExpAst(sourceExpr, flags) {
|
|
6168
|
+
return {
|
|
6169
|
+
type: "NewExpression",
|
|
6170
|
+
callee: { type: "Identifier", name: "RegExp" },
|
|
6171
|
+
arguments: flags.length > 0 ? [
|
|
6172
|
+
sourceExpr,
|
|
6173
|
+
{
|
|
6174
|
+
type: "Literal",
|
|
6175
|
+
value: flags,
|
|
6176
|
+
raw: JSON.stringify(flags)
|
|
6177
|
+
}
|
|
6178
|
+
] : [sourceExpr]
|
|
6179
|
+
};
|
|
6180
|
+
}
|
|
6181
|
+
function mutateNodeToNewRegExp(node, sourceExpr, flags) {
|
|
6182
|
+
const newExpr = createNewRegExpAst(sourceExpr, flags);
|
|
6183
|
+
node.type = "NewExpression";
|
|
6184
|
+
node.callee = newExpr.callee;
|
|
6185
|
+
node.arguments = newExpr.arguments;
|
|
6186
|
+
delete node.value;
|
|
6187
|
+
delete node.raw;
|
|
6188
|
+
delete node.regex;
|
|
6189
|
+
delete node.optional;
|
|
6190
|
+
}
|
|
6191
|
+
var SCOPE_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
6192
|
+
"FunctionDeclaration",
|
|
6193
|
+
"FunctionExpression",
|
|
6194
|
+
"ArrowFunctionExpression"
|
|
6195
|
+
]);
|
|
6196
|
+
var SCOPE_LEXICAL_TYPES = /* @__PURE__ */ new Set([
|
|
6197
|
+
"Program",
|
|
6198
|
+
"FunctionDeclaration",
|
|
6199
|
+
"FunctionExpression",
|
|
6200
|
+
"ArrowFunctionExpression",
|
|
6201
|
+
"BlockStatement",
|
|
6202
|
+
"ForStatement",
|
|
6203
|
+
"ForInStatement",
|
|
6204
|
+
"ForOfStatement",
|
|
6205
|
+
"SwitchStatement",
|
|
6206
|
+
"CatchClause",
|
|
6207
|
+
"ClassDeclaration",
|
|
6208
|
+
"ClassExpression",
|
|
6209
|
+
"StaticBlock"
|
|
6210
|
+
]);
|
|
6211
|
+
function patternContainsIdentifier(pattern, targetName) {
|
|
6212
|
+
if (!pattern || typeof pattern !== "object") return false;
|
|
6213
|
+
switch (pattern.type) {
|
|
6214
|
+
case "Identifier":
|
|
6215
|
+
return pattern.name === targetName;
|
|
6216
|
+
case "AssignmentPattern":
|
|
6217
|
+
return patternContainsIdentifier(pattern.left, targetName);
|
|
6218
|
+
case "RestElement":
|
|
6219
|
+
return patternContainsIdentifier(pattern.argument, targetName);
|
|
6220
|
+
case "ArrayPattern":
|
|
6221
|
+
return (pattern.elements || []).some(
|
|
6222
|
+
(el) => patternContainsIdentifier(el, targetName)
|
|
6223
|
+
);
|
|
6224
|
+
case "ObjectPattern":
|
|
6225
|
+
return (pattern.properties || []).some(
|
|
6226
|
+
(prop) => prop?.type === "Property" ? patternContainsIdentifier(prop.value, targetName) : prop?.type === "RestElement" ? patternContainsIdentifier(prop.argument, targetName) : false
|
|
6227
|
+
);
|
|
6228
|
+
default:
|
|
6229
|
+
return false;
|
|
6230
|
+
}
|
|
6231
|
+
}
|
|
6232
|
+
function findEnclosingScope(ancestors, scopeSet, fallback) {
|
|
6233
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
6234
|
+
if (scopeSet.has(ancestors[i].type)) {
|
|
6235
|
+
return ancestors[i];
|
|
6236
|
+
}
|
|
6237
|
+
}
|
|
6238
|
+
return fallback;
|
|
6239
|
+
}
|
|
6240
|
+
function collectIdentifierShadowedScopes(ast, identName = "RegExp") {
|
|
6241
|
+
const shadowed = /* @__PURE__ */ new WeakSet();
|
|
6242
|
+
walk4.ancestor(ast, {
|
|
6243
|
+
FunctionDeclaration(node, _state, ancestors) {
|
|
6244
|
+
if (node.id?.name === identName) {
|
|
6245
|
+
shadowed.add(
|
|
6246
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
6247
|
+
);
|
|
6248
|
+
shadowed.add(node);
|
|
6249
|
+
}
|
|
6250
|
+
if (Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
6251
|
+
shadowed.add(node);
|
|
6252
|
+
}
|
|
6253
|
+
},
|
|
6254
|
+
FunctionExpression(node) {
|
|
6255
|
+
if (node.id?.name === identName || Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
6256
|
+
shadowed.add(node);
|
|
6257
|
+
}
|
|
6258
|
+
},
|
|
6259
|
+
ArrowFunctionExpression(node) {
|
|
6260
|
+
if (Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
6261
|
+
shadowed.add(node);
|
|
6262
|
+
}
|
|
6263
|
+
},
|
|
6264
|
+
ClassDeclaration(node, _state, ancestors) {
|
|
6265
|
+
if (node.id?.name === identName) {
|
|
6266
|
+
shadowed.add(
|
|
6267
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
6268
|
+
);
|
|
6269
|
+
shadowed.add(node);
|
|
6270
|
+
}
|
|
6271
|
+
},
|
|
6272
|
+
ClassExpression(node) {
|
|
6273
|
+
if (node.id?.name === identName) {
|
|
6274
|
+
shadowed.add(node);
|
|
6275
|
+
}
|
|
6276
|
+
},
|
|
6277
|
+
CatchClause(node) {
|
|
6278
|
+
if (node.param && patternContainsIdentifier(node.param, identName)) {
|
|
6279
|
+
shadowed.add(node);
|
|
6280
|
+
}
|
|
6281
|
+
},
|
|
6282
|
+
WithStatement(node) {
|
|
6283
|
+
shadowed.add(node);
|
|
6284
|
+
},
|
|
6285
|
+
ImportDeclaration(node) {
|
|
6286
|
+
if (Array.isArray(node.specifiers) && node.specifiers.some((s) => s?.local?.name === identName)) {
|
|
6287
|
+
shadowed.add(ast);
|
|
6288
|
+
}
|
|
6289
|
+
},
|
|
6290
|
+
VariableDeclaration(node, _state, ancestors) {
|
|
6291
|
+
if (!Array.isArray(node.declarations) || !node.declarations.some(
|
|
6292
|
+
(d) => patternContainsIdentifier(d?.id, identName)
|
|
6293
|
+
)) {
|
|
6294
|
+
return;
|
|
6295
|
+
}
|
|
6296
|
+
if (node.kind === "var") {
|
|
6297
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
6298
|
+
const a = ancestors[i];
|
|
6299
|
+
if (SCOPE_FUNCTION_TYPES.has(a.type) || a.type === "StaticBlock" || a.type === "Program") {
|
|
6300
|
+
shadowed.add(a);
|
|
6301
|
+
break;
|
|
6302
|
+
}
|
|
6303
|
+
}
|
|
6304
|
+
} else {
|
|
6305
|
+
shadowed.add(
|
|
6306
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
6307
|
+
);
|
|
6308
|
+
}
|
|
6309
|
+
}
|
|
6310
|
+
});
|
|
6311
|
+
return shadowed;
|
|
6312
|
+
}
|
|
6313
|
+
function isEligibleSecretRegExp(node, ancestors, hotExemptNodes, exemptSubtreeRoots, getShadowedScopes) {
|
|
6314
|
+
const pattern = node?.regex?.pattern;
|
|
6315
|
+
if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 4096) {
|
|
6316
|
+
return false;
|
|
6317
|
+
}
|
|
6318
|
+
if (!hasRegexSecretRun(pattern)) {
|
|
6319
|
+
return false;
|
|
6320
|
+
}
|
|
6321
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
6322
|
+
return false;
|
|
6323
|
+
}
|
|
6324
|
+
if (isInsideLoopOrSerialized(ancestors)) {
|
|
6325
|
+
return false;
|
|
6326
|
+
}
|
|
6327
|
+
if (isNodeInExemptSubtree(ancestors, hotExemptNodes)) {
|
|
6328
|
+
return false;
|
|
6329
|
+
}
|
|
6330
|
+
if (getShadowedScopes && isNodeInExemptSubtree(ancestors, getShadowedScopes())) {
|
|
6331
|
+
return false;
|
|
6332
|
+
}
|
|
6333
|
+
return true;
|
|
6334
|
+
}
|
|
5164
6335
|
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode, config, shieldCoupled = true, detectHeadless = false, exemptSubtreeRoots) {
|
|
5165
6336
|
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
5166
6337
|
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
@@ -5192,7 +6363,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5192
6363
|
}
|
|
5193
6364
|
const alreadyVaulted = ast.body.some(
|
|
5194
6365
|
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
5195
|
-
(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")
|
|
6366
|
+
(d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && (d.id.name.startsWith("_uC") || d.id.name.startsWith("_uD") && !d.id.name.startsWith("_uDec") || 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")
|
|
5196
6367
|
)
|
|
5197
6368
|
);
|
|
5198
6369
|
if (alreadyVaulted) {
|
|
@@ -5222,6 +6393,12 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5222
6393
|
const shaderPayloads = [];
|
|
5223
6394
|
const targetsToReplace = [];
|
|
5224
6395
|
const hotTargetsToReplace = [];
|
|
6396
|
+
const interpolatedTemplates = [];
|
|
6397
|
+
let regExpShadowedScopes;
|
|
6398
|
+
const getRegExpShadowedScopes = () => {
|
|
6399
|
+
regExpShadowedScopes ??= collectIdentifierShadowedScopes(ast, "RegExp");
|
|
6400
|
+
return regExpShadowedScopes;
|
|
6401
|
+
};
|
|
5225
6402
|
const customWalkBase = {
|
|
5226
6403
|
...walk4.base,
|
|
5227
6404
|
Property(node, st, c) {
|
|
@@ -5229,16 +6406,16 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5229
6406
|
if (node.value) c(node.value, st);
|
|
5230
6407
|
}
|
|
5231
6408
|
};
|
|
5232
|
-
function processVaultCandidate(val, node, parent, ancestors) {
|
|
6409
|
+
function processVaultCandidate(val, node, parent, ancestors, onReplace) {
|
|
5233
6410
|
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5234
|
-
return;
|
|
6411
|
+
return false;
|
|
5235
6412
|
}
|
|
5236
6413
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
5237
|
-
return;
|
|
6414
|
+
return false;
|
|
5238
6415
|
}
|
|
5239
6416
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
5240
6417
|
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
5241
|
-
return;
|
|
6418
|
+
return false;
|
|
5242
6419
|
}
|
|
5243
6420
|
}
|
|
5244
6421
|
let isHotExempt = false;
|
|
@@ -5270,9 +6447,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5270
6447
|
node,
|
|
5271
6448
|
parent,
|
|
5272
6449
|
idx: idx2,
|
|
5273
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
6450
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
6451
|
+
...onReplace ? { onReplace } : {}
|
|
5274
6452
|
});
|
|
5275
|
-
return;
|
|
6453
|
+
return true;
|
|
5276
6454
|
}
|
|
5277
6455
|
if (isHotExempt) {
|
|
5278
6456
|
if (isEligibleHotLiteral(
|
|
@@ -5291,10 +6469,12 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5291
6469
|
node,
|
|
5292
6470
|
parent,
|
|
5293
6471
|
val,
|
|
5294
|
-
idx: hotTargetsToReplace.length
|
|
6472
|
+
idx: hotTargetsToReplace.length,
|
|
6473
|
+
...onReplace ? { onReplace } : {}
|
|
5295
6474
|
});
|
|
6475
|
+
return true;
|
|
5296
6476
|
}
|
|
5297
|
-
return;
|
|
6477
|
+
return false;
|
|
5298
6478
|
}
|
|
5299
6479
|
if (!shouldEncryptString(
|
|
5300
6480
|
val,
|
|
@@ -5303,7 +6483,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5303
6483
|
activeDirectives,
|
|
5304
6484
|
customReserved
|
|
5305
6485
|
)) {
|
|
5306
|
-
return;
|
|
6486
|
+
return false;
|
|
5307
6487
|
}
|
|
5308
6488
|
let idx = stringToIndex.get(val);
|
|
5309
6489
|
if (idx === void 0) {
|
|
@@ -5316,13 +6496,44 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5316
6496
|
node,
|
|
5317
6497
|
parent,
|
|
5318
6498
|
idx,
|
|
5319
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
6499
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
6500
|
+
...onReplace ? { onReplace } : {}
|
|
5320
6501
|
});
|
|
6502
|
+
return true;
|
|
5321
6503
|
}
|
|
5322
6504
|
walk4.ancestor(
|
|
5323
6505
|
ast,
|
|
5324
6506
|
{
|
|
5325
6507
|
Literal(node, _state, ancestors) {
|
|
6508
|
+
if (node.regex) {
|
|
6509
|
+
if (isEligibleSecretRegExp(
|
|
6510
|
+
node,
|
|
6511
|
+
ancestors,
|
|
6512
|
+
hotExemptNodes,
|
|
6513
|
+
exemptSubtreeRoots,
|
|
6514
|
+
getRegExpShadowedScopes
|
|
6515
|
+
)) {
|
|
6516
|
+
const pattern = node.regex.pattern;
|
|
6517
|
+
const flags = node.regex.flags ?? "";
|
|
6518
|
+
const parent2 = ancestors[ancestors.length - 2];
|
|
6519
|
+
let idx = stringToIndex.get(pattern);
|
|
6520
|
+
if (idx === void 0) {
|
|
6521
|
+
idx = uniqueStrings.length;
|
|
6522
|
+
stringToIndex.set(pattern, idx);
|
|
6523
|
+
uniqueStrings.push(pattern);
|
|
6524
|
+
}
|
|
6525
|
+
targetsToReplace.push({
|
|
6526
|
+
type: "string",
|
|
6527
|
+
node,
|
|
6528
|
+
parent: parent2,
|
|
6529
|
+
idx,
|
|
6530
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
6531
|
+
replaceMode: "regexp",
|
|
6532
|
+
flags
|
|
6533
|
+
});
|
|
6534
|
+
}
|
|
6535
|
+
return;
|
|
6536
|
+
}
|
|
5326
6537
|
if (typeof node.value !== "string") return;
|
|
5327
6538
|
const val = node.value;
|
|
5328
6539
|
if (activeDirectives.has(val)) return;
|
|
@@ -5340,19 +6551,42 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5340
6551
|
processVaultCandidate(val, node, parent, ancestors);
|
|
5341
6552
|
},
|
|
5342
6553
|
TemplateLiteral(node, _state, ancestors) {
|
|
5343
|
-
if (!node.quasis || node.quasis.length
|
|
5344
|
-
if (node.expressions && node.expressions.length !== 0) return;
|
|
5345
|
-
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
5346
|
-
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
6554
|
+
if (!Array.isArray(node.quasis) || node.quasis.length === 0) return;
|
|
5347
6555
|
const parent = ancestors[ancestors.length - 2];
|
|
5348
|
-
if (
|
|
5349
|
-
|
|
6556
|
+
if (isExemptTemplateLiteral(node, parent)) return;
|
|
6557
|
+
const exprCount = Array.isArray(node.expressions) ? node.expressions.length : 0;
|
|
6558
|
+
if (exprCount === 0) {
|
|
6559
|
+
if (node.quasis.length !== 1) return;
|
|
6560
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
6561
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
6562
|
+
processVaultCandidate(val, node, parent, ancestors);
|
|
5350
6563
|
return;
|
|
5351
6564
|
}
|
|
5352
|
-
if (
|
|
6565
|
+
if (node.quasis.length !== exprCount + 1) return;
|
|
6566
|
+
if (node.quasis.some((q) => typeof q?.value?.cooked !== "string")) {
|
|
5353
6567
|
return;
|
|
5354
6568
|
}
|
|
5355
|
-
|
|
6569
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
6570
|
+
let queuedCount = 0;
|
|
6571
|
+
for (let qIdx = 0; qIdx < node.quasis.length; qIdx++) {
|
|
6572
|
+
const val = node.quasis[qIdx].value.cooked;
|
|
6573
|
+
if (activeDirectives.has(val)) continue;
|
|
6574
|
+
const queued = processVaultCandidate(
|
|
6575
|
+
val,
|
|
6576
|
+
node,
|
|
6577
|
+
parent,
|
|
6578
|
+
ancestors,
|
|
6579
|
+
(exprAst) => {
|
|
6580
|
+
replacements.set(qIdx, exprAst);
|
|
6581
|
+
}
|
|
6582
|
+
);
|
|
6583
|
+
if (queued) {
|
|
6584
|
+
queuedCount++;
|
|
6585
|
+
}
|
|
6586
|
+
}
|
|
6587
|
+
if (queuedCount > 0) {
|
|
6588
|
+
interpolatedTemplates.push({ node, replacements });
|
|
6589
|
+
}
|
|
5356
6590
|
}
|
|
5357
6591
|
},
|
|
5358
6592
|
customWalkBase
|
|
@@ -5364,38 +6598,69 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5364
6598
|
shaderBuffersCount: 0
|
|
5365
6599
|
};
|
|
5366
6600
|
}
|
|
5367
|
-
for (const { node, parent, val, idx } of hotTargetsToReplace) {
|
|
6601
|
+
for (const { node, parent, val, idx, onReplace } of hotTargetsToReplace) {
|
|
5368
6602
|
const key = idx % 3 + 1;
|
|
5369
6603
|
let encodedStr = "";
|
|
5370
6604
|
for (let i = 0; i < val.length; i++) {
|
|
5371
6605
|
encodedStr += String.fromCharCode(val.charCodeAt(i) ^ key);
|
|
5372
6606
|
}
|
|
6607
|
+
const callExpr = {
|
|
6608
|
+
type: "CallExpression",
|
|
6609
|
+
callee: {
|
|
6610
|
+
type: "Identifier",
|
|
6611
|
+
name: "_hX"
|
|
6612
|
+
},
|
|
6613
|
+
arguments: [
|
|
6614
|
+
{
|
|
6615
|
+
type: "Literal",
|
|
6616
|
+
value: encodedStr,
|
|
6617
|
+
raw: JSON.stringify(encodedStr)
|
|
6618
|
+
},
|
|
6619
|
+
{
|
|
6620
|
+
type: "Literal",
|
|
6621
|
+
value: key,
|
|
6622
|
+
raw: String(key)
|
|
6623
|
+
}
|
|
6624
|
+
],
|
|
6625
|
+
optional: false
|
|
6626
|
+
};
|
|
6627
|
+
if (onReplace) {
|
|
6628
|
+
onReplace(callExpr);
|
|
6629
|
+
continue;
|
|
6630
|
+
}
|
|
5373
6631
|
if (parent?.type === "Property" && parent.key === node) {
|
|
5374
6632
|
parent.computed = true;
|
|
5375
6633
|
}
|
|
5376
6634
|
node.type = "CallExpression";
|
|
5377
|
-
node.callee =
|
|
5378
|
-
|
|
5379
|
-
name: "_hX"
|
|
5380
|
-
};
|
|
5381
|
-
node.arguments = [
|
|
5382
|
-
{
|
|
5383
|
-
type: "Literal",
|
|
5384
|
-
value: encodedStr,
|
|
5385
|
-
raw: JSON.stringify(encodedStr)
|
|
5386
|
-
},
|
|
5387
|
-
{
|
|
5388
|
-
type: "Literal",
|
|
5389
|
-
value: key,
|
|
5390
|
-
raw: String(key)
|
|
5391
|
-
}
|
|
5392
|
-
];
|
|
6635
|
+
node.callee = callExpr.callee;
|
|
6636
|
+
node.arguments = callExpr.arguments;
|
|
5393
6637
|
node.optional = false;
|
|
5394
6638
|
delete node.value;
|
|
5395
6639
|
delete node.raw;
|
|
5396
6640
|
delete node.quasis;
|
|
5397
6641
|
delete node.expressions;
|
|
5398
6642
|
}
|
|
6643
|
+
function applyVaultTargetReplacement(target, callExpr) {
|
|
6644
|
+
if (target.onReplace) {
|
|
6645
|
+
target.onReplace(callExpr);
|
|
6646
|
+
return;
|
|
6647
|
+
}
|
|
6648
|
+
if (target.replaceMode === "regexp") {
|
|
6649
|
+
mutateNodeToNewRegExp(target.node, callExpr, target.flags ?? "");
|
|
6650
|
+
return;
|
|
6651
|
+
}
|
|
6652
|
+
if (target.parent?.type === "Property" && target.parent.key === target.node) {
|
|
6653
|
+
target.parent.computed = true;
|
|
6654
|
+
}
|
|
6655
|
+
target.node.type = "CallExpression";
|
|
6656
|
+
target.node.callee = callExpr.callee;
|
|
6657
|
+
target.node.arguments = callExpr.arguments;
|
|
6658
|
+
target.node.optional = false;
|
|
6659
|
+
delete target.node.value;
|
|
6660
|
+
delete target.node.raw;
|
|
6661
|
+
delete target.node.quasis;
|
|
6662
|
+
delete target.node.expressions;
|
|
6663
|
+
}
|
|
5399
6664
|
let insertIdx = findVaultInsertIndex(ast, activeDirectives);
|
|
5400
6665
|
const wantFragmented = Boolean(config?.vault?.fragmented);
|
|
5401
6666
|
let fragCount = Math.max(2, Math.min(8, Math.floor(config?.vault?.fragmentCount ?? 3)));
|
|
@@ -5412,28 +6677,28 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5412
6677
|
);
|
|
5413
6678
|
}
|
|
5414
6679
|
integrityToken = computeFnv1aHash(JSON.stringify(encryptedPayloads), seed);
|
|
5415
|
-
for (const
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
6680
|
+
for (const target of targetsToReplace) {
|
|
6681
|
+
let callExpr;
|
|
6682
|
+
if (target.type === "shader") {
|
|
6683
|
+
callExpr = {
|
|
6684
|
+
type: "CallExpression",
|
|
6685
|
+
callee: { type: "Identifier", name: shaderVarName },
|
|
6686
|
+
arguments: [{ type: "Literal", value: target.idx, raw: String(target.idx) }],
|
|
6687
|
+
optional: false
|
|
6688
|
+
};
|
|
5423
6689
|
} else {
|
|
5424
|
-
const salt = computeCallSiteSalt(seed, idx);
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
delete node.expressions;
|
|
6690
|
+
const salt = computeCallSiteSalt(seed, target.idx);
|
|
6691
|
+
callExpr = {
|
|
6692
|
+
type: "CallExpression",
|
|
6693
|
+
callee: { type: "Identifier", name: decryptFnName },
|
|
6694
|
+
arguments: [
|
|
6695
|
+
{ type: "Literal", value: target.idx, raw: String(target.idx) },
|
|
6696
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
6697
|
+
],
|
|
6698
|
+
optional: false
|
|
6699
|
+
};
|
|
6700
|
+
}
|
|
6701
|
+
applyVaultTargetReplacement(target, callExpr);
|
|
5437
6702
|
}
|
|
5438
6703
|
} else {
|
|
5439
6704
|
const perm = [];
|
|
@@ -5501,31 +6766,31 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5501
6766
|
chains: []
|
|
5502
6767
|
});
|
|
5503
6768
|
}
|
|
5504
|
-
for (const
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
6769
|
+
for (const target of targetsToReplace) {
|
|
6770
|
+
let callExpr;
|
|
6771
|
+
if (target.type === "shader") {
|
|
6772
|
+
callExpr = {
|
|
6773
|
+
type: "CallExpression",
|
|
6774
|
+
callee: { type: "Identifier", name: shaderVarName },
|
|
6775
|
+
arguments: [{ type: "Literal", value: target.idx, raw: String(target.idx) }],
|
|
6776
|
+
optional: false
|
|
6777
|
+
};
|
|
5512
6778
|
} else {
|
|
5513
|
-
const { fragId, localIdx } = stringFragAssign[idx];
|
|
6779
|
+
const { fragId, localIdx } = stringFragAssign[target.idx];
|
|
5514
6780
|
const meta = fragMeta[fragId];
|
|
5515
|
-
meta.chains.push(scopeChain);
|
|
6781
|
+
meta.chains.push(target.scopeChain);
|
|
5516
6782
|
const salt = computeCallSiteSalt(meta.fragSeed, localIdx);
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
delete node.expressions;
|
|
6783
|
+
callExpr = {
|
|
6784
|
+
type: "CallExpression",
|
|
6785
|
+
callee: { type: "Identifier", name: meta.fnName },
|
|
6786
|
+
arguments: [
|
|
6787
|
+
{ type: "Literal", value: localIdx, raw: String(localIdx) },
|
|
6788
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
6789
|
+
],
|
|
6790
|
+
optional: false
|
|
6791
|
+
};
|
|
6792
|
+
}
|
|
6793
|
+
applyVaultTargetReplacement(target, callExpr);
|
|
5529
6794
|
}
|
|
5530
6795
|
const allPayloads = [];
|
|
5531
6796
|
for (const meta of fragMeta) {
|
|
@@ -5548,6 +6813,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5548
6813
|
}
|
|
5549
6814
|
integrityToken = computeFnv1aHash(JSON.stringify(allPayloads), seed);
|
|
5550
6815
|
}
|
|
6816
|
+
rebuildInterpolatedTemplates(interpolatedTemplates);
|
|
5551
6817
|
if (hotTargetsToReplace.length > 0) {
|
|
5552
6818
|
const alreadyHasHx = ast.body.some(
|
|
5553
6819
|
(stmt) => stmt.type === "FunctionDeclaration" && stmt.id?.name === "_hX"
|
|
@@ -5572,7 +6838,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5572
6838
|
const shaderHelperStmt = createShaderVaultAst(
|
|
5573
6839
|
shaderVarName,
|
|
5574
6840
|
shaderPayloads,
|
|
5575
|
-
seed
|
|
6841
|
+
seed,
|
|
6842
|
+
sym,
|
|
6843
|
+
expDelta,
|
|
6844
|
+
shieldCoupled
|
|
5576
6845
|
);
|
|
5577
6846
|
ast.body.splice(insertIdx++, 0, shaderHelperStmt);
|
|
5578
6847
|
}
|
|
@@ -6171,6 +7440,26 @@ function mixSeed32(seed, salt) {
|
|
|
6171
7440
|
h ^= h >>> 16;
|
|
6172
7441
|
return h | 0;
|
|
6173
7442
|
}
|
|
7443
|
+
function modInverseUint32(oddValue) {
|
|
7444
|
+
const m = (oddValue | 1) >>> 0;
|
|
7445
|
+
let inv = 1;
|
|
7446
|
+
for (let i = 0; i < 5; i++) {
|
|
7447
|
+
inv = Math.imul(inv, 2 - Math.imul(m, inv) | 0) >>> 0;
|
|
7448
|
+
}
|
|
7449
|
+
return inv >>> 0;
|
|
7450
|
+
}
|
|
7451
|
+
function deriveAffineMbaParams(seed, salt) {
|
|
7452
|
+
let m = (mixSeed32(seed, salt) | 1) >>> 0;
|
|
7453
|
+
if (m === 1 || m === 4294967295 || m === 2654435769) {
|
|
7454
|
+
m = (m ^ 1540483477 | 1) >>> 0;
|
|
7455
|
+
}
|
|
7456
|
+
const m2 = Math.imul(m, 2) >>> 0;
|
|
7457
|
+
const mInv = modInverseUint32(m);
|
|
7458
|
+
let c = mixSeed32(seed, salt + 40503) >>> 0;
|
|
7459
|
+
if (c === 0) c = 668265263;
|
|
7460
|
+
const d = -Math.imul(mInv, c) >>> 0;
|
|
7461
|
+
return { m, m2, mInv, c, d };
|
|
7462
|
+
}
|
|
6174
7463
|
function cloneNode(node) {
|
|
6175
7464
|
return JSON.parse(JSON.stringify(node));
|
|
6176
7465
|
}
|
|
@@ -6685,28 +7974,158 @@ function buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn = false, ctxOpt
|
|
|
6685
7974
|
return [candidates[0], candidates[1], candidates[2], candidates[3]];
|
|
6686
7975
|
}
|
|
6687
7976
|
var QNR_RESIDUE_FAMILIES = [
|
|
6688
|
-
|
|
6689
|
-
{ add:
|
|
6690
|
-
|
|
6691
|
-
{ add:
|
|
7977
|
+
// LHS in {1, 2}: > 2 is false; ((v ^ (v >> 1)) & 1) === 1
|
|
7978
|
+
{ add: 1, mask: 3, target: 3, outBoundOp: ">", outBoundVal: 2, bitKind: "xor1", expectedBit: 1 },
|
|
7979
|
+
// LHS in {3, 4, 7}: < 3 is false; ((v | (v >> 2)) & 1) === 1
|
|
7980
|
+
{ add: 3, mask: 7, target: 6, outBoundOp: "<", outBoundVal: 3, bitKind: "or2", expectedBit: 1 },
|
|
7981
|
+
// LHS in {1, 5, 6}: > 6 is false; ((v ^ (v >> 1)) & 1) === 1
|
|
7982
|
+
{ add: 5, mask: 7, target: 3, outBoundOp: ">", outBoundVal: 6, bitKind: "xor1", expectedBit: 1 },
|
|
7983
|
+
// LHS in {0, 7, 8, 11}: > 11 is false; ((v ^ (v >> 1)) & 1) === 0
|
|
7984
|
+
{ add: 7, mask: 15, target: 13, outBoundOp: ">", outBoundVal: 11, bitKind: "xor1", expectedBit: 0 }
|
|
6692
7985
|
];
|
|
6693
|
-
function
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
7986
|
+
function makeTypeofGlobalLen() {
|
|
7987
|
+
return {
|
|
7988
|
+
type: "MemberExpression",
|
|
7989
|
+
computed: false,
|
|
7990
|
+
object: makeUnary("typeof", { type: "Identifier", name: "globalThis" }),
|
|
7991
|
+
property: { type: "Identifier", name: "length" }
|
|
7992
|
+
};
|
|
7993
|
+
}
|
|
7994
|
+
function makePropAccess(objExpr, propName) {
|
|
7995
|
+
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(propName)) {
|
|
7996
|
+
return {
|
|
7997
|
+
type: "MemberExpression",
|
|
7998
|
+
computed: false,
|
|
7999
|
+
object: objExpr,
|
|
8000
|
+
property: { type: "Identifier", name: propName }
|
|
8001
|
+
};
|
|
8002
|
+
}
|
|
8003
|
+
return {
|
|
8004
|
+
type: "MemberExpression",
|
|
8005
|
+
computed: true,
|
|
8006
|
+
object: objExpr,
|
|
8007
|
+
property: makeLiteral(propName)
|
|
8008
|
+
};
|
|
8009
|
+
}
|
|
8010
|
+
function buildQnrBitExpr(qnrValRef, bitKind) {
|
|
8011
|
+
const shiftAmt = bitKind === "xor1" ? 1 : 2;
|
|
8012
|
+
const combOp = bitKind === "xor1" ? "^" : "|";
|
|
8013
|
+
return makeBinary(
|
|
8014
|
+
"&",
|
|
8015
|
+
makeBinary(
|
|
8016
|
+
combOp,
|
|
8017
|
+
cloneNode(qnrValRef),
|
|
8018
|
+
makeBinary(">>", cloneNode(qnrValRef), makeLiteral(shiftAmt))
|
|
8019
|
+
),
|
|
8020
|
+
makeLiteral(1)
|
|
8021
|
+
);
|
|
8022
|
+
}
|
|
8023
|
+
function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false, ctxOpts) {
|
|
8024
|
+
const domain = ctxOpts?.returnDomain ?? "object";
|
|
8025
|
+
const [x1, x2, x3, x4] = buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn, ctxOpts);
|
|
8026
|
+
const mba4 = buildMba4Ast(seed, fnIndex, x1, x2, x3, x4);
|
|
8027
|
+
const qnrFamilyIdx = ((seed ^ Math.imul(fnIndex + 1, 2654435761)) >>> 0) % QNR_RESIDUE_FAMILIES.length;
|
|
8028
|
+
const qnrFamily = QNR_RESIDUE_FAMILIES[qnrFamilyIdx];
|
|
8029
|
+
const slotA = fnIndex + (seed & 3) & 3;
|
|
8030
|
+
const slotB = slotA + 1 + (seed >>> 2 & 1) & 3;
|
|
8031
|
+
const hasAlias = Boolean(ctxOpts?.aliasIdentA);
|
|
8032
|
+
const aliasReadIdent = ctxOpts?.aliasIdentB ?? ctxOpts?.aliasIdentA ?? "";
|
|
8033
|
+
let qnrLeft;
|
|
8034
|
+
let qnrValForForm0;
|
|
8035
|
+
let zRefForDecoy;
|
|
8036
|
+
let aliasInvZero = null;
|
|
8037
|
+
if (ctxOpts?.mxIdent && ctxOpts?.scratchVarIdent && hasAlias) {
|
|
8038
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
8039
|
+
const names = [...ctxOpts?.liveVars ?? [], ...extractParamNames(paramNode)];
|
|
8040
|
+
const uniqueNames = [];
|
|
8041
|
+
for (const n of names) {
|
|
8042
|
+
if (n && n !== "arguments" && n !== "eval" && !uniqueNames.includes(n)) {
|
|
8043
|
+
uniqueNames.push(n);
|
|
8044
|
+
}
|
|
8045
|
+
}
|
|
8046
|
+
const arg0 = uniqueNames.length >= 1 ? makeSafeNumericParam(uniqueNames[0]) : !isArrowFn ? {
|
|
8047
|
+
type: "MemberExpression",
|
|
8048
|
+
computed: false,
|
|
8049
|
+
object: { type: "Identifier", name: "arguments" },
|
|
8050
|
+
property: { type: "Identifier", name: "length" }
|
|
8051
|
+
} : makeTypeofGlobalLen();
|
|
8052
|
+
const arg1 = uniqueNames.length >= 2 ? makeSafeNumericParam(uniqueNames[1]) : uniqueNames.length === 1 && !isArrowFn ? {
|
|
8053
|
+
type: "MemberExpression",
|
|
8054
|
+
computed: false,
|
|
8055
|
+
object: { type: "Identifier", name: "arguments" },
|
|
8056
|
+
property: { type: "Identifier", name: "length" }
|
|
8057
|
+
} : makeTypeofGlobalLen();
|
|
8058
|
+
const a0 = mixSeed32(seed, fnIndex * 13 + 3);
|
|
8059
|
+
const a1 = mixSeed32(seed, fnIndex * 13 + 5) | 1;
|
|
8060
|
+
const a2 = mixSeed32(seed, fnIndex * 13 + 7) & ~1;
|
|
8061
|
+
const a3 = mixSeed32(seed, fnIndex * 13 + 9) & ~1;
|
|
8062
|
+
const maskConst = mixSeed32(seed, fnIndex + 97) | 1;
|
|
8063
|
+
const r0 = mixSeed32(seed, fnIndex * 17 + 1);
|
|
8064
|
+
const r1 = mixSeed32(seed, fnIndex * 17 + 3) | 1;
|
|
8065
|
+
const seqExprs = [
|
|
8066
|
+
{
|
|
8067
|
+
type: "AssignmentExpression",
|
|
8068
|
+
operator: "=",
|
|
8069
|
+
left: cloneNode(scratchId),
|
|
8070
|
+
right: {
|
|
8071
|
+
type: "CallExpression",
|
|
8072
|
+
callee: { type: "Identifier", name: ctxOpts.mxIdent },
|
|
8073
|
+
arguments: [
|
|
8074
|
+
arg0,
|
|
8075
|
+
arg1,
|
|
8076
|
+
makeLiteral(slotA),
|
|
8077
|
+
makeLiteral(slotB),
|
|
8078
|
+
makeInt32Literal(maskConst),
|
|
8079
|
+
makeInt32Literal(a0),
|
|
8080
|
+
makeInt32Literal(a1),
|
|
8081
|
+
makeInt32Literal(a2),
|
|
8082
|
+
makeInt32Literal(a3)
|
|
8083
|
+
],
|
|
8084
|
+
optional: false
|
|
8085
|
+
}
|
|
8086
|
+
},
|
|
8087
|
+
{
|
|
8088
|
+
type: "AssignmentExpression",
|
|
8089
|
+
operator: "=",
|
|
8090
|
+
left: cloneNode(scratchId),
|
|
8091
|
+
right: makeBinary(
|
|
8092
|
+
"|",
|
|
8093
|
+
makeBinary("+", makeInt32Literal(r0), makeImul(cloneNode(scratchId), makeInt32Literal(r1))),
|
|
8094
|
+
makeLiteral(0)
|
|
8095
|
+
)
|
|
8096
|
+
}
|
|
8097
|
+
];
|
|
8098
|
+
const qnrCore = makeBinary(
|
|
8099
|
+
"&",
|
|
8100
|
+
makeBinary("+", makeImul(cloneNode(scratchId), cloneNode(scratchId)), makeLiteral(qnrFamily.add)),
|
|
8101
|
+
makeLiteral(qnrFamily.mask)
|
|
8102
|
+
);
|
|
8103
|
+
qnrLeft = {
|
|
8104
|
+
type: "SequenceExpression",
|
|
8105
|
+
expressions: [...seqExprs, qnrCore]
|
|
8106
|
+
};
|
|
8107
|
+
qnrValForForm0 = {
|
|
8108
|
+
type: "SequenceExpression",
|
|
8109
|
+
expressions: [
|
|
8110
|
+
{
|
|
8111
|
+
type: "AssignmentExpression",
|
|
8112
|
+
operator: "=",
|
|
8113
|
+
left: cloneNode(scratchId),
|
|
8114
|
+
right: cloneNode(qnrCore)
|
|
8115
|
+
},
|
|
8116
|
+
buildQnrBitExpr(scratchId, qnrFamily.bitKind)
|
|
8117
|
+
]
|
|
8118
|
+
};
|
|
8119
|
+
zRefForDecoy = cloneNode(scratchId);
|
|
8120
|
+
} else if (ctxOpts?.scratchVarIdent) {
|
|
8121
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
8122
|
+
const rivestOnScratch = buildRivestPermAst(seed, fnIndex, scratchId);
|
|
8123
|
+
const seqExprs = [
|
|
8124
|
+
{
|
|
8125
|
+
type: "AssignmentExpression",
|
|
8126
|
+
operator: "=",
|
|
8127
|
+
left: cloneNode(scratchId),
|
|
8128
|
+
right: mba4
|
|
6710
8129
|
},
|
|
6711
8130
|
{
|
|
6712
8131
|
type: "AssignmentExpression",
|
|
@@ -6723,176 +8142,845 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6723
8142
|
right: buildSboxMixAst(ctxOpts.sboxIdent, ctxOpts.scratchVarIdent)
|
|
6724
8143
|
});
|
|
6725
8144
|
}
|
|
6726
|
-
if (
|
|
6727
|
-
const
|
|
6728
|
-
const
|
|
8145
|
+
if (hasAlias) {
|
|
8146
|
+
const aliasWriteMemA = makeMemberIndex(ctxOpts.aliasIdentA, makeLiteral(slotA));
|
|
8147
|
+
const maskConst = mixSeed32(seed, fnIndex + 97) | 1;
|
|
8148
|
+
const updateMask = makeBinary(
|
|
8149
|
+
"^",
|
|
8150
|
+
makeBinary("<<", cloneNode(scratchId), makeLiteral(3)),
|
|
8151
|
+
makeInt32Literal(maskConst)
|
|
8152
|
+
);
|
|
6729
8153
|
seqExprs.push({
|
|
6730
8154
|
type: "AssignmentExpression",
|
|
6731
8155
|
operator: "=",
|
|
6732
|
-
left: cloneNode(
|
|
6733
|
-
right: makeBinary(
|
|
6734
|
-
"|",
|
|
6735
|
-
makeBinary(
|
|
6736
|
-
"^",
|
|
6737
|
-
cloneNode(aliasMem),
|
|
6738
|
-
makeBinary("&", cloneNode(scratchId), makeLiteral(0))
|
|
6739
|
-
),
|
|
6740
|
-
makeLiteral(0)
|
|
6741
|
-
)
|
|
8156
|
+
left: cloneNode(aliasWriteMemA),
|
|
8157
|
+
right: makeBinary("|", makeBinary("^", cloneNode(aliasWriteMemA), cloneNode(updateMask)), makeLiteral(0))
|
|
6742
8158
|
});
|
|
8159
|
+
aliasInvZero = makeBinary(
|
|
8160
|
+
"^",
|
|
8161
|
+
makeBinary("|", makeBinary("^", cloneNode(aliasWriteMemA), cloneNode(updateMask)), makeLiteral(0)),
|
|
8162
|
+
{
|
|
8163
|
+
type: "AssignmentExpression",
|
|
8164
|
+
operator: "=",
|
|
8165
|
+
left: cloneNode(aliasWriteMemA),
|
|
8166
|
+
right: makeBinary("|", makeBinary("^", cloneNode(aliasWriteMemA), cloneNode(updateMask)), makeLiteral(0))
|
|
8167
|
+
}
|
|
8168
|
+
);
|
|
6743
8169
|
}
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
makeLiteral(qnrFamily.mask)
|
|
6749
|
-
)
|
|
8170
|
+
const qnrCore = makeBinary(
|
|
8171
|
+
"&",
|
|
8172
|
+
makeBinary("+", makeImul(cloneNode(scratchId), cloneNode(scratchId)), makeLiteral(qnrFamily.add)),
|
|
8173
|
+
makeLiteral(qnrFamily.mask)
|
|
6750
8174
|
);
|
|
6751
8175
|
qnrLeft = {
|
|
6752
8176
|
type: "SequenceExpression",
|
|
6753
|
-
expressions: seqExprs
|
|
8177
|
+
expressions: [...seqExprs, qnrCore]
|
|
8178
|
+
};
|
|
8179
|
+
qnrValForForm0 = {
|
|
8180
|
+
type: "SequenceExpression",
|
|
8181
|
+
expressions: [
|
|
8182
|
+
{
|
|
8183
|
+
type: "AssignmentExpression",
|
|
8184
|
+
operator: "=",
|
|
8185
|
+
left: cloneNode(scratchId),
|
|
8186
|
+
right: cloneNode(qnrCore)
|
|
8187
|
+
},
|
|
8188
|
+
buildQnrBitExpr(scratchId, qnrFamily.bitKind)
|
|
8189
|
+
]
|
|
6754
8190
|
};
|
|
6755
8191
|
zRefForDecoy = cloneNode(scratchId);
|
|
6756
8192
|
} else {
|
|
6757
8193
|
const zExpr = buildRivestPermAst(seed, fnIndex, mba4);
|
|
6758
|
-
|
|
8194
|
+
const qnrCore = makeBinary(
|
|
6759
8195
|
"&",
|
|
6760
8196
|
makeBinary("+", makeImul(cloneNode(zExpr), cloneNode(zExpr)), makeLiteral(qnrFamily.add)),
|
|
6761
8197
|
makeLiteral(qnrFamily.mask)
|
|
6762
8198
|
);
|
|
8199
|
+
qnrLeft = qnrCore;
|
|
8200
|
+
qnrValForForm0 = buildQnrBitExpr(qnrCore, qnrFamily.bitKind);
|
|
6763
8201
|
zRefForDecoy = zExpr;
|
|
6764
8202
|
}
|
|
6765
|
-
const consequent = createContextualDecoyConsequent(
|
|
6766
|
-
fnIndex,
|
|
6767
|
-
seed,
|
|
6768
|
-
domain,
|
|
6769
|
-
decoyIdent,
|
|
6770
|
-
zRefForDecoy
|
|
6771
|
-
);
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
8203
|
+
const consequent = createContextualDecoyConsequent(
|
|
8204
|
+
fnIndex,
|
|
8205
|
+
seed,
|
|
8206
|
+
domain,
|
|
8207
|
+
decoyIdent,
|
|
8208
|
+
zRefForDecoy
|
|
8209
|
+
);
|
|
8210
|
+
const hasShieldCoupling = Boolean(ctxOpts?.shieldCoupled && ctxOpts?.windowKeySymbol);
|
|
8211
|
+
const predOffset = hasShieldCoupling ? 1 : (seed >>> 2) % 6;
|
|
8212
|
+
const predForm = ((fnIndex + predOffset) % 6 + 6) % 6;
|
|
8213
|
+
let testExpr;
|
|
8214
|
+
if (predForm === 0) {
|
|
8215
|
+
let pathACore = qnrValForForm0;
|
|
8216
|
+
if (aliasInvZero) {
|
|
8217
|
+
pathACore = makeBinary("^", aliasInvZero, qnrValForForm0);
|
|
8218
|
+
}
|
|
8219
|
+
if (hasAlias) {
|
|
8220
|
+
pathACore = makeBinary(
|
|
8221
|
+
"^",
|
|
8222
|
+
pathACore,
|
|
8223
|
+
makeBinary("&", makeMemberIndex(aliasReadIdent, makeLiteral(slotB)), makeLiteral(1))
|
|
8224
|
+
);
|
|
8225
|
+
}
|
|
8226
|
+
const pathA = ctxOpts?.scratchVarIdent ? {
|
|
8227
|
+
type: "SequenceExpression",
|
|
8228
|
+
expressions: [...qnrLeft.expressions.slice(0, -1), pathACore]
|
|
8229
|
+
} : pathACore;
|
|
8230
|
+
const pathB = hasAlias ? makeBinary(
|
|
8231
|
+
"^",
|
|
8232
|
+
makeLiteral(qnrFamily.expectedBit),
|
|
8233
|
+
makeBinary("&", makeMemberIndex(ctxOpts.aliasIdentA, makeLiteral(slotB)), makeLiteral(1))
|
|
8234
|
+
) : makeLiteral(qnrFamily.expectedBit);
|
|
8235
|
+
testExpr = makeBinary("!==", makeBinary("^", pathA, pathB), makeLiteral(0));
|
|
8236
|
+
} else if (predForm === 1) {
|
|
8237
|
+
const qnrLhs = aliasInvZero ? makeBinary("+", qnrLeft, makeBinary("&", aliasInvZero, makeLiteral(1))) : qnrLeft;
|
|
8238
|
+
const qnrFail = makeBinary(qnrFamily.outBoundOp, qnrLhs, makeLiteral(qnrFamily.outBoundVal));
|
|
8239
|
+
const hasGlobal = makeBinary(
|
|
8240
|
+
"<",
|
|
8241
|
+
makeUnary("typeof", { type: "Identifier", name: "globalThis" }),
|
|
8242
|
+
makeLiteral("u")
|
|
8243
|
+
);
|
|
8244
|
+
const tamperCheck = hasShieldCoupling ? {
|
|
8245
|
+
type: "LogicalExpression",
|
|
8246
|
+
operator: "&&",
|
|
8247
|
+
left: hasGlobal,
|
|
8248
|
+
right: {
|
|
8249
|
+
type: "LogicalExpression",
|
|
8250
|
+
operator: "&&",
|
|
8251
|
+
left: makePropAccess({ type: "Identifier", name: "globalThis" }, `${ctxOpts.windowKeySymbol}_s`),
|
|
8252
|
+
right: makeBinary(
|
|
8253
|
+
"===",
|
|
8254
|
+
{
|
|
8255
|
+
type: "MemberExpression",
|
|
8256
|
+
computed: true,
|
|
8257
|
+
object: makePropAccess({ type: "Identifier", name: "globalThis" }, `${ctxOpts.windowKeySymbol}_s`),
|
|
8258
|
+
property: makeLiteral(0)
|
|
8259
|
+
},
|
|
8260
|
+
makeLiteral(2)
|
|
8261
|
+
)
|
|
8262
|
+
}
|
|
8263
|
+
} : {
|
|
8264
|
+
type: "LogicalExpression",
|
|
8265
|
+
operator: "&&",
|
|
8266
|
+
left: hasGlobal,
|
|
8267
|
+
right: makeBinary(
|
|
8268
|
+
"===",
|
|
8269
|
+
makePropAccess({ type: "Identifier", name: "globalThis" }, "__unpeek_tampered"),
|
|
8270
|
+
makeUnary("!", makeLiteral(0))
|
|
8271
|
+
)
|
|
8272
|
+
};
|
|
8273
|
+
testExpr = {
|
|
8274
|
+
type: "LogicalExpression",
|
|
8275
|
+
operator: "||",
|
|
8276
|
+
left: qnrFail,
|
|
8277
|
+
right: tamperCheck
|
|
8278
|
+
};
|
|
8279
|
+
} else if (predForm === 2) {
|
|
8280
|
+
const slotReadB = hasAlias ? makeBinary("&", makeMemberIndex(aliasReadIdent, makeLiteral(slotB)), makeLiteral(7)) : makeBinary("&", makeTypeofGlobalLen(), makeLiteral(7));
|
|
8281
|
+
const slotWriteB = hasAlias ? makeBinary("&", makeMemberIndex(ctxOpts.aliasIdentA, makeLiteral(slotB)), makeLiteral(7)) : makeBinary("&", makeTypeofGlobalLen(), makeLiteral(7));
|
|
8282
|
+
let lhsExpr = makeBinary("+", qnrLeft, slotReadB);
|
|
8283
|
+
if (aliasInvZero) {
|
|
8284
|
+
lhsExpr = makeBinary("+", lhsExpr, makeBinary("&", aliasInvZero, makeLiteral(3)));
|
|
8285
|
+
}
|
|
8286
|
+
const rhsExpr = makeBinary("+", makeLiteral(qnrFamily.outBoundVal), slotWriteB);
|
|
8287
|
+
testExpr = makeBinary(qnrFamily.outBoundOp, lhsExpr, rhsExpr);
|
|
8288
|
+
} else if (predForm === 3) {
|
|
8289
|
+
const tagLhs = hasAlias ? makeBinary("&", makeMemberIndex(ctxOpts.aliasIdentA, makeLiteral(slotB)), makeLiteral(240)) : makeBinary("&", makeBinary("<<", makeTypeofGlobalLen(), makeLiteral(4)), makeLiteral(240));
|
|
8290
|
+
const tagRhsBase = hasAlias ? makeBinary("&", makeMemberIndex(aliasReadIdent, makeLiteral(slotB)), makeLiteral(240)) : makeBinary("&", makeBinary("<<", makeTypeofGlobalLen(), makeLiteral(4)), makeLiteral(240));
|
|
8291
|
+
const tagRhs = aliasInvZero ? makeBinary("^", tagRhsBase, makeBinary("&", aliasInvZero, makeLiteral(15))) : tagRhsBase;
|
|
8292
|
+
const lhsExpr = makeBinary("|", makeBinary("^", qnrLeft, tagLhs), makeLiteral(0));
|
|
8293
|
+
const rhsExpr = makeBinary("|", makeBinary("^", makeLiteral(qnrFamily.target), tagRhs), makeLiteral(0));
|
|
8294
|
+
testExpr = makeBinary("===", lhsExpr, rhsExpr);
|
|
8295
|
+
} else if (predForm === 4) {
|
|
8296
|
+
const k4 = mixSeed32(seed, fnIndex * 29 + 13) >>> 0 || 1;
|
|
8297
|
+
if (ctxOpts?.scratchVarIdent) {
|
|
8298
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
8299
|
+
const preU = aliasInvZero ? makeBinary("^", cloneNode(scratchId), aliasInvZero) : cloneNode(scratchId);
|
|
8300
|
+
const uAssign = {
|
|
8301
|
+
type: "AssignmentExpression",
|
|
8302
|
+
operator: "=",
|
|
8303
|
+
left: cloneNode(scratchId),
|
|
8304
|
+
right: makeBinary(">>>", makeBinary("^", preU, makeLiteral(k4)), makeLiteral(0))
|
|
8305
|
+
};
|
|
8306
|
+
const uMinus1Lhs = makeBinary(">>>", makeBinary("-", cloneNode(scratchId), makeLiteral(1)), makeLiteral(0));
|
|
8307
|
+
const uMinus1Rhs = makeBinary(">>>", makeBinary("-", cloneNode(scratchId), makeLiteral(1)), makeLiteral(0));
|
|
8308
|
+
const orU = makeBinary(">>>", makeBinary("|", cloneNode(scratchId), uMinus1Lhs), makeLiteral(0));
|
|
8309
|
+
const xorU = makeBinary(">>>", makeBinary("^", cloneNode(scratchId), uMinus1Rhs), makeLiteral(0));
|
|
8310
|
+
const lhsSeq = {
|
|
8311
|
+
type: "SequenceExpression",
|
|
8312
|
+
expressions: [...qnrLeft.expressions.slice(0, -1), uAssign, orU]
|
|
8313
|
+
};
|
|
8314
|
+
testExpr = makeBinary("<", lhsSeq, xorU);
|
|
8315
|
+
} else {
|
|
8316
|
+
const uExpr = makeBinary(">>>", makeBinary("^", cloneNode(zRefForDecoy), makeLiteral(k4)), makeLiteral(0));
|
|
8317
|
+
const uMinus1Lhs = makeBinary(">>>", makeBinary("-", cloneNode(uExpr), makeLiteral(1)), makeLiteral(0));
|
|
8318
|
+
const uMinus1Rhs = makeBinary(">>>", makeBinary("-", cloneNode(uExpr), makeLiteral(1)), makeLiteral(0));
|
|
8319
|
+
const orU = makeBinary(">>>", makeBinary("|", cloneNode(uExpr), uMinus1Lhs), makeLiteral(0));
|
|
8320
|
+
const xorU = makeBinary(">>>", makeBinary("^", cloneNode(uExpr), uMinus1Rhs), makeLiteral(0));
|
|
8321
|
+
testExpr = makeBinary("<", orU, xorU);
|
|
8322
|
+
}
|
|
8323
|
+
} else {
|
|
8324
|
+
const k5 = mixSeed32(seed, fnIndex * 31 + 17) >>> 0 || 3;
|
|
8325
|
+
const { m, m2, mInv, c, d } = deriveAffineMbaParams(seed, fnIndex * 37 + 23);
|
|
8326
|
+
const buildAffineLhs = (valNode) => {
|
|
8327
|
+
const inner = makeBinary(
|
|
8328
|
+
"|",
|
|
8329
|
+
makeBinary(
|
|
8330
|
+
"+",
|
|
8331
|
+
makeBinary(
|
|
8332
|
+
"+",
|
|
8333
|
+
makeImul(makeLiteral(m), makeBinary("^", cloneNode(valNode), makeLiteral(k5))),
|
|
8334
|
+
makeImul(makeLiteral(m2), makeBinary("&", cloneNode(valNode), makeLiteral(k5)))
|
|
8335
|
+
),
|
|
8336
|
+
makeLiteral(c)
|
|
8337
|
+
),
|
|
8338
|
+
makeLiteral(0)
|
|
8339
|
+
);
|
|
8340
|
+
return makeBinary(
|
|
8341
|
+
"|",
|
|
8342
|
+
makeBinary("+", makeImul(makeLiteral(mInv), inner), makeLiteral(d)),
|
|
8343
|
+
makeLiteral(0)
|
|
8344
|
+
);
|
|
8345
|
+
};
|
|
8346
|
+
const buildAffineRhs = (valNode) => makeBinary("|", makeBinary("+", cloneNode(valNode), makeLiteral(k5)), makeLiteral(0));
|
|
8347
|
+
if (ctxOpts?.scratchVarIdent) {
|
|
8348
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
8349
|
+
const preSeqs = [...qnrLeft.expressions.slice(0, -1)];
|
|
8350
|
+
if (aliasInvZero) {
|
|
8351
|
+
preSeqs.push({
|
|
8352
|
+
type: "AssignmentExpression",
|
|
8353
|
+
operator: "=",
|
|
8354
|
+
left: cloneNode(scratchId),
|
|
8355
|
+
right: makeBinary("|", makeBinary("^", cloneNode(scratchId), aliasInvZero), makeLiteral(0))
|
|
8356
|
+
});
|
|
8357
|
+
}
|
|
8358
|
+
const lhsSeq = {
|
|
8359
|
+
type: "SequenceExpression",
|
|
8360
|
+
expressions: [...preSeqs, buildAffineLhs(scratchId)]
|
|
8361
|
+
};
|
|
8362
|
+
testExpr = makeBinary("!==", lhsSeq, buildAffineRhs(scratchId));
|
|
8363
|
+
} else {
|
|
8364
|
+
testExpr = makeBinary("!==", buildAffineLhs(zRefForDecoy), buildAffineRhs(zRefForDecoy));
|
|
8365
|
+
}
|
|
8366
|
+
}
|
|
8367
|
+
return {
|
|
8368
|
+
type: "IfStatement",
|
|
8369
|
+
test: testExpr,
|
|
8370
|
+
consequent,
|
|
8371
|
+
alternate: null
|
|
8372
|
+
};
|
|
8373
|
+
}
|
|
8374
|
+
function inferFunctionReturnDomain(fnNode) {
|
|
8375
|
+
let hasReturnArg = false;
|
|
8376
|
+
let seenNumber = false;
|
|
8377
|
+
let seenBoolean = false;
|
|
8378
|
+
let seenString = false;
|
|
8379
|
+
let seenObject = false;
|
|
8380
|
+
function scanStmts(node) {
|
|
8381
|
+
if (!node || typeof node !== "object") return;
|
|
8382
|
+
if (Array.isArray(node)) {
|
|
8383
|
+
for (const item of node) scanStmts(item);
|
|
8384
|
+
return;
|
|
8385
|
+
}
|
|
8386
|
+
if (node !== fnNode && (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression")) {
|
|
8387
|
+
return;
|
|
8388
|
+
}
|
|
8389
|
+
if (node.type === "ReturnStatement") {
|
|
8390
|
+
if (!node.argument) return;
|
|
8391
|
+
hasReturnArg = true;
|
|
8392
|
+
const arg = node.argument;
|
|
8393
|
+
if (arg.type === "Literal") {
|
|
8394
|
+
if (typeof arg.value === "number") seenNumber = true;
|
|
8395
|
+
else if (typeof arg.value === "boolean") seenBoolean = true;
|
|
8396
|
+
else if (typeof arg.value === "string") seenString = true;
|
|
8397
|
+
} else if (arg.type === "ObjectExpression" || arg.type === "ArrayExpression") {
|
|
8398
|
+
seenObject = true;
|
|
8399
|
+
} else if (arg.type === "BinaryExpression") {
|
|
8400
|
+
if (["===", "!==", "==", "!=", "<", ">", "<=", ">=", "in", "instanceof"].includes(arg.operator)) {
|
|
8401
|
+
seenBoolean = true;
|
|
8402
|
+
} else if (arg.operator !== "+") {
|
|
8403
|
+
seenNumber = true;
|
|
8404
|
+
}
|
|
8405
|
+
} else if (arg.type === "UnaryExpression") {
|
|
8406
|
+
if (arg.operator === "!") seenBoolean = true;
|
|
8407
|
+
else if (arg.operator === "typeof") seenString = true;
|
|
8408
|
+
else if (arg.operator === "-" || arg.operator === "+" || arg.operator === "~") seenNumber = true;
|
|
8409
|
+
}
|
|
8410
|
+
return;
|
|
8411
|
+
}
|
|
8412
|
+
for (const key of Object.keys(node)) {
|
|
8413
|
+
if (key === "loc" || key === "range") continue;
|
|
8414
|
+
const val = node[key];
|
|
8415
|
+
if (val && typeof val === "object") {
|
|
8416
|
+
scanStmts(val);
|
|
8417
|
+
}
|
|
8418
|
+
}
|
|
8419
|
+
}
|
|
8420
|
+
scanStmts(fnNode.body);
|
|
8421
|
+
if (!hasReturnArg && fnNode.body?.type === "BlockStatement") return "void";
|
|
8422
|
+
if (seenObject) return "object";
|
|
8423
|
+
if (seenBoolean && !seenNumber && !seenString) return "boolean";
|
|
8424
|
+
if (seenNumber && !seenBoolean && !seenString) return "number";
|
|
8425
|
+
if (seenString && !seenNumber && !seenBoolean) return "string";
|
|
8426
|
+
return "object";
|
|
8427
|
+
}
|
|
8428
|
+
function createSboxAndAliasDeclarations(sboxIdent, aliasIdentA, aliasIdentB, scratchVarIdent, seed, mxIdent) {
|
|
8429
|
+
const sboxInit = acorn5.parseExpressionAt(
|
|
8430
|
+
`(function(){var a=[],i,s=${seed | 0},j,t;for(i=0;i<256;i++)a[i]=i;for(i=255;i>0;i--){s=(Math.imul(s,1664525)+1013904223)|0;j=(s>>>0)%(i+1);t=a[i];a[i]=a[j];a[j]=t;}return a;})()`,
|
|
8431
|
+
0,
|
|
8432
|
+
{ ecmaVersion: "latest" }
|
|
8433
|
+
);
|
|
8434
|
+
const stateVals = [
|
|
8435
|
+
mixSeed32(seed, 101),
|
|
8436
|
+
mixSeed32(seed, 103),
|
|
8437
|
+
mixSeed32(seed, 107),
|
|
8438
|
+
mixSeed32(seed, 109)
|
|
8439
|
+
];
|
|
8440
|
+
const declarations = [
|
|
8441
|
+
{
|
|
8442
|
+
type: "VariableDeclarator",
|
|
8443
|
+
id: { type: "Identifier", name: sboxIdent },
|
|
8444
|
+
init: sboxInit
|
|
8445
|
+
},
|
|
8446
|
+
{
|
|
8447
|
+
type: "VariableDeclarator",
|
|
8448
|
+
id: { type: "Identifier", name: aliasIdentA },
|
|
8449
|
+
init: {
|
|
8450
|
+
type: "ArrayExpression",
|
|
8451
|
+
elements: stateVals.map((v) => makeInt32Literal(v))
|
|
8452
|
+
}
|
|
8453
|
+
},
|
|
8454
|
+
{
|
|
8455
|
+
type: "VariableDeclarator",
|
|
8456
|
+
id: { type: "Identifier", name: aliasIdentB },
|
|
8457
|
+
init: { type: "Identifier", name: aliasIdentA }
|
|
8458
|
+
},
|
|
8459
|
+
{
|
|
8460
|
+
type: "VariableDeclarator",
|
|
8461
|
+
id: { type: "Identifier", name: scratchVarIdent },
|
|
8462
|
+
init: makeLiteral(0)
|
|
8463
|
+
}
|
|
8464
|
+
];
|
|
8465
|
+
if (mxIdent) {
|
|
8466
|
+
const mbaAst = buildMba4Ast(
|
|
8467
|
+
seed,
|
|
8468
|
+
0,
|
|
8469
|
+
{ type: "Identifier", name: "$u" },
|
|
8470
|
+
{ type: "Identifier", name: "$v" },
|
|
8471
|
+
{ type: "Identifier", name: "$p" },
|
|
8472
|
+
{ type: "Identifier", name: "$q" }
|
|
8473
|
+
);
|
|
8474
|
+
const mxFn = {
|
|
8475
|
+
type: "FunctionExpression",
|
|
8476
|
+
id: null,
|
|
8477
|
+
params: [
|
|
8478
|
+
{ type: "Identifier", name: "$a" },
|
|
8479
|
+
{ type: "Identifier", name: "$b" },
|
|
8480
|
+
{ type: "Identifier", name: "$c" },
|
|
8481
|
+
{ type: "Identifier", name: "$d" },
|
|
8482
|
+
{ type: "Identifier", name: "$e" },
|
|
8483
|
+
{ type: "Identifier", name: "$f" },
|
|
8484
|
+
{ type: "Identifier", name: "$g" },
|
|
8485
|
+
{ type: "Identifier", name: "$h" },
|
|
8486
|
+
{ type: "Identifier", name: "$i" }
|
|
8487
|
+
],
|
|
8488
|
+
body: {
|
|
8489
|
+
type: "BlockStatement",
|
|
8490
|
+
body: [
|
|
8491
|
+
{
|
|
8492
|
+
type: "VariableDeclaration",
|
|
8493
|
+
kind: "var",
|
|
8494
|
+
declarations: [
|
|
8495
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$u" }, init: makeBinary("|", { type: "Identifier", name: "$a" }, makeLiteral(0)) },
|
|
8496
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$v" }, init: makeBinary("|", { type: "Identifier", name: "$b" }, makeLiteral(0)) },
|
|
8497
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$p" }, init: makeBinary("|", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }), makeLiteral(0)) },
|
|
8498
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$q" }, init: makeBinary("|", makeMemberIndex(aliasIdentB, { type: "Identifier", name: "$d" }), makeLiteral(0)) },
|
|
8499
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$z" }, init: mbaAst }
|
|
8500
|
+
]
|
|
8501
|
+
},
|
|
8502
|
+
{
|
|
8503
|
+
type: "ExpressionStatement",
|
|
8504
|
+
expression: {
|
|
8505
|
+
type: "AssignmentExpression",
|
|
8506
|
+
operator: "=",
|
|
8507
|
+
left: { type: "Identifier", name: "$z" },
|
|
8508
|
+
right: makeBinary(
|
|
8509
|
+
"|",
|
|
8510
|
+
makeBinary(
|
|
8511
|
+
"+",
|
|
8512
|
+
{ type: "Identifier", name: "$f" },
|
|
8513
|
+
makeImul(
|
|
8514
|
+
{ type: "Identifier", name: "$z" },
|
|
8515
|
+
makeBinary(
|
|
8516
|
+
"+",
|
|
8517
|
+
{ type: "Identifier", name: "$g" },
|
|
8518
|
+
makeImul(
|
|
8519
|
+
{ type: "Identifier", name: "$z" },
|
|
8520
|
+
makeBinary(
|
|
8521
|
+
"+",
|
|
8522
|
+
{ type: "Identifier", name: "$h" },
|
|
8523
|
+
makeImul({ type: "Identifier", name: "$z" }, { type: "Identifier", name: "$i" })
|
|
8524
|
+
)
|
|
8525
|
+
)
|
|
8526
|
+
)
|
|
8527
|
+
)
|
|
8528
|
+
),
|
|
8529
|
+
makeLiteral(0)
|
|
8530
|
+
)
|
|
8531
|
+
}
|
|
8532
|
+
},
|
|
8533
|
+
{
|
|
8534
|
+
type: "ExpressionStatement",
|
|
8535
|
+
expression: {
|
|
8536
|
+
type: "AssignmentExpression",
|
|
8537
|
+
operator: "=",
|
|
8538
|
+
left: { type: "Identifier", name: "$z" },
|
|
8539
|
+
right: buildSboxMixAst(sboxIdent, "$z")
|
|
8540
|
+
}
|
|
8541
|
+
},
|
|
8542
|
+
{
|
|
8543
|
+
type: "VariableDeclaration",
|
|
8544
|
+
kind: "var",
|
|
8545
|
+
declarations: [
|
|
8546
|
+
{
|
|
8547
|
+
type: "VariableDeclarator",
|
|
8548
|
+
id: { type: "Identifier", name: "$m" },
|
|
8549
|
+
init: makeBinary("^", makeBinary("<<", { type: "Identifier", name: "$z" }, makeLiteral(3)), { type: "Identifier", name: "$e" })
|
|
8550
|
+
}
|
|
8551
|
+
]
|
|
8552
|
+
},
|
|
8553
|
+
{
|
|
8554
|
+
type: "ExpressionStatement",
|
|
8555
|
+
expression: {
|
|
8556
|
+
type: "AssignmentExpression",
|
|
8557
|
+
operator: "=",
|
|
8558
|
+
left: makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }),
|
|
8559
|
+
right: makeBinary("|", makeBinary("^", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }), { type: "Identifier", name: "$m" }), makeLiteral(0))
|
|
8560
|
+
}
|
|
8561
|
+
},
|
|
8562
|
+
{
|
|
8563
|
+
type: "VariableDeclaration",
|
|
8564
|
+
kind: "var",
|
|
8565
|
+
declarations: [
|
|
8566
|
+
{
|
|
8567
|
+
type: "VariableDeclarator",
|
|
8568
|
+
id: { type: "Identifier", name: "$w" },
|
|
8569
|
+
init: makeBinary(
|
|
8570
|
+
"^",
|
|
8571
|
+
makeBinary("|", makeBinary("^", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }), { type: "Identifier", name: "$m" }), makeLiteral(0)),
|
|
8572
|
+
{
|
|
8573
|
+
type: "AssignmentExpression",
|
|
8574
|
+
operator: "=",
|
|
8575
|
+
left: makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }),
|
|
8576
|
+
right: makeBinary("|", makeBinary("^", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }), { type: "Identifier", name: "$m" }), makeLiteral(0))
|
|
8577
|
+
}
|
|
8578
|
+
)
|
|
8579
|
+
}
|
|
8580
|
+
]
|
|
8581
|
+
},
|
|
8582
|
+
{
|
|
8583
|
+
type: "ReturnStatement",
|
|
8584
|
+
argument: {
|
|
8585
|
+
type: "AssignmentExpression",
|
|
8586
|
+
operator: "=",
|
|
8587
|
+
left: { type: "Identifier", name: scratchVarIdent },
|
|
8588
|
+
right: makeBinary("|", makeBinary("^", { type: "Identifier", name: "$z" }, { type: "Identifier", name: "$w" }), makeLiteral(0))
|
|
8589
|
+
}
|
|
8590
|
+
}
|
|
8591
|
+
]
|
|
8592
|
+
},
|
|
8593
|
+
generator: false,
|
|
8594
|
+
async: false,
|
|
8595
|
+
expression: false
|
|
8596
|
+
};
|
|
8597
|
+
declarations.push({
|
|
8598
|
+
type: "VariableDeclarator",
|
|
8599
|
+
id: { type: "Identifier", name: mxIdent },
|
|
8600
|
+
init: mxFn
|
|
8601
|
+
});
|
|
8602
|
+
}
|
|
8603
|
+
return {
|
|
8604
|
+
type: "VariableDeclaration",
|
|
8605
|
+
kind: "var",
|
|
8606
|
+
declarations
|
|
8607
|
+
};
|
|
8608
|
+
}
|
|
8609
|
+
var MAX_COLD_GUARDS_PER_CHUNK = 12;
|
|
8610
|
+
var MAX_COLD_BITWISE_MBA_PER_CHUNK = 8;
|
|
8611
|
+
var BITWISE_MBA_OPS = /* @__PURE__ */ new Set(["^", "|", "&"]);
|
|
8612
|
+
var BITWISE_LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
8613
|
+
"ForStatement",
|
|
8614
|
+
"WhileStatement",
|
|
8615
|
+
"DoWhileStatement",
|
|
8616
|
+
"ForInStatement",
|
|
8617
|
+
"ForOfStatement"
|
|
8618
|
+
]);
|
|
8619
|
+
var BITWISE_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
8620
|
+
"FunctionDeclaration",
|
|
8621
|
+
"FunctionExpression",
|
|
8622
|
+
"ArrowFunctionExpression"
|
|
8623
|
+
]);
|
|
8624
|
+
var BITWISE_LEXICAL_SCOPE_TYPES = /* @__PURE__ */ new Set([
|
|
8625
|
+
"Program",
|
|
8626
|
+
"FunctionDeclaration",
|
|
8627
|
+
"FunctionExpression",
|
|
8628
|
+
"ArrowFunctionExpression",
|
|
8629
|
+
"BlockStatement",
|
|
8630
|
+
"ForStatement",
|
|
8631
|
+
"ForInStatement",
|
|
8632
|
+
"ForOfStatement",
|
|
8633
|
+
"SwitchStatement",
|
|
8634
|
+
"CatchClause",
|
|
8635
|
+
"StaticBlock"
|
|
8636
|
+
]);
|
|
8637
|
+
var FORBIDDEN_BITWISE_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
8638
|
+
"arguments",
|
|
8639
|
+
"eval",
|
|
8640
|
+
"undefined",
|
|
8641
|
+
"NaN",
|
|
8642
|
+
"Infinity",
|
|
8643
|
+
"globalThis",
|
|
8644
|
+
"window",
|
|
8645
|
+
"self",
|
|
8646
|
+
"Math",
|
|
8647
|
+
"BigInt"
|
|
8648
|
+
]);
|
|
8649
|
+
function collectBoundPatternNames(pattern, out) {
|
|
8650
|
+
if (!pattern || typeof pattern !== "object") return;
|
|
8651
|
+
switch (pattern.type) {
|
|
8652
|
+
case "Identifier":
|
|
8653
|
+
out.push(pattern.name);
|
|
8654
|
+
break;
|
|
8655
|
+
case "AssignmentPattern":
|
|
8656
|
+
collectBoundPatternNames(pattern.left, out);
|
|
8657
|
+
break;
|
|
8658
|
+
case "RestElement":
|
|
8659
|
+
collectBoundPatternNames(pattern.argument, out);
|
|
8660
|
+
break;
|
|
8661
|
+
case "ArrayPattern":
|
|
8662
|
+
for (const el of pattern.elements || []) {
|
|
8663
|
+
if (el) collectBoundPatternNames(el, out);
|
|
8664
|
+
}
|
|
8665
|
+
break;
|
|
8666
|
+
case "ObjectPattern":
|
|
8667
|
+
for (const prop of pattern.properties || []) {
|
|
8668
|
+
if (prop.type === "Property") {
|
|
8669
|
+
collectBoundPatternNames(prop.value, out);
|
|
8670
|
+
} else if (prop.type === "RestElement") {
|
|
8671
|
+
collectBoundPatternNames(prop.argument, out);
|
|
8672
|
+
}
|
|
8673
|
+
}
|
|
8674
|
+
break;
|
|
8675
|
+
}
|
|
6783
8676
|
}
|
|
6784
|
-
function
|
|
6785
|
-
|
|
6786
|
-
let
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
function scanStmts(node) {
|
|
6791
|
-
if (!node || typeof node !== "object") return;
|
|
6792
|
-
if (Array.isArray(node)) {
|
|
6793
|
-
for (const item of node) scanStmts(item);
|
|
8677
|
+
function analyzeBitwiseMbaScopes(ast) {
|
|
8678
|
+
const scopeBindings = /* @__PURE__ */ new Map();
|
|
8679
|
+
let unsafe = false;
|
|
8680
|
+
const addBinding = (scopeNode, name) => {
|
|
8681
|
+
if (name === "Math") {
|
|
8682
|
+
unsafe = true;
|
|
6794
8683
|
return;
|
|
6795
8684
|
}
|
|
6796
|
-
|
|
8685
|
+
let set = scopeBindings.get(scopeNode);
|
|
8686
|
+
if (!set) {
|
|
8687
|
+
set = /* @__PURE__ */ new Set();
|
|
8688
|
+
scopeBindings.set(scopeNode, set);
|
|
8689
|
+
}
|
|
8690
|
+
set.add(name);
|
|
8691
|
+
};
|
|
8692
|
+
const scopeStack = [];
|
|
8693
|
+
const varTargetStack = [];
|
|
8694
|
+
const getNearestLexicalScope = () => scopeStack[scopeStack.length - 1] ?? ast;
|
|
8695
|
+
const getNearestVarScope = () => varTargetStack[varTargetStack.length - 1] ?? ast;
|
|
8696
|
+
function scan(node) {
|
|
8697
|
+
if (unsafe || !node || typeof node !== "object" || typeof node.type !== "string") {
|
|
6797
8698
|
return;
|
|
6798
8699
|
}
|
|
6799
|
-
if (node.type === "
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
8700
|
+
if (node.type === "WithStatement") {
|
|
8701
|
+
unsafe = true;
|
|
8702
|
+
return;
|
|
8703
|
+
}
|
|
8704
|
+
if (node.type === "Literal" && (typeof node.value === "bigint" || typeof node.bigint === "string") || node.type === "BigIntLiteral") {
|
|
8705
|
+
unsafe = true;
|
|
8706
|
+
return;
|
|
8707
|
+
}
|
|
8708
|
+
if (node.type === "Identifier" && node.name === "BigInt") {
|
|
8709
|
+
unsafe = true;
|
|
8710
|
+
return;
|
|
8711
|
+
}
|
|
8712
|
+
if (node.type === "ImportSpecifier" || node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier") {
|
|
8713
|
+
if (node.local?.type === "Identifier") {
|
|
8714
|
+
addBinding(ast, node.local.name);
|
|
8715
|
+
}
|
|
8716
|
+
} else if (node.type === "FunctionDeclaration") {
|
|
8717
|
+
if (node.id?.type === "Identifier") {
|
|
8718
|
+
addBinding(getNearestLexicalScope(), node.id.name);
|
|
8719
|
+
addBinding(getNearestVarScope(), node.id.name);
|
|
8720
|
+
}
|
|
8721
|
+
} else if (node.type === "ClassDeclaration") {
|
|
8722
|
+
if (node.id?.type === "Identifier") {
|
|
8723
|
+
addBinding(getNearestLexicalScope(), node.id.name);
|
|
8724
|
+
}
|
|
8725
|
+
} else if (node.type === "VariableDeclaration") {
|
|
8726
|
+
const targetScope = node.kind === "var" ? getNearestVarScope() : getNearestLexicalScope();
|
|
8727
|
+
for (const decl of node.declarations || []) {
|
|
8728
|
+
const names = [];
|
|
8729
|
+
collectBoundPatternNames(decl.id, names);
|
|
8730
|
+
for (const name of names) {
|
|
8731
|
+
addBinding(targetScope, name);
|
|
6814
8732
|
}
|
|
6815
|
-
} else if (arg.type === "UnaryExpression") {
|
|
6816
|
-
if (arg.operator === "!") seenBoolean = true;
|
|
6817
|
-
else if (arg.operator === "typeof") seenString = true;
|
|
6818
|
-
else if (arg.operator === "-" || arg.operator === "+" || arg.operator === "~") seenNumber = true;
|
|
6819
8733
|
}
|
|
6820
|
-
return;
|
|
6821
8734
|
}
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
8735
|
+
if (unsafe) return;
|
|
8736
|
+
const pushesLexical = BITWISE_LEXICAL_SCOPE_TYPES.has(node.type);
|
|
8737
|
+
const isFn = BITWISE_FUNCTION_TYPES.has(node.type);
|
|
8738
|
+
const isStaticBlock = node.type === "StaticBlock";
|
|
8739
|
+
if (pushesLexical) {
|
|
8740
|
+
scopeStack.push(node);
|
|
8741
|
+
if (!scopeBindings.has(node)) {
|
|
8742
|
+
scopeBindings.set(node, /* @__PURE__ */ new Set());
|
|
8743
|
+
}
|
|
8744
|
+
}
|
|
8745
|
+
if (isFn) {
|
|
8746
|
+
if (node.id?.type === "Identifier") {
|
|
8747
|
+
addBinding(node, node.id.name);
|
|
8748
|
+
}
|
|
8749
|
+
for (const param of node.params || []) {
|
|
8750
|
+
const names = [];
|
|
8751
|
+
collectBoundPatternNames(param, names);
|
|
8752
|
+
for (const name of names) {
|
|
8753
|
+
addBinding(node, name);
|
|
8754
|
+
}
|
|
8755
|
+
}
|
|
8756
|
+
const bodyScope = node.body?.type === "BlockStatement" ? node.body : node;
|
|
8757
|
+
varTargetStack.push(bodyScope);
|
|
8758
|
+
} else if (node.type === "Program" || isStaticBlock) {
|
|
8759
|
+
varTargetStack.push(node);
|
|
8760
|
+
} else if (node.type === "CatchClause" && node.param) {
|
|
8761
|
+
const names = [];
|
|
8762
|
+
collectBoundPatternNames(node.param, names);
|
|
8763
|
+
for (const name of names) {
|
|
8764
|
+
addBinding(node, name);
|
|
8765
|
+
}
|
|
8766
|
+
} else if (node.type === "ClassExpression" && node.id?.type === "Identifier") {
|
|
8767
|
+
addBinding(node, node.id.name);
|
|
8768
|
+
}
|
|
8769
|
+
try {
|
|
8770
|
+
for (const key of Object.keys(node)) {
|
|
8771
|
+
if (key === "loc" || key === "range" || key === "start" || key === "end" || key === "comments" || key === "tokens") {
|
|
8772
|
+
continue;
|
|
8773
|
+
}
|
|
8774
|
+
const child = node[key];
|
|
8775
|
+
if (Array.isArray(child)) {
|
|
8776
|
+
for (const item of child) {
|
|
8777
|
+
scan(item);
|
|
8778
|
+
if (unsafe) return;
|
|
8779
|
+
}
|
|
8780
|
+
} else if (child && typeof child === "object") {
|
|
8781
|
+
scan(child);
|
|
8782
|
+
if (unsafe) return;
|
|
8783
|
+
}
|
|
8784
|
+
}
|
|
8785
|
+
} finally {
|
|
8786
|
+
if (isFn || node.type === "Program" || isStaticBlock) {
|
|
8787
|
+
varTargetStack.pop();
|
|
8788
|
+
}
|
|
8789
|
+
if (pushesLexical) {
|
|
8790
|
+
scopeStack.pop();
|
|
6827
8791
|
}
|
|
6828
8792
|
}
|
|
6829
8793
|
}
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
if (seenObject) return "object";
|
|
6833
|
-
if (seenBoolean && !seenNumber && !seenString) return "boolean";
|
|
6834
|
-
if (seenNumber && !seenBoolean && !seenString) return "number";
|
|
6835
|
-
if (seenString && !seenNumber && !seenBoolean) return "string";
|
|
6836
|
-
return "object";
|
|
8794
|
+
scan(ast);
|
|
8795
|
+
return { unsafe, scopeBindings };
|
|
6837
8796
|
}
|
|
6838
|
-
function
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
0,
|
|
6842
|
-
{ ecmaVersion: "latest" }
|
|
8797
|
+
function isSafeAtomicIntegerLiteral(node) {
|
|
8798
|
+
return Boolean(
|
|
8799
|
+
node && node.type === "Literal" && typeof node.value === "number" && Number.isInteger(node.value) && node.value >= 0 && node.value <= 4294967295
|
|
6843
8800
|
);
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
return
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
8801
|
+
}
|
|
8802
|
+
function isZeroNumericLiteral(node) {
|
|
8803
|
+
return Boolean(node && node.type === "Literal" && typeof node.value === "number" && node.value === 0);
|
|
8804
|
+
}
|
|
8805
|
+
function isLocalBoundIdentifier(node, scopeStack, scopeBindings, programNode) {
|
|
8806
|
+
if (!node || node.type !== "Identifier") return false;
|
|
8807
|
+
if (FORBIDDEN_BITWISE_IDENTIFIERS.has(node.name)) return false;
|
|
8808
|
+
for (let i = scopeStack.length - 1; i >= 0; i--) {
|
|
8809
|
+
const scopeNode = scopeStack[i];
|
|
8810
|
+
if (scopeNode === programNode) return false;
|
|
8811
|
+
const bindings = scopeBindings.get(scopeNode);
|
|
8812
|
+
if (bindings && bindings.has(node.name)) {
|
|
8813
|
+
return true;
|
|
8814
|
+
}
|
|
8815
|
+
}
|
|
8816
|
+
return false;
|
|
8817
|
+
}
|
|
8818
|
+
function buildColdBitwiseConditional(op, left, right, seed, subIndex, hotExemptNodes) {
|
|
8819
|
+
const { m, mInv, c, d } = deriveAffineMbaParams(seed, 16640 + subIndex * 43);
|
|
8820
|
+
const a1 = cloneNode(left);
|
|
8821
|
+
const b1 = cloneNode(right);
|
|
8822
|
+
const a2 = cloneNode(left);
|
|
8823
|
+
const b2 = cloneNode(right);
|
|
8824
|
+
let affineComb;
|
|
8825
|
+
if (op === "^") {
|
|
8826
|
+
affineComb = makeBinary(
|
|
8827
|
+
"-",
|
|
8828
|
+
makeImul(makeLiteral(m), makeBinary("|", a1, b1)),
|
|
8829
|
+
makeImul(makeLiteral(m), makeBinary("&", a2, b2))
|
|
8830
|
+
);
|
|
8831
|
+
} else if (op === "|") {
|
|
8832
|
+
affineComb = makeBinary(
|
|
8833
|
+
"+",
|
|
8834
|
+
makeImul(makeLiteral(m), makeBinary("&", a1, b1)),
|
|
8835
|
+
makeImul(makeLiteral(m), makeBinary("^", a2, b2))
|
|
8836
|
+
);
|
|
8837
|
+
} else {
|
|
8838
|
+
affineComb = makeBinary(
|
|
8839
|
+
"-",
|
|
8840
|
+
makeImul(makeLiteral(m), makeBinary("|", a1, b1)),
|
|
8841
|
+
makeImul(makeLiteral(m), makeBinary("^", a2, b2))
|
|
8842
|
+
);
|
|
8843
|
+
}
|
|
8844
|
+
const innerWithC = makeBinary("|", makeBinary("+", affineComb, makeLiteral(c)), makeLiteral(0));
|
|
8845
|
+
const consequent = makeBinary(
|
|
8846
|
+
"|",
|
|
8847
|
+
makeBinary("+", makeImul(makeLiteral(mInv), innerWithC), makeLiteral(d)),
|
|
8848
|
+
makeLiteral(0)
|
|
8849
|
+
);
|
|
8850
|
+
const alternate = makeBinary(op, cloneNode(left), cloneNode(right));
|
|
8851
|
+
const exemptNodes = [];
|
|
8852
|
+
const uniqueIdents = [];
|
|
8853
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
8854
|
+
for (const operand of [left, right]) {
|
|
8855
|
+
if (operand?.type === "Identifier" && !seenNames.has(operand.name)) {
|
|
8856
|
+
seenNames.add(operand.name);
|
|
8857
|
+
uniqueIdents.push(operand);
|
|
8858
|
+
}
|
|
8859
|
+
}
|
|
8860
|
+
const makeIsNumberExpr = (ident) => {
|
|
8861
|
+
const numLit = makeLiteral("number");
|
|
8862
|
+
const eqNode = makeBinary("===", makeUnary("typeof", { type: "Identifier", name: ident.name }), numLit);
|
|
8863
|
+
exemptNodes.push(numLit, eqNode);
|
|
8864
|
+
return eqNode;
|
|
8865
|
+
};
|
|
8866
|
+
const testExpr = uniqueIdents.length === 2 ? {
|
|
8867
|
+
type: "LogicalExpression",
|
|
8868
|
+
operator: "&&",
|
|
8869
|
+
left: makeIsNumberExpr(uniqueIdents[0]),
|
|
8870
|
+
right: makeIsNumberExpr(uniqueIdents[1])
|
|
8871
|
+
} : makeIsNumberExpr(uniqueIdents[0]);
|
|
8872
|
+
const replacement = {
|
|
8873
|
+
type: "ConditionalExpression",
|
|
8874
|
+
test: testExpr,
|
|
8875
|
+
consequent,
|
|
8876
|
+
alternate,
|
|
8877
|
+
_unpeekGuardSubtree: true
|
|
8878
|
+
};
|
|
8879
|
+
if (hotExemptNodes) {
|
|
8880
|
+
hotExemptNodes.add(replacement);
|
|
8881
|
+
hotExemptNodes.add(testExpr);
|
|
8882
|
+
for (const nodeToExempt of exemptNodes) {
|
|
8883
|
+
hotExemptNodes.add(nodeToExempt);
|
|
8884
|
+
}
|
|
8885
|
+
}
|
|
8886
|
+
return replacement;
|
|
8887
|
+
}
|
|
8888
|
+
function applyColdBitwiseMba(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes, guardSubtreeNodes) {
|
|
8889
|
+
const { unsafe, scopeBindings } = analyzeBitwiseMbaScopes(ast);
|
|
8890
|
+
if (unsafe) return 0;
|
|
8891
|
+
let mbaCount = 0;
|
|
8892
|
+
const scopeStack = [];
|
|
8893
|
+
function walkTransform(node, setInParent, inColdFn) {
|
|
8894
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) return;
|
|
8895
|
+
if (!node || typeof node !== "object" || typeof node.type !== "string") return;
|
|
8896
|
+
if (hotExemptNodes?.has(node) || guardSubtreeNodes?.has(node)) return;
|
|
8897
|
+
if (node._unpeekGuardSubtree === true) return;
|
|
8898
|
+
if (node._unpeekSerialized || node._unpeekVirtualized === true) return;
|
|
8899
|
+
if (BITWISE_LOOP_NODE_TYPES.has(node.type)) return;
|
|
8900
|
+
const pushedScope = scopeBindings.has(node);
|
|
8901
|
+
if (pushedScope) scopeStack.push(node);
|
|
8902
|
+
try {
|
|
8903
|
+
const childInColdFn = BITWISE_FUNCTION_TYPES.has(node.type) ? coldFunctionNodes.has(node) : inColdFn;
|
|
8904
|
+
if (childInColdFn && node.type === "BinaryExpression" && BITWISE_MBA_OPS.has(node.operator)) {
|
|
8905
|
+
const op = node.operator;
|
|
8906
|
+
const { left, right } = node;
|
|
8907
|
+
const isCoercionOrZero = op === "|" && isZeroNumericLiteral(right);
|
|
8908
|
+
if (!isCoercionOrZero) {
|
|
8909
|
+
const leftAtomic = isSafeAtomicIntegerLiteral(left) || isLocalBoundIdentifier(left, scopeStack, scopeBindings, ast);
|
|
8910
|
+
const rightAtomic = isSafeAtomicIntegerLiteral(right) || isLocalBoundIdentifier(right, scopeStack, scopeBindings, ast);
|
|
8911
|
+
const hasIdent = left?.type === "Identifier" || right?.type === "Identifier";
|
|
8912
|
+
if (leftAtomic && rightAtomic && hasIdent) {
|
|
8913
|
+
const replacement = buildColdBitwiseConditional(
|
|
8914
|
+
op,
|
|
8915
|
+
left,
|
|
8916
|
+
right,
|
|
8917
|
+
seed,
|
|
8918
|
+
mbaCount,
|
|
8919
|
+
hotExemptNodes
|
|
8920
|
+
);
|
|
8921
|
+
mbaCount++;
|
|
8922
|
+
setInParent(replacement);
|
|
8923
|
+
return;
|
|
8924
|
+
}
|
|
6865
8925
|
}
|
|
6866
|
-
},
|
|
6867
|
-
{
|
|
6868
|
-
type: "VariableDeclarator",
|
|
6869
|
-
id: { type: "Identifier", name: aliasIdentB },
|
|
6870
|
-
init: { type: "Identifier", name: aliasIdentA }
|
|
6871
|
-
},
|
|
6872
|
-
{
|
|
6873
|
-
type: "VariableDeclarator",
|
|
6874
|
-
id: { type: "Identifier", name: scratchVarIdent },
|
|
6875
|
-
init: makeLiteral(0)
|
|
6876
8926
|
}
|
|
6877
|
-
|
|
6878
|
-
|
|
8927
|
+
for (const key of Object.keys(node)) {
|
|
8928
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) break;
|
|
8929
|
+
if (key === "loc" || key === "range" || key === "start" || key === "end" || key === "comments" || key === "tokens") {
|
|
8930
|
+
continue;
|
|
8931
|
+
}
|
|
8932
|
+
const child = node[key];
|
|
8933
|
+
if (Array.isArray(child)) {
|
|
8934
|
+
for (let i = 0; i < child.length; i++) {
|
|
8935
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) break;
|
|
8936
|
+
const item = child[i];
|
|
8937
|
+
if (item && typeof item === "object" && typeof item.type === "string") {
|
|
8938
|
+
walkTransform(
|
|
8939
|
+
item,
|
|
8940
|
+
(rep) => {
|
|
8941
|
+
child[i] = rep;
|
|
8942
|
+
},
|
|
8943
|
+
childInColdFn
|
|
8944
|
+
);
|
|
8945
|
+
}
|
|
8946
|
+
}
|
|
8947
|
+
} else if (child && typeof child === "object" && typeof child.type === "string") {
|
|
8948
|
+
walkTransform(
|
|
8949
|
+
child,
|
|
8950
|
+
(rep) => {
|
|
8951
|
+
node[key] = rep;
|
|
8952
|
+
},
|
|
8953
|
+
childInColdFn
|
|
8954
|
+
);
|
|
8955
|
+
}
|
|
8956
|
+
}
|
|
8957
|
+
} finally {
|
|
8958
|
+
if (pushedScope) scopeStack.pop();
|
|
8959
|
+
}
|
|
8960
|
+
}
|
|
8961
|
+
walkTransform(ast, () => {
|
|
8962
|
+
}, false);
|
|
8963
|
+
return mbaCount;
|
|
6879
8964
|
}
|
|
6880
|
-
|
|
6881
|
-
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
|
|
6882
|
-
const decoyIdent = "_d";
|
|
8965
|
+
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes, windowKeySymbol, expectedDelta, shieldCoupled = false, options) {
|
|
6883
8966
|
const sfx = (seed >>> 0).toString(36).slice(0, 4);
|
|
8967
|
+
const decoyIdent = `_uDec${sfx}`;
|
|
6884
8968
|
const sboxIdent = `_uSb${sfx}`;
|
|
6885
8969
|
const aliasIdentA = `_uAl${sfx}`;
|
|
6886
8970
|
const aliasIdentB = `_uAm${sfx}`;
|
|
6887
8971
|
const scratchVarIdent = `_uZt${sfx}`;
|
|
8972
|
+
const mxIdent = `_uMx${sfx}`;
|
|
6888
8973
|
if (Array.isArray(ast.body)) {
|
|
6889
8974
|
const alreadyGuarded = ast.body.some(
|
|
6890
8975
|
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
6891
|
-
(d) => d.id?.type === "Identifier" && (d.id.name === decoyIdent || d.id.name === sboxIdent)
|
|
8976
|
+
(d) => d.id?.type === "Identifier" && (d.id.name === decoyIdent || d.id.name === sboxIdent || d.id.name === mxIdent)
|
|
6892
8977
|
)
|
|
6893
8978
|
);
|
|
6894
8979
|
if (alreadyGuarded) return 0;
|
|
6895
8980
|
}
|
|
8981
|
+
if (options?.enableBitwiseMba) {
|
|
8982
|
+
applyColdBitwiseMba(ast, coldFunctionNodes, seed, hotExemptNodes);
|
|
8983
|
+
}
|
|
6896
8984
|
let guardedCount = 0;
|
|
6897
8985
|
function maybeInjectGuard(node) {
|
|
6898
8986
|
if (guardedCount >= MAX_COLD_GUARDS_PER_CHUNK) return;
|
|
@@ -6919,10 +9007,15 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
6919
9007
|
aliasIdentA,
|
|
6920
9008
|
aliasIdentB,
|
|
6921
9009
|
scratchVarIdent,
|
|
6922
|
-
|
|
9010
|
+
mxIdent,
|
|
9011
|
+
returnDomain,
|
|
9012
|
+
windowKeySymbol,
|
|
9013
|
+
expectedDelta,
|
|
9014
|
+
shieldCoupled
|
|
6923
9015
|
}
|
|
6924
9016
|
);
|
|
6925
9017
|
guardedCount++;
|
|
9018
|
+
guardStmt._unpeekGuardSubtree = true;
|
|
6926
9019
|
if (hotExemptNodes) {
|
|
6927
9020
|
hotExemptNodes.add(guardStmt);
|
|
6928
9021
|
hotExemptNodes.add(guardStmt.consequent);
|
|
@@ -6949,11 +9042,17 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
6949
9042
|
aliasIdentA,
|
|
6950
9043
|
aliasIdentB,
|
|
6951
9044
|
scratchVarIdent,
|
|
6952
|
-
seed
|
|
9045
|
+
seed,
|
|
9046
|
+
mxIdent
|
|
6953
9047
|
);
|
|
6954
9048
|
if (hotExemptNodes) {
|
|
6955
9049
|
hotExemptNodes.add(sharedDecoyDecl);
|
|
6956
9050
|
hotExemptNodes.add(sboxAliasDecl);
|
|
9051
|
+
for (const decl of sboxAliasDecl.declarations || []) {
|
|
9052
|
+
if (decl.init?.type === "FunctionExpression") {
|
|
9053
|
+
hotExemptNodes.add(decl.init);
|
|
9054
|
+
}
|
|
9055
|
+
}
|
|
6957
9056
|
for (const decl of sharedDecoyDecl.declarations || []) {
|
|
6958
9057
|
if (decl.init?.type === "ArrayExpression" && decl.init.elements) {
|
|
6959
9058
|
for (const el of decl.init.elements) {
|
|
@@ -7052,7 +9151,7 @@ function mixOpSeed(seed, salt) {
|
|
|
7052
9151
|
h ^= h >>> 13;
|
|
7053
9152
|
return h | 0;
|
|
7054
9153
|
}
|
|
7055
|
-
function encryptBytecodeStream(plainBytecode, fnSalt, vmKey, stateSlots, accSlots) {
|
|
9154
|
+
function encryptBytecodeStream(plainBytecode, fnSalt, vmKey, stateSlots, accSlots, jumpTargets) {
|
|
7056
9155
|
const len = plainBytecode.length;
|
|
7057
9156
|
const enc = new Array(len);
|
|
7058
9157
|
const stateBefore = new Array(len + 1);
|
|
@@ -7083,14 +9182,14 @@ function encryptBytecodeStream(plainBytecode, fnSalt, vmKey, stateSlots, accSlot
|
|
|
7083
9182
|
accBefore[len] = ac;
|
|
7084
9183
|
if (stateSlots) {
|
|
7085
9184
|
for (const slot of stateSlots) {
|
|
7086
|
-
const targetPc = plainBytecode[slot - 1];
|
|
9185
|
+
const targetPc = jumpTargets?.get(slot - 1) ?? plainBytecode[slot - 1];
|
|
7087
9186
|
const sBefore = stAtSlot.get(slot) ?? 0;
|
|
7088
9187
|
enc[slot] = stateBefore[targetPc] ^ sBefore | 0;
|
|
7089
9188
|
}
|
|
7090
9189
|
}
|
|
7091
9190
|
if (accSlots) {
|
|
7092
9191
|
for (const slot of accSlots) {
|
|
7093
|
-
const targetPc = plainBytecode[slot - 2];
|
|
9192
|
+
const targetPc = jumpTargets?.get(slot - 2) ?? plainBytecode[slot - 2];
|
|
7094
9193
|
const aBefore = acAtSlot.get(slot) ?? 0;
|
|
7095
9194
|
enc[slot] = accBefore[targetPc] ^ aBefore | 0;
|
|
7096
9195
|
}
|
|
@@ -7115,43 +9214,39 @@ function generateOpcodeMap(seed, count = OPCODE_COUNT) {
|
|
|
7115
9214
|
}
|
|
7116
9215
|
return pool.slice(0, count);
|
|
7117
9216
|
}
|
|
7118
|
-
function
|
|
7119
|
-
const
|
|
7120
|
-
return
|
|
9217
|
+
function computeHandlerBias(seed, op) {
|
|
9218
|
+
const mixed = Math.abs(mixOpSeed(seed, op * 19 + 7)) % 31;
|
|
9219
|
+
return mixed + 1;
|
|
7121
9220
|
}
|
|
7122
|
-
function makeHandlerMbaOffsetExpr(seed, op,
|
|
9221
|
+
function makeHandlerMbaOffsetExpr(seed, op, bias) {
|
|
7123
9222
|
const variant = Math.abs(mixOpSeed(seed, op * 11 + 3)) % 4;
|
|
7124
9223
|
const c1 = mixOpSeed(seed, op * 11 + 5);
|
|
7125
9224
|
const c2 = mixOpSeed(seed, op * 11 + 7);
|
|
7126
9225
|
if (variant === 0) {
|
|
7127
|
-
const cSum = c1 + c2 -
|
|
9226
|
+
const cSum = c1 + c2 - bias | 0;
|
|
7128
9227
|
return `(((((($f.ac|${c1})+($f.ac&${c1}))|0)|((($f.p^${c2})+(($f.p&${c2})<<1))|0))+((((($f.ac|${c1})+($f.ac&${c1}))|0)&((($f.p^${c2})+(($f.p&${c2})<<1))|0))))-(((((($f.ac^$f.p)+(($f.ac&$f.p)<<1))|0)|${cSum})+((((($f.ac^$f.p)+(($f.ac&$f.p)<<1))|0)&${cSum})))|0))|0`;
|
|
7129
9228
|
}
|
|
7130
9229
|
if (variant === 1) {
|
|
7131
|
-
const cSum = c1 + c2 +
|
|
9230
|
+
const cSum = c1 + c2 + bias | 0;
|
|
7132
9231
|
return `((((($f.ac|$f.p)<<1)-($f.ac^$f.p))+${cSum})-((($f.ac^${c1})+(($f.ac&${c1})<<1))+(($f.p|${c2})+($f.p&${c2}))))|0`;
|
|
7133
9232
|
}
|
|
7134
9233
|
if (variant === 2) {
|
|
7135
|
-
const cFold2 = 1 +
|
|
9234
|
+
const cFold2 = 1 + bias - c1 - c2 | 0;
|
|
7136
9235
|
return `(((~$f.ac|${c1})+(~$f.ac&${c1}))+(($f.ac|$f.p)-(~$f.ac&$f.p))+(($f.p&${c2})+(~$f.p&${c2}))+${cFold2})|0`;
|
|
7137
9236
|
}
|
|
7138
|
-
const cFold = c1 -
|
|
9237
|
+
const cFold = c1 - bias | 0;
|
|
7139
9238
|
return `((((($f.ac|$f.p)-(~$f.ac&$f.p))|${c1})+((($f.ac|$f.p)-(~$f.ac&$f.p))&${c1}))-(((($f.ac&${c2})+($f.ac&~${c2}))^${cFold})+(((($f.ac&${c2})+($f.ac&~${c2}))&${cFold})<<1)))|0`;
|
|
7140
9239
|
}
|
|
7141
9240
|
function wrapHandlerWithMba(seed, op, coreBody, isTerminal = false) {
|
|
7142
|
-
const
|
|
7143
|
-
const zExpr = makeHandlerMbaOffsetExpr(seed, op,
|
|
9241
|
+
const bias = computeHandlerBias(seed, op);
|
|
9242
|
+
const zExpr = makeHandlerMbaOffsetExpr(seed, op, bias);
|
|
7144
9243
|
const shape = Math.abs(mixOpSeed(seed, op * 17 + 1)) % 3;
|
|
7145
9244
|
const zVar = shape === 0 ? "$z0" : shape === 1 ? "$m0" : "$k0";
|
|
7146
9245
|
const tail = isTerminal ? "return void 0;" : shape === 0 ? "return $step($f);" : shape === 1 ? "var $nx=$step($f);return $nx;" : "return $f.d?void 0:$step($f);";
|
|
7147
|
-
const
|
|
7148
|
-
|
|
7149
|
-
if (coreBody.includes("$Z")) {
|
|
7150
|
-
return `function($f){var ${zVar}=${zExpr};${adjustedBody}${tail}}`;
|
|
7151
|
-
}
|
|
7152
|
-
return `function($f){var ${zVar}=${zExpr};$f.r=($f.r+${balancedOffset})|0;${adjustedBody}${tail}}`;
|
|
9246
|
+
const adjustedBody = coreBody.replace(/\$Z/g, zVar).replace(/\$B/g, String(bias));
|
|
9247
|
+
return `function($f){var ${zVar}=${zExpr};${adjustedBody}${tail}}`;
|
|
7153
9248
|
}
|
|
7154
|
-
function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowKeySymbol, expectedDelta) {
|
|
9249
|
+
function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowKeySymbol, expectedDelta, expectedStateHash) {
|
|
7155
9250
|
const opCount = opMap.length;
|
|
7156
9251
|
const slotMap = shuffleRange(opCount, (seed ^ 1367130551) >>> 0);
|
|
7157
9252
|
const pairOrder = shuffleRange(opCount, (seed ^ 1013904242) >>> 0);
|
|
@@ -7166,52 +9261,52 @@ function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowK
|
|
|
7166
9261
|
const andImpl = Math.abs(mixOpSeed(seed, OP_AND)) % 2 === 0 ? "~(~$a|~$b)" : "$a&$b";
|
|
7167
9262
|
const orImpl = Math.abs(mixOpSeed(seed, OP_OR)) % 2 === 0 ? "(($a^$b)+($a&$b))|0" : "$a|$b";
|
|
7168
9263
|
const coreHandlers = {
|
|
7169
|
-
[OP_LDC]: { body: "$f.q[
|
|
7170
|
-
[OP_LDV]: { body: "$f.q[
|
|
7171
|
-
[OP_STV]: { body: "$f.s[$rd($f)]=$f.q[
|
|
7172
|
-
[OP_LDG]: { body: "$f.q[
|
|
7173
|
-
[OP_GETP]: { body: "var $b=$f.q[
|
|
7174
|
-
[OP_SETP]: { body: "var $v=$f.q[
|
|
7175
|
-
[OP_CALL]: { body: "var $n
|
|
7176
|
-
[OP_MCALL]: { body: "var $n
|
|
7177
|
-
[OP_ADD]: { body: "var $b=$f.q[
|
|
7178
|
-
[OP_SUB]: { body: "var $b=$f.q[
|
|
7179
|
-
[OP_MUL]: { body: "var $b=$f.q[
|
|
7180
|
-
[OP_XOR]: { body:
|
|
7181
|
-
[OP_AND]: { body:
|
|
7182
|
-
[OP_OR]: { body:
|
|
7183
|
-
[OP_SEQ]: { body: "var $b=$f.q[
|
|
7184
|
-
[OP_LT]: { body: "var $b=$f.q[
|
|
7185
|
-
[OP_NOT]: { body: "$f.q[
|
|
7186
|
-
[OP_JMP]: { body: "var $j
|
|
7187
|
-
[OP_JZ]: { body: "var $j
|
|
7188
|
-
[OP_RET]: { body: "$f.d=1;$f.v=$f.q[(
|
|
7189
|
-
[OP_THROW]: { body: "
|
|
9264
|
+
[OP_LDC]: { body: "$f.q[$f.r++]=$f.k[($rd($f)-$Z)&0xffff];" },
|
|
9265
|
+
[OP_LDV]: { body: "$f.q[$f.r++]=$f.s[($rd($f)-$Z)&0xffff];" },
|
|
9266
|
+
[OP_STV]: { body: "$f.s[($rd($f)-$Z)&0xffff]=$f.q[--$f.r];" },
|
|
9267
|
+
[OP_LDG]: { body: "$f.q[$f.r++]=$G[$f.k[($rd($f)-$Z)&0xffff]];" },
|
|
9268
|
+
[OP_GETP]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a[$b];$f.r=($f.r-$B)|0;" },
|
|
9269
|
+
[OP_SETP]: { body: "$f.r=($f.r+$Z)|0;var $v=$f.q[($f.r-=1)-$B],$b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=($a[$b]=$v);$f.r=($f.r-$B)|0;" },
|
|
9270
|
+
[OP_CALL]: { body: "var $n=($rd($f)-$Z)&0xffff,$g=[];for(var $i=$n-1;$i>=0;$i--)$g[$i]=$f.q[--$f.r];var $fn=$f.q[--$f.r];$f.q[$f.r++]=$fn.apply(void 0,$g);" },
|
|
9271
|
+
[OP_MCALL]: { body: "var $n=($rd($f)-$Z)&0xffff,$g=[];for(var $i=$n-1;$i>=0;$i--)$g[$i]=$f.q[--$f.r];var $b=$f.q[--$f.r],$a=$f.q[--$f.r];$f.q[$f.r++]=$a[$b].apply($a,$g);" },
|
|
9272
|
+
[OP_ADD]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a+$b;$f.r=($f.r-$B)|0;" },
|
|
9273
|
+
[OP_SUB]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a-$b;$f.r=($f.r-$B)|0;" },
|
|
9274
|
+
[OP_MUL]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a*$b;$f.r=($f.r-$B)|0;" },
|
|
9275
|
+
[OP_XOR]: { body: `$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=${xorImpl};$f.r=($f.r-$B)|0;` },
|
|
9276
|
+
[OP_AND]: { body: `$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=${andImpl};$f.r=($f.r-$B)|0;` },
|
|
9277
|
+
[OP_OR]: { body: `$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=${orImpl};$f.r=($f.r-$B)|0;` },
|
|
9278
|
+
[OP_SEQ]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a===$b;$f.r=($f.r-$B)|0;" },
|
|
9279
|
+
[OP_LT]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a<$b;$f.r=($f.r-$B)|0;" },
|
|
9280
|
+
[OP_NOT]: { body: "$f.r=($f.r+$Z)|0;$f.q[$f.r-(1+$B)]=!$f.q[$f.r-(1+$B)];$f.r=($f.r-$B)|0;" },
|
|
9281
|
+
[OP_JMP]: { body: "var $j=($rd($f)-$Z)&0xffff,$ts=$f.c[$f.p++]^$f.st,$ta=$f.c[$f.p++]^$f.ac;$f.p=$j;$f.st=$ts;$f.ac=$ta;" },
|
|
9282
|
+
[OP_JZ]: { body: "var $j=($rd($f)-$Z)&0xffff,$ts=$f.c[$f.p++]^$f.st,$ta=$f.c[$f.p++]^$f.ac;if(!$f.q[--$f.r]){$f.p=$j;$f.st=$ts;$f.ac=$ta;}" },
|
|
9283
|
+
[OP_RET]: { body: "$f.r=($f.r+$Z)|0;$f.d=1;$f.v=$f.q[($f.r-=1)-$B];$f.r=($f.r-$B)|0;", terminal: true },
|
|
9284
|
+
[OP_THROW]: { body: "$f.r=($f.r+$Z)|0;var $tv=$f.q[($f.r-=1)-$B];$f.r=($f.r-$B)|0;throw $tv;" },
|
|
7190
9285
|
[OP_AWAIT]: {
|
|
7191
|
-
body: "var $v=$f.q[(
|
|
9286
|
+
body: "$f.r=($f.r+$Z)|0;var $v=$f.q[($f.r-=1)-$B];$f.r=($f.r-$B)|0;$f.d=2;$f.v=Promise.resolve($v).then(function($w){$f.d=0;$f.q[$f.r++]=$w;return $x($f);},function($e){if($f.e.length>0){var $ex=$f.e.pop();$f.d=0;$f.r=$ex.r;$f.q[$f.r++]=$e;$f.p=$ex.p;$f.st=$ex.s;$f.ac=$ex.a;return $x($f);}throw $e;});",
|
|
7192
9287
|
terminal: true
|
|
7193
9288
|
},
|
|
7194
|
-
[OP_OBJ]: { body: "var $n
|
|
7195
|
-
[OP_ARR]: { body: "var $n
|
|
7196
|
-
[OP_LDU]: { body: "$f.q[
|
|
7197
|
-
[OP_STU]: { body: "$f.u[$rd($f)][1]($f.q[
|
|
7198
|
-
[OP_DIV]: { body: "var $b=$f.q[
|
|
7199
|
-
[OP_MOD]: { body: "var $b=$f.q[
|
|
7200
|
-
[OP_SHL]: { body: "var $b=$f.q[
|
|
7201
|
-
[OP_SHR]: { body: "var $b=$f.q[
|
|
7202
|
-
[OP_USHR]: { body: "var $b=$f.q[
|
|
7203
|
-
[OP_POW]: { body: "var $b=$f.q[
|
|
7204
|
-
[OP_EQ]: { body: "var $b=$f.q[
|
|
7205
|
-
[OP_TYPEOF]: { body: "$f.q[
|
|
7206
|
-
[OP_IN]: { body: "var $b=$f.q[
|
|
7207
|
-
[OP_INSTOF]: { body: "var $b=$f.q[
|
|
7208
|
-
[OP_NEW]: { body: "var $n
|
|
7209
|
-
[OP_THIS]: { body: "$f.q[($f.r++)
|
|
7210
|
-
[OP_POP]: { body: "
|
|
7211
|
-
[OP_TRY]: { body: "var $cp
|
|
7212
|
-
[OP_ENDTRY]: { body: "$f.e.pop();$f.r
|
|
7213
|
-
[OP_NULLISH]: { body: "var $v=$f.q[
|
|
7214
|
-
[OP_DUP]: { body: "var $top=$f.q[
|
|
9289
|
+
[OP_OBJ]: { body: "var $n=($rd($f)-$Z)&0xffff,$o={},$e=[];for(var $i=0;$i<$n;$i++){var $v=$f.q[--$f.r],$ky=$f.q[--$f.r];$e.push([$ky,$v]);}for(var $i=$e.length-1;$i>=0;$i--){$o[$e[$i][0]]=$e[$i][1];}$f.q[$f.r++]=$o;" },
|
|
9290
|
+
[OP_ARR]: { body: "var $n=($rd($f)-$Z)&0xffff,$a=[];for(var $i=$n-1;$i>=0;$i--)$a[$i]=$f.q[--$f.r];$f.q[$f.r++]=$a;" },
|
|
9291
|
+
[OP_LDU]: { body: "$f.q[$f.r++]=$f.u[($rd($f)-$Z)&0xffff][0]();" },
|
|
9292
|
+
[OP_STU]: { body: "$f.u[($rd($f)-$Z)&0xffff][1]($f.q[--$f.r]);" },
|
|
9293
|
+
[OP_DIV]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a/$b;$f.r=($f.r-$B)|0;" },
|
|
9294
|
+
[OP_MOD]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a%$b;$f.r=($f.r-$B)|0;" },
|
|
9295
|
+
[OP_SHL]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a<<$b;$f.r=($f.r-$B)|0;" },
|
|
9296
|
+
[OP_SHR]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a>>$b;$f.r=($f.r-$B)|0;" },
|
|
9297
|
+
[OP_USHR]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a>>>$b;$f.r=($f.r-$B)|0;" },
|
|
9298
|
+
[OP_POW]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a**$b;$f.r=($f.r-$B)|0;" },
|
|
9299
|
+
[OP_EQ]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a==$b;$f.r=($f.r-$B)|0;" },
|
|
9300
|
+
[OP_TYPEOF]: { body: "$f.r=($f.r+$Z)|0;$f.q[$f.r-(1+$B)]=typeof $f.q[$f.r-(1+$B)];$f.r=($f.r-$B)|0;" },
|
|
9301
|
+
[OP_IN]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a in $b;$f.r=($f.r-$B)|0;" },
|
|
9302
|
+
[OP_INSTOF]: { body: "$f.r=($f.r+$Z)|0;var $b=$f.q[($f.r-=1)-$B],$a=$f.q[($f.r-=1)-$B];$f.q[($f.r++)-$B]=$a instanceof $b;$f.r=($f.r-$B)|0;" },
|
|
9303
|
+
[OP_NEW]: { body: "var $n=($rd($f)-$Z)&0xffff,$g=[];for(var $i=$n-1;$i>=0;$i--)$g[$i]=$f.q[--$f.r];var $fn=$f.q[--$f.r];$f.q[$f.r++]=new $fn(...$g);" },
|
|
9304
|
+
[OP_THIS]: { body: "$f.r=($f.r+$Z)|0;$f.q[($f.r++)-$B]=$f.t;$f.r=($f.r-$B)|0;" },
|
|
9305
|
+
[OP_POP]: { body: "$f.r=($f.r+$Z)|0;$f.r=($f.r-(1+$B))|0;" },
|
|
9306
|
+
[OP_TRY]: { body: "var $cp=($rd($f)-$Z)&0xffff,$cs=$f.c[$f.p++]^$f.st,$ca=$f.c[$f.p++]^$f.ac;$f.e.push({p:$cp,r:$f.r,s:$cs,a:$ca});" },
|
|
9307
|
+
[OP_ENDTRY]: { body: "$f.r=($f.r+$Z)|0;$f.e.pop();$f.r=($f.r-$B)|0;" },
|
|
9308
|
+
[OP_NULLISH]: { body: "$f.r=($f.r+$Z)|0;var $v=$f.q[$f.r-(1+$B)];$f.q[$f.r-(1+$B)]=($v===null||$v===void 0);$f.r=($f.r-$B)|0;" },
|
|
9309
|
+
[OP_DUP]: { body: "$f.r=($f.r+$Z)|0;var $top=$f.q[$f.r-(1+$B)];$f.q[($f.r++)-$B]=$top;$f.r=($f.r-$B)|0;" }
|
|
7215
9310
|
};
|
|
7216
9311
|
const handlers = new Array(opCount);
|
|
7217
9312
|
for (let op = 0; op < opCount; op++) {
|
|
@@ -7220,17 +9315,25 @@ function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowK
|
|
|
7220
9315
|
}
|
|
7221
9316
|
const hasSym = Boolean(windowKeySymbol);
|
|
7222
9317
|
const hasExpDelta = Boolean(hasSym && expectedDelta !== void 0);
|
|
9318
|
+
const hasExpHash = Boolean(hasSym && expectedStateHash !== void 0);
|
|
9319
|
+
const hasDigest = hasExpDelta || hasExpHash;
|
|
7223
9320
|
const symPropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(windowKeySymbol) ? `.${windowKeySymbol}` : `[${JSON.stringify(windowKeySymbol)}]` : "";
|
|
7224
9321
|
const symTamperPropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(`${windowKeySymbol}_t`) ? `.${windowKeySymbol}_t` : `[${JSON.stringify(`${windowKeySymbol}_t`)}]` : "";
|
|
7225
9322
|
const symStatePropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(`${windowKeySymbol}_s`) ? `.${windowKeySymbol}_s` : `[${JSON.stringify(`${windowKeySymbol}_s`)}]` : "";
|
|
7226
9323
|
const expD = hasExpDelta ? expectedDelta & 65535 : 0;
|
|
9324
|
+
const expH = hasExpHash ? expectedStateHash | 0 : 0;
|
|
7227
9325
|
const seed32 = seed | 0;
|
|
7228
9326
|
const seedU32 = seed >>> 0;
|
|
7229
|
-
const scopeKey = hasSym ? computeFnv1aHash(
|
|
7230
|
-
|
|
9327
|
+
const scopeKey = hasSym ? computeFnv1aHash(
|
|
9328
|
+
`${windowKeySymbol}:${hasExpDelta ? expD : ""}${hasExpHash ? `:${expH}` : ""}`,
|
|
9329
|
+
seed
|
|
9330
|
+
) >>> 0 : 0;
|
|
9331
|
+
const expDigest = hasExpDelta ? hasExpHash ? Math.imul(expD ^ expH ^ seed32 | 0, 2654435761) ^ (expD << 16 | seed32 >>> 16) ^ (expH >>> 13 | expH << 19) ^ 2246822507 | 0 : Math.imul(expD ^ seed32 | 0, 2654435761) ^ (expD << 16 | seed32 >>> 16) ^ 2246822507 | 0 : hasExpHash ? Math.imul(expH ^ seed32 | 0, 2654435761) ^ (expH >>> 13 | expH << 19) ^ 2246822507 | 0 : 0;
|
|
7231
9332
|
const selfPrettyCheck = "$pp||/\\n/.test(Function.prototype.toString.call($vm))";
|
|
7232
|
-
const
|
|
7233
|
-
const
|
|
9333
|
+
const asyncEnvGuard = "var $br=(typeof window<'u'&&typeof document<'u'&&window.document===document&&document.nodeType===9&&document.scripts&&document.scripts.length>0&&document.readyState!==['co','mp','le','te'].join(''))||(typeof self<'u'&&typeof self.importScripts===['fu','nct','ion'].join(''));";
|
|
9334
|
+
const svPresentBranch = hasExpHash ? hasExpDelta ? "else if(!Array.isArray($sr)||$sr[0]!==1||$sv!==($sv|0)){$bad=!0;}else{var $s1=$sr[1]|0,$sh=(Math.imul(($sv^$s1^$S)|0,0x9e3779b1)^(($sv<<16)|($S>>>16))^(($s1>>>13)|($s1<<19))^0x85ebca6b)|0;if($sh!==$D)$bad=!0;}" : "else if(!Array.isArray($sr)||$sr[0]!==1){$bad=!0;}else{var $s1=$sr[1]|0,$sh=(Math.imul(($s1^$S)|0,0x9e3779b1)^(($s1>>>13)|($s1<<19))^0x85ebca6b)|0;if($sh!==$D)$bad=!0;}" : `else if(Array.isArray($sv)){if($sv[0]===2)$bad=!0;}${hasExpDelta ? "else if($sv!==($sv|0)){$bad=!0;}else{var $sh=(Math.imul(($sv^$S)|0,0x9e3779b1)^(($sv<<16)|($S>>>16))^0x85ebca6b)|0;if($sh!==$D)$bad=!0;}" : ""}`;
|
|
9335
|
+
const tamperCheckExpr = hasSym ? `var $sr=$G?$G${symStatePropAccess}:void 0,$bad=${selfPrettyCheck}||($G&&($G[$tk]===!0||$G${symTamperPropAccess}===!0||($sr&&$sr[0]===2))),$sv=$G?$G${symPropAccess}:void 0;if(!$bad){${asyncEnvGuard}if($sv===void 0){if(!$br)$bad=!0;}${svPresentBranch}}` : `var $bad=${selfPrettyCheck}||($G&&$G[$tk]===!0);`;
|
|
9336
|
+
const paramsList = hasDigest ? "$P,$A,$B,$C,$S,$D" : "$P,$A,$B,$C,$S";
|
|
7234
9337
|
const factoryRaw = `(function $I(${paramsList}){var $G=typeof globalThis<"u"?globalThis:(typeof window<"u"?window:(typeof self<"u"?self:this));var $pp=/\\n/.test(Function.prototype.toString.call($I));var $rk=['__','unp','eek','_vm'].join('');var $rg=0,$rs=0;try{$rg=$G?($G[$rk]||($G[$rk]={})) : 0;$rs=$rg?($rg[${scopeKey}]||($rg[${scopeKey}]={})) : 0;if(!$pp&&$rs&&$rs[${seedU32}])return $rs[${seedU32}];}catch($e){}var $tk=['__','unp','eek','_ta','mpe','red'].join('');var $M=[],$ok=$A&255,$sk=$B&255,$vk=$C|0;for(var $j=0;$j<$P.length;$j+=2)$M[$P[$j]]=$P[$j+1];function $rd($f){var $p=$f.p++;var $x0=$f.st=(Math.imul($f.st^($p+1),0x45d9f3b)+(($f.ac|0x9e3779b9)+($f.ac&0x9e3779b9)))|0;var $w=$f.c[$p],$v=$w^(($x0>>>16)&0xffff);$f.st=($f.st^Math.imul($w+1,0x85ebca6b))|0;$f.ac=(Math.imul($f.ac^$v,0x27d4eb2d)^(($f.st>>>13)|($f.st<<19)))|0;return $v;}var $H=[${handlers.join(
|
|
7235
9338
|
","
|
|
7236
9339
|
)}];function $step($f){if($f.d||$f.p>=$f.c.length)return void 0;var $o=$rd($f),$m=$M[$o^$ok];return $m!==void 0?$H[$m^$sk]:void 0;}function $x($f){var $fn=$step($f);while($fn!==void 0){try{$fn=$fn($f);}catch($err){if($f.e.length>0){var $ex=$f.e.pop();$f.r=$ex.r;$f.q[$f.r++]=$err;$f.p=$ex.p;$f.st=$ex.s;$f.ac=$ex.a;$fn=$step($f);}else{throw $err;}}}return $f.v;}var $vm=function($c,$k,$s0,$t,$a,$u){${tamperCheckExpr}var $flt=$bad?(Math.imul($vk^$a,0x45d9f3b)|1):0;return $x({c:$c,k:$k,s:$s0,t:$t,u:$u||[],q:[],r:0,p:0,st:($vk^$a^$flt)|0,ac:($vk^($a<<5)^0x517cc1b7^$flt)|0,e:[],d:0,v:void 0});};try{if(!$pp&&$rs)$rs[${seedU32}]=$vm;}catch($e){}return $vm;})`;
|
|
@@ -7242,7 +9345,7 @@ function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowK
|
|
|
7242
9345
|
const argA = opMask & 255;
|
|
7243
9346
|
const argB = slotMask & 255;
|
|
7244
9347
|
const argC = vmKey | 0;
|
|
7245
|
-
return `var ${vmHelperName}=(${compactFactory})([${pairs.join(",")}],${argA},${argB},${argC},${seed32}${
|
|
9348
|
+
return `var ${vmHelperName}=(${compactFactory})([${pairs.join(",")}],${argA},${argB},${argC},${seed32}${hasDigest ? `,${expDigest}` : ""});`;
|
|
7246
9349
|
}
|
|
7247
9350
|
function walkWithParent(node, parent, visitor) {
|
|
7248
9351
|
if (!node || typeof node !== "object") return;
|
|
@@ -7479,11 +9582,13 @@ function definitelyTerminates(stmt) {
|
|
|
7479
9582
|
return false;
|
|
7480
9583
|
}
|
|
7481
9584
|
}
|
|
7482
|
-
function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
|
|
9585
|
+
function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654435769) {
|
|
7483
9586
|
const bytecode = [];
|
|
7484
9587
|
const consts = [];
|
|
7485
9588
|
const stateSlots = /* @__PURE__ */ new Set();
|
|
7486
9589
|
const accSlots = /* @__PURE__ */ new Set();
|
|
9590
|
+
const jumpTargets = /* @__PURE__ */ new Map();
|
|
9591
|
+
const jumpOps = /* @__PURE__ */ new Map();
|
|
7487
9592
|
const fnScope = /* @__PURE__ */ new Map();
|
|
7488
9593
|
const scopeStack = [fnScope];
|
|
7489
9594
|
const upvalues = [];
|
|
@@ -7612,17 +9717,24 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
|
|
|
7612
9717
|
}
|
|
7613
9718
|
function emit(op, ...args) {
|
|
7614
9719
|
bytecode.push(opMap[op]);
|
|
7615
|
-
|
|
9720
|
+
if (args.length === 1) {
|
|
9721
|
+
bytecode.push(args[0] + computeHandlerBias(seed, op) & 65535);
|
|
9722
|
+
} else {
|
|
9723
|
+
for (const a of args) bytecode.push(a);
|
|
9724
|
+
}
|
|
7616
9725
|
}
|
|
7617
9726
|
function emitJumpPlaceholder(op) {
|
|
7618
9727
|
const pos = bytecode.length;
|
|
7619
9728
|
emit(op, 0, 0, 0);
|
|
9729
|
+
jumpOps.set(pos, op);
|
|
7620
9730
|
stateSlots.add(pos + 2);
|
|
7621
9731
|
accSlots.add(pos + 3);
|
|
7622
9732
|
return pos;
|
|
7623
9733
|
}
|
|
7624
9734
|
function patchJump(pos, targetPc) {
|
|
7625
|
-
|
|
9735
|
+
const op = jumpOps.get(pos) ?? OP_JMP;
|
|
9736
|
+
jumpTargets.set(pos + 1, targetPc);
|
|
9737
|
+
bytecode[pos + 1] = targetPc + computeHandlerBias(seed, op) & 65535;
|
|
7626
9738
|
}
|
|
7627
9739
|
function compilePatternAssignFromSlot(pattern, sourceSlot) {
|
|
7628
9740
|
if (!pattern) return false;
|
|
@@ -8485,7 +10597,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
|
|
|
8485
10597
|
emit(OP_LDC, addConst(void 0));
|
|
8486
10598
|
emit(OP_RET);
|
|
8487
10599
|
}
|
|
8488
|
-
return { bytecode, consts, localCount, stateSlots, accSlots, upvalues };
|
|
10600
|
+
return { bytecode, consts, localCount, stateSlots, accSlots, jumpTargets, upvalues };
|
|
8489
10601
|
}
|
|
8490
10602
|
function findInjectedVmHelperName(ast) {
|
|
8491
10603
|
if (!ast || !Array.isArray(ast.body)) return null;
|
|
@@ -8742,7 +10854,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8742
10854
|
if (!lowered) {
|
|
8743
10855
|
continue;
|
|
8744
10856
|
}
|
|
8745
|
-
const compiled = compileFunctionToBytecode(lowered.loweredFn, opMap, enclosingBindings);
|
|
10857
|
+
const compiled = compileFunctionToBytecode(lowered.loweredFn, opMap, enclosingBindings, seed);
|
|
8746
10858
|
if (!compiled) {
|
|
8747
10859
|
continue;
|
|
8748
10860
|
}
|
|
@@ -8752,7 +10864,8 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8752
10864
|
fnSalt,
|
|
8753
10865
|
vmKey,
|
|
8754
10866
|
compiled.stateSlots,
|
|
8755
|
-
compiled.accSlots
|
|
10867
|
+
compiled.accSlots,
|
|
10868
|
+
compiled.jumpTargets
|
|
8756
10869
|
);
|
|
8757
10870
|
const constElements = compiled.consts.map((c) => {
|
|
8758
10871
|
if (c === void 0) {
|
|
@@ -8872,7 +10985,8 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8872
10985
|
opMap,
|
|
8873
10986
|
seed,
|
|
8874
10987
|
windowKeySymbol,
|
|
8875
|
-
expectedDelta
|
|
10988
|
+
expectedDelta,
|
|
10989
|
+
extraOpts?.expectedStateHash
|
|
8876
10990
|
);
|
|
8877
10991
|
const parsedHelper = acorn6.parse(interpreterSource, {
|
|
8878
10992
|
ecmaVersion: "latest",
|
|
@@ -9040,7 +11154,7 @@ function isAstAlreadyProtected(ast) {
|
|
|
9040
11154
|
for (const d of stmt.declarations) {
|
|
9041
11155
|
const name = d.id?.type === "Identifier" ? d.id.name : void 0;
|
|
9042
11156
|
if (typeof name === "string") {
|
|
9043
|
-
if (name
|
|
11157
|
+
if (name.startsWith("_uC") || name.startsWith("_uD") || name.startsWith("_uS") || name.startsWith("_uSb") || name.startsWith("_uDec") || name.startsWith("_uAl") || name.startsWith("_uAm") || name.startsWith("_uZt") || name.startsWith("_uVm") || name.startsWith("_wKdf") || name.startsWith("_uP") || name.startsWith("_uCache") || name.startsWith("_uDc") || d.init?.type === "CallExpression" && d.init.callee?.type === "FunctionExpression" && d.init.callee?.id?.name === "f" && d.init.arguments?.[0]?.type === "ArrayExpression" || d.init?.type === "CallExpression" && d.init.callee?.type === "MemberExpression" && d.init.callee.object?.type === "Identifier" && d.init.callee.object.name === "Symbol" && d.init.callee.property?.type === "Identifier" && d.init.callee.property.name === "for" && typeof d.init.arguments?.[0]?.value === "string" && d.init.arguments[0].value.startsWith("__upk_v4_")) {
|
|
9044
11158
|
return true;
|
|
9045
11159
|
}
|
|
9046
11160
|
}
|
|
@@ -9048,7 +11162,7 @@ function isAstAlreadyProtected(ast) {
|
|
|
9048
11162
|
}
|
|
9049
11163
|
if (stmt.type === "FunctionDeclaration" && stmt.id?.type === "Identifier") {
|
|
9050
11164
|
const fnName = stmt.id.name;
|
|
9051
|
-
if (typeof fnName === "string" && (fnName.startsWith("_uD") || fnName.startsWith("_uVm") || fnName.startsWith("_wKdf") || fnName
|
|
11165
|
+
if (typeof fnName === "string" && (fnName.startsWith("_uD") || fnName.startsWith("_uVm") || fnName.startsWith("_wKdf") || fnName === "_hX")) {
|
|
9052
11166
|
return true;
|
|
9053
11167
|
}
|
|
9054
11168
|
}
|
|
@@ -9056,7 +11170,7 @@ function isAstAlreadyProtected(ast) {
|
|
|
9056
11170
|
const callee = stmt.expression.callee;
|
|
9057
11171
|
if (callee?.type === "FunctionExpression") {
|
|
9058
11172
|
const name = callee.id?.name;
|
|
9059
|
-
if (typeof name === "string" &&
|
|
11173
|
+
if (typeof name === "string" && name.startsWith("_u$") || containsUnpeekShieldMarker(callee.body)) {
|
|
9060
11174
|
return true;
|
|
9061
11175
|
}
|
|
9062
11176
|
}
|
|
@@ -9133,7 +11247,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
9133
11247
|
attachMagicComments(boundary.importExpressions, comments);
|
|
9134
11248
|
const effectiveConfig = options.critical ? { ...options.config ?? {}, critical: options.critical } : options.config;
|
|
9135
11249
|
const effectiveProfile = options.profile ?? effectiveConfig?.profile;
|
|
9136
|
-
const
|
|
11250
|
+
const originalSourceMap = internalOptions.originalSourceMap;
|
|
11251
|
+
const hotRes = analyzeAstHotPaths(ast, effectiveConfig, originalSourceMap);
|
|
9137
11252
|
const {
|
|
9138
11253
|
report: hotPathReport,
|
|
9139
11254
|
coldFunctionNodes,
|
|
@@ -9158,20 +11273,27 @@ function transformJavaScript(code, options = {}) {
|
|
|
9158
11273
|
const detectHeadless = internalOptions.detectHeadless ?? effectiveConfig?.shield?.detectHeadless ?? false;
|
|
9159
11274
|
const sym = shieldCoupled ? internalOptions.windowKeySymbol ?? deriveWindowKeySymbol(seed) : void 0;
|
|
9160
11275
|
let shieldDelta = shieldCoupled ? internalOptions.expectedDelta : void 0;
|
|
9161
|
-
|
|
11276
|
+
let expectedStateHash = shieldCoupled ? internalOptions.expectedStateHash : void 0;
|
|
11277
|
+
if (shieldCoupled && (shieldDelta === void 0 || expectedStateHash === void 0)) {
|
|
9162
11278
|
const shieldInfo = generateRuntimeShield({
|
|
9163
11279
|
seed,
|
|
9164
11280
|
windowKeySymbol: sym,
|
|
9165
11281
|
deterrentMode,
|
|
9166
11282
|
detectHeadless
|
|
9167
11283
|
});
|
|
9168
|
-
shieldDelta
|
|
11284
|
+
if (shieldDelta === void 0) {
|
|
11285
|
+
shieldDelta = shieldInfo.expectedDelta ?? 0;
|
|
11286
|
+
}
|
|
11287
|
+
if (expectedStateHash === void 0) {
|
|
11288
|
+
expectedStateHash = shieldInfo.expectedStateHash;
|
|
11289
|
+
}
|
|
9169
11290
|
}
|
|
9170
11291
|
let virtualizedFunctionsCount = 0;
|
|
9171
11292
|
if (isAggressive) {
|
|
9172
|
-
const extraVmOpts = criticalFunctionNodes || effectiveConfig?.critical?.maxFunctionsPerChunk !== void 0 ? {
|
|
11293
|
+
const extraVmOpts = criticalFunctionNodes || effectiveConfig?.critical?.maxFunctionsPerChunk !== void 0 || expectedStateHash !== void 0 ? {
|
|
9173
11294
|
...criticalFunctionNodes ? { criticalFunctionNodes } : {},
|
|
9174
|
-
...effectiveConfig?.critical?.maxFunctionsPerChunk !== void 0 ? { maxFunctionsPerChunk: effectiveConfig.critical.maxFunctionsPerChunk } : {}
|
|
11295
|
+
...effectiveConfig?.critical?.maxFunctionsPerChunk !== void 0 ? { maxFunctionsPerChunk: effectiveConfig.critical.maxFunctionsPerChunk } : {},
|
|
11296
|
+
...expectedStateHash !== void 0 ? { expectedStateHash } : {}
|
|
9175
11297
|
} : void 0;
|
|
9176
11298
|
const vmRes = extraVmOpts ? applyMicroVm(
|
|
9177
11299
|
ast,
|
|
@@ -9192,7 +11314,16 @@ function transformJavaScript(code, options = {}) {
|
|
|
9192
11314
|
virtualizedFunctionsCount = vmRes.virtualizedCount;
|
|
9193
11315
|
}
|
|
9194
11316
|
if (effectiveProfile !== "minimal" && effectiveConfig?.coldFlow !== false) {
|
|
9195
|
-
applyColdFlowGuard(
|
|
11317
|
+
applyColdFlowGuard(
|
|
11318
|
+
ast,
|
|
11319
|
+
coldFunctionNodes,
|
|
11320
|
+
seed,
|
|
11321
|
+
hotExemptNodes,
|
|
11322
|
+
sym,
|
|
11323
|
+
shieldDelta,
|
|
11324
|
+
shieldCoupled,
|
|
11325
|
+
{ enableBitwiseMba: isAggressive || effectiveProfile === "strict" }
|
|
11326
|
+
);
|
|
9196
11327
|
}
|
|
9197
11328
|
const mangledSymbolsCount = applyPolymorphicMangler(
|
|
9198
11329
|
ast,
|
|
@@ -9483,7 +11614,7 @@ async function protectProject(options = {}) {
|
|
|
9483
11614
|
const config = await loadUnpeekConfig(cwd, effectiveConfigInput);
|
|
9484
11615
|
const effectiveProfile = options.profile ?? config.profile ?? "recommended";
|
|
9485
11616
|
const { framework, outDir } = detectTargetFramework(cwd, options.outDir, config);
|
|
9486
|
-
const seed = typeof options.seed === "number" ? options.seed : Math.floor(Math.random() * 2147483647) || 1597463007;
|
|
11617
|
+
const seed = typeof options.seed === "number" && Number.isFinite(options.seed) ? options.seed : typeof config.seed === "number" && Number.isFinite(config.seed) ? config.seed : Math.floor(Math.random() * 2147483647) || 1597463007;
|
|
9487
11618
|
const dryRun = Boolean(options.dryRun);
|
|
9488
11619
|
const keepPrivateMaps = options.keepPrivateMaps ?? config.sourcemaps?.keepPrivate ?? true;
|
|
9489
11620
|
const privateMapsDir = options.privateMapsDir ?? config.sourcemaps?.vaultDir ?? ".unpeek-maps";
|
|
@@ -9561,6 +11692,7 @@ async function protectProject(options = {}) {
|
|
|
9561
11692
|
originalBytes += origBuf.byteLength;
|
|
9562
11693
|
allOrigBufs.push(origBuf);
|
|
9563
11694
|
const relPath = allRelPaths[i];
|
|
11695
|
+
const originalMap = keepPrivateMaps ? readOriginalSourceMapForFile(filePath, relPath, vaultResult.vaultDir, deferVaultWrites) : void 0;
|
|
9564
11696
|
const preExistingHits = countPreExistingEvalCalls(codeToTransform);
|
|
9565
11697
|
const isEntry = isEntryChunk(relPath, i, allRelPaths, manifestEntries, isWorkerTarget);
|
|
9566
11698
|
const shouldInjectShield = injectRuntimeShield && isEntry;
|
|
@@ -9574,14 +11706,16 @@ async function protectProject(options = {}) {
|
|
|
9574
11706
|
shieldCoupled: injectRuntimeShield,
|
|
9575
11707
|
windowKeySymbol: masterSym,
|
|
9576
11708
|
expectedDelta: masterShield?.expectedDelta,
|
|
11709
|
+
expectedStateHash: masterShield?.expectedStateHash,
|
|
11710
|
+
originalSourceMap: originalMap,
|
|
9577
11711
|
deterrentMode,
|
|
9578
11712
|
detectHeadless,
|
|
9579
11713
|
aggressive,
|
|
9580
11714
|
scrubPaths,
|
|
9581
|
-
config
|
|
11715
|
+
config,
|
|
11716
|
+
generateMap: keepPrivateMaps,
|
|
11717
|
+
rootDir: cwd
|
|
9582
11718
|
};
|
|
9583
|
-
transformOptions.generateMap = keepPrivateMaps;
|
|
9584
|
-
transformOptions.rootDir = cwd;
|
|
9585
11719
|
const result = transformJavaScript(codeToTransform, transformOptions);
|
|
9586
11720
|
if (result.skippedReason === "parse-error") {
|
|
9587
11721
|
diagnostics.push({
|
|
@@ -9622,7 +11756,6 @@ async function protectProject(options = {}) {
|
|
|
9622
11756
|
preambleLineOffset = (prefix.match(/\n/g) ?? []).length;
|
|
9623
11757
|
finalCode = `${prefix}${finalCode}`;
|
|
9624
11758
|
}
|
|
9625
|
-
const originalMap = keepPrivateMaps ? readOriginalSourceMapForFile(filePath, relPath, vaultResult.vaultDir, deferVaultWrites) : void 0;
|
|
9626
11759
|
const rawTransformMap = result.sourceMap;
|
|
9627
11760
|
const shiftedTransformMap = rawTransformMap ? shiftSourceMapLines(rawTransformMap, preambleLineOffset) : void 0;
|
|
9628
11761
|
let composedMap;
|
|
@@ -9635,8 +11768,9 @@ async function protectProject(options = {}) {
|
|
|
9635
11768
|
}
|
|
9636
11769
|
const originalMapDebugId = originalMap?.debugId ?? originalMap?.debug_id;
|
|
9637
11770
|
const hadDebugId = Boolean(fileDebugId || originalMapDebugId || result.debugId);
|
|
11771
|
+
const shouldMintDebugId = hadDebugId || keepPrivateMaps && !result.skippedReason && Boolean(composedMap || originalMap);
|
|
9638
11772
|
let mintedDebugId;
|
|
9639
|
-
if (
|
|
11773
|
+
if (shouldMintDebugId) {
|
|
9640
11774
|
const codeWithoutDebugId = stripDebugIdComments(finalCode);
|
|
9641
11775
|
mintedDebugId = computeDeterministicDebugId(
|
|
9642
11776
|
codeWithoutDebugId,
|
|
@@ -9699,8 +11833,9 @@ async function protectProject(options = {}) {
|
|
|
9699
11833
|
`${safeDecodeURIComponent(relPath)}.map`
|
|
9700
11834
|
);
|
|
9701
11835
|
const targetMapPath = fs6.existsSync(vaultedMapPath) ? vaultedMapPath : fs6.existsSync(decodedMapPath) ? decodedMapPath : vaultedMapPath;
|
|
9702
|
-
if (map
|
|
11836
|
+
if (map) {
|
|
9703
11837
|
try {
|
|
11838
|
+
fs6.mkdirSync(path5.dirname(targetMapPath), { recursive: true });
|
|
9704
11839
|
fs6.writeFileSync(targetMapPath, JSON.stringify(map), "utf8");
|
|
9705
11840
|
} catch {
|
|
9706
11841
|
}
|
|
@@ -9777,6 +11912,8 @@ async function protectProject(options = {}) {
|
|
|
9777
11912
|
seed,
|
|
9778
11913
|
tier: resolvedTier,
|
|
9779
11914
|
aggressive,
|
|
11915
|
+
deterrentMode,
|
|
11916
|
+
detectHeadless,
|
|
9780
11917
|
dockerIgnoreMissing: vaultResult.dockerIgnoreMissing,
|
|
9781
11918
|
dryRun,
|
|
9782
11919
|
profile: effectiveProfile,
|
|
@@ -9790,7 +11927,7 @@ async function protectProject(options = {}) {
|
|
|
9790
11927
|
import fs7 from "fs";
|
|
9791
11928
|
import path6 from "path";
|
|
9792
11929
|
import * as acorn8 from "acorn";
|
|
9793
|
-
import { simple as walkSimple2 } from "acorn-walk";
|
|
11930
|
+
import { recursive as walkRecursive, simple as walkSimple2 } from "acorn-walk";
|
|
9794
11931
|
function walkPublicMaps(currentDir, rootOutDir, found) {
|
|
9795
11932
|
if (hasNextServerSegment(currentDir, rootOutDir)) {
|
|
9796
11933
|
return;
|
|
@@ -9866,11 +12003,13 @@ function isHitFromNodeModules(hit, map, allSourcesNodeModules) {
|
|
|
9866
12003
|
}
|
|
9867
12004
|
return allSourcesNodeModules;
|
|
9868
12005
|
}
|
|
9869
|
-
|
|
9870
|
-
|
|
9871
|
-
|
|
12006
|
+
var MAX_PLAINTEXT_SECRET_FINDINGS_PER_FILE = 5;
|
|
12007
|
+
var UNPEEK_VAULT_IDENT_PREFIXES = ["_uP", "_uC", "_uD", "_uS", "_uSb", "_uDec"];
|
|
12008
|
+
var BINARY_DATA_URI_RE2 = /^data:(?:application\/(?:wasm|octet-stream|pdf|zip|gzip|(?:x-)?font-[a-z0-9-]+)|image\/|font\/|audio\/|video\/)/i;
|
|
12009
|
+
var SECRET_LIMIT_REACHED = {};
|
|
12010
|
+
function parseCheckAst(code) {
|
|
9872
12011
|
try {
|
|
9873
|
-
|
|
12012
|
+
return acorn8.parse(code, {
|
|
9874
12013
|
ecmaVersion: "latest",
|
|
9875
12014
|
sourceType: "module",
|
|
9876
12015
|
allowReturnOutsideFunction: true,
|
|
@@ -9878,16 +12017,137 @@ function findEvalOrFunctionCalls(code) {
|
|
|
9878
12017
|
});
|
|
9879
12018
|
} catch {
|
|
9880
12019
|
try {
|
|
9881
|
-
|
|
12020
|
+
return acorn8.parse(code, {
|
|
9882
12021
|
ecmaVersion: "latest",
|
|
9883
12022
|
sourceType: "script",
|
|
9884
12023
|
allowReturnOutsideFunction: true,
|
|
9885
12024
|
locations: true
|
|
9886
12025
|
});
|
|
9887
12026
|
} catch {
|
|
9888
|
-
return
|
|
12027
|
+
return null;
|
|
12028
|
+
}
|
|
12029
|
+
}
|
|
12030
|
+
}
|
|
12031
|
+
function isUnpeekVaultIdentifier(name) {
|
|
12032
|
+
return UNPEEK_VAULT_IDENT_PREFIXES.some((prefix) => name.startsWith(prefix));
|
|
12033
|
+
}
|
|
12034
|
+
function isUnpeekShaderVaultIife(init) {
|
|
12035
|
+
if (!init || init.type !== "CallExpression" || init.callee.type !== "FunctionExpression" || init.callee.id?.name !== "f" || init.callee.params.length !== 1 || init.arguments.length !== 1 || init.arguments[0]?.type !== "ArrayExpression") {
|
|
12036
|
+
return false;
|
|
12037
|
+
}
|
|
12038
|
+
const first = init.callee.body?.body?.[0];
|
|
12039
|
+
return first?.type === "VariableDeclaration" && first.declarations.some(
|
|
12040
|
+
(d) => d.id.type === "Identifier" && d.id.name === "h" && d.init?.type === "Literal" && d.init.value === 2166136261
|
|
12041
|
+
);
|
|
12042
|
+
}
|
|
12043
|
+
function isSkippedBinaryPayload(value) {
|
|
12044
|
+
return value.startsWith("AGFzbQE") || BINARY_DATA_URI_RE2.test(value);
|
|
12045
|
+
}
|
|
12046
|
+
function redactSecretPreview(value) {
|
|
12047
|
+
const singleLine = value.replace(/[\r\n\t]+/g, " ");
|
|
12048
|
+
if (singleLine.length <= 10) {
|
|
12049
|
+
return "[redacted]";
|
|
12050
|
+
}
|
|
12051
|
+
return `${singleLine.slice(0, 4)}...${singleLine.slice(-4)}`;
|
|
12052
|
+
}
|
|
12053
|
+
function findPlaintextSecrets(code, parsedAst) {
|
|
12054
|
+
const ast = parsedAst !== void 0 ? parsedAst : parseCheckAst(code);
|
|
12055
|
+
if (!ast) {
|
|
12056
|
+
return [];
|
|
12057
|
+
}
|
|
12058
|
+
const hits = [];
|
|
12059
|
+
const pushHit = (category, rawValue, node) => {
|
|
12060
|
+
hits.push({
|
|
12061
|
+
category,
|
|
12062
|
+
preview: redactSecretPreview(rawValue),
|
|
12063
|
+
line: node.loc ? node.loc.start.line : 1
|
|
12064
|
+
});
|
|
12065
|
+
if (hits.length >= MAX_PLAINTEXT_SECRET_FINDINGS_PER_FILE) {
|
|
12066
|
+
throw SECRET_LIMIT_REACHED;
|
|
12067
|
+
}
|
|
12068
|
+
};
|
|
12069
|
+
const inspectString = (value, node) => {
|
|
12070
|
+
if (!value || isSkippedBinaryPayload(value)) return;
|
|
12071
|
+
const match = classifyPlaintextSecret(value);
|
|
12072
|
+
if (match) {
|
|
12073
|
+
pushHit(match.category, value, node);
|
|
12074
|
+
}
|
|
12075
|
+
};
|
|
12076
|
+
try {
|
|
12077
|
+
walkRecursive(ast, void 0, {
|
|
12078
|
+
VariableDeclarator(node, state, c) {
|
|
12079
|
+
if (node.id.type === "Identifier" && isUnpeekVaultIdentifier(node.id.name) || isUnpeekShaderVaultIife(node.init)) {
|
|
12080
|
+
return;
|
|
12081
|
+
}
|
|
12082
|
+
c(node.id, state);
|
|
12083
|
+
if (node.init) {
|
|
12084
|
+
c(node.init, state);
|
|
12085
|
+
}
|
|
12086
|
+
},
|
|
12087
|
+
FunctionDeclaration(node, state, c) {
|
|
12088
|
+
if (node.id && isUnpeekVaultIdentifier(node.id.name)) {
|
|
12089
|
+
return;
|
|
12090
|
+
}
|
|
12091
|
+
for (const param of node.params) {
|
|
12092
|
+
c(param, state);
|
|
12093
|
+
}
|
|
12094
|
+
c(node.body, state);
|
|
12095
|
+
},
|
|
12096
|
+
ExpressionStatement(node, state, c) {
|
|
12097
|
+
if (node.directive) {
|
|
12098
|
+
return;
|
|
12099
|
+
}
|
|
12100
|
+
c(node.expression, state);
|
|
12101
|
+
},
|
|
12102
|
+
ImportDeclaration() {
|
|
12103
|
+
},
|
|
12104
|
+
ExportNamedDeclaration(node, state, c) {
|
|
12105
|
+
if (node.declaration) {
|
|
12106
|
+
c(node.declaration, state);
|
|
12107
|
+
}
|
|
12108
|
+
},
|
|
12109
|
+
ExportAllDeclaration() {
|
|
12110
|
+
},
|
|
12111
|
+
ImportExpression(node, state, c) {
|
|
12112
|
+
if (node.options) {
|
|
12113
|
+
c(node.options, state);
|
|
12114
|
+
}
|
|
12115
|
+
},
|
|
12116
|
+
ImportSpecifier() {
|
|
12117
|
+
},
|
|
12118
|
+
ExportSpecifier() {
|
|
12119
|
+
},
|
|
12120
|
+
ImportAttribute() {
|
|
12121
|
+
},
|
|
12122
|
+
Literal(node) {
|
|
12123
|
+
if (typeof node.value === "string") {
|
|
12124
|
+
inspectString(node.value, node);
|
|
12125
|
+
} else if (node.regex && typeof node.regex.pattern === "string") {
|
|
12126
|
+
if (hasRegexSecretRun(node.regex.pattern)) {
|
|
12127
|
+
pushHit("regex-secret", node.regex.pattern, node);
|
|
12128
|
+
}
|
|
12129
|
+
}
|
|
12130
|
+
},
|
|
12131
|
+
TemplateElement(node) {
|
|
12132
|
+
const val = node.value.cooked ?? node.value.raw;
|
|
12133
|
+
if (typeof val === "string") {
|
|
12134
|
+
inspectString(val, node);
|
|
12135
|
+
}
|
|
12136
|
+
}
|
|
12137
|
+
});
|
|
12138
|
+
} catch (err) {
|
|
12139
|
+
if (err !== SECRET_LIMIT_REACHED) {
|
|
12140
|
+
throw err;
|
|
9889
12141
|
}
|
|
9890
12142
|
}
|
|
12143
|
+
return hits;
|
|
12144
|
+
}
|
|
12145
|
+
function findEvalOrFunctionCalls(code, parsedAst) {
|
|
12146
|
+
const hits = [];
|
|
12147
|
+
const ast = parsedAst !== void 0 ? parsedAst : parseCheckAst(code);
|
|
12148
|
+
if (!ast) {
|
|
12149
|
+
return hits;
|
|
12150
|
+
}
|
|
9891
12151
|
walkSimple2(ast, {
|
|
9892
12152
|
CallExpression(node) {
|
|
9893
12153
|
if (node.callee.type === "Identifier") {
|
|
@@ -10037,7 +12297,8 @@ async function checkProject(options = {}) {
|
|
|
10037
12297
|
file: rel
|
|
10038
12298
|
});
|
|
10039
12299
|
}
|
|
10040
|
-
const
|
|
12300
|
+
const ast = parseCheckAst(content);
|
|
12301
|
+
const evalHits = findEvalOrFunctionCalls(content, ast);
|
|
10041
12302
|
if (evalHits.length > 0) {
|
|
10042
12303
|
if (!requireZeroEval) {
|
|
10043
12304
|
const kinds = Array.from(new Set(evalHits.map((h) => h.kind)));
|
|
@@ -10099,6 +12360,20 @@ async function checkProject(options = {}) {
|
|
|
10099
12360
|
}
|
|
10100
12361
|
}
|
|
10101
12362
|
}
|
|
12363
|
+
const secretHits = findPlaintextSecrets(content, ast);
|
|
12364
|
+
if (secretHits.length > 0) {
|
|
12365
|
+
const failOnSecrets = options.failOnPlaintextSecrets === true;
|
|
12366
|
+
const targetBucket = failOnSecrets ? violations : warnings;
|
|
12367
|
+
const severity = failOnSecrets ? "error" : "warning";
|
|
12368
|
+
for (const hit of secretHits) {
|
|
12369
|
+
targetBucket.push({
|
|
12370
|
+
rule: "plaintext-secret",
|
|
12371
|
+
severity,
|
|
12372
|
+
message: `Plaintext secret (${hit.category}) "${hit.preview}" detected in "${rel}" at line ${hit.line}.`,
|
|
12373
|
+
file: rel
|
|
12374
|
+
});
|
|
12375
|
+
}
|
|
12376
|
+
}
|
|
10102
12377
|
}
|
|
10103
12378
|
const relVault = path6.relative(cwd, vaultDir).replace(/\\/g, "/");
|
|
10104
12379
|
const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
|
|
@@ -10169,7 +12444,7 @@ async function checkProject(options = {}) {
|
|
|
10169
12444
|
}
|
|
10170
12445
|
|
|
10171
12446
|
// src/cli/index.ts
|
|
10172
|
-
var VERSION = "4.0
|
|
12447
|
+
var VERSION = "4.2.0";
|
|
10173
12448
|
var cachedPackageVersion;
|
|
10174
12449
|
function getPackageVersion() {
|
|
10175
12450
|
if (cachedPackageVersion !== void 0) {
|
|
@@ -10218,7 +12493,7 @@ function printHelp() {
|
|
|
10218
12493
|
"",
|
|
10219
12494
|
" Usage:",
|
|
10220
12495
|
" unpeek init [--dry-run] [--profile <name>] wire postbuild and the .unpeek-maps/ vault",
|
|
10221
|
-
" unpeek protect [options] protect client bundles in place (Tier
|
|
12496
|
+
" unpeek protect [options] protect client bundles in place (Tier 2 default: <2% CPU, <15% Gzip)",
|
|
10222
12497
|
" unpeek check [options] read-only CI gate for leaks, ignores, budget, and CSP",
|
|
10223
12498
|
" unpeek symbolicate [options] resolve stack traces locally using .unpeek-maps/",
|
|
10224
12499
|
"",
|
|
@@ -10235,7 +12510,7 @@ function printHelp() {
|
|
|
10235
12510
|
" --min-string-length <num> minimum string length for the vault (default: 4)",
|
|
10236
12511
|
" --private-maps-dir <dir> vault directory (default: .unpeek-maps)",
|
|
10237
12512
|
" --no-shield skip the runtime anti-tamper shield",
|
|
10238
|
-
" --aggressive enable Tier
|
|
12513
|
+
" --aggressive enable Tier 3 strict protection (Micro-VM & WASM KDF)",
|
|
10239
12514
|
"",
|
|
10240
12515
|
" Options (check):",
|
|
10241
12516
|
" --out-dir <dir> explicit client output directory",
|
|
@@ -10254,8 +12529,9 @@ function printHelp() {
|
|
|
10254
12529
|
" -v, --version show version",
|
|
10255
12530
|
"",
|
|
10256
12531
|
" Tiers:",
|
|
10257
|
-
" Tier 1 (
|
|
10258
|
-
" Tier 2 (
|
|
12532
|
+
" Tier 1 (minimal) call-graph hot-path exemption (<2% CPU, <15% Gzip)",
|
|
12533
|
+
" Tier 2 (recommended, default) string vault & cold-flow protection (<2% CPU, <15% Gzip)",
|
|
12534
|
+
" Tier 3 (strict / --aggressive) zero plaintext exposure via Micro-VM & WASM KDF"
|
|
10259
12535
|
].join("\n");
|
|
10260
12536
|
console.log(helpText);
|
|
10261
12537
|
}
|
|
@@ -10266,7 +12542,10 @@ function formatBytes(bytes) {
|
|
|
10266
12542
|
function printSummaryTable(summary) {
|
|
10267
12543
|
const sign = summary.gzipDeltaPercent > 0 ? "+" : "";
|
|
10268
12544
|
const gzip = `${formatBytes(summary.originalGzipBytes)} -> ${formatBytes(summary.protectedGzipBytes)} ${sign}${summary.gzipDeltaPercent}%`;
|
|
10269
|
-
const
|
|
12545
|
+
const effectiveTier = summary.tier ?? (summary.aggressive || summary.profile === "strict" ? "Tier 3" : summary.profile === "minimal" ? "Tier 1" : "Tier 2");
|
|
12546
|
+
const tierLabel = effectiveTier === "Tier 1" ? "Tier 1 (minimal: <2% CPU, <15% Gzip)" : effectiveTier === "Tier 3" ? "Tier 3 (strict / --aggressive: Micro-VM & WASM KDF)" : "Tier 2 (recommended: string vault & cold-flow)";
|
|
12547
|
+
const effectiveDeterrent = summary.deterrentMode ?? "passive";
|
|
12548
|
+
const effectiveHeadless = summary.detectHeadless ? "on" : "off";
|
|
10270
12549
|
console.log("");
|
|
10271
12550
|
console.log(brandBlock());
|
|
10272
12551
|
if (summary.dryRun) {
|
|
@@ -10276,7 +12555,8 @@ function printSummaryTable(summary) {
|
|
|
10276
12555
|
console.log("");
|
|
10277
12556
|
const projectRows = [
|
|
10278
12557
|
["framework", summary.framework],
|
|
10279
|
-
["tier", tierLabel]
|
|
12558
|
+
["tier", tierLabel],
|
|
12559
|
+
["shield", `${effectiveDeterrent} (detectHeadless: ${effectiveHeadless})`]
|
|
10280
12560
|
];
|
|
10281
12561
|
if (summary.profile) {
|
|
10282
12562
|
projectRows.push(["profile", summary.profile]);
|