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({}, 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 = node.imported?.type === "Identifier" && node.local?.type === "Identifier" && node.imported.name === node.local.name;
|
|
2822
|
+
if (!sameIdent && node.local?.name) {
|
|
2823
|
+
state.write(" as " + node.local.name);
|
|
2824
|
+
}
|
|
2825
|
+
},
|
|
2826
|
+
ExportSpecifier(node, state) {
|
|
2827
|
+
writeModuleBindingName(this, node.local, state);
|
|
2828
|
+
const sameIdent = node.local?.type === "Identifier" && node.exported?.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 = options?.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),
|
|
@@ -3747,12 +3921,13 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
3747
3921
|
const id = existing?.declarations[0]?.id?.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;
|
|
@@ -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 (obj?.type !== "MetaProperty" || obj.meta?.type !== "Identifier" || obj.meta.name !== "import" || obj.property?.type !== "Identifier" || obj.property.name !== "meta") {
|
|
4132
|
+
return false;
|
|
4133
|
+
}
|
|
4134
|
+
if (!node.computed && node.property?.type === "Identifier") {
|
|
4135
|
+
return node.property.name === propName;
|
|
4136
|
+
}
|
|
4137
|
+
return node.computed && node.property?.type === "Literal" && node.property.value === propName;
|
|
4138
|
+
}
|
|
4139
|
+
function isRequireResolveCallee(callee) {
|
|
4140
|
+
if (!callee || callee.type !== "MemberExpression") return false;
|
|
4141
|
+
if (callee.object?.type !== "Identifier" || callee.object.name !== "require") {
|
|
4142
|
+
return false;
|
|
4143
|
+
}
|
|
4144
|
+
if (!callee.computed && callee.property?.type === "Identifier") {
|
|
4145
|
+
return callee.property.name === "resolve";
|
|
4146
|
+
}
|
|
4147
|
+
return callee.computed && callee.property?.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 parent.callee?.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 (callee?.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,6 +4189,10 @@ 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
4197
|
const isPushCall = callee?.type === "MemberExpression" && (!callee.computed && callee.property?.type === "Identifier" && callee.property.name === "push" || callee.computed && callee.property?.type === "Literal" && callee.property.value === "push");
|
|
3963
4198
|
if (isPushCall) {
|
|
@@ -4021,6 +4256,49 @@ function classifyChunkBoundary(ast) {
|
|
|
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 (spec?.type === "ImportSpecifier" && spec.imported?.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 (spec?.type === "ExportSpecifier") {
|
|
4284
|
+
if (spec.local?.type === "Literal") {
|
|
4285
|
+
exemptSubtreeRoots.add(spec.local);
|
|
4286
|
+
}
|
|
4287
|
+
if (spec.exported?.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") {
|
|
@@ -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",
|
|
@@ -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,
|
|
@@ -4202,16 +4494,39 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
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: 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 = 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 q?.value?.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 = 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, (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, target.flags ?? "")
|
|
4745
|
+
);
|
|
4746
|
+
} else {
|
|
4747
|
+
if (target.parent?.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, (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([
|
|
@@ -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
|
}
|
|
@@ -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 (lhs.object?.type === "Identifier" && lhs.object.name === "module" && (!lhs.computed && lhs.property?.type === "Identifier" && lhs.property.name === "exports" || lhs.computed && lhs.property?.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" && anc.callee?.type === "MemberExpression" && !anc.callee.computed && anc.callee.object?.type === "Identifier" && anc.callee.object.name === "Object" && anc.callee.property?.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,7 +5381,223 @@ function findLowestCommonScope(ast, chains) {
|
|
|
4825
5381
|
}
|
|
4826
5382
|
return lca[lca.length - 1] ?? ast;
|
|
4827
5383
|
}
|
|
4828
|
-
function
|
|
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 += quasi.value?.raw ?? "";
|
|
5420
|
+
pendingCooked += quasi.value?.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) => prop?.type === "Property" ? patternContainsIdentifier(prop.value, targetName) : prop?.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 (node.id?.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 (node.id?.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 (node.id?.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 (node.id?.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) => s?.local?.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(d?.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 = node?.regex?.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) {
|
|
4829
5601
|
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
4830
5602
|
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
4831
5603
|
if (config?.vault?.customDirectives) {
|
|
@@ -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 = 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 = 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 = 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 q?.value?.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,38 +5859,69 @@ 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
|
}
|
|
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
|
+
}
|
|
5037
5892
|
if (parent?.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, target.flags ?? "");
|
|
5911
|
+
return;
|
|
5912
|
+
}
|
|
5913
|
+
if (target.parent?.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
5926
|
const wantFragmented = Boolean(config?.vault?.fragmented);
|
|
5065
5927
|
let fragCount = Math.max(2, Math.min(8, Math.floor(config?.vault?.fragmentCount ?? 3)));
|
|
@@ -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 ? (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) {
|
|
@@ -5212,6 +6075,7 @@ 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
6081
|
(stmt) => stmt.type === "FunctionDeclaration" && stmt.id?.name === "_hX"
|
|
@@ -5433,14 +6297,55 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
5433
6297
|
}
|
|
5434
6298
|
const manglerConfig = config?.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 (stmt?.type !== "ExpressionStatement") break;
|
|
6308
|
+
const isStrLit = stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string";
|
|
6309
|
+
if (!stmt.directive && !isStrLit) break;
|
|
6310
|
+
if (stmt.directive === "use strict" || stmt.expression?.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) && anc.body?.type === "BlockStatement" && hasStrictDirective(anc.body.body)) {
|
|
6332
|
+
return false;
|
|
6333
|
+
}
|
|
6334
|
+
}
|
|
6335
|
+
if (fnNode.body?.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) => p?.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 && node.callee?.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
|
},
|
|
@@ -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
|
import * as acorn5 from "acorn";
|
|
5817
6759
|
import * as walk6 from "acorn-walk";
|
|
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
|
}
|
|
@@ -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" ? "^" : "|";
|
|
@@ -6404,8 +7403,8 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
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
|
|
7406
|
+
const slotA = 2 + (fnIndex + (seed & 1) & 1);
|
|
7407
|
+
const slotB = slotA ^ 1;
|
|
6409
7408
|
const hasAlias = Boolean(ctxOpts?.aliasIdentA);
|
|
6410
7409
|
const aliasReadIdent = ctxOpts?.aliasIdentB ?? ctxOpts?.aliasIdentA ?? "";
|
|
6411
7410
|
let qnrLeft;
|
|
@@ -6586,7 +7585,8 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
6586
7585
|
zRefForDecoy
|
|
6587
7586
|
);
|
|
6588
7587
|
const hasShieldCoupling = Boolean(ctxOpts?.shieldCoupled && ctxOpts?.windowKeySymbol);
|
|
6589
|
-
const
|
|
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,7 +7597,7 @@ 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
7603
|
const pathA = ctxOpts?.scratchVarIdent ? {
|
|
@@ -6607,7 +7607,7 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
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,351 +7654,1130 @@ 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 (ctxOpts?.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 (ctxOpts?.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 && fnNode.body?.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 = () => scopeStack[scopeStack.length - 1] ?? ast;
|
|
8172
|
+
const getNearestVarScope = () => 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 (node.local?.type === "Identifier") {
|
|
8191
|
+
addBinding(ast, node.local.name);
|
|
8192
|
+
}
|
|
8193
|
+
} else if (node.type === "FunctionDeclaration") {
|
|
8194
|
+
if (node.id?.type === "Identifier") {
|
|
8195
|
+
addBinding(getNearestLexicalScope(), node.id.name);
|
|
8196
|
+
addBinding(getNearestVarScope(), node.id.name);
|
|
8197
|
+
}
|
|
8198
|
+
} else if (node.type === "ClassDeclaration") {
|
|
8199
|
+
if (node.id?.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 (node.id?.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 = node.body?.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" && node.id?.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 (operand?.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 (hotExemptNodes?.has(node) || guardSubtreeNodes?.has(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 = left?.type === "Identifier" || right?.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 (node.local?.name === "Math") unsafe.add(ast);
|
|
8507
|
+
},
|
|
8508
|
+
ImportDefaultSpecifier(node) {
|
|
8509
|
+
if (node.local?.name === "Math") unsafe.add(ast);
|
|
8510
|
+
},
|
|
8511
|
+
ImportNamespaceSpecifier(node) {
|
|
8512
|
+
if (node.local?.name === "Math") unsafe.add(ast);
|
|
8513
|
+
},
|
|
8514
|
+
FunctionDeclaration(node, _st, ancestors) {
|
|
8515
|
+
if (node.id?.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 (node.id?.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 (node.id?.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 (node.id?.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(d?.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 stmt.expression?.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 (hotExemptNodes?.has(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
8607
|
(stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
|
|
6927
8608
|
(d) => d.id?.type === "Identifier" && (d.id.name === decoyIdent || d.id.name === sboxIdent || d.id.name === mxIdent)
|
|
6928
|
-
)
|
|
8609
|
+
) || stmt.type === "FunctionDeclaration" && stmt.id?.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 (options?.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: node.params?.[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
8783
|
if (decl.init?.type === "ArrayExpression" && decl.init.elements) {
|
|
@@ -7018,9 +8797,16 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
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);
|
|
@@ -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++) {
|
|
@@ -7860,6 +9648,7 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings, seed = 2654
|
|
|
7860
9648
|
emit(OP_LDC, addConst(quasis[0]?.value?.cooked ?? quasis[0]?.value?.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
9653
|
const qStr = quasis[i + 1]?.value?.cooked ?? quasis[i + 1]?.value?.raw ?? "";
|
|
7865
9654
|
if (qStr.length > 0) {
|
|
@@ -9032,7 +10821,7 @@ function scrubResidualPaths(ast, options = {}, hotExemptNodes, exemptSubtreeRoot
|
|
|
9032
10821
|
if (exemptSet?.has(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,7 +10843,7 @@ 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) {
|
|
@@ -9109,7 +10898,7 @@ function isAstAlreadyProtected(ast) {
|
|
|
9109
10898
|
}
|
|
9110
10899
|
if (stmt.type === "FunctionDeclaration" && stmt.id?.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
|
}
|
|
@@ -9260,17 +11049,20 @@ function transformJavaScript(code, options = {}) {
|
|
|
9260
11049
|
);
|
|
9261
11050
|
virtualizedFunctionsCount = vmRes.virtualizedCount;
|
|
9262
11051
|
}
|
|
11052
|
+
let coldFlowGuardedCount = 0;
|
|
9263
11053
|
if (effectiveProfile !== "minimal" && effectiveConfig?.coldFlow !== false) {
|
|
9264
|
-
applyColdFlowGuard(
|
|
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;
|
|
@@ -9378,5 +11172,7 @@ export {
|
|
|
9378
11172
|
deriveWindowKeySymbol,
|
|
9379
11173
|
createDeterrentSnippet,
|
|
9380
11174
|
generateRuntimeShield,
|
|
11175
|
+
classifyPlaintextSecret,
|
|
11176
|
+
hasRegexSecretRun,
|
|
9381
11177
|
transformJavaScript
|
|
9382
11178
|
};
|