unpeek 4.1.0 → 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 +7 -7
- package/README.tr.md +7 -7
- package/dist/adapters/esbuild.cjs +4 -4
- package/dist/adapters/esbuild.js +2 -2
- package/dist/adapters/next/adapter.cjs +4 -4
- package/dist/adapters/next/adapter.js +3 -3
- package/dist/adapters/next/index.cjs +4 -4
- package/dist/adapters/next/index.js +3 -3
- package/dist/adapters/rollup.cjs +4 -4
- package/dist/adapters/rollup.js +2 -2
- package/dist/adapters/rspack.cjs +4 -4
- package/dist/adapters/rspack.js +2 -2
- package/dist/adapters/vite.cjs +4 -4
- package/dist/adapters/vite.js +2 -2
- package/dist/adapters/webpack.cjs +4 -4
- package/dist/adapters/webpack.js +2 -2
- package/dist/browser.cjs +2 -2
- package/dist/browser.d.cts +3 -2
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-STTUFUDC.js → chunk-APQOBFRO.js} +1 -1
- package/dist/{chunk-6KLUNEKE.js → chunk-BL2UXZGD.js} +1187 -162
- package/dist/{chunk-TOUYQ4N5.js → chunk-GCWXTWTN.js} +1 -1
- package/dist/{chunk-HV47WJIR.js → chunk-K77WRITN.js} +2 -2
- package/dist/{chunk-WYW5UOBE.cjs → chunk-KIAYVIC5.cjs} +11 -11
- package/dist/{chunk-VLL4THTG.cjs → chunk-MSECP2P4.cjs} +1326 -301
- package/dist/{chunk-FLZ4FSP5.cjs → chunk-SJK45WAU.cjs} +6 -6
- package/dist/{chunk-Q4DFRMAV.cjs → chunk-UUJLTW7O.cjs} +9 -9
- package/dist/cli/index.js +1332 -171
- package/dist/index.cjs +159 -19
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +150 -10
- package/dist/plugins/unplugin.cjs +3 -3
- package/dist/plugins/unplugin.js +2 -2
- package/dist/{types-BZqvBhBI.d.ts → types-BDpFfokR.d.ts} +2 -1
- package/dist/{types-E4ugA4Oz.d.cts → types-WIoud53X.d.cts} +2 -1
- package/package.json +1 -1
|
@@ -2956,7 +2956,7 @@ function createDeterrentSnippet(config) {
|
|
|
2956
2956
|
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=()=>0;" : "";
|
|
2957
2957
|
const symLit = JSON.stringify(sym);
|
|
2958
2958
|
const headlessDecl = detectHeadless ? ",n=w.navigator||0" : "";
|
|
2959
|
-
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)" : "";
|
|
2959
|
+
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)||['__playwright','__puppeteer_evaluation_script__','__nightmare','frida','_frida_'].some(k=>w[k]||G[k])" : "";
|
|
2960
2960
|
const k1Mul = (seed | 1) >>> 0;
|
|
2961
2961
|
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);`;
|
|
2962
2962
|
}
|
|
@@ -3061,7 +3061,88 @@ function deriveWasmHostParams(seed) {
|
|
|
3061
3061
|
const pcMask = computeFnv1aHash("wasm-pcmask", seed) | 1 | 0;
|
|
3062
3062
|
return { gArr, sOff, rA0, rA1, rA2, rA3, gMask, pcMask };
|
|
3063
3063
|
}
|
|
3064
|
-
|
|
3064
|
+
var ABI_START_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
|
3065
|
+
var ABI_CONT_CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
|
3066
|
+
var FORBIDDEN_ABI_NAMES = /* @__PURE__ */ new Set([
|
|
3067
|
+
"env",
|
|
3068
|
+
"g",
|
|
3069
|
+
"m",
|
|
3070
|
+
"kdf",
|
|
3071
|
+
"bulkmix",
|
|
3072
|
+
"mem",
|
|
3073
|
+
"as",
|
|
3074
|
+
"do",
|
|
3075
|
+
"if",
|
|
3076
|
+
"in",
|
|
3077
|
+
"of",
|
|
3078
|
+
"for",
|
|
3079
|
+
"int",
|
|
3080
|
+
"let",
|
|
3081
|
+
"new",
|
|
3082
|
+
"try",
|
|
3083
|
+
"var",
|
|
3084
|
+
"nan",
|
|
3085
|
+
"map",
|
|
3086
|
+
"set",
|
|
3087
|
+
"url",
|
|
3088
|
+
"top",
|
|
3089
|
+
"get",
|
|
3090
|
+
"set"
|
|
3091
|
+
]);
|
|
3092
|
+
function avalancheMix32(h) {
|
|
3093
|
+
let x = h >>> 0;
|
|
3094
|
+
x = Math.imul(x ^ x >>> 16, 2246822507) >>> 0;
|
|
3095
|
+
x = Math.imul(x ^ x >>> 13, 3266489909) >>> 0;
|
|
3096
|
+
return (x ^ x >>> 16) >>> 0;
|
|
3097
|
+
}
|
|
3098
|
+
function encodeWasmName(name) {
|
|
3099
|
+
const utf8 = new TextEncoder().encode(name);
|
|
3100
|
+
return [...encodeUnsignedLeb128(utf8.length), ...utf8];
|
|
3101
|
+
}
|
|
3102
|
+
function deriveWasmAbiNames(seed) {
|
|
3103
|
+
const s = seed >>> 0;
|
|
3104
|
+
const used = new Set(FORBIDDEN_ABI_NAMES);
|
|
3105
|
+
const pickName = (role) => {
|
|
3106
|
+
for (let attempt = 0; attempt < 64; attempt++) {
|
|
3107
|
+
const h = avalancheMix32(computeFnv1aHash(`wasm-abi:${role}:${attempt}`, s));
|
|
3108
|
+
const len = h >>> 18 & 1 ? 3 : 2;
|
|
3109
|
+
const c0 = ABI_START_CHARS[h % ABI_START_CHARS.length];
|
|
3110
|
+
const c1 = ABI_CONT_CHARS[(h >>> 6) % ABI_CONT_CHARS.length];
|
|
3111
|
+
const c2 = len === 3 ? ABI_CONT_CHARS[(h >>> 12) % ABI_CONT_CHARS.length] : "";
|
|
3112
|
+
const candidate = `${c0}${c1}${c2}`;
|
|
3113
|
+
const lower = candidate.toLowerCase();
|
|
3114
|
+
if (!candidate.startsWith("__") && !used.has(lower)) {
|
|
3115
|
+
used.add(lower);
|
|
3116
|
+
return candidate;
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
const fallback = `w${s.toString(36).slice(0, 2).padStart(2, "0")}`;
|
|
3120
|
+
used.add(fallback.toLowerCase());
|
|
3121
|
+
return fallback;
|
|
3122
|
+
};
|
|
3123
|
+
const envMod = pickName("envMod");
|
|
3124
|
+
const gImport = pickName("gImport");
|
|
3125
|
+
const mImport = pickName("mImport");
|
|
3126
|
+
const kdfExport = pickName("kdfExport");
|
|
3127
|
+
const bulkMixExport = pickName("bulkMixExport");
|
|
3128
|
+
const memExport = pickName("memExport");
|
|
3129
|
+
const exportOrder = [0, 1, 2];
|
|
3130
|
+
const orderHash = avalancheMix32(computeFnv1aHash("wasm-abi:order", s));
|
|
3131
|
+
const j2 = orderHash % 3;
|
|
3132
|
+
[exportOrder[2], exportOrder[j2]] = [exportOrder[j2], exportOrder[2]];
|
|
3133
|
+
const j1 = (orderHash >>> 8) % 2;
|
|
3134
|
+
[exportOrder[1], exportOrder[j1]] = [exportOrder[j1], exportOrder[1]];
|
|
3135
|
+
return {
|
|
3136
|
+
envMod,
|
|
3137
|
+
gImport,
|
|
3138
|
+
mImport,
|
|
3139
|
+
kdfExport,
|
|
3140
|
+
bulkMixExport,
|
|
3141
|
+
memExport,
|
|
3142
|
+
exportOrder
|
|
3143
|
+
};
|
|
3144
|
+
}
|
|
3145
|
+
function generateWasmKdfBinary(seed, options) {
|
|
3065
3146
|
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
3066
3147
|
const { gMask, pcMask } = deriveWasmHostParams(seed);
|
|
3067
3148
|
const memBase = (seed >>> 0 & 127) * 4;
|
|
@@ -3587,27 +3668,23 @@ function generateWasmKdfBinary(seed) {
|
|
|
3587
3668
|
...encodeUnsignedLeb128(typePayload.length),
|
|
3588
3669
|
...typePayload
|
|
3589
3670
|
];
|
|
3671
|
+
const abi = options?.polymorphicAbi ? deriveWasmAbiNames(seed) : null;
|
|
3672
|
+
const envModName = abi ? abi.envMod : "env";
|
|
3673
|
+
const gImportName = abi ? abi.gImport : "g";
|
|
3674
|
+
const mImportName = abi ? abi.mImport : "m";
|
|
3590
3675
|
const importPayload = [
|
|
3591
3676
|
2,
|
|
3592
3677
|
// 2 imports
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
110,
|
|
3596
|
-
118,
|
|
3597
|
-
1,
|
|
3598
|
-
103,
|
|
3678
|
+
...encodeWasmName(envModName),
|
|
3679
|
+
...encodeWasmName(gImportName),
|
|
3599
3680
|
0,
|
|
3600
3681
|
0,
|
|
3601
|
-
//
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
110,
|
|
3605
|
-
118,
|
|
3606
|
-
1,
|
|
3607
|
-
109,
|
|
3682
|
+
// g: func type 0
|
|
3683
|
+
...encodeWasmName(envModName),
|
|
3684
|
+
...encodeWasmName(mImportName),
|
|
3608
3685
|
0,
|
|
3609
3686
|
1
|
|
3610
|
-
//
|
|
3687
|
+
// m: func type 1
|
|
3611
3688
|
];
|
|
3612
3689
|
const importSection = [
|
|
3613
3690
|
2,
|
|
@@ -3621,35 +3698,21 @@ function generateWasmKdfBinary(seed) {
|
|
|
3621
3698
|
...funcPayload
|
|
3622
3699
|
];
|
|
3623
3700
|
const memSection = [5, 3, 1, 0, 1];
|
|
3624
|
-
const
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
0
|
|
3632
|
-
2,
|
|
3633
|
-
// "kdf" -> func 2
|
|
3634
|
-
7,
|
|
3635
|
-
98,
|
|
3636
|
-
117,
|
|
3637
|
-
108,
|
|
3638
|
-
107,
|
|
3639
|
-
77,
|
|
3640
|
-
105,
|
|
3641
|
-
120,
|
|
3642
|
-
0,
|
|
3643
|
-
3,
|
|
3644
|
-
// "bulkMix" -> func 3
|
|
3645
|
-
3,
|
|
3646
|
-
109,
|
|
3647
|
-
101,
|
|
3648
|
-
109,
|
|
3649
|
-
2,
|
|
3650
|
-
0
|
|
3651
|
-
// "mem" -> memory 0
|
|
3701
|
+
const exportSpecs = abi ? [
|
|
3702
|
+
[abi.kdfExport, 0, 2],
|
|
3703
|
+
[abi.bulkMixExport, 0, 3],
|
|
3704
|
+
[abi.memExport, 2, 0]
|
|
3705
|
+
] : [
|
|
3706
|
+
["kdf", 0, 2],
|
|
3707
|
+
["bulkMix", 0, 3],
|
|
3708
|
+
["mem", 2, 0]
|
|
3652
3709
|
];
|
|
3710
|
+
const exportOrder = abi ? abi.exportOrder : [0, 1, 2];
|
|
3711
|
+
const exportPayload = [3];
|
|
3712
|
+
for (const idx of exportOrder) {
|
|
3713
|
+
const [name, kind, targetIdx] = exportSpecs[idx];
|
|
3714
|
+
exportPayload.push(...encodeWasmName(name), kind, targetIdx);
|
|
3715
|
+
}
|
|
3653
3716
|
const exportSection = [
|
|
3654
3717
|
7,
|
|
3655
3718
|
...encodeUnsignedLeb128(exportPayload.length),
|
|
@@ -3747,12 +3810,13 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
3747
3810
|
const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
|
|
3748
3811
|
return {
|
|
3749
3812
|
kdfFnName: id,
|
|
3750
|
-
wasmBytes: generateWasmKdfBinary(seed),
|
|
3813
|
+
wasmBytes: generateWasmKdfBinary(seed, { polymorphicAbi: true }),
|
|
3751
3814
|
wasmVarName,
|
|
3752
3815
|
kdfParityVerified: true
|
|
3753
3816
|
};
|
|
3754
3817
|
}
|
|
3755
|
-
const
|
|
3818
|
+
const abi = deriveWasmAbiNames(seed);
|
|
3819
|
+
const wasmBytes = generateWasmKdfBinary(seed, { polymorphicAbi: true });
|
|
3756
3820
|
const byteArrayLiteral = Array.from(wasmBytes).join(",");
|
|
3757
3821
|
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
3758
3822
|
const { gArr, sOff, rA0, rA1, rA2, rA3, gMask, pcMask } = deriveWasmHostParams(seed);
|
|
@@ -3789,8 +3853,8 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
3789
3853
|
try {
|
|
3790
3854
|
var ${wasmVarName} = new Uint8Array([${byteArrayLiteral}]);
|
|
3791
3855
|
var _wm${suffix} = new WebAssembly.Module(${wasmVarName});
|
|
3792
|
-
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix}, {
|
|
3793
|
-
${kdfFnName} = _wi${suffix}.exports.
|
|
3856
|
+
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix}, { ${abi.envMod}: { ${abi.gImport}: _eG, ${abi.mImport}: _eM } });
|
|
3857
|
+
${kdfFnName} = _wi${suffix}.exports[${JSON.stringify(abi.kdfExport)}];
|
|
3794
3858
|
} catch (e) {
|
|
3795
3859
|
var _kx = [${rivEncodedTargets.join(",")}];
|
|
3796
3860
|
var _k = [];
|
|
@@ -4202,16 +4266,39 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4202
4266
|
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
4203
4267
|
const shaderPayloads = [];
|
|
4204
4268
|
const shaderTargets = [];
|
|
4205
|
-
|
|
4269
|
+
const interpolatedTemplates = [];
|
|
4270
|
+
let regExpShadowedScopes;
|
|
4271
|
+
const getRegExpShadowedScopes = () => {
|
|
4272
|
+
regExpShadowedScopes ??= collectIdentifierShadowedScopes(ast, "RegExp");
|
|
4273
|
+
return regExpShadowedScopes;
|
|
4274
|
+
};
|
|
4275
|
+
function pushSaltedTarget(rawString, node, parent, extra) {
|
|
4276
|
+
const callSiteIdx = targetsToReplace.length;
|
|
4277
|
+
const [saltLo, saltHi] = computeCallSiteSalt64(
|
|
4278
|
+
seed >>> 0,
|
|
4279
|
+
callSiteIdx >>> 0,
|
|
4280
|
+
seed >>> 0
|
|
4281
|
+
);
|
|
4282
|
+
const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
|
|
4283
|
+
targetsToReplace.push({
|
|
4284
|
+
node,
|
|
4285
|
+
parent,
|
|
4286
|
+
callSiteIdx,
|
|
4287
|
+
localSalt,
|
|
4288
|
+
rawString,
|
|
4289
|
+
...extra
|
|
4290
|
+
});
|
|
4291
|
+
}
|
|
4292
|
+
function processSaltedCandidate(val, node, parent, ancestors, onReplace) {
|
|
4206
4293
|
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
4207
|
-
return;
|
|
4294
|
+
return false;
|
|
4208
4295
|
}
|
|
4209
4296
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
4210
|
-
return;
|
|
4297
|
+
return false;
|
|
4211
4298
|
}
|
|
4212
4299
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
4213
4300
|
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
4214
|
-
return;
|
|
4301
|
+
return false;
|
|
4215
4302
|
}
|
|
4216
4303
|
}
|
|
4217
4304
|
let isHotExempt = false;
|
|
@@ -4238,11 +4325,11 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4238
4325
|
shaderToIndex.set(val, idx);
|
|
4239
4326
|
shaderPayloads.push(val);
|
|
4240
4327
|
}
|
|
4241
|
-
shaderTargets.push({ node, parent, idx });
|
|
4242
|
-
return;
|
|
4328
|
+
shaderTargets.push({ node, parent, idx, ...onReplace ? { onReplace } : {} });
|
|
4329
|
+
return true;
|
|
4243
4330
|
}
|
|
4244
4331
|
if (isHotExempt) {
|
|
4245
|
-
return;
|
|
4332
|
+
return false;
|
|
4246
4333
|
}
|
|
4247
4334
|
if (!shouldEncryptString(
|
|
4248
4335
|
val,
|
|
@@ -4251,25 +4338,33 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4251
4338
|
activeDirectives,
|
|
4252
4339
|
customReserved
|
|
4253
4340
|
)) {
|
|
4254
|
-
return;
|
|
4341
|
+
return false;
|
|
4255
4342
|
}
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
seed >>> 0,
|
|
4259
|
-
callSiteIdx >>> 0,
|
|
4260
|
-
seed >>> 0
|
|
4261
|
-
);
|
|
4262
|
-
const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
|
|
4263
|
-
targetsToReplace.push({
|
|
4264
|
-
node,
|
|
4265
|
-
parent,
|
|
4266
|
-
callSiteIdx,
|
|
4267
|
-
localSalt,
|
|
4268
|
-
rawString: val
|
|
4269
|
-
});
|
|
4343
|
+
pushSaltedTarget(val, node, parent, onReplace ? { onReplace } : void 0);
|
|
4344
|
+
return true;
|
|
4270
4345
|
}
|
|
4271
4346
|
walk3.ancestor(ast, {
|
|
4272
4347
|
Literal(node, ancestors) {
|
|
4348
|
+
if (node.regex) {
|
|
4349
|
+
if (isEligibleSecretRegExp(
|
|
4350
|
+
node,
|
|
4351
|
+
ancestors,
|
|
4352
|
+
hotExemptNodes,
|
|
4353
|
+
exemptSubtreeRoots,
|
|
4354
|
+
getRegExpShadowedScopes
|
|
4355
|
+
)) {
|
|
4356
|
+
pushSaltedTarget(
|
|
4357
|
+
node.regex.pattern,
|
|
4358
|
+
node,
|
|
4359
|
+
ancestors[ancestors.length - 2],
|
|
4360
|
+
{
|
|
4361
|
+
replaceMode: "regexp",
|
|
4362
|
+
flags: node.regex.flags ?? ""
|
|
4363
|
+
}
|
|
4364
|
+
);
|
|
4365
|
+
}
|
|
4366
|
+
return;
|
|
4367
|
+
}
|
|
4273
4368
|
if (typeof node.value !== "string") return;
|
|
4274
4369
|
const val = node.value;
|
|
4275
4370
|
if (activeDirectives.has(val)) return;
|
|
@@ -4290,19 +4385,42 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4290
4385
|
processSaltedCandidate(val, node, parent, ancestors);
|
|
4291
4386
|
},
|
|
4292
4387
|
TemplateLiteral(node, ancestors) {
|
|
4293
|
-
if (!node.quasis || node.quasis.length
|
|
4294
|
-
if (node.expressions && node.expressions.length !== 0) return;
|
|
4295
|
-
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
4296
|
-
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
4388
|
+
if (!Array.isArray(node.quasis) || node.quasis.length === 0) return;
|
|
4297
4389
|
const parent = ancestors[ancestors.length - 2];
|
|
4298
|
-
if (
|
|
4299
|
-
|
|
4390
|
+
if (isExemptTemplateLiteral(node, parent)) return;
|
|
4391
|
+
const exprCount = Array.isArray(node.expressions) ? node.expressions.length : 0;
|
|
4392
|
+
if (exprCount === 0) {
|
|
4393
|
+
if (node.quasis.length !== 1) return;
|
|
4394
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
4395
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
4396
|
+
processSaltedCandidate(val, node, parent, ancestors);
|
|
4300
4397
|
return;
|
|
4301
4398
|
}
|
|
4302
|
-
if (
|
|
4399
|
+
if (node.quasis.length !== exprCount + 1) return;
|
|
4400
|
+
if (node.quasis.some((q) => typeof q?.value?.cooked !== "string")) {
|
|
4303
4401
|
return;
|
|
4304
4402
|
}
|
|
4305
|
-
|
|
4403
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
4404
|
+
let queuedCount = 0;
|
|
4405
|
+
for (let qIdx = 0; qIdx < node.quasis.length; qIdx++) {
|
|
4406
|
+
const val = node.quasis[qIdx].value.cooked;
|
|
4407
|
+
if (activeDirectives.has(val)) continue;
|
|
4408
|
+
const queued = processSaltedCandidate(
|
|
4409
|
+
val,
|
|
4410
|
+
node,
|
|
4411
|
+
parent,
|
|
4412
|
+
ancestors,
|
|
4413
|
+
(exprAst) => {
|
|
4414
|
+
replacements.set(qIdx, exprAst);
|
|
4415
|
+
}
|
|
4416
|
+
);
|
|
4417
|
+
if (queued) {
|
|
4418
|
+
queuedCount++;
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
if (queuedCount > 0) {
|
|
4422
|
+
interpolatedTemplates.push({ node, replacements });
|
|
4423
|
+
}
|
|
4306
4424
|
}
|
|
4307
4425
|
});
|
|
4308
4426
|
if (targetsToReplace.length === 0 && shaderTargets.length === 0) {
|
|
@@ -4383,7 +4501,17 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4383
4501
|
],
|
|
4384
4502
|
optional: false
|
|
4385
4503
|
};
|
|
4386
|
-
|
|
4504
|
+
if (target.onReplace) {
|
|
4505
|
+
target.onReplace(callExpr);
|
|
4506
|
+
} else if (target.replaceMode === "regexp") {
|
|
4507
|
+
replaceNodeInParent(
|
|
4508
|
+
target.parent,
|
|
4509
|
+
target.node,
|
|
4510
|
+
createNewRegExpAst(callExpr, target.flags ?? "")
|
|
4511
|
+
);
|
|
4512
|
+
} else {
|
|
4513
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
4514
|
+
}
|
|
4387
4515
|
}
|
|
4388
4516
|
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
4389
4517
|
integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
@@ -4413,7 +4541,11 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4413
4541
|
],
|
|
4414
4542
|
optional: false
|
|
4415
4543
|
};
|
|
4416
|
-
|
|
4544
|
+
if (target.onReplace) {
|
|
4545
|
+
target.onReplace(callExpr);
|
|
4546
|
+
} else {
|
|
4547
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
4548
|
+
}
|
|
4417
4549
|
}
|
|
4418
4550
|
const shaderHelperStmt = createShaderVaultAst(
|
|
4419
4551
|
shaderVarName,
|
|
@@ -4429,6 +4561,7 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4429
4561
|
integrityToken = computeFnv1aHash(JSON.stringify(shaderPayloads), seed);
|
|
4430
4562
|
}
|
|
4431
4563
|
}
|
|
4564
|
+
rebuildInterpolatedTemplates(interpolatedTemplates);
|
|
4432
4565
|
return {
|
|
4433
4566
|
encryptedStringsCount: targetsToReplace.length,
|
|
4434
4567
|
integrityToken,
|
|
@@ -4438,6 +4571,133 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4438
4571
|
};
|
|
4439
4572
|
}
|
|
4440
4573
|
|
|
4574
|
+
// src/ast/secret-patterns.ts
|
|
4575
|
+
var PEM_HEADER_RE = /-----BEGIN\s+[A-Z0-9 ]+-----/;
|
|
4576
|
+
var PEM_REGEX_HEADER_RE = /-----BEGIN(?:\s|\\s[+*?]?)+(?:[A-Z0-9 ]|\\s[+*?]?)+-----/;
|
|
4577
|
+
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,})/;
|
|
4578
|
+
var ESCAPED_FLAG_REGEX_RE = /\bFLAG\\\{[^}]{4,}\\\}/;
|
|
4579
|
+
var HEX_RE = /^[0-9a-fA-F]+$/;
|
|
4580
|
+
var BASE64_RE = /^[A-Za-z0-9+/]+=*$/;
|
|
4581
|
+
var TOKEN_CHARSET_RE = /^[A-Za-z0-9_\-+/=.~:@!#$%^&*]+$/;
|
|
4582
|
+
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;
|
|
4583
|
+
var REGEX_CHAR_CLASS_RE = /\[(?:\\[\s\S]|[^\]\\])*\]/g;
|
|
4584
|
+
var REGEX_META_SPLIT_RE = /\(\?(?:<[=!]|<[^>]+>|[:=!])?|\\[\s\S]|[\s^$.*+?()[\]{}|/]+/;
|
|
4585
|
+
var COMMON_BIGRAMS = new Set(
|
|
4586
|
+
"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(" ")
|
|
4587
|
+
);
|
|
4588
|
+
var COMMON_BIGRAM_CHANCE = COMMON_BIGRAMS.size / 676;
|
|
4589
|
+
var NATURAL_TEXT_Z = 3.5;
|
|
4590
|
+
function isAsciiLetter(code) {
|
|
4591
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
4592
|
+
}
|
|
4593
|
+
function isBinaryOrWasmPrefix(value) {
|
|
4594
|
+
return value.startsWith("AGFzbQE") || /^data:/i.test(value);
|
|
4595
|
+
}
|
|
4596
|
+
function countBase64MarkerRatio(value) {
|
|
4597
|
+
let hits = 0;
|
|
4598
|
+
for (let i = 0; i < value.length; i++) {
|
|
4599
|
+
const code = value.charCodeAt(i);
|
|
4600
|
+
if (code >= 48 && code <= 57 || // 0-9
|
|
4601
|
+
code === 43 || // +
|
|
4602
|
+
code === 47 || // /
|
|
4603
|
+
code === 61) {
|
|
4604
|
+
hits += 1;
|
|
4605
|
+
}
|
|
4606
|
+
}
|
|
4607
|
+
return hits / value.length;
|
|
4608
|
+
}
|
|
4609
|
+
function shannonEntropy(value) {
|
|
4610
|
+
if (value.length === 0) return 0;
|
|
4611
|
+
const counts = /* @__PURE__ */ new Map();
|
|
4612
|
+
for (let i = 0; i < value.length; i++) {
|
|
4613
|
+
const code = value.charCodeAt(i);
|
|
4614
|
+
counts.set(code, (counts.get(code) ?? 0) + 1);
|
|
4615
|
+
}
|
|
4616
|
+
let h = 0;
|
|
4617
|
+
for (const count of counts.values()) {
|
|
4618
|
+
const p = count / value.length;
|
|
4619
|
+
h -= p * Math.log2(p);
|
|
4620
|
+
}
|
|
4621
|
+
return h;
|
|
4622
|
+
}
|
|
4623
|
+
function isSequentialAlphabet(value) {
|
|
4624
|
+
if (value.length < 8) return false;
|
|
4625
|
+
let ascending = 0;
|
|
4626
|
+
for (let i = 1; i < value.length; i++) {
|
|
4627
|
+
if (value.charCodeAt(i) - value.charCodeAt(i - 1) === 1) {
|
|
4628
|
+
ascending += 1;
|
|
4629
|
+
}
|
|
4630
|
+
}
|
|
4631
|
+
return ascending / (value.length - 1) >= 0.6;
|
|
4632
|
+
}
|
|
4633
|
+
function looksLikeNaturalText(value) {
|
|
4634
|
+
let pairs = 0;
|
|
4635
|
+
let hits = 0;
|
|
4636
|
+
const lower = value.toLowerCase();
|
|
4637
|
+
for (let i = 1; i < value.length; i++) {
|
|
4638
|
+
const a = value.charCodeAt(i - 1);
|
|
4639
|
+
const b = value.charCodeAt(i);
|
|
4640
|
+
if (!isAsciiLetter(a) || !isAsciiLetter(b)) continue;
|
|
4641
|
+
pairs += 1;
|
|
4642
|
+
if (a >= 97 && b <= 90) continue;
|
|
4643
|
+
if (COMMON_BIGRAMS.has(lower[i - 1] + lower[i])) {
|
|
4644
|
+
hits += 1;
|
|
4645
|
+
}
|
|
4646
|
+
}
|
|
4647
|
+
if (pairs < 4) return false;
|
|
4648
|
+
const expected = COMMON_BIGRAM_CHANCE * pairs;
|
|
4649
|
+
const deviation = Math.sqrt(
|
|
4650
|
+
pairs * COMMON_BIGRAM_CHANCE * (1 - COMMON_BIGRAM_CHANCE)
|
|
4651
|
+
);
|
|
4652
|
+
return (hits - expected) / deviation >= NATURAL_TEXT_Z;
|
|
4653
|
+
}
|
|
4654
|
+
function classifyPlaintextSecret(value) {
|
|
4655
|
+
if (typeof value !== "string" || value.length < 8) return null;
|
|
4656
|
+
if (isBinaryOrWasmPrefix(value)) return null;
|
|
4657
|
+
if (PATH_LIKE_RE.test(value)) return null;
|
|
4658
|
+
const entropy = shannonEntropy(value);
|
|
4659
|
+
if (PEM_HEADER_RE.test(value)) {
|
|
4660
|
+
return { category: "pem-header", entropy };
|
|
4661
|
+
}
|
|
4662
|
+
if (TOKEN_PREFIX_RE.test(value)) {
|
|
4663
|
+
return { category: "token-prefix", entropy };
|
|
4664
|
+
}
|
|
4665
|
+
if (isSequentialAlphabet(value)) {
|
|
4666
|
+
return null;
|
|
4667
|
+
}
|
|
4668
|
+
const isHex = value.length >= 24 && value.length % 2 === 0 && HEX_RE.test(value) && entropy >= 3.2;
|
|
4669
|
+
if (isHex) {
|
|
4670
|
+
return { category: "hex-or-base64", entropy };
|
|
4671
|
+
}
|
|
4672
|
+
const isBase64Like = value.length >= 28 && BASE64_RE.test(value) && countBase64MarkerRatio(value) >= 0.15 && !looksLikeNaturalText(value) && entropy >= 4;
|
|
4673
|
+
if (isBase64Like) {
|
|
4674
|
+
return { category: "hex-or-base64", entropy };
|
|
4675
|
+
}
|
|
4676
|
+
if (value.length >= 20 && value.length <= 512 && TOKEN_CHARSET_RE.test(value) && !looksLikeNaturalText(value) && entropy >= 4.1) {
|
|
4677
|
+
return { category: "high-entropy", entropy };
|
|
4678
|
+
}
|
|
4679
|
+
return null;
|
|
4680
|
+
}
|
|
4681
|
+
function isLikelySecretLiteral(value) {
|
|
4682
|
+
return classifyPlaintextSecret(value) !== null;
|
|
4683
|
+
}
|
|
4684
|
+
function hasRegexSecretRun(pattern) {
|
|
4685
|
+
if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 4096) {
|
|
4686
|
+
return false;
|
|
4687
|
+
}
|
|
4688
|
+
if (PEM_HEADER_RE.test(pattern) || PEM_REGEX_HEADER_RE.test(pattern) || TOKEN_PREFIX_RE.test(pattern) || ESCAPED_FLAG_REGEX_RE.test(pattern)) {
|
|
4689
|
+
return true;
|
|
4690
|
+
}
|
|
4691
|
+
const outsideClasses = pattern.replace(REGEX_CHAR_CLASS_RE, " ");
|
|
4692
|
+
const parts = outsideClasses.split(REGEX_META_SPLIT_RE);
|
|
4693
|
+
for (const part of parts) {
|
|
4694
|
+
if (part.length >= 20 && isLikelySecretLiteral(part)) {
|
|
4695
|
+
return true;
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4698
|
+
return false;
|
|
4699
|
+
}
|
|
4700
|
+
|
|
4441
4701
|
// src/ast/string-vault.ts
|
|
4442
4702
|
var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
|
|
4443
4703
|
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
@@ -4825,6 +5085,222 @@ function findLowestCommonScope(ast, chains) {
|
|
|
4825
5085
|
}
|
|
4826
5086
|
return lca[lca.length - 1] ?? ast;
|
|
4827
5087
|
}
|
|
5088
|
+
function isExemptTemplateLiteral(node, parent) {
|
|
5089
|
+
if (!parent) return true;
|
|
5090
|
+
if (parent.type === "TaggedTemplateExpression" && parent.quasi === node) {
|
|
5091
|
+
return true;
|
|
5092
|
+
}
|
|
5093
|
+
if (parent.type === "ImportExpression" && parent.source === node) {
|
|
5094
|
+
return true;
|
|
5095
|
+
}
|
|
5096
|
+
return false;
|
|
5097
|
+
}
|
|
5098
|
+
function rebuildInterpolatedTemplates(plans) {
|
|
5099
|
+
for (const { node, replacements } of plans) {
|
|
5100
|
+
if (replacements.size === 0) continue;
|
|
5101
|
+
const origQuasis = node.quasis;
|
|
5102
|
+
const origExprs = node.expressions;
|
|
5103
|
+
const nextQuasis = [];
|
|
5104
|
+
const nextExprs = [];
|
|
5105
|
+
let pendingRaw = "";
|
|
5106
|
+
let pendingCooked = "";
|
|
5107
|
+
const flushQuasi = (tail) => {
|
|
5108
|
+
nextQuasis.push({
|
|
5109
|
+
type: "TemplateElement",
|
|
5110
|
+
value: { raw: pendingRaw, cooked: pendingCooked },
|
|
5111
|
+
tail
|
|
5112
|
+
});
|
|
5113
|
+
pendingRaw = "";
|
|
5114
|
+
pendingCooked = "";
|
|
5115
|
+
};
|
|
5116
|
+
for (let i = 0; i < origQuasis.length; i++) {
|
|
5117
|
+
const quasi = origQuasis[i];
|
|
5118
|
+
const replacement = replacements.get(i);
|
|
5119
|
+
if (replacement !== void 0) {
|
|
5120
|
+
flushQuasi(false);
|
|
5121
|
+
nextExprs.push(replacement);
|
|
5122
|
+
} else {
|
|
5123
|
+
pendingRaw += quasi.value?.raw ?? "";
|
|
5124
|
+
pendingCooked += quasi.value?.cooked ?? "";
|
|
5125
|
+
}
|
|
5126
|
+
if (i < origExprs.length) {
|
|
5127
|
+
flushQuasi(false);
|
|
5128
|
+
nextExprs.push(origExprs[i]);
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
5131
|
+
flushQuasi(true);
|
|
5132
|
+
node.quasis = nextQuasis;
|
|
5133
|
+
node.expressions = nextExprs;
|
|
5134
|
+
}
|
|
5135
|
+
}
|
|
5136
|
+
function createNewRegExpAst(sourceExpr, flags) {
|
|
5137
|
+
return {
|
|
5138
|
+
type: "NewExpression",
|
|
5139
|
+
callee: { type: "Identifier", name: "RegExp" },
|
|
5140
|
+
arguments: flags.length > 0 ? [
|
|
5141
|
+
sourceExpr,
|
|
5142
|
+
{
|
|
5143
|
+
type: "Literal",
|
|
5144
|
+
value: flags,
|
|
5145
|
+
raw: JSON.stringify(flags)
|
|
5146
|
+
}
|
|
5147
|
+
] : [sourceExpr]
|
|
5148
|
+
};
|
|
5149
|
+
}
|
|
5150
|
+
function mutateNodeToNewRegExp(node, sourceExpr, flags) {
|
|
5151
|
+
const newExpr = createNewRegExpAst(sourceExpr, flags);
|
|
5152
|
+
node.type = "NewExpression";
|
|
5153
|
+
node.callee = newExpr.callee;
|
|
5154
|
+
node.arguments = newExpr.arguments;
|
|
5155
|
+
delete node.value;
|
|
5156
|
+
delete node.raw;
|
|
5157
|
+
delete node.regex;
|
|
5158
|
+
delete node.optional;
|
|
5159
|
+
}
|
|
5160
|
+
var SCOPE_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
5161
|
+
"FunctionDeclaration",
|
|
5162
|
+
"FunctionExpression",
|
|
5163
|
+
"ArrowFunctionExpression"
|
|
5164
|
+
]);
|
|
5165
|
+
var SCOPE_LEXICAL_TYPES = /* @__PURE__ */ new Set([
|
|
5166
|
+
"Program",
|
|
5167
|
+
"FunctionDeclaration",
|
|
5168
|
+
"FunctionExpression",
|
|
5169
|
+
"ArrowFunctionExpression",
|
|
5170
|
+
"BlockStatement",
|
|
5171
|
+
"ForStatement",
|
|
5172
|
+
"ForInStatement",
|
|
5173
|
+
"ForOfStatement",
|
|
5174
|
+
"SwitchStatement",
|
|
5175
|
+
"CatchClause",
|
|
5176
|
+
"ClassDeclaration",
|
|
5177
|
+
"ClassExpression",
|
|
5178
|
+
"StaticBlock"
|
|
5179
|
+
]);
|
|
5180
|
+
function patternContainsIdentifier(pattern, targetName) {
|
|
5181
|
+
if (!pattern || typeof pattern !== "object") return false;
|
|
5182
|
+
switch (pattern.type) {
|
|
5183
|
+
case "Identifier":
|
|
5184
|
+
return pattern.name === targetName;
|
|
5185
|
+
case "AssignmentPattern":
|
|
5186
|
+
return patternContainsIdentifier(pattern.left, targetName);
|
|
5187
|
+
case "RestElement":
|
|
5188
|
+
return patternContainsIdentifier(pattern.argument, targetName);
|
|
5189
|
+
case "ArrayPattern":
|
|
5190
|
+
return (pattern.elements || []).some(
|
|
5191
|
+
(el) => patternContainsIdentifier(el, targetName)
|
|
5192
|
+
);
|
|
5193
|
+
case "ObjectPattern":
|
|
5194
|
+
return (pattern.properties || []).some(
|
|
5195
|
+
(prop) => prop?.type === "Property" ? patternContainsIdentifier(prop.value, targetName) : prop?.type === "RestElement" ? patternContainsIdentifier(prop.argument, targetName) : false
|
|
5196
|
+
);
|
|
5197
|
+
default:
|
|
5198
|
+
return false;
|
|
5199
|
+
}
|
|
5200
|
+
}
|
|
5201
|
+
function findEnclosingScope(ancestors, scopeSet, fallback) {
|
|
5202
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
5203
|
+
if (scopeSet.has(ancestors[i].type)) {
|
|
5204
|
+
return ancestors[i];
|
|
5205
|
+
}
|
|
5206
|
+
}
|
|
5207
|
+
return fallback;
|
|
5208
|
+
}
|
|
5209
|
+
function collectIdentifierShadowedScopes(ast, identName = "RegExp") {
|
|
5210
|
+
const shadowed = /* @__PURE__ */ new WeakSet();
|
|
5211
|
+
walk4.ancestor(ast, {
|
|
5212
|
+
FunctionDeclaration(node, _state, ancestors) {
|
|
5213
|
+
if (node.id?.name === identName) {
|
|
5214
|
+
shadowed.add(
|
|
5215
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
5216
|
+
);
|
|
5217
|
+
shadowed.add(node);
|
|
5218
|
+
}
|
|
5219
|
+
if (Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
5220
|
+
shadowed.add(node);
|
|
5221
|
+
}
|
|
5222
|
+
},
|
|
5223
|
+
FunctionExpression(node) {
|
|
5224
|
+
if (node.id?.name === identName || Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
5225
|
+
shadowed.add(node);
|
|
5226
|
+
}
|
|
5227
|
+
},
|
|
5228
|
+
ArrowFunctionExpression(node) {
|
|
5229
|
+
if (Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
5230
|
+
shadowed.add(node);
|
|
5231
|
+
}
|
|
5232
|
+
},
|
|
5233
|
+
ClassDeclaration(node, _state, ancestors) {
|
|
5234
|
+
if (node.id?.name === identName) {
|
|
5235
|
+
shadowed.add(
|
|
5236
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
5237
|
+
);
|
|
5238
|
+
shadowed.add(node);
|
|
5239
|
+
}
|
|
5240
|
+
},
|
|
5241
|
+
ClassExpression(node) {
|
|
5242
|
+
if (node.id?.name === identName) {
|
|
5243
|
+
shadowed.add(node);
|
|
5244
|
+
}
|
|
5245
|
+
},
|
|
5246
|
+
CatchClause(node) {
|
|
5247
|
+
if (node.param && patternContainsIdentifier(node.param, identName)) {
|
|
5248
|
+
shadowed.add(node);
|
|
5249
|
+
}
|
|
5250
|
+
},
|
|
5251
|
+
WithStatement(node) {
|
|
5252
|
+
shadowed.add(node);
|
|
5253
|
+
},
|
|
5254
|
+
ImportDeclaration(node) {
|
|
5255
|
+
if (Array.isArray(node.specifiers) && node.specifiers.some((s) => s?.local?.name === identName)) {
|
|
5256
|
+
shadowed.add(ast);
|
|
5257
|
+
}
|
|
5258
|
+
},
|
|
5259
|
+
VariableDeclaration(node, _state, ancestors) {
|
|
5260
|
+
if (!Array.isArray(node.declarations) || !node.declarations.some(
|
|
5261
|
+
(d) => patternContainsIdentifier(d?.id, identName)
|
|
5262
|
+
)) {
|
|
5263
|
+
return;
|
|
5264
|
+
}
|
|
5265
|
+
if (node.kind === "var") {
|
|
5266
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
5267
|
+
const a = ancestors[i];
|
|
5268
|
+
if (SCOPE_FUNCTION_TYPES.has(a.type) || a.type === "StaticBlock" || a.type === "Program") {
|
|
5269
|
+
shadowed.add(a);
|
|
5270
|
+
break;
|
|
5271
|
+
}
|
|
5272
|
+
}
|
|
5273
|
+
} else {
|
|
5274
|
+
shadowed.add(
|
|
5275
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
5276
|
+
);
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
});
|
|
5280
|
+
return shadowed;
|
|
5281
|
+
}
|
|
5282
|
+
function isEligibleSecretRegExp(node, ancestors, hotExemptNodes, exemptSubtreeRoots, getShadowedScopes) {
|
|
5283
|
+
const pattern = node?.regex?.pattern;
|
|
5284
|
+
if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 4096) {
|
|
5285
|
+
return false;
|
|
5286
|
+
}
|
|
5287
|
+
if (!hasRegexSecretRun(pattern)) {
|
|
5288
|
+
return false;
|
|
5289
|
+
}
|
|
5290
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5291
|
+
return false;
|
|
5292
|
+
}
|
|
5293
|
+
if (isInsideLoopOrSerialized(ancestors)) {
|
|
5294
|
+
return false;
|
|
5295
|
+
}
|
|
5296
|
+
if (isNodeInExemptSubtree(ancestors, hotExemptNodes)) {
|
|
5297
|
+
return false;
|
|
5298
|
+
}
|
|
5299
|
+
if (getShadowedScopes && isNodeInExemptSubtree(ancestors, getShadowedScopes())) {
|
|
5300
|
+
return false;
|
|
5301
|
+
}
|
|
5302
|
+
return true;
|
|
5303
|
+
}
|
|
4828
5304
|
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode, config, shieldCoupled = true, detectHeadless = false, exemptSubtreeRoots) {
|
|
4829
5305
|
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
4830
5306
|
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
@@ -4886,6 +5362,12 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4886
5362
|
const shaderPayloads = [];
|
|
4887
5363
|
const targetsToReplace = [];
|
|
4888
5364
|
const hotTargetsToReplace = [];
|
|
5365
|
+
const interpolatedTemplates = [];
|
|
5366
|
+
let regExpShadowedScopes;
|
|
5367
|
+
const getRegExpShadowedScopes = () => {
|
|
5368
|
+
regExpShadowedScopes ??= collectIdentifierShadowedScopes(ast, "RegExp");
|
|
5369
|
+
return regExpShadowedScopes;
|
|
5370
|
+
};
|
|
4889
5371
|
const customWalkBase = {
|
|
4890
5372
|
...walk4.base,
|
|
4891
5373
|
Property(node, st, c) {
|
|
@@ -4893,16 +5375,16 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4893
5375
|
if (node.value) c(node.value, st);
|
|
4894
5376
|
}
|
|
4895
5377
|
};
|
|
4896
|
-
function processVaultCandidate(val, node, parent, ancestors) {
|
|
5378
|
+
function processVaultCandidate(val, node, parent, ancestors, onReplace) {
|
|
4897
5379
|
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
4898
|
-
return;
|
|
5380
|
+
return false;
|
|
4899
5381
|
}
|
|
4900
5382
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
4901
|
-
return;
|
|
5383
|
+
return false;
|
|
4902
5384
|
}
|
|
4903
5385
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
4904
5386
|
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
4905
|
-
return;
|
|
5387
|
+
return false;
|
|
4906
5388
|
}
|
|
4907
5389
|
}
|
|
4908
5390
|
let isHotExempt = false;
|
|
@@ -4934,9 +5416,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4934
5416
|
node,
|
|
4935
5417
|
parent,
|
|
4936
5418
|
idx: idx2,
|
|
4937
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
5419
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
5420
|
+
...onReplace ? { onReplace } : {}
|
|
4938
5421
|
});
|
|
4939
|
-
return;
|
|
5422
|
+
return true;
|
|
4940
5423
|
}
|
|
4941
5424
|
if (isHotExempt) {
|
|
4942
5425
|
if (isEligibleHotLiteral(
|
|
@@ -4955,10 +5438,12 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4955
5438
|
node,
|
|
4956
5439
|
parent,
|
|
4957
5440
|
val,
|
|
4958
|
-
idx: hotTargetsToReplace.length
|
|
5441
|
+
idx: hotTargetsToReplace.length,
|
|
5442
|
+
...onReplace ? { onReplace } : {}
|
|
4959
5443
|
});
|
|
5444
|
+
return true;
|
|
4960
5445
|
}
|
|
4961
|
-
return;
|
|
5446
|
+
return false;
|
|
4962
5447
|
}
|
|
4963
5448
|
if (!shouldEncryptString(
|
|
4964
5449
|
val,
|
|
@@ -4967,7 +5452,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4967
5452
|
activeDirectives,
|
|
4968
5453
|
customReserved
|
|
4969
5454
|
)) {
|
|
4970
|
-
return;
|
|
5455
|
+
return false;
|
|
4971
5456
|
}
|
|
4972
5457
|
let idx = stringToIndex.get(val);
|
|
4973
5458
|
if (idx === void 0) {
|
|
@@ -4980,13 +5465,44 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4980
5465
|
node,
|
|
4981
5466
|
parent,
|
|
4982
5467
|
idx,
|
|
4983
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
5468
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
5469
|
+
...onReplace ? { onReplace } : {}
|
|
4984
5470
|
});
|
|
5471
|
+
return true;
|
|
4985
5472
|
}
|
|
4986
5473
|
walk4.ancestor(
|
|
4987
5474
|
ast,
|
|
4988
5475
|
{
|
|
4989
5476
|
Literal(node, _state, ancestors) {
|
|
5477
|
+
if (node.regex) {
|
|
5478
|
+
if (isEligibleSecretRegExp(
|
|
5479
|
+
node,
|
|
5480
|
+
ancestors,
|
|
5481
|
+
hotExemptNodes,
|
|
5482
|
+
exemptSubtreeRoots,
|
|
5483
|
+
getRegExpShadowedScopes
|
|
5484
|
+
)) {
|
|
5485
|
+
const pattern = node.regex.pattern;
|
|
5486
|
+
const flags = node.regex.flags ?? "";
|
|
5487
|
+
const parent2 = ancestors[ancestors.length - 2];
|
|
5488
|
+
let idx = stringToIndex.get(pattern);
|
|
5489
|
+
if (idx === void 0) {
|
|
5490
|
+
idx = uniqueStrings.length;
|
|
5491
|
+
stringToIndex.set(pattern, idx);
|
|
5492
|
+
uniqueStrings.push(pattern);
|
|
5493
|
+
}
|
|
5494
|
+
targetsToReplace.push({
|
|
5495
|
+
type: "string",
|
|
5496
|
+
node,
|
|
5497
|
+
parent: parent2,
|
|
5498
|
+
idx,
|
|
5499
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
5500
|
+
replaceMode: "regexp",
|
|
5501
|
+
flags
|
|
5502
|
+
});
|
|
5503
|
+
}
|
|
5504
|
+
return;
|
|
5505
|
+
}
|
|
4990
5506
|
if (typeof node.value !== "string") return;
|
|
4991
5507
|
const val = node.value;
|
|
4992
5508
|
if (activeDirectives.has(val)) return;
|
|
@@ -5004,19 +5520,42 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5004
5520
|
processVaultCandidate(val, node, parent, ancestors);
|
|
5005
5521
|
},
|
|
5006
5522
|
TemplateLiteral(node, _state, ancestors) {
|
|
5007
|
-
if (!node.quasis || node.quasis.length
|
|
5008
|
-
if (node.expressions && node.expressions.length !== 0) return;
|
|
5009
|
-
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
5010
|
-
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
5523
|
+
if (!Array.isArray(node.quasis) || node.quasis.length === 0) return;
|
|
5011
5524
|
const parent = ancestors[ancestors.length - 2];
|
|
5012
|
-
if (
|
|
5013
|
-
|
|
5525
|
+
if (isExemptTemplateLiteral(node, parent)) return;
|
|
5526
|
+
const exprCount = Array.isArray(node.expressions) ? node.expressions.length : 0;
|
|
5527
|
+
if (exprCount === 0) {
|
|
5528
|
+
if (node.quasis.length !== 1) return;
|
|
5529
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
5530
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
5531
|
+
processVaultCandidate(val, node, parent, ancestors);
|
|
5014
5532
|
return;
|
|
5015
5533
|
}
|
|
5016
|
-
if (
|
|
5534
|
+
if (node.quasis.length !== exprCount + 1) return;
|
|
5535
|
+
if (node.quasis.some((q) => typeof q?.value?.cooked !== "string")) {
|
|
5017
5536
|
return;
|
|
5018
5537
|
}
|
|
5019
|
-
|
|
5538
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
5539
|
+
let queuedCount = 0;
|
|
5540
|
+
for (let qIdx = 0; qIdx < node.quasis.length; qIdx++) {
|
|
5541
|
+
const val = node.quasis[qIdx].value.cooked;
|
|
5542
|
+
if (activeDirectives.has(val)) continue;
|
|
5543
|
+
const queued = processVaultCandidate(
|
|
5544
|
+
val,
|
|
5545
|
+
node,
|
|
5546
|
+
parent,
|
|
5547
|
+
ancestors,
|
|
5548
|
+
(exprAst) => {
|
|
5549
|
+
replacements.set(qIdx, exprAst);
|
|
5550
|
+
}
|
|
5551
|
+
);
|
|
5552
|
+
if (queued) {
|
|
5553
|
+
queuedCount++;
|
|
5554
|
+
}
|
|
5555
|
+
}
|
|
5556
|
+
if (queuedCount > 0) {
|
|
5557
|
+
interpolatedTemplates.push({ node, replacements });
|
|
5558
|
+
}
|
|
5020
5559
|
}
|
|
5021
5560
|
},
|
|
5022
5561
|
customWalkBase
|
|
@@ -5028,38 +5567,69 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5028
5567
|
shaderBuffersCount: 0
|
|
5029
5568
|
};
|
|
5030
5569
|
}
|
|
5031
|
-
for (const { node, parent, val, idx } of hotTargetsToReplace) {
|
|
5570
|
+
for (const { node, parent, val, idx, onReplace } of hotTargetsToReplace) {
|
|
5032
5571
|
const key = idx % 3 + 1;
|
|
5033
5572
|
let encodedStr = "";
|
|
5034
5573
|
for (let i = 0; i < val.length; i++) {
|
|
5035
5574
|
encodedStr += String.fromCharCode(val.charCodeAt(i) ^ key);
|
|
5036
5575
|
}
|
|
5576
|
+
const callExpr = {
|
|
5577
|
+
type: "CallExpression",
|
|
5578
|
+
callee: {
|
|
5579
|
+
type: "Identifier",
|
|
5580
|
+
name: "_hX"
|
|
5581
|
+
},
|
|
5582
|
+
arguments: [
|
|
5583
|
+
{
|
|
5584
|
+
type: "Literal",
|
|
5585
|
+
value: encodedStr,
|
|
5586
|
+
raw: JSON.stringify(encodedStr)
|
|
5587
|
+
},
|
|
5588
|
+
{
|
|
5589
|
+
type: "Literal",
|
|
5590
|
+
value: key,
|
|
5591
|
+
raw: String(key)
|
|
5592
|
+
}
|
|
5593
|
+
],
|
|
5594
|
+
optional: false
|
|
5595
|
+
};
|
|
5596
|
+
if (onReplace) {
|
|
5597
|
+
onReplace(callExpr);
|
|
5598
|
+
continue;
|
|
5599
|
+
}
|
|
5037
5600
|
if (parent?.type === "Property" && parent.key === node) {
|
|
5038
5601
|
parent.computed = true;
|
|
5039
5602
|
}
|
|
5040
5603
|
node.type = "CallExpression";
|
|
5041
|
-
node.callee =
|
|
5042
|
-
|
|
5043
|
-
name: "_hX"
|
|
5044
|
-
};
|
|
5045
|
-
node.arguments = [
|
|
5046
|
-
{
|
|
5047
|
-
type: "Literal",
|
|
5048
|
-
value: encodedStr,
|
|
5049
|
-
raw: JSON.stringify(encodedStr)
|
|
5050
|
-
},
|
|
5051
|
-
{
|
|
5052
|
-
type: "Literal",
|
|
5053
|
-
value: key,
|
|
5054
|
-
raw: String(key)
|
|
5055
|
-
}
|
|
5056
|
-
];
|
|
5604
|
+
node.callee = callExpr.callee;
|
|
5605
|
+
node.arguments = callExpr.arguments;
|
|
5057
5606
|
node.optional = false;
|
|
5058
5607
|
delete node.value;
|
|
5059
5608
|
delete node.raw;
|
|
5060
5609
|
delete node.quasis;
|
|
5061
5610
|
delete node.expressions;
|
|
5062
5611
|
}
|
|
5612
|
+
function applyVaultTargetReplacement(target, callExpr) {
|
|
5613
|
+
if (target.onReplace) {
|
|
5614
|
+
target.onReplace(callExpr);
|
|
5615
|
+
return;
|
|
5616
|
+
}
|
|
5617
|
+
if (target.replaceMode === "regexp") {
|
|
5618
|
+
mutateNodeToNewRegExp(target.node, callExpr, target.flags ?? "");
|
|
5619
|
+
return;
|
|
5620
|
+
}
|
|
5621
|
+
if (target.parent?.type === "Property" && target.parent.key === target.node) {
|
|
5622
|
+
target.parent.computed = true;
|
|
5623
|
+
}
|
|
5624
|
+
target.node.type = "CallExpression";
|
|
5625
|
+
target.node.callee = callExpr.callee;
|
|
5626
|
+
target.node.arguments = callExpr.arguments;
|
|
5627
|
+
target.node.optional = false;
|
|
5628
|
+
delete target.node.value;
|
|
5629
|
+
delete target.node.raw;
|
|
5630
|
+
delete target.node.quasis;
|
|
5631
|
+
delete target.node.expressions;
|
|
5632
|
+
}
|
|
5063
5633
|
let insertIdx = findVaultInsertIndex(ast, activeDirectives);
|
|
5064
5634
|
const wantFragmented = Boolean(config?.vault?.fragmented);
|
|
5065
5635
|
let fragCount = Math.max(2, Math.min(8, Math.floor(config?.vault?.fragmentCount ?? 3)));
|
|
@@ -5076,28 +5646,28 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5076
5646
|
);
|
|
5077
5647
|
}
|
|
5078
5648
|
integrityToken = computeFnv1aHash(JSON.stringify(encryptedPayloads), seed);
|
|
5079
|
-
for (const
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5649
|
+
for (const target of targetsToReplace) {
|
|
5650
|
+
let callExpr;
|
|
5651
|
+
if (target.type === "shader") {
|
|
5652
|
+
callExpr = {
|
|
5653
|
+
type: "CallExpression",
|
|
5654
|
+
callee: { type: "Identifier", name: shaderVarName },
|
|
5655
|
+
arguments: [{ type: "Literal", value: target.idx, raw: String(target.idx) }],
|
|
5656
|
+
optional: false
|
|
5657
|
+
};
|
|
5087
5658
|
} else {
|
|
5088
|
-
const salt = computeCallSiteSalt(seed, idx);
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
delete node.expressions;
|
|
5659
|
+
const salt = computeCallSiteSalt(seed, target.idx);
|
|
5660
|
+
callExpr = {
|
|
5661
|
+
type: "CallExpression",
|
|
5662
|
+
callee: { type: "Identifier", name: decryptFnName },
|
|
5663
|
+
arguments: [
|
|
5664
|
+
{ type: "Literal", value: target.idx, raw: String(target.idx) },
|
|
5665
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
5666
|
+
],
|
|
5667
|
+
optional: false
|
|
5668
|
+
};
|
|
5669
|
+
}
|
|
5670
|
+
applyVaultTargetReplacement(target, callExpr);
|
|
5101
5671
|
}
|
|
5102
5672
|
} else {
|
|
5103
5673
|
const perm = [];
|
|
@@ -5165,31 +5735,31 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5165
5735
|
chains: []
|
|
5166
5736
|
});
|
|
5167
5737
|
}
|
|
5168
|
-
for (const
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5738
|
+
for (const target of targetsToReplace) {
|
|
5739
|
+
let callExpr;
|
|
5740
|
+
if (target.type === "shader") {
|
|
5741
|
+
callExpr = {
|
|
5742
|
+
type: "CallExpression",
|
|
5743
|
+
callee: { type: "Identifier", name: shaderVarName },
|
|
5744
|
+
arguments: [{ type: "Literal", value: target.idx, raw: String(target.idx) }],
|
|
5745
|
+
optional: false
|
|
5746
|
+
};
|
|
5176
5747
|
} else {
|
|
5177
|
-
const { fragId, localIdx } = stringFragAssign[idx];
|
|
5748
|
+
const { fragId, localIdx } = stringFragAssign[target.idx];
|
|
5178
5749
|
const meta = fragMeta[fragId];
|
|
5179
|
-
meta.chains.push(scopeChain);
|
|
5750
|
+
meta.chains.push(target.scopeChain);
|
|
5180
5751
|
const salt = computeCallSiteSalt(meta.fragSeed, localIdx);
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
delete node.expressions;
|
|
5752
|
+
callExpr = {
|
|
5753
|
+
type: "CallExpression",
|
|
5754
|
+
callee: { type: "Identifier", name: meta.fnName },
|
|
5755
|
+
arguments: [
|
|
5756
|
+
{ type: "Literal", value: localIdx, raw: String(localIdx) },
|
|
5757
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
5758
|
+
],
|
|
5759
|
+
optional: false
|
|
5760
|
+
};
|
|
5761
|
+
}
|
|
5762
|
+
applyVaultTargetReplacement(target, callExpr);
|
|
5193
5763
|
}
|
|
5194
5764
|
const allPayloads = [];
|
|
5195
5765
|
for (const meta of fragMeta) {
|
|
@@ -5212,6 +5782,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5212
5782
|
}
|
|
5213
5783
|
integrityToken = computeFnv1aHash(JSON.stringify(allPayloads), seed);
|
|
5214
5784
|
}
|
|
5785
|
+
rebuildInterpolatedTemplates(interpolatedTemplates);
|
|
5215
5786
|
if (hotTargetsToReplace.length > 0) {
|
|
5216
5787
|
const alreadyHasHx = ast.body.some(
|
|
5217
5788
|
(stmt) => stmt.type === "FunctionDeclaration" && stmt.id?.name === "_hX"
|
|
@@ -5838,6 +6409,26 @@ function mixSeed32(seed, salt) {
|
|
|
5838
6409
|
h ^= h >>> 16;
|
|
5839
6410
|
return h | 0;
|
|
5840
6411
|
}
|
|
6412
|
+
function modInverseUint32(oddValue) {
|
|
6413
|
+
const m = (oddValue | 1) >>> 0;
|
|
6414
|
+
let inv = 1;
|
|
6415
|
+
for (let i = 0; i < 5; i++) {
|
|
6416
|
+
inv = Math.imul(inv, 2 - Math.imul(m, inv) | 0) >>> 0;
|
|
6417
|
+
}
|
|
6418
|
+
return inv >>> 0;
|
|
6419
|
+
}
|
|
6420
|
+
function deriveAffineMbaParams(seed, salt) {
|
|
6421
|
+
let m = (mixSeed32(seed, salt) | 1) >>> 0;
|
|
6422
|
+
if (m === 1 || m === 4294967295 || m === 2654435769) {
|
|
6423
|
+
m = (m ^ 1540483477 | 1) >>> 0;
|
|
6424
|
+
}
|
|
6425
|
+
const m2 = Math.imul(m, 2) >>> 0;
|
|
6426
|
+
const mInv = modInverseUint32(m);
|
|
6427
|
+
let c = mixSeed32(seed, salt + 40503) >>> 0;
|
|
6428
|
+
if (c === 0) c = 668265263;
|
|
6429
|
+
const d = -Math.imul(mInv, c) >>> 0;
|
|
6430
|
+
return { m, m2, mInv, c, d };
|
|
6431
|
+
}
|
|
5841
6432
|
function cloneNode(node) {
|
|
5842
6433
|
return JSON.parse(JSON.stringify(node));
|
|
5843
6434
|
}
|
|
@@ -6586,7 +7177,8 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6586
7177
|
zRefForDecoy
|
|
6587
7178
|
);
|
|
6588
7179
|
const hasShieldCoupling = Boolean(ctxOpts?.shieldCoupled && ctxOpts?.windowKeySymbol);
|
|
6589
|
-
const
|
|
7180
|
+
const predOffset = hasShieldCoupling ? 1 : (seed >>> 2) % 6;
|
|
7181
|
+
const predForm = ((fnIndex + predOffset) % 6 + 6) % 6;
|
|
6590
7182
|
let testExpr;
|
|
6591
7183
|
if (predForm === 0) {
|
|
6592
7184
|
let pathACore = qnrValForForm0;
|
|
@@ -6662,13 +7254,84 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6662
7254
|
}
|
|
6663
7255
|
const rhsExpr = makeBinary("+", makeLiteral(qnrFamily.outBoundVal), slotWriteB);
|
|
6664
7256
|
testExpr = makeBinary(qnrFamily.outBoundOp, lhsExpr, rhsExpr);
|
|
6665
|
-
} else {
|
|
7257
|
+
} else if (predForm === 3) {
|
|
6666
7258
|
const tagLhs = hasAlias ? makeBinary("&", makeMemberIndex(ctxOpts.aliasIdentA, makeLiteral(slotB)), makeLiteral(240)) : makeBinary("&", makeBinary("<<", makeTypeofGlobalLen(), makeLiteral(4)), makeLiteral(240));
|
|
6667
7259
|
const tagRhsBase = hasAlias ? makeBinary("&", makeMemberIndex(aliasReadIdent, makeLiteral(slotB)), makeLiteral(240)) : makeBinary("&", makeBinary("<<", makeTypeofGlobalLen(), makeLiteral(4)), makeLiteral(240));
|
|
6668
7260
|
const tagRhs = aliasInvZero ? makeBinary("^", tagRhsBase, makeBinary("&", aliasInvZero, makeLiteral(15))) : tagRhsBase;
|
|
6669
7261
|
const lhsExpr = makeBinary("|", makeBinary("^", qnrLeft, tagLhs), makeLiteral(0));
|
|
6670
7262
|
const rhsExpr = makeBinary("|", makeBinary("^", makeLiteral(qnrFamily.target), tagRhs), makeLiteral(0));
|
|
6671
7263
|
testExpr = makeBinary("===", lhsExpr, rhsExpr);
|
|
7264
|
+
} else if (predForm === 4) {
|
|
7265
|
+
const k4 = mixSeed32(seed, fnIndex * 29 + 13) >>> 0 || 1;
|
|
7266
|
+
if (ctxOpts?.scratchVarIdent) {
|
|
7267
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
7268
|
+
const preU = aliasInvZero ? makeBinary("^", cloneNode(scratchId), aliasInvZero) : cloneNode(scratchId);
|
|
7269
|
+
const uAssign = {
|
|
7270
|
+
type: "AssignmentExpression",
|
|
7271
|
+
operator: "=",
|
|
7272
|
+
left: cloneNode(scratchId),
|
|
7273
|
+
right: makeBinary(">>>", makeBinary("^", preU, makeLiteral(k4)), makeLiteral(0))
|
|
7274
|
+
};
|
|
7275
|
+
const uMinus1Lhs = makeBinary(">>>", makeBinary("-", cloneNode(scratchId), makeLiteral(1)), makeLiteral(0));
|
|
7276
|
+
const uMinus1Rhs = makeBinary(">>>", makeBinary("-", cloneNode(scratchId), makeLiteral(1)), makeLiteral(0));
|
|
7277
|
+
const orU = makeBinary(">>>", makeBinary("|", cloneNode(scratchId), uMinus1Lhs), makeLiteral(0));
|
|
7278
|
+
const xorU = makeBinary(">>>", makeBinary("^", cloneNode(scratchId), uMinus1Rhs), makeLiteral(0));
|
|
7279
|
+
const lhsSeq = {
|
|
7280
|
+
type: "SequenceExpression",
|
|
7281
|
+
expressions: [...qnrLeft.expressions.slice(0, -1), uAssign, orU]
|
|
7282
|
+
};
|
|
7283
|
+
testExpr = makeBinary("<", lhsSeq, xorU);
|
|
7284
|
+
} else {
|
|
7285
|
+
const uExpr = makeBinary(">>>", makeBinary("^", cloneNode(zRefForDecoy), makeLiteral(k4)), makeLiteral(0));
|
|
7286
|
+
const uMinus1Lhs = makeBinary(">>>", makeBinary("-", cloneNode(uExpr), makeLiteral(1)), makeLiteral(0));
|
|
7287
|
+
const uMinus1Rhs = makeBinary(">>>", makeBinary("-", cloneNode(uExpr), makeLiteral(1)), makeLiteral(0));
|
|
7288
|
+
const orU = makeBinary(">>>", makeBinary("|", cloneNode(uExpr), uMinus1Lhs), makeLiteral(0));
|
|
7289
|
+
const xorU = makeBinary(">>>", makeBinary("^", cloneNode(uExpr), uMinus1Rhs), makeLiteral(0));
|
|
7290
|
+
testExpr = makeBinary("<", orU, xorU);
|
|
7291
|
+
}
|
|
7292
|
+
} else {
|
|
7293
|
+
const k5 = mixSeed32(seed, fnIndex * 31 + 17) >>> 0 || 3;
|
|
7294
|
+
const { m, m2, mInv, c, d } = deriveAffineMbaParams(seed, fnIndex * 37 + 23);
|
|
7295
|
+
const buildAffineLhs = (valNode) => {
|
|
7296
|
+
const inner = makeBinary(
|
|
7297
|
+
"|",
|
|
7298
|
+
makeBinary(
|
|
7299
|
+
"+",
|
|
7300
|
+
makeBinary(
|
|
7301
|
+
"+",
|
|
7302
|
+
makeImul(makeLiteral(m), makeBinary("^", cloneNode(valNode), makeLiteral(k5))),
|
|
7303
|
+
makeImul(makeLiteral(m2), makeBinary("&", cloneNode(valNode), makeLiteral(k5)))
|
|
7304
|
+
),
|
|
7305
|
+
makeLiteral(c)
|
|
7306
|
+
),
|
|
7307
|
+
makeLiteral(0)
|
|
7308
|
+
);
|
|
7309
|
+
return makeBinary(
|
|
7310
|
+
"|",
|
|
7311
|
+
makeBinary("+", makeImul(makeLiteral(mInv), inner), makeLiteral(d)),
|
|
7312
|
+
makeLiteral(0)
|
|
7313
|
+
);
|
|
7314
|
+
};
|
|
7315
|
+
const buildAffineRhs = (valNode) => makeBinary("|", makeBinary("+", cloneNode(valNode), makeLiteral(k5)), makeLiteral(0));
|
|
7316
|
+
if (ctxOpts?.scratchVarIdent) {
|
|
7317
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
7318
|
+
const preSeqs = [...qnrLeft.expressions.slice(0, -1)];
|
|
7319
|
+
if (aliasInvZero) {
|
|
7320
|
+
preSeqs.push({
|
|
7321
|
+
type: "AssignmentExpression",
|
|
7322
|
+
operator: "=",
|
|
7323
|
+
left: cloneNode(scratchId),
|
|
7324
|
+
right: makeBinary("|", makeBinary("^", cloneNode(scratchId), aliasInvZero), makeLiteral(0))
|
|
7325
|
+
});
|
|
7326
|
+
}
|
|
7327
|
+
const lhsSeq = {
|
|
7328
|
+
type: "SequenceExpression",
|
|
7329
|
+
expressions: [...preSeqs, buildAffineLhs(scratchId)]
|
|
7330
|
+
};
|
|
7331
|
+
testExpr = makeBinary("!==", lhsSeq, buildAffineRhs(scratchId));
|
|
7332
|
+
} else {
|
|
7333
|
+
testExpr = makeBinary("!==", buildAffineLhs(zRefForDecoy), buildAffineRhs(zRefForDecoy));
|
|
7334
|
+
}
|
|
6672
7335
|
}
|
|
6673
7336
|
return {
|
|
6674
7337
|
type: "IfStatement",
|
|
@@ -6913,7 +7576,362 @@ function createSboxAndAliasDeclarations(sboxIdent, aliasIdentA, aliasIdentB, scr
|
|
|
6913
7576
|
};
|
|
6914
7577
|
}
|
|
6915
7578
|
var MAX_COLD_GUARDS_PER_CHUNK = 12;
|
|
6916
|
-
|
|
7579
|
+
var MAX_COLD_BITWISE_MBA_PER_CHUNK = 8;
|
|
7580
|
+
var BITWISE_MBA_OPS = /* @__PURE__ */ new Set(["^", "|", "&"]);
|
|
7581
|
+
var BITWISE_LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
7582
|
+
"ForStatement",
|
|
7583
|
+
"WhileStatement",
|
|
7584
|
+
"DoWhileStatement",
|
|
7585
|
+
"ForInStatement",
|
|
7586
|
+
"ForOfStatement"
|
|
7587
|
+
]);
|
|
7588
|
+
var BITWISE_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
7589
|
+
"FunctionDeclaration",
|
|
7590
|
+
"FunctionExpression",
|
|
7591
|
+
"ArrowFunctionExpression"
|
|
7592
|
+
]);
|
|
7593
|
+
var BITWISE_LEXICAL_SCOPE_TYPES = /* @__PURE__ */ new Set([
|
|
7594
|
+
"Program",
|
|
7595
|
+
"FunctionDeclaration",
|
|
7596
|
+
"FunctionExpression",
|
|
7597
|
+
"ArrowFunctionExpression",
|
|
7598
|
+
"BlockStatement",
|
|
7599
|
+
"ForStatement",
|
|
7600
|
+
"ForInStatement",
|
|
7601
|
+
"ForOfStatement",
|
|
7602
|
+
"SwitchStatement",
|
|
7603
|
+
"CatchClause",
|
|
7604
|
+
"StaticBlock"
|
|
7605
|
+
]);
|
|
7606
|
+
var FORBIDDEN_BITWISE_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
7607
|
+
"arguments",
|
|
7608
|
+
"eval",
|
|
7609
|
+
"undefined",
|
|
7610
|
+
"NaN",
|
|
7611
|
+
"Infinity",
|
|
7612
|
+
"globalThis",
|
|
7613
|
+
"window",
|
|
7614
|
+
"self",
|
|
7615
|
+
"Math",
|
|
7616
|
+
"BigInt"
|
|
7617
|
+
]);
|
|
7618
|
+
function collectBoundPatternNames(pattern, out) {
|
|
7619
|
+
if (!pattern || typeof pattern !== "object") return;
|
|
7620
|
+
switch (pattern.type) {
|
|
7621
|
+
case "Identifier":
|
|
7622
|
+
out.push(pattern.name);
|
|
7623
|
+
break;
|
|
7624
|
+
case "AssignmentPattern":
|
|
7625
|
+
collectBoundPatternNames(pattern.left, out);
|
|
7626
|
+
break;
|
|
7627
|
+
case "RestElement":
|
|
7628
|
+
collectBoundPatternNames(pattern.argument, out);
|
|
7629
|
+
break;
|
|
7630
|
+
case "ArrayPattern":
|
|
7631
|
+
for (const el of pattern.elements || []) {
|
|
7632
|
+
if (el) collectBoundPatternNames(el, out);
|
|
7633
|
+
}
|
|
7634
|
+
break;
|
|
7635
|
+
case "ObjectPattern":
|
|
7636
|
+
for (const prop of pattern.properties || []) {
|
|
7637
|
+
if (prop.type === "Property") {
|
|
7638
|
+
collectBoundPatternNames(prop.value, out);
|
|
7639
|
+
} else if (prop.type === "RestElement") {
|
|
7640
|
+
collectBoundPatternNames(prop.argument, out);
|
|
7641
|
+
}
|
|
7642
|
+
}
|
|
7643
|
+
break;
|
|
7644
|
+
}
|
|
7645
|
+
}
|
|
7646
|
+
function analyzeBitwiseMbaScopes(ast) {
|
|
7647
|
+
const scopeBindings = /* @__PURE__ */ new Map();
|
|
7648
|
+
let unsafe = false;
|
|
7649
|
+
const addBinding = (scopeNode, name) => {
|
|
7650
|
+
if (name === "Math") {
|
|
7651
|
+
unsafe = true;
|
|
7652
|
+
return;
|
|
7653
|
+
}
|
|
7654
|
+
let set = scopeBindings.get(scopeNode);
|
|
7655
|
+
if (!set) {
|
|
7656
|
+
set = /* @__PURE__ */ new Set();
|
|
7657
|
+
scopeBindings.set(scopeNode, set);
|
|
7658
|
+
}
|
|
7659
|
+
set.add(name);
|
|
7660
|
+
};
|
|
7661
|
+
const scopeStack = [];
|
|
7662
|
+
const varTargetStack = [];
|
|
7663
|
+
const getNearestLexicalScope = () => scopeStack[scopeStack.length - 1] ?? ast;
|
|
7664
|
+
const getNearestVarScope = () => varTargetStack[varTargetStack.length - 1] ?? ast;
|
|
7665
|
+
function scan(node) {
|
|
7666
|
+
if (unsafe || !node || typeof node !== "object" || typeof node.type !== "string") {
|
|
7667
|
+
return;
|
|
7668
|
+
}
|
|
7669
|
+
if (node.type === "WithStatement") {
|
|
7670
|
+
unsafe = true;
|
|
7671
|
+
return;
|
|
7672
|
+
}
|
|
7673
|
+
if (node.type === "Literal" && (typeof node.value === "bigint" || typeof node.bigint === "string") || node.type === "BigIntLiteral") {
|
|
7674
|
+
unsafe = true;
|
|
7675
|
+
return;
|
|
7676
|
+
}
|
|
7677
|
+
if (node.type === "Identifier" && node.name === "BigInt") {
|
|
7678
|
+
unsafe = true;
|
|
7679
|
+
return;
|
|
7680
|
+
}
|
|
7681
|
+
if (node.type === "ImportSpecifier" || node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier") {
|
|
7682
|
+
if (node.local?.type === "Identifier") {
|
|
7683
|
+
addBinding(ast, node.local.name);
|
|
7684
|
+
}
|
|
7685
|
+
} else if (node.type === "FunctionDeclaration") {
|
|
7686
|
+
if (node.id?.type === "Identifier") {
|
|
7687
|
+
addBinding(getNearestLexicalScope(), node.id.name);
|
|
7688
|
+
addBinding(getNearestVarScope(), node.id.name);
|
|
7689
|
+
}
|
|
7690
|
+
} else if (node.type === "ClassDeclaration") {
|
|
7691
|
+
if (node.id?.type === "Identifier") {
|
|
7692
|
+
addBinding(getNearestLexicalScope(), node.id.name);
|
|
7693
|
+
}
|
|
7694
|
+
} else if (node.type === "VariableDeclaration") {
|
|
7695
|
+
const targetScope = node.kind === "var" ? getNearestVarScope() : getNearestLexicalScope();
|
|
7696
|
+
for (const decl of node.declarations || []) {
|
|
7697
|
+
const names = [];
|
|
7698
|
+
collectBoundPatternNames(decl.id, names);
|
|
7699
|
+
for (const name of names) {
|
|
7700
|
+
addBinding(targetScope, name);
|
|
7701
|
+
}
|
|
7702
|
+
}
|
|
7703
|
+
}
|
|
7704
|
+
if (unsafe) return;
|
|
7705
|
+
const pushesLexical = BITWISE_LEXICAL_SCOPE_TYPES.has(node.type);
|
|
7706
|
+
const isFn = BITWISE_FUNCTION_TYPES.has(node.type);
|
|
7707
|
+
const isStaticBlock = node.type === "StaticBlock";
|
|
7708
|
+
if (pushesLexical) {
|
|
7709
|
+
scopeStack.push(node);
|
|
7710
|
+
if (!scopeBindings.has(node)) {
|
|
7711
|
+
scopeBindings.set(node, /* @__PURE__ */ new Set());
|
|
7712
|
+
}
|
|
7713
|
+
}
|
|
7714
|
+
if (isFn) {
|
|
7715
|
+
if (node.id?.type === "Identifier") {
|
|
7716
|
+
addBinding(node, node.id.name);
|
|
7717
|
+
}
|
|
7718
|
+
for (const param of node.params || []) {
|
|
7719
|
+
const names = [];
|
|
7720
|
+
collectBoundPatternNames(param, names);
|
|
7721
|
+
for (const name of names) {
|
|
7722
|
+
addBinding(node, name);
|
|
7723
|
+
}
|
|
7724
|
+
}
|
|
7725
|
+
const bodyScope = node.body?.type === "BlockStatement" ? node.body : node;
|
|
7726
|
+
varTargetStack.push(bodyScope);
|
|
7727
|
+
} else if (node.type === "Program" || isStaticBlock) {
|
|
7728
|
+
varTargetStack.push(node);
|
|
7729
|
+
} else if (node.type === "CatchClause" && node.param) {
|
|
7730
|
+
const names = [];
|
|
7731
|
+
collectBoundPatternNames(node.param, names);
|
|
7732
|
+
for (const name of names) {
|
|
7733
|
+
addBinding(node, name);
|
|
7734
|
+
}
|
|
7735
|
+
} else if (node.type === "ClassExpression" && node.id?.type === "Identifier") {
|
|
7736
|
+
addBinding(node, node.id.name);
|
|
7737
|
+
}
|
|
7738
|
+
try {
|
|
7739
|
+
for (const key of Object.keys(node)) {
|
|
7740
|
+
if (key === "loc" || key === "range" || key === "start" || key === "end" || key === "comments" || key === "tokens") {
|
|
7741
|
+
continue;
|
|
7742
|
+
}
|
|
7743
|
+
const child = node[key];
|
|
7744
|
+
if (Array.isArray(child)) {
|
|
7745
|
+
for (const item of child) {
|
|
7746
|
+
scan(item);
|
|
7747
|
+
if (unsafe) return;
|
|
7748
|
+
}
|
|
7749
|
+
} else if (child && typeof child === "object") {
|
|
7750
|
+
scan(child);
|
|
7751
|
+
if (unsafe) return;
|
|
7752
|
+
}
|
|
7753
|
+
}
|
|
7754
|
+
} finally {
|
|
7755
|
+
if (isFn || node.type === "Program" || isStaticBlock) {
|
|
7756
|
+
varTargetStack.pop();
|
|
7757
|
+
}
|
|
7758
|
+
if (pushesLexical) {
|
|
7759
|
+
scopeStack.pop();
|
|
7760
|
+
}
|
|
7761
|
+
}
|
|
7762
|
+
}
|
|
7763
|
+
scan(ast);
|
|
7764
|
+
return { unsafe, scopeBindings };
|
|
7765
|
+
}
|
|
7766
|
+
function isSafeAtomicIntegerLiteral(node) {
|
|
7767
|
+
return Boolean(
|
|
7768
|
+
node && node.type === "Literal" && typeof node.value === "number" && Number.isInteger(node.value) && node.value >= 0 && node.value <= 4294967295
|
|
7769
|
+
);
|
|
7770
|
+
}
|
|
7771
|
+
function isZeroNumericLiteral(node) {
|
|
7772
|
+
return Boolean(node && node.type === "Literal" && typeof node.value === "number" && node.value === 0);
|
|
7773
|
+
}
|
|
7774
|
+
function isLocalBoundIdentifier(node, scopeStack, scopeBindings, programNode) {
|
|
7775
|
+
if (!node || node.type !== "Identifier") return false;
|
|
7776
|
+
if (FORBIDDEN_BITWISE_IDENTIFIERS.has(node.name)) return false;
|
|
7777
|
+
for (let i = scopeStack.length - 1; i >= 0; i--) {
|
|
7778
|
+
const scopeNode = scopeStack[i];
|
|
7779
|
+
if (scopeNode === programNode) return false;
|
|
7780
|
+
const bindings = scopeBindings.get(scopeNode);
|
|
7781
|
+
if (bindings && bindings.has(node.name)) {
|
|
7782
|
+
return true;
|
|
7783
|
+
}
|
|
7784
|
+
}
|
|
7785
|
+
return false;
|
|
7786
|
+
}
|
|
7787
|
+
function buildColdBitwiseConditional(op, left, right, seed, subIndex, hotExemptNodes) {
|
|
7788
|
+
const { m, mInv, c, d } = deriveAffineMbaParams(seed, 16640 + subIndex * 43);
|
|
7789
|
+
const a1 = cloneNode(left);
|
|
7790
|
+
const b1 = cloneNode(right);
|
|
7791
|
+
const a2 = cloneNode(left);
|
|
7792
|
+
const b2 = cloneNode(right);
|
|
7793
|
+
let affineComb;
|
|
7794
|
+
if (op === "^") {
|
|
7795
|
+
affineComb = makeBinary(
|
|
7796
|
+
"-",
|
|
7797
|
+
makeImul(makeLiteral(m), makeBinary("|", a1, b1)),
|
|
7798
|
+
makeImul(makeLiteral(m), makeBinary("&", a2, b2))
|
|
7799
|
+
);
|
|
7800
|
+
} else if (op === "|") {
|
|
7801
|
+
affineComb = makeBinary(
|
|
7802
|
+
"+",
|
|
7803
|
+
makeImul(makeLiteral(m), makeBinary("&", a1, b1)),
|
|
7804
|
+
makeImul(makeLiteral(m), makeBinary("^", a2, b2))
|
|
7805
|
+
);
|
|
7806
|
+
} else {
|
|
7807
|
+
affineComb = makeBinary(
|
|
7808
|
+
"-",
|
|
7809
|
+
makeImul(makeLiteral(m), makeBinary("|", a1, b1)),
|
|
7810
|
+
makeImul(makeLiteral(m), makeBinary("^", a2, b2))
|
|
7811
|
+
);
|
|
7812
|
+
}
|
|
7813
|
+
const innerWithC = makeBinary("|", makeBinary("+", affineComb, makeLiteral(c)), makeLiteral(0));
|
|
7814
|
+
const consequent = makeBinary(
|
|
7815
|
+
"|",
|
|
7816
|
+
makeBinary("+", makeImul(makeLiteral(mInv), innerWithC), makeLiteral(d)),
|
|
7817
|
+
makeLiteral(0)
|
|
7818
|
+
);
|
|
7819
|
+
const alternate = makeBinary(op, cloneNode(left), cloneNode(right));
|
|
7820
|
+
const exemptNodes = [];
|
|
7821
|
+
const uniqueIdents = [];
|
|
7822
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
7823
|
+
for (const operand of [left, right]) {
|
|
7824
|
+
if (operand?.type === "Identifier" && !seenNames.has(operand.name)) {
|
|
7825
|
+
seenNames.add(operand.name);
|
|
7826
|
+
uniqueIdents.push(operand);
|
|
7827
|
+
}
|
|
7828
|
+
}
|
|
7829
|
+
const makeIsNumberExpr = (ident) => {
|
|
7830
|
+
const numLit = makeLiteral("number");
|
|
7831
|
+
const eqNode = makeBinary("===", makeUnary("typeof", { type: "Identifier", name: ident.name }), numLit);
|
|
7832
|
+
exemptNodes.push(numLit, eqNode);
|
|
7833
|
+
return eqNode;
|
|
7834
|
+
};
|
|
7835
|
+
const testExpr = uniqueIdents.length === 2 ? {
|
|
7836
|
+
type: "LogicalExpression",
|
|
7837
|
+
operator: "&&",
|
|
7838
|
+
left: makeIsNumberExpr(uniqueIdents[0]),
|
|
7839
|
+
right: makeIsNumberExpr(uniqueIdents[1])
|
|
7840
|
+
} : makeIsNumberExpr(uniqueIdents[0]);
|
|
7841
|
+
const replacement = {
|
|
7842
|
+
type: "ConditionalExpression",
|
|
7843
|
+
test: testExpr,
|
|
7844
|
+
consequent,
|
|
7845
|
+
alternate,
|
|
7846
|
+
_unpeekGuardSubtree: true
|
|
7847
|
+
};
|
|
7848
|
+
if (hotExemptNodes) {
|
|
7849
|
+
hotExemptNodes.add(replacement);
|
|
7850
|
+
hotExemptNodes.add(testExpr);
|
|
7851
|
+
for (const nodeToExempt of exemptNodes) {
|
|
7852
|
+
hotExemptNodes.add(nodeToExempt);
|
|
7853
|
+
}
|
|
7854
|
+
}
|
|
7855
|
+
return replacement;
|
|
7856
|
+
}
|
|
7857
|
+
function applyColdBitwiseMba(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes, guardSubtreeNodes) {
|
|
7858
|
+
const { unsafe, scopeBindings } = analyzeBitwiseMbaScopes(ast);
|
|
7859
|
+
if (unsafe) return 0;
|
|
7860
|
+
let mbaCount = 0;
|
|
7861
|
+
const scopeStack = [];
|
|
7862
|
+
function walkTransform(node, setInParent, inColdFn) {
|
|
7863
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) return;
|
|
7864
|
+
if (!node || typeof node !== "object" || typeof node.type !== "string") return;
|
|
7865
|
+
if (hotExemptNodes?.has(node) || guardSubtreeNodes?.has(node)) return;
|
|
7866
|
+
if (node._unpeekGuardSubtree === true) return;
|
|
7867
|
+
if (node._unpeekSerialized || node._unpeekVirtualized === true) return;
|
|
7868
|
+
if (BITWISE_LOOP_NODE_TYPES.has(node.type)) return;
|
|
7869
|
+
const pushedScope = scopeBindings.has(node);
|
|
7870
|
+
if (pushedScope) scopeStack.push(node);
|
|
7871
|
+
try {
|
|
7872
|
+
const childInColdFn = BITWISE_FUNCTION_TYPES.has(node.type) ? coldFunctionNodes.has(node) : inColdFn;
|
|
7873
|
+
if (childInColdFn && node.type === "BinaryExpression" && BITWISE_MBA_OPS.has(node.operator)) {
|
|
7874
|
+
const op = node.operator;
|
|
7875
|
+
const { left, right } = node;
|
|
7876
|
+
const isCoercionOrZero = op === "|" && isZeroNumericLiteral(right);
|
|
7877
|
+
if (!isCoercionOrZero) {
|
|
7878
|
+
const leftAtomic = isSafeAtomicIntegerLiteral(left) || isLocalBoundIdentifier(left, scopeStack, scopeBindings, ast);
|
|
7879
|
+
const rightAtomic = isSafeAtomicIntegerLiteral(right) || isLocalBoundIdentifier(right, scopeStack, scopeBindings, ast);
|
|
7880
|
+
const hasIdent = left?.type === "Identifier" || right?.type === "Identifier";
|
|
7881
|
+
if (leftAtomic && rightAtomic && hasIdent) {
|
|
7882
|
+
const replacement = buildColdBitwiseConditional(
|
|
7883
|
+
op,
|
|
7884
|
+
left,
|
|
7885
|
+
right,
|
|
7886
|
+
seed,
|
|
7887
|
+
mbaCount,
|
|
7888
|
+
hotExemptNodes
|
|
7889
|
+
);
|
|
7890
|
+
mbaCount++;
|
|
7891
|
+
setInParent(replacement);
|
|
7892
|
+
return;
|
|
7893
|
+
}
|
|
7894
|
+
}
|
|
7895
|
+
}
|
|
7896
|
+
for (const key of Object.keys(node)) {
|
|
7897
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) break;
|
|
7898
|
+
if (key === "loc" || key === "range" || key === "start" || key === "end" || key === "comments" || key === "tokens") {
|
|
7899
|
+
continue;
|
|
7900
|
+
}
|
|
7901
|
+
const child = node[key];
|
|
7902
|
+
if (Array.isArray(child)) {
|
|
7903
|
+
for (let i = 0; i < child.length; i++) {
|
|
7904
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) break;
|
|
7905
|
+
const item = child[i];
|
|
7906
|
+
if (item && typeof item === "object" && typeof item.type === "string") {
|
|
7907
|
+
walkTransform(
|
|
7908
|
+
item,
|
|
7909
|
+
(rep) => {
|
|
7910
|
+
child[i] = rep;
|
|
7911
|
+
},
|
|
7912
|
+
childInColdFn
|
|
7913
|
+
);
|
|
7914
|
+
}
|
|
7915
|
+
}
|
|
7916
|
+
} else if (child && typeof child === "object" && typeof child.type === "string") {
|
|
7917
|
+
walkTransform(
|
|
7918
|
+
child,
|
|
7919
|
+
(rep) => {
|
|
7920
|
+
node[key] = rep;
|
|
7921
|
+
},
|
|
7922
|
+
childInColdFn
|
|
7923
|
+
);
|
|
7924
|
+
}
|
|
7925
|
+
}
|
|
7926
|
+
} finally {
|
|
7927
|
+
if (pushedScope) scopeStack.pop();
|
|
7928
|
+
}
|
|
7929
|
+
}
|
|
7930
|
+
walkTransform(ast, () => {
|
|
7931
|
+
}, false);
|
|
7932
|
+
return mbaCount;
|
|
7933
|
+
}
|
|
7934
|
+
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes, windowKeySymbol, expectedDelta, shieldCoupled = false, options) {
|
|
6917
7935
|
const sfx = (seed >>> 0).toString(36).slice(0, 4);
|
|
6918
7936
|
const decoyIdent = `_uDec${sfx}`;
|
|
6919
7937
|
const sboxIdent = `_uSb${sfx}`;
|
|
@@ -6929,6 +7947,9 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
6929
7947
|
);
|
|
6930
7948
|
if (alreadyGuarded) return 0;
|
|
6931
7949
|
}
|
|
7950
|
+
if (options?.enableBitwiseMba) {
|
|
7951
|
+
applyColdBitwiseMba(ast, coldFunctionNodes, seed, hotExemptNodes);
|
|
7952
|
+
}
|
|
6932
7953
|
let guardedCount = 0;
|
|
6933
7954
|
function maybeInjectGuard(node) {
|
|
6934
7955
|
if (guardedCount >= MAX_COLD_GUARDS_PER_CHUNK) return;
|
|
@@ -6963,6 +7984,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
6963
7984
|
}
|
|
6964
7985
|
);
|
|
6965
7986
|
guardedCount++;
|
|
7987
|
+
guardStmt._unpeekGuardSubtree = true;
|
|
6966
7988
|
if (hotExemptNodes) {
|
|
6967
7989
|
hotExemptNodes.add(guardStmt);
|
|
6968
7990
|
hotExemptNodes.add(guardStmt.consequent);
|
|
@@ -9268,7 +10290,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
9268
10290
|
hotExemptNodes,
|
|
9269
10291
|
sym,
|
|
9270
10292
|
shieldDelta,
|
|
9271
|
-
shieldCoupled
|
|
10293
|
+
shieldCoupled,
|
|
10294
|
+
{ enableBitwiseMba: isAggressive || effectiveProfile === "strict" }
|
|
9272
10295
|
);
|
|
9273
10296
|
}
|
|
9274
10297
|
const mangledSymbolsCount = applyPolymorphicMangler(
|
|
@@ -9378,5 +10401,7 @@ export {
|
|
|
9378
10401
|
deriveWindowKeySymbol,
|
|
9379
10402
|
createDeterrentSnippet,
|
|
9380
10403
|
generateRuntimeShield,
|
|
10404
|
+
classifyPlaintextSecret,
|
|
10405
|
+
hasRegexSecretRun,
|
|
9381
10406
|
transformJavaScript
|
|
9382
10407
|
};
|