unpeek 4.1.0 → 4.3.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 +5 -5
- package/dist/adapters/esbuild.js +3 -3
- package/dist/adapters/next/adapter.cjs +5 -5
- package/dist/adapters/next/adapter.js +4 -4
- package/dist/adapters/next/index.cjs +5 -5
- package/dist/adapters/next/index.js +4 -4
- package/dist/adapters/rollup.cjs +5 -5
- package/dist/adapters/rollup.js +3 -3
- package/dist/adapters/rspack.cjs +5 -5
- package/dist/adapters/rspack.js +3 -3
- package/dist/adapters/vite.cjs +5 -5
- package/dist/adapters/vite.js +3 -3
- package/dist/adapters/webpack.cjs +5 -5
- package/dist/adapters/webpack.js +3 -3
- 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-Q4DFRMAV.cjs → chunk-4IRIMLT3.cjs} +16 -16
- package/dist/{chunk-AD6UFBPA.cjs → chunk-4XSFPX2Z.cjs} +367 -8
- package/dist/{chunk-WYW5UOBE.cjs → chunk-7F75S3GQ.cjs} +60 -36
- package/dist/{chunk-HV47WJIR.js → chunk-EASD7C2B.js} +3 -3
- package/dist/{chunk-STTUFUDC.js → chunk-GKWTP4Z5.js} +30 -6
- package/dist/{chunk-VLL4THTG.cjs → chunk-OR5M3SN2.cjs} +2432 -636
- package/dist/{chunk-32GLSJAW.js → chunk-RDP4MTHK.js} +359 -0
- package/dist/{chunk-6KLUNEKE.js → chunk-RM3V7KJA.js} +2298 -502
- package/dist/{chunk-FLZ4FSP5.cjs → chunk-SBRU7GSX.cjs} +8 -8
- package/dist/{chunk-TOUYQ4N5.js → chunk-XEYMZUP5.js} +2 -2
- package/dist/cli/index.js +2781 -469
- package/dist/index.cjs +169 -29
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +151 -11
- package/dist/plugins/unplugin.cjs +4 -4
- package/dist/plugins/unplugin.js +3 -3
- 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
|
@@ -2815,8 +2815,119 @@ var compactGenerator = Object.assign({}, _astring.baseGenerator, {
|
|
|
2815
2815
|
this[node.options.type](node.options, state);
|
|
2816
2816
|
}
|
|
2817
2817
|
state.write(")");
|
|
2818
|
+
},
|
|
2819
|
+
ImportSpecifier(node, state) {
|
|
2820
|
+
writeModuleBindingName(this, node.imported, state);
|
|
2821
|
+
const sameIdent = _optionalChain([node, 'access', _239 => _239.imported, 'optionalAccess', _240 => _240.type]) === "Identifier" && _optionalChain([node, 'access', _241 => _241.local, 'optionalAccess', _242 => _242.type]) === "Identifier" && node.imported.name === node.local.name;
|
|
2822
|
+
if (!sameIdent && _optionalChain([node, 'access', _243 => _243.local, 'optionalAccess', _244 => _244.name])) {
|
|
2823
|
+
state.write(" as " + node.local.name);
|
|
2824
|
+
}
|
|
2825
|
+
},
|
|
2826
|
+
ExportSpecifier(node, state) {
|
|
2827
|
+
writeModuleBindingName(this, node.local, state);
|
|
2828
|
+
const sameIdent = _optionalChain([node, 'access', _245 => _245.local, 'optionalAccess', _246 => _246.type]) === "Identifier" && _optionalChain([node, 'access', _247 => _247.exported, 'optionalAccess', _248 => _248.type]) === "Identifier" && node.local.name === node.exported.name;
|
|
2829
|
+
if (!sameIdent && node.exported) {
|
|
2830
|
+
state.write(" as ");
|
|
2831
|
+
writeModuleBindingName(this, node.exported, state);
|
|
2832
|
+
}
|
|
2833
|
+
},
|
|
2834
|
+
ImportDeclaration(node, state) {
|
|
2835
|
+
state.write("import ");
|
|
2836
|
+
const specifiers = node.specifiers || [];
|
|
2837
|
+
const len = specifiers.length;
|
|
2838
|
+
let i = 0;
|
|
2839
|
+
if (len > 0) {
|
|
2840
|
+
while (i < len) {
|
|
2841
|
+
if (i > 0) state.write(", ");
|
|
2842
|
+
const spec = specifiers[i];
|
|
2843
|
+
const tag = spec.type[6];
|
|
2844
|
+
if (tag === "D") {
|
|
2845
|
+
state.write(spec.local.name, spec);
|
|
2846
|
+
i++;
|
|
2847
|
+
} else if (tag === "N") {
|
|
2848
|
+
state.write("* as " + spec.local.name, spec);
|
|
2849
|
+
i++;
|
|
2850
|
+
} else {
|
|
2851
|
+
break;
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
if (i < len) {
|
|
2855
|
+
state.write("{");
|
|
2856
|
+
for (; ; ) {
|
|
2857
|
+
this.ImportSpecifier(specifiers[i], state);
|
|
2858
|
+
if (++i < len) {
|
|
2859
|
+
state.write(", ");
|
|
2860
|
+
} else {
|
|
2861
|
+
break;
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
state.write("}");
|
|
2865
|
+
}
|
|
2866
|
+
state.write(" from ");
|
|
2867
|
+
}
|
|
2868
|
+
this.Literal(node.source, state);
|
|
2869
|
+
writeImportAttributes(this, node.attributes, state);
|
|
2870
|
+
state.write(";");
|
|
2871
|
+
},
|
|
2872
|
+
ExportNamedDeclaration(node, state) {
|
|
2873
|
+
state.write("export ");
|
|
2874
|
+
if (node.declaration) {
|
|
2875
|
+
this[node.declaration.type](node.declaration, state);
|
|
2876
|
+
return;
|
|
2877
|
+
}
|
|
2878
|
+
state.write("{");
|
|
2879
|
+
const specifiers = node.specifiers || [];
|
|
2880
|
+
const len = specifiers.length;
|
|
2881
|
+
if (len > 0) {
|
|
2882
|
+
for (let i = 0; ; ) {
|
|
2883
|
+
this.ExportSpecifier(specifiers[i], state);
|
|
2884
|
+
if (++i < len) {
|
|
2885
|
+
state.write(", ");
|
|
2886
|
+
} else {
|
|
2887
|
+
break;
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
state.write("}");
|
|
2892
|
+
if (node.source) {
|
|
2893
|
+
state.write(" from ");
|
|
2894
|
+
this.Literal(node.source, state);
|
|
2895
|
+
}
|
|
2896
|
+
writeImportAttributes(this, node.attributes, state);
|
|
2897
|
+
state.write(";");
|
|
2898
|
+
},
|
|
2899
|
+
ExportAllDeclaration(node, state) {
|
|
2900
|
+
if (node.exported == null) {
|
|
2901
|
+
state.write("export * from ");
|
|
2902
|
+
} else {
|
|
2903
|
+
state.write("export * as ");
|
|
2904
|
+
writeModuleBindingName(this, node.exported, state);
|
|
2905
|
+
state.write(" from ");
|
|
2906
|
+
}
|
|
2907
|
+
this.Literal(node.source, state);
|
|
2908
|
+
writeImportAttributes(this, node.attributes, state);
|
|
2909
|
+
state.write(";");
|
|
2818
2910
|
}
|
|
2819
2911
|
});
|
|
2912
|
+
function writeModuleBindingName(generator, node, state) {
|
|
2913
|
+
if (!node) return;
|
|
2914
|
+
if (node.type === "Literal") {
|
|
2915
|
+
generator.Literal(node, state);
|
|
2916
|
+
} else {
|
|
2917
|
+
state.write(node.name, node);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
function writeImportAttributes(generator, attributes, state) {
|
|
2921
|
+
if (!attributes || attributes.length === 0) return;
|
|
2922
|
+
state.write(" with { ");
|
|
2923
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
2924
|
+
generator.ImportAttribute(attributes[i], state);
|
|
2925
|
+
if (i < attributes.length - 1) {
|
|
2926
|
+
state.write(", ");
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
state.write(" }");
|
|
2930
|
+
}
|
|
2820
2931
|
var VLQ_BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
2821
2932
|
function encodeVlq2(value) {
|
|
2822
2933
|
let vlq = value < 0 ? (-value << 1) + 1 : value << 1;
|
|
@@ -2956,7 +3067,7 @@ function createDeterrentSnippet(config) {
|
|
|
2956
3067
|
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=()=>0;" : "";
|
|
2957
3068
|
const symLit = JSON.stringify(sym);
|
|
2958
3069
|
const headlessDecl = detectHeadless ? ",n=w.navigator||0" : "";
|
|
2959
|
-
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)" : "";
|
|
3070
|
+
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)||['__playwright','__puppeteer_evaluation_script__','__nightmare','frida','_frida_'].some(k=>w[k]||G[k])" : "";
|
|
2960
3071
|
const k1Mul = (seed | 1) >>> 0;
|
|
2961
3072
|
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
3073
|
}
|
|
@@ -3061,7 +3172,88 @@ function deriveWasmHostParams(seed) {
|
|
|
3061
3172
|
const pcMask = computeFnv1aHash("wasm-pcmask", seed) | 1 | 0;
|
|
3062
3173
|
return { gArr, sOff, rA0, rA1, rA2, rA3, gMask, pcMask };
|
|
3063
3174
|
}
|
|
3064
|
-
|
|
3175
|
+
var ABI_START_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
|
3176
|
+
var ABI_CONT_CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
|
3177
|
+
var FORBIDDEN_ABI_NAMES = /* @__PURE__ */ new Set([
|
|
3178
|
+
"env",
|
|
3179
|
+
"g",
|
|
3180
|
+
"m",
|
|
3181
|
+
"kdf",
|
|
3182
|
+
"bulkmix",
|
|
3183
|
+
"mem",
|
|
3184
|
+
"as",
|
|
3185
|
+
"do",
|
|
3186
|
+
"if",
|
|
3187
|
+
"in",
|
|
3188
|
+
"of",
|
|
3189
|
+
"for",
|
|
3190
|
+
"int",
|
|
3191
|
+
"let",
|
|
3192
|
+
"new",
|
|
3193
|
+
"try",
|
|
3194
|
+
"var",
|
|
3195
|
+
"nan",
|
|
3196
|
+
"map",
|
|
3197
|
+
"set",
|
|
3198
|
+
"url",
|
|
3199
|
+
"top",
|
|
3200
|
+
"get",
|
|
3201
|
+
"set"
|
|
3202
|
+
]);
|
|
3203
|
+
function avalancheMix32(h) {
|
|
3204
|
+
let x = h >>> 0;
|
|
3205
|
+
x = Math.imul(x ^ x >>> 16, 2246822507) >>> 0;
|
|
3206
|
+
x = Math.imul(x ^ x >>> 13, 3266489909) >>> 0;
|
|
3207
|
+
return (x ^ x >>> 16) >>> 0;
|
|
3208
|
+
}
|
|
3209
|
+
function encodeWasmName(name) {
|
|
3210
|
+
const utf8 = new TextEncoder().encode(name);
|
|
3211
|
+
return [...encodeUnsignedLeb128(utf8.length), ...utf8];
|
|
3212
|
+
}
|
|
3213
|
+
function deriveWasmAbiNames(seed) {
|
|
3214
|
+
const s = seed >>> 0;
|
|
3215
|
+
const used = new Set(FORBIDDEN_ABI_NAMES);
|
|
3216
|
+
const pickName = (role) => {
|
|
3217
|
+
for (let attempt = 0; attempt < 64; attempt++) {
|
|
3218
|
+
const h = avalancheMix32(computeFnv1aHash(`wasm-abi:${role}:${attempt}`, s));
|
|
3219
|
+
const len = h >>> 18 & 1 ? 3 : 2;
|
|
3220
|
+
const c0 = ABI_START_CHARS[h % ABI_START_CHARS.length];
|
|
3221
|
+
const c1 = ABI_CONT_CHARS[(h >>> 6) % ABI_CONT_CHARS.length];
|
|
3222
|
+
const c2 = len === 3 ? ABI_CONT_CHARS[(h >>> 12) % ABI_CONT_CHARS.length] : "";
|
|
3223
|
+
const candidate = `${c0}${c1}${c2}`;
|
|
3224
|
+
const lower = candidate.toLowerCase();
|
|
3225
|
+
if (!candidate.startsWith("__") && !used.has(lower)) {
|
|
3226
|
+
used.add(lower);
|
|
3227
|
+
return candidate;
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
const fallback = `w${s.toString(36).slice(0, 2).padStart(2, "0")}`;
|
|
3231
|
+
used.add(fallback.toLowerCase());
|
|
3232
|
+
return fallback;
|
|
3233
|
+
};
|
|
3234
|
+
const envMod = pickName("envMod");
|
|
3235
|
+
const gImport = pickName("gImport");
|
|
3236
|
+
const mImport = pickName("mImport");
|
|
3237
|
+
const kdfExport = pickName("kdfExport");
|
|
3238
|
+
const bulkMixExport = pickName("bulkMixExport");
|
|
3239
|
+
const memExport = pickName("memExport");
|
|
3240
|
+
const exportOrder = [0, 1, 2];
|
|
3241
|
+
const orderHash = avalancheMix32(computeFnv1aHash("wasm-abi:order", s));
|
|
3242
|
+
const j2 = orderHash % 3;
|
|
3243
|
+
[exportOrder[2], exportOrder[j2]] = [exportOrder[j2], exportOrder[2]];
|
|
3244
|
+
const j1 = (orderHash >>> 8) % 2;
|
|
3245
|
+
[exportOrder[1], exportOrder[j1]] = [exportOrder[j1], exportOrder[1]];
|
|
3246
|
+
return {
|
|
3247
|
+
envMod,
|
|
3248
|
+
gImport,
|
|
3249
|
+
mImport,
|
|
3250
|
+
kdfExport,
|
|
3251
|
+
bulkMixExport,
|
|
3252
|
+
memExport,
|
|
3253
|
+
exportOrder
|
|
3254
|
+
};
|
|
3255
|
+
}
|
|
3256
|
+
function generateWasmKdfBinary(seed, options) {
|
|
3065
3257
|
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
3066
3258
|
const { gMask, pcMask } = deriveWasmHostParams(seed);
|
|
3067
3259
|
const memBase = (seed >>> 0 & 127) * 4;
|
|
@@ -3587,27 +3779,23 @@ function generateWasmKdfBinary(seed) {
|
|
|
3587
3779
|
...encodeUnsignedLeb128(typePayload.length),
|
|
3588
3780
|
...typePayload
|
|
3589
3781
|
];
|
|
3782
|
+
const abi = _optionalChain([options, 'optionalAccess', _249 => _249.polymorphicAbi]) ? deriveWasmAbiNames(seed) : null;
|
|
3783
|
+
const envModName = abi ? abi.envMod : "env";
|
|
3784
|
+
const gImportName = abi ? abi.gImport : "g";
|
|
3785
|
+
const mImportName = abi ? abi.mImport : "m";
|
|
3590
3786
|
const importPayload = [
|
|
3591
3787
|
2,
|
|
3592
3788
|
// 2 imports
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
110,
|
|
3596
|
-
118,
|
|
3597
|
-
1,
|
|
3598
|
-
103,
|
|
3789
|
+
...encodeWasmName(envModName),
|
|
3790
|
+
...encodeWasmName(gImportName),
|
|
3599
3791
|
0,
|
|
3600
3792
|
0,
|
|
3601
|
-
//
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
110,
|
|
3605
|
-
118,
|
|
3606
|
-
1,
|
|
3607
|
-
109,
|
|
3793
|
+
// g: func type 0
|
|
3794
|
+
...encodeWasmName(envModName),
|
|
3795
|
+
...encodeWasmName(mImportName),
|
|
3608
3796
|
0,
|
|
3609
3797
|
1
|
|
3610
|
-
//
|
|
3798
|
+
// m: func type 1
|
|
3611
3799
|
];
|
|
3612
3800
|
const importSection = [
|
|
3613
3801
|
2,
|
|
@@ -3621,35 +3809,21 @@ function generateWasmKdfBinary(seed) {
|
|
|
3621
3809
|
...funcPayload
|
|
3622
3810
|
];
|
|
3623
3811
|
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
|
|
3812
|
+
const exportSpecs = abi ? [
|
|
3813
|
+
[abi.kdfExport, 0, 2],
|
|
3814
|
+
[abi.bulkMixExport, 0, 3],
|
|
3815
|
+
[abi.memExport, 2, 0]
|
|
3816
|
+
] : [
|
|
3817
|
+
["kdf", 0, 2],
|
|
3818
|
+
["bulkMix", 0, 3],
|
|
3819
|
+
["mem", 2, 0]
|
|
3652
3820
|
];
|
|
3821
|
+
const exportOrder = abi ? abi.exportOrder : [0, 1, 2];
|
|
3822
|
+
const exportPayload = [3];
|
|
3823
|
+
for (const idx of exportOrder) {
|
|
3824
|
+
const [name, kind, targetIdx] = exportSpecs[idx];
|
|
3825
|
+
exportPayload.push(...encodeWasmName(name), kind, targetIdx);
|
|
3826
|
+
}
|
|
3653
3827
|
const exportSection = [
|
|
3654
3828
|
7,
|
|
3655
3829
|
...encodeUnsignedLeb128(exportPayload.length),
|
|
@@ -3726,8 +3900,8 @@ function fallbackKdf(fnId, callSiteSalt, shieldHash, seed) {
|
|
|
3726
3900
|
function isWasmVaultAlreadyInjected(ast) {
|
|
3727
3901
|
if (!ast || !Array.isArray(ast.body)) return false;
|
|
3728
3902
|
return ast.body.some((stmt) => {
|
|
3729
|
-
if (stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access',
|
|
3730
|
-
(d) => _optionalChain([d, 'access',
|
|
3903
|
+
if (stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access', _250 => _250.declarations, 'optionalAccess', _251 => _251.some, 'call', _252 => _252(
|
|
3904
|
+
(d) => _optionalChain([d, 'access', _253 => _253.id, 'optionalAccess', _254 => _254.type]) === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
3731
3905
|
)])) {
|
|
3732
3906
|
return true;
|
|
3733
3907
|
}
|
|
@@ -3740,19 +3914,20 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
3740
3914
|
const wasmVarName = `_wb${suffix}`;
|
|
3741
3915
|
if (isWasmVaultAlreadyInjected(ast)) {
|
|
3742
3916
|
const existing = ast.body.find(
|
|
3743
|
-
(stmt) => stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access',
|
|
3744
|
-
(d) => _optionalChain([d, 'access',
|
|
3917
|
+
(stmt) => stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access', _255 => _255.declarations, 'optionalAccess', _256 => _256.some, 'call', _257 => _257(
|
|
3918
|
+
(d) => _optionalChain([d, 'access', _258 => _258.id, 'optionalAccess', _259 => _259.type]) === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
|
|
3745
3919
|
)])
|
|
3746
3920
|
);
|
|
3747
|
-
const id = _nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
3921
|
+
const id = _nullishCoalesce(_optionalChain([existing, 'optionalAccess', _260 => _260.declarations, 'access', _261 => _261[0], 'optionalAccess', _262 => _262.id, 'optionalAccess', _263 => _263.name]), () => ( kdfFnName));
|
|
3748
3922
|
return {
|
|
3749
3923
|
kdfFnName: id,
|
|
3750
|
-
wasmBytes: generateWasmKdfBinary(seed),
|
|
3924
|
+
wasmBytes: generateWasmKdfBinary(seed, { polymorphicAbi: true }),
|
|
3751
3925
|
wasmVarName,
|
|
3752
3926
|
kdfParityVerified: true
|
|
3753
3927
|
};
|
|
3754
3928
|
}
|
|
3755
|
-
const
|
|
3929
|
+
const abi = deriveWasmAbiNames(seed);
|
|
3930
|
+
const wasmBytes = generateWasmKdfBinary(seed, { polymorphicAbi: true });
|
|
3756
3931
|
const byteArrayLiteral = Array.from(wasmBytes).join(",");
|
|
3757
3932
|
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
3758
3933
|
const { gArr, sOff, rA0, rA1, rA2, rA3, gMask, pcMask } = deriveWasmHostParams(seed);
|
|
@@ -3764,7 +3939,8 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
3764
3939
|
const mChars = [105 ^ strKey, 109 ^ strKey, 117 ^ strKey, 108 ^ strKey].join(",");
|
|
3765
3940
|
const helperSnippet = `var ${kdfFnName};
|
|
3766
3941
|
(function(){
|
|
3767
|
-
var _G = typeof globalThis < 'u' ? globalThis : typeof self < 'u' ? self : 0;
|
|
3942
|
+
var _G = typeof globalThis < 'u' ? globalThis : typeof self < 'u' ? self : typeof window < 'u' ? window : 0;
|
|
3943
|
+
var _M = (_G && _G.Math) || Math;
|
|
3768
3944
|
var _reg = _G ? (_G.__unpeek_wasm_kdf || (_G.__unpeek_wasm_kdf = {})) : 0;
|
|
3769
3945
|
if (_reg && _reg['${suffix}']) {
|
|
3770
3946
|
${kdfFnName} = _reg['${suffix}'];
|
|
@@ -3772,10 +3948,10 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
3772
3948
|
}
|
|
3773
3949
|
var _g = [${gArr.join(",")}];
|
|
3774
3950
|
var _evR = function(x) {
|
|
3775
|
-
return (${rA0} +
|
|
3951
|
+
return (${rA0} + _M.imul(x, (${rA1} + _M.imul(x, (${rA2} + _M.imul(${rA3}, x)) | 0)) | 0)) | 0;
|
|
3776
3952
|
};
|
|
3777
3953
|
var _sb = function(b) {
|
|
3778
|
-
return (
|
|
3954
|
+
return (_M.imul(167, b & 255) + ${sOff}) & 255;
|
|
3779
3955
|
};
|
|
3780
3956
|
var _tk = ['__','unp','eek_t','ampered'].join('');
|
|
3781
3957
|
var _eG = function(sl) {
|
|
@@ -3789,8 +3965,8 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
3789
3965
|
try {
|
|
3790
3966
|
var ${wasmVarName} = new Uint8Array([${byteArrayLiteral}]);
|
|
3791
3967
|
var _wm${suffix} = new WebAssembly.Module(${wasmVarName});
|
|
3792
|
-
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix}, {
|
|
3793
|
-
${kdfFnName} = _wi${suffix}.exports.
|
|
3968
|
+
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix}, { ${abi.envMod}: { ${abi.gImport}: _eG, ${abi.mImport}: _eM } });
|
|
3969
|
+
${kdfFnName} = _wi${suffix}.exports[${JSON.stringify(abi.kdfExport)}];
|
|
3794
3970
|
} catch (e) {
|
|
3795
3971
|
var _kx = [${rivEncodedTargets.join(",")}];
|
|
3796
3972
|
var _k = [];
|
|
@@ -3802,7 +3978,7 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
3802
3978
|
for (var _i = 0; _i < _c.length; _i++) {
|
|
3803
3979
|
_p += String.fromCharCode(_c[_i] ^ ${strKey});
|
|
3804
3980
|
}
|
|
3805
|
-
var _m =
|
|
3981
|
+
var _m = _M[_p];
|
|
3806
3982
|
${kdfFnName} = function(f, s, h) {
|
|
3807
3983
|
var _x = (f ^ _k[2] ^ _k[3] ^ (_eG(0) ^ ${gMask})) | 0;
|
|
3808
3984
|
_x = (_x ^ (_x >>> 16)) | 0;
|
|
@@ -3827,7 +4003,7 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
3827
4003
|
let insertIdx = 0;
|
|
3828
4004
|
while (insertIdx < ast.body.length) {
|
|
3829
4005
|
const stmt = ast.body[insertIdx];
|
|
3830
|
-
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || _optionalChain([stmt, 'access',
|
|
4006
|
+
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || _optionalChain([stmt, 'access', _264 => _264.expression, 'optionalAccess', _265 => _265.type]) === "Literal" && typeof stmt.expression.value === "string" && /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim()));
|
|
3831
4007
|
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
3832
4008
|
insertIdx++;
|
|
3833
4009
|
} else {
|
|
@@ -3858,7 +4034,7 @@ function isWebpackModuleMap(node) {
|
|
|
3858
4034
|
return false;
|
|
3859
4035
|
}
|
|
3860
4036
|
return node.properties.some(
|
|
3861
|
-
(p) => _optionalChain([p, 'optionalAccess',
|
|
4037
|
+
(p) => _optionalChain([p, 'optionalAccess', _266 => _266.type]) === "Property" && (_optionalChain([p, 'access', _267 => _267.value, 'optionalAccess', _268 => _268.type]) === "FunctionExpression" || _optionalChain([p, 'access', _269 => _269.value, 'optionalAccess', _270 => _270.type]) === "ArrowFunctionExpression")
|
|
3862
4038
|
);
|
|
3863
4039
|
}
|
|
3864
4040
|
function exemptWebpackPushArg(arg, exemptSubtreeRoots) {
|
|
@@ -3878,9 +4054,9 @@ function exemptWebpackPushArg(arg, exemptSubtreeRoots) {
|
|
|
3878
4054
|
exemptSubtreeRoots.add(arg);
|
|
3879
4055
|
}
|
|
3880
4056
|
function exemptTurbopackPropertyKeys(objNode, exemptSubtreeRoots) {
|
|
3881
|
-
if (!Array.isArray(_optionalChain([objNode, 'optionalAccess',
|
|
4057
|
+
if (!Array.isArray(_optionalChain([objNode, 'optionalAccess', _271 => _271.properties]))) return;
|
|
3882
4058
|
for (const prop of objNode.properties) {
|
|
3883
|
-
if (_optionalChain([prop, 'optionalAccess',
|
|
4059
|
+
if (_optionalChain([prop, 'optionalAccess', _272 => _272.type]) === "Property" && prop.key && typeof prop.key === "object") {
|
|
3884
4060
|
exemptSubtreeRoots.add(prop.key);
|
|
3885
4061
|
}
|
|
3886
4062
|
}
|
|
@@ -3919,11 +4095,11 @@ function isHostMember(node, matcher) {
|
|
|
3919
4095
|
if (node.type === "Identifier" && matchesPropName(node.name, matcher)) {
|
|
3920
4096
|
return true;
|
|
3921
4097
|
}
|
|
3922
|
-
if (node.type === "MemberExpression" && (_optionalChain([node, 'access',
|
|
3923
|
-
if (!node.computed && _optionalChain([node, 'access',
|
|
4098
|
+
if (node.type === "MemberExpression" && (_optionalChain([node, 'access', _273 => _273.object, 'optionalAccess', _274 => _274.type]) === "Identifier" && GLOBAL_HOSTS.has(node.object.name) || _optionalChain([node, 'access', _275 => _275.object, 'optionalAccess', _276 => _276.type]) === "ThisExpression")) {
|
|
4099
|
+
if (!node.computed && _optionalChain([node, 'access', _277 => _277.property, 'optionalAccess', _278 => _278.type]) === "Identifier") {
|
|
3924
4100
|
return matchesPropName(node.property.name, matcher);
|
|
3925
4101
|
}
|
|
3926
|
-
if (node.computed && _optionalChain([node, 'access',
|
|
4102
|
+
if (node.computed && _optionalChain([node, 'access', _279 => _279.property, 'optionalAccess', _280 => _280.type]) === "Literal" && typeof node.property.value === "string") {
|
|
3927
4103
|
return matchesPropName(node.property.value, matcher);
|
|
3928
4104
|
}
|
|
3929
4105
|
}
|
|
@@ -3949,6 +4125,61 @@ function unwrapAssignedHostMember(node, matcher, depth = 0) {
|
|
|
3949
4125
|
return false;
|
|
3950
4126
|
}
|
|
3951
4127
|
}
|
|
4128
|
+
function isImportMetaMember(node, propName) {
|
|
4129
|
+
if (!node || node.type !== "MemberExpression") return false;
|
|
4130
|
+
const obj = node.object;
|
|
4131
|
+
if (_optionalChain([obj, 'optionalAccess', _281 => _281.type]) !== "MetaProperty" || _optionalChain([obj, 'access', _282 => _282.meta, 'optionalAccess', _283 => _283.type]) !== "Identifier" || obj.meta.name !== "import" || _optionalChain([obj, 'access', _284 => _284.property, 'optionalAccess', _285 => _285.type]) !== "Identifier" || obj.property.name !== "meta") {
|
|
4132
|
+
return false;
|
|
4133
|
+
}
|
|
4134
|
+
if (!node.computed && _optionalChain([node, 'access', _286 => _286.property, 'optionalAccess', _287 => _287.type]) === "Identifier") {
|
|
4135
|
+
return node.property.name === propName;
|
|
4136
|
+
}
|
|
4137
|
+
return node.computed && _optionalChain([node, 'access', _288 => _288.property, 'optionalAccess', _289 => _289.type]) === "Literal" && node.property.value === propName;
|
|
4138
|
+
}
|
|
4139
|
+
function isRequireResolveCallee(callee) {
|
|
4140
|
+
if (!callee || callee.type !== "MemberExpression") return false;
|
|
4141
|
+
if (_optionalChain([callee, 'access', _290 => _290.object, 'optionalAccess', _291 => _291.type]) !== "Identifier" || callee.object.name !== "require") {
|
|
4142
|
+
return false;
|
|
4143
|
+
}
|
|
4144
|
+
if (!callee.computed && _optionalChain([callee, 'access', _292 => _292.property, 'optionalAccess', _293 => _293.type]) === "Identifier") {
|
|
4145
|
+
return callee.property.name === "resolve";
|
|
4146
|
+
}
|
|
4147
|
+
return callee.computed && _optionalChain([callee, 'access', _294 => _294.property, 'optionalAccess', _295 => _295.type]) === "Literal" && callee.property.value === "resolve";
|
|
4148
|
+
}
|
|
4149
|
+
function isStaticModuleOrAssetPosition(node, parent) {
|
|
4150
|
+
if (!node || !parent) return false;
|
|
4151
|
+
if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration") {
|
|
4152
|
+
return parent.source === node;
|
|
4153
|
+
}
|
|
4154
|
+
if (parent.type === "ExportAllDeclaration") {
|
|
4155
|
+
return parent.source === node || parent.exported === node;
|
|
4156
|
+
}
|
|
4157
|
+
if (parent.type === "ImportExpression") {
|
|
4158
|
+
return parent.source === node;
|
|
4159
|
+
}
|
|
4160
|
+
if (parent.type === "ImportSpecifier") {
|
|
4161
|
+
return parent.imported === node;
|
|
4162
|
+
}
|
|
4163
|
+
if (parent.type === "ExportSpecifier") {
|
|
4164
|
+
return parent.local === node || parent.exported === node;
|
|
4165
|
+
}
|
|
4166
|
+
if (parent.type === "ImportAttribute") {
|
|
4167
|
+
return true;
|
|
4168
|
+
}
|
|
4169
|
+
if (parent.type === "NewExpression") {
|
|
4170
|
+
return _optionalChain([parent, 'access', _296 => _296.callee, 'optionalAccess', _297 => _297.type]) === "Identifier" && parent.callee.name === "URL" && Array.isArray(parent.arguments) && parent.arguments.length >= 2 && parent.arguments[0] === node && isImportMetaMember(parent.arguments[1], "url");
|
|
4171
|
+
}
|
|
4172
|
+
if (parent.type === "CallExpression") {
|
|
4173
|
+
if (!Array.isArray(parent.arguments) || parent.arguments[0] !== node) {
|
|
4174
|
+
return false;
|
|
4175
|
+
}
|
|
4176
|
+
const callee = parent.callee;
|
|
4177
|
+
if (isImportMetaMember(callee, "resolve")) return true;
|
|
4178
|
+
if (isRequireResolveCallee(callee)) return true;
|
|
4179
|
+
if (_optionalChain([callee, 'optionalAccess', _298 => _298.type]) === "Identifier" && callee.name === "require") return true;
|
|
4180
|
+
}
|
|
4181
|
+
return false;
|
|
4182
|
+
}
|
|
3952
4183
|
function classifyChunkBoundary(ast) {
|
|
3953
4184
|
const exemptSubtreeRoots = /* @__PURE__ */ new WeakSet();
|
|
3954
4185
|
const importSourceNodes = /* @__PURE__ */ new WeakSet();
|
|
@@ -3958,8 +4189,12 @@ function classifyChunkBoundary(ast) {
|
|
|
3958
4189
|
let hasPreloadManifest = false;
|
|
3959
4190
|
walk2.simple(ast, {
|
|
3960
4191
|
CallExpression(node) {
|
|
4192
|
+
const firstArg = Array.isArray(node.arguments) ? node.arguments[0] : void 0;
|
|
4193
|
+
if (firstArg && (firstArg.type === "Literal" || firstArg.type === "TemplateLiteral") && isStaticModuleOrAssetPosition(firstArg, node)) {
|
|
4194
|
+
exemptSubtreeRoots.add(firstArg);
|
|
4195
|
+
}
|
|
3961
4196
|
const callee = node.callee;
|
|
3962
|
-
const isPushCall = _optionalChain([callee, 'optionalAccess',
|
|
4197
|
+
const isPushCall = _optionalChain([callee, 'optionalAccess', _299 => _299.type]) === "MemberExpression" && (!callee.computed && _optionalChain([callee, 'access', _300 => _300.property, 'optionalAccess', _301 => _301.type]) === "Identifier" && callee.property.name === "push" || callee.computed && _optionalChain([callee, 'access', _302 => _302.property, 'optionalAccess', _303 => _303.type]) === "Literal" && callee.property.value === "push");
|
|
3963
4198
|
if (isPushCall) {
|
|
3964
4199
|
if (unwrapAssignedHostMember(callee.object, "__next_f")) {
|
|
3965
4200
|
hasRscFlight = true;
|
|
@@ -3999,13 +4234,13 @@ function classifyChunkBoundary(ast) {
|
|
|
3999
4234
|
if (isHostMember(node.left, "TURBOPACK") || isHostMember(node.left, isWebpackOrRspackChunkName)) {
|
|
4000
4235
|
hasEntryBootstrap = true;
|
|
4001
4236
|
exemptSubtreeRoots.add(node);
|
|
4002
|
-
} else if (_optionalChain([node, 'access',
|
|
4237
|
+
} else if (_optionalChain([node, 'access', _304 => _304.left, 'optionalAccess', _305 => _305.type]) === "Identifier" && node.left.name === "__vite__mapDeps") {
|
|
4003
4238
|
hasPreloadManifest = true;
|
|
4004
4239
|
exemptSubtreeRoots.add(node);
|
|
4005
4240
|
}
|
|
4006
4241
|
},
|
|
4007
4242
|
VariableDeclarator(node) {
|
|
4008
|
-
if (_optionalChain([node, 'access',
|
|
4243
|
+
if (_optionalChain([node, 'access', _306 => _306.id, 'optionalAccess', _307 => _307.type]) === "Identifier") {
|
|
4009
4244
|
if (node.id.name === "__vite__mapDeps") {
|
|
4010
4245
|
hasPreloadManifest = true;
|
|
4011
4246
|
exemptSubtreeRoots.add(node);
|
|
@@ -4016,11 +4251,54 @@ function classifyChunkBoundary(ast) {
|
|
|
4016
4251
|
}
|
|
4017
4252
|
},
|
|
4018
4253
|
FunctionDeclaration(node) {
|
|
4019
|
-
if (_optionalChain([node, 'access',
|
|
4254
|
+
if (_optionalChain([node, 'access', _308 => _308.id, 'optionalAccess', _309 => _309.type]) === "Identifier" && node.id.name === "__vite__mapDeps") {
|
|
4020
4255
|
hasPreloadManifest = true;
|
|
4021
4256
|
exemptSubtreeRoots.add(node);
|
|
4022
4257
|
}
|
|
4023
4258
|
},
|
|
4259
|
+
NewExpression(node) {
|
|
4260
|
+
const firstArg = Array.isArray(node.arguments) ? node.arguments[0] : void 0;
|
|
4261
|
+
if (firstArg && (firstArg.type === "Literal" || firstArg.type === "TemplateLiteral") && isStaticModuleOrAssetPosition(firstArg, node)) {
|
|
4262
|
+
exemptSubtreeRoots.add(firstArg);
|
|
4263
|
+
}
|
|
4264
|
+
},
|
|
4265
|
+
ImportDeclaration(node) {
|
|
4266
|
+
if (node.source && typeof node.source === "object") {
|
|
4267
|
+
exemptSubtreeRoots.add(node.source);
|
|
4268
|
+
}
|
|
4269
|
+
if (Array.isArray(node.specifiers)) {
|
|
4270
|
+
for (const spec of node.specifiers) {
|
|
4271
|
+
if (_optionalChain([spec, 'optionalAccess', _310 => _310.type]) === "ImportSpecifier" && _optionalChain([spec, 'access', _311 => _311.imported, 'optionalAccess', _312 => _312.type]) === "Literal") {
|
|
4272
|
+
exemptSubtreeRoots.add(spec.imported);
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
},
|
|
4277
|
+
ExportNamedDeclaration(node) {
|
|
4278
|
+
if (node.source && typeof node.source === "object") {
|
|
4279
|
+
exemptSubtreeRoots.add(node.source);
|
|
4280
|
+
}
|
|
4281
|
+
if (Array.isArray(node.specifiers)) {
|
|
4282
|
+
for (const spec of node.specifiers) {
|
|
4283
|
+
if (_optionalChain([spec, 'optionalAccess', _313 => _313.type]) === "ExportSpecifier") {
|
|
4284
|
+
if (_optionalChain([spec, 'access', _314 => _314.local, 'optionalAccess', _315 => _315.type]) === "Literal") {
|
|
4285
|
+
exemptSubtreeRoots.add(spec.local);
|
|
4286
|
+
}
|
|
4287
|
+
if (_optionalChain([spec, 'access', _316 => _316.exported, 'optionalAccess', _317 => _317.type]) === "Literal") {
|
|
4288
|
+
exemptSubtreeRoots.add(spec.exported);
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
},
|
|
4294
|
+
ExportAllDeclaration(node) {
|
|
4295
|
+
if (node.source && typeof node.source === "object") {
|
|
4296
|
+
exemptSubtreeRoots.add(node.source);
|
|
4297
|
+
}
|
|
4298
|
+
if (node.exported && typeof node.exported === "object") {
|
|
4299
|
+
exemptSubtreeRoots.add(node.exported);
|
|
4300
|
+
}
|
|
4301
|
+
},
|
|
4024
4302
|
ImportExpression(node) {
|
|
4025
4303
|
importExpressions.push(node);
|
|
4026
4304
|
if (node.source && typeof node.source === "object") {
|
|
@@ -4058,7 +4336,7 @@ function attachMagicComments(importExpressions, comments) {
|
|
|
4058
4336
|
const magicComments = comments.filter((c) => MAGIC_COMMENT_RE.test(c.value));
|
|
4059
4337
|
if (magicComments.length === 0) return;
|
|
4060
4338
|
for (const expr of importExpressions) {
|
|
4061
|
-
const src = _optionalChain([expr, 'optionalAccess',
|
|
4339
|
+
const src = _optionalChain([expr, 'optionalAccess', _318 => _318.source]);
|
|
4062
4340
|
if (!src || typeof expr.start !== "number" || typeof src.start !== "number") {
|
|
4063
4341
|
continue;
|
|
4064
4342
|
}
|
|
@@ -4090,22 +4368,36 @@ function buildRivestDeltaExpr(seed, expectedDelta, varName = "_ed") {
|
|
|
4090
4368
|
const xMasked = xEnc ^ xMask | 0;
|
|
4091
4369
|
return `var _rx=(${xMasked}^${xMask | 0})|0,${varName}=(${rA0}+Math.imul(_rx,(${rA1}+Math.imul(_rx,(${rA2}+Math.imul(${rA3},_rx))|0))|0))&65535;`;
|
|
4092
4370
|
}
|
|
4093
|
-
function
|
|
4371
|
+
function buildLatchInitSnippet(seed, latchCoupling) {
|
|
4372
|
+
if (!latchCoupling || typeof latchCoupling.latchFnName !== "string" || !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(latchCoupling.latchFnName)) {
|
|
4373
|
+
return { hasLatch: false, latchDecl: "" };
|
|
4374
|
+
}
|
|
4375
|
+
const tamperByte = seed >>> 8 & 127 | 53;
|
|
4376
|
+
const expectedLatch = latchCoupling.expectedLatchByte & 255;
|
|
4377
|
+
return {
|
|
4378
|
+
hasLatch: true,
|
|
4379
|
+
latchDecl: `var _ld=typeof ${latchCoupling.latchFnName}==="function"?((${latchCoupling.latchFnName}()^${expectedLatch})&255):${tamperByte};`
|
|
4380
|
+
};
|
|
4381
|
+
}
|
|
4382
|
+
function createSaltedDecryptorFnAst(seed, pChars, expectedDelta, windowKeySymbol, safeAlpha = SAFE_ALPHA, shieldCoupled = true, _browserOnly = false, latchCoupling) {
|
|
4094
4383
|
const propAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(windowKeySymbol) ? `.${windowKeySymbol}` : `[${JSON.stringify(windowKeySymbol)}]`;
|
|
4095
4384
|
const stateSym = `${windowKeySymbol}_s`;
|
|
4096
4385
|
const stateAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(stateSym) ? `.${stateSym}` : `[${JSON.stringify(stateSym)}]`;
|
|
4097
4386
|
const flagSym = `${windowKeySymbol}_t`;
|
|
4098
4387
|
const flagAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(flagSym) ? `.${flagSym}` : `[${JSON.stringify(flagSym)}]`;
|
|
4099
4388
|
const tkExpr = `['__','unp','eek_t','ampered'].join('')`;
|
|
4389
|
+
const { hasLatch, latchDecl } = buildLatchInitSnippet(seed, latchCoupling);
|
|
4390
|
+
const charEmit = hasLatch ? `o+=String.fromCharCode((k<0?ch:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92]).charCodeAt(0)^_ld);` : `o+=k<0?ch:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];`;
|
|
4391
|
+
const cacheGuardSuffix = hasLatch ? "&&!_ld" : "";
|
|
4100
4392
|
let fBody;
|
|
4101
4393
|
if (!shieldCoupled) {
|
|
4102
|
-
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}";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;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||((""._u||a._u||0)!==0);if(!tm&&(i in m))return m[i]
|
|
4394
|
+
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}";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;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||((""._u||a._u||0)!==0);if(!tm&&(i in m))return m[i];` + latchDecl + `var d=tm?(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1):0;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);` + charEmit + `}if(!tm${cacheGuardSuffix})m[i]=o;return o;};`;
|
|
4103
4395
|
} else {
|
|
4104
4396
|
const edInit = buildRivestDeltaExpr(seed, expectedDelta, "_ed");
|
|
4105
4397
|
const hasWindowKey = Boolean(windowKeySymbol);
|
|
4106
4398
|
const brDecl = hasWindowKey ? NARROWED_ASYNC_BR_DECL : "";
|
|
4107
4399
|
const svCheck = hasWindowKey ? `(sv===void 0?!_br:sv!==_ed)` : `(sv!==void 0&&sv!==_ed)`;
|
|
4108
|
-
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]
|
|
4400
|
+
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];` + latchDecl + `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);` + charEmit + `}if(!tm&&sv===_ed${cacheGuardSuffix})m[i]=o;return o;};`;
|
|
4109
4401
|
}
|
|
4110
4402
|
return acorn3.parse(`(function f(a){${fBody}})`, {
|
|
4111
4403
|
ecmaVersion: "latest",
|
|
@@ -4153,8 +4445,8 @@ function encodeSaltedString(str, k) {
|
|
|
4153
4445
|
function isAstAlreadySalted(ast) {
|
|
4154
4446
|
if (!ast || !Array.isArray(ast.body)) return false;
|
|
4155
4447
|
return ast.body.some((stmt) => {
|
|
4156
|
-
if (stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access',
|
|
4157
|
-
(d) => _optionalChain([d, 'access',
|
|
4448
|
+
if (stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access', _319 => _319.declarations, 'optionalAccess', _320 => _320.some, 'call', _321 => _321(
|
|
4449
|
+
(d) => _optionalChain([d, 'access', _322 => _322.id, 'optionalAccess', _323 => _323.type]) === "Identifier" && typeof d.id.name === "string" && (d.id.name.startsWith("_uP") || _optionalChain([d, 'access', _324 => _324.init, 'optionalAccess', _325 => _325.type]) === "CallExpression" && _optionalChain([d, 'access', _326 => _326.init, 'access', _327 => _327.callee, 'optionalAccess', _328 => _328.type]) === "FunctionExpression" && _optionalChain([d, 'access', _329 => _329.init, 'access', _330 => _330.callee, 'optionalAccess', _331 => _331.id, 'optionalAccess', _332 => _332.name]) === "f" && _optionalChain([d, 'access', _333 => _333.init, 'access', _334 => _334.arguments, 'optionalAccess', _335 => _335[0], 'optionalAccess', _336 => _336.type]) === "ArrayExpression")
|
|
4158
4450
|
)])) {
|
|
4159
4451
|
return true;
|
|
4160
4452
|
}
|
|
@@ -4179,7 +4471,7 @@ function replaceNodeInParent(parent, oldNode, newNode) {
|
|
|
4179
4471
|
}
|
|
4180
4472
|
return false;
|
|
4181
4473
|
}
|
|
4182
|
-
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, config, windowKeySymbol, expectedDelta, deterrentMode, shieldCoupled = true, detectHeadless = false, exemptSubtreeRoots) {
|
|
4474
|
+
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, config, windowKeySymbol, expectedDelta, deterrentMode, shieldCoupled = true, detectHeadless = false, exemptSubtreeRoots, latchCoupling) {
|
|
4183
4475
|
if (isAstAlreadySalted(ast)) {
|
|
4184
4476
|
return {
|
|
4185
4477
|
encryptedStringsCount: 0,
|
|
@@ -4189,29 +4481,52 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4189
4481
|
shaderBuffersCount: 0
|
|
4190
4482
|
};
|
|
4191
4483
|
}
|
|
4192
|
-
const minLen = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4484
|
+
const minLen = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _337 => _337.vault, 'optionalAccess', _338 => _338.minStringLength]), () => ( minStringLength));
|
|
4193
4485
|
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
4194
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
4486
|
+
if (_optionalChain([config, 'optionalAccess', _339 => _339.vault, 'optionalAccess', _340 => _340.customDirectives])) {
|
|
4195
4487
|
for (const dir of config.vault.customDirectives) {
|
|
4196
4488
|
activeDirectives.add(dir);
|
|
4197
4489
|
}
|
|
4198
4490
|
}
|
|
4199
|
-
const customReserved = _optionalChain([config, 'optionalAccess',
|
|
4491
|
+
const customReserved = _optionalChain([config, 'optionalAccess', _341 => _341.vault, 'optionalAccess', _342 => _342.reservedProps]) ? new Set(config.vault.reservedProps) : void 0;
|
|
4200
4492
|
const targetsToReplace = [];
|
|
4201
4493
|
const encryptedPayloads = [];
|
|
4202
4494
|
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
4203
4495
|
const shaderPayloads = [];
|
|
4204
4496
|
const shaderTargets = [];
|
|
4205
|
-
|
|
4497
|
+
const interpolatedTemplates = [];
|
|
4498
|
+
let regExpShadowedScopes;
|
|
4499
|
+
const getRegExpShadowedScopes = () => {
|
|
4500
|
+
regExpShadowedScopes ??= collectIdentifierShadowedScopes(ast, "RegExp");
|
|
4501
|
+
return regExpShadowedScopes;
|
|
4502
|
+
};
|
|
4503
|
+
function pushSaltedTarget(rawString, node, parent, extra) {
|
|
4504
|
+
const callSiteIdx = targetsToReplace.length;
|
|
4505
|
+
const [saltLo, saltHi] = computeCallSiteSalt64(
|
|
4506
|
+
seed >>> 0,
|
|
4507
|
+
callSiteIdx >>> 0,
|
|
4508
|
+
seed >>> 0
|
|
4509
|
+
);
|
|
4510
|
+
const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
|
|
4511
|
+
targetsToReplace.push({
|
|
4512
|
+
node,
|
|
4513
|
+
parent,
|
|
4514
|
+
callSiteIdx,
|
|
4515
|
+
localSalt,
|
|
4516
|
+
rawString,
|
|
4517
|
+
...extra
|
|
4518
|
+
});
|
|
4519
|
+
}
|
|
4520
|
+
function processSaltedCandidate(val, node, parent, ancestors, onReplace) {
|
|
4206
4521
|
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
4207
|
-
return;
|
|
4522
|
+
return false;
|
|
4208
4523
|
}
|
|
4209
4524
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
4210
|
-
return;
|
|
4525
|
+
return false;
|
|
4211
4526
|
}
|
|
4212
4527
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
4213
4528
|
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
4214
|
-
return;
|
|
4529
|
+
return false;
|
|
4215
4530
|
}
|
|
4216
4531
|
}
|
|
4217
4532
|
let isHotExempt = false;
|
|
@@ -4238,11 +4553,11 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4238
4553
|
shaderToIndex.set(val, idx);
|
|
4239
4554
|
shaderPayloads.push(val);
|
|
4240
4555
|
}
|
|
4241
|
-
shaderTargets.push({ node, parent, idx });
|
|
4242
|
-
return;
|
|
4556
|
+
shaderTargets.push({ node, parent, idx, ...onReplace ? { onReplace } : {} });
|
|
4557
|
+
return true;
|
|
4243
4558
|
}
|
|
4244
4559
|
if (isHotExempt) {
|
|
4245
|
-
return;
|
|
4560
|
+
return false;
|
|
4246
4561
|
}
|
|
4247
4562
|
if (!shouldEncryptString(
|
|
4248
4563
|
val,
|
|
@@ -4251,60 +4566,94 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4251
4566
|
activeDirectives,
|
|
4252
4567
|
customReserved
|
|
4253
4568
|
)) {
|
|
4254
|
-
return;
|
|
4569
|
+
return false;
|
|
4255
4570
|
}
|
|
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
|
-
});
|
|
4571
|
+
pushSaltedTarget(val, node, parent, onReplace ? { onReplace } : void 0);
|
|
4572
|
+
return true;
|
|
4270
4573
|
}
|
|
4271
|
-
walk3.ancestor(
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4574
|
+
walk3.ancestor(
|
|
4575
|
+
ast,
|
|
4576
|
+
{
|
|
4577
|
+
Literal(node, _state, ancestors) {
|
|
4578
|
+
if (node.regex) {
|
|
4579
|
+
if (isEligibleSecretRegExp(
|
|
4580
|
+
node,
|
|
4581
|
+
ancestors,
|
|
4582
|
+
hotExemptNodes,
|
|
4583
|
+
exemptSubtreeRoots,
|
|
4584
|
+
getRegExpShadowedScopes
|
|
4585
|
+
)) {
|
|
4586
|
+
pushSaltedTarget(
|
|
4587
|
+
node.regex.pattern,
|
|
4588
|
+
node,
|
|
4589
|
+
ancestors[ancestors.length - 2],
|
|
4590
|
+
{
|
|
4591
|
+
replaceMode: "regexp",
|
|
4592
|
+
flags: _nullishCoalesce(node.regex.flags, () => ( ""))
|
|
4593
|
+
}
|
|
4594
|
+
);
|
|
4595
|
+
}
|
|
4596
|
+
return;
|
|
4597
|
+
}
|
|
4598
|
+
if (typeof node.value !== "string") return;
|
|
4599
|
+
const val = node.value;
|
|
4600
|
+
if (activeDirectives.has(val)) return;
|
|
4601
|
+
const parent = ancestors[ancestors.length - 2];
|
|
4602
|
+
if (!parent) return;
|
|
4603
|
+
if (isStaticModuleOrAssetPosition(node, parent)) {
|
|
4604
|
+
return;
|
|
4605
|
+
}
|
|
4606
|
+
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
4607
|
+
if (!isEligibleObjectPropertyKey(val, node, parent, ancestors)) {
|
|
4608
|
+
return;
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
4612
|
+
return;
|
|
4613
|
+
}
|
|
4614
|
+
processSaltedCandidate(val, node, parent, ancestors);
|
|
4615
|
+
},
|
|
4616
|
+
TemplateLiteral(node, _state, ancestors) {
|
|
4617
|
+
if (!Array.isArray(node.quasis) || node.quasis.length === 0) return;
|
|
4618
|
+
const parent = ancestors[ancestors.length - 2];
|
|
4619
|
+
if (isExemptTemplateLiteral(node, parent)) return;
|
|
4620
|
+
const exprCount = Array.isArray(node.expressions) ? node.expressions.length : 0;
|
|
4621
|
+
if (exprCount === 0) {
|
|
4622
|
+
if (node.quasis.length !== 1) return;
|
|
4623
|
+
const val = _nullishCoalesce(node.quasis[0].value.cooked, () => ( node.quasis[0].value.raw));
|
|
4624
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
4625
|
+
processSaltedCandidate(val, node, parent, ancestors);
|
|
4626
|
+
return;
|
|
4627
|
+
}
|
|
4628
|
+
if (node.quasis.length !== exprCount + 1) return;
|
|
4629
|
+
if (node.quasis.some((q) => typeof _optionalChain([q, 'optionalAccess', _343 => _343.value, 'optionalAccess', _344 => _344.cooked]) !== "string")) {
|
|
4630
|
+
return;
|
|
4631
|
+
}
|
|
4632
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
4633
|
+
let queuedCount = 0;
|
|
4634
|
+
for (let qIdx = 0; qIdx < node.quasis.length; qIdx++) {
|
|
4635
|
+
const val = node.quasis[qIdx].value.cooked;
|
|
4636
|
+
if (activeDirectives.has(val)) continue;
|
|
4637
|
+
const queued = processSaltedCandidate(
|
|
4638
|
+
val,
|
|
4639
|
+
node,
|
|
4640
|
+
parent,
|
|
4641
|
+
ancestors,
|
|
4642
|
+
(exprAst) => {
|
|
4643
|
+
replacements.set(qIdx, exprAst);
|
|
4644
|
+
}
|
|
4645
|
+
);
|
|
4646
|
+
if (queued) {
|
|
4647
|
+
queuedCount++;
|
|
4648
|
+
}
|
|
4649
|
+
}
|
|
4650
|
+
if (queuedCount > 0) {
|
|
4651
|
+
interpolatedTemplates.push({ node, replacements });
|
|
4652
|
+
}
|
|
4289
4653
|
}
|
|
4290
|
-
processSaltedCandidate(val, node, parent, ancestors);
|
|
4291
4654
|
},
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
if (node.expressions && node.expressions.length !== 0) return;
|
|
4295
|
-
const val = _nullishCoalesce(node.quasis[0].value.cooked, () => ( node.quasis[0].value.raw));
|
|
4296
|
-
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
4297
|
-
const parent = ancestors[ancestors.length - 2];
|
|
4298
|
-
if (!parent) return;
|
|
4299
|
-
if (parent.type === "TaggedTemplateExpression" && parent.quasi === node) {
|
|
4300
|
-
return;
|
|
4301
|
-
}
|
|
4302
|
-
if (parent.type === "ImportExpression" && parent.source === node) {
|
|
4303
|
-
return;
|
|
4304
|
-
}
|
|
4305
|
-
processSaltedCandidate(val, node, parent, ancestors);
|
|
4306
|
-
}
|
|
4307
|
-
});
|
|
4655
|
+
VAULT_WALK_BASE
|
|
4656
|
+
);
|
|
4308
4657
|
if (targetsToReplace.length === 0 && shaderTargets.length === 0) {
|
|
4309
4658
|
return {
|
|
4310
4659
|
encryptedStringsCount: 0,
|
|
@@ -4343,15 +4692,18 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4343
4692
|
const flagAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(flagSym) ? `.${flagSym}` : `[${JSON.stringify(flagSym)}]`;
|
|
4344
4693
|
const tkExpr = `['__','unp','eek_t','ampered'].join('')`;
|
|
4345
4694
|
const dkExpr = `['__','unp','eek_d','elta'].join('')`;
|
|
4695
|
+
const { hasLatch, latchDecl } = buildLatchInitSnippet(seed, latchCoupling);
|
|
4696
|
+
const charMaskXor = hasLatch ? "^_ld" : "";
|
|
4697
|
+
const cacheGuardSuffix = hasLatch ? "&&!_ld" : "";
|
|
4346
4698
|
let helperFnSnippet;
|
|
4347
4699
|
if (!shieldCoupled) {
|
|
4348
|
-
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};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))||((""._u||0)!==0)||(dv!==0);if(!tm&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i]
|
|
4700
|
+
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};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))||((""._u||0)!==0)||(dv!==0);if(!tm&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];` + latchDecl + `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;}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)${charMaskXor});}if(!tm${cacheGuardSuffix})${cacheVarName}[i]=o;return o;}`;
|
|
4349
4701
|
} else {
|
|
4350
4702
|
const edInit = buildRivestDeltaExpr(seed, (_nullishCoalesce(expDelta, () => ( 0))) & 65535, "_ed");
|
|
4351
4703
|
const hasWindowKey = Boolean(sym);
|
|
4352
4704
|
const brDecl = hasWindowKey ? NARROWED_ASYNC_BR_DECL : "";
|
|
4353
4705
|
const svCheck = hasWindowKey ? `(sv===void 0?!_br:sv!==_ed)` : `(sv!==void 0&&sv!==_ed)`;
|
|
4354
|
-
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]
|
|
4706
|
+
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];` + latchDecl + `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)${charMaskXor});}if(!tm&&sv===_ed${cacheGuardSuffix})${cacheVarName}[i]=o;return o;}`;
|
|
4355
4707
|
}
|
|
4356
4708
|
const parsedFn = acorn3.parse(helperFnSnippet, {
|
|
4357
4709
|
ecmaVersion: "latest",
|
|
@@ -4383,7 +4735,20 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4383
4735
|
],
|
|
4384
4736
|
optional: false
|
|
4385
4737
|
};
|
|
4386
|
-
|
|
4738
|
+
if (target.onReplace) {
|
|
4739
|
+
target.onReplace(callExpr);
|
|
4740
|
+
} else if (target.replaceMode === "regexp") {
|
|
4741
|
+
replaceNodeInParent(
|
|
4742
|
+
target.parent,
|
|
4743
|
+
target.node,
|
|
4744
|
+
createNewRegExpAst(callExpr, _nullishCoalesce(target.flags, () => ( "")))
|
|
4745
|
+
);
|
|
4746
|
+
} else {
|
|
4747
|
+
if (_optionalChain([target, 'access', _345 => _345.parent, 'optionalAccess', _346 => _346.type]) === "Property" && target.parent.key === target.node) {
|
|
4748
|
+
target.parent.computed = true;
|
|
4749
|
+
}
|
|
4750
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
4751
|
+
}
|
|
4387
4752
|
}
|
|
4388
4753
|
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
4389
4754
|
integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
@@ -4413,7 +4778,11 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4413
4778
|
],
|
|
4414
4779
|
optional: false
|
|
4415
4780
|
};
|
|
4416
|
-
|
|
4781
|
+
if (target.onReplace) {
|
|
4782
|
+
target.onReplace(callExpr);
|
|
4783
|
+
} else {
|
|
4784
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
4785
|
+
}
|
|
4417
4786
|
}
|
|
4418
4787
|
const shaderHelperStmt = createShaderVaultAst(
|
|
4419
4788
|
shaderVarName,
|
|
@@ -4429,6 +4798,7 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4429
4798
|
integrityToken = computeFnv1aHash(JSON.stringify(shaderPayloads), seed);
|
|
4430
4799
|
}
|
|
4431
4800
|
}
|
|
4801
|
+
rebuildInterpolatedTemplates(interpolatedTemplates);
|
|
4432
4802
|
return {
|
|
4433
4803
|
encryptedStringsCount: targetsToReplace.length,
|
|
4434
4804
|
integrityToken,
|
|
@@ -4438,6 +4808,133 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
4438
4808
|
};
|
|
4439
4809
|
}
|
|
4440
4810
|
|
|
4811
|
+
// src/ast/secret-patterns.ts
|
|
4812
|
+
var PEM_HEADER_RE = /-----BEGIN\s+[A-Z0-9 ]+-----/;
|
|
4813
|
+
var PEM_REGEX_HEADER_RE = /-----BEGIN(?:\s|\\s[+*?]?)+(?:[A-Z0-9 ]|\\s[+*?]?)+-----/;
|
|
4814
|
+
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,})/;
|
|
4815
|
+
var ESCAPED_FLAG_REGEX_RE = /\bFLAG\\\{[^}]{4,}\\\}/;
|
|
4816
|
+
var HEX_RE = /^[0-9a-fA-F]+$/;
|
|
4817
|
+
var BASE64_RE = /^[A-Za-z0-9+/]+=*$/;
|
|
4818
|
+
var TOKEN_CHARSET_RE = /^[A-Za-z0-9_\-+/=.~:@!#$%^&*]+$/;
|
|
4819
|
+
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;
|
|
4820
|
+
var REGEX_CHAR_CLASS_RE = /\[(?:\\[\s\S]|[^\]\\])*\]/g;
|
|
4821
|
+
var REGEX_META_SPLIT_RE = /\(\?(?:<[=!]|<[^>]+>|[:=!])?|\\[\s\S]|[\s^$.*+?()[\]{}|/]+/;
|
|
4822
|
+
var COMMON_BIGRAMS = new Set(
|
|
4823
|
+
"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(" ")
|
|
4824
|
+
);
|
|
4825
|
+
var COMMON_BIGRAM_CHANCE = COMMON_BIGRAMS.size / 676;
|
|
4826
|
+
var NATURAL_TEXT_Z = 3.5;
|
|
4827
|
+
function isAsciiLetter(code) {
|
|
4828
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
4829
|
+
}
|
|
4830
|
+
function isBinaryOrWasmPrefix(value) {
|
|
4831
|
+
return value.startsWith("AGFzbQE") || /^data:/i.test(value);
|
|
4832
|
+
}
|
|
4833
|
+
function countBase64MarkerRatio(value) {
|
|
4834
|
+
let hits = 0;
|
|
4835
|
+
for (let i = 0; i < value.length; i++) {
|
|
4836
|
+
const code = value.charCodeAt(i);
|
|
4837
|
+
if (code >= 48 && code <= 57 || // 0-9
|
|
4838
|
+
code === 43 || // +
|
|
4839
|
+
code === 47 || // /
|
|
4840
|
+
code === 61) {
|
|
4841
|
+
hits += 1;
|
|
4842
|
+
}
|
|
4843
|
+
}
|
|
4844
|
+
return hits / value.length;
|
|
4845
|
+
}
|
|
4846
|
+
function shannonEntropy(value) {
|
|
4847
|
+
if (value.length === 0) return 0;
|
|
4848
|
+
const counts = /* @__PURE__ */ new Map();
|
|
4849
|
+
for (let i = 0; i < value.length; i++) {
|
|
4850
|
+
const code = value.charCodeAt(i);
|
|
4851
|
+
counts.set(code, (_nullishCoalesce(counts.get(code), () => ( 0))) + 1);
|
|
4852
|
+
}
|
|
4853
|
+
let h = 0;
|
|
4854
|
+
for (const count of counts.values()) {
|
|
4855
|
+
const p = count / value.length;
|
|
4856
|
+
h -= p * Math.log2(p);
|
|
4857
|
+
}
|
|
4858
|
+
return h;
|
|
4859
|
+
}
|
|
4860
|
+
function isSequentialAlphabet(value) {
|
|
4861
|
+
if (value.length < 8) return false;
|
|
4862
|
+
let ascending = 0;
|
|
4863
|
+
for (let i = 1; i < value.length; i++) {
|
|
4864
|
+
if (value.charCodeAt(i) - value.charCodeAt(i - 1) === 1) {
|
|
4865
|
+
ascending += 1;
|
|
4866
|
+
}
|
|
4867
|
+
}
|
|
4868
|
+
return ascending / (value.length - 1) >= 0.6;
|
|
4869
|
+
}
|
|
4870
|
+
function looksLikeNaturalText(value) {
|
|
4871
|
+
let pairs = 0;
|
|
4872
|
+
let hits = 0;
|
|
4873
|
+
const lower = value.toLowerCase();
|
|
4874
|
+
for (let i = 1; i < value.length; i++) {
|
|
4875
|
+
const a = value.charCodeAt(i - 1);
|
|
4876
|
+
const b = value.charCodeAt(i);
|
|
4877
|
+
if (!isAsciiLetter(a) || !isAsciiLetter(b)) continue;
|
|
4878
|
+
pairs += 1;
|
|
4879
|
+
if (a >= 97 && b <= 90) continue;
|
|
4880
|
+
if (COMMON_BIGRAMS.has(lower[i - 1] + lower[i])) {
|
|
4881
|
+
hits += 1;
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
if (pairs < 4) return false;
|
|
4885
|
+
const expected = COMMON_BIGRAM_CHANCE * pairs;
|
|
4886
|
+
const deviation = Math.sqrt(
|
|
4887
|
+
pairs * COMMON_BIGRAM_CHANCE * (1 - COMMON_BIGRAM_CHANCE)
|
|
4888
|
+
);
|
|
4889
|
+
return (hits - expected) / deviation >= NATURAL_TEXT_Z;
|
|
4890
|
+
}
|
|
4891
|
+
function classifyPlaintextSecret(value) {
|
|
4892
|
+
if (typeof value !== "string" || value.length < 8) return null;
|
|
4893
|
+
if (isBinaryOrWasmPrefix(value)) return null;
|
|
4894
|
+
if (PATH_LIKE_RE.test(value)) return null;
|
|
4895
|
+
const entropy = shannonEntropy(value);
|
|
4896
|
+
if (PEM_HEADER_RE.test(value)) {
|
|
4897
|
+
return { category: "pem-header", entropy };
|
|
4898
|
+
}
|
|
4899
|
+
if (TOKEN_PREFIX_RE.test(value)) {
|
|
4900
|
+
return { category: "token-prefix", entropy };
|
|
4901
|
+
}
|
|
4902
|
+
if (isSequentialAlphabet(value)) {
|
|
4903
|
+
return null;
|
|
4904
|
+
}
|
|
4905
|
+
const isHex = value.length >= 24 && value.length % 2 === 0 && HEX_RE.test(value) && entropy >= 3.2;
|
|
4906
|
+
if (isHex) {
|
|
4907
|
+
return { category: "hex-or-base64", entropy };
|
|
4908
|
+
}
|
|
4909
|
+
const isBase64Like = value.length >= 28 && BASE64_RE.test(value) && countBase64MarkerRatio(value) >= 0.15 && !looksLikeNaturalText(value) && entropy >= 4;
|
|
4910
|
+
if (isBase64Like) {
|
|
4911
|
+
return { category: "hex-or-base64", entropy };
|
|
4912
|
+
}
|
|
4913
|
+
if (value.length >= 20 && value.length <= 512 && TOKEN_CHARSET_RE.test(value) && !looksLikeNaturalText(value) && entropy >= 4.1) {
|
|
4914
|
+
return { category: "high-entropy", entropy };
|
|
4915
|
+
}
|
|
4916
|
+
return null;
|
|
4917
|
+
}
|
|
4918
|
+
function isLikelySecretLiteral(value) {
|
|
4919
|
+
return classifyPlaintextSecret(value) !== null;
|
|
4920
|
+
}
|
|
4921
|
+
function hasRegexSecretRun(pattern) {
|
|
4922
|
+
if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 4096) {
|
|
4923
|
+
return false;
|
|
4924
|
+
}
|
|
4925
|
+
if (PEM_HEADER_RE.test(pattern) || PEM_REGEX_HEADER_RE.test(pattern) || TOKEN_PREFIX_RE.test(pattern) || ESCAPED_FLAG_REGEX_RE.test(pattern)) {
|
|
4926
|
+
return true;
|
|
4927
|
+
}
|
|
4928
|
+
const outsideClasses = pattern.replace(REGEX_CHAR_CLASS_RE, " ");
|
|
4929
|
+
const parts = outsideClasses.split(REGEX_META_SPLIT_RE);
|
|
4930
|
+
for (const part of parts) {
|
|
4931
|
+
if (part.length >= 20 && isLikelySecretLiteral(part)) {
|
|
4932
|
+
return true;
|
|
4933
|
+
}
|
|
4934
|
+
}
|
|
4935
|
+
return false;
|
|
4936
|
+
}
|
|
4937
|
+
|
|
4441
4938
|
// src/ast/string-vault.ts
|
|
4442
4939
|
var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
|
|
4443
4940
|
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
@@ -4494,7 +4991,7 @@ function isReactDomSpecialProp(val, node, parent, customReserved) {
|
|
|
4494
4991
|
if (parent.key === node && !parent.computed) {
|
|
4495
4992
|
return true;
|
|
4496
4993
|
}
|
|
4497
|
-
const keyName = _optionalChain([parent, 'access',
|
|
4994
|
+
const keyName = _optionalChain([parent, 'access', _347 => _347.key, 'optionalAccess', _348 => _348.type]) === "Identifier" ? parent.key.name : _optionalChain([parent, 'access', _349 => _349.key, 'optionalAccess', _350 => _350.type]) === "Literal" ? String(parent.key.value) : "";
|
|
4498
4995
|
if (keyName && isReservedProp(keyName, customReserved)) {
|
|
4499
4996
|
return true;
|
|
4500
4997
|
}
|
|
@@ -4557,11 +5054,11 @@ var DEFAULT_SEMANTIC_ANCHOR_RE = /(?:\bapi\/|\bcheckout\b|\badmin\b|\bauth\b|\bt
|
|
|
4557
5054
|
function isUiClassName(val, parent) {
|
|
4558
5055
|
if (parent) {
|
|
4559
5056
|
if (parent.type === "Property") {
|
|
4560
|
-
const k = _optionalChain([parent, 'access',
|
|
5057
|
+
const k = _optionalChain([parent, 'access', _351 => _351.key, 'optionalAccess', _352 => _352.type]) === "Identifier" ? parent.key.name : _optionalChain([parent, 'access', _353 => _353.key, 'optionalAccess', _354 => _354.type]) === "Literal" ? String(parent.key.value) : "";
|
|
4561
5058
|
if (k === "className" || k === "class" || k === "classList") return true;
|
|
4562
5059
|
}
|
|
4563
5060
|
if (parent.type === "JSXAttribute") {
|
|
4564
|
-
const name = _optionalChain([parent, 'access',
|
|
5061
|
+
const name = _optionalChain([parent, 'access', _355 => _355.name, 'optionalAccess', _356 => _356.name]);
|
|
4565
5062
|
if (name === "className" || name === "class") return true;
|
|
4566
5063
|
}
|
|
4567
5064
|
}
|
|
@@ -4622,13 +5119,10 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen, seed = 26544
|
|
|
4622
5119
|
return false;
|
|
4623
5120
|
}
|
|
4624
5121
|
if (parent) {
|
|
4625
|
-
if (
|
|
4626
|
-
if (parent.source === node) return false;
|
|
4627
|
-
}
|
|
4628
|
-
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
5122
|
+
if (isStaticModuleOrAssetPosition(node, parent)) {
|
|
4629
5123
|
return false;
|
|
4630
5124
|
}
|
|
4631
|
-
if (parent.type === "
|
|
5125
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
4632
5126
|
return false;
|
|
4633
5127
|
}
|
|
4634
5128
|
}
|
|
@@ -4657,7 +5151,7 @@ function isBinaryOrBase64Payload(val) {
|
|
|
4657
5151
|
function isShaderPayload(val, node, parent, ancestors, seed, isHotExempt, customReserved) {
|
|
4658
5152
|
if (isBinaryOrBase64Payload(val)) return false;
|
|
4659
5153
|
if (isInsideLoopOrSerialized(ancestors)) return false;
|
|
4660
|
-
if (_optionalChain([parent, 'optionalAccess',
|
|
5154
|
+
if (_optionalChain([parent, 'optionalAccess', _357 => _357.type]) === "Property" && parent.key === node && !parent.computed) return false;
|
|
4661
5155
|
if (isReservedProp(val, customReserved)) return false;
|
|
4662
5156
|
if (isTailwindNoise(val)) return false;
|
|
4663
5157
|
if (isSvgPathString(val, parent)) return false;
|
|
@@ -4674,7 +5168,7 @@ function findVaultInsertIndex(ast, activeDirectives = DIRECTIVE_STRINGS) {
|
|
|
4674
5168
|
let insertIdx = 0;
|
|
4675
5169
|
while (insertIdx < ast.body.length) {
|
|
4676
5170
|
const stmt = ast.body[insertIdx];
|
|
4677
|
-
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || _optionalChain([stmt, 'access',
|
|
5171
|
+
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || _optionalChain([stmt, 'access', _358 => _358.expression, 'optionalAccess', _359 => _359.type]) === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
|
|
4678
5172
|
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
4679
5173
|
insertIdx++;
|
|
4680
5174
|
} else {
|
|
@@ -4691,8 +5185,70 @@ function shouldEncryptString(val, minLen, parent, activeDirectives = DIRECTIVE_S
|
|
|
4691
5185
|
if (isTailwindNoise(val)) return false;
|
|
4692
5186
|
return true;
|
|
4693
5187
|
}
|
|
4694
|
-
|
|
4695
|
-
|
|
5188
|
+
var VAULT_WALK_BASE = {
|
|
5189
|
+
...walk4.base,
|
|
5190
|
+
Property(node, st, c) {
|
|
5191
|
+
c(node.key, st);
|
|
5192
|
+
if (node.value) c(node.value, st);
|
|
5193
|
+
}
|
|
5194
|
+
};
|
|
5195
|
+
function isCjsExportsTarget(lhs) {
|
|
5196
|
+
if (!lhs || typeof lhs !== "object") return false;
|
|
5197
|
+
if (lhs.type === "ParenthesizedExpression") {
|
|
5198
|
+
return isCjsExportsTarget(lhs.expression);
|
|
5199
|
+
}
|
|
5200
|
+
if (lhs.type === "Identifier") {
|
|
5201
|
+
return lhs.name === "exports";
|
|
5202
|
+
}
|
|
5203
|
+
if (lhs.type === "MemberExpression") {
|
|
5204
|
+
if (_optionalChain([lhs, 'access', _360 => _360.object, 'optionalAccess', _361 => _361.type]) === "Identifier" && lhs.object.name === "module" && (!lhs.computed && _optionalChain([lhs, 'access', _362 => _362.property, 'optionalAccess', _363 => _363.type]) === "Identifier" && lhs.property.name === "exports" || lhs.computed && _optionalChain([lhs, 'access', _364 => _364.property, 'optionalAccess', _365 => _365.type]) === "Literal" && lhs.property.value === "exports")) {
|
|
5205
|
+
return true;
|
|
5206
|
+
}
|
|
5207
|
+
return isCjsExportsTarget(lhs.object);
|
|
5208
|
+
}
|
|
5209
|
+
return false;
|
|
5210
|
+
}
|
|
5211
|
+
function isInsideCjsExportsObject(ancestors, objIdx) {
|
|
5212
|
+
if (objIdx < 1) return false;
|
|
5213
|
+
let cur = ancestors[objIdx];
|
|
5214
|
+
for (let i = objIdx - 1; i >= 0; i--) {
|
|
5215
|
+
const anc = ancestors[i];
|
|
5216
|
+
if (!anc) break;
|
|
5217
|
+
if (anc.type === "ParenthesizedExpression") {
|
|
5218
|
+
cur = anc;
|
|
5219
|
+
continue;
|
|
5220
|
+
}
|
|
5221
|
+
if (anc.type === "AssignmentExpression" && anc.right === cur) {
|
|
5222
|
+
if (isCjsExportsTarget(anc.left)) {
|
|
5223
|
+
return true;
|
|
5224
|
+
}
|
|
5225
|
+
cur = anc;
|
|
5226
|
+
continue;
|
|
5227
|
+
}
|
|
5228
|
+
if (anc.type === "CallExpression" && _optionalChain([anc, 'access', _366 => _366.callee, 'optionalAccess', _367 => _367.type]) === "MemberExpression" && !anc.callee.computed && _optionalChain([anc, 'access', _368 => _368.callee, 'access', _369 => _369.object, 'optionalAccess', _370 => _370.type]) === "Identifier" && anc.callee.object.name === "Object" && _optionalChain([anc, 'access', _371 => _371.callee, 'access', _372 => _372.property, 'optionalAccess', _373 => _373.type]) === "Identifier" && anc.callee.property.name === "assign" && Array.isArray(anc.arguments) && anc.arguments.slice(1).includes(cur) && isCjsExportsTarget(anc.arguments[0])) {
|
|
5229
|
+
return true;
|
|
5230
|
+
}
|
|
5231
|
+
break;
|
|
5232
|
+
}
|
|
5233
|
+
return false;
|
|
5234
|
+
}
|
|
5235
|
+
function isEligibleObjectPropertyKey(val, node, parent, ancestors) {
|
|
5236
|
+
if (!parent || parent.type !== "Property" || parent.key !== node || parent.computed) {
|
|
5237
|
+
return false;
|
|
5238
|
+
}
|
|
5239
|
+
if (val === "__proto__") return false;
|
|
5240
|
+
if (parent.kind !== "init" || parent.shorthand) return false;
|
|
5241
|
+
if (!isLikelySecretLiteral(val)) return false;
|
|
5242
|
+
const containerIdx = ancestors.length - 3;
|
|
5243
|
+
const container = containerIdx >= 0 ? ancestors[containerIdx] : void 0;
|
|
5244
|
+
if (!container || container.type === "ObjectPattern") return false;
|
|
5245
|
+
if (container.type === "ObjectExpression" && isInsideCjsExportsObject(ancestors, containerIdx)) {
|
|
5246
|
+
return false;
|
|
5247
|
+
}
|
|
5248
|
+
return true;
|
|
5249
|
+
}
|
|
5250
|
+
function createPermutationTable(seed) {
|
|
5251
|
+
let s = (seed || 305419896) >>> 0;
|
|
4696
5252
|
function xorshift() {
|
|
4697
5253
|
s ^= s << 13;
|
|
4698
5254
|
s ^= s >>> 17;
|
|
@@ -4825,25 +5381,241 @@ function findLowestCommonScope(ast, chains) {
|
|
|
4825
5381
|
}
|
|
4826
5382
|
return _nullishCoalesce(lca[lca.length - 1], () => ( ast));
|
|
4827
5383
|
}
|
|
4828
|
-
function
|
|
4829
|
-
|
|
5384
|
+
function isExemptTemplateLiteral(node, parent) {
|
|
5385
|
+
if (!parent) return true;
|
|
5386
|
+
if (parent.type === "TaggedTemplateExpression" && parent.quasi === node) {
|
|
5387
|
+
return true;
|
|
5388
|
+
}
|
|
5389
|
+
if (isStaticModuleOrAssetPosition(node, parent)) {
|
|
5390
|
+
return true;
|
|
5391
|
+
}
|
|
5392
|
+
return false;
|
|
5393
|
+
}
|
|
5394
|
+
function rebuildInterpolatedTemplates(plans) {
|
|
5395
|
+
for (const { node, replacements } of plans) {
|
|
5396
|
+
if (replacements.size === 0) continue;
|
|
5397
|
+
const origQuasis = node.quasis;
|
|
5398
|
+
const origExprs = node.expressions;
|
|
5399
|
+
const nextQuasis = [];
|
|
5400
|
+
const nextExprs = [];
|
|
5401
|
+
let pendingRaw = "";
|
|
5402
|
+
let pendingCooked = "";
|
|
5403
|
+
const flushQuasi = (tail) => {
|
|
5404
|
+
nextQuasis.push({
|
|
5405
|
+
type: "TemplateElement",
|
|
5406
|
+
value: { raw: pendingRaw, cooked: pendingCooked },
|
|
5407
|
+
tail
|
|
5408
|
+
});
|
|
5409
|
+
pendingRaw = "";
|
|
5410
|
+
pendingCooked = "";
|
|
5411
|
+
};
|
|
5412
|
+
for (let i = 0; i < origQuasis.length; i++) {
|
|
5413
|
+
const quasi = origQuasis[i];
|
|
5414
|
+
const replacement = replacements.get(i);
|
|
5415
|
+
if (replacement !== void 0) {
|
|
5416
|
+
flushQuasi(false);
|
|
5417
|
+
nextExprs.push(replacement);
|
|
5418
|
+
} else {
|
|
5419
|
+
pendingRaw += _nullishCoalesce(_optionalChain([quasi, 'access', _374 => _374.value, 'optionalAccess', _375 => _375.raw]), () => ( ""));
|
|
5420
|
+
pendingCooked += _nullishCoalesce(_optionalChain([quasi, 'access', _376 => _376.value, 'optionalAccess', _377 => _377.cooked]), () => ( ""));
|
|
5421
|
+
}
|
|
5422
|
+
if (i < origExprs.length) {
|
|
5423
|
+
flushQuasi(false);
|
|
5424
|
+
nextExprs.push(origExprs[i]);
|
|
5425
|
+
}
|
|
5426
|
+
}
|
|
5427
|
+
flushQuasi(true);
|
|
5428
|
+
node.quasis = nextQuasis;
|
|
5429
|
+
node.expressions = nextExprs;
|
|
5430
|
+
}
|
|
5431
|
+
}
|
|
5432
|
+
function createNewRegExpAst(sourceExpr, flags) {
|
|
5433
|
+
return {
|
|
5434
|
+
type: "NewExpression",
|
|
5435
|
+
callee: { type: "Identifier", name: "RegExp" },
|
|
5436
|
+
arguments: flags.length > 0 ? [
|
|
5437
|
+
sourceExpr,
|
|
5438
|
+
{
|
|
5439
|
+
type: "Literal",
|
|
5440
|
+
value: flags,
|
|
5441
|
+
raw: JSON.stringify(flags)
|
|
5442
|
+
}
|
|
5443
|
+
] : [sourceExpr]
|
|
5444
|
+
};
|
|
5445
|
+
}
|
|
5446
|
+
function mutateNodeToNewRegExp(node, sourceExpr, flags) {
|
|
5447
|
+
const newExpr = createNewRegExpAst(sourceExpr, flags);
|
|
5448
|
+
node.type = "NewExpression";
|
|
5449
|
+
node.callee = newExpr.callee;
|
|
5450
|
+
node.arguments = newExpr.arguments;
|
|
5451
|
+
delete node.value;
|
|
5452
|
+
delete node.raw;
|
|
5453
|
+
delete node.regex;
|
|
5454
|
+
delete node.optional;
|
|
5455
|
+
}
|
|
5456
|
+
var SCOPE_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
5457
|
+
"FunctionDeclaration",
|
|
5458
|
+
"FunctionExpression",
|
|
5459
|
+
"ArrowFunctionExpression"
|
|
5460
|
+
]);
|
|
5461
|
+
var SCOPE_LEXICAL_TYPES = /* @__PURE__ */ new Set([
|
|
5462
|
+
"Program",
|
|
5463
|
+
"FunctionDeclaration",
|
|
5464
|
+
"FunctionExpression",
|
|
5465
|
+
"ArrowFunctionExpression",
|
|
5466
|
+
"BlockStatement",
|
|
5467
|
+
"ForStatement",
|
|
5468
|
+
"ForInStatement",
|
|
5469
|
+
"ForOfStatement",
|
|
5470
|
+
"SwitchStatement",
|
|
5471
|
+
"CatchClause",
|
|
5472
|
+
"ClassDeclaration",
|
|
5473
|
+
"ClassExpression",
|
|
5474
|
+
"StaticBlock"
|
|
5475
|
+
]);
|
|
5476
|
+
function patternContainsIdentifier(pattern, targetName) {
|
|
5477
|
+
if (!pattern || typeof pattern !== "object") return false;
|
|
5478
|
+
switch (pattern.type) {
|
|
5479
|
+
case "Identifier":
|
|
5480
|
+
return pattern.name === targetName;
|
|
5481
|
+
case "AssignmentPattern":
|
|
5482
|
+
return patternContainsIdentifier(pattern.left, targetName);
|
|
5483
|
+
case "RestElement":
|
|
5484
|
+
return patternContainsIdentifier(pattern.argument, targetName);
|
|
5485
|
+
case "ArrayPattern":
|
|
5486
|
+
return (pattern.elements || []).some(
|
|
5487
|
+
(el) => patternContainsIdentifier(el, targetName)
|
|
5488
|
+
);
|
|
5489
|
+
case "ObjectPattern":
|
|
5490
|
+
return (pattern.properties || []).some(
|
|
5491
|
+
(prop) => _optionalChain([prop, 'optionalAccess', _378 => _378.type]) === "Property" ? patternContainsIdentifier(prop.value, targetName) : _optionalChain([prop, 'optionalAccess', _379 => _379.type]) === "RestElement" ? patternContainsIdentifier(prop.argument, targetName) : false
|
|
5492
|
+
);
|
|
5493
|
+
default:
|
|
5494
|
+
return false;
|
|
5495
|
+
}
|
|
5496
|
+
}
|
|
5497
|
+
function findEnclosingScope(ancestors, scopeSet, fallback) {
|
|
5498
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
5499
|
+
if (scopeSet.has(ancestors[i].type)) {
|
|
5500
|
+
return ancestors[i];
|
|
5501
|
+
}
|
|
5502
|
+
}
|
|
5503
|
+
return fallback;
|
|
5504
|
+
}
|
|
5505
|
+
function collectIdentifierShadowedScopes(ast, identName = "RegExp") {
|
|
5506
|
+
const shadowed = /* @__PURE__ */ new WeakSet();
|
|
5507
|
+
walk4.ancestor(ast, {
|
|
5508
|
+
FunctionDeclaration(node, _state, ancestors) {
|
|
5509
|
+
if (_optionalChain([node, 'access', _380 => _380.id, 'optionalAccess', _381 => _381.name]) === identName) {
|
|
5510
|
+
shadowed.add(
|
|
5511
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
5512
|
+
);
|
|
5513
|
+
shadowed.add(node);
|
|
5514
|
+
}
|
|
5515
|
+
if (Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
5516
|
+
shadowed.add(node);
|
|
5517
|
+
}
|
|
5518
|
+
},
|
|
5519
|
+
FunctionExpression(node) {
|
|
5520
|
+
if (_optionalChain([node, 'access', _382 => _382.id, 'optionalAccess', _383 => _383.name]) === identName || Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
5521
|
+
shadowed.add(node);
|
|
5522
|
+
}
|
|
5523
|
+
},
|
|
5524
|
+
ArrowFunctionExpression(node) {
|
|
5525
|
+
if (Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
5526
|
+
shadowed.add(node);
|
|
5527
|
+
}
|
|
5528
|
+
},
|
|
5529
|
+
ClassDeclaration(node, _state, ancestors) {
|
|
5530
|
+
if (_optionalChain([node, 'access', _384 => _384.id, 'optionalAccess', _385 => _385.name]) === identName) {
|
|
5531
|
+
shadowed.add(
|
|
5532
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
5533
|
+
);
|
|
5534
|
+
shadowed.add(node);
|
|
5535
|
+
}
|
|
5536
|
+
},
|
|
5537
|
+
ClassExpression(node) {
|
|
5538
|
+
if (_optionalChain([node, 'access', _386 => _386.id, 'optionalAccess', _387 => _387.name]) === identName) {
|
|
5539
|
+
shadowed.add(node);
|
|
5540
|
+
}
|
|
5541
|
+
},
|
|
5542
|
+
CatchClause(node) {
|
|
5543
|
+
if (node.param && patternContainsIdentifier(node.param, identName)) {
|
|
5544
|
+
shadowed.add(node);
|
|
5545
|
+
}
|
|
5546
|
+
},
|
|
5547
|
+
WithStatement(node) {
|
|
5548
|
+
shadowed.add(node);
|
|
5549
|
+
},
|
|
5550
|
+
ImportDeclaration(node) {
|
|
5551
|
+
if (Array.isArray(node.specifiers) && node.specifiers.some((s) => _optionalChain([s, 'optionalAccess', _388 => _388.local, 'optionalAccess', _389 => _389.name]) === identName)) {
|
|
5552
|
+
shadowed.add(ast);
|
|
5553
|
+
}
|
|
5554
|
+
},
|
|
5555
|
+
VariableDeclaration(node, _state, ancestors) {
|
|
5556
|
+
if (!Array.isArray(node.declarations) || !node.declarations.some(
|
|
5557
|
+
(d) => patternContainsIdentifier(_optionalChain([d, 'optionalAccess', _390 => _390.id]), identName)
|
|
5558
|
+
)) {
|
|
5559
|
+
return;
|
|
5560
|
+
}
|
|
5561
|
+
if (node.kind === "var") {
|
|
5562
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
5563
|
+
const a = ancestors[i];
|
|
5564
|
+
if (SCOPE_FUNCTION_TYPES.has(a.type) || a.type === "StaticBlock" || a.type === "Program") {
|
|
5565
|
+
shadowed.add(a);
|
|
5566
|
+
break;
|
|
5567
|
+
}
|
|
5568
|
+
}
|
|
5569
|
+
} else {
|
|
5570
|
+
shadowed.add(
|
|
5571
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
5572
|
+
);
|
|
5573
|
+
}
|
|
5574
|
+
}
|
|
5575
|
+
});
|
|
5576
|
+
return shadowed;
|
|
5577
|
+
}
|
|
5578
|
+
function isEligibleSecretRegExp(node, ancestors, hotExemptNodes, exemptSubtreeRoots, getShadowedScopes) {
|
|
5579
|
+
const pattern = _optionalChain([node, 'optionalAccess', _391 => _391.regex, 'optionalAccess', _392 => _392.pattern]);
|
|
5580
|
+
if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 4096) {
|
|
5581
|
+
return false;
|
|
5582
|
+
}
|
|
5583
|
+
if (!hasRegexSecretRun(pattern)) {
|
|
5584
|
+
return false;
|
|
5585
|
+
}
|
|
5586
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5587
|
+
return false;
|
|
5588
|
+
}
|
|
5589
|
+
if (isInsideLoopOrSerialized(ancestors)) {
|
|
5590
|
+
return false;
|
|
5591
|
+
}
|
|
5592
|
+
if (isNodeInExemptSubtree(ancestors, hotExemptNodes)) {
|
|
5593
|
+
return false;
|
|
5594
|
+
}
|
|
5595
|
+
if (getShadowedScopes && isNodeInExemptSubtree(ancestors, getShadowedScopes())) {
|
|
5596
|
+
return false;
|
|
5597
|
+
}
|
|
5598
|
+
return true;
|
|
5599
|
+
}
|
|
5600
|
+
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode, config, shieldCoupled = true, detectHeadless = false, exemptSubtreeRoots, latchCoupling) {
|
|
5601
|
+
const minLen = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _393 => _393.vault, 'optionalAccess', _394 => _394.minStringLength]), () => ( minStringLength));
|
|
4830
5602
|
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
4831
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
5603
|
+
if (_optionalChain([config, 'optionalAccess', _395 => _395.vault, 'optionalAccess', _396 => _396.customDirectives])) {
|
|
4832
5604
|
for (const dir of config.vault.customDirectives) {
|
|
4833
5605
|
activeDirectives.add(dir);
|
|
4834
5606
|
}
|
|
4835
5607
|
}
|
|
4836
|
-
const customReserved = _optionalChain([config, 'optionalAccess',
|
|
4837
|
-
const semanticPatterns = _optionalChain([config, 'optionalAccess',
|
|
5608
|
+
const customReserved = _optionalChain([config, 'optionalAccess', _397 => _397.vault, 'optionalAccess', _398 => _398.reservedProps]) ? new Set(config.vault.reservedProps) : void 0;
|
|
5609
|
+
const semanticPatterns = _optionalChain([config, 'optionalAccess', _399 => _399.vault, 'optionalAccess', _400 => _400.semanticAnchors, 'optionalAccess', _401 => _401.patterns, 'optionalAccess', _402 => _402.map, 'call', _403 => _403(
|
|
4838
5610
|
(p) => typeof p === "string" ? new RegExp(p) : p
|
|
4839
5611
|
)]);
|
|
4840
|
-
const excludeUi = _optionalChain([config, 'optionalAccess',
|
|
5612
|
+
const excludeUi = _optionalChain([config, 'optionalAccess', _404 => _404.vault, 'optionalAccess', _405 => _405.semanticAnchors, 'optionalAccess', _406 => _406.excludeUiClasses]) !== false;
|
|
4841
5613
|
const suffix = (seed >>> 0 & 65535).toString(36);
|
|
4842
5614
|
const decryptFnName = `_uD${suffix}`;
|
|
4843
5615
|
const cacheVarName = derivePolymorphicIdent(seed, "vault");
|
|
4844
5616
|
const shaderVarName = derivePolymorphicIdent(seed, "shader");
|
|
4845
5617
|
const sym = _nullishCoalesce(windowKeySymbol, () => ( deriveWindowKeySymbol(seed)));
|
|
4846
|
-
const browserOnly = _optionalChain([config, 'optionalAccess',
|
|
5618
|
+
const browserOnly = _optionalChain([config, 'optionalAccess', _407 => _407.target]) === "browser";
|
|
4847
5619
|
let expDelta = shieldCoupled ? expectedDelta : 0;
|
|
4848
5620
|
if (shieldCoupled && expDelta === void 0) {
|
|
4849
5621
|
const shield = generateRuntimeShield({
|
|
@@ -4855,8 +5627,8 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4855
5627
|
expDelta = _nullishCoalesce(shield.expectedDelta, () => ( 0));
|
|
4856
5628
|
}
|
|
4857
5629
|
const alreadyVaulted = ast.body.some(
|
|
4858
|
-
(stmt) => stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access',
|
|
4859
|
-
(d) => _optionalChain([d, 'access',
|
|
5630
|
+
(stmt) => stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access', _408 => _408.declarations, 'optionalAccess', _409 => _409.some, 'call', _410 => _410(
|
|
5631
|
+
(d) => _optionalChain([d, 'access', _411 => _411.id, 'optionalAccess', _412 => _412.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 || _optionalChain([d, 'access', _413 => _413.init, 'optionalAccess', _414 => _414.type]) === "CallExpression" && _optionalChain([d, 'access', _415 => _415.init, 'access', _416 => _416.callee, 'optionalAccess', _417 => _417.type]) === "FunctionExpression" && _optionalChain([d, 'access', _418 => _418.init, 'access', _419 => _419.callee, 'optionalAccess', _420 => _420.id, 'optionalAccess', _421 => _421.name]) === "f" && _optionalChain([d, 'access', _422 => _422.init, 'access', _423 => _423.arguments, 'optionalAccess', _424 => _424[0], 'optionalAccess', _425 => _425.type]) === "ArrayExpression")
|
|
4860
5632
|
)])
|
|
4861
5633
|
);
|
|
4862
5634
|
if (alreadyVaulted) {
|
|
@@ -4874,7 +5646,8 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4874
5646
|
sym,
|
|
4875
5647
|
SAFE_ALPHA,
|
|
4876
5648
|
shieldCoupled,
|
|
4877
|
-
browserOnly
|
|
5649
|
+
browserOnly,
|
|
5650
|
+
latchCoupling
|
|
4878
5651
|
);
|
|
4879
5652
|
const compactFnStr = generateCompactJs(fnAst);
|
|
4880
5653
|
const buildH = computeIntegrityHash(compactFnStr, 0);
|
|
@@ -4886,23 +5659,22 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4886
5659
|
const shaderPayloads = [];
|
|
4887
5660
|
const targetsToReplace = [];
|
|
4888
5661
|
const hotTargetsToReplace = [];
|
|
4889
|
-
const
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
}
|
|
5662
|
+
const interpolatedTemplates = [];
|
|
5663
|
+
let regExpShadowedScopes;
|
|
5664
|
+
const getRegExpShadowedScopes = () => {
|
|
5665
|
+
regExpShadowedScopes ??= collectIdentifierShadowedScopes(ast, "RegExp");
|
|
5666
|
+
return regExpShadowedScopes;
|
|
4895
5667
|
};
|
|
4896
|
-
function processVaultCandidate(val, node, parent, ancestors) {
|
|
5668
|
+
function processVaultCandidate(val, node, parent, ancestors, onReplace) {
|
|
4897
5669
|
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
4898
|
-
return;
|
|
5670
|
+
return false;
|
|
4899
5671
|
}
|
|
4900
5672
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
4901
|
-
return;
|
|
5673
|
+
return false;
|
|
4902
5674
|
}
|
|
4903
5675
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
4904
5676
|
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
4905
|
-
return;
|
|
5677
|
+
return false;
|
|
4906
5678
|
}
|
|
4907
5679
|
}
|
|
4908
5680
|
let isHotExempt = false;
|
|
@@ -4934,9 +5706,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4934
5706
|
node,
|
|
4935
5707
|
parent,
|
|
4936
5708
|
idx: idx2,
|
|
4937
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
5709
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
5710
|
+
...onReplace ? { onReplace } : {}
|
|
4938
5711
|
});
|
|
4939
|
-
return;
|
|
5712
|
+
return true;
|
|
4940
5713
|
}
|
|
4941
5714
|
if (isHotExempt) {
|
|
4942
5715
|
if (isEligibleHotLiteral(
|
|
@@ -4955,10 +5728,12 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4955
5728
|
node,
|
|
4956
5729
|
parent,
|
|
4957
5730
|
val,
|
|
4958
|
-
idx: hotTargetsToReplace.length
|
|
5731
|
+
idx: hotTargetsToReplace.length,
|
|
5732
|
+
...onReplace ? { onReplace } : {}
|
|
4959
5733
|
});
|
|
5734
|
+
return true;
|
|
4960
5735
|
}
|
|
4961
|
-
return;
|
|
5736
|
+
return false;
|
|
4962
5737
|
}
|
|
4963
5738
|
if (!shouldEncryptString(
|
|
4964
5739
|
val,
|
|
@@ -4967,7 +5742,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4967
5742
|
activeDirectives,
|
|
4968
5743
|
customReserved
|
|
4969
5744
|
)) {
|
|
4970
|
-
return;
|
|
5745
|
+
return false;
|
|
4971
5746
|
}
|
|
4972
5747
|
let idx = stringToIndex.get(val);
|
|
4973
5748
|
if (idx === void 0) {
|
|
@@ -4980,46 +5755,102 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
4980
5755
|
node,
|
|
4981
5756
|
parent,
|
|
4982
5757
|
idx,
|
|
4983
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
5758
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
5759
|
+
...onReplace ? { onReplace } : {}
|
|
4984
5760
|
});
|
|
5761
|
+
return true;
|
|
4985
5762
|
}
|
|
4986
5763
|
walk4.ancestor(
|
|
4987
5764
|
ast,
|
|
4988
5765
|
{
|
|
4989
5766
|
Literal(node, _state, ancestors) {
|
|
5767
|
+
if (node.regex) {
|
|
5768
|
+
if (isEligibleSecretRegExp(
|
|
5769
|
+
node,
|
|
5770
|
+
ancestors,
|
|
5771
|
+
hotExemptNodes,
|
|
5772
|
+
exemptSubtreeRoots,
|
|
5773
|
+
getRegExpShadowedScopes
|
|
5774
|
+
)) {
|
|
5775
|
+
const pattern = node.regex.pattern;
|
|
5776
|
+
const flags = _nullishCoalesce(node.regex.flags, () => ( ""));
|
|
5777
|
+
const parent2 = ancestors[ancestors.length - 2];
|
|
5778
|
+
let idx = stringToIndex.get(pattern);
|
|
5779
|
+
if (idx === void 0) {
|
|
5780
|
+
idx = uniqueStrings.length;
|
|
5781
|
+
stringToIndex.set(pattern, idx);
|
|
5782
|
+
uniqueStrings.push(pattern);
|
|
5783
|
+
}
|
|
5784
|
+
targetsToReplace.push({
|
|
5785
|
+
type: "string",
|
|
5786
|
+
node,
|
|
5787
|
+
parent: parent2,
|
|
5788
|
+
idx,
|
|
5789
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
5790
|
+
replaceMode: "regexp",
|
|
5791
|
+
flags
|
|
5792
|
+
});
|
|
5793
|
+
}
|
|
5794
|
+
return;
|
|
5795
|
+
}
|
|
4990
5796
|
if (typeof node.value !== "string") return;
|
|
4991
5797
|
const val = node.value;
|
|
4992
5798
|
if (activeDirectives.has(val)) return;
|
|
4993
5799
|
const parent = ancestors[ancestors.length - 2];
|
|
4994
5800
|
if (!parent) return;
|
|
4995
|
-
if (
|
|
4996
|
-
|
|
5801
|
+
if (isStaticModuleOrAssetPosition(node, parent)) {
|
|
5802
|
+
return;
|
|
4997
5803
|
}
|
|
4998
5804
|
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
4999
5805
|
return;
|
|
5000
5806
|
}
|
|
5001
|
-
if (parent.type === "
|
|
5002
|
-
|
|
5807
|
+
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
5808
|
+
if (!isEligibleObjectPropertyKey(val, node, parent, ancestors)) {
|
|
5809
|
+
return;
|
|
5810
|
+
}
|
|
5003
5811
|
}
|
|
5004
5812
|
processVaultCandidate(val, node, parent, ancestors);
|
|
5005
5813
|
},
|
|
5006
5814
|
TemplateLiteral(node, _state, ancestors) {
|
|
5007
|
-
if (!node.quasis || node.quasis.length
|
|
5008
|
-
if (node.expressions && node.expressions.length !== 0) return;
|
|
5009
|
-
const val = _nullishCoalesce(node.quasis[0].value.cooked, () => ( node.quasis[0].value.raw));
|
|
5010
|
-
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
5815
|
+
if (!Array.isArray(node.quasis) || node.quasis.length === 0) return;
|
|
5011
5816
|
const parent = ancestors[ancestors.length - 2];
|
|
5012
|
-
if (
|
|
5013
|
-
|
|
5817
|
+
if (isExemptTemplateLiteral(node, parent)) return;
|
|
5818
|
+
const exprCount = Array.isArray(node.expressions) ? node.expressions.length : 0;
|
|
5819
|
+
if (exprCount === 0) {
|
|
5820
|
+
if (node.quasis.length !== 1) return;
|
|
5821
|
+
const val = _nullishCoalesce(node.quasis[0].value.cooked, () => ( node.quasis[0].value.raw));
|
|
5822
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
5823
|
+
processVaultCandidate(val, node, parent, ancestors);
|
|
5014
5824
|
return;
|
|
5015
5825
|
}
|
|
5016
|
-
if (
|
|
5826
|
+
if (node.quasis.length !== exprCount + 1) return;
|
|
5827
|
+
if (node.quasis.some((q) => typeof _optionalChain([q, 'optionalAccess', _426 => _426.value, 'optionalAccess', _427 => _427.cooked]) !== "string")) {
|
|
5017
5828
|
return;
|
|
5018
5829
|
}
|
|
5019
|
-
|
|
5830
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
5831
|
+
let queuedCount = 0;
|
|
5832
|
+
for (let qIdx = 0; qIdx < node.quasis.length; qIdx++) {
|
|
5833
|
+
const val = node.quasis[qIdx].value.cooked;
|
|
5834
|
+
if (activeDirectives.has(val)) continue;
|
|
5835
|
+
const queued = processVaultCandidate(
|
|
5836
|
+
val,
|
|
5837
|
+
node,
|
|
5838
|
+
parent,
|
|
5839
|
+
ancestors,
|
|
5840
|
+
(exprAst) => {
|
|
5841
|
+
replacements.set(qIdx, exprAst);
|
|
5842
|
+
}
|
|
5843
|
+
);
|
|
5844
|
+
if (queued) {
|
|
5845
|
+
queuedCount++;
|
|
5846
|
+
}
|
|
5847
|
+
}
|
|
5848
|
+
if (queuedCount > 0) {
|
|
5849
|
+
interpolatedTemplates.push({ node, replacements });
|
|
5850
|
+
}
|
|
5020
5851
|
}
|
|
5021
5852
|
},
|
|
5022
|
-
|
|
5853
|
+
VAULT_WALK_BASE
|
|
5023
5854
|
);
|
|
5024
5855
|
if (targetsToReplace.length === 0 && hotTargetsToReplace.length === 0) {
|
|
5025
5856
|
return {
|
|
@@ -5028,41 +5859,72 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5028
5859
|
shaderBuffersCount: 0
|
|
5029
5860
|
};
|
|
5030
5861
|
}
|
|
5031
|
-
for (const { node, parent, val, idx } of hotTargetsToReplace) {
|
|
5862
|
+
for (const { node, parent, val, idx, onReplace } of hotTargetsToReplace) {
|
|
5032
5863
|
const key = idx % 3 + 1;
|
|
5033
5864
|
let encodedStr = "";
|
|
5034
5865
|
for (let i = 0; i < val.length; i++) {
|
|
5035
5866
|
encodedStr += String.fromCharCode(val.charCodeAt(i) ^ key);
|
|
5036
5867
|
}
|
|
5037
|
-
|
|
5868
|
+
const callExpr = {
|
|
5869
|
+
type: "CallExpression",
|
|
5870
|
+
callee: {
|
|
5871
|
+
type: "Identifier",
|
|
5872
|
+
name: "_hX"
|
|
5873
|
+
},
|
|
5874
|
+
arguments: [
|
|
5875
|
+
{
|
|
5876
|
+
type: "Literal",
|
|
5877
|
+
value: encodedStr,
|
|
5878
|
+
raw: JSON.stringify(encodedStr)
|
|
5879
|
+
},
|
|
5880
|
+
{
|
|
5881
|
+
type: "Literal",
|
|
5882
|
+
value: key,
|
|
5883
|
+
raw: String(key)
|
|
5884
|
+
}
|
|
5885
|
+
],
|
|
5886
|
+
optional: false
|
|
5887
|
+
};
|
|
5888
|
+
if (onReplace) {
|
|
5889
|
+
onReplace(callExpr);
|
|
5890
|
+
continue;
|
|
5891
|
+
}
|
|
5892
|
+
if (_optionalChain([parent, 'optionalAccess', _428 => _428.type]) === "Property" && parent.key === node) {
|
|
5038
5893
|
parent.computed = true;
|
|
5039
5894
|
}
|
|
5040
5895
|
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
|
-
];
|
|
5896
|
+
node.callee = callExpr.callee;
|
|
5897
|
+
node.arguments = callExpr.arguments;
|
|
5057
5898
|
node.optional = false;
|
|
5058
5899
|
delete node.value;
|
|
5059
5900
|
delete node.raw;
|
|
5060
5901
|
delete node.quasis;
|
|
5061
5902
|
delete node.expressions;
|
|
5062
5903
|
}
|
|
5904
|
+
function applyVaultTargetReplacement(target, callExpr) {
|
|
5905
|
+
if (target.onReplace) {
|
|
5906
|
+
target.onReplace(callExpr);
|
|
5907
|
+
return;
|
|
5908
|
+
}
|
|
5909
|
+
if (target.replaceMode === "regexp") {
|
|
5910
|
+
mutateNodeToNewRegExp(target.node, callExpr, _nullishCoalesce(target.flags, () => ( "")));
|
|
5911
|
+
return;
|
|
5912
|
+
}
|
|
5913
|
+
if (_optionalChain([target, 'access', _429 => _429.parent, 'optionalAccess', _430 => _430.type]) === "Property" && target.parent.key === target.node) {
|
|
5914
|
+
target.parent.computed = true;
|
|
5915
|
+
}
|
|
5916
|
+
target.node.type = "CallExpression";
|
|
5917
|
+
target.node.callee = callExpr.callee;
|
|
5918
|
+
target.node.arguments = callExpr.arguments;
|
|
5919
|
+
target.node.optional = false;
|
|
5920
|
+
delete target.node.value;
|
|
5921
|
+
delete target.node.raw;
|
|
5922
|
+
delete target.node.quasis;
|
|
5923
|
+
delete target.node.expressions;
|
|
5924
|
+
}
|
|
5063
5925
|
let insertIdx = findVaultInsertIndex(ast, activeDirectives);
|
|
5064
|
-
const wantFragmented = Boolean(_optionalChain([config, 'optionalAccess',
|
|
5065
|
-
let fragCount = Math.max(2, Math.min(8, Math.floor(_nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5926
|
+
const wantFragmented = Boolean(_optionalChain([config, 'optionalAccess', _431 => _431.vault, 'optionalAccess', _432 => _432.fragmented]));
|
|
5927
|
+
let fragCount = Math.max(2, Math.min(8, Math.floor(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _433 => _433.vault, 'optionalAccess', _434 => _434.fragmentCount]), () => ( 3)))));
|
|
5066
5928
|
while (fragCount > 2 && Math.floor(uniqueStrings.length / fragCount) < 4) {
|
|
5067
5929
|
fragCount--;
|
|
5068
5930
|
}
|
|
@@ -5076,28 +5938,28 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5076
5938
|
);
|
|
5077
5939
|
}
|
|
5078
5940
|
integrityToken = computeFnv1aHash(JSON.stringify(encryptedPayloads), seed);
|
|
5079
|
-
for (const
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5941
|
+
for (const target of targetsToReplace) {
|
|
5942
|
+
let callExpr;
|
|
5943
|
+
if (target.type === "shader") {
|
|
5944
|
+
callExpr = {
|
|
5945
|
+
type: "CallExpression",
|
|
5946
|
+
callee: { type: "Identifier", name: shaderVarName },
|
|
5947
|
+
arguments: [{ type: "Literal", value: target.idx, raw: String(target.idx) }],
|
|
5948
|
+
optional: false
|
|
5949
|
+
};
|
|
5087
5950
|
} else {
|
|
5088
|
-
const salt = computeCallSiteSalt(seed, idx);
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
delete node.expressions;
|
|
5951
|
+
const salt = computeCallSiteSalt(seed, target.idx);
|
|
5952
|
+
callExpr = {
|
|
5953
|
+
type: "CallExpression",
|
|
5954
|
+
callee: { type: "Identifier", name: decryptFnName },
|
|
5955
|
+
arguments: [
|
|
5956
|
+
{ type: "Literal", value: target.idx, raw: String(target.idx) },
|
|
5957
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
5958
|
+
],
|
|
5959
|
+
optional: false
|
|
5960
|
+
};
|
|
5961
|
+
}
|
|
5962
|
+
applyVaultTargetReplacement(target, callExpr);
|
|
5101
5963
|
}
|
|
5102
5964
|
} else {
|
|
5103
5965
|
const perm = [];
|
|
@@ -5140,7 +6002,8 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5140
6002
|
sym,
|
|
5141
6003
|
SAFE_ALPHA,
|
|
5142
6004
|
shieldCoupled,
|
|
5143
|
-
browserOnly
|
|
6005
|
+
browserOnly,
|
|
6006
|
+
latchCoupling
|
|
5144
6007
|
);
|
|
5145
6008
|
const buildHF = computeIntegrityHash(generateCompactJs(fnAstF), 0);
|
|
5146
6009
|
const expectedKeyF = (buildHF ^ 0 ^ (shieldCoupled ? (_nullishCoalesce(expDelta, () => ( 0))) & 65535 : 0)) >>> 0;
|
|
@@ -5165,31 +6028,31 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5165
6028
|
chains: []
|
|
5166
6029
|
});
|
|
5167
6030
|
}
|
|
5168
|
-
for (const
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
6031
|
+
for (const target of targetsToReplace) {
|
|
6032
|
+
let callExpr;
|
|
6033
|
+
if (target.type === "shader") {
|
|
6034
|
+
callExpr = {
|
|
6035
|
+
type: "CallExpression",
|
|
6036
|
+
callee: { type: "Identifier", name: shaderVarName },
|
|
6037
|
+
arguments: [{ type: "Literal", value: target.idx, raw: String(target.idx) }],
|
|
6038
|
+
optional: false
|
|
6039
|
+
};
|
|
5176
6040
|
} else {
|
|
5177
|
-
const { fragId, localIdx } = stringFragAssign[idx];
|
|
6041
|
+
const { fragId, localIdx } = stringFragAssign[target.idx];
|
|
5178
6042
|
const meta = fragMeta[fragId];
|
|
5179
|
-
meta.chains.push(scopeChain);
|
|
6043
|
+
meta.chains.push(target.scopeChain);
|
|
5180
6044
|
const salt = computeCallSiteSalt(meta.fragSeed, localIdx);
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
delete node.expressions;
|
|
6045
|
+
callExpr = {
|
|
6046
|
+
type: "CallExpression",
|
|
6047
|
+
callee: { type: "Identifier", name: meta.fnName },
|
|
6048
|
+
arguments: [
|
|
6049
|
+
{ type: "Literal", value: localIdx, raw: String(localIdx) },
|
|
6050
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
6051
|
+
],
|
|
6052
|
+
optional: false
|
|
6053
|
+
};
|
|
6054
|
+
}
|
|
6055
|
+
applyVaultTargetReplacement(target, callExpr);
|
|
5193
6056
|
}
|
|
5194
6057
|
const allPayloads = [];
|
|
5195
6058
|
for (const meta of fragMeta) {
|
|
@@ -5204,7 +6067,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5204
6067
|
ast.body.splice(insertIdx++, 0, helperStmt);
|
|
5205
6068
|
} else {
|
|
5206
6069
|
let blockInsertIdx = 0;
|
|
5207
|
-
while (blockInsertIdx < lcaScope.body.length && _optionalChain([lcaScope, 'access',
|
|
6070
|
+
while (blockInsertIdx < lcaScope.body.length && _optionalChain([lcaScope, 'access', _435 => _435.body, 'access', _436 => _436[blockInsertIdx], 'optionalAccess', _437 => _437.type]) === "ExpressionStatement" && Boolean(_optionalChain([lcaScope, 'access', _438 => _438.body, 'access', _439 => _439[blockInsertIdx], 'optionalAccess', _440 => _440.directive]))) {
|
|
5208
6071
|
blockInsertIdx++;
|
|
5209
6072
|
}
|
|
5210
6073
|
lcaScope.body.splice(blockInsertIdx, 0, helperStmt);
|
|
@@ -5212,9 +6075,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5212
6075
|
}
|
|
5213
6076
|
integrityToken = computeFnv1aHash(JSON.stringify(allPayloads), seed);
|
|
5214
6077
|
}
|
|
6078
|
+
rebuildInterpolatedTemplates(interpolatedTemplates);
|
|
5215
6079
|
if (hotTargetsToReplace.length > 0) {
|
|
5216
6080
|
const alreadyHasHx = ast.body.some(
|
|
5217
|
-
(stmt) => stmt.type === "FunctionDeclaration" && _optionalChain([stmt, 'access',
|
|
6081
|
+
(stmt) => stmt.type === "FunctionDeclaration" && _optionalChain([stmt, 'access', _441 => _441.id, 'optionalAccess', _442 => _442.name]) === "_hX"
|
|
5218
6082
|
);
|
|
5219
6083
|
if (!alreadyHasHx) {
|
|
5220
6084
|
const hxAst = acorn4.parse(
|
|
@@ -5405,8 +6269,8 @@ function collectPatternTargets(pattern, out, shorthandProp) {
|
|
|
5405
6269
|
}
|
|
5406
6270
|
}
|
|
5407
6271
|
function isMangleableName(origName, reservedSet = RESERVED_IDENTIFIERS, manglerConfig) {
|
|
5408
|
-
const minLength = _nullishCoalesce(_optionalChain([manglerConfig, 'optionalAccess',
|
|
5409
|
-
return origName.length >= minLength && !reservedSet.has(origName) && !JS_KEYWORDS.has(origName) && !origName.startsWith("$") && !origName.startsWith("__") && !origName.startsWith("_u") && !origName.startsWith("_0x") && (!_optionalChain([manglerConfig, 'optionalAccess',
|
|
6272
|
+
const minLength = _nullishCoalesce(_optionalChain([manglerConfig, 'optionalAccess', _443 => _443.minLength]), () => ( 1));
|
|
6273
|
+
return origName.length >= minLength && !reservedSet.has(origName) && !JS_KEYWORDS.has(origName) && !origName.startsWith("$") && !origName.startsWith("__") && !origName.startsWith("_u") && !origName.startsWith("_0x") && (!_optionalChain([manglerConfig, 'optionalAccess', _444 => _444.excludePrefixes]) || !manglerConfig.excludePrefixes.some((p) => origName.startsWith(p))) && (!_optionalChain([manglerConfig, 'optionalAccess', _445 => _445.excludePatterns]) || !manglerConfig.excludePatterns.some(
|
|
5410
6274
|
(re) => (typeof re === "string" ? new RegExp(re) : re).test(origName)
|
|
5411
6275
|
));
|
|
5412
6276
|
}
|
|
@@ -5426,21 +6290,62 @@ function shuffleAlphabet(chars, seed) {
|
|
|
5426
6290
|
}
|
|
5427
6291
|
function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes, config) {
|
|
5428
6292
|
const activeReserved = new Set(RESERVED_IDENTIFIERS);
|
|
5429
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
6293
|
+
if (_optionalChain([config, 'optionalAccess', _446 => _446.mangler, 'optionalAccess', _447 => _447.reservedIdentifiers])) {
|
|
5430
6294
|
for (const id of config.mangler.reservedIdentifiers) {
|
|
5431
6295
|
activeReserved.add(id);
|
|
5432
6296
|
}
|
|
5433
6297
|
}
|
|
5434
|
-
const manglerConfig = _optionalChain([config, 'optionalAccess',
|
|
6298
|
+
const manglerConfig = _optionalChain([config, 'optionalAccess', _448 => _448.mangler]);
|
|
5435
6299
|
const scopeRecords = /* @__PURE__ */ new Map();
|
|
6300
|
+
const protectedScopeNodes = /* @__PURE__ */ new Set();
|
|
5436
6301
|
const barrierOrFreeIds = /* @__PURE__ */ new Set();
|
|
5437
6302
|
const renamedTargetNodes = /* @__PURE__ */ new WeakSet();
|
|
5438
6303
|
let counter = 0;
|
|
6304
|
+
function hasStrictDirective(stmts) {
|
|
6305
|
+
if (!Array.isArray(stmts)) return false;
|
|
6306
|
+
for (const stmt of stmts) {
|
|
6307
|
+
if (_optionalChain([stmt, 'optionalAccess', _449 => _449.type]) !== "ExpressionStatement") break;
|
|
6308
|
+
const isStrLit = _optionalChain([stmt, 'access', _450 => _450.expression, 'optionalAccess', _451 => _451.type]) === "Literal" && typeof stmt.expression.value === "string";
|
|
6309
|
+
if (!stmt.directive && !isStrLit) break;
|
|
6310
|
+
if (stmt.directive === "use strict" || _optionalChain([stmt, 'access', _452 => _452.expression, 'optionalAccess', _453 => _453.value]) === "use strict") {
|
|
6311
|
+
return true;
|
|
6312
|
+
}
|
|
6313
|
+
}
|
|
6314
|
+
return false;
|
|
6315
|
+
}
|
|
6316
|
+
function isSloppyFunctionNode(fnNode, ancestors) {
|
|
6317
|
+
if (fnNode.type === "ArrowFunctionExpression") return false;
|
|
6318
|
+
if (ast.sourceType === "module") return false;
|
|
6319
|
+
const parent = ancestors.length >= 2 ? ancestors[ancestors.length - 2] : null;
|
|
6320
|
+
if (parent && (parent.type === "MethodDefinition" || parent.type === "Property" && (parent.method || parent.kind === "get" || parent.kind === "set"))) {
|
|
6321
|
+
return false;
|
|
6322
|
+
}
|
|
6323
|
+
for (let i = 0; i < ancestors.length - 1; i++) {
|
|
6324
|
+
const anc = ancestors[i];
|
|
6325
|
+
if (anc.type === "ClassDeclaration" || anc.type === "ClassExpression") {
|
|
6326
|
+
return false;
|
|
6327
|
+
}
|
|
6328
|
+
if (anc.type === "Program" && hasStrictDirective(anc.body)) {
|
|
6329
|
+
return false;
|
|
6330
|
+
}
|
|
6331
|
+
if (FUNCTION_TYPES.has(anc.type) && _optionalChain([anc, 'access', _454 => _454.body, 'optionalAccess', _455 => _455.type]) === "BlockStatement" && hasStrictDirective(anc.body.body)) {
|
|
6332
|
+
return false;
|
|
6333
|
+
}
|
|
6334
|
+
}
|
|
6335
|
+
if (_optionalChain([fnNode, 'access', _456 => _456.body, 'optionalAccess', _457 => _457.type]) === "BlockStatement" && hasStrictDirective(fnNode.body.body)) {
|
|
6336
|
+
return false;
|
|
6337
|
+
}
|
|
6338
|
+
return true;
|
|
6339
|
+
}
|
|
5439
6340
|
function ensureScopeChain(ancestors) {
|
|
6341
|
+
const insideWith = ancestors.some((a) => a.type === "WithStatement");
|
|
5440
6342
|
let prevScope = null;
|
|
5441
6343
|
for (let i = 0; i < ancestors.length; i++) {
|
|
5442
6344
|
const node = ancestors[i];
|
|
5443
6345
|
if (!LEXICAL_SCOPE_TYPES.has(node.type)) continue;
|
|
6346
|
+
if (insideWith) {
|
|
6347
|
+
protectedScopeNodes.add(node);
|
|
6348
|
+
}
|
|
5444
6349
|
let record = scopeRecords.get(node);
|
|
5445
6350
|
if (!record) {
|
|
5446
6351
|
const isFn = FUNCTION_TYPES.has(node.type);
|
|
@@ -5527,16 +6432,45 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
5527
6432
|
}
|
|
5528
6433
|
function registerFunctionParams(fnNode, ancestors) {
|
|
5529
6434
|
ensureScopeChain(ancestors);
|
|
5530
|
-
|
|
6435
|
+
const params = fnNode.params || [];
|
|
6436
|
+
const duplicateParamNames = /* @__PURE__ */ new Set();
|
|
6437
|
+
const allSimpleParams = params.every((p) => _optionalChain([p, 'optionalAccess', _458 => _458.type]) === "Identifier");
|
|
6438
|
+
if (allSimpleParams && params.length > 1 && isSloppyFunctionNode(fnNode, ancestors)) {
|
|
6439
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6440
|
+
for (const p of params) {
|
|
6441
|
+
if (seen.has(p.name)) {
|
|
6442
|
+
duplicateParamNames.add(p.name);
|
|
6443
|
+
}
|
|
6444
|
+
seen.add(p.name);
|
|
6445
|
+
}
|
|
6446
|
+
}
|
|
6447
|
+
for (const param of params) {
|
|
5531
6448
|
const targets = [];
|
|
5532
6449
|
collectPatternTargets(param, targets);
|
|
5533
6450
|
for (const target of targets) {
|
|
5534
|
-
|
|
6451
|
+
const allowMangle = !duplicateParamNames.has(target.idNode.name);
|
|
6452
|
+
registerBindingTarget(fnNode, target, allowMangle, fnNode);
|
|
5535
6453
|
}
|
|
5536
6454
|
}
|
|
5537
6455
|
}
|
|
5538
6456
|
ensureScopeChain([ast]);
|
|
5539
6457
|
walk5.ancestor(ast, {
|
|
6458
|
+
CallExpression(node, _state, ancestors) {
|
|
6459
|
+
if (!node.optional && _optionalChain([node, 'access', _459 => _459.callee, 'optionalAccess', _460 => _460.type]) === "Identifier" && node.callee.name === "eval") {
|
|
6460
|
+
for (const anc of ancestors) {
|
|
6461
|
+
if (LEXICAL_SCOPE_TYPES.has(anc.type)) {
|
|
6462
|
+
protectedScopeNodes.add(anc);
|
|
6463
|
+
}
|
|
6464
|
+
}
|
|
6465
|
+
}
|
|
6466
|
+
},
|
|
6467
|
+
WithStatement(_node, _state, ancestors) {
|
|
6468
|
+
for (const anc of ancestors) {
|
|
6469
|
+
if (LEXICAL_SCOPE_TYPES.has(anc.type)) {
|
|
6470
|
+
protectedScopeNodes.add(anc);
|
|
6471
|
+
}
|
|
6472
|
+
}
|
|
6473
|
+
},
|
|
5540
6474
|
BlockStatement(_node, _state, ancestors) {
|
|
5541
6475
|
ensureScopeChain(ancestors);
|
|
5542
6476
|
},
|
|
@@ -5553,17 +6487,17 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
5553
6487
|
ensureScopeChain(ancestors);
|
|
5554
6488
|
},
|
|
5555
6489
|
ImportSpecifier(node) {
|
|
5556
|
-
if (_optionalChain([node, 'access',
|
|
6490
|
+
if (_optionalChain([node, 'access', _461 => _461.local, 'optionalAccess', _462 => _462.name])) barrierOrFreeIds.add(node.local.name);
|
|
5557
6491
|
},
|
|
5558
6492
|
ImportDefaultSpecifier(node) {
|
|
5559
|
-
if (_optionalChain([node, 'access',
|
|
6493
|
+
if (_optionalChain([node, 'access', _463 => _463.local, 'optionalAccess', _464 => _464.name])) barrierOrFreeIds.add(node.local.name);
|
|
5560
6494
|
},
|
|
5561
6495
|
ImportNamespaceSpecifier(node) {
|
|
5562
|
-
if (_optionalChain([node, 'access',
|
|
6496
|
+
if (_optionalChain([node, 'access', _465 => _465.local, 'optionalAccess', _466 => _466.name])) barrierOrFreeIds.add(node.local.name);
|
|
5563
6497
|
},
|
|
5564
6498
|
FunctionDeclaration(node, _state, ancestors) {
|
|
5565
6499
|
registerFunctionParams(node, ancestors);
|
|
5566
|
-
if (_optionalChain([node, 'access',
|
|
6500
|
+
if (_optionalChain([node, 'access', _467 => _467.id, 'optionalAccess', _468 => _468.type]) === "Identifier") {
|
|
5567
6501
|
const parentAncestors = ancestors.slice(0, -1);
|
|
5568
6502
|
const lexNode = findEnclosingLexicalNode(parentAncestors);
|
|
5569
6503
|
const fnNode = _nullishCoalesce(findEnclosingFunctionNode(parentAncestors), () => ( ast));
|
|
@@ -5571,15 +6505,15 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
5571
6505
|
if (lexNode === fnNode.body || fnNode === ast) {
|
|
5572
6506
|
registerBarrierName(fnNode, node.id.name);
|
|
5573
6507
|
}
|
|
5574
|
-
if (!_optionalChain([scopeRecords, 'access',
|
|
6508
|
+
if (!_optionalChain([scopeRecords, 'access', _469 => _469.get, 'call', _470 => _470(node), 'optionalAccess', _471 => _471.bindings, 'access', _472 => _472.has, 'call', _473 => _473(node.id.name)])) {
|
|
5575
6509
|
registerBarrierName(node, node.id.name);
|
|
5576
6510
|
}
|
|
5577
6511
|
}
|
|
5578
6512
|
},
|
|
5579
6513
|
FunctionExpression(node, _state, ancestors) {
|
|
5580
6514
|
registerFunctionParams(node, ancestors);
|
|
5581
|
-
if (_optionalChain([node, 'access',
|
|
5582
|
-
if (!_optionalChain([scopeRecords, 'access',
|
|
6515
|
+
if (_optionalChain([node, 'access', _474 => _474.id, 'optionalAccess', _475 => _475.type]) === "Identifier") {
|
|
6516
|
+
if (!_optionalChain([scopeRecords, 'access', _476 => _476.get, 'call', _477 => _477(node), 'optionalAccess', _478 => _478.bindings, 'access', _479 => _479.has, 'call', _480 => _480(node.id.name)])) {
|
|
5583
6517
|
registerBarrierName(node, node.id.name);
|
|
5584
6518
|
}
|
|
5585
6519
|
}
|
|
@@ -5589,7 +6523,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
5589
6523
|
},
|
|
5590
6524
|
ClassDeclaration(node, _state, ancestors) {
|
|
5591
6525
|
ensureScopeChain(ancestors);
|
|
5592
|
-
if (_optionalChain([node, 'access',
|
|
6526
|
+
if (_optionalChain([node, 'access', _481 => _481.id, 'optionalAccess', _482 => _482.type]) === "Identifier") {
|
|
5593
6527
|
const parentAncestors = ancestors.slice(0, -1);
|
|
5594
6528
|
const lexNode = findEnclosingLexicalNode(parentAncestors);
|
|
5595
6529
|
registerBarrierName(lexNode, node.id.name);
|
|
@@ -5598,7 +6532,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
5598
6532
|
},
|
|
5599
6533
|
ClassExpression(node, _state, ancestors) {
|
|
5600
6534
|
ensureScopeChain(ancestors);
|
|
5601
|
-
if (_optionalChain([node, 'access',
|
|
6535
|
+
if (_optionalChain([node, 'access', _483 => _483.id, 'optionalAccess', _484 => _484.type]) === "Identifier") {
|
|
5602
6536
|
registerBarrierName(node, node.id.name);
|
|
5603
6537
|
}
|
|
5604
6538
|
},
|
|
@@ -5637,7 +6571,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
5637
6571
|
if (ancestors[i] === fnScope) break;
|
|
5638
6572
|
if (ancestors[i].type === "CatchClause") {
|
|
5639
6573
|
const catchScope = scopeRecords.get(ancestors[i]);
|
|
5640
|
-
if (_optionalChain([catchScope, 'optionalAccess',
|
|
6574
|
+
if (_optionalChain([catchScope, 'optionalAccess', _485 => _485.bindings, 'access', _486 => _486.has, 'call', _487 => _487(origName)])) {
|
|
5641
6575
|
registerBarrierName(ancestors[i], origName);
|
|
5642
6576
|
registerBarrierName(fnScope, origName);
|
|
5643
6577
|
}
|
|
@@ -5649,6 +6583,14 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
5649
6583
|
}
|
|
5650
6584
|
}
|
|
5651
6585
|
});
|
|
6586
|
+
for (const scopeNode of protectedScopeNodes) {
|
|
6587
|
+
const scope = scopeRecords.get(scopeNode);
|
|
6588
|
+
if (!scope) continue;
|
|
6589
|
+
for (const entry of scope.bindings.values()) {
|
|
6590
|
+
entry.shouldMangle = false;
|
|
6591
|
+
barrierOrFreeIds.add(entry.origName);
|
|
6592
|
+
}
|
|
6593
|
+
}
|
|
5652
6594
|
function resolveBinding(name, ancestors) {
|
|
5653
6595
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
5654
6596
|
const scope = scopeRecords.get(ancestors[i]);
|
|
@@ -5815,11 +6757,40 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
5815
6757
|
// src/ast/cold-flow-guard.ts
|
|
5816
6758
|
|
|
5817
6759
|
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
6760
|
+
function deriveColdFlowSuffix(seed) {
|
|
6761
|
+
return (seed >>> 0).toString(36).slice(0, 4);
|
|
6762
|
+
}
|
|
6763
|
+
function deriveColdAliasInitWords(seed) {
|
|
6764
|
+
const words = [
|
|
6765
|
+
mixSeed32(seed, 101),
|
|
6766
|
+
mixSeed32(seed, 103),
|
|
6767
|
+
mixSeed32(seed, 107),
|
|
6768
|
+
mixSeed32(seed, 109),
|
|
6769
|
+
mixSeed32(seed, 113),
|
|
6770
|
+
mixSeed32(seed, 127),
|
|
6771
|
+
mixSeed32(seed, 131),
|
|
6772
|
+
mixSeed32(seed, 137)
|
|
6773
|
+
];
|
|
6774
|
+
const latchByte = (words[0] ^ words[1]) & 255;
|
|
6775
|
+
if (latchByte === 0 || latchByte === 255) {
|
|
6776
|
+
words[1] = words[1] ^ 90 | 0;
|
|
6777
|
+
}
|
|
6778
|
+
return words;
|
|
6779
|
+
}
|
|
6780
|
+
function deriveColdLatchCoupling(seed) {
|
|
6781
|
+
const sfx = deriveColdFlowSuffix(seed);
|
|
6782
|
+
const initWords = deriveColdAliasInitWords(seed);
|
|
6783
|
+
const expectedLatchByte = (initWords[0] ^ initWords[1]) & 255;
|
|
6784
|
+
return {
|
|
6785
|
+
latchFnName: `_uLr${sfx}`,
|
|
6786
|
+
expectedLatchByte
|
|
6787
|
+
};
|
|
6788
|
+
}
|
|
6789
|
+
var NEUTRAL_DECOY_KEYS = [
|
|
6790
|
+
"telemetryOk",
|
|
6791
|
+
"retryBudget",
|
|
6792
|
+
"slotMask",
|
|
6793
|
+
"frameSeq",
|
|
5823
6794
|
"digestTag",
|
|
5824
6795
|
"phaseFlag",
|
|
5825
6796
|
"epochSync",
|
|
@@ -5838,6 +6809,26 @@ function mixSeed32(seed, salt) {
|
|
|
5838
6809
|
h ^= h >>> 16;
|
|
5839
6810
|
return h | 0;
|
|
5840
6811
|
}
|
|
6812
|
+
function modInverseUint32(oddValue) {
|
|
6813
|
+
const m = (oddValue | 1) >>> 0;
|
|
6814
|
+
let inv = 1;
|
|
6815
|
+
for (let i = 0; i < 5; i++) {
|
|
6816
|
+
inv = Math.imul(inv, 2 - Math.imul(m, inv) | 0) >>> 0;
|
|
6817
|
+
}
|
|
6818
|
+
return inv >>> 0;
|
|
6819
|
+
}
|
|
6820
|
+
function deriveAffineMbaParams(seed, salt) {
|
|
6821
|
+
let m = (mixSeed32(seed, salt) | 1) >>> 0;
|
|
6822
|
+
if (m === 1 || m === 4294967295 || m === 2654435769) {
|
|
6823
|
+
m = (m ^ 1540483477 | 1) >>> 0;
|
|
6824
|
+
}
|
|
6825
|
+
const m2 = Math.imul(m, 2) >>> 0;
|
|
6826
|
+
const mInv = modInverseUint32(m);
|
|
6827
|
+
let c = mixSeed32(seed, salt + 40503) >>> 0;
|
|
6828
|
+
if (c === 0) c = 668265263;
|
|
6829
|
+
const d = -Math.imul(mInv, c) >>> 0;
|
|
6830
|
+
return { m, m2, mInv, c, d };
|
|
6831
|
+
}
|
|
5841
6832
|
function cloneNode(node) {
|
|
5842
6833
|
return JSON.parse(JSON.stringify(node));
|
|
5843
6834
|
}
|
|
@@ -6300,14 +7291,14 @@ function makeSafeNumericParam(name) {
|
|
|
6300
7291
|
function buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn = false, ctxOpts) {
|
|
6301
7292
|
const candidates = [];
|
|
6302
7293
|
const seenNames = /* @__PURE__ */ new Set();
|
|
6303
|
-
const names = [..._nullishCoalesce(_optionalChain([ctxOpts, 'optionalAccess',
|
|
7294
|
+
const names = [..._nullishCoalesce(_optionalChain([ctxOpts, 'optionalAccess', _488 => _488.liveVars]), () => ( [])), ...extractParamNames(paramNode)];
|
|
6304
7295
|
for (const name of names) {
|
|
6305
7296
|
if (name && name !== "arguments" && name !== "eval" && !seenNames.has(name)) {
|
|
6306
7297
|
seenNames.add(name);
|
|
6307
7298
|
candidates.push(makeSafeNumericParam(name));
|
|
6308
7299
|
}
|
|
6309
7300
|
}
|
|
6310
|
-
if (_optionalChain([ctxOpts, 'optionalAccess',
|
|
7301
|
+
if (_optionalChain([ctxOpts, 'optionalAccess', _489 => _489.aliasIdentA]) && _optionalChain([ctxOpts, 'optionalAccess', _490 => _490.aliasIdentB])) {
|
|
6311
7302
|
const slot0 = fnIndex + 0 & 3;
|
|
6312
7303
|
const slot1 = fnIndex + 1 & 3;
|
|
6313
7304
|
candidates.push(makeBinary("|", makeMemberIndex(ctxOpts.aliasIdentA, makeLiteral(slot0)), makeLiteral(0)));
|
|
@@ -6385,6 +7376,14 @@ function makePropAccess(objExpr, propName) {
|
|
|
6385
7376
|
property: makeLiteral(propName)
|
|
6386
7377
|
};
|
|
6387
7378
|
}
|
|
7379
|
+
function makeSafeAliasRead(aliasIdent, slot) {
|
|
7380
|
+
return {
|
|
7381
|
+
type: "ConditionalExpression",
|
|
7382
|
+
test: makeBinary("<", makeUnary("typeof", { type: "Identifier", name: aliasIdent }), makeLiteral("u")),
|
|
7383
|
+
consequent: makeMemberIndex(aliasIdent, makeLiteral(slot)),
|
|
7384
|
+
alternate: makeLiteral(0)
|
|
7385
|
+
};
|
|
7386
|
+
}
|
|
6388
7387
|
function buildQnrBitExpr(qnrValRef, bitKind) {
|
|
6389
7388
|
const shiftAmt = bitKind === "xor1" ? 1 : 2;
|
|
6390
7389
|
const combOp = bitKind === "xor1" ? "^" : "|";
|
|
@@ -6399,22 +7398,22 @@ function buildQnrBitExpr(qnrValRef, bitKind) {
|
|
|
6399
7398
|
);
|
|
6400
7399
|
}
|
|
6401
7400
|
function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false, ctxOpts) {
|
|
6402
|
-
const domain = _nullishCoalesce(_optionalChain([ctxOpts, 'optionalAccess',
|
|
7401
|
+
const domain = _nullishCoalesce(_optionalChain([ctxOpts, 'optionalAccess', _491 => _491.returnDomain]), () => ( "object"));
|
|
6403
7402
|
const [x1, x2, x3, x4] = buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn, ctxOpts);
|
|
6404
7403
|
const mba4 = buildMba4Ast(seed, fnIndex, x1, x2, x3, x4);
|
|
6405
7404
|
const qnrFamilyIdx = ((seed ^ Math.imul(fnIndex + 1, 2654435761)) >>> 0) % QNR_RESIDUE_FAMILIES.length;
|
|
6406
7405
|
const qnrFamily = QNR_RESIDUE_FAMILIES[qnrFamilyIdx];
|
|
6407
|
-
const slotA = fnIndex + (seed &
|
|
6408
|
-
const slotB = slotA
|
|
6409
|
-
const hasAlias = Boolean(_optionalChain([ctxOpts, 'optionalAccess',
|
|
6410
|
-
const aliasReadIdent = _nullishCoalesce(_nullishCoalesce(_optionalChain([ctxOpts, 'optionalAccess',
|
|
7406
|
+
const slotA = 2 + (fnIndex + (seed & 1) & 1);
|
|
7407
|
+
const slotB = slotA ^ 1;
|
|
7408
|
+
const hasAlias = Boolean(_optionalChain([ctxOpts, 'optionalAccess', _492 => _492.aliasIdentA]));
|
|
7409
|
+
const aliasReadIdent = _nullishCoalesce(_nullishCoalesce(_optionalChain([ctxOpts, 'optionalAccess', _493 => _493.aliasIdentB]), () => ( _optionalChain([ctxOpts, 'optionalAccess', _494 => _494.aliasIdentA]))), () => ( ""));
|
|
6411
7410
|
let qnrLeft;
|
|
6412
7411
|
let qnrValForForm0;
|
|
6413
7412
|
let zRefForDecoy;
|
|
6414
7413
|
let aliasInvZero = null;
|
|
6415
|
-
if (_optionalChain([ctxOpts, 'optionalAccess',
|
|
7414
|
+
if (_optionalChain([ctxOpts, 'optionalAccess', _495 => _495.mxIdent]) && _optionalChain([ctxOpts, 'optionalAccess', _496 => _496.scratchVarIdent]) && hasAlias) {
|
|
6416
7415
|
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
6417
|
-
const names = [..._nullishCoalesce(_optionalChain([ctxOpts, 'optionalAccess',
|
|
7416
|
+
const names = [..._nullishCoalesce(_optionalChain([ctxOpts, 'optionalAccess', _497 => _497.liveVars]), () => ( [])), ...extractParamNames(paramNode)];
|
|
6418
7417
|
const uniqueNames = [];
|
|
6419
7418
|
for (const n of names) {
|
|
6420
7419
|
if (n && n !== "arguments" && n !== "eval" && !uniqueNames.includes(n)) {
|
|
@@ -6495,7 +7494,7 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6495
7494
|
]
|
|
6496
7495
|
};
|
|
6497
7496
|
zRefForDecoy = cloneNode(scratchId);
|
|
6498
|
-
} else if (_optionalChain([ctxOpts, 'optionalAccess',
|
|
7497
|
+
} else if (_optionalChain([ctxOpts, 'optionalAccess', _498 => _498.scratchVarIdent])) {
|
|
6499
7498
|
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
6500
7499
|
const rivestOnScratch = buildRivestPermAst(seed, fnIndex, scratchId);
|
|
6501
7500
|
const seqExprs = [
|
|
@@ -6585,8 +7584,9 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6585
7584
|
decoyIdent,
|
|
6586
7585
|
zRefForDecoy
|
|
6587
7586
|
);
|
|
6588
|
-
const hasShieldCoupling = Boolean(_optionalChain([ctxOpts, 'optionalAccess',
|
|
6589
|
-
const
|
|
7587
|
+
const hasShieldCoupling = Boolean(_optionalChain([ctxOpts, 'optionalAccess', _499 => _499.shieldCoupled]) && _optionalChain([ctxOpts, 'optionalAccess', _500 => _500.windowKeySymbol]));
|
|
7588
|
+
const predOffset = hasShieldCoupling ? 1 : (seed >>> 2) % 6;
|
|
7589
|
+
const predForm = ((fnIndex + predOffset) % 6 + 6) % 6;
|
|
6590
7590
|
let testExpr;
|
|
6591
7591
|
if (predForm === 0) {
|
|
6592
7592
|
let pathACore = qnrValForForm0;
|
|
@@ -6597,17 +7597,17 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6597
7597
|
pathACore = makeBinary(
|
|
6598
7598
|
"^",
|
|
6599
7599
|
pathACore,
|
|
6600
|
-
makeBinary("&",
|
|
7600
|
+
makeBinary("&", makeSafeAliasRead(aliasReadIdent, slotB), makeLiteral(1))
|
|
6601
7601
|
);
|
|
6602
7602
|
}
|
|
6603
|
-
const pathA = _optionalChain([ctxOpts, 'optionalAccess',
|
|
7603
|
+
const pathA = _optionalChain([ctxOpts, 'optionalAccess', _501 => _501.scratchVarIdent]) ? {
|
|
6604
7604
|
type: "SequenceExpression",
|
|
6605
7605
|
expressions: [...qnrLeft.expressions.slice(0, -1), pathACore]
|
|
6606
7606
|
} : pathACore;
|
|
6607
7607
|
const pathB = hasAlias ? makeBinary(
|
|
6608
7608
|
"^",
|
|
6609
7609
|
makeLiteral(qnrFamily.expectedBit),
|
|
6610
|
-
makeBinary("&",
|
|
7610
|
+
makeBinary("&", makeSafeAliasRead(ctxOpts.aliasIdentA, slotB), makeLiteral(1))
|
|
6611
7611
|
) : makeLiteral(qnrFamily.expectedBit);
|
|
6612
7612
|
testExpr = makeBinary("!==", makeBinary("^", pathA, pathB), makeLiteral(0));
|
|
6613
7613
|
} else if (predForm === 1) {
|
|
@@ -6654,354 +7654,1133 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6654
7654
|
right: tamperCheck
|
|
6655
7655
|
};
|
|
6656
7656
|
} else if (predForm === 2) {
|
|
6657
|
-
const slotReadB = hasAlias ? makeBinary("&",
|
|
6658
|
-
const slotWriteB = hasAlias ? makeBinary("&",
|
|
7657
|
+
const slotReadB = hasAlias ? makeBinary("&", makeSafeAliasRead(aliasReadIdent, slotB), makeLiteral(7)) : makeBinary("&", makeTypeofGlobalLen(), makeLiteral(7));
|
|
7658
|
+
const slotWriteB = hasAlias ? makeBinary("&", makeSafeAliasRead(ctxOpts.aliasIdentA, slotB), makeLiteral(7)) : makeBinary("&", makeTypeofGlobalLen(), makeLiteral(7));
|
|
6659
7659
|
let lhsExpr = makeBinary("+", qnrLeft, slotReadB);
|
|
6660
7660
|
if (aliasInvZero) {
|
|
6661
7661
|
lhsExpr = makeBinary("+", lhsExpr, makeBinary("&", aliasInvZero, makeLiteral(3)));
|
|
6662
7662
|
}
|
|
6663
7663
|
const rhsExpr = makeBinary("+", makeLiteral(qnrFamily.outBoundVal), slotWriteB);
|
|
6664
7664
|
testExpr = makeBinary(qnrFamily.outBoundOp, lhsExpr, rhsExpr);
|
|
6665
|
-
} else {
|
|
6666
|
-
const tagLhs = hasAlias ? makeBinary("&",
|
|
6667
|
-
const tagRhsBase = hasAlias ? makeBinary("&",
|
|
7665
|
+
} else if (predForm === 3) {
|
|
7666
|
+
const tagLhs = hasAlias ? makeBinary("&", makeSafeAliasRead(ctxOpts.aliasIdentA, slotB), makeLiteral(240)) : makeBinary("&", makeBinary("<<", makeTypeofGlobalLen(), makeLiteral(4)), makeLiteral(240));
|
|
7667
|
+
const tagRhsBase = hasAlias ? makeBinary("&", makeSafeAliasRead(aliasReadIdent, slotB), makeLiteral(240)) : makeBinary("&", makeBinary("<<", makeTypeofGlobalLen(), makeLiteral(4)), makeLiteral(240));
|
|
6668
7668
|
const tagRhs = aliasInvZero ? makeBinary("^", tagRhsBase, makeBinary("&", aliasInvZero, makeLiteral(15))) : tagRhsBase;
|
|
6669
7669
|
const lhsExpr = makeBinary("|", makeBinary("^", qnrLeft, tagLhs), makeLiteral(0));
|
|
6670
7670
|
const rhsExpr = makeBinary("|", makeBinary("^", makeLiteral(qnrFamily.target), tagRhs), makeLiteral(0));
|
|
6671
7671
|
testExpr = makeBinary("===", lhsExpr, rhsExpr);
|
|
7672
|
+
} else if (predForm === 4) {
|
|
7673
|
+
const k4 = mixSeed32(seed, fnIndex * 29 + 13) >>> 0 || 1;
|
|
7674
|
+
if (_optionalChain([ctxOpts, 'optionalAccess', _502 => _502.scratchVarIdent])) {
|
|
7675
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
7676
|
+
const preU = aliasInvZero ? makeBinary("^", cloneNode(scratchId), aliasInvZero) : cloneNode(scratchId);
|
|
7677
|
+
const uAssign = {
|
|
7678
|
+
type: "AssignmentExpression",
|
|
7679
|
+
operator: "=",
|
|
7680
|
+
left: cloneNode(scratchId),
|
|
7681
|
+
right: makeBinary(">>>", makeBinary("^", preU, makeLiteral(k4)), makeLiteral(0))
|
|
7682
|
+
};
|
|
7683
|
+
const uMinus1Lhs = makeBinary(">>>", makeBinary("-", cloneNode(scratchId), makeLiteral(1)), makeLiteral(0));
|
|
7684
|
+
const uMinus1Rhs = makeBinary(">>>", makeBinary("-", cloneNode(scratchId), makeLiteral(1)), makeLiteral(0));
|
|
7685
|
+
const orU = makeBinary(">>>", makeBinary("|", cloneNode(scratchId), uMinus1Lhs), makeLiteral(0));
|
|
7686
|
+
const xorU = makeBinary(">>>", makeBinary("^", cloneNode(scratchId), uMinus1Rhs), makeLiteral(0));
|
|
7687
|
+
const lhsSeq = {
|
|
7688
|
+
type: "SequenceExpression",
|
|
7689
|
+
expressions: [...qnrLeft.expressions.slice(0, -1), uAssign, orU]
|
|
7690
|
+
};
|
|
7691
|
+
testExpr = makeBinary("<", lhsSeq, xorU);
|
|
7692
|
+
} else {
|
|
7693
|
+
const uExpr = makeBinary(">>>", makeBinary("^", cloneNode(zRefForDecoy), makeLiteral(k4)), makeLiteral(0));
|
|
7694
|
+
const uMinus1Lhs = makeBinary(">>>", makeBinary("-", cloneNode(uExpr), makeLiteral(1)), makeLiteral(0));
|
|
7695
|
+
const uMinus1Rhs = makeBinary(">>>", makeBinary("-", cloneNode(uExpr), makeLiteral(1)), makeLiteral(0));
|
|
7696
|
+
const orU = makeBinary(">>>", makeBinary("|", cloneNode(uExpr), uMinus1Lhs), makeLiteral(0));
|
|
7697
|
+
const xorU = makeBinary(">>>", makeBinary("^", cloneNode(uExpr), uMinus1Rhs), makeLiteral(0));
|
|
7698
|
+
testExpr = makeBinary("<", orU, xorU);
|
|
7699
|
+
}
|
|
7700
|
+
} else {
|
|
7701
|
+
const k5 = mixSeed32(seed, fnIndex * 31 + 17) >>> 0 || 3;
|
|
7702
|
+
const { m, m2, mInv, c, d } = deriveAffineMbaParams(seed, fnIndex * 37 + 23);
|
|
7703
|
+
const buildAffineLhs = (valNode) => {
|
|
7704
|
+
const inner = makeBinary(
|
|
7705
|
+
"|",
|
|
7706
|
+
makeBinary(
|
|
7707
|
+
"+",
|
|
7708
|
+
makeBinary(
|
|
7709
|
+
"+",
|
|
7710
|
+
makeImul(makeLiteral(m), makeBinary("^", cloneNode(valNode), makeLiteral(k5))),
|
|
7711
|
+
makeImul(makeLiteral(m2), makeBinary("&", cloneNode(valNode), makeLiteral(k5)))
|
|
7712
|
+
),
|
|
7713
|
+
makeLiteral(c)
|
|
7714
|
+
),
|
|
7715
|
+
makeLiteral(0)
|
|
7716
|
+
);
|
|
7717
|
+
return makeBinary(
|
|
7718
|
+
"|",
|
|
7719
|
+
makeBinary("+", makeImul(makeLiteral(mInv), inner), makeLiteral(d)),
|
|
7720
|
+
makeLiteral(0)
|
|
7721
|
+
);
|
|
7722
|
+
};
|
|
7723
|
+
const buildAffineRhs = (valNode) => makeBinary("|", makeBinary("+", cloneNode(valNode), makeLiteral(k5)), makeLiteral(0));
|
|
7724
|
+
if (_optionalChain([ctxOpts, 'optionalAccess', _503 => _503.scratchVarIdent])) {
|
|
7725
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
7726
|
+
const preSeqs = [...qnrLeft.expressions.slice(0, -1)];
|
|
7727
|
+
if (aliasInvZero) {
|
|
7728
|
+
preSeqs.push({
|
|
7729
|
+
type: "AssignmentExpression",
|
|
7730
|
+
operator: "=",
|
|
7731
|
+
left: cloneNode(scratchId),
|
|
7732
|
+
right: makeBinary("|", makeBinary("^", cloneNode(scratchId), aliasInvZero), makeLiteral(0))
|
|
7733
|
+
});
|
|
7734
|
+
}
|
|
7735
|
+
const lhsSeq = {
|
|
7736
|
+
type: "SequenceExpression",
|
|
7737
|
+
expressions: [...preSeqs, buildAffineLhs(scratchId)]
|
|
7738
|
+
};
|
|
7739
|
+
testExpr = makeBinary("!==", lhsSeq, buildAffineRhs(scratchId));
|
|
7740
|
+
} else {
|
|
7741
|
+
testExpr = makeBinary("!==", buildAffineLhs(zRefForDecoy), buildAffineRhs(zRefForDecoy));
|
|
7742
|
+
}
|
|
7743
|
+
}
|
|
7744
|
+
return {
|
|
7745
|
+
type: "IfStatement",
|
|
7746
|
+
test: testExpr,
|
|
7747
|
+
consequent,
|
|
7748
|
+
alternate: null
|
|
7749
|
+
};
|
|
7750
|
+
}
|
|
7751
|
+
function inferFunctionReturnDomain(fnNode) {
|
|
7752
|
+
let hasReturnArg = false;
|
|
7753
|
+
let seenNumber = false;
|
|
7754
|
+
let seenBoolean = false;
|
|
7755
|
+
let seenString = false;
|
|
7756
|
+
let seenObject = false;
|
|
7757
|
+
function scanStmts(node) {
|
|
7758
|
+
if (!node || typeof node !== "object") return;
|
|
7759
|
+
if (Array.isArray(node)) {
|
|
7760
|
+
for (const item of node) scanStmts(item);
|
|
7761
|
+
return;
|
|
7762
|
+
}
|
|
7763
|
+
if (node !== fnNode && (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression")) {
|
|
7764
|
+
return;
|
|
7765
|
+
}
|
|
7766
|
+
if (node.type === "ReturnStatement") {
|
|
7767
|
+
if (!node.argument) return;
|
|
7768
|
+
hasReturnArg = true;
|
|
7769
|
+
const arg = node.argument;
|
|
7770
|
+
if (arg.type === "Literal") {
|
|
7771
|
+
if (typeof arg.value === "number") seenNumber = true;
|
|
7772
|
+
else if (typeof arg.value === "boolean") seenBoolean = true;
|
|
7773
|
+
else if (typeof arg.value === "string") seenString = true;
|
|
7774
|
+
} else if (arg.type === "ObjectExpression" || arg.type === "ArrayExpression") {
|
|
7775
|
+
seenObject = true;
|
|
7776
|
+
} else if (arg.type === "BinaryExpression") {
|
|
7777
|
+
if (["===", "!==", "==", "!=", "<", ">", "<=", ">=", "in", "instanceof"].includes(arg.operator)) {
|
|
7778
|
+
seenBoolean = true;
|
|
7779
|
+
} else if (arg.operator !== "+") {
|
|
7780
|
+
seenNumber = true;
|
|
7781
|
+
}
|
|
7782
|
+
} else if (arg.type === "UnaryExpression") {
|
|
7783
|
+
if (arg.operator === "!") seenBoolean = true;
|
|
7784
|
+
else if (arg.operator === "typeof") seenString = true;
|
|
7785
|
+
else if (arg.operator === "-" || arg.operator === "+" || arg.operator === "~") seenNumber = true;
|
|
7786
|
+
}
|
|
7787
|
+
return;
|
|
7788
|
+
}
|
|
7789
|
+
for (const key of Object.keys(node)) {
|
|
7790
|
+
if (key === "loc" || key === "range") continue;
|
|
7791
|
+
const val = node[key];
|
|
7792
|
+
if (val && typeof val === "object") {
|
|
7793
|
+
scanStmts(val);
|
|
7794
|
+
}
|
|
7795
|
+
}
|
|
7796
|
+
}
|
|
7797
|
+
scanStmts(fnNode.body);
|
|
7798
|
+
if (!hasReturnArg && _optionalChain([fnNode, 'access', _504 => _504.body, 'optionalAccess', _505 => _505.type]) === "BlockStatement") return "void";
|
|
7799
|
+
if (seenObject) return "object";
|
|
7800
|
+
if (seenBoolean && !seenNumber && !seenString) return "boolean";
|
|
7801
|
+
if (seenNumber && !seenBoolean && !seenString) return "number";
|
|
7802
|
+
if (seenString && !seenNumber && !seenBoolean) return "string";
|
|
7803
|
+
return "object";
|
|
7804
|
+
}
|
|
7805
|
+
function buildSboxInitExpression(seed) {
|
|
7806
|
+
return acorn5.parseExpressionAt(
|
|
7807
|
+
`(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;})()`,
|
|
7808
|
+
0,
|
|
7809
|
+
{ ecmaVersion: "latest" }
|
|
7810
|
+
);
|
|
7811
|
+
}
|
|
7812
|
+
function createColdFlowRuntimeDeclarations(sboxIdent, aliasIdentA, aliasIdentB, scratchVarIdent, seed, latchFnName, mxIdent) {
|
|
7813
|
+
const sboxInit = buildSboxInitExpression(seed);
|
|
7814
|
+
const initWords = deriveColdAliasInitWords(seed);
|
|
7815
|
+
const wordsArrayExpr = {
|
|
7816
|
+
type: "ArrayExpression",
|
|
7817
|
+
elements: initWords.map((v) => makeInt32Literal(v))
|
|
7818
|
+
};
|
|
7819
|
+
const newArrayBuffer32 = {
|
|
7820
|
+
type: "NewExpression",
|
|
7821
|
+
callee: { type: "Identifier", name: "ArrayBuffer" },
|
|
7822
|
+
arguments: [makeLiteral(32)]
|
|
7823
|
+
};
|
|
7824
|
+
const declarations = [
|
|
7825
|
+
{
|
|
7826
|
+
type: "VariableDeclarator",
|
|
7827
|
+
id: { type: "Identifier", name: sboxIdent },
|
|
7828
|
+
init: sboxInit
|
|
7829
|
+
},
|
|
7830
|
+
{
|
|
7831
|
+
type: "VariableDeclarator",
|
|
7832
|
+
id: { type: "Identifier", name: aliasIdentA },
|
|
7833
|
+
init: {
|
|
7834
|
+
type: "NewExpression",
|
|
7835
|
+
callee: { type: "Identifier", name: "Uint32Array" },
|
|
7836
|
+
arguments: [newArrayBuffer32]
|
|
7837
|
+
}
|
|
7838
|
+
},
|
|
7839
|
+
{
|
|
7840
|
+
type: "VariableDeclarator",
|
|
7841
|
+
id: { type: "Identifier", name: aliasIdentB },
|
|
7842
|
+
init: {
|
|
7843
|
+
type: "NewExpression",
|
|
7844
|
+
callee: { type: "Identifier", name: "Int32Array" },
|
|
7845
|
+
arguments: [
|
|
7846
|
+
{
|
|
7847
|
+
type: "MemberExpression",
|
|
7848
|
+
computed: false,
|
|
7849
|
+
object: { type: "Identifier", name: aliasIdentA },
|
|
7850
|
+
property: { type: "Identifier", name: "buffer" }
|
|
7851
|
+
}
|
|
7852
|
+
]
|
|
7853
|
+
}
|
|
7854
|
+
},
|
|
7855
|
+
{
|
|
7856
|
+
type: "VariableDeclarator",
|
|
7857
|
+
id: { type: "Identifier", name: scratchVarIdent },
|
|
7858
|
+
init: makeLiteral(0)
|
|
7859
|
+
}
|
|
7860
|
+
];
|
|
7861
|
+
const varDecl = {
|
|
7862
|
+
type: "VariableDeclaration",
|
|
7863
|
+
kind: "var",
|
|
7864
|
+
declarations
|
|
7865
|
+
};
|
|
7866
|
+
const aliasInitStmt = {
|
|
7867
|
+
type: "ExpressionStatement",
|
|
7868
|
+
expression: {
|
|
7869
|
+
type: "CallExpression",
|
|
7870
|
+
callee: {
|
|
7871
|
+
type: "MemberExpression",
|
|
7872
|
+
computed: false,
|
|
7873
|
+
object: { type: "Identifier", name: aliasIdentB },
|
|
7874
|
+
property: { type: "Identifier", name: "set" }
|
|
7875
|
+
},
|
|
7876
|
+
arguments: [cloneNode(wordsArrayExpr)],
|
|
7877
|
+
optional: false
|
|
7878
|
+
}
|
|
7879
|
+
};
|
|
7880
|
+
const wordsList = initWords.map((w) => w | 0).join(",");
|
|
7881
|
+
const latchFnParsed = acorn5.parse(
|
|
7882
|
+
`function ${latchFnName}(){try{return(${aliasIdentA}!==void 0&&${aliasIdentB}!==void 0)||(${aliasIdentA}=new Uint32Array(new ArrayBuffer(32)),${aliasIdentB}=new Int32Array(${aliasIdentA}.buffer),${aliasIdentB}.set([${wordsList}])),((${aliasIdentA}[0]^${aliasIdentB}[1])&255)}catch(e){return -1}}`,
|
|
7883
|
+
{ ecmaVersion: "latest", sourceType: "script" }
|
|
7884
|
+
);
|
|
7885
|
+
const latchFnDecl = latchFnParsed.body[0];
|
|
7886
|
+
let mxFnDecl;
|
|
7887
|
+
if (mxIdent) {
|
|
7888
|
+
const mbaAst = buildMba4Ast(
|
|
7889
|
+
seed,
|
|
7890
|
+
0,
|
|
7891
|
+
{ type: "Identifier", name: "$u" },
|
|
7892
|
+
{ type: "Identifier", name: "$v" },
|
|
7893
|
+
{ type: "Identifier", name: "$p" },
|
|
7894
|
+
{ type: "Identifier", name: "$q" }
|
|
7895
|
+
);
|
|
7896
|
+
const slotExpr = makeBinary("+", makeLiteral(2), makeBinary("&", { type: "Identifier", name: "$c" }, makeLiteral(1)));
|
|
7897
|
+
const lazyAliasGuard = {
|
|
7898
|
+
type: "ExpressionStatement",
|
|
7899
|
+
expression: {
|
|
7900
|
+
type: "LogicalExpression",
|
|
7901
|
+
operator: "||",
|
|
7902
|
+
left: {
|
|
7903
|
+
type: "LogicalExpression",
|
|
7904
|
+
operator: "&&",
|
|
7905
|
+
left: makeBinary("!==", { type: "Identifier", name: aliasIdentA }, makeUnary("void", makeLiteral(0))),
|
|
7906
|
+
right: makeBinary("!==", { type: "Identifier", name: aliasIdentB }, makeUnary("void", makeLiteral(0)))
|
|
7907
|
+
},
|
|
7908
|
+
right: {
|
|
7909
|
+
type: "LogicalExpression",
|
|
7910
|
+
operator: "||",
|
|
7911
|
+
left: makeBinary("!==", makeUnary("typeof", { type: "Identifier", name: latchFnName }), makeLiteral("function")),
|
|
7912
|
+
right: {
|
|
7913
|
+
type: "CallExpression",
|
|
7914
|
+
callee: { type: "Identifier", name: latchFnName },
|
|
7915
|
+
arguments: [],
|
|
7916
|
+
optional: false
|
|
7917
|
+
}
|
|
7918
|
+
}
|
|
7919
|
+
}
|
|
7920
|
+
};
|
|
7921
|
+
const lazySboxGuard = {
|
|
7922
|
+
type: "ExpressionStatement",
|
|
7923
|
+
expression: {
|
|
7924
|
+
type: "LogicalExpression",
|
|
7925
|
+
operator: "||",
|
|
7926
|
+
left: { type: "Identifier", name: sboxIdent },
|
|
7927
|
+
right: {
|
|
7928
|
+
type: "AssignmentExpression",
|
|
7929
|
+
operator: "=",
|
|
7930
|
+
left: { type: "Identifier", name: sboxIdent },
|
|
7931
|
+
right: buildSboxInitExpression(seed)
|
|
7932
|
+
}
|
|
7933
|
+
}
|
|
7934
|
+
};
|
|
7935
|
+
mxFnDecl = {
|
|
7936
|
+
type: "FunctionDeclaration",
|
|
7937
|
+
id: { type: "Identifier", name: mxIdent },
|
|
7938
|
+
params: [
|
|
7939
|
+
{ type: "Identifier", name: "$a" },
|
|
7940
|
+
{ type: "Identifier", name: "$b" },
|
|
7941
|
+
{ type: "Identifier", name: "$c" },
|
|
7942
|
+
{ type: "Identifier", name: "$d" },
|
|
7943
|
+
{ type: "Identifier", name: "$e" },
|
|
7944
|
+
{ type: "Identifier", name: "$f" },
|
|
7945
|
+
{ type: "Identifier", name: "$g" },
|
|
7946
|
+
{ type: "Identifier", name: "$h" },
|
|
7947
|
+
{ type: "Identifier", name: "$i" }
|
|
7948
|
+
],
|
|
7949
|
+
body: {
|
|
7950
|
+
type: "BlockStatement",
|
|
7951
|
+
body: [
|
|
7952
|
+
{
|
|
7953
|
+
type: "TryStatement",
|
|
7954
|
+
block: {
|
|
7955
|
+
type: "BlockStatement",
|
|
7956
|
+
body: [
|
|
7957
|
+
lazyAliasGuard,
|
|
7958
|
+
lazySboxGuard,
|
|
7959
|
+
{
|
|
7960
|
+
type: "VariableDeclaration",
|
|
7961
|
+
kind: "var",
|
|
7962
|
+
declarations: [
|
|
7963
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$s" }, init: slotExpr },
|
|
7964
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$u" }, init: makeBinary("|", { type: "Identifier", name: "$a" }, makeLiteral(0)) },
|
|
7965
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$v" }, init: makeBinary("|", { type: "Identifier", name: "$b" }, makeLiteral(0)) },
|
|
7966
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$p" }, init: makeBinary("|", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$s" }), makeLiteral(0)) },
|
|
7967
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$q" }, init: makeBinary("|", makeMemberIndex(aliasIdentB, { type: "Identifier", name: "$d" }), makeLiteral(0)) },
|
|
7968
|
+
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$z" }, init: mbaAst }
|
|
7969
|
+
]
|
|
7970
|
+
},
|
|
7971
|
+
{
|
|
7972
|
+
type: "ExpressionStatement",
|
|
7973
|
+
expression: {
|
|
7974
|
+
type: "AssignmentExpression",
|
|
7975
|
+
operator: "=",
|
|
7976
|
+
left: { type: "Identifier", name: "$z" },
|
|
7977
|
+
right: makeBinary(
|
|
7978
|
+
"|",
|
|
7979
|
+
makeBinary(
|
|
7980
|
+
"+",
|
|
7981
|
+
{ type: "Identifier", name: "$f" },
|
|
7982
|
+
makeImul(
|
|
7983
|
+
{ type: "Identifier", name: "$z" },
|
|
7984
|
+
makeBinary(
|
|
7985
|
+
"+",
|
|
7986
|
+
{ type: "Identifier", name: "$g" },
|
|
7987
|
+
makeImul(
|
|
7988
|
+
{ type: "Identifier", name: "$z" },
|
|
7989
|
+
makeBinary(
|
|
7990
|
+
"+",
|
|
7991
|
+
{ type: "Identifier", name: "$h" },
|
|
7992
|
+
makeImul({ type: "Identifier", name: "$z" }, { type: "Identifier", name: "$i" })
|
|
7993
|
+
)
|
|
7994
|
+
)
|
|
7995
|
+
)
|
|
7996
|
+
)
|
|
7997
|
+
),
|
|
7998
|
+
makeLiteral(0)
|
|
7999
|
+
)
|
|
8000
|
+
}
|
|
8001
|
+
},
|
|
8002
|
+
{
|
|
8003
|
+
type: "ExpressionStatement",
|
|
8004
|
+
expression: {
|
|
8005
|
+
type: "AssignmentExpression",
|
|
8006
|
+
operator: "=",
|
|
8007
|
+
left: { type: "Identifier", name: "$z" },
|
|
8008
|
+
right: buildSboxMixAst(sboxIdent, "$z")
|
|
8009
|
+
}
|
|
8010
|
+
},
|
|
8011
|
+
{
|
|
8012
|
+
type: "VariableDeclaration",
|
|
8013
|
+
kind: "var",
|
|
8014
|
+
declarations: [
|
|
8015
|
+
{
|
|
8016
|
+
type: "VariableDeclarator",
|
|
8017
|
+
id: { type: "Identifier", name: "$m" },
|
|
8018
|
+
init: makeBinary("^", makeBinary("<<", { type: "Identifier", name: "$z" }, makeLiteral(3)), { type: "Identifier", name: "$e" })
|
|
8019
|
+
}
|
|
8020
|
+
]
|
|
8021
|
+
},
|
|
8022
|
+
{
|
|
8023
|
+
type: "ExpressionStatement",
|
|
8024
|
+
expression: {
|
|
8025
|
+
type: "AssignmentExpression",
|
|
8026
|
+
operator: "=",
|
|
8027
|
+
left: makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$s" }),
|
|
8028
|
+
right: makeBinary("|", makeBinary("^", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$s" }), { type: "Identifier", name: "$m" }), makeLiteral(0))
|
|
8029
|
+
}
|
|
8030
|
+
},
|
|
8031
|
+
{
|
|
8032
|
+
type: "VariableDeclaration",
|
|
8033
|
+
kind: "var",
|
|
8034
|
+
declarations: [
|
|
8035
|
+
{
|
|
8036
|
+
type: "VariableDeclarator",
|
|
8037
|
+
id: { type: "Identifier", name: "$w" },
|
|
8038
|
+
init: makeBinary(
|
|
8039
|
+
"^",
|
|
8040
|
+
makeBinary("|", makeBinary("^", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$s" }), { type: "Identifier", name: "$m" }), makeLiteral(0)),
|
|
8041
|
+
{
|
|
8042
|
+
type: "AssignmentExpression",
|
|
8043
|
+
operator: "=",
|
|
8044
|
+
left: makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$s" }),
|
|
8045
|
+
right: makeBinary("|", makeBinary("^", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$s" }), { type: "Identifier", name: "$m" }), makeLiteral(0))
|
|
8046
|
+
}
|
|
8047
|
+
)
|
|
8048
|
+
}
|
|
8049
|
+
]
|
|
8050
|
+
},
|
|
8051
|
+
{
|
|
8052
|
+
type: "ReturnStatement",
|
|
8053
|
+
argument: {
|
|
8054
|
+
type: "AssignmentExpression",
|
|
8055
|
+
operator: "=",
|
|
8056
|
+
left: { type: "Identifier", name: scratchVarIdent },
|
|
8057
|
+
right: makeBinary("|", makeBinary("^", { type: "Identifier", name: "$z" }, { type: "Identifier", name: "$w" }), makeLiteral(0))
|
|
8058
|
+
}
|
|
8059
|
+
}
|
|
8060
|
+
]
|
|
8061
|
+
},
|
|
8062
|
+
handler: {
|
|
8063
|
+
type: "CatchClause",
|
|
8064
|
+
param: { type: "Identifier", name: "$e" },
|
|
8065
|
+
body: {
|
|
8066
|
+
type: "BlockStatement",
|
|
8067
|
+
body: [{ type: "ReturnStatement", argument: makeLiteral(0) }]
|
|
8068
|
+
}
|
|
8069
|
+
},
|
|
8070
|
+
finalizer: null
|
|
8071
|
+
}
|
|
8072
|
+
]
|
|
8073
|
+
},
|
|
8074
|
+
generator: false,
|
|
8075
|
+
async: false,
|
|
8076
|
+
expression: false
|
|
8077
|
+
};
|
|
8078
|
+
}
|
|
8079
|
+
return {
|
|
8080
|
+
varDecl,
|
|
8081
|
+
aliasInitStmt,
|
|
8082
|
+
latchFnDecl,
|
|
8083
|
+
...mxFnDecl ? { mxFnDecl } : {}
|
|
8084
|
+
};
|
|
8085
|
+
}
|
|
8086
|
+
var MAX_COLD_GUARDS_PER_CHUNK = 12;
|
|
8087
|
+
var MAX_COLD_BITWISE_MBA_PER_CHUNK = 8;
|
|
8088
|
+
var BITWISE_MBA_OPS = /* @__PURE__ */ new Set(["^", "|", "&"]);
|
|
8089
|
+
var BITWISE_LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
8090
|
+
"ForStatement",
|
|
8091
|
+
"WhileStatement",
|
|
8092
|
+
"DoWhileStatement",
|
|
8093
|
+
"ForInStatement",
|
|
8094
|
+
"ForOfStatement"
|
|
8095
|
+
]);
|
|
8096
|
+
var BITWISE_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
8097
|
+
"FunctionDeclaration",
|
|
8098
|
+
"FunctionExpression",
|
|
8099
|
+
"ArrowFunctionExpression"
|
|
8100
|
+
]);
|
|
8101
|
+
var BITWISE_LEXICAL_SCOPE_TYPES = /* @__PURE__ */ new Set([
|
|
8102
|
+
"Program",
|
|
8103
|
+
"FunctionDeclaration",
|
|
8104
|
+
"FunctionExpression",
|
|
8105
|
+
"ArrowFunctionExpression",
|
|
8106
|
+
"BlockStatement",
|
|
8107
|
+
"ForStatement",
|
|
8108
|
+
"ForInStatement",
|
|
8109
|
+
"ForOfStatement",
|
|
8110
|
+
"SwitchStatement",
|
|
8111
|
+
"CatchClause",
|
|
8112
|
+
"StaticBlock"
|
|
8113
|
+
]);
|
|
8114
|
+
var FORBIDDEN_BITWISE_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
8115
|
+
"arguments",
|
|
8116
|
+
"eval",
|
|
8117
|
+
"undefined",
|
|
8118
|
+
"NaN",
|
|
8119
|
+
"Infinity",
|
|
8120
|
+
"globalThis",
|
|
8121
|
+
"window",
|
|
8122
|
+
"self",
|
|
8123
|
+
"Math",
|
|
8124
|
+
"BigInt"
|
|
8125
|
+
]);
|
|
8126
|
+
function collectBoundPatternNames(pattern, out) {
|
|
8127
|
+
if (!pattern || typeof pattern !== "object") return;
|
|
8128
|
+
switch (pattern.type) {
|
|
8129
|
+
case "Identifier":
|
|
8130
|
+
out.push(pattern.name);
|
|
8131
|
+
break;
|
|
8132
|
+
case "AssignmentPattern":
|
|
8133
|
+
collectBoundPatternNames(pattern.left, out);
|
|
8134
|
+
break;
|
|
8135
|
+
case "RestElement":
|
|
8136
|
+
collectBoundPatternNames(pattern.argument, out);
|
|
8137
|
+
break;
|
|
8138
|
+
case "ArrayPattern":
|
|
8139
|
+
for (const el of pattern.elements || []) {
|
|
8140
|
+
if (el) collectBoundPatternNames(el, out);
|
|
8141
|
+
}
|
|
8142
|
+
break;
|
|
8143
|
+
case "ObjectPattern":
|
|
8144
|
+
for (const prop of pattern.properties || []) {
|
|
8145
|
+
if (prop.type === "Property") {
|
|
8146
|
+
collectBoundPatternNames(prop.value, out);
|
|
8147
|
+
} else if (prop.type === "RestElement") {
|
|
8148
|
+
collectBoundPatternNames(prop.argument, out);
|
|
8149
|
+
}
|
|
8150
|
+
}
|
|
8151
|
+
break;
|
|
8152
|
+
}
|
|
8153
|
+
}
|
|
8154
|
+
function analyzeBitwiseMbaScopes(ast) {
|
|
8155
|
+
const scopeBindings = /* @__PURE__ */ new Map();
|
|
8156
|
+
let unsafe = false;
|
|
8157
|
+
const addBinding = (scopeNode, name) => {
|
|
8158
|
+
if (name === "Math") {
|
|
8159
|
+
unsafe = true;
|
|
8160
|
+
return;
|
|
8161
|
+
}
|
|
8162
|
+
let set = scopeBindings.get(scopeNode);
|
|
8163
|
+
if (!set) {
|
|
8164
|
+
set = /* @__PURE__ */ new Set();
|
|
8165
|
+
scopeBindings.set(scopeNode, set);
|
|
8166
|
+
}
|
|
8167
|
+
set.add(name);
|
|
8168
|
+
};
|
|
8169
|
+
const scopeStack = [];
|
|
8170
|
+
const varTargetStack = [];
|
|
8171
|
+
const getNearestLexicalScope = () => _nullishCoalesce(scopeStack[scopeStack.length - 1], () => ( ast));
|
|
8172
|
+
const getNearestVarScope = () => _nullishCoalesce(varTargetStack[varTargetStack.length - 1], () => ( ast));
|
|
8173
|
+
function scan(node) {
|
|
8174
|
+
if (unsafe || !node || typeof node !== "object" || typeof node.type !== "string") {
|
|
8175
|
+
return;
|
|
8176
|
+
}
|
|
8177
|
+
if (node.type === "WithStatement") {
|
|
8178
|
+
unsafe = true;
|
|
8179
|
+
return;
|
|
8180
|
+
}
|
|
8181
|
+
if (node.type === "Literal" && (typeof node.value === "bigint" || typeof node.bigint === "string") || node.type === "BigIntLiteral") {
|
|
8182
|
+
unsafe = true;
|
|
8183
|
+
return;
|
|
8184
|
+
}
|
|
8185
|
+
if (node.type === "Identifier" && node.name === "BigInt") {
|
|
8186
|
+
unsafe = true;
|
|
8187
|
+
return;
|
|
8188
|
+
}
|
|
8189
|
+
if (node.type === "ImportSpecifier" || node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier") {
|
|
8190
|
+
if (_optionalChain([node, 'access', _506 => _506.local, 'optionalAccess', _507 => _507.type]) === "Identifier") {
|
|
8191
|
+
addBinding(ast, node.local.name);
|
|
8192
|
+
}
|
|
8193
|
+
} else if (node.type === "FunctionDeclaration") {
|
|
8194
|
+
if (_optionalChain([node, 'access', _508 => _508.id, 'optionalAccess', _509 => _509.type]) === "Identifier") {
|
|
8195
|
+
addBinding(getNearestLexicalScope(), node.id.name);
|
|
8196
|
+
addBinding(getNearestVarScope(), node.id.name);
|
|
8197
|
+
}
|
|
8198
|
+
} else if (node.type === "ClassDeclaration") {
|
|
8199
|
+
if (_optionalChain([node, 'access', _510 => _510.id, 'optionalAccess', _511 => _511.type]) === "Identifier") {
|
|
8200
|
+
addBinding(getNearestLexicalScope(), node.id.name);
|
|
8201
|
+
}
|
|
8202
|
+
} else if (node.type === "VariableDeclaration") {
|
|
8203
|
+
const targetScope = node.kind === "var" ? getNearestVarScope() : getNearestLexicalScope();
|
|
8204
|
+
for (const decl of node.declarations || []) {
|
|
8205
|
+
const names = [];
|
|
8206
|
+
collectBoundPatternNames(decl.id, names);
|
|
8207
|
+
for (const name of names) {
|
|
8208
|
+
addBinding(targetScope, name);
|
|
8209
|
+
}
|
|
8210
|
+
}
|
|
8211
|
+
}
|
|
8212
|
+
if (unsafe) return;
|
|
8213
|
+
const pushesLexical = BITWISE_LEXICAL_SCOPE_TYPES.has(node.type);
|
|
8214
|
+
const isFn = BITWISE_FUNCTION_TYPES.has(node.type);
|
|
8215
|
+
const isStaticBlock = node.type === "StaticBlock";
|
|
8216
|
+
if (pushesLexical) {
|
|
8217
|
+
scopeStack.push(node);
|
|
8218
|
+
if (!scopeBindings.has(node)) {
|
|
8219
|
+
scopeBindings.set(node, /* @__PURE__ */ new Set());
|
|
8220
|
+
}
|
|
8221
|
+
}
|
|
8222
|
+
if (isFn) {
|
|
8223
|
+
if (_optionalChain([node, 'access', _512 => _512.id, 'optionalAccess', _513 => _513.type]) === "Identifier") {
|
|
8224
|
+
addBinding(node, node.id.name);
|
|
8225
|
+
}
|
|
8226
|
+
for (const param of node.params || []) {
|
|
8227
|
+
const names = [];
|
|
8228
|
+
collectBoundPatternNames(param, names);
|
|
8229
|
+
for (const name of names) {
|
|
8230
|
+
addBinding(node, name);
|
|
8231
|
+
}
|
|
8232
|
+
}
|
|
8233
|
+
const bodyScope = _optionalChain([node, 'access', _514 => _514.body, 'optionalAccess', _515 => _515.type]) === "BlockStatement" ? node.body : node;
|
|
8234
|
+
varTargetStack.push(bodyScope);
|
|
8235
|
+
} else if (node.type === "Program" || isStaticBlock) {
|
|
8236
|
+
varTargetStack.push(node);
|
|
8237
|
+
} else if (node.type === "CatchClause" && node.param) {
|
|
8238
|
+
const names = [];
|
|
8239
|
+
collectBoundPatternNames(node.param, names);
|
|
8240
|
+
for (const name of names) {
|
|
8241
|
+
addBinding(node, name);
|
|
8242
|
+
}
|
|
8243
|
+
} else if (node.type === "ClassExpression" && _optionalChain([node, 'access', _516 => _516.id, 'optionalAccess', _517 => _517.type]) === "Identifier") {
|
|
8244
|
+
addBinding(node, node.id.name);
|
|
8245
|
+
}
|
|
8246
|
+
try {
|
|
8247
|
+
for (const key of Object.keys(node)) {
|
|
8248
|
+
if (key === "loc" || key === "range" || key === "start" || key === "end" || key === "comments" || key === "tokens") {
|
|
8249
|
+
continue;
|
|
8250
|
+
}
|
|
8251
|
+
const child = node[key];
|
|
8252
|
+
if (Array.isArray(child)) {
|
|
8253
|
+
for (const item of child) {
|
|
8254
|
+
scan(item);
|
|
8255
|
+
if (unsafe) return;
|
|
8256
|
+
}
|
|
8257
|
+
} else if (child && typeof child === "object") {
|
|
8258
|
+
scan(child);
|
|
8259
|
+
if (unsafe) return;
|
|
8260
|
+
}
|
|
8261
|
+
}
|
|
8262
|
+
} finally {
|
|
8263
|
+
if (isFn || node.type === "Program" || isStaticBlock) {
|
|
8264
|
+
varTargetStack.pop();
|
|
8265
|
+
}
|
|
8266
|
+
if (pushesLexical) {
|
|
8267
|
+
scopeStack.pop();
|
|
8268
|
+
}
|
|
8269
|
+
}
|
|
8270
|
+
}
|
|
8271
|
+
scan(ast);
|
|
8272
|
+
return { unsafe, scopeBindings };
|
|
8273
|
+
}
|
|
8274
|
+
function isSafeAtomicIntegerLiteral(node) {
|
|
8275
|
+
return Boolean(
|
|
8276
|
+
node && node.type === "Literal" && typeof node.value === "number" && Number.isInteger(node.value) && node.value >= 0 && node.value <= 4294967295
|
|
8277
|
+
);
|
|
8278
|
+
}
|
|
8279
|
+
function isZeroNumericLiteral(node) {
|
|
8280
|
+
return Boolean(node && node.type === "Literal" && typeof node.value === "number" && node.value === 0);
|
|
8281
|
+
}
|
|
8282
|
+
function isLocalBoundIdentifier(node, scopeStack, scopeBindings, programNode) {
|
|
8283
|
+
if (!node || node.type !== "Identifier") return false;
|
|
8284
|
+
if (FORBIDDEN_BITWISE_IDENTIFIERS.has(node.name)) return false;
|
|
8285
|
+
for (let i = scopeStack.length - 1; i >= 0; i--) {
|
|
8286
|
+
const scopeNode = scopeStack[i];
|
|
8287
|
+
if (scopeNode === programNode) return false;
|
|
8288
|
+
const bindings = scopeBindings.get(scopeNode);
|
|
8289
|
+
if (bindings && bindings.has(node.name)) {
|
|
8290
|
+
return true;
|
|
8291
|
+
}
|
|
8292
|
+
}
|
|
8293
|
+
return false;
|
|
8294
|
+
}
|
|
8295
|
+
function buildColdBitwiseConditional(op, left, right, seed, subIndex, hotExemptNodes) {
|
|
8296
|
+
const { m, mInv, c, d } = deriveAffineMbaParams(seed, 16640 + subIndex * 43);
|
|
8297
|
+
const a1 = cloneNode(left);
|
|
8298
|
+
const b1 = cloneNode(right);
|
|
8299
|
+
const a2 = cloneNode(left);
|
|
8300
|
+
const b2 = cloneNode(right);
|
|
8301
|
+
let affineComb;
|
|
8302
|
+
if (op === "^") {
|
|
8303
|
+
affineComb = makeBinary(
|
|
8304
|
+
"-",
|
|
8305
|
+
makeImul(makeLiteral(m), makeBinary("|", a1, b1)),
|
|
8306
|
+
makeImul(makeLiteral(m), makeBinary("&", a2, b2))
|
|
8307
|
+
);
|
|
8308
|
+
} else if (op === "|") {
|
|
8309
|
+
affineComb = makeBinary(
|
|
8310
|
+
"+",
|
|
8311
|
+
makeImul(makeLiteral(m), makeBinary("&", a1, b1)),
|
|
8312
|
+
makeImul(makeLiteral(m), makeBinary("^", a2, b2))
|
|
8313
|
+
);
|
|
8314
|
+
} else {
|
|
8315
|
+
affineComb = makeBinary(
|
|
8316
|
+
"-",
|
|
8317
|
+
makeImul(makeLiteral(m), makeBinary("|", a1, b1)),
|
|
8318
|
+
makeImul(makeLiteral(m), makeBinary("^", a2, b2))
|
|
8319
|
+
);
|
|
8320
|
+
}
|
|
8321
|
+
const innerWithC = makeBinary("|", makeBinary("+", affineComb, makeLiteral(c)), makeLiteral(0));
|
|
8322
|
+
const consequent = makeBinary(
|
|
8323
|
+
"|",
|
|
8324
|
+
makeBinary("+", makeImul(makeLiteral(mInv), innerWithC), makeLiteral(d)),
|
|
8325
|
+
makeLiteral(0)
|
|
8326
|
+
);
|
|
8327
|
+
const alternate = makeBinary(op, cloneNode(left), cloneNode(right));
|
|
8328
|
+
const exemptNodes = [];
|
|
8329
|
+
const uniqueIdents = [];
|
|
8330
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
8331
|
+
for (const operand of [left, right]) {
|
|
8332
|
+
if (_optionalChain([operand, 'optionalAccess', _518 => _518.type]) === "Identifier" && !seenNames.has(operand.name)) {
|
|
8333
|
+
seenNames.add(operand.name);
|
|
8334
|
+
uniqueIdents.push(operand);
|
|
8335
|
+
}
|
|
6672
8336
|
}
|
|
6673
|
-
|
|
6674
|
-
|
|
8337
|
+
const makeIsNumberExpr = (ident) => {
|
|
8338
|
+
const numLit = makeLiteral("number");
|
|
8339
|
+
const eqNode = makeBinary("===", makeUnary("typeof", { type: "Identifier", name: ident.name }), numLit);
|
|
8340
|
+
exemptNodes.push(numLit, eqNode);
|
|
8341
|
+
return eqNode;
|
|
8342
|
+
};
|
|
8343
|
+
const testExpr = uniqueIdents.length === 2 ? {
|
|
8344
|
+
type: "LogicalExpression",
|
|
8345
|
+
operator: "&&",
|
|
8346
|
+
left: makeIsNumberExpr(uniqueIdents[0]),
|
|
8347
|
+
right: makeIsNumberExpr(uniqueIdents[1])
|
|
8348
|
+
} : makeIsNumberExpr(uniqueIdents[0]);
|
|
8349
|
+
const replacement = {
|
|
8350
|
+
type: "ConditionalExpression",
|
|
6675
8351
|
test: testExpr,
|
|
6676
8352
|
consequent,
|
|
6677
|
-
alternate
|
|
8353
|
+
alternate,
|
|
8354
|
+
_unpeekGuardSubtree: true
|
|
6678
8355
|
};
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
if (node.type
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
8356
|
+
if (hotExemptNodes) {
|
|
8357
|
+
hotExemptNodes.add(replacement);
|
|
8358
|
+
hotExemptNodes.add(testExpr);
|
|
8359
|
+
for (const nodeToExempt of exemptNodes) {
|
|
8360
|
+
hotExemptNodes.add(nodeToExempt);
|
|
8361
|
+
}
|
|
8362
|
+
}
|
|
8363
|
+
return replacement;
|
|
8364
|
+
}
|
|
8365
|
+
function applyColdBitwiseMba(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes, guardSubtreeNodes) {
|
|
8366
|
+
const { unsafe, scopeBindings } = analyzeBitwiseMbaScopes(ast);
|
|
8367
|
+
if (unsafe) return 0;
|
|
8368
|
+
let mbaCount = 0;
|
|
8369
|
+
const scopeStack = [];
|
|
8370
|
+
function walkTransform(node, setInParent, inColdFn) {
|
|
8371
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) return;
|
|
8372
|
+
if (!node || typeof node !== "object" || typeof node.type !== "string") return;
|
|
8373
|
+
if (_optionalChain([hotExemptNodes, 'optionalAccess', _519 => _519.has, 'call', _520 => _520(node)]) || _optionalChain([guardSubtreeNodes, 'optionalAccess', _521 => _521.has, 'call', _522 => _522(node)])) return;
|
|
8374
|
+
if (node._unpeekGuardSubtree === true) return;
|
|
8375
|
+
if (node._unpeekSerialized || node._unpeekVirtualized === true) return;
|
|
8376
|
+
if (BITWISE_LOOP_NODE_TYPES.has(node.type)) return;
|
|
8377
|
+
const pushedScope = scopeBindings.has(node);
|
|
8378
|
+
if (pushedScope) scopeStack.push(node);
|
|
8379
|
+
try {
|
|
8380
|
+
const childInColdFn = BITWISE_FUNCTION_TYPES.has(node.type) ? coldFunctionNodes.has(node) : inColdFn;
|
|
8381
|
+
if (childInColdFn && node.type === "BinaryExpression" && BITWISE_MBA_OPS.has(node.operator)) {
|
|
8382
|
+
const op = node.operator;
|
|
8383
|
+
const { left, right } = node;
|
|
8384
|
+
const isCoercionOrZero = op === "|" && isZeroNumericLiteral(right);
|
|
8385
|
+
if (!isCoercionOrZero) {
|
|
8386
|
+
const leftAtomic = isSafeAtomicIntegerLiteral(left) || isLocalBoundIdentifier(left, scopeStack, scopeBindings, ast);
|
|
8387
|
+
const rightAtomic = isSafeAtomicIntegerLiteral(right) || isLocalBoundIdentifier(right, scopeStack, scopeBindings, ast);
|
|
8388
|
+
const hasIdent = _optionalChain([left, 'optionalAccess', _523 => _523.type]) === "Identifier" || _optionalChain([right, 'optionalAccess', _524 => _524.type]) === "Identifier";
|
|
8389
|
+
if (leftAtomic && rightAtomic && hasIdent) {
|
|
8390
|
+
const replacement = buildColdBitwiseConditional(
|
|
8391
|
+
op,
|
|
8392
|
+
left,
|
|
8393
|
+
right,
|
|
8394
|
+
seed,
|
|
8395
|
+
mbaCount,
|
|
8396
|
+
hotExemptNodes
|
|
8397
|
+
);
|
|
8398
|
+
mbaCount++;
|
|
8399
|
+
setInParent(replacement);
|
|
8400
|
+
return;
|
|
8401
|
+
}
|
|
6710
8402
|
}
|
|
6711
|
-
} else if (arg.type === "UnaryExpression") {
|
|
6712
|
-
if (arg.operator === "!") seenBoolean = true;
|
|
6713
|
-
else if (arg.operator === "typeof") seenString = true;
|
|
6714
|
-
else if (arg.operator === "-" || arg.operator === "+" || arg.operator === "~") seenNumber = true;
|
|
6715
8403
|
}
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
8404
|
+
for (const key of Object.keys(node)) {
|
|
8405
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) break;
|
|
8406
|
+
if (key === "loc" || key === "range" || key === "start" || key === "end" || key === "comments" || key === "tokens") {
|
|
8407
|
+
continue;
|
|
8408
|
+
}
|
|
8409
|
+
const child = node[key];
|
|
8410
|
+
if (Array.isArray(child)) {
|
|
8411
|
+
for (let i = 0; i < child.length; i++) {
|
|
8412
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) break;
|
|
8413
|
+
const item = child[i];
|
|
8414
|
+
if (item && typeof item === "object" && typeof item.type === "string") {
|
|
8415
|
+
walkTransform(
|
|
8416
|
+
item,
|
|
8417
|
+
(rep) => {
|
|
8418
|
+
child[i] = rep;
|
|
8419
|
+
},
|
|
8420
|
+
childInColdFn
|
|
8421
|
+
);
|
|
8422
|
+
}
|
|
8423
|
+
}
|
|
8424
|
+
} else if (child && typeof child === "object" && typeof child.type === "string") {
|
|
8425
|
+
walkTransform(
|
|
8426
|
+
child,
|
|
8427
|
+
(rep) => {
|
|
8428
|
+
node[key] = rep;
|
|
8429
|
+
},
|
|
8430
|
+
childInColdFn
|
|
8431
|
+
);
|
|
8432
|
+
}
|
|
6723
8433
|
}
|
|
8434
|
+
} finally {
|
|
8435
|
+
if (pushedScope) scopeStack.pop();
|
|
6724
8436
|
}
|
|
6725
8437
|
}
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
if (seenBoolean && !seenNumber && !seenString) return "boolean";
|
|
6730
|
-
if (seenNumber && !seenBoolean && !seenString) return "number";
|
|
6731
|
-
if (seenString && !seenNumber && !seenBoolean) return "string";
|
|
6732
|
-
return "object";
|
|
8438
|
+
walkTransform(ast, () => {
|
|
8439
|
+
}, false);
|
|
8440
|
+
return mbaCount;
|
|
6733
8441
|
}
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
8442
|
+
var UNSAFE_EXPRESSION_NODE_TYPES = /* @__PURE__ */ new Set(["Super", "WithStatement"]);
|
|
8443
|
+
var UNSAFE_IF_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
8444
|
+
"Super",
|
|
8445
|
+
"WithStatement",
|
|
8446
|
+
"FunctionDeclaration",
|
|
8447
|
+
"ClassDeclaration"
|
|
8448
|
+
]);
|
|
8449
|
+
function containsAstNodeType(node, types) {
|
|
8450
|
+
if (!node || typeof node !== "object") return false;
|
|
8451
|
+
if (Array.isArray(node)) {
|
|
8452
|
+
for (const item of node) {
|
|
8453
|
+
if (containsAstNodeType(item, types)) return true;
|
|
8454
|
+
}
|
|
8455
|
+
return false;
|
|
8456
|
+
}
|
|
8457
|
+
if (typeof node.type === "string" && types.has(node.type)) {
|
|
8458
|
+
return true;
|
|
8459
|
+
}
|
|
8460
|
+
for (const key of Object.keys(node)) {
|
|
8461
|
+
if (key === "loc" || key === "range" || key === "start" || key === "end" || key === "comments" || key === "tokens") {
|
|
8462
|
+
continue;
|
|
8463
|
+
}
|
|
8464
|
+
const val = node[key];
|
|
8465
|
+
if (val && typeof val === "object" && containsAstNodeType(val, types)) {
|
|
8466
|
+
return true;
|
|
8467
|
+
}
|
|
8468
|
+
}
|
|
8469
|
+
return false;
|
|
8470
|
+
}
|
|
8471
|
+
function collectMathUnsafeScopes(ast) {
|
|
8472
|
+
const unsafe = /* @__PURE__ */ new WeakSet();
|
|
8473
|
+
const findEnclosing = (ancestors) => {
|
|
8474
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
8475
|
+
if (BITWISE_LEXICAL_SCOPE_TYPES.has(ancestors[i].type)) {
|
|
8476
|
+
return ancestors[i];
|
|
8477
|
+
}
|
|
8478
|
+
}
|
|
8479
|
+
return ast;
|
|
8480
|
+
};
|
|
8481
|
+
const markScopeAndEnclosingFn = (ancestors, scopeNode) => {
|
|
8482
|
+
unsafe.add(scopeNode);
|
|
8483
|
+
const parent = ancestors.length >= 2 ? ancestors[ancestors.length - 2] : null;
|
|
8484
|
+
if (parent && BITWISE_FUNCTION_TYPES.has(parent.type) && parent.body === scopeNode) {
|
|
8485
|
+
unsafe.add(parent);
|
|
8486
|
+
}
|
|
8487
|
+
};
|
|
8488
|
+
const patternHasMath = (pat) => {
|
|
8489
|
+
const names = [];
|
|
8490
|
+
collectBoundPatternNames(pat, names);
|
|
8491
|
+
return names.includes("Math");
|
|
8492
|
+
};
|
|
8493
|
+
walk6.ancestor(ast, {
|
|
8494
|
+
WithStatement(node, _st, ancestors) {
|
|
8495
|
+
unsafe.add(node);
|
|
8496
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
8497
|
+
const a = ancestors[i];
|
|
8498
|
+
if (BITWISE_FUNCTION_TYPES.has(a.type)) {
|
|
8499
|
+
unsafe.add(a);
|
|
8500
|
+
break;
|
|
8501
|
+
}
|
|
8502
|
+
if (a.type === "Program") break;
|
|
8503
|
+
}
|
|
6751
8504
|
},
|
|
6752
|
-
{
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
8505
|
+
ImportSpecifier(node) {
|
|
8506
|
+
if (_optionalChain([node, 'access', _525 => _525.local, 'optionalAccess', _526 => _526.name]) === "Math") unsafe.add(ast);
|
|
8507
|
+
},
|
|
8508
|
+
ImportDefaultSpecifier(node) {
|
|
8509
|
+
if (_optionalChain([node, 'access', _527 => _527.local, 'optionalAccess', _528 => _528.name]) === "Math") unsafe.add(ast);
|
|
8510
|
+
},
|
|
8511
|
+
ImportNamespaceSpecifier(node) {
|
|
8512
|
+
if (_optionalChain([node, 'access', _529 => _529.local, 'optionalAccess', _530 => _530.name]) === "Math") unsafe.add(ast);
|
|
8513
|
+
},
|
|
8514
|
+
FunctionDeclaration(node, _st, ancestors) {
|
|
8515
|
+
if (_optionalChain([node, 'access', _531 => _531.id, 'optionalAccess', _532 => _532.name]) === "Math") {
|
|
8516
|
+
const prefix = ancestors.slice(0, -1);
|
|
8517
|
+
markScopeAndEnclosingFn(prefix, findEnclosing(prefix));
|
|
8518
|
+
unsafe.add(node);
|
|
8519
|
+
}
|
|
8520
|
+
if (Array.isArray(node.params) && node.params.some(patternHasMath)) {
|
|
8521
|
+
unsafe.add(node);
|
|
6758
8522
|
}
|
|
6759
8523
|
},
|
|
6760
|
-
{
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
8524
|
+
FunctionExpression(node) {
|
|
8525
|
+
if (_optionalChain([node, 'access', _533 => _533.id, 'optionalAccess', _534 => _534.name]) === "Math" || Array.isArray(node.params) && node.params.some(patternHasMath)) {
|
|
8526
|
+
unsafe.add(node);
|
|
8527
|
+
}
|
|
6764
8528
|
},
|
|
6765
|
-
{
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
}
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
{
|
|
6798
|
-
type: "VariableDeclaration",
|
|
6799
|
-
kind: "var",
|
|
6800
|
-
declarations: [
|
|
6801
|
-
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$u" }, init: makeBinary("|", { type: "Identifier", name: "$a" }, makeLiteral(0)) },
|
|
6802
|
-
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$v" }, init: makeBinary("|", { type: "Identifier", name: "$b" }, makeLiteral(0)) },
|
|
6803
|
-
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$p" }, init: makeBinary("|", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }), makeLiteral(0)) },
|
|
6804
|
-
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$q" }, init: makeBinary("|", makeMemberIndex(aliasIdentB, { type: "Identifier", name: "$d" }), makeLiteral(0)) },
|
|
6805
|
-
{ type: "VariableDeclarator", id: { type: "Identifier", name: "$z" }, init: mbaAst }
|
|
6806
|
-
]
|
|
6807
|
-
},
|
|
6808
|
-
{
|
|
6809
|
-
type: "ExpressionStatement",
|
|
6810
|
-
expression: {
|
|
6811
|
-
type: "AssignmentExpression",
|
|
6812
|
-
operator: "=",
|
|
6813
|
-
left: { type: "Identifier", name: "$z" },
|
|
6814
|
-
right: makeBinary(
|
|
6815
|
-
"|",
|
|
6816
|
-
makeBinary(
|
|
6817
|
-
"+",
|
|
6818
|
-
{ type: "Identifier", name: "$f" },
|
|
6819
|
-
makeImul(
|
|
6820
|
-
{ type: "Identifier", name: "$z" },
|
|
6821
|
-
makeBinary(
|
|
6822
|
-
"+",
|
|
6823
|
-
{ type: "Identifier", name: "$g" },
|
|
6824
|
-
makeImul(
|
|
6825
|
-
{ type: "Identifier", name: "$z" },
|
|
6826
|
-
makeBinary(
|
|
6827
|
-
"+",
|
|
6828
|
-
{ type: "Identifier", name: "$h" },
|
|
6829
|
-
makeImul({ type: "Identifier", name: "$z" }, { type: "Identifier", name: "$i" })
|
|
6830
|
-
)
|
|
6831
|
-
)
|
|
6832
|
-
)
|
|
6833
|
-
)
|
|
6834
|
-
),
|
|
6835
|
-
makeLiteral(0)
|
|
6836
|
-
)
|
|
6837
|
-
}
|
|
6838
|
-
},
|
|
6839
|
-
{
|
|
6840
|
-
type: "ExpressionStatement",
|
|
6841
|
-
expression: {
|
|
6842
|
-
type: "AssignmentExpression",
|
|
6843
|
-
operator: "=",
|
|
6844
|
-
left: { type: "Identifier", name: "$z" },
|
|
6845
|
-
right: buildSboxMixAst(sboxIdent, "$z")
|
|
6846
|
-
}
|
|
6847
|
-
},
|
|
6848
|
-
{
|
|
6849
|
-
type: "VariableDeclaration",
|
|
6850
|
-
kind: "var",
|
|
6851
|
-
declarations: [
|
|
6852
|
-
{
|
|
6853
|
-
type: "VariableDeclarator",
|
|
6854
|
-
id: { type: "Identifier", name: "$m" },
|
|
6855
|
-
init: makeBinary("^", makeBinary("<<", { type: "Identifier", name: "$z" }, makeLiteral(3)), { type: "Identifier", name: "$e" })
|
|
6856
|
-
}
|
|
6857
|
-
]
|
|
6858
|
-
},
|
|
6859
|
-
{
|
|
6860
|
-
type: "ExpressionStatement",
|
|
6861
|
-
expression: {
|
|
6862
|
-
type: "AssignmentExpression",
|
|
6863
|
-
operator: "=",
|
|
6864
|
-
left: makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }),
|
|
6865
|
-
right: makeBinary("|", makeBinary("^", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }), { type: "Identifier", name: "$m" }), makeLiteral(0))
|
|
6866
|
-
}
|
|
6867
|
-
},
|
|
6868
|
-
{
|
|
6869
|
-
type: "VariableDeclaration",
|
|
6870
|
-
kind: "var",
|
|
6871
|
-
declarations: [
|
|
6872
|
-
{
|
|
6873
|
-
type: "VariableDeclarator",
|
|
6874
|
-
id: { type: "Identifier", name: "$w" },
|
|
6875
|
-
init: makeBinary(
|
|
6876
|
-
"^",
|
|
6877
|
-
makeBinary("|", makeBinary("^", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }), { type: "Identifier", name: "$m" }), makeLiteral(0)),
|
|
6878
|
-
{
|
|
6879
|
-
type: "AssignmentExpression",
|
|
6880
|
-
operator: "=",
|
|
6881
|
-
left: makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }),
|
|
6882
|
-
right: makeBinary("|", makeBinary("^", makeMemberIndex(aliasIdentA, { type: "Identifier", name: "$c" }), { type: "Identifier", name: "$m" }), makeLiteral(0))
|
|
6883
|
-
}
|
|
6884
|
-
)
|
|
6885
|
-
}
|
|
6886
|
-
]
|
|
6887
|
-
},
|
|
6888
|
-
{
|
|
6889
|
-
type: "ReturnStatement",
|
|
6890
|
-
argument: {
|
|
6891
|
-
type: "AssignmentExpression",
|
|
6892
|
-
operator: "=",
|
|
6893
|
-
left: { type: "Identifier", name: scratchVarIdent },
|
|
6894
|
-
right: makeBinary("|", makeBinary("^", { type: "Identifier", name: "$z" }, { type: "Identifier", name: "$w" }), makeLiteral(0))
|
|
6895
|
-
}
|
|
8529
|
+
ArrowFunctionExpression(node) {
|
|
8530
|
+
if (Array.isArray(node.params) && node.params.some(patternHasMath)) {
|
|
8531
|
+
unsafe.add(node);
|
|
8532
|
+
}
|
|
8533
|
+
},
|
|
8534
|
+
ClassDeclaration(node, _st, ancestors) {
|
|
8535
|
+
if (_optionalChain([node, 'access', _535 => _535.id, 'optionalAccess', _536 => _536.name]) === "Math") {
|
|
8536
|
+
const prefix = ancestors.slice(0, -1);
|
|
8537
|
+
markScopeAndEnclosingFn(prefix, findEnclosing(prefix));
|
|
8538
|
+
unsafe.add(node);
|
|
8539
|
+
}
|
|
8540
|
+
},
|
|
8541
|
+
ClassExpression(node) {
|
|
8542
|
+
if (_optionalChain([node, 'access', _537 => _537.id, 'optionalAccess', _538 => _538.name]) === "Math") {
|
|
8543
|
+
unsafe.add(node);
|
|
8544
|
+
}
|
|
8545
|
+
},
|
|
8546
|
+
CatchClause(node) {
|
|
8547
|
+
if (node.param && patternHasMath(node.param)) {
|
|
8548
|
+
unsafe.add(node);
|
|
8549
|
+
}
|
|
8550
|
+
},
|
|
8551
|
+
VariableDeclaration(node, _st, ancestors) {
|
|
8552
|
+
if (!Array.isArray(node.declarations) || !node.declarations.some((d) => patternHasMath(_optionalChain([d, 'optionalAccess', _539 => _539.id])))) {
|
|
8553
|
+
return;
|
|
8554
|
+
}
|
|
8555
|
+
if (node.kind === "var") {
|
|
8556
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
8557
|
+
const a = ancestors[i];
|
|
8558
|
+
if (BITWISE_FUNCTION_TYPES.has(a.type) || a.type === "StaticBlock" || a.type === "Program") {
|
|
8559
|
+
unsafe.add(a);
|
|
8560
|
+
break;
|
|
6896
8561
|
}
|
|
6897
|
-
|
|
6898
|
-
}
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
|
|
6902
|
-
}
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
8562
|
+
}
|
|
8563
|
+
} else {
|
|
8564
|
+
const prefix = ancestors.slice(0, -1);
|
|
8565
|
+
markScopeAndEnclosingFn(prefix, findEnclosing(prefix));
|
|
8566
|
+
}
|
|
8567
|
+
}
|
|
8568
|
+
});
|
|
8569
|
+
return unsafe;
|
|
8570
|
+
}
|
|
8571
|
+
function isAnyAncestorInSet(ancestors, set) {
|
|
8572
|
+
if (!set) return false;
|
|
8573
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
8574
|
+
if (set.has(ancestors[i])) return true;
|
|
6908
8575
|
}
|
|
6909
|
-
return
|
|
6910
|
-
type: "VariableDeclaration",
|
|
6911
|
-
kind: "var",
|
|
6912
|
-
declarations
|
|
6913
|
-
};
|
|
8576
|
+
return false;
|
|
6914
8577
|
}
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
8578
|
+
function isDirectiveStatement(stmt) {
|
|
8579
|
+
if (!stmt || stmt.type !== "ExpressionStatement") return false;
|
|
8580
|
+
if (stmt.directive) return true;
|
|
8581
|
+
return _optionalChain([stmt, 'access', _540 => _540.expression, 'optionalAccess', _541 => _541.type]) === "Literal" && typeof stmt.expression.value === "string" && /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim());
|
|
8582
|
+
}
|
|
8583
|
+
function isSafeC9Statement(stmt, hotExemptNodes) {
|
|
8584
|
+
if (!stmt || typeof stmt !== "object") return false;
|
|
8585
|
+
if (stmt._unpeekGuardSubtree === true) return false;
|
|
8586
|
+
if (_optionalChain([hotExemptNodes, 'optionalAccess', _542 => _542.has, 'call', _543 => _543(stmt)])) return false;
|
|
8587
|
+
if (stmt.type === "ExpressionStatement") {
|
|
8588
|
+
if (isDirectiveStatement(stmt)) return false;
|
|
8589
|
+
return !containsAstNodeType(stmt, UNSAFE_EXPRESSION_NODE_TYPES);
|
|
8590
|
+
}
|
|
8591
|
+
if (stmt.type === "IfStatement") {
|
|
8592
|
+
return !containsAstNodeType(stmt, UNSAFE_IF_NODE_TYPES);
|
|
8593
|
+
}
|
|
8594
|
+
return false;
|
|
8595
|
+
}
|
|
8596
|
+
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes, windowKeySymbol, expectedDelta, shieldCoupled = false, options) {
|
|
8597
|
+
const sfx = deriveColdFlowSuffix(seed);
|
|
6918
8598
|
const decoyIdent = `_uDec${sfx}`;
|
|
6919
8599
|
const sboxIdent = `_uSb${sfx}`;
|
|
6920
8600
|
const aliasIdentA = `_uAl${sfx}`;
|
|
6921
8601
|
const aliasIdentB = `_uAm${sfx}`;
|
|
6922
8602
|
const scratchVarIdent = `_uZt${sfx}`;
|
|
6923
8603
|
const mxIdent = `_uMx${sfx}`;
|
|
8604
|
+
const latchFnName = `_uLr${sfx}`;
|
|
6924
8605
|
if (Array.isArray(ast.body)) {
|
|
6925
8606
|
const alreadyGuarded = ast.body.some(
|
|
6926
|
-
(stmt) => stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access',
|
|
6927
|
-
(d) => _optionalChain([d, 'access',
|
|
6928
|
-
)])
|
|
8607
|
+
(stmt) => stmt.type === "VariableDeclaration" && _optionalChain([stmt, 'access', _544 => _544.declarations, 'optionalAccess', _545 => _545.some, 'call', _546 => _546(
|
|
8608
|
+
(d) => _optionalChain([d, 'access', _547 => _547.id, 'optionalAccess', _548 => _548.type]) === "Identifier" && (d.id.name === decoyIdent || d.id.name === sboxIdent || d.id.name === mxIdent)
|
|
8609
|
+
)]) || stmt.type === "FunctionDeclaration" && _optionalChain([stmt, 'access', _549 => _549.id, 'optionalAccess', _550 => _550.type]) === "Identifier" && (stmt.id.name === mxIdent || stmt.id.name === latchFnName)
|
|
6929
8610
|
);
|
|
6930
8611
|
if (alreadyGuarded) return 0;
|
|
6931
8612
|
}
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
8613
|
+
if (_optionalChain([options, 'optionalAccess', _551 => _551.enableBitwiseMba])) {
|
|
8614
|
+
applyColdBitwiseMba(ast, coldFunctionNodes, seed, hotExemptNodes);
|
|
8615
|
+
}
|
|
8616
|
+
const mathUnsafeScopes = collectMathUnsafeScopes(ast);
|
|
8617
|
+
const C9_RESERVED_SLOTS = 4;
|
|
8618
|
+
const eligibleColdFns = [];
|
|
8619
|
+
function collectEligibleColdFn(node, _state, ancestors) {
|
|
8620
|
+
if (eligibleColdFns.length >= MAX_COLD_GUARDS_PER_CHUNK) return;
|
|
6935
8621
|
if (!coldFunctionNodes.has(node)) return;
|
|
6936
|
-
if (
|
|
8622
|
+
if (isAnyAncestorInSet(ancestors, hotExemptNodes)) return;
|
|
8623
|
+
if (isAnyAncestorInSet(ancestors, mathUnsafeScopes)) return;
|
|
8624
|
+
if (node._unpeekSerialized) return;
|
|
6937
8625
|
if (node._unpeekVirtualized === true) return;
|
|
6938
8626
|
if (!node.body || node.body.type !== "BlockStatement") return;
|
|
6939
8627
|
const paramNames = [];
|
|
6940
8628
|
for (const p of node.params || []) {
|
|
6941
8629
|
extractParamNames(p, paramNames);
|
|
6942
8630
|
}
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
8631
|
+
eligibleColdFns.push({
|
|
8632
|
+
node,
|
|
8633
|
+
paramNames,
|
|
8634
|
+
firstParam: _optionalChain([node, 'access', _552 => _552.params, 'optionalAccess', _553 => _553[0]]),
|
|
8635
|
+
isArrow: node.type === "ArrowFunctionExpression",
|
|
8636
|
+
returnDomain: inferFunctionReturnDomain(node)
|
|
8637
|
+
});
|
|
8638
|
+
}
|
|
8639
|
+
walk6.ancestor(ast, {
|
|
8640
|
+
FunctionDeclaration: collectEligibleColdFn,
|
|
8641
|
+
FunctionExpression: collectEligibleColdFn,
|
|
8642
|
+
ArrowFunctionExpression: collectEligibleColdFn
|
|
8643
|
+
});
|
|
8644
|
+
let availableC9Slots = 0;
|
|
8645
|
+
for (const fnInfo of eligibleColdFns) {
|
|
8646
|
+
if (availableC9Slots >= C9_RESERVED_SLOTS) break;
|
|
8647
|
+
const bodyStmts = fnInfo.node.body.body;
|
|
8648
|
+
let idx = 0;
|
|
8649
|
+
while (idx < bodyStmts.length && isDirectiveStatement(bodyStmts[idx])) {
|
|
8650
|
+
idx++;
|
|
8651
|
+
}
|
|
8652
|
+
for (; idx < bodyStmts.length; idx++) {
|
|
8653
|
+
if (isSafeC9Statement(bodyStmts[idx], hotExemptNodes)) {
|
|
8654
|
+
availableC9Slots++;
|
|
8655
|
+
if (availableC9Slots >= C9_RESERVED_SLOTS) break;
|
|
8656
|
+
}
|
|
8657
|
+
}
|
|
8658
|
+
}
|
|
8659
|
+
const opaqueFalseLimit = MAX_COLD_GUARDS_PER_CHUNK - availableC9Slots;
|
|
8660
|
+
let opaqueFalseCount = 0;
|
|
8661
|
+
for (let i = 0; i < eligibleColdFns.length && opaqueFalseCount < opaqueFalseLimit; i++) {
|
|
8662
|
+
const fnInfo = eligibleColdFns[i];
|
|
6946
8663
|
const guardStmt = createSotaMbaPredicate(
|
|
6947
8664
|
seed,
|
|
6948
|
-
|
|
6949
|
-
firstParam,
|
|
8665
|
+
opaqueFalseCount,
|
|
8666
|
+
fnInfo.firstParam,
|
|
6950
8667
|
decoyIdent,
|
|
6951
|
-
isArrow,
|
|
8668
|
+
fnInfo.isArrow,
|
|
6952
8669
|
{
|
|
6953
|
-
liveVars: paramNames,
|
|
8670
|
+
liveVars: fnInfo.paramNames,
|
|
6954
8671
|
sboxIdent,
|
|
6955
8672
|
aliasIdentA,
|
|
6956
8673
|
aliasIdentB,
|
|
6957
8674
|
scratchVarIdent,
|
|
6958
8675
|
mxIdent,
|
|
6959
|
-
returnDomain,
|
|
8676
|
+
returnDomain: fnInfo.returnDomain,
|
|
6960
8677
|
windowKeySymbol,
|
|
6961
8678
|
expectedDelta,
|
|
6962
8679
|
shieldCoupled
|
|
6963
8680
|
}
|
|
6964
8681
|
);
|
|
6965
|
-
|
|
8682
|
+
opaqueFalseCount++;
|
|
8683
|
+
guardStmt._unpeekGuardSubtree = true;
|
|
6966
8684
|
if (hotExemptNodes) {
|
|
6967
8685
|
hotExemptNodes.add(guardStmt);
|
|
6968
8686
|
hotExemptNodes.add(guardStmt.consequent);
|
|
6969
8687
|
}
|
|
6970
8688
|
let insertIdx = 0;
|
|
6971
|
-
while (insertIdx < node.body.body.length &&
|
|
8689
|
+
while (insertIdx < fnInfo.node.body.body.length && isDirectiveStatement(fnInfo.node.body.body[insertIdx])) {
|
|
6972
8690
|
insertIdx++;
|
|
6973
8691
|
}
|
|
6974
|
-
node.body.body.splice(insertIdx, 0, guardStmt);
|
|
8692
|
+
fnInfo.node.body.body.splice(insertIdx, 0, guardStmt);
|
|
6975
8693
|
}
|
|
6976
|
-
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
8694
|
+
let c9WrappedCount = 0;
|
|
8695
|
+
if (eligibleColdFns.length > 0 && opaqueFalseCount < MAX_COLD_GUARDS_PER_CHUNK) {
|
|
8696
|
+
const fnCursors = eligibleColdFns.map((fnInfo) => {
|
|
8697
|
+
const bodyStmts = fnInfo.node.body.body;
|
|
8698
|
+
let startIdx = 0;
|
|
8699
|
+
while (startIdx < bodyStmts.length && isDirectiveStatement(bodyStmts[startIdx])) {
|
|
8700
|
+
startIdx++;
|
|
8701
|
+
}
|
|
8702
|
+
return { fnInfo, bodyStmts, idx: startIdx };
|
|
8703
|
+
});
|
|
8704
|
+
let progress = true;
|
|
8705
|
+
while (progress && opaqueFalseCount + c9WrappedCount < MAX_COLD_GUARDS_PER_CHUNK) {
|
|
8706
|
+
progress = false;
|
|
8707
|
+
for (const cursor of fnCursors) {
|
|
8708
|
+
if (opaqueFalseCount + c9WrappedCount >= MAX_COLD_GUARDS_PER_CHUNK) break;
|
|
8709
|
+
const { fnInfo, bodyStmts } = cursor;
|
|
8710
|
+
while (cursor.idx < bodyStmts.length) {
|
|
8711
|
+
const stmt = bodyStmts[cursor.idx];
|
|
8712
|
+
const curIdx = cursor.idx++;
|
|
8713
|
+
if (!isSafeC9Statement(stmt, hotExemptNodes)) continue;
|
|
8714
|
+
const pred = createSotaMbaPredicate(
|
|
8715
|
+
seed,
|
|
8716
|
+
opaqueFalseCount + c9WrappedCount,
|
|
8717
|
+
fnInfo.firstParam,
|
|
8718
|
+
decoyIdent,
|
|
8719
|
+
fnInfo.isArrow,
|
|
8720
|
+
{
|
|
8721
|
+
liveVars: fnInfo.paramNames,
|
|
8722
|
+
sboxIdent,
|
|
8723
|
+
aliasIdentA,
|
|
8724
|
+
aliasIdentB,
|
|
8725
|
+
scratchVarIdent,
|
|
8726
|
+
mxIdent,
|
|
8727
|
+
returnDomain: "void",
|
|
8728
|
+
windowKeySymbol,
|
|
8729
|
+
expectedDelta,
|
|
8730
|
+
shieldCoupled
|
|
8731
|
+
}
|
|
8732
|
+
);
|
|
8733
|
+
const negatedTest = makeUnary("!", pred.test);
|
|
8734
|
+
negatedTest._unpeekGuardSubtree = true;
|
|
8735
|
+
if (hotExemptNodes) {
|
|
8736
|
+
hotExemptNodes.add(negatedTest);
|
|
8737
|
+
}
|
|
8738
|
+
bodyStmts[curIdx] = {
|
|
8739
|
+
type: "IfStatement",
|
|
8740
|
+
test: negatedTest,
|
|
8741
|
+
consequent: {
|
|
8742
|
+
type: "BlockStatement",
|
|
8743
|
+
body: [stmt]
|
|
8744
|
+
},
|
|
8745
|
+
alternate: null
|
|
8746
|
+
};
|
|
8747
|
+
c9WrappedCount++;
|
|
8748
|
+
progress = true;
|
|
8749
|
+
break;
|
|
8750
|
+
}
|
|
8751
|
+
}
|
|
8752
|
+
}
|
|
8753
|
+
}
|
|
8754
|
+
if ((opaqueFalseCount > 0 || c9WrappedCount > 0) && Array.isArray(ast.body)) {
|
|
6982
8755
|
const sharedDecoyDecl = createSharedDecoyDeclaration(
|
|
6983
8756
|
decoyIdent,
|
|
6984
|
-
|
|
8757
|
+
Math.max(1, opaqueFalseCount),
|
|
6985
8758
|
seed
|
|
6986
8759
|
);
|
|
6987
|
-
const
|
|
8760
|
+
const { varDecl, aliasInitStmt, latchFnDecl, mxFnDecl } = createColdFlowRuntimeDeclarations(
|
|
6988
8761
|
sboxIdent,
|
|
6989
8762
|
aliasIdentA,
|
|
6990
8763
|
aliasIdentB,
|
|
6991
8764
|
scratchVarIdent,
|
|
6992
8765
|
seed,
|
|
8766
|
+
latchFnName,
|
|
6993
8767
|
mxIdent
|
|
6994
8768
|
);
|
|
8769
|
+
aliasInitStmt._unpeekGuardSubtree = true;
|
|
8770
|
+
latchFnDecl._unpeekGuardSubtree = true;
|
|
8771
|
+
if (mxFnDecl) {
|
|
8772
|
+
mxFnDecl._unpeekGuardSubtree = true;
|
|
8773
|
+
}
|
|
6995
8774
|
if (hotExemptNodes) {
|
|
6996
8775
|
hotExemptNodes.add(sharedDecoyDecl);
|
|
6997
|
-
hotExemptNodes.add(
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
8776
|
+
hotExemptNodes.add(varDecl);
|
|
8777
|
+
hotExemptNodes.add(aliasInitStmt);
|
|
8778
|
+
hotExemptNodes.add(latchFnDecl);
|
|
8779
|
+
if (mxFnDecl) {
|
|
8780
|
+
hotExemptNodes.add(mxFnDecl);
|
|
7002
8781
|
}
|
|
7003
8782
|
for (const decl of sharedDecoyDecl.declarations || []) {
|
|
7004
|
-
if (_optionalChain([decl, 'access',
|
|
8783
|
+
if (_optionalChain([decl, 'access', _554 => _554.init, 'optionalAccess', _555 => _555.type]) === "ArrayExpression" && decl.init.elements) {
|
|
7005
8784
|
for (const el of decl.init.elements) {
|
|
7006
8785
|
if (el) hotExemptNodes.add(el);
|
|
7007
8786
|
}
|
|
@@ -7011,16 +8790,23 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
7011
8790
|
let insertIdx = 0;
|
|
7012
8791
|
while (insertIdx < ast.body.length) {
|
|
7013
8792
|
const stmt = ast.body[insertIdx];
|
|
7014
|
-
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || _optionalChain([stmt, 'access',
|
|
8793
|
+
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || _optionalChain([stmt, 'access', _556 => _556.expression, 'optionalAccess', _557 => _557.type]) === "Literal" && typeof stmt.expression.value === "string" && /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim()));
|
|
7015
8794
|
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
7016
8795
|
insertIdx++;
|
|
7017
8796
|
} else {
|
|
7018
8797
|
break;
|
|
7019
8798
|
}
|
|
7020
8799
|
}
|
|
7021
|
-
|
|
8800
|
+
const injectedDecls = [
|
|
8801
|
+
varDecl,
|
|
8802
|
+
aliasInitStmt,
|
|
8803
|
+
latchFnDecl,
|
|
8804
|
+
...mxFnDecl ? [mxFnDecl] : [],
|
|
8805
|
+
sharedDecoyDecl
|
|
8806
|
+
];
|
|
8807
|
+
ast.body.splice(insertIdx, 0, ...injectedDecls);
|
|
7022
8808
|
}
|
|
7023
|
-
return
|
|
8809
|
+
return opaqueFalseCount;
|
|
7024
8810
|
}
|
|
7025
8811
|
|
|
7026
8812
|
// src/ast/micro-vm.ts
|
|
@@ -7069,7 +8855,8 @@ var OP_TRY = 39;
|
|
|
7069
8855
|
var OP_ENDTRY = 40;
|
|
7070
8856
|
var OP_NULLISH = 41;
|
|
7071
8857
|
var OP_DUP = 42;
|
|
7072
|
-
var
|
|
8858
|
+
var OP_TOSTR = 43;
|
|
8859
|
+
var OPCODE_COUNT = 44;
|
|
7073
8860
|
function shuffleRange(n, seed) {
|
|
7074
8861
|
const arr = [];
|
|
7075
8862
|
for (let i = 0; i < n; i++) arr.push(i);
|
|
@@ -7129,14 +8916,14 @@ function encryptBytecodeStream(plainBytecode, fnSalt, vmKey, stateSlots, accSlot
|
|
|
7129
8916
|
accBefore[len] = ac;
|
|
7130
8917
|
if (stateSlots) {
|
|
7131
8918
|
for (const slot of stateSlots) {
|
|
7132
|
-
const targetPc = _nullishCoalesce(_optionalChain([jumpTargets, 'optionalAccess',
|
|
8919
|
+
const targetPc = _nullishCoalesce(_optionalChain([jumpTargets, 'optionalAccess', _558 => _558.get, 'call', _559 => _559(slot - 1)]), () => ( plainBytecode[slot - 1]));
|
|
7133
8920
|
const sBefore = _nullishCoalesce(stAtSlot.get(slot), () => ( 0));
|
|
7134
8921
|
enc[slot] = stateBefore[targetPc] ^ sBefore | 0;
|
|
7135
8922
|
}
|
|
7136
8923
|
}
|
|
7137
8924
|
if (accSlots) {
|
|
7138
8925
|
for (const slot of accSlots) {
|
|
7139
|
-
const targetPc = _nullishCoalesce(_optionalChain([jumpTargets, 'optionalAccess',
|
|
8926
|
+
const targetPc = _nullishCoalesce(_optionalChain([jumpTargets, 'optionalAccess', _560 => _560.get, 'call', _561 => _561(slot - 2)]), () => ( plainBytecode[slot - 2]));
|
|
7140
8927
|
const aBefore = _nullishCoalesce(acAtSlot.get(slot), () => ( 0));
|
|
7141
8928
|
enc[slot] = accBefore[targetPc] ^ aBefore | 0;
|
|
7142
8929
|
}
|
|
@@ -7253,7 +9040,8 @@ function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowK
|
|
|
7253
9040
|
[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});" },
|
|
7254
9041
|
[OP_ENDTRY]: { body: "$f.r=($f.r+$Z)|0;$f.e.pop();$f.r=($f.r-$B)|0;" },
|
|
7255
9042
|
[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;" },
|
|
7256
|
-
[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;" }
|
|
9043
|
+
[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;" },
|
|
9044
|
+
[OP_TOSTR]: { body: "$f.r=($f.r+$Z)|0;var $v=$f.q[$f.r-(1+$B)];$f.r=($f.r-$B)|0;$f.q[$f.r-1]=`${$v}`;" }
|
|
7257
9045
|
};
|
|
7258
9046
|
const handlers = new Array(opCount);
|
|
7259
9047
|
for (let op = 0; op < opCount; op++) {
|
|
@@ -7426,7 +9214,7 @@ function prepareLoweredFunction(fnNode, enclosingBindings) {
|
|
|
7426
9214
|
loweredParams.push({ type: "Identifier", name: param.name });
|
|
7427
9215
|
continue;
|
|
7428
9216
|
}
|
|
7429
|
-
if (param.type === "RestElement" && _optionalChain([param, 'access',
|
|
9217
|
+
if (param.type === "RestElement" && _optionalChain([param, 'access', _562 => _562.argument, 'optionalAccess', _563 => _563.type]) === "Identifier") {
|
|
7430
9218
|
wrapperParams.push(param);
|
|
7431
9219
|
paramPassExprs.push({ type: "Identifier", name: param.argument.name });
|
|
7432
9220
|
loweredParams.push({ type: "Identifier", name: param.argument.name });
|
|
@@ -7485,7 +9273,7 @@ function prepareLoweredFunction(fnNode, enclosingBindings) {
|
|
|
7485
9273
|
return null;
|
|
7486
9274
|
}
|
|
7487
9275
|
clone.params = loweredParams;
|
|
7488
|
-
if (_optionalChain([clone, 'access',
|
|
9276
|
+
if (_optionalChain([clone, 'access', _564 => _564.body, 'optionalAccess', _565 => _565.type]) !== "BlockStatement") {
|
|
7489
9277
|
clone.body = {
|
|
7490
9278
|
type: "BlockStatement",
|
|
7491
9279
|
body: [
|
|
@@ -7593,7 +9381,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
7593
9381
|
}
|
|
7594
9382
|
if (node.type === "TryStatement") {
|
|
7595
9383
|
scanVarDecls(node.block, false);
|
|
7596
|
-
if (_optionalChain([node, 'access',
|
|
9384
|
+
if (_optionalChain([node, 'access', _566 => _566.handler, 'optionalAccess', _567 => _567.body])) scanVarDecls(node.handler.body, false);
|
|
7597
9385
|
if (node.finalizer) scanVarDecls(node.finalizer, false);
|
|
7598
9386
|
return;
|
|
7599
9387
|
}
|
|
@@ -7718,7 +9506,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
7718
9506
|
if (prop.computed) {
|
|
7719
9507
|
if (!compileExpr(prop.key, true)) return false;
|
|
7720
9508
|
} else {
|
|
7721
|
-
const keyName = _optionalChain([prop, 'access',
|
|
9509
|
+
const keyName = _optionalChain([prop, 'access', _568 => _568.key, 'optionalAccess', _569 => _569.type]) === "Identifier" ? prop.key.name : _optionalChain([prop, 'access', _570 => _570.key, 'optionalAccess', _571 => _571.type]) === "Literal" ? String(prop.key.value) : void 0;
|
|
7722
9510
|
if (keyName === void 0) return false;
|
|
7723
9511
|
emit(OP_LDC, addConst(keyName));
|
|
7724
9512
|
}
|
|
@@ -7857,11 +9645,12 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
7857
9645
|
case "TemplateLiteral": {
|
|
7858
9646
|
const quasis = node.quasis || [];
|
|
7859
9647
|
const exprs = node.expressions || [];
|
|
7860
|
-
emit(OP_LDC, addConst(_nullishCoalesce(_nullishCoalesce(_optionalChain([quasis, 'access',
|
|
9648
|
+
emit(OP_LDC, addConst(_nullishCoalesce(_nullishCoalesce(_optionalChain([quasis, 'access', _572 => _572[0], 'optionalAccess', _573 => _573.value, 'optionalAccess', _574 => _574.cooked]), () => ( _optionalChain([quasis, 'access', _575 => _575[0], 'optionalAccess', _576 => _576.value, 'optionalAccess', _577 => _577.raw]))), () => ( ""))));
|
|
7861
9649
|
for (let i = 0; i < exprs.length; i++) {
|
|
7862
9650
|
if (!compileExpr(exprs[i], true)) return false;
|
|
9651
|
+
emit(OP_TOSTR);
|
|
7863
9652
|
emit(OP_ADD);
|
|
7864
|
-
const qStr = _nullishCoalesce(_nullishCoalesce(_optionalChain([quasis, 'access',
|
|
9653
|
+
const qStr = _nullishCoalesce(_nullishCoalesce(_optionalChain([quasis, 'access', _578 => _578[i + 1], 'optionalAccess', _579 => _579.value, 'optionalAccess', _580 => _580.cooked]), () => ( _optionalChain([quasis, 'access', _581 => _581[i + 1], 'optionalAccess', _582 => _582.value, 'optionalAccess', _583 => _583.raw]))), () => ( ""));
|
|
7865
9654
|
if (qStr.length > 0) {
|
|
7866
9655
|
emit(OP_LDC, addConst(qStr));
|
|
7867
9656
|
emit(OP_ADD);
|
|
@@ -7947,7 +9736,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
7947
9736
|
if (inValuePos) emit(OP_LDC, addConst(void 0));
|
|
7948
9737
|
return true;
|
|
7949
9738
|
}
|
|
7950
|
-
if (node.operator === "typeof" && _optionalChain([node, 'access',
|
|
9739
|
+
if (node.operator === "typeof" && _optionalChain([node, 'access', _584 => _584.argument, 'optionalAccess', _585 => _585.type]) === "Identifier") {
|
|
7951
9740
|
const name = node.argument.name;
|
|
7952
9741
|
if (name === "undefined" && resolveLocal("undefined") === void 0) {
|
|
7953
9742
|
emit(OP_LDC, addConst(void 0));
|
|
@@ -7994,7 +9783,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
7994
9783
|
if (node.computed) {
|
|
7995
9784
|
if (!compileExpr(node.property, true)) return false;
|
|
7996
9785
|
} else {
|
|
7997
|
-
if (_optionalChain([node, 'access',
|
|
9786
|
+
if (_optionalChain([node, 'access', _586 => _586.property, 'optionalAccess', _587 => _587.type]) !== "Identifier") return false;
|
|
7998
9787
|
emit(OP_LDC, addConst(node.property.name));
|
|
7999
9788
|
}
|
|
8000
9789
|
emit(OP_GETP);
|
|
@@ -8004,7 +9793,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8004
9793
|
case "CallExpression": {
|
|
8005
9794
|
if (node.optional) return false;
|
|
8006
9795
|
for (const arg of node.arguments || []) {
|
|
8007
|
-
if (_optionalChain([arg, 'optionalAccess',
|
|
9796
|
+
if (_optionalChain([arg, 'optionalAccess', _588 => _588.type]) === "SpreadElement") return false;
|
|
8008
9797
|
}
|
|
8009
9798
|
if (node.callee.type === "MemberExpression") {
|
|
8010
9799
|
if (node.callee.optional) return false;
|
|
@@ -8012,7 +9801,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8012
9801
|
if (node.callee.computed) {
|
|
8013
9802
|
if (!compileExpr(node.callee.property, true)) return false;
|
|
8014
9803
|
} else {
|
|
8015
|
-
if (_optionalChain([node, 'access',
|
|
9804
|
+
if (_optionalChain([node, 'access', _589 => _589.callee, 'access', _590 => _590.property, 'optionalAccess', _591 => _591.type]) !== "Identifier") return false;
|
|
8016
9805
|
emit(OP_LDC, addConst(node.callee.property.name));
|
|
8017
9806
|
}
|
|
8018
9807
|
for (const arg of node.arguments) {
|
|
@@ -8031,7 +9820,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8031
9820
|
}
|
|
8032
9821
|
case "NewExpression": {
|
|
8033
9822
|
for (const arg of node.arguments || []) {
|
|
8034
|
-
if (_optionalChain([arg, 'optionalAccess',
|
|
9823
|
+
if (_optionalChain([arg, 'optionalAccess', _592 => _592.type]) === "SpreadElement") return false;
|
|
8035
9824
|
}
|
|
8036
9825
|
if (!compileExpr(node.callee, true)) return false;
|
|
8037
9826
|
for (const arg of node.arguments || []) {
|
|
@@ -8074,7 +9863,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8074
9863
|
if (node.left.computed) {
|
|
8075
9864
|
if (!compileExpr(node.left.property, true)) return false;
|
|
8076
9865
|
} else {
|
|
8077
|
-
if (_optionalChain([node, 'access',
|
|
9866
|
+
if (_optionalChain([node, 'access', _593 => _593.left, 'access', _594 => _594.property, 'optionalAccess', _595 => _595.type]) !== "Identifier") return false;
|
|
8078
9867
|
emit(OP_LDC, addConst(node.left.property.name));
|
|
8079
9868
|
}
|
|
8080
9869
|
if (!compileExpr(node.right, true)) return false;
|
|
@@ -8090,7 +9879,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8090
9879
|
if (node.left.computed) {
|
|
8091
9880
|
if (!compileExpr(node.left.property, true)) return false;
|
|
8092
9881
|
} else {
|
|
8093
|
-
if (_optionalChain([node, 'access',
|
|
9882
|
+
if (_optionalChain([node, 'access', _596 => _596.left, 'access', _597 => _597.property, 'optionalAccess', _598 => _598.type]) !== "Identifier") return false;
|
|
8094
9883
|
emit(OP_LDC, addConst(node.left.property.name));
|
|
8095
9884
|
}
|
|
8096
9885
|
emit(OP_STV, keySlot);
|
|
@@ -8110,7 +9899,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8110
9899
|
case "UpdateExpression": {
|
|
8111
9900
|
const oneIdx = addConst(1);
|
|
8112
9901
|
const stepOp = node.operator === "++" ? OP_ADD : OP_SUB;
|
|
8113
|
-
if (_optionalChain([node, 'access',
|
|
9902
|
+
if (_optionalChain([node, 'access', _599 => _599.argument, 'optionalAccess', _600 => _600.type]) === "Identifier") {
|
|
8114
9903
|
const name = node.argument.name;
|
|
8115
9904
|
if (!canWriteVar(name)) return false;
|
|
8116
9905
|
if (node.prefix) {
|
|
@@ -8136,7 +9925,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8136
9925
|
}
|
|
8137
9926
|
return true;
|
|
8138
9927
|
}
|
|
8139
|
-
if (_optionalChain([node, 'access',
|
|
9928
|
+
if (_optionalChain([node, 'access', _601 => _601.argument, 'optionalAccess', _602 => _602.type]) === "MemberExpression" && !node.argument.optional) {
|
|
8140
9929
|
const objSlot = allocTempSlot();
|
|
8141
9930
|
const keySlot = allocTempSlot();
|
|
8142
9931
|
const oldSlot = allocTempSlot();
|
|
@@ -8145,7 +9934,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8145
9934
|
if (node.argument.computed) {
|
|
8146
9935
|
if (!compileExpr(node.argument.property, true)) return false;
|
|
8147
9936
|
} else {
|
|
8148
|
-
if (_optionalChain([node, 'access',
|
|
9937
|
+
if (_optionalChain([node, 'access', _603 => _603.argument, 'access', _604 => _604.property, 'optionalAccess', _605 => _605.type]) !== "Identifier") return false;
|
|
8149
9938
|
emit(OP_LDC, addConst(node.argument.property.name));
|
|
8150
9939
|
}
|
|
8151
9940
|
emit(OP_STV, keySlot);
|
|
@@ -8177,7 +9966,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8177
9966
|
if (prop.computed) {
|
|
8178
9967
|
if (!compileExpr(prop.key, true)) return false;
|
|
8179
9968
|
} else {
|
|
8180
|
-
const keyName = _nullishCoalesce(_optionalChain([prop, 'access',
|
|
9969
|
+
const keyName = _nullishCoalesce(_optionalChain([prop, 'access', _606 => _606.key, 'optionalAccess', _607 => _607.name]), () => ( _optionalChain([prop, 'access', _608 => _608.key, 'optionalAccess', _609 => _609.value])));
|
|
8181
9970
|
if (keyName === void 0) return false;
|
|
8182
9971
|
emit(OP_LDC, addConst(keyName));
|
|
8183
9972
|
}
|
|
@@ -8229,14 +10018,14 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8229
10018
|
}
|
|
8230
10019
|
case "VariableDeclaration": {
|
|
8231
10020
|
for (const decl of stmt.declarations) {
|
|
8232
|
-
if (_optionalChain([decl, 'access',
|
|
10021
|
+
if (_optionalChain([decl, 'access', _610 => _610.id, 'optionalAccess', _611 => _611.type]) === "Identifier") {
|
|
8233
10022
|
const slot = resolveLocal(decl.id.name);
|
|
8234
10023
|
if (slot === void 0) return false;
|
|
8235
10024
|
if (decl.init) {
|
|
8236
10025
|
if (!compileExpr(decl.init, true)) return false;
|
|
8237
10026
|
emit(OP_STV, slot);
|
|
8238
10027
|
}
|
|
8239
|
-
} else if (_optionalChain([decl, 'access',
|
|
10028
|
+
} else if (_optionalChain([decl, 'access', _612 => _612.id, 'optionalAccess', _613 => _613.type]) === "ObjectPattern" || _optionalChain([decl, 'access', _614 => _614.id, 'optionalAccess', _615 => _615.type]) === "ArrayPattern") {
|
|
8240
10029
|
if (!decl.init) return false;
|
|
8241
10030
|
const srcSlot = allocTempSlot();
|
|
8242
10031
|
if (!compileExpr(decl.init, true)) return false;
|
|
@@ -8332,7 +10121,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8332
10121
|
}
|
|
8333
10122
|
case "ForStatement": {
|
|
8334
10123
|
let pushedForScope = false;
|
|
8335
|
-
if (_optionalChain([stmt, 'access',
|
|
10124
|
+
if (_optionalChain([stmt, 'access', _616 => _616.init, 'optionalAccess', _617 => _617.type]) === "VariableDeclaration" && stmt.init.kind !== "var") {
|
|
8336
10125
|
const forScope = /* @__PURE__ */ new Map();
|
|
8337
10126
|
const names = /* @__PURE__ */ new Set();
|
|
8338
10127
|
for (const decl of stmt.init.declarations || []) {
|
|
@@ -8400,7 +10189,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8400
10189
|
case "BreakStatement":
|
|
8401
10190
|
case "ContinueStatement": {
|
|
8402
10191
|
const isBreak = stmt.type === "BreakStatement";
|
|
8403
|
-
const labelName = _optionalChain([stmt, 'access',
|
|
10192
|
+
const labelName = _optionalChain([stmt, 'access', _618 => _618.label, 'optionalAccess', _619 => _619.name]);
|
|
8404
10193
|
let target;
|
|
8405
10194
|
for (let i = loopStack.length - 1; i >= 0; i--) {
|
|
8406
10195
|
if (!labelName || loopStack[i].label === labelName) {
|
|
@@ -8419,7 +10208,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8419
10208
|
return true;
|
|
8420
10209
|
}
|
|
8421
10210
|
case "LabeledStatement": {
|
|
8422
|
-
return compileStmt(stmt.body, false, _optionalChain([stmt, 'access',
|
|
10211
|
+
return compileStmt(stmt.body, false, _optionalChain([stmt, 'access', _620 => _620.label, 'optionalAccess', _621 => _621.name]));
|
|
8423
10212
|
}
|
|
8424
10213
|
case "TryStatement": {
|
|
8425
10214
|
if (stmt.finalizer) {
|
|
@@ -8549,12 +10338,12 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
8549
10338
|
function findInjectedVmHelperName(ast) {
|
|
8550
10339
|
if (!ast || !Array.isArray(ast.body)) return null;
|
|
8551
10340
|
for (const stmt of ast.body) {
|
|
8552
|
-
if (stmt.type === "FunctionDeclaration" && typeof _optionalChain([stmt, 'access',
|
|
10341
|
+
if (stmt.type === "FunctionDeclaration" && typeof _optionalChain([stmt, 'access', _622 => _622.id, 'optionalAccess', _623 => _623.name]) === "string" && stmt.id.name.startsWith("_uVm")) {
|
|
8553
10342
|
return stmt.id.name;
|
|
8554
10343
|
}
|
|
8555
10344
|
if (stmt.type === "VariableDeclaration" && Array.isArray(stmt.declarations)) {
|
|
8556
10345
|
for (const d of stmt.declarations) {
|
|
8557
|
-
if (_optionalChain([d, 'access',
|
|
10346
|
+
if (_optionalChain([d, 'access', _624 => _624.id, 'optionalAccess', _625 => _625.type]) === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uVm")) {
|
|
8558
10347
|
return d.id.name;
|
|
8559
10348
|
}
|
|
8560
10349
|
}
|
|
@@ -8565,26 +10354,26 @@ function findInjectedVmHelperName(ast) {
|
|
|
8565
10354
|
var PRIORITY_HANDLER_NAME_RE = /^(?:onSubmit|handleSubmit|submit[A-Za-z0-9_]*|validate[A-Za-z0-9_]*|login(?:[A-Z0-9_].*)?|signIn(?:[A-Z0-9_].*)?|register(?:[A-Z0-9_].*)?|checkout(?:[A-Z0-9_].*)?)$/i;
|
|
8566
10355
|
var PRIORITY_CALL_NAME_RE = /^(?:onSubmit|handleSubmit|submit[A-Za-z0-9_]*|validate[A-Za-z0-9_]*|login(?:[A-Z0-9_].*)?|signIn(?:[A-Z0-9_].*)?|register(?:[A-Z0-9_].*)?|checkout(?:[A-Z0-9_].*)?|createServerReference|fetch)$/i;
|
|
8567
10356
|
function getVmCandidateName(fn, ancestors) {
|
|
8568
|
-
if (_optionalChain([fn, 'access',
|
|
10357
|
+
if (_optionalChain([fn, 'access', _626 => _626.id, 'optionalAccess', _627 => _627.type]) === "Identifier" && typeof fn.id.name === "string") {
|
|
8569
10358
|
return fn.id.name;
|
|
8570
10359
|
}
|
|
8571
10360
|
const parent = ancestors.length >= 2 ? ancestors[ancestors.length - 2] : null;
|
|
8572
10361
|
if (!parent) return "";
|
|
8573
|
-
if (parent.type === "VariableDeclarator" && _optionalChain([parent, 'access',
|
|
10362
|
+
if (parent.type === "VariableDeclarator" && _optionalChain([parent, 'access', _628 => _628.id, 'optionalAccess', _629 => _629.type]) === "Identifier") {
|
|
8574
10363
|
return parent.id.name;
|
|
8575
10364
|
}
|
|
8576
10365
|
if (parent.type === "Property") {
|
|
8577
|
-
if (_optionalChain([parent, 'access',
|
|
8578
|
-
if (_optionalChain([parent, 'access',
|
|
10366
|
+
if (_optionalChain([parent, 'access', _630 => _630.key, 'optionalAccess', _631 => _631.type]) === "Identifier") return parent.key.name;
|
|
10367
|
+
if (_optionalChain([parent, 'access', _632 => _632.key, 'optionalAccess', _633 => _633.type]) === "Literal" && typeof parent.key.value === "string") {
|
|
8579
10368
|
return parent.key.value;
|
|
8580
10369
|
}
|
|
8581
10370
|
}
|
|
8582
|
-
if (parent.type === "MethodDefinition" && _optionalChain([parent, 'access',
|
|
10371
|
+
if (parent.type === "MethodDefinition" && _optionalChain([parent, 'access', _634 => _634.key, 'optionalAccess', _635 => _635.type]) === "Identifier") {
|
|
8583
10372
|
return parent.key.name;
|
|
8584
10373
|
}
|
|
8585
10374
|
if (parent.type === "AssignmentExpression") {
|
|
8586
|
-
if (_optionalChain([parent, 'access',
|
|
8587
|
-
if (_optionalChain([parent, 'access',
|
|
10375
|
+
if (_optionalChain([parent, 'access', _636 => _636.left, 'optionalAccess', _637 => _637.type]) === "Identifier") return parent.left.name;
|
|
10376
|
+
if (_optionalChain([parent, 'access', _638 => _638.left, 'optionalAccess', _639 => _639.type]) === "MemberExpression" && !parent.left.computed && _optionalChain([parent, 'access', _640 => _640.left, 'access', _641 => _641.property, 'optionalAccess', _642 => _642.type]) === "Identifier") {
|
|
8588
10377
|
return parent.left.property.name;
|
|
8589
10378
|
}
|
|
8590
10379
|
}
|
|
@@ -8597,11 +10386,11 @@ function bodyHasPrioritySignal(fnNode) {
|
|
|
8597
10386
|
if (n !== fnNode && FUNCTION_NODE_TYPES2.has(n.type)) return false;
|
|
8598
10387
|
if (n.type === "CallExpression") {
|
|
8599
10388
|
const callee = n.callee;
|
|
8600
|
-
if (_optionalChain([callee, 'optionalAccess',
|
|
10389
|
+
if (_optionalChain([callee, 'optionalAccess', _643 => _643.type]) === "Identifier" && PRIORITY_CALL_NAME_RE.test(callee.name)) {
|
|
8601
10390
|
matched = true;
|
|
8602
10391
|
return false;
|
|
8603
10392
|
}
|
|
8604
|
-
if (_optionalChain([callee, 'optionalAccess',
|
|
10393
|
+
if (_optionalChain([callee, 'optionalAccess', _644 => _644.type]) === "MemberExpression" && !callee.computed && _optionalChain([callee, 'access', _645 => _645.property, 'optionalAccess', _646 => _646.type]) === "Identifier" && PRIORITY_CALL_NAME_RE.test(callee.property.name)) {
|
|
8605
10394
|
matched = true;
|
|
8606
10395
|
return false;
|
|
8607
10396
|
}
|
|
@@ -8621,14 +10410,14 @@ function bodyHasPrioritySignal(fnNode) {
|
|
|
8621
10410
|
}
|
|
8622
10411
|
function scoreVmCandidate(fn, ancestors, criticalSet) {
|
|
8623
10412
|
let score = 0;
|
|
8624
|
-
if (_optionalChain([criticalSet, 'optionalAccess',
|
|
10413
|
+
if (_optionalChain([criticalSet, 'optionalAccess', _647 => _647.has, 'call', _648 => _648(fn)])) {
|
|
8625
10414
|
score += 1e3;
|
|
8626
10415
|
}
|
|
8627
10416
|
const candName = getVmCandidateName(fn, ancestors);
|
|
8628
10417
|
if (candName && PRIORITY_HANDLER_NAME_RE.test(candName) || bodyHasPrioritySignal(fn)) {
|
|
8629
10418
|
score += 500;
|
|
8630
10419
|
}
|
|
8631
|
-
if (_optionalChain([fn, 'access',
|
|
10420
|
+
if (_optionalChain([fn, 'access', _649 => _649.body, 'optionalAccess', _650 => _650.type]) === "BlockStatement" && Array.isArray(fn.body.body)) {
|
|
8632
10421
|
const stmtCount = fn.body.body.length;
|
|
8633
10422
|
if (stmtCount >= 2) {
|
|
8634
10423
|
score += Math.min(200, 10 + (stmtCount - 2) * 15);
|
|
@@ -8646,8 +10435,8 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8646
10435
|
vmHelperName: existingName
|
|
8647
10436
|
};
|
|
8648
10437
|
}
|
|
8649
|
-
const maxFunctions = _nullishCoalesce(_optionalChain([extraOpts, 'optionalAccess',
|
|
8650
|
-
const criticalSet = _optionalChain([extraOpts, 'optionalAccess',
|
|
10438
|
+
const maxFunctions = _nullishCoalesce(_optionalChain([extraOpts, 'optionalAccess', _651 => _651.maxFunctionsPerChunk]), () => ( 12));
|
|
10439
|
+
const criticalSet = _optionalChain([extraOpts, 'optionalAccess', _652 => _652.criticalFunctionNodes]);
|
|
8651
10440
|
const opMap = generateOpcodeMap(seed, OPCODE_COUNT);
|
|
8652
10441
|
const vmKey = deriveVmKey(seed);
|
|
8653
10442
|
const scopeBindings = /* @__PURE__ */ new Map();
|
|
@@ -8680,7 +10469,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8680
10469
|
walk7.ancestor(ast, {
|
|
8681
10470
|
ImportDeclaration(node) {
|
|
8682
10471
|
for (const spec of node.specifiers || []) {
|
|
8683
|
-
if (_optionalChain([spec, 'access',
|
|
10472
|
+
if (_optionalChain([spec, 'access', _653 => _653.local, 'optionalAccess', _654 => _654.type]) === "Identifier") {
|
|
8684
10473
|
addScopeBinding(ast, spec.local.name);
|
|
8685
10474
|
}
|
|
8686
10475
|
}
|
|
@@ -8697,7 +10486,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8697
10486
|
},
|
|
8698
10487
|
FunctionDeclaration(node, _state, ancestors) {
|
|
8699
10488
|
const parentAncestors = ancestors.slice(0, -1);
|
|
8700
|
-
if (_optionalChain([node, 'access',
|
|
10489
|
+
if (_optionalChain([node, 'access', _655 => _655.id, 'optionalAccess', _656 => _656.type]) === "Identifier") {
|
|
8701
10490
|
addScopeBinding(findNearestLexicalScope(parentAncestors), node.id.name);
|
|
8702
10491
|
addScopeBinding(findNearestFunctionOrProgram(parentAncestors), node.id.name);
|
|
8703
10492
|
}
|
|
@@ -8711,7 +10500,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8711
10500
|
rawCandidates.push({ fn: node, ancestors: ancestors.slice() });
|
|
8712
10501
|
},
|
|
8713
10502
|
FunctionExpression(node, _state, ancestors) {
|
|
8714
|
-
if (_optionalChain([node, 'access',
|
|
10503
|
+
if (_optionalChain([node, 'access', _657 => _657.id, 'optionalAccess', _658 => _658.type]) === "Identifier") {
|
|
8715
10504
|
addScopeBinding(node, node.id.name);
|
|
8716
10505
|
}
|
|
8717
10506
|
const paramNames = /* @__PURE__ */ new Set();
|
|
@@ -8734,13 +10523,13 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8734
10523
|
rawCandidates.push({ fn: node, ancestors: ancestors.slice() });
|
|
8735
10524
|
},
|
|
8736
10525
|
ClassDeclaration(node, _state, ancestors) {
|
|
8737
|
-
if (_optionalChain([node, 'access',
|
|
10526
|
+
if (_optionalChain([node, 'access', _659 => _659.id, 'optionalAccess', _660 => _660.type]) === "Identifier") {
|
|
8738
10527
|
addScopeBinding(findNearestLexicalScope(ancestors.slice(0, -1)), node.id.name);
|
|
8739
10528
|
addScopeBinding(node, node.id.name);
|
|
8740
10529
|
}
|
|
8741
10530
|
},
|
|
8742
10531
|
ClassExpression(node) {
|
|
8743
|
-
if (_optionalChain([node, 'access',
|
|
10532
|
+
if (_optionalChain([node, 'access', _661 => _661.id, 'optionalAccess', _662 => _662.type]) === "Identifier") {
|
|
8744
10533
|
addScopeBinding(node, node.id.name);
|
|
8745
10534
|
}
|
|
8746
10535
|
},
|
|
@@ -8772,7 +10561,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8772
10561
|
continue;
|
|
8773
10562
|
}
|
|
8774
10563
|
const parentNode = ancestors.length >= 2 ? ancestors[ancestors.length - 2] : null;
|
|
8775
|
-
if (_optionalChain([parentNode, 'optionalAccess',
|
|
10564
|
+
if (_optionalChain([parentNode, 'optionalAccess', _663 => _663.type]) === "MethodDefinition" && parentNode.kind === "constructor") {
|
|
8776
10565
|
continue;
|
|
8777
10566
|
}
|
|
8778
10567
|
if (ancestors.some((a) => a.type === "WithStatement")) {
|
|
@@ -8794,7 +10583,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8794
10583
|
}
|
|
8795
10584
|
}
|
|
8796
10585
|
}
|
|
8797
|
-
if (fn.type === "FunctionExpression" && _optionalChain([fn, 'access',
|
|
10586
|
+
if (fn.type === "FunctionExpression" && _optionalChain([fn, 'access', _664 => _664.id, 'optionalAccess', _665 => _665.type]) === "Identifier") {
|
|
8798
10587
|
enclosingBindings.add(fn.id.name);
|
|
8799
10588
|
}
|
|
8800
10589
|
const lowered = prepareLoweredFunction(fn, enclosingBindings);
|
|
@@ -8933,7 +10722,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8933
10722
|
seed,
|
|
8934
10723
|
windowKeySymbol,
|
|
8935
10724
|
expectedDelta,
|
|
8936
|
-
_optionalChain([extraOpts, 'optionalAccess',
|
|
10725
|
+
_optionalChain([extraOpts, 'optionalAccess', _666 => _666.expectedStateHash])
|
|
8937
10726
|
);
|
|
8938
10727
|
const parsedHelper = acorn6.parse(interpreterSource, {
|
|
8939
10728
|
ecmaVersion: "latest",
|
|
@@ -8942,7 +10731,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
8942
10731
|
let insertIdx = 0;
|
|
8943
10732
|
while (insertIdx < ast.body.length) {
|
|
8944
10733
|
const stmt = ast.body[insertIdx];
|
|
8945
|
-
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || _optionalChain([stmt, 'access',
|
|
10734
|
+
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || _optionalChain([stmt, 'access', _667 => _667.expression, 'optionalAccess', _668 => _668.type]) === "Literal" && typeof stmt.expression.value === "string" && /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim()));
|
|
8946
10735
|
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
8947
10736
|
insertIdx++;
|
|
8948
10737
|
} else {
|
|
@@ -9029,10 +10818,10 @@ function scrubResidualPaths(ast, options = {}, hotExemptNodes, exemptSubtreeRoot
|
|
|
9029
10818
|
Literal(node, _state, ancestors) {
|
|
9030
10819
|
if (node.regex || typeof node.value !== "string") return;
|
|
9031
10820
|
const val = node.value;
|
|
9032
|
-
if (_optionalChain([exemptSet, 'optionalAccess',
|
|
10821
|
+
if (_optionalChain([exemptSet, 'optionalAccess', _669 => _669.has, 'call', _670 => _670(val)])) return;
|
|
9033
10822
|
const parent = ancestors[ancestors.length - 2];
|
|
9034
10823
|
if (!parent) return;
|
|
9035
|
-
if ((
|
|
10824
|
+
if (isStaticModuleOrAssetPosition(node, parent)) {
|
|
9036
10825
|
return;
|
|
9037
10826
|
}
|
|
9038
10827
|
if (parent.type === "ExpressionStatement" && Boolean(parent.directive)) {
|
|
@@ -9054,12 +10843,12 @@ function scrubResidualPaths(ast, options = {}, hotExemptNodes, exemptSubtreeRoot
|
|
|
9054
10843
|
return;
|
|
9055
10844
|
}
|
|
9056
10845
|
const parent = ancestors[ancestors.length - 2];
|
|
9057
|
-
if (
|
|
10846
|
+
if (isStaticModuleOrAssetPosition(node, parent)) {
|
|
9058
10847
|
return;
|
|
9059
10848
|
}
|
|
9060
10849
|
for (const quasi of node.quasis) {
|
|
9061
|
-
const val = _nullishCoalesce(_optionalChain([quasi, 'optionalAccess',
|
|
9062
|
-
if (typeof val !== "string" || _optionalChain([exemptSet, 'optionalAccess',
|
|
10850
|
+
const val = _nullishCoalesce(_optionalChain([quasi, 'optionalAccess', _671 => _671.value, 'optionalAccess', _672 => _672.cooked]), () => ( _optionalChain([quasi, 'optionalAccess', _673 => _673.value, 'optionalAccess', _674 => _674.raw])));
|
|
10851
|
+
if (typeof val !== "string" || _optionalChain([exemptSet, 'optionalAccess', _675 => _675.has, 'call', _676 => _676(val)])) continue;
|
|
9063
10852
|
const scrubbed = scrubStringValue(val, options.rootDir);
|
|
9064
10853
|
if (scrubbed !== val) {
|
|
9065
10854
|
quasi.value.cooked = scrubbed;
|
|
@@ -9099,24 +10888,24 @@ function isAstAlreadyProtected(ast) {
|
|
|
9099
10888
|
return ast.body.some((stmt) => {
|
|
9100
10889
|
if (stmt.type === "VariableDeclaration" && Array.isArray(stmt.declarations)) {
|
|
9101
10890
|
for (const d of stmt.declarations) {
|
|
9102
|
-
const name = _optionalChain([d, 'access',
|
|
10891
|
+
const name = _optionalChain([d, 'access', _677 => _677.id, 'optionalAccess', _678 => _678.type]) === "Identifier" ? d.id.name : void 0;
|
|
9103
10892
|
if (typeof name === "string") {
|
|
9104
|
-
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") || _optionalChain([d, 'access',
|
|
10893
|
+
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") || _optionalChain([d, 'access', _679 => _679.init, 'optionalAccess', _680 => _680.type]) === "CallExpression" && _optionalChain([d, 'access', _681 => _681.init, 'access', _682 => _682.callee, 'optionalAccess', _683 => _683.type]) === "FunctionExpression" && _optionalChain([d, 'access', _684 => _684.init, 'access', _685 => _685.callee, 'optionalAccess', _686 => _686.id, 'optionalAccess', _687 => _687.name]) === "f" && _optionalChain([d, 'access', _688 => _688.init, 'access', _689 => _689.arguments, 'optionalAccess', _690 => _690[0], 'optionalAccess', _691 => _691.type]) === "ArrayExpression" || _optionalChain([d, 'access', _692 => _692.init, 'optionalAccess', _693 => _693.type]) === "CallExpression" && _optionalChain([d, 'access', _694 => _694.init, 'access', _695 => _695.callee, 'optionalAccess', _696 => _696.type]) === "MemberExpression" && _optionalChain([d, 'access', _697 => _697.init, 'access', _698 => _698.callee, 'access', _699 => _699.object, 'optionalAccess', _700 => _700.type]) === "Identifier" && d.init.callee.object.name === "Symbol" && _optionalChain([d, 'access', _701 => _701.init, 'access', _702 => _702.callee, 'access', _703 => _703.property, 'optionalAccess', _704 => _704.type]) === "Identifier" && d.init.callee.property.name === "for" && typeof _optionalChain([d, 'access', _705 => _705.init, 'access', _706 => _706.arguments, 'optionalAccess', _707 => _707[0], 'optionalAccess', _708 => _708.value]) === "string" && d.init.arguments[0].value.startsWith("__upk_v4_")) {
|
|
9105
10894
|
return true;
|
|
9106
10895
|
}
|
|
9107
10896
|
}
|
|
9108
10897
|
}
|
|
9109
10898
|
}
|
|
9110
|
-
if (stmt.type === "FunctionDeclaration" && _optionalChain([stmt, 'access',
|
|
10899
|
+
if (stmt.type === "FunctionDeclaration" && _optionalChain([stmt, 'access', _709 => _709.id, 'optionalAccess', _710 => _710.type]) === "Identifier") {
|
|
9111
10900
|
const fnName = stmt.id.name;
|
|
9112
|
-
if (typeof fnName === "string" && (fnName.startsWith("_uD") || fnName.startsWith("_uVm") || fnName.startsWith("_wKdf") || fnName === "_hX")) {
|
|
10901
|
+
if (typeof fnName === "string" && (fnName.startsWith("_uD") || fnName.startsWith("_uVm") || fnName.startsWith("_wKdf") || fnName.startsWith("_uLr") || fnName.startsWith("_uMx") || fnName === "_hX")) {
|
|
9113
10902
|
return true;
|
|
9114
10903
|
}
|
|
9115
10904
|
}
|
|
9116
|
-
if (stmt.type === "ExpressionStatement" && _optionalChain([stmt, 'access',
|
|
10905
|
+
if (stmt.type === "ExpressionStatement" && _optionalChain([stmt, 'access', _711 => _711.expression, 'optionalAccess', _712 => _712.type]) === "CallExpression") {
|
|
9117
10906
|
const callee = stmt.expression.callee;
|
|
9118
|
-
if (_optionalChain([callee, 'optionalAccess',
|
|
9119
|
-
const name = _optionalChain([callee, 'access',
|
|
10907
|
+
if (_optionalChain([callee, 'optionalAccess', _713 => _713.type]) === "FunctionExpression") {
|
|
10908
|
+
const name = _optionalChain([callee, 'access', _714 => _714.id, 'optionalAccess', _715 => _715.name]);
|
|
9120
10909
|
if (typeof name === "string" && name.startsWith("_u$") || containsUnpeekShieldMarker(callee.body)) {
|
|
9121
10910
|
return true;
|
|
9122
10911
|
}
|
|
@@ -9128,7 +10917,7 @@ function isAstAlreadyProtected(ast) {
|
|
|
9128
10917
|
function transformJavaScript(code, options = {}) {
|
|
9129
10918
|
const internalOptions = options;
|
|
9130
10919
|
const seed = _nullishCoalesce(internalOptions.seed, () => ( 2654435769));
|
|
9131
|
-
const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([options, 'access',
|
|
10920
|
+
const minStringLength = _nullishCoalesce(_nullishCoalesce(options.minStringLength, () => ( _optionalChain([options, 'access', _716 => _716.config, 'optionalAccess', _717 => _717.vault, 'optionalAccess', _718 => _718.minStringLength]))), () => ( 4));
|
|
9132
10921
|
const isAggressive = _nullishCoalesce(options.aggressive, () => ( false));
|
|
9133
10922
|
if (!code || !code.trim()) {
|
|
9134
10923
|
const emptyResult = {
|
|
@@ -9193,7 +10982,7 @@ function transformJavaScript(code, options = {}) {
|
|
|
9193
10982
|
const boundary = classifyChunkBoundary(ast);
|
|
9194
10983
|
attachMagicComments(boundary.importExpressions, comments);
|
|
9195
10984
|
const effectiveConfig = options.critical ? { ..._nullishCoalesce(options.config, () => ( {})), critical: options.critical } : options.config;
|
|
9196
|
-
const effectiveProfile = _nullishCoalesce(options.profile, () => ( _optionalChain([effectiveConfig, 'optionalAccess',
|
|
10985
|
+
const effectiveProfile = _nullishCoalesce(options.profile, () => ( _optionalChain([effectiveConfig, 'optionalAccess', _719 => _719.profile])));
|
|
9197
10986
|
const originalSourceMap = internalOptions.originalSourceMap;
|
|
9198
10987
|
const hotRes = analyzeAstHotPaths(ast, effectiveConfig, originalSourceMap);
|
|
9199
10988
|
const {
|
|
@@ -9204,7 +10993,7 @@ function transformJavaScript(code, options = {}) {
|
|
|
9204
10993
|
serializedFunctionNodes
|
|
9205
10994
|
} = hotRes;
|
|
9206
10995
|
const criticalFunctionNodes = hotRes.criticalFunctionNodes;
|
|
9207
|
-
if (options.scrubPaths || _optionalChain([effectiveConfig, 'optionalAccess',
|
|
10996
|
+
if (options.scrubPaths || _optionalChain([effectiveConfig, 'optionalAccess', _720 => _720.scrubPaths])) {
|
|
9208
10997
|
scrubResidualPaths(
|
|
9209
10998
|
ast,
|
|
9210
10999
|
{
|
|
@@ -9216,8 +11005,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
9216
11005
|
);
|
|
9217
11006
|
}
|
|
9218
11007
|
const shieldCoupled = _nullishCoalesce(internalOptions.shieldCoupled, () => ( Boolean(internalOptions.injectRuntimeShield)));
|
|
9219
|
-
const deterrentMode = _nullishCoalesce(_nullishCoalesce(internalOptions.deterrentMode, () => ( _optionalChain([effectiveConfig, 'optionalAccess',
|
|
9220
|
-
const detectHeadless = _nullishCoalesce(_nullishCoalesce(internalOptions.detectHeadless, () => ( _optionalChain([effectiveConfig, 'optionalAccess',
|
|
11008
|
+
const deterrentMode = _nullishCoalesce(_nullishCoalesce(internalOptions.deterrentMode, () => ( _optionalChain([effectiveConfig, 'optionalAccess', _721 => _721.shield, 'optionalAccess', _722 => _722.deterrentMode]))), () => ( "passive"));
|
|
11009
|
+
const detectHeadless = _nullishCoalesce(_nullishCoalesce(internalOptions.detectHeadless, () => ( _optionalChain([effectiveConfig, 'optionalAccess', _723 => _723.shield, 'optionalAccess', _724 => _724.detectHeadless]))), () => ( false));
|
|
9221
11010
|
const sym = shieldCoupled ? _nullishCoalesce(internalOptions.windowKeySymbol, () => ( deriveWindowKeySymbol(seed))) : void 0;
|
|
9222
11011
|
let shieldDelta = shieldCoupled ? internalOptions.expectedDelta : void 0;
|
|
9223
11012
|
let expectedStateHash = shieldCoupled ? internalOptions.expectedStateHash : void 0;
|
|
@@ -9237,9 +11026,9 @@ function transformJavaScript(code, options = {}) {
|
|
|
9237
11026
|
}
|
|
9238
11027
|
let virtualizedFunctionsCount = 0;
|
|
9239
11028
|
if (isAggressive) {
|
|
9240
|
-
const extraVmOpts = criticalFunctionNodes || _optionalChain([effectiveConfig, 'optionalAccess',
|
|
11029
|
+
const extraVmOpts = criticalFunctionNodes || _optionalChain([effectiveConfig, 'optionalAccess', _725 => _725.critical, 'optionalAccess', _726 => _726.maxFunctionsPerChunk]) !== void 0 || expectedStateHash !== void 0 ? {
|
|
9241
11030
|
...criticalFunctionNodes ? { criticalFunctionNodes } : {},
|
|
9242
|
-
..._optionalChain([effectiveConfig, 'optionalAccess',
|
|
11031
|
+
..._optionalChain([effectiveConfig, 'optionalAccess', _727 => _727.critical, 'optionalAccess', _728 => _728.maxFunctionsPerChunk]) !== void 0 ? { maxFunctionsPerChunk: effectiveConfig.critical.maxFunctionsPerChunk } : {},
|
|
9243
11032
|
...expectedStateHash !== void 0 ? { expectedStateHash } : {}
|
|
9244
11033
|
} : void 0;
|
|
9245
11034
|
const vmRes = extraVmOpts ? applyMicroVm(
|
|
@@ -9260,17 +11049,20 @@ function transformJavaScript(code, options = {}) {
|
|
|
9260
11049
|
);
|
|
9261
11050
|
virtualizedFunctionsCount = vmRes.virtualizedCount;
|
|
9262
11051
|
}
|
|
9263
|
-
|
|
9264
|
-
|
|
11052
|
+
let coldFlowGuardedCount = 0;
|
|
11053
|
+
if (effectiveProfile !== "minimal" && _optionalChain([effectiveConfig, 'optionalAccess', _729 => _729.coldFlow]) !== false) {
|
|
11054
|
+
coldFlowGuardedCount = applyColdFlowGuard(
|
|
9265
11055
|
ast,
|
|
9266
11056
|
coldFunctionNodes,
|
|
9267
11057
|
seed,
|
|
9268
11058
|
hotExemptNodes,
|
|
9269
11059
|
sym,
|
|
9270
11060
|
shieldDelta,
|
|
9271
|
-
shieldCoupled
|
|
11061
|
+
shieldCoupled,
|
|
11062
|
+
{ enableBitwiseMba: isAggressive || effectiveProfile === "strict" }
|
|
9272
11063
|
);
|
|
9273
11064
|
}
|
|
11065
|
+
const latchCoupling = coldFlowGuardedCount > 0 ? deriveColdLatchCoupling(seed) : void 0;
|
|
9274
11066
|
const mangledSymbolsCount = applyPolymorphicMangler(
|
|
9275
11067
|
ast,
|
|
9276
11068
|
seed,
|
|
@@ -9292,7 +11084,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
9292
11084
|
deterrentMode,
|
|
9293
11085
|
shieldCoupled,
|
|
9294
11086
|
detectHeadless,
|
|
9295
|
-
boundary.exemptSubtreeRoots
|
|
11087
|
+
boundary.exemptSubtreeRoots,
|
|
11088
|
+
latchCoupling
|
|
9296
11089
|
);
|
|
9297
11090
|
encryptedStringsCount = saltedRes.encryptedStringsCount;
|
|
9298
11091
|
integrityToken = saltedRes.integrityToken;
|
|
@@ -9309,7 +11102,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
9309
11102
|
effectiveConfig,
|
|
9310
11103
|
shieldCoupled,
|
|
9311
11104
|
detectHeadless,
|
|
9312
|
-
boundary.exemptSubtreeRoots
|
|
11105
|
+
boundary.exemptSubtreeRoots,
|
|
11106
|
+
latchCoupling
|
|
9313
11107
|
);
|
|
9314
11108
|
encryptedStringsCount = vaultRes.encryptedStringsCount;
|
|
9315
11109
|
integrityToken = vaultRes.integrityToken;
|
|
@@ -9379,4 +11173,6 @@ ${finalCode}`;
|
|
|
9379
11173
|
|
|
9380
11174
|
|
|
9381
11175
|
|
|
9382
|
-
|
|
11176
|
+
|
|
11177
|
+
|
|
11178
|
+
exports.computeFnv1aHash = computeFnv1aHash; exports.flattenSourceMapSections = flattenSourceMapSections; exports.shiftSourceMapLines = shiftSourceMapLines; exports.computeDeterministicDebugId = computeDeterministicDebugId; exports.chainSourceMaps = chainSourceMaps; exports.resolvePosition = resolvePosition; exports.safeDecodeURIComponent = safeDecodeURIComponent; exports.symbolicateStackTrace = symbolicateStackTrace; exports.detectHotPaths = detectHotPaths; exports.computeIntegrityHash = computeIntegrityHash; exports.verifyCodeIntegrity = verifyCodeIntegrity; exports.deriveWindowKeySymbol = deriveWindowKeySymbol; exports.createDeterrentSnippet = createDeterrentSnippet; exports.generateRuntimeShield = generateRuntimeShield; exports.classifyPlaintextSecret = classifyPlaintextSecret; exports.hasRegexSecretRun = hasRegexSecretRun; exports.transformJavaScript = transformJavaScript;
|