unpeek 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/README.tr.md +7 -7
- package/dist/adapters/esbuild.cjs +4 -4
- package/dist/adapters/esbuild.js +2 -2
- package/dist/adapters/next/adapter.cjs +4 -4
- package/dist/adapters/next/adapter.js +3 -3
- package/dist/adapters/next/index.cjs +4 -4
- package/dist/adapters/next/index.js +3 -3
- package/dist/adapters/rollup.cjs +4 -4
- package/dist/adapters/rollup.js +2 -2
- package/dist/adapters/rspack.cjs +4 -4
- package/dist/adapters/rspack.js +2 -2
- package/dist/adapters/vite.cjs +4 -4
- package/dist/adapters/vite.js +2 -2
- package/dist/adapters/webpack.cjs +4 -4
- package/dist/adapters/webpack.js +2 -2
- package/dist/browser.cjs +2 -2
- package/dist/browser.d.cts +3 -2
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +1 -1
- package/dist/{chunk-STTUFUDC.js → chunk-APQOBFRO.js} +1 -1
- package/dist/{chunk-6KLUNEKE.js → chunk-BL2UXZGD.js} +1187 -162
- package/dist/{chunk-TOUYQ4N5.js → chunk-GCWXTWTN.js} +1 -1
- package/dist/{chunk-HV47WJIR.js → chunk-K77WRITN.js} +2 -2
- package/dist/{chunk-WYW5UOBE.cjs → chunk-KIAYVIC5.cjs} +11 -11
- package/dist/{chunk-VLL4THTG.cjs → chunk-MSECP2P4.cjs} +1326 -301
- package/dist/{chunk-FLZ4FSP5.cjs → chunk-SJK45WAU.cjs} +6 -6
- package/dist/{chunk-Q4DFRMAV.cjs → chunk-UUJLTW7O.cjs} +9 -9
- package/dist/cli/index.js +1332 -171
- package/dist/index.cjs +159 -19
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +150 -10
- package/dist/plugins/unplugin.cjs +3 -3
- package/dist/plugins/unplugin.js +2 -2
- package/dist/{types-BZqvBhBI.d.ts → types-BDpFfokR.d.ts} +2 -1
- package/dist/{types-E4ugA4Oz.d.cts → types-WIoud53X.d.cts} +2 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -3991,7 +3991,7 @@ function createDeterrentSnippet(config) {
|
|
|
3991
3991
|
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=()=>0;" : "";
|
|
3992
3992
|
const symLit = JSON.stringify(sym);
|
|
3993
3993
|
const headlessDecl = detectHeadless ? ",n=w.navigator||0" : "";
|
|
3994
|
-
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)" : "";
|
|
3994
|
+
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)||['__playwright','__puppeteer_evaluation_script__','__nightmare','frida','_frida_'].some(k=>w[k]||G[k])" : "";
|
|
3995
3995
|
const k1Mul = (seed | 1) >>> 0;
|
|
3996
3996
|
return `(function ${fnName}(w){var G=globalThis||w;if(w){var O=Object,P=O.getOwnPropertyDescriptor,RF=G.Reflect,R=RF&&RF.apply,FP=Function.prototype,SP=String.prototype,ER=Error,EP=ER.prototype,Q='__unpeek_',y=${symLit},z=y+'_s',U='__unpeek_tampered',K=Q+'seed',ST='stack',PS='prepareStackTrace',A='\\n at ',T=(o,k)=>{try{for(var r;o;o=O.getPrototypeOf(o))if((r=P(o,k))&&(r.set||!r.writable))return 1;}catch(e){return 1;}},D=k=>T(w,k)|T(G,k),B=(k,v,c,W)=>{W=o=>{try{if(!c||!T(o,k))o[k]=v;}catch(e){}};W(G);W(w);},s=FP.toString${headlessDecl},src='',t=+((G[z]||w[z])?.[0]==2),sd=P(EP,ST),ep=ER[PS],M=/^function (?:get )?(\\w*)\\(\\)\\s*\\x7b\\s*\\[native code\\]\\s*\\}$/;try{var ps,rf=P(new ER(),ST),Z=()=>{if(ER[PS]!==void 0){if(typeof process>'u')t=1;ER[PS]=void 0;}},F=(f,n,l)=>typeof f!='function'||'prototype'in f||(l>=0&&(f.name!=n||f.length!=l))||M.exec(R(R,null,[s,f,[]]))?.[1]!=n,E=(f,a,b)=>{try{R(f,a,b);t=1;}catch(e){Z();var ed=P(e,ST),st=sd&&sd.get?R(sd.get,e,[]):ed&&ed.get?R(ed.get,e,[]):e[ST];if(ed&&(!rf||F(ed.get,'',0)))t=1;t|=e?.name!='TypeError'||!st||st.indexOf(A)<0||/(?:Object|Proxy)\\.apply\\b|\\n at (?!.* \\(<anonymous>\\)$)/m.test(st.split(A+'E (')[0]);}};Z();try{E(P,null,[]);E(s,{toString(){}},[]);E(R,s,[null,s,[]]);}finally{if(ep!==void 0)ER[PS]=ep;}src=R(s,${fnName},[]);t|=(sd&&F(sd.get,ST,-1))|F(R,'apply',3)|F(s,'toString',0)|s.call(T)!==(ps=R(s,T,[]))|FP.call.call(s,T)!==ps|/\\n/.test(src)${headlessCond};}catch(e){t=1;}t|=D(y)|D(z)|D(U)|T(SP,'_u')|T(FP,'toString')|T(FP,'call')|T(RF,'apply')|T(ER,PS)|(sd?T(O.getPrototypeOf(EP),ST):T(EP,ST));for(var h=2166136261,i=0;i<src.length;)h=Math.imul(h^src.charCodeAt(i++),16777619);var d=h&65535,pd=t?d^((h>>>16^23131)||1):d;B(z,[t+1,h^${seed}^t,h^${k1Mul}^t,1,d^h>>>16],t);B(y,pd,t);if(t){B(y+'_t',!0);B(Q+'delta',pd);try{SP._u=14;}catch(e){}B(K,((w[K]||${seed})^1)>>>0);B(U,!0);try{${consoleSilence}w.dispatchEvent?.(new CustomEvent('unpeek:tamper'));}catch(e){}}}})(typeof window!=='undefined'?window:typeof self<'u'?self:typeof globalThis<'u'?globalThis:0);`;
|
|
3997
3997
|
}
|
|
@@ -4092,7 +4092,88 @@ function deriveWasmHostParams(seed) {
|
|
|
4092
4092
|
const pcMask = computeFnv1aHash("wasm-pcmask", seed) | 1 | 0;
|
|
4093
4093
|
return { gArr, sOff, rA0, rA1, rA2, rA3, gMask, pcMask };
|
|
4094
4094
|
}
|
|
4095
|
-
|
|
4095
|
+
var ABI_START_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
|
4096
|
+
var ABI_CONT_CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
|
4097
|
+
var FORBIDDEN_ABI_NAMES = /* @__PURE__ */ new Set([
|
|
4098
|
+
"env",
|
|
4099
|
+
"g",
|
|
4100
|
+
"m",
|
|
4101
|
+
"kdf",
|
|
4102
|
+
"bulkmix",
|
|
4103
|
+
"mem",
|
|
4104
|
+
"as",
|
|
4105
|
+
"do",
|
|
4106
|
+
"if",
|
|
4107
|
+
"in",
|
|
4108
|
+
"of",
|
|
4109
|
+
"for",
|
|
4110
|
+
"int",
|
|
4111
|
+
"let",
|
|
4112
|
+
"new",
|
|
4113
|
+
"try",
|
|
4114
|
+
"var",
|
|
4115
|
+
"nan",
|
|
4116
|
+
"map",
|
|
4117
|
+
"set",
|
|
4118
|
+
"url",
|
|
4119
|
+
"top",
|
|
4120
|
+
"get",
|
|
4121
|
+
"set"
|
|
4122
|
+
]);
|
|
4123
|
+
function avalancheMix32(h) {
|
|
4124
|
+
let x = h >>> 0;
|
|
4125
|
+
x = Math.imul(x ^ x >>> 16, 2246822507) >>> 0;
|
|
4126
|
+
x = Math.imul(x ^ x >>> 13, 3266489909) >>> 0;
|
|
4127
|
+
return (x ^ x >>> 16) >>> 0;
|
|
4128
|
+
}
|
|
4129
|
+
function encodeWasmName(name) {
|
|
4130
|
+
const utf8 = new TextEncoder().encode(name);
|
|
4131
|
+
return [...encodeUnsignedLeb128(utf8.length), ...utf8];
|
|
4132
|
+
}
|
|
4133
|
+
function deriveWasmAbiNames(seed) {
|
|
4134
|
+
const s = seed >>> 0;
|
|
4135
|
+
const used = new Set(FORBIDDEN_ABI_NAMES);
|
|
4136
|
+
const pickName = (role) => {
|
|
4137
|
+
for (let attempt = 0; attempt < 64; attempt++) {
|
|
4138
|
+
const h = avalancheMix32(computeFnv1aHash(`wasm-abi:${role}:${attempt}`, s));
|
|
4139
|
+
const len = h >>> 18 & 1 ? 3 : 2;
|
|
4140
|
+
const c0 = ABI_START_CHARS[h % ABI_START_CHARS.length];
|
|
4141
|
+
const c1 = ABI_CONT_CHARS[(h >>> 6) % ABI_CONT_CHARS.length];
|
|
4142
|
+
const c2 = len === 3 ? ABI_CONT_CHARS[(h >>> 12) % ABI_CONT_CHARS.length] : "";
|
|
4143
|
+
const candidate = `${c0}${c1}${c2}`;
|
|
4144
|
+
const lower = candidate.toLowerCase();
|
|
4145
|
+
if (!candidate.startsWith("__") && !used.has(lower)) {
|
|
4146
|
+
used.add(lower);
|
|
4147
|
+
return candidate;
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
const fallback = `w${s.toString(36).slice(0, 2).padStart(2, "0")}`;
|
|
4151
|
+
used.add(fallback.toLowerCase());
|
|
4152
|
+
return fallback;
|
|
4153
|
+
};
|
|
4154
|
+
const envMod = pickName("envMod");
|
|
4155
|
+
const gImport = pickName("gImport");
|
|
4156
|
+
const mImport = pickName("mImport");
|
|
4157
|
+
const kdfExport = pickName("kdfExport");
|
|
4158
|
+
const bulkMixExport = pickName("bulkMixExport");
|
|
4159
|
+
const memExport = pickName("memExport");
|
|
4160
|
+
const exportOrder = [0, 1, 2];
|
|
4161
|
+
const orderHash = avalancheMix32(computeFnv1aHash("wasm-abi:order", s));
|
|
4162
|
+
const j2 = orderHash % 3;
|
|
4163
|
+
[exportOrder[2], exportOrder[j2]] = [exportOrder[j2], exportOrder[2]];
|
|
4164
|
+
const j1 = (orderHash >>> 8) % 2;
|
|
4165
|
+
[exportOrder[1], exportOrder[j1]] = [exportOrder[j1], exportOrder[1]];
|
|
4166
|
+
return {
|
|
4167
|
+
envMod,
|
|
4168
|
+
gImport,
|
|
4169
|
+
mImport,
|
|
4170
|
+
kdfExport,
|
|
4171
|
+
bulkMixExport,
|
|
4172
|
+
memExport,
|
|
4173
|
+
exportOrder
|
|
4174
|
+
};
|
|
4175
|
+
}
|
|
4176
|
+
function generateWasmKdfBinary(seed, options) {
|
|
4096
4177
|
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
4097
4178
|
const { gMask, pcMask } = deriveWasmHostParams(seed);
|
|
4098
4179
|
const memBase = (seed >>> 0 & 127) * 4;
|
|
@@ -4618,27 +4699,23 @@ function generateWasmKdfBinary(seed) {
|
|
|
4618
4699
|
...encodeUnsignedLeb128(typePayload.length),
|
|
4619
4700
|
...typePayload
|
|
4620
4701
|
];
|
|
4702
|
+
const abi = options?.polymorphicAbi ? deriveWasmAbiNames(seed) : null;
|
|
4703
|
+
const envModName = abi ? abi.envMod : "env";
|
|
4704
|
+
const gImportName = abi ? abi.gImport : "g";
|
|
4705
|
+
const mImportName = abi ? abi.mImport : "m";
|
|
4621
4706
|
const importPayload = [
|
|
4622
4707
|
2,
|
|
4623
4708
|
// 2 imports
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
110,
|
|
4627
|
-
118,
|
|
4628
|
-
1,
|
|
4629
|
-
103,
|
|
4709
|
+
...encodeWasmName(envModName),
|
|
4710
|
+
...encodeWasmName(gImportName),
|
|
4630
4711
|
0,
|
|
4631
4712
|
0,
|
|
4632
|
-
//
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
110,
|
|
4636
|
-
118,
|
|
4637
|
-
1,
|
|
4638
|
-
109,
|
|
4713
|
+
// g: func type 0
|
|
4714
|
+
...encodeWasmName(envModName),
|
|
4715
|
+
...encodeWasmName(mImportName),
|
|
4639
4716
|
0,
|
|
4640
4717
|
1
|
|
4641
|
-
//
|
|
4718
|
+
// m: func type 1
|
|
4642
4719
|
];
|
|
4643
4720
|
const importSection = [
|
|
4644
4721
|
2,
|
|
@@ -4652,35 +4729,21 @@ function generateWasmKdfBinary(seed) {
|
|
|
4652
4729
|
...funcPayload
|
|
4653
4730
|
];
|
|
4654
4731
|
const memSection = [5, 3, 1, 0, 1];
|
|
4655
|
-
const
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
0
|
|
4663
|
-
2,
|
|
4664
|
-
// "kdf" -> func 2
|
|
4665
|
-
7,
|
|
4666
|
-
98,
|
|
4667
|
-
117,
|
|
4668
|
-
108,
|
|
4669
|
-
107,
|
|
4670
|
-
77,
|
|
4671
|
-
105,
|
|
4672
|
-
120,
|
|
4673
|
-
0,
|
|
4674
|
-
3,
|
|
4675
|
-
// "bulkMix" -> func 3
|
|
4676
|
-
3,
|
|
4677
|
-
109,
|
|
4678
|
-
101,
|
|
4679
|
-
109,
|
|
4680
|
-
2,
|
|
4681
|
-
0
|
|
4682
|
-
// "mem" -> memory 0
|
|
4732
|
+
const exportSpecs = abi ? [
|
|
4733
|
+
[abi.kdfExport, 0, 2],
|
|
4734
|
+
[abi.bulkMixExport, 0, 3],
|
|
4735
|
+
[abi.memExport, 2, 0]
|
|
4736
|
+
] : [
|
|
4737
|
+
["kdf", 0, 2],
|
|
4738
|
+
["bulkMix", 0, 3],
|
|
4739
|
+
["mem", 2, 0]
|
|
4683
4740
|
];
|
|
4741
|
+
const exportOrder = abi ? abi.exportOrder : [0, 1, 2];
|
|
4742
|
+
const exportPayload = [3];
|
|
4743
|
+
for (const idx of exportOrder) {
|
|
4744
|
+
const [name, kind, targetIdx] = exportSpecs[idx];
|
|
4745
|
+
exportPayload.push(...encodeWasmName(name), kind, targetIdx);
|
|
4746
|
+
}
|
|
4684
4747
|
const exportSection = [
|
|
4685
4748
|
7,
|
|
4686
4749
|
...encodeUnsignedLeb128(exportPayload.length),
|
|
@@ -4778,12 +4841,13 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
4778
4841
|
const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
|
|
4779
4842
|
return {
|
|
4780
4843
|
kdfFnName: id,
|
|
4781
|
-
wasmBytes: generateWasmKdfBinary(seed),
|
|
4844
|
+
wasmBytes: generateWasmKdfBinary(seed, { polymorphicAbi: true }),
|
|
4782
4845
|
wasmVarName,
|
|
4783
4846
|
kdfParityVerified: true
|
|
4784
4847
|
};
|
|
4785
4848
|
}
|
|
4786
|
-
const
|
|
4849
|
+
const abi = deriveWasmAbiNames(seed);
|
|
4850
|
+
const wasmBytes = generateWasmKdfBinary(seed, { polymorphicAbi: true });
|
|
4787
4851
|
const byteArrayLiteral = Array.from(wasmBytes).join(",");
|
|
4788
4852
|
const { sVal, c1, c2, k0, r1, r2 } = deriveKdfParams(seed);
|
|
4789
4853
|
const { gArr, sOff, rA0, rA1, rA2, rA3, gMask, pcMask } = deriveWasmHostParams(seed);
|
|
@@ -4820,8 +4884,8 @@ function injectWasmVault(ast, seed = 2654435769) {
|
|
|
4820
4884
|
try {
|
|
4821
4885
|
var ${wasmVarName} = new Uint8Array([${byteArrayLiteral}]);
|
|
4822
4886
|
var _wm${suffix} = new WebAssembly.Module(${wasmVarName});
|
|
4823
|
-
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix}, {
|
|
4824
|
-
${kdfFnName} = _wi${suffix}.exports.
|
|
4887
|
+
var _wi${suffix} = new WebAssembly.Instance(_wm${suffix}, { ${abi.envMod}: { ${abi.gImport}: _eG, ${abi.mImport}: _eM } });
|
|
4888
|
+
${kdfFnName} = _wi${suffix}.exports[${JSON.stringify(abi.kdfExport)}];
|
|
4825
4889
|
} catch (e) {
|
|
4826
4890
|
var _kx = [${rivEncodedTargets.join(",")}];
|
|
4827
4891
|
var _k = [];
|
|
@@ -5233,16 +5297,39 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
5233
5297
|
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
5234
5298
|
const shaderPayloads = [];
|
|
5235
5299
|
const shaderTargets = [];
|
|
5236
|
-
|
|
5300
|
+
const interpolatedTemplates = [];
|
|
5301
|
+
let regExpShadowedScopes;
|
|
5302
|
+
const getRegExpShadowedScopes = () => {
|
|
5303
|
+
regExpShadowedScopes ??= collectIdentifierShadowedScopes(ast, "RegExp");
|
|
5304
|
+
return regExpShadowedScopes;
|
|
5305
|
+
};
|
|
5306
|
+
function pushSaltedTarget(rawString, node, parent, extra) {
|
|
5307
|
+
const callSiteIdx = targetsToReplace.length;
|
|
5308
|
+
const [saltLo, saltHi] = computeCallSiteSalt64(
|
|
5309
|
+
seed >>> 0,
|
|
5310
|
+
callSiteIdx >>> 0,
|
|
5311
|
+
seed >>> 0
|
|
5312
|
+
);
|
|
5313
|
+
const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
|
|
5314
|
+
targetsToReplace.push({
|
|
5315
|
+
node,
|
|
5316
|
+
parent,
|
|
5317
|
+
callSiteIdx,
|
|
5318
|
+
localSalt,
|
|
5319
|
+
rawString,
|
|
5320
|
+
...extra
|
|
5321
|
+
});
|
|
5322
|
+
}
|
|
5323
|
+
function processSaltedCandidate(val, node, parent, ancestors, onReplace) {
|
|
5237
5324
|
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5238
|
-
return;
|
|
5325
|
+
return false;
|
|
5239
5326
|
}
|
|
5240
5327
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
5241
|
-
return;
|
|
5328
|
+
return false;
|
|
5242
5329
|
}
|
|
5243
5330
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
5244
5331
|
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
5245
|
-
return;
|
|
5332
|
+
return false;
|
|
5246
5333
|
}
|
|
5247
5334
|
}
|
|
5248
5335
|
let isHotExempt = false;
|
|
@@ -5269,11 +5356,11 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
5269
5356
|
shaderToIndex.set(val, idx);
|
|
5270
5357
|
shaderPayloads.push(val);
|
|
5271
5358
|
}
|
|
5272
|
-
shaderTargets.push({ node, parent, idx });
|
|
5273
|
-
return;
|
|
5359
|
+
shaderTargets.push({ node, parent, idx, ...onReplace ? { onReplace } : {} });
|
|
5360
|
+
return true;
|
|
5274
5361
|
}
|
|
5275
5362
|
if (isHotExempt) {
|
|
5276
|
-
return;
|
|
5363
|
+
return false;
|
|
5277
5364
|
}
|
|
5278
5365
|
if (!shouldEncryptString(
|
|
5279
5366
|
val,
|
|
@@ -5282,25 +5369,33 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
5282
5369
|
activeDirectives,
|
|
5283
5370
|
customReserved
|
|
5284
5371
|
)) {
|
|
5285
|
-
return;
|
|
5372
|
+
return false;
|
|
5286
5373
|
}
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
seed >>> 0,
|
|
5290
|
-
callSiteIdx >>> 0,
|
|
5291
|
-
seed >>> 0
|
|
5292
|
-
);
|
|
5293
|
-
const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
|
|
5294
|
-
targetsToReplace.push({
|
|
5295
|
-
node,
|
|
5296
|
-
parent,
|
|
5297
|
-
callSiteIdx,
|
|
5298
|
-
localSalt,
|
|
5299
|
-
rawString: val
|
|
5300
|
-
});
|
|
5374
|
+
pushSaltedTarget(val, node, parent, onReplace ? { onReplace } : void 0);
|
|
5375
|
+
return true;
|
|
5301
5376
|
}
|
|
5302
5377
|
walk3.ancestor(ast, {
|
|
5303
5378
|
Literal(node, ancestors) {
|
|
5379
|
+
if (node.regex) {
|
|
5380
|
+
if (isEligibleSecretRegExp(
|
|
5381
|
+
node,
|
|
5382
|
+
ancestors,
|
|
5383
|
+
hotExemptNodes,
|
|
5384
|
+
exemptSubtreeRoots,
|
|
5385
|
+
getRegExpShadowedScopes
|
|
5386
|
+
)) {
|
|
5387
|
+
pushSaltedTarget(
|
|
5388
|
+
node.regex.pattern,
|
|
5389
|
+
node,
|
|
5390
|
+
ancestors[ancestors.length - 2],
|
|
5391
|
+
{
|
|
5392
|
+
replaceMode: "regexp",
|
|
5393
|
+
flags: node.regex.flags ?? ""
|
|
5394
|
+
}
|
|
5395
|
+
);
|
|
5396
|
+
}
|
|
5397
|
+
return;
|
|
5398
|
+
}
|
|
5304
5399
|
if (typeof node.value !== "string") return;
|
|
5305
5400
|
const val = node.value;
|
|
5306
5401
|
if (activeDirectives.has(val)) return;
|
|
@@ -5321,19 +5416,42 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
5321
5416
|
processSaltedCandidate(val, node, parent, ancestors);
|
|
5322
5417
|
},
|
|
5323
5418
|
TemplateLiteral(node, ancestors) {
|
|
5324
|
-
if (!node.quasis || node.quasis.length
|
|
5325
|
-
if (node.expressions && node.expressions.length !== 0) return;
|
|
5326
|
-
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
5327
|
-
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
5419
|
+
if (!Array.isArray(node.quasis) || node.quasis.length === 0) return;
|
|
5328
5420
|
const parent = ancestors[ancestors.length - 2];
|
|
5329
|
-
if (
|
|
5330
|
-
|
|
5421
|
+
if (isExemptTemplateLiteral(node, parent)) return;
|
|
5422
|
+
const exprCount = Array.isArray(node.expressions) ? node.expressions.length : 0;
|
|
5423
|
+
if (exprCount === 0) {
|
|
5424
|
+
if (node.quasis.length !== 1) return;
|
|
5425
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
5426
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
5427
|
+
processSaltedCandidate(val, node, parent, ancestors);
|
|
5331
5428
|
return;
|
|
5332
5429
|
}
|
|
5333
|
-
if (
|
|
5430
|
+
if (node.quasis.length !== exprCount + 1) return;
|
|
5431
|
+
if (node.quasis.some((q) => typeof q?.value?.cooked !== "string")) {
|
|
5334
5432
|
return;
|
|
5335
5433
|
}
|
|
5336
|
-
|
|
5434
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
5435
|
+
let queuedCount = 0;
|
|
5436
|
+
for (let qIdx = 0; qIdx < node.quasis.length; qIdx++) {
|
|
5437
|
+
const val = node.quasis[qIdx].value.cooked;
|
|
5438
|
+
if (activeDirectives.has(val)) continue;
|
|
5439
|
+
const queued = processSaltedCandidate(
|
|
5440
|
+
val,
|
|
5441
|
+
node,
|
|
5442
|
+
parent,
|
|
5443
|
+
ancestors,
|
|
5444
|
+
(exprAst) => {
|
|
5445
|
+
replacements.set(qIdx, exprAst);
|
|
5446
|
+
}
|
|
5447
|
+
);
|
|
5448
|
+
if (queued) {
|
|
5449
|
+
queuedCount++;
|
|
5450
|
+
}
|
|
5451
|
+
}
|
|
5452
|
+
if (queuedCount > 0) {
|
|
5453
|
+
interpolatedTemplates.push({ node, replacements });
|
|
5454
|
+
}
|
|
5337
5455
|
}
|
|
5338
5456
|
});
|
|
5339
5457
|
if (targetsToReplace.length === 0 && shaderTargets.length === 0) {
|
|
@@ -5414,7 +5532,17 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
5414
5532
|
],
|
|
5415
5533
|
optional: false
|
|
5416
5534
|
};
|
|
5417
|
-
|
|
5535
|
+
if (target.onReplace) {
|
|
5536
|
+
target.onReplace(callExpr);
|
|
5537
|
+
} else if (target.replaceMode === "regexp") {
|
|
5538
|
+
replaceNodeInParent(
|
|
5539
|
+
target.parent,
|
|
5540
|
+
target.node,
|
|
5541
|
+
createNewRegExpAst(callExpr, target.flags ?? "")
|
|
5542
|
+
);
|
|
5543
|
+
} else {
|
|
5544
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
5545
|
+
}
|
|
5418
5546
|
}
|
|
5419
5547
|
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
5420
5548
|
integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
@@ -5444,7 +5572,11 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
5444
5572
|
],
|
|
5445
5573
|
optional: false
|
|
5446
5574
|
};
|
|
5447
|
-
|
|
5575
|
+
if (target.onReplace) {
|
|
5576
|
+
target.onReplace(callExpr);
|
|
5577
|
+
} else {
|
|
5578
|
+
replaceNodeInParent(target.parent, target.node, callExpr);
|
|
5579
|
+
}
|
|
5448
5580
|
}
|
|
5449
5581
|
const shaderHelperStmt = createShaderVaultAst(
|
|
5450
5582
|
shaderVarName,
|
|
@@ -5460,6 +5592,7 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
5460
5592
|
integrityToken = computeFnv1aHash(JSON.stringify(shaderPayloads), seed);
|
|
5461
5593
|
}
|
|
5462
5594
|
}
|
|
5595
|
+
rebuildInterpolatedTemplates(interpolatedTemplates);
|
|
5463
5596
|
return {
|
|
5464
5597
|
encryptedStringsCount: targetsToReplace.length,
|
|
5465
5598
|
integrityToken,
|
|
@@ -5469,6 +5602,133 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
5469
5602
|
};
|
|
5470
5603
|
}
|
|
5471
5604
|
|
|
5605
|
+
// src/ast/secret-patterns.ts
|
|
5606
|
+
var PEM_HEADER_RE = /-----BEGIN\s+[A-Z0-9 ]+-----/;
|
|
5607
|
+
var PEM_REGEX_HEADER_RE = /-----BEGIN(?:\s|\\s[+*?]?)+(?:[A-Z0-9 ]|\\s[+*?]?)+-----/;
|
|
5608
|
+
var TOKEN_PREFIX_RE = /\b(?:sk_live_|sk_test_|pk_live_|ghp_|gho_|github_pat_|xox[baprs]-|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z_-]{35}|FLAG\{[^}]{4,}\}|eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,})/;
|
|
5609
|
+
var ESCAPED_FLAG_REGEX_RE = /\bFLAG\\\{[^}]{4,}\\\}/;
|
|
5610
|
+
var HEX_RE = /^[0-9a-fA-F]+$/;
|
|
5611
|
+
var BASE64_RE = /^[A-Za-z0-9+/]+=*$/;
|
|
5612
|
+
var TOKEN_CHARSET_RE = /^[A-Za-z0-9_\-+/=.~:@!#$%^&*]+$/;
|
|
5613
|
+
var PATH_LIKE_RE = /^(?:\.{1,2}\/|@[\w.-]+\/)|\.(?:[cm]?[jt]sx?|json|css|map|wasm|html?|node|svg|png|jpe?g|gif|woff2?|ttf|md|txt|ya?ml|toml|lock)$/i;
|
|
5614
|
+
var REGEX_CHAR_CLASS_RE = /\[(?:\\[\s\S]|[^\]\\])*\]/g;
|
|
5615
|
+
var REGEX_META_SPLIT_RE = /\(\?(?:<[=!]|<[^>]+>|[:=!])?|\\[\s\S]|[\s^$.*+?()[\]{}|/]+/;
|
|
5616
|
+
var COMMON_BIGRAMS = new Set(
|
|
5617
|
+
"th he in er an re on at en nd ti es or te of ed is it al ar st to nt ng se ha as ou io le ve co me de hi ri ro ic ne ea ra ce li ch ll be ma si om ur ca el ta la ns ge ec ct pe ol un il us ss ac em tr pr po fi ad lo ut id pa so mo wi no di ee ul et ai rs oo ex".split(" ")
|
|
5618
|
+
);
|
|
5619
|
+
var COMMON_BIGRAM_CHANCE = COMMON_BIGRAMS.size / 676;
|
|
5620
|
+
var NATURAL_TEXT_Z = 3.5;
|
|
5621
|
+
function isAsciiLetter(code) {
|
|
5622
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
5623
|
+
}
|
|
5624
|
+
function isBinaryOrWasmPrefix(value) {
|
|
5625
|
+
return value.startsWith("AGFzbQE") || /^data:/i.test(value);
|
|
5626
|
+
}
|
|
5627
|
+
function countBase64MarkerRatio(value) {
|
|
5628
|
+
let hits = 0;
|
|
5629
|
+
for (let i = 0; i < value.length; i++) {
|
|
5630
|
+
const code = value.charCodeAt(i);
|
|
5631
|
+
if (code >= 48 && code <= 57 || // 0-9
|
|
5632
|
+
code === 43 || // +
|
|
5633
|
+
code === 47 || // /
|
|
5634
|
+
code === 61) {
|
|
5635
|
+
hits += 1;
|
|
5636
|
+
}
|
|
5637
|
+
}
|
|
5638
|
+
return hits / value.length;
|
|
5639
|
+
}
|
|
5640
|
+
function shannonEntropy(value) {
|
|
5641
|
+
if (value.length === 0) return 0;
|
|
5642
|
+
const counts = /* @__PURE__ */ new Map();
|
|
5643
|
+
for (let i = 0; i < value.length; i++) {
|
|
5644
|
+
const code = value.charCodeAt(i);
|
|
5645
|
+
counts.set(code, (counts.get(code) ?? 0) + 1);
|
|
5646
|
+
}
|
|
5647
|
+
let h = 0;
|
|
5648
|
+
for (const count of counts.values()) {
|
|
5649
|
+
const p = count / value.length;
|
|
5650
|
+
h -= p * Math.log2(p);
|
|
5651
|
+
}
|
|
5652
|
+
return h;
|
|
5653
|
+
}
|
|
5654
|
+
function isSequentialAlphabet(value) {
|
|
5655
|
+
if (value.length < 8) return false;
|
|
5656
|
+
let ascending = 0;
|
|
5657
|
+
for (let i = 1; i < value.length; i++) {
|
|
5658
|
+
if (value.charCodeAt(i) - value.charCodeAt(i - 1) === 1) {
|
|
5659
|
+
ascending += 1;
|
|
5660
|
+
}
|
|
5661
|
+
}
|
|
5662
|
+
return ascending / (value.length - 1) >= 0.6;
|
|
5663
|
+
}
|
|
5664
|
+
function looksLikeNaturalText(value) {
|
|
5665
|
+
let pairs = 0;
|
|
5666
|
+
let hits = 0;
|
|
5667
|
+
const lower = value.toLowerCase();
|
|
5668
|
+
for (let i = 1; i < value.length; i++) {
|
|
5669
|
+
const a = value.charCodeAt(i - 1);
|
|
5670
|
+
const b = value.charCodeAt(i);
|
|
5671
|
+
if (!isAsciiLetter(a) || !isAsciiLetter(b)) continue;
|
|
5672
|
+
pairs += 1;
|
|
5673
|
+
if (a >= 97 && b <= 90) continue;
|
|
5674
|
+
if (COMMON_BIGRAMS.has(lower[i - 1] + lower[i])) {
|
|
5675
|
+
hits += 1;
|
|
5676
|
+
}
|
|
5677
|
+
}
|
|
5678
|
+
if (pairs < 4) return false;
|
|
5679
|
+
const expected = COMMON_BIGRAM_CHANCE * pairs;
|
|
5680
|
+
const deviation = Math.sqrt(
|
|
5681
|
+
pairs * COMMON_BIGRAM_CHANCE * (1 - COMMON_BIGRAM_CHANCE)
|
|
5682
|
+
);
|
|
5683
|
+
return (hits - expected) / deviation >= NATURAL_TEXT_Z;
|
|
5684
|
+
}
|
|
5685
|
+
function classifyPlaintextSecret(value) {
|
|
5686
|
+
if (typeof value !== "string" || value.length < 8) return null;
|
|
5687
|
+
if (isBinaryOrWasmPrefix(value)) return null;
|
|
5688
|
+
if (PATH_LIKE_RE.test(value)) return null;
|
|
5689
|
+
const entropy = shannonEntropy(value);
|
|
5690
|
+
if (PEM_HEADER_RE.test(value)) {
|
|
5691
|
+
return { category: "pem-header", entropy };
|
|
5692
|
+
}
|
|
5693
|
+
if (TOKEN_PREFIX_RE.test(value)) {
|
|
5694
|
+
return { category: "token-prefix", entropy };
|
|
5695
|
+
}
|
|
5696
|
+
if (isSequentialAlphabet(value)) {
|
|
5697
|
+
return null;
|
|
5698
|
+
}
|
|
5699
|
+
const isHex = value.length >= 24 && value.length % 2 === 0 && HEX_RE.test(value) && entropy >= 3.2;
|
|
5700
|
+
if (isHex) {
|
|
5701
|
+
return { category: "hex-or-base64", entropy };
|
|
5702
|
+
}
|
|
5703
|
+
const isBase64Like = value.length >= 28 && BASE64_RE.test(value) && countBase64MarkerRatio(value) >= 0.15 && !looksLikeNaturalText(value) && entropy >= 4;
|
|
5704
|
+
if (isBase64Like) {
|
|
5705
|
+
return { category: "hex-or-base64", entropy };
|
|
5706
|
+
}
|
|
5707
|
+
if (value.length >= 20 && value.length <= 512 && TOKEN_CHARSET_RE.test(value) && !looksLikeNaturalText(value) && entropy >= 4.1) {
|
|
5708
|
+
return { category: "high-entropy", entropy };
|
|
5709
|
+
}
|
|
5710
|
+
return null;
|
|
5711
|
+
}
|
|
5712
|
+
function isLikelySecretLiteral(value) {
|
|
5713
|
+
return classifyPlaintextSecret(value) !== null;
|
|
5714
|
+
}
|
|
5715
|
+
function hasRegexSecretRun(pattern) {
|
|
5716
|
+
if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 4096) {
|
|
5717
|
+
return false;
|
|
5718
|
+
}
|
|
5719
|
+
if (PEM_HEADER_RE.test(pattern) || PEM_REGEX_HEADER_RE.test(pattern) || TOKEN_PREFIX_RE.test(pattern) || ESCAPED_FLAG_REGEX_RE.test(pattern)) {
|
|
5720
|
+
return true;
|
|
5721
|
+
}
|
|
5722
|
+
const outsideClasses = pattern.replace(REGEX_CHAR_CLASS_RE, " ");
|
|
5723
|
+
const parts = outsideClasses.split(REGEX_META_SPLIT_RE);
|
|
5724
|
+
for (const part of parts) {
|
|
5725
|
+
if (part.length >= 20 && isLikelySecretLiteral(part)) {
|
|
5726
|
+
return true;
|
|
5727
|
+
}
|
|
5728
|
+
}
|
|
5729
|
+
return false;
|
|
5730
|
+
}
|
|
5731
|
+
|
|
5472
5732
|
// src/ast/string-vault.ts
|
|
5473
5733
|
var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
|
|
5474
5734
|
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
@@ -5856,6 +6116,222 @@ function findLowestCommonScope(ast, chains) {
|
|
|
5856
6116
|
}
|
|
5857
6117
|
return lca[lca.length - 1] ?? ast;
|
|
5858
6118
|
}
|
|
6119
|
+
function isExemptTemplateLiteral(node, parent) {
|
|
6120
|
+
if (!parent) return true;
|
|
6121
|
+
if (parent.type === "TaggedTemplateExpression" && parent.quasi === node) {
|
|
6122
|
+
return true;
|
|
6123
|
+
}
|
|
6124
|
+
if (parent.type === "ImportExpression" && parent.source === node) {
|
|
6125
|
+
return true;
|
|
6126
|
+
}
|
|
6127
|
+
return false;
|
|
6128
|
+
}
|
|
6129
|
+
function rebuildInterpolatedTemplates(plans) {
|
|
6130
|
+
for (const { node, replacements } of plans) {
|
|
6131
|
+
if (replacements.size === 0) continue;
|
|
6132
|
+
const origQuasis = node.quasis;
|
|
6133
|
+
const origExprs = node.expressions;
|
|
6134
|
+
const nextQuasis = [];
|
|
6135
|
+
const nextExprs = [];
|
|
6136
|
+
let pendingRaw = "";
|
|
6137
|
+
let pendingCooked = "";
|
|
6138
|
+
const flushQuasi = (tail) => {
|
|
6139
|
+
nextQuasis.push({
|
|
6140
|
+
type: "TemplateElement",
|
|
6141
|
+
value: { raw: pendingRaw, cooked: pendingCooked },
|
|
6142
|
+
tail
|
|
6143
|
+
});
|
|
6144
|
+
pendingRaw = "";
|
|
6145
|
+
pendingCooked = "";
|
|
6146
|
+
};
|
|
6147
|
+
for (let i = 0; i < origQuasis.length; i++) {
|
|
6148
|
+
const quasi = origQuasis[i];
|
|
6149
|
+
const replacement = replacements.get(i);
|
|
6150
|
+
if (replacement !== void 0) {
|
|
6151
|
+
flushQuasi(false);
|
|
6152
|
+
nextExprs.push(replacement);
|
|
6153
|
+
} else {
|
|
6154
|
+
pendingRaw += quasi.value?.raw ?? "";
|
|
6155
|
+
pendingCooked += quasi.value?.cooked ?? "";
|
|
6156
|
+
}
|
|
6157
|
+
if (i < origExprs.length) {
|
|
6158
|
+
flushQuasi(false);
|
|
6159
|
+
nextExprs.push(origExprs[i]);
|
|
6160
|
+
}
|
|
6161
|
+
}
|
|
6162
|
+
flushQuasi(true);
|
|
6163
|
+
node.quasis = nextQuasis;
|
|
6164
|
+
node.expressions = nextExprs;
|
|
6165
|
+
}
|
|
6166
|
+
}
|
|
6167
|
+
function createNewRegExpAst(sourceExpr, flags) {
|
|
6168
|
+
return {
|
|
6169
|
+
type: "NewExpression",
|
|
6170
|
+
callee: { type: "Identifier", name: "RegExp" },
|
|
6171
|
+
arguments: flags.length > 0 ? [
|
|
6172
|
+
sourceExpr,
|
|
6173
|
+
{
|
|
6174
|
+
type: "Literal",
|
|
6175
|
+
value: flags,
|
|
6176
|
+
raw: JSON.stringify(flags)
|
|
6177
|
+
}
|
|
6178
|
+
] : [sourceExpr]
|
|
6179
|
+
};
|
|
6180
|
+
}
|
|
6181
|
+
function mutateNodeToNewRegExp(node, sourceExpr, flags) {
|
|
6182
|
+
const newExpr = createNewRegExpAst(sourceExpr, flags);
|
|
6183
|
+
node.type = "NewExpression";
|
|
6184
|
+
node.callee = newExpr.callee;
|
|
6185
|
+
node.arguments = newExpr.arguments;
|
|
6186
|
+
delete node.value;
|
|
6187
|
+
delete node.raw;
|
|
6188
|
+
delete node.regex;
|
|
6189
|
+
delete node.optional;
|
|
6190
|
+
}
|
|
6191
|
+
var SCOPE_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
6192
|
+
"FunctionDeclaration",
|
|
6193
|
+
"FunctionExpression",
|
|
6194
|
+
"ArrowFunctionExpression"
|
|
6195
|
+
]);
|
|
6196
|
+
var SCOPE_LEXICAL_TYPES = /* @__PURE__ */ new Set([
|
|
6197
|
+
"Program",
|
|
6198
|
+
"FunctionDeclaration",
|
|
6199
|
+
"FunctionExpression",
|
|
6200
|
+
"ArrowFunctionExpression",
|
|
6201
|
+
"BlockStatement",
|
|
6202
|
+
"ForStatement",
|
|
6203
|
+
"ForInStatement",
|
|
6204
|
+
"ForOfStatement",
|
|
6205
|
+
"SwitchStatement",
|
|
6206
|
+
"CatchClause",
|
|
6207
|
+
"ClassDeclaration",
|
|
6208
|
+
"ClassExpression",
|
|
6209
|
+
"StaticBlock"
|
|
6210
|
+
]);
|
|
6211
|
+
function patternContainsIdentifier(pattern, targetName) {
|
|
6212
|
+
if (!pattern || typeof pattern !== "object") return false;
|
|
6213
|
+
switch (pattern.type) {
|
|
6214
|
+
case "Identifier":
|
|
6215
|
+
return pattern.name === targetName;
|
|
6216
|
+
case "AssignmentPattern":
|
|
6217
|
+
return patternContainsIdentifier(pattern.left, targetName);
|
|
6218
|
+
case "RestElement":
|
|
6219
|
+
return patternContainsIdentifier(pattern.argument, targetName);
|
|
6220
|
+
case "ArrayPattern":
|
|
6221
|
+
return (pattern.elements || []).some(
|
|
6222
|
+
(el) => patternContainsIdentifier(el, targetName)
|
|
6223
|
+
);
|
|
6224
|
+
case "ObjectPattern":
|
|
6225
|
+
return (pattern.properties || []).some(
|
|
6226
|
+
(prop) => prop?.type === "Property" ? patternContainsIdentifier(prop.value, targetName) : prop?.type === "RestElement" ? patternContainsIdentifier(prop.argument, targetName) : false
|
|
6227
|
+
);
|
|
6228
|
+
default:
|
|
6229
|
+
return false;
|
|
6230
|
+
}
|
|
6231
|
+
}
|
|
6232
|
+
function findEnclosingScope(ancestors, scopeSet, fallback) {
|
|
6233
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
6234
|
+
if (scopeSet.has(ancestors[i].type)) {
|
|
6235
|
+
return ancestors[i];
|
|
6236
|
+
}
|
|
6237
|
+
}
|
|
6238
|
+
return fallback;
|
|
6239
|
+
}
|
|
6240
|
+
function collectIdentifierShadowedScopes(ast, identName = "RegExp") {
|
|
6241
|
+
const shadowed = /* @__PURE__ */ new WeakSet();
|
|
6242
|
+
walk4.ancestor(ast, {
|
|
6243
|
+
FunctionDeclaration(node, _state, ancestors) {
|
|
6244
|
+
if (node.id?.name === identName) {
|
|
6245
|
+
shadowed.add(
|
|
6246
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
6247
|
+
);
|
|
6248
|
+
shadowed.add(node);
|
|
6249
|
+
}
|
|
6250
|
+
if (Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
6251
|
+
shadowed.add(node);
|
|
6252
|
+
}
|
|
6253
|
+
},
|
|
6254
|
+
FunctionExpression(node) {
|
|
6255
|
+
if (node.id?.name === identName || Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
6256
|
+
shadowed.add(node);
|
|
6257
|
+
}
|
|
6258
|
+
},
|
|
6259
|
+
ArrowFunctionExpression(node) {
|
|
6260
|
+
if (Array.isArray(node.params) && node.params.some((p) => patternContainsIdentifier(p, identName))) {
|
|
6261
|
+
shadowed.add(node);
|
|
6262
|
+
}
|
|
6263
|
+
},
|
|
6264
|
+
ClassDeclaration(node, _state, ancestors) {
|
|
6265
|
+
if (node.id?.name === identName) {
|
|
6266
|
+
shadowed.add(
|
|
6267
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
6268
|
+
);
|
|
6269
|
+
shadowed.add(node);
|
|
6270
|
+
}
|
|
6271
|
+
},
|
|
6272
|
+
ClassExpression(node) {
|
|
6273
|
+
if (node.id?.name === identName) {
|
|
6274
|
+
shadowed.add(node);
|
|
6275
|
+
}
|
|
6276
|
+
},
|
|
6277
|
+
CatchClause(node) {
|
|
6278
|
+
if (node.param && patternContainsIdentifier(node.param, identName)) {
|
|
6279
|
+
shadowed.add(node);
|
|
6280
|
+
}
|
|
6281
|
+
},
|
|
6282
|
+
WithStatement(node) {
|
|
6283
|
+
shadowed.add(node);
|
|
6284
|
+
},
|
|
6285
|
+
ImportDeclaration(node) {
|
|
6286
|
+
if (Array.isArray(node.specifiers) && node.specifiers.some((s) => s?.local?.name === identName)) {
|
|
6287
|
+
shadowed.add(ast);
|
|
6288
|
+
}
|
|
6289
|
+
},
|
|
6290
|
+
VariableDeclaration(node, _state, ancestors) {
|
|
6291
|
+
if (!Array.isArray(node.declarations) || !node.declarations.some(
|
|
6292
|
+
(d) => patternContainsIdentifier(d?.id, identName)
|
|
6293
|
+
)) {
|
|
6294
|
+
return;
|
|
6295
|
+
}
|
|
6296
|
+
if (node.kind === "var") {
|
|
6297
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
6298
|
+
const a = ancestors[i];
|
|
6299
|
+
if (SCOPE_FUNCTION_TYPES.has(a.type) || a.type === "StaticBlock" || a.type === "Program") {
|
|
6300
|
+
shadowed.add(a);
|
|
6301
|
+
break;
|
|
6302
|
+
}
|
|
6303
|
+
}
|
|
6304
|
+
} else {
|
|
6305
|
+
shadowed.add(
|
|
6306
|
+
findEnclosingScope(ancestors.slice(0, -1), SCOPE_LEXICAL_TYPES, ast)
|
|
6307
|
+
);
|
|
6308
|
+
}
|
|
6309
|
+
}
|
|
6310
|
+
});
|
|
6311
|
+
return shadowed;
|
|
6312
|
+
}
|
|
6313
|
+
function isEligibleSecretRegExp(node, ancestors, hotExemptNodes, exemptSubtreeRoots, getShadowedScopes) {
|
|
6314
|
+
const pattern = node?.regex?.pattern;
|
|
6315
|
+
if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > 4096) {
|
|
6316
|
+
return false;
|
|
6317
|
+
}
|
|
6318
|
+
if (!hasRegexSecretRun(pattern)) {
|
|
6319
|
+
return false;
|
|
6320
|
+
}
|
|
6321
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
6322
|
+
return false;
|
|
6323
|
+
}
|
|
6324
|
+
if (isInsideLoopOrSerialized(ancestors)) {
|
|
6325
|
+
return false;
|
|
6326
|
+
}
|
|
6327
|
+
if (isNodeInExemptSubtree(ancestors, hotExemptNodes)) {
|
|
6328
|
+
return false;
|
|
6329
|
+
}
|
|
6330
|
+
if (getShadowedScopes && isNodeInExemptSubtree(ancestors, getShadowedScopes())) {
|
|
6331
|
+
return false;
|
|
6332
|
+
}
|
|
6333
|
+
return true;
|
|
6334
|
+
}
|
|
5859
6335
|
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode, config, shieldCoupled = true, detectHeadless = false, exemptSubtreeRoots) {
|
|
5860
6336
|
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
5861
6337
|
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
@@ -5917,6 +6393,12 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5917
6393
|
const shaderPayloads = [];
|
|
5918
6394
|
const targetsToReplace = [];
|
|
5919
6395
|
const hotTargetsToReplace = [];
|
|
6396
|
+
const interpolatedTemplates = [];
|
|
6397
|
+
let regExpShadowedScopes;
|
|
6398
|
+
const getRegExpShadowedScopes = () => {
|
|
6399
|
+
regExpShadowedScopes ??= collectIdentifierShadowedScopes(ast, "RegExp");
|
|
6400
|
+
return regExpShadowedScopes;
|
|
6401
|
+
};
|
|
5920
6402
|
const customWalkBase = {
|
|
5921
6403
|
...walk4.base,
|
|
5922
6404
|
Property(node, st, c) {
|
|
@@ -5924,16 +6406,16 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5924
6406
|
if (node.value) c(node.value, st);
|
|
5925
6407
|
}
|
|
5926
6408
|
};
|
|
5927
|
-
function processVaultCandidate(val, node, parent, ancestors) {
|
|
6409
|
+
function processVaultCandidate(val, node, parent, ancestors, onReplace) {
|
|
5928
6410
|
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5929
|
-
return;
|
|
6411
|
+
return false;
|
|
5930
6412
|
}
|
|
5931
6413
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
5932
|
-
return;
|
|
6414
|
+
return false;
|
|
5933
6415
|
}
|
|
5934
6416
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
5935
6417
|
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
5936
|
-
return;
|
|
6418
|
+
return false;
|
|
5937
6419
|
}
|
|
5938
6420
|
}
|
|
5939
6421
|
let isHotExempt = false;
|
|
@@ -5965,9 +6447,10 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5965
6447
|
node,
|
|
5966
6448
|
parent,
|
|
5967
6449
|
idx: idx2,
|
|
5968
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
6450
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
6451
|
+
...onReplace ? { onReplace } : {}
|
|
5969
6452
|
});
|
|
5970
|
-
return;
|
|
6453
|
+
return true;
|
|
5971
6454
|
}
|
|
5972
6455
|
if (isHotExempt) {
|
|
5973
6456
|
if (isEligibleHotLiteral(
|
|
@@ -5986,10 +6469,12 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5986
6469
|
node,
|
|
5987
6470
|
parent,
|
|
5988
6471
|
val,
|
|
5989
|
-
idx: hotTargetsToReplace.length
|
|
6472
|
+
idx: hotTargetsToReplace.length,
|
|
6473
|
+
...onReplace ? { onReplace } : {}
|
|
5990
6474
|
});
|
|
6475
|
+
return true;
|
|
5991
6476
|
}
|
|
5992
|
-
return;
|
|
6477
|
+
return false;
|
|
5993
6478
|
}
|
|
5994
6479
|
if (!shouldEncryptString(
|
|
5995
6480
|
val,
|
|
@@ -5998,7 +6483,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
5998
6483
|
activeDirectives,
|
|
5999
6484
|
customReserved
|
|
6000
6485
|
)) {
|
|
6001
|
-
return;
|
|
6486
|
+
return false;
|
|
6002
6487
|
}
|
|
6003
6488
|
let idx = stringToIndex.get(val);
|
|
6004
6489
|
if (idx === void 0) {
|
|
@@ -6011,13 +6496,44 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
6011
6496
|
node,
|
|
6012
6497
|
parent,
|
|
6013
6498
|
idx,
|
|
6014
|
-
scopeChain: extractScopeChain(ast, ancestors)
|
|
6499
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
6500
|
+
...onReplace ? { onReplace } : {}
|
|
6015
6501
|
});
|
|
6502
|
+
return true;
|
|
6016
6503
|
}
|
|
6017
6504
|
walk4.ancestor(
|
|
6018
6505
|
ast,
|
|
6019
6506
|
{
|
|
6020
6507
|
Literal(node, _state, ancestors) {
|
|
6508
|
+
if (node.regex) {
|
|
6509
|
+
if (isEligibleSecretRegExp(
|
|
6510
|
+
node,
|
|
6511
|
+
ancestors,
|
|
6512
|
+
hotExemptNodes,
|
|
6513
|
+
exemptSubtreeRoots,
|
|
6514
|
+
getRegExpShadowedScopes
|
|
6515
|
+
)) {
|
|
6516
|
+
const pattern = node.regex.pattern;
|
|
6517
|
+
const flags = node.regex.flags ?? "";
|
|
6518
|
+
const parent2 = ancestors[ancestors.length - 2];
|
|
6519
|
+
let idx = stringToIndex.get(pattern);
|
|
6520
|
+
if (idx === void 0) {
|
|
6521
|
+
idx = uniqueStrings.length;
|
|
6522
|
+
stringToIndex.set(pattern, idx);
|
|
6523
|
+
uniqueStrings.push(pattern);
|
|
6524
|
+
}
|
|
6525
|
+
targetsToReplace.push({
|
|
6526
|
+
type: "string",
|
|
6527
|
+
node,
|
|
6528
|
+
parent: parent2,
|
|
6529
|
+
idx,
|
|
6530
|
+
scopeChain: extractScopeChain(ast, ancestors),
|
|
6531
|
+
replaceMode: "regexp",
|
|
6532
|
+
flags
|
|
6533
|
+
});
|
|
6534
|
+
}
|
|
6535
|
+
return;
|
|
6536
|
+
}
|
|
6021
6537
|
if (typeof node.value !== "string") return;
|
|
6022
6538
|
const val = node.value;
|
|
6023
6539
|
if (activeDirectives.has(val)) return;
|
|
@@ -6035,19 +6551,42 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
6035
6551
|
processVaultCandidate(val, node, parent, ancestors);
|
|
6036
6552
|
},
|
|
6037
6553
|
TemplateLiteral(node, _state, ancestors) {
|
|
6038
|
-
if (!node.quasis || node.quasis.length
|
|
6039
|
-
if (node.expressions && node.expressions.length !== 0) return;
|
|
6040
|
-
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
6041
|
-
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
6554
|
+
if (!Array.isArray(node.quasis) || node.quasis.length === 0) return;
|
|
6042
6555
|
const parent = ancestors[ancestors.length - 2];
|
|
6043
|
-
if (
|
|
6044
|
-
|
|
6556
|
+
if (isExemptTemplateLiteral(node, parent)) return;
|
|
6557
|
+
const exprCount = Array.isArray(node.expressions) ? node.expressions.length : 0;
|
|
6558
|
+
if (exprCount === 0) {
|
|
6559
|
+
if (node.quasis.length !== 1) return;
|
|
6560
|
+
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
6561
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
6562
|
+
processVaultCandidate(val, node, parent, ancestors);
|
|
6045
6563
|
return;
|
|
6046
6564
|
}
|
|
6047
|
-
if (
|
|
6565
|
+
if (node.quasis.length !== exprCount + 1) return;
|
|
6566
|
+
if (node.quasis.some((q) => typeof q?.value?.cooked !== "string")) {
|
|
6048
6567
|
return;
|
|
6049
6568
|
}
|
|
6050
|
-
|
|
6569
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
6570
|
+
let queuedCount = 0;
|
|
6571
|
+
for (let qIdx = 0; qIdx < node.quasis.length; qIdx++) {
|
|
6572
|
+
const val = node.quasis[qIdx].value.cooked;
|
|
6573
|
+
if (activeDirectives.has(val)) continue;
|
|
6574
|
+
const queued = processVaultCandidate(
|
|
6575
|
+
val,
|
|
6576
|
+
node,
|
|
6577
|
+
parent,
|
|
6578
|
+
ancestors,
|
|
6579
|
+
(exprAst) => {
|
|
6580
|
+
replacements.set(qIdx, exprAst);
|
|
6581
|
+
}
|
|
6582
|
+
);
|
|
6583
|
+
if (queued) {
|
|
6584
|
+
queuedCount++;
|
|
6585
|
+
}
|
|
6586
|
+
}
|
|
6587
|
+
if (queuedCount > 0) {
|
|
6588
|
+
interpolatedTemplates.push({ node, replacements });
|
|
6589
|
+
}
|
|
6051
6590
|
}
|
|
6052
6591
|
},
|
|
6053
6592
|
customWalkBase
|
|
@@ -6059,38 +6598,69 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
6059
6598
|
shaderBuffersCount: 0
|
|
6060
6599
|
};
|
|
6061
6600
|
}
|
|
6062
|
-
for (const { node, parent, val, idx } of hotTargetsToReplace) {
|
|
6601
|
+
for (const { node, parent, val, idx, onReplace } of hotTargetsToReplace) {
|
|
6063
6602
|
const key = idx % 3 + 1;
|
|
6064
6603
|
let encodedStr = "";
|
|
6065
6604
|
for (let i = 0; i < val.length; i++) {
|
|
6066
6605
|
encodedStr += String.fromCharCode(val.charCodeAt(i) ^ key);
|
|
6067
6606
|
}
|
|
6607
|
+
const callExpr = {
|
|
6608
|
+
type: "CallExpression",
|
|
6609
|
+
callee: {
|
|
6610
|
+
type: "Identifier",
|
|
6611
|
+
name: "_hX"
|
|
6612
|
+
},
|
|
6613
|
+
arguments: [
|
|
6614
|
+
{
|
|
6615
|
+
type: "Literal",
|
|
6616
|
+
value: encodedStr,
|
|
6617
|
+
raw: JSON.stringify(encodedStr)
|
|
6618
|
+
},
|
|
6619
|
+
{
|
|
6620
|
+
type: "Literal",
|
|
6621
|
+
value: key,
|
|
6622
|
+
raw: String(key)
|
|
6623
|
+
}
|
|
6624
|
+
],
|
|
6625
|
+
optional: false
|
|
6626
|
+
};
|
|
6627
|
+
if (onReplace) {
|
|
6628
|
+
onReplace(callExpr);
|
|
6629
|
+
continue;
|
|
6630
|
+
}
|
|
6068
6631
|
if (parent?.type === "Property" && parent.key === node) {
|
|
6069
6632
|
parent.computed = true;
|
|
6070
6633
|
}
|
|
6071
6634
|
node.type = "CallExpression";
|
|
6072
|
-
node.callee =
|
|
6073
|
-
|
|
6074
|
-
name: "_hX"
|
|
6075
|
-
};
|
|
6076
|
-
node.arguments = [
|
|
6077
|
-
{
|
|
6078
|
-
type: "Literal",
|
|
6079
|
-
value: encodedStr,
|
|
6080
|
-
raw: JSON.stringify(encodedStr)
|
|
6081
|
-
},
|
|
6082
|
-
{
|
|
6083
|
-
type: "Literal",
|
|
6084
|
-
value: key,
|
|
6085
|
-
raw: String(key)
|
|
6086
|
-
}
|
|
6087
|
-
];
|
|
6635
|
+
node.callee = callExpr.callee;
|
|
6636
|
+
node.arguments = callExpr.arguments;
|
|
6088
6637
|
node.optional = false;
|
|
6089
6638
|
delete node.value;
|
|
6090
6639
|
delete node.raw;
|
|
6091
6640
|
delete node.quasis;
|
|
6092
6641
|
delete node.expressions;
|
|
6093
6642
|
}
|
|
6643
|
+
function applyVaultTargetReplacement(target, callExpr) {
|
|
6644
|
+
if (target.onReplace) {
|
|
6645
|
+
target.onReplace(callExpr);
|
|
6646
|
+
return;
|
|
6647
|
+
}
|
|
6648
|
+
if (target.replaceMode === "regexp") {
|
|
6649
|
+
mutateNodeToNewRegExp(target.node, callExpr, target.flags ?? "");
|
|
6650
|
+
return;
|
|
6651
|
+
}
|
|
6652
|
+
if (target.parent?.type === "Property" && target.parent.key === target.node) {
|
|
6653
|
+
target.parent.computed = true;
|
|
6654
|
+
}
|
|
6655
|
+
target.node.type = "CallExpression";
|
|
6656
|
+
target.node.callee = callExpr.callee;
|
|
6657
|
+
target.node.arguments = callExpr.arguments;
|
|
6658
|
+
target.node.optional = false;
|
|
6659
|
+
delete target.node.value;
|
|
6660
|
+
delete target.node.raw;
|
|
6661
|
+
delete target.node.quasis;
|
|
6662
|
+
delete target.node.expressions;
|
|
6663
|
+
}
|
|
6094
6664
|
let insertIdx = findVaultInsertIndex(ast, activeDirectives);
|
|
6095
6665
|
const wantFragmented = Boolean(config?.vault?.fragmented);
|
|
6096
6666
|
let fragCount = Math.max(2, Math.min(8, Math.floor(config?.vault?.fragmentCount ?? 3)));
|
|
@@ -6107,28 +6677,28 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
6107
6677
|
);
|
|
6108
6678
|
}
|
|
6109
6679
|
integrityToken = computeFnv1aHash(JSON.stringify(encryptedPayloads), seed);
|
|
6110
|
-
for (const
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6680
|
+
for (const target of targetsToReplace) {
|
|
6681
|
+
let callExpr;
|
|
6682
|
+
if (target.type === "shader") {
|
|
6683
|
+
callExpr = {
|
|
6684
|
+
type: "CallExpression",
|
|
6685
|
+
callee: { type: "Identifier", name: shaderVarName },
|
|
6686
|
+
arguments: [{ type: "Literal", value: target.idx, raw: String(target.idx) }],
|
|
6687
|
+
optional: false
|
|
6688
|
+
};
|
|
6118
6689
|
} else {
|
|
6119
|
-
const salt = computeCallSiteSalt(seed, idx);
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
delete node.expressions;
|
|
6690
|
+
const salt = computeCallSiteSalt(seed, target.idx);
|
|
6691
|
+
callExpr = {
|
|
6692
|
+
type: "CallExpression",
|
|
6693
|
+
callee: { type: "Identifier", name: decryptFnName },
|
|
6694
|
+
arguments: [
|
|
6695
|
+
{ type: "Literal", value: target.idx, raw: String(target.idx) },
|
|
6696
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
6697
|
+
],
|
|
6698
|
+
optional: false
|
|
6699
|
+
};
|
|
6700
|
+
}
|
|
6701
|
+
applyVaultTargetReplacement(target, callExpr);
|
|
6132
6702
|
}
|
|
6133
6703
|
} else {
|
|
6134
6704
|
const perm = [];
|
|
@@ -6196,31 +6766,31 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
6196
6766
|
chains: []
|
|
6197
6767
|
});
|
|
6198
6768
|
}
|
|
6199
|
-
for (const
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6769
|
+
for (const target of targetsToReplace) {
|
|
6770
|
+
let callExpr;
|
|
6771
|
+
if (target.type === "shader") {
|
|
6772
|
+
callExpr = {
|
|
6773
|
+
type: "CallExpression",
|
|
6774
|
+
callee: { type: "Identifier", name: shaderVarName },
|
|
6775
|
+
arguments: [{ type: "Literal", value: target.idx, raw: String(target.idx) }],
|
|
6776
|
+
optional: false
|
|
6777
|
+
};
|
|
6207
6778
|
} else {
|
|
6208
|
-
const { fragId, localIdx } = stringFragAssign[idx];
|
|
6779
|
+
const { fragId, localIdx } = stringFragAssign[target.idx];
|
|
6209
6780
|
const meta = fragMeta[fragId];
|
|
6210
|
-
meta.chains.push(scopeChain);
|
|
6781
|
+
meta.chains.push(target.scopeChain);
|
|
6211
6782
|
const salt = computeCallSiteSalt(meta.fragSeed, localIdx);
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
delete node.expressions;
|
|
6783
|
+
callExpr = {
|
|
6784
|
+
type: "CallExpression",
|
|
6785
|
+
callee: { type: "Identifier", name: meta.fnName },
|
|
6786
|
+
arguments: [
|
|
6787
|
+
{ type: "Literal", value: localIdx, raw: String(localIdx) },
|
|
6788
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
6789
|
+
],
|
|
6790
|
+
optional: false
|
|
6791
|
+
};
|
|
6792
|
+
}
|
|
6793
|
+
applyVaultTargetReplacement(target, callExpr);
|
|
6224
6794
|
}
|
|
6225
6795
|
const allPayloads = [];
|
|
6226
6796
|
for (const meta of fragMeta) {
|
|
@@ -6243,6 +6813,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
6243
6813
|
}
|
|
6244
6814
|
integrityToken = computeFnv1aHash(JSON.stringify(allPayloads), seed);
|
|
6245
6815
|
}
|
|
6816
|
+
rebuildInterpolatedTemplates(interpolatedTemplates);
|
|
6246
6817
|
if (hotTargetsToReplace.length > 0) {
|
|
6247
6818
|
const alreadyHasHx = ast.body.some(
|
|
6248
6819
|
(stmt) => stmt.type === "FunctionDeclaration" && stmt.id?.name === "_hX"
|
|
@@ -6869,6 +7440,26 @@ function mixSeed32(seed, salt) {
|
|
|
6869
7440
|
h ^= h >>> 16;
|
|
6870
7441
|
return h | 0;
|
|
6871
7442
|
}
|
|
7443
|
+
function modInverseUint32(oddValue) {
|
|
7444
|
+
const m = (oddValue | 1) >>> 0;
|
|
7445
|
+
let inv = 1;
|
|
7446
|
+
for (let i = 0; i < 5; i++) {
|
|
7447
|
+
inv = Math.imul(inv, 2 - Math.imul(m, inv) | 0) >>> 0;
|
|
7448
|
+
}
|
|
7449
|
+
return inv >>> 0;
|
|
7450
|
+
}
|
|
7451
|
+
function deriveAffineMbaParams(seed, salt) {
|
|
7452
|
+
let m = (mixSeed32(seed, salt) | 1) >>> 0;
|
|
7453
|
+
if (m === 1 || m === 4294967295 || m === 2654435769) {
|
|
7454
|
+
m = (m ^ 1540483477 | 1) >>> 0;
|
|
7455
|
+
}
|
|
7456
|
+
const m2 = Math.imul(m, 2) >>> 0;
|
|
7457
|
+
const mInv = modInverseUint32(m);
|
|
7458
|
+
let c = mixSeed32(seed, salt + 40503) >>> 0;
|
|
7459
|
+
if (c === 0) c = 668265263;
|
|
7460
|
+
const d = -Math.imul(mInv, c) >>> 0;
|
|
7461
|
+
return { m, m2, mInv, c, d };
|
|
7462
|
+
}
|
|
6872
7463
|
function cloneNode(node) {
|
|
6873
7464
|
return JSON.parse(JSON.stringify(node));
|
|
6874
7465
|
}
|
|
@@ -7617,7 +8208,8 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
7617
8208
|
zRefForDecoy
|
|
7618
8209
|
);
|
|
7619
8210
|
const hasShieldCoupling = Boolean(ctxOpts?.shieldCoupled && ctxOpts?.windowKeySymbol);
|
|
7620
|
-
const
|
|
8211
|
+
const predOffset = hasShieldCoupling ? 1 : (seed >>> 2) % 6;
|
|
8212
|
+
const predForm = ((fnIndex + predOffset) % 6 + 6) % 6;
|
|
7621
8213
|
let testExpr;
|
|
7622
8214
|
if (predForm === 0) {
|
|
7623
8215
|
let pathACore = qnrValForForm0;
|
|
@@ -7693,13 +8285,84 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
7693
8285
|
}
|
|
7694
8286
|
const rhsExpr = makeBinary("+", makeLiteral(qnrFamily.outBoundVal), slotWriteB);
|
|
7695
8287
|
testExpr = makeBinary(qnrFamily.outBoundOp, lhsExpr, rhsExpr);
|
|
7696
|
-
} else {
|
|
8288
|
+
} else if (predForm === 3) {
|
|
7697
8289
|
const tagLhs = hasAlias ? makeBinary("&", makeMemberIndex(ctxOpts.aliasIdentA, makeLiteral(slotB)), makeLiteral(240)) : makeBinary("&", makeBinary("<<", makeTypeofGlobalLen(), makeLiteral(4)), makeLiteral(240));
|
|
7698
8290
|
const tagRhsBase = hasAlias ? makeBinary("&", makeMemberIndex(aliasReadIdent, makeLiteral(slotB)), makeLiteral(240)) : makeBinary("&", makeBinary("<<", makeTypeofGlobalLen(), makeLiteral(4)), makeLiteral(240));
|
|
7699
8291
|
const tagRhs = aliasInvZero ? makeBinary("^", tagRhsBase, makeBinary("&", aliasInvZero, makeLiteral(15))) : tagRhsBase;
|
|
7700
8292
|
const lhsExpr = makeBinary("|", makeBinary("^", qnrLeft, tagLhs), makeLiteral(0));
|
|
7701
8293
|
const rhsExpr = makeBinary("|", makeBinary("^", makeLiteral(qnrFamily.target), tagRhs), makeLiteral(0));
|
|
7702
8294
|
testExpr = makeBinary("===", lhsExpr, rhsExpr);
|
|
8295
|
+
} else if (predForm === 4) {
|
|
8296
|
+
const k4 = mixSeed32(seed, fnIndex * 29 + 13) >>> 0 || 1;
|
|
8297
|
+
if (ctxOpts?.scratchVarIdent) {
|
|
8298
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
8299
|
+
const preU = aliasInvZero ? makeBinary("^", cloneNode(scratchId), aliasInvZero) : cloneNode(scratchId);
|
|
8300
|
+
const uAssign = {
|
|
8301
|
+
type: "AssignmentExpression",
|
|
8302
|
+
operator: "=",
|
|
8303
|
+
left: cloneNode(scratchId),
|
|
8304
|
+
right: makeBinary(">>>", makeBinary("^", preU, makeLiteral(k4)), makeLiteral(0))
|
|
8305
|
+
};
|
|
8306
|
+
const uMinus1Lhs = makeBinary(">>>", makeBinary("-", cloneNode(scratchId), makeLiteral(1)), makeLiteral(0));
|
|
8307
|
+
const uMinus1Rhs = makeBinary(">>>", makeBinary("-", cloneNode(scratchId), makeLiteral(1)), makeLiteral(0));
|
|
8308
|
+
const orU = makeBinary(">>>", makeBinary("|", cloneNode(scratchId), uMinus1Lhs), makeLiteral(0));
|
|
8309
|
+
const xorU = makeBinary(">>>", makeBinary("^", cloneNode(scratchId), uMinus1Rhs), makeLiteral(0));
|
|
8310
|
+
const lhsSeq = {
|
|
8311
|
+
type: "SequenceExpression",
|
|
8312
|
+
expressions: [...qnrLeft.expressions.slice(0, -1), uAssign, orU]
|
|
8313
|
+
};
|
|
8314
|
+
testExpr = makeBinary("<", lhsSeq, xorU);
|
|
8315
|
+
} else {
|
|
8316
|
+
const uExpr = makeBinary(">>>", makeBinary("^", cloneNode(zRefForDecoy), makeLiteral(k4)), makeLiteral(0));
|
|
8317
|
+
const uMinus1Lhs = makeBinary(">>>", makeBinary("-", cloneNode(uExpr), makeLiteral(1)), makeLiteral(0));
|
|
8318
|
+
const uMinus1Rhs = makeBinary(">>>", makeBinary("-", cloneNode(uExpr), makeLiteral(1)), makeLiteral(0));
|
|
8319
|
+
const orU = makeBinary(">>>", makeBinary("|", cloneNode(uExpr), uMinus1Lhs), makeLiteral(0));
|
|
8320
|
+
const xorU = makeBinary(">>>", makeBinary("^", cloneNode(uExpr), uMinus1Rhs), makeLiteral(0));
|
|
8321
|
+
testExpr = makeBinary("<", orU, xorU);
|
|
8322
|
+
}
|
|
8323
|
+
} else {
|
|
8324
|
+
const k5 = mixSeed32(seed, fnIndex * 31 + 17) >>> 0 || 3;
|
|
8325
|
+
const { m, m2, mInv, c, d } = deriveAffineMbaParams(seed, fnIndex * 37 + 23);
|
|
8326
|
+
const buildAffineLhs = (valNode) => {
|
|
8327
|
+
const inner = makeBinary(
|
|
8328
|
+
"|",
|
|
8329
|
+
makeBinary(
|
|
8330
|
+
"+",
|
|
8331
|
+
makeBinary(
|
|
8332
|
+
"+",
|
|
8333
|
+
makeImul(makeLiteral(m), makeBinary("^", cloneNode(valNode), makeLiteral(k5))),
|
|
8334
|
+
makeImul(makeLiteral(m2), makeBinary("&", cloneNode(valNode), makeLiteral(k5)))
|
|
8335
|
+
),
|
|
8336
|
+
makeLiteral(c)
|
|
8337
|
+
),
|
|
8338
|
+
makeLiteral(0)
|
|
8339
|
+
);
|
|
8340
|
+
return makeBinary(
|
|
8341
|
+
"|",
|
|
8342
|
+
makeBinary("+", makeImul(makeLiteral(mInv), inner), makeLiteral(d)),
|
|
8343
|
+
makeLiteral(0)
|
|
8344
|
+
);
|
|
8345
|
+
};
|
|
8346
|
+
const buildAffineRhs = (valNode) => makeBinary("|", makeBinary("+", cloneNode(valNode), makeLiteral(k5)), makeLiteral(0));
|
|
8347
|
+
if (ctxOpts?.scratchVarIdent) {
|
|
8348
|
+
const scratchId = { type: "Identifier", name: ctxOpts.scratchVarIdent };
|
|
8349
|
+
const preSeqs = [...qnrLeft.expressions.slice(0, -1)];
|
|
8350
|
+
if (aliasInvZero) {
|
|
8351
|
+
preSeqs.push({
|
|
8352
|
+
type: "AssignmentExpression",
|
|
8353
|
+
operator: "=",
|
|
8354
|
+
left: cloneNode(scratchId),
|
|
8355
|
+
right: makeBinary("|", makeBinary("^", cloneNode(scratchId), aliasInvZero), makeLiteral(0))
|
|
8356
|
+
});
|
|
8357
|
+
}
|
|
8358
|
+
const lhsSeq = {
|
|
8359
|
+
type: "SequenceExpression",
|
|
8360
|
+
expressions: [...preSeqs, buildAffineLhs(scratchId)]
|
|
8361
|
+
};
|
|
8362
|
+
testExpr = makeBinary("!==", lhsSeq, buildAffineRhs(scratchId));
|
|
8363
|
+
} else {
|
|
8364
|
+
testExpr = makeBinary("!==", buildAffineLhs(zRefForDecoy), buildAffineRhs(zRefForDecoy));
|
|
8365
|
+
}
|
|
7703
8366
|
}
|
|
7704
8367
|
return {
|
|
7705
8368
|
type: "IfStatement",
|
|
@@ -7944,7 +8607,362 @@ function createSboxAndAliasDeclarations(sboxIdent, aliasIdentA, aliasIdentB, scr
|
|
|
7944
8607
|
};
|
|
7945
8608
|
}
|
|
7946
8609
|
var MAX_COLD_GUARDS_PER_CHUNK = 12;
|
|
7947
|
-
|
|
8610
|
+
var MAX_COLD_BITWISE_MBA_PER_CHUNK = 8;
|
|
8611
|
+
var BITWISE_MBA_OPS = /* @__PURE__ */ new Set(["^", "|", "&"]);
|
|
8612
|
+
var BITWISE_LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
8613
|
+
"ForStatement",
|
|
8614
|
+
"WhileStatement",
|
|
8615
|
+
"DoWhileStatement",
|
|
8616
|
+
"ForInStatement",
|
|
8617
|
+
"ForOfStatement"
|
|
8618
|
+
]);
|
|
8619
|
+
var BITWISE_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
8620
|
+
"FunctionDeclaration",
|
|
8621
|
+
"FunctionExpression",
|
|
8622
|
+
"ArrowFunctionExpression"
|
|
8623
|
+
]);
|
|
8624
|
+
var BITWISE_LEXICAL_SCOPE_TYPES = /* @__PURE__ */ new Set([
|
|
8625
|
+
"Program",
|
|
8626
|
+
"FunctionDeclaration",
|
|
8627
|
+
"FunctionExpression",
|
|
8628
|
+
"ArrowFunctionExpression",
|
|
8629
|
+
"BlockStatement",
|
|
8630
|
+
"ForStatement",
|
|
8631
|
+
"ForInStatement",
|
|
8632
|
+
"ForOfStatement",
|
|
8633
|
+
"SwitchStatement",
|
|
8634
|
+
"CatchClause",
|
|
8635
|
+
"StaticBlock"
|
|
8636
|
+
]);
|
|
8637
|
+
var FORBIDDEN_BITWISE_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
8638
|
+
"arguments",
|
|
8639
|
+
"eval",
|
|
8640
|
+
"undefined",
|
|
8641
|
+
"NaN",
|
|
8642
|
+
"Infinity",
|
|
8643
|
+
"globalThis",
|
|
8644
|
+
"window",
|
|
8645
|
+
"self",
|
|
8646
|
+
"Math",
|
|
8647
|
+
"BigInt"
|
|
8648
|
+
]);
|
|
8649
|
+
function collectBoundPatternNames(pattern, out) {
|
|
8650
|
+
if (!pattern || typeof pattern !== "object") return;
|
|
8651
|
+
switch (pattern.type) {
|
|
8652
|
+
case "Identifier":
|
|
8653
|
+
out.push(pattern.name);
|
|
8654
|
+
break;
|
|
8655
|
+
case "AssignmentPattern":
|
|
8656
|
+
collectBoundPatternNames(pattern.left, out);
|
|
8657
|
+
break;
|
|
8658
|
+
case "RestElement":
|
|
8659
|
+
collectBoundPatternNames(pattern.argument, out);
|
|
8660
|
+
break;
|
|
8661
|
+
case "ArrayPattern":
|
|
8662
|
+
for (const el of pattern.elements || []) {
|
|
8663
|
+
if (el) collectBoundPatternNames(el, out);
|
|
8664
|
+
}
|
|
8665
|
+
break;
|
|
8666
|
+
case "ObjectPattern":
|
|
8667
|
+
for (const prop of pattern.properties || []) {
|
|
8668
|
+
if (prop.type === "Property") {
|
|
8669
|
+
collectBoundPatternNames(prop.value, out);
|
|
8670
|
+
} else if (prop.type === "RestElement") {
|
|
8671
|
+
collectBoundPatternNames(prop.argument, out);
|
|
8672
|
+
}
|
|
8673
|
+
}
|
|
8674
|
+
break;
|
|
8675
|
+
}
|
|
8676
|
+
}
|
|
8677
|
+
function analyzeBitwiseMbaScopes(ast) {
|
|
8678
|
+
const scopeBindings = /* @__PURE__ */ new Map();
|
|
8679
|
+
let unsafe = false;
|
|
8680
|
+
const addBinding = (scopeNode, name) => {
|
|
8681
|
+
if (name === "Math") {
|
|
8682
|
+
unsafe = true;
|
|
8683
|
+
return;
|
|
8684
|
+
}
|
|
8685
|
+
let set = scopeBindings.get(scopeNode);
|
|
8686
|
+
if (!set) {
|
|
8687
|
+
set = /* @__PURE__ */ new Set();
|
|
8688
|
+
scopeBindings.set(scopeNode, set);
|
|
8689
|
+
}
|
|
8690
|
+
set.add(name);
|
|
8691
|
+
};
|
|
8692
|
+
const scopeStack = [];
|
|
8693
|
+
const varTargetStack = [];
|
|
8694
|
+
const getNearestLexicalScope = () => scopeStack[scopeStack.length - 1] ?? ast;
|
|
8695
|
+
const getNearestVarScope = () => varTargetStack[varTargetStack.length - 1] ?? ast;
|
|
8696
|
+
function scan(node) {
|
|
8697
|
+
if (unsafe || !node || typeof node !== "object" || typeof node.type !== "string") {
|
|
8698
|
+
return;
|
|
8699
|
+
}
|
|
8700
|
+
if (node.type === "WithStatement") {
|
|
8701
|
+
unsafe = true;
|
|
8702
|
+
return;
|
|
8703
|
+
}
|
|
8704
|
+
if (node.type === "Literal" && (typeof node.value === "bigint" || typeof node.bigint === "string") || node.type === "BigIntLiteral") {
|
|
8705
|
+
unsafe = true;
|
|
8706
|
+
return;
|
|
8707
|
+
}
|
|
8708
|
+
if (node.type === "Identifier" && node.name === "BigInt") {
|
|
8709
|
+
unsafe = true;
|
|
8710
|
+
return;
|
|
8711
|
+
}
|
|
8712
|
+
if (node.type === "ImportSpecifier" || node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier") {
|
|
8713
|
+
if (node.local?.type === "Identifier") {
|
|
8714
|
+
addBinding(ast, node.local.name);
|
|
8715
|
+
}
|
|
8716
|
+
} else if (node.type === "FunctionDeclaration") {
|
|
8717
|
+
if (node.id?.type === "Identifier") {
|
|
8718
|
+
addBinding(getNearestLexicalScope(), node.id.name);
|
|
8719
|
+
addBinding(getNearestVarScope(), node.id.name);
|
|
8720
|
+
}
|
|
8721
|
+
} else if (node.type === "ClassDeclaration") {
|
|
8722
|
+
if (node.id?.type === "Identifier") {
|
|
8723
|
+
addBinding(getNearestLexicalScope(), node.id.name);
|
|
8724
|
+
}
|
|
8725
|
+
} else if (node.type === "VariableDeclaration") {
|
|
8726
|
+
const targetScope = node.kind === "var" ? getNearestVarScope() : getNearestLexicalScope();
|
|
8727
|
+
for (const decl of node.declarations || []) {
|
|
8728
|
+
const names = [];
|
|
8729
|
+
collectBoundPatternNames(decl.id, names);
|
|
8730
|
+
for (const name of names) {
|
|
8731
|
+
addBinding(targetScope, name);
|
|
8732
|
+
}
|
|
8733
|
+
}
|
|
8734
|
+
}
|
|
8735
|
+
if (unsafe) return;
|
|
8736
|
+
const pushesLexical = BITWISE_LEXICAL_SCOPE_TYPES.has(node.type);
|
|
8737
|
+
const isFn = BITWISE_FUNCTION_TYPES.has(node.type);
|
|
8738
|
+
const isStaticBlock = node.type === "StaticBlock";
|
|
8739
|
+
if (pushesLexical) {
|
|
8740
|
+
scopeStack.push(node);
|
|
8741
|
+
if (!scopeBindings.has(node)) {
|
|
8742
|
+
scopeBindings.set(node, /* @__PURE__ */ new Set());
|
|
8743
|
+
}
|
|
8744
|
+
}
|
|
8745
|
+
if (isFn) {
|
|
8746
|
+
if (node.id?.type === "Identifier") {
|
|
8747
|
+
addBinding(node, node.id.name);
|
|
8748
|
+
}
|
|
8749
|
+
for (const param of node.params || []) {
|
|
8750
|
+
const names = [];
|
|
8751
|
+
collectBoundPatternNames(param, names);
|
|
8752
|
+
for (const name of names) {
|
|
8753
|
+
addBinding(node, name);
|
|
8754
|
+
}
|
|
8755
|
+
}
|
|
8756
|
+
const bodyScope = node.body?.type === "BlockStatement" ? node.body : node;
|
|
8757
|
+
varTargetStack.push(bodyScope);
|
|
8758
|
+
} else if (node.type === "Program" || isStaticBlock) {
|
|
8759
|
+
varTargetStack.push(node);
|
|
8760
|
+
} else if (node.type === "CatchClause" && node.param) {
|
|
8761
|
+
const names = [];
|
|
8762
|
+
collectBoundPatternNames(node.param, names);
|
|
8763
|
+
for (const name of names) {
|
|
8764
|
+
addBinding(node, name);
|
|
8765
|
+
}
|
|
8766
|
+
} else if (node.type === "ClassExpression" && node.id?.type === "Identifier") {
|
|
8767
|
+
addBinding(node, node.id.name);
|
|
8768
|
+
}
|
|
8769
|
+
try {
|
|
8770
|
+
for (const key of Object.keys(node)) {
|
|
8771
|
+
if (key === "loc" || key === "range" || key === "start" || key === "end" || key === "comments" || key === "tokens") {
|
|
8772
|
+
continue;
|
|
8773
|
+
}
|
|
8774
|
+
const child = node[key];
|
|
8775
|
+
if (Array.isArray(child)) {
|
|
8776
|
+
for (const item of child) {
|
|
8777
|
+
scan(item);
|
|
8778
|
+
if (unsafe) return;
|
|
8779
|
+
}
|
|
8780
|
+
} else if (child && typeof child === "object") {
|
|
8781
|
+
scan(child);
|
|
8782
|
+
if (unsafe) return;
|
|
8783
|
+
}
|
|
8784
|
+
}
|
|
8785
|
+
} finally {
|
|
8786
|
+
if (isFn || node.type === "Program" || isStaticBlock) {
|
|
8787
|
+
varTargetStack.pop();
|
|
8788
|
+
}
|
|
8789
|
+
if (pushesLexical) {
|
|
8790
|
+
scopeStack.pop();
|
|
8791
|
+
}
|
|
8792
|
+
}
|
|
8793
|
+
}
|
|
8794
|
+
scan(ast);
|
|
8795
|
+
return { unsafe, scopeBindings };
|
|
8796
|
+
}
|
|
8797
|
+
function isSafeAtomicIntegerLiteral(node) {
|
|
8798
|
+
return Boolean(
|
|
8799
|
+
node && node.type === "Literal" && typeof node.value === "number" && Number.isInteger(node.value) && node.value >= 0 && node.value <= 4294967295
|
|
8800
|
+
);
|
|
8801
|
+
}
|
|
8802
|
+
function isZeroNumericLiteral(node) {
|
|
8803
|
+
return Boolean(node && node.type === "Literal" && typeof node.value === "number" && node.value === 0);
|
|
8804
|
+
}
|
|
8805
|
+
function isLocalBoundIdentifier(node, scopeStack, scopeBindings, programNode) {
|
|
8806
|
+
if (!node || node.type !== "Identifier") return false;
|
|
8807
|
+
if (FORBIDDEN_BITWISE_IDENTIFIERS.has(node.name)) return false;
|
|
8808
|
+
for (let i = scopeStack.length - 1; i >= 0; i--) {
|
|
8809
|
+
const scopeNode = scopeStack[i];
|
|
8810
|
+
if (scopeNode === programNode) return false;
|
|
8811
|
+
const bindings = scopeBindings.get(scopeNode);
|
|
8812
|
+
if (bindings && bindings.has(node.name)) {
|
|
8813
|
+
return true;
|
|
8814
|
+
}
|
|
8815
|
+
}
|
|
8816
|
+
return false;
|
|
8817
|
+
}
|
|
8818
|
+
function buildColdBitwiseConditional(op, left, right, seed, subIndex, hotExemptNodes) {
|
|
8819
|
+
const { m, mInv, c, d } = deriveAffineMbaParams(seed, 16640 + subIndex * 43);
|
|
8820
|
+
const a1 = cloneNode(left);
|
|
8821
|
+
const b1 = cloneNode(right);
|
|
8822
|
+
const a2 = cloneNode(left);
|
|
8823
|
+
const b2 = cloneNode(right);
|
|
8824
|
+
let affineComb;
|
|
8825
|
+
if (op === "^") {
|
|
8826
|
+
affineComb = makeBinary(
|
|
8827
|
+
"-",
|
|
8828
|
+
makeImul(makeLiteral(m), makeBinary("|", a1, b1)),
|
|
8829
|
+
makeImul(makeLiteral(m), makeBinary("&", a2, b2))
|
|
8830
|
+
);
|
|
8831
|
+
} else if (op === "|") {
|
|
8832
|
+
affineComb = makeBinary(
|
|
8833
|
+
"+",
|
|
8834
|
+
makeImul(makeLiteral(m), makeBinary("&", a1, b1)),
|
|
8835
|
+
makeImul(makeLiteral(m), makeBinary("^", a2, b2))
|
|
8836
|
+
);
|
|
8837
|
+
} else {
|
|
8838
|
+
affineComb = makeBinary(
|
|
8839
|
+
"-",
|
|
8840
|
+
makeImul(makeLiteral(m), makeBinary("|", a1, b1)),
|
|
8841
|
+
makeImul(makeLiteral(m), makeBinary("^", a2, b2))
|
|
8842
|
+
);
|
|
8843
|
+
}
|
|
8844
|
+
const innerWithC = makeBinary("|", makeBinary("+", affineComb, makeLiteral(c)), makeLiteral(0));
|
|
8845
|
+
const consequent = makeBinary(
|
|
8846
|
+
"|",
|
|
8847
|
+
makeBinary("+", makeImul(makeLiteral(mInv), innerWithC), makeLiteral(d)),
|
|
8848
|
+
makeLiteral(0)
|
|
8849
|
+
);
|
|
8850
|
+
const alternate = makeBinary(op, cloneNode(left), cloneNode(right));
|
|
8851
|
+
const exemptNodes = [];
|
|
8852
|
+
const uniqueIdents = [];
|
|
8853
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
8854
|
+
for (const operand of [left, right]) {
|
|
8855
|
+
if (operand?.type === "Identifier" && !seenNames.has(operand.name)) {
|
|
8856
|
+
seenNames.add(operand.name);
|
|
8857
|
+
uniqueIdents.push(operand);
|
|
8858
|
+
}
|
|
8859
|
+
}
|
|
8860
|
+
const makeIsNumberExpr = (ident) => {
|
|
8861
|
+
const numLit = makeLiteral("number");
|
|
8862
|
+
const eqNode = makeBinary("===", makeUnary("typeof", { type: "Identifier", name: ident.name }), numLit);
|
|
8863
|
+
exemptNodes.push(numLit, eqNode);
|
|
8864
|
+
return eqNode;
|
|
8865
|
+
};
|
|
8866
|
+
const testExpr = uniqueIdents.length === 2 ? {
|
|
8867
|
+
type: "LogicalExpression",
|
|
8868
|
+
operator: "&&",
|
|
8869
|
+
left: makeIsNumberExpr(uniqueIdents[0]),
|
|
8870
|
+
right: makeIsNumberExpr(uniqueIdents[1])
|
|
8871
|
+
} : makeIsNumberExpr(uniqueIdents[0]);
|
|
8872
|
+
const replacement = {
|
|
8873
|
+
type: "ConditionalExpression",
|
|
8874
|
+
test: testExpr,
|
|
8875
|
+
consequent,
|
|
8876
|
+
alternate,
|
|
8877
|
+
_unpeekGuardSubtree: true
|
|
8878
|
+
};
|
|
8879
|
+
if (hotExemptNodes) {
|
|
8880
|
+
hotExemptNodes.add(replacement);
|
|
8881
|
+
hotExemptNodes.add(testExpr);
|
|
8882
|
+
for (const nodeToExempt of exemptNodes) {
|
|
8883
|
+
hotExemptNodes.add(nodeToExempt);
|
|
8884
|
+
}
|
|
8885
|
+
}
|
|
8886
|
+
return replacement;
|
|
8887
|
+
}
|
|
8888
|
+
function applyColdBitwiseMba(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes, guardSubtreeNodes) {
|
|
8889
|
+
const { unsafe, scopeBindings } = analyzeBitwiseMbaScopes(ast);
|
|
8890
|
+
if (unsafe) return 0;
|
|
8891
|
+
let mbaCount = 0;
|
|
8892
|
+
const scopeStack = [];
|
|
8893
|
+
function walkTransform(node, setInParent, inColdFn) {
|
|
8894
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) return;
|
|
8895
|
+
if (!node || typeof node !== "object" || typeof node.type !== "string") return;
|
|
8896
|
+
if (hotExemptNodes?.has(node) || guardSubtreeNodes?.has(node)) return;
|
|
8897
|
+
if (node._unpeekGuardSubtree === true) return;
|
|
8898
|
+
if (node._unpeekSerialized || node._unpeekVirtualized === true) return;
|
|
8899
|
+
if (BITWISE_LOOP_NODE_TYPES.has(node.type)) return;
|
|
8900
|
+
const pushedScope = scopeBindings.has(node);
|
|
8901
|
+
if (pushedScope) scopeStack.push(node);
|
|
8902
|
+
try {
|
|
8903
|
+
const childInColdFn = BITWISE_FUNCTION_TYPES.has(node.type) ? coldFunctionNodes.has(node) : inColdFn;
|
|
8904
|
+
if (childInColdFn && node.type === "BinaryExpression" && BITWISE_MBA_OPS.has(node.operator)) {
|
|
8905
|
+
const op = node.operator;
|
|
8906
|
+
const { left, right } = node;
|
|
8907
|
+
const isCoercionOrZero = op === "|" && isZeroNumericLiteral(right);
|
|
8908
|
+
if (!isCoercionOrZero) {
|
|
8909
|
+
const leftAtomic = isSafeAtomicIntegerLiteral(left) || isLocalBoundIdentifier(left, scopeStack, scopeBindings, ast);
|
|
8910
|
+
const rightAtomic = isSafeAtomicIntegerLiteral(right) || isLocalBoundIdentifier(right, scopeStack, scopeBindings, ast);
|
|
8911
|
+
const hasIdent = left?.type === "Identifier" || right?.type === "Identifier";
|
|
8912
|
+
if (leftAtomic && rightAtomic && hasIdent) {
|
|
8913
|
+
const replacement = buildColdBitwiseConditional(
|
|
8914
|
+
op,
|
|
8915
|
+
left,
|
|
8916
|
+
right,
|
|
8917
|
+
seed,
|
|
8918
|
+
mbaCount,
|
|
8919
|
+
hotExemptNodes
|
|
8920
|
+
);
|
|
8921
|
+
mbaCount++;
|
|
8922
|
+
setInParent(replacement);
|
|
8923
|
+
return;
|
|
8924
|
+
}
|
|
8925
|
+
}
|
|
8926
|
+
}
|
|
8927
|
+
for (const key of Object.keys(node)) {
|
|
8928
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) break;
|
|
8929
|
+
if (key === "loc" || key === "range" || key === "start" || key === "end" || key === "comments" || key === "tokens") {
|
|
8930
|
+
continue;
|
|
8931
|
+
}
|
|
8932
|
+
const child = node[key];
|
|
8933
|
+
if (Array.isArray(child)) {
|
|
8934
|
+
for (let i = 0; i < child.length; i++) {
|
|
8935
|
+
if (mbaCount >= MAX_COLD_BITWISE_MBA_PER_CHUNK) break;
|
|
8936
|
+
const item = child[i];
|
|
8937
|
+
if (item && typeof item === "object" && typeof item.type === "string") {
|
|
8938
|
+
walkTransform(
|
|
8939
|
+
item,
|
|
8940
|
+
(rep) => {
|
|
8941
|
+
child[i] = rep;
|
|
8942
|
+
},
|
|
8943
|
+
childInColdFn
|
|
8944
|
+
);
|
|
8945
|
+
}
|
|
8946
|
+
}
|
|
8947
|
+
} else if (child && typeof child === "object" && typeof child.type === "string") {
|
|
8948
|
+
walkTransform(
|
|
8949
|
+
child,
|
|
8950
|
+
(rep) => {
|
|
8951
|
+
node[key] = rep;
|
|
8952
|
+
},
|
|
8953
|
+
childInColdFn
|
|
8954
|
+
);
|
|
8955
|
+
}
|
|
8956
|
+
}
|
|
8957
|
+
} finally {
|
|
8958
|
+
if (pushedScope) scopeStack.pop();
|
|
8959
|
+
}
|
|
8960
|
+
}
|
|
8961
|
+
walkTransform(ast, () => {
|
|
8962
|
+
}, false);
|
|
8963
|
+
return mbaCount;
|
|
8964
|
+
}
|
|
8965
|
+
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes, windowKeySymbol, expectedDelta, shieldCoupled = false, options) {
|
|
7948
8966
|
const sfx = (seed >>> 0).toString(36).slice(0, 4);
|
|
7949
8967
|
const decoyIdent = `_uDec${sfx}`;
|
|
7950
8968
|
const sboxIdent = `_uSb${sfx}`;
|
|
@@ -7960,6 +8978,9 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
7960
8978
|
);
|
|
7961
8979
|
if (alreadyGuarded) return 0;
|
|
7962
8980
|
}
|
|
8981
|
+
if (options?.enableBitwiseMba) {
|
|
8982
|
+
applyColdBitwiseMba(ast, coldFunctionNodes, seed, hotExemptNodes);
|
|
8983
|
+
}
|
|
7963
8984
|
let guardedCount = 0;
|
|
7964
8985
|
function maybeInjectGuard(node) {
|
|
7965
8986
|
if (guardedCount >= MAX_COLD_GUARDS_PER_CHUNK) return;
|
|
@@ -7994,6 +9015,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
7994
9015
|
}
|
|
7995
9016
|
);
|
|
7996
9017
|
guardedCount++;
|
|
9018
|
+
guardStmt._unpeekGuardSubtree = true;
|
|
7997
9019
|
if (hotExemptNodes) {
|
|
7998
9020
|
hotExemptNodes.add(guardStmt);
|
|
7999
9021
|
hotExemptNodes.add(guardStmt.consequent);
|
|
@@ -10299,7 +11321,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
10299
11321
|
hotExemptNodes,
|
|
10300
11322
|
sym,
|
|
10301
11323
|
shieldDelta,
|
|
10302
|
-
shieldCoupled
|
|
11324
|
+
shieldCoupled,
|
|
11325
|
+
{ enableBitwiseMba: isAggressive || effectiveProfile === "strict" }
|
|
10303
11326
|
);
|
|
10304
11327
|
}
|
|
10305
11328
|
const mangledSymbolsCount = applyPolymorphicMangler(
|
|
@@ -10904,7 +11927,7 @@ async function protectProject(options = {}) {
|
|
|
10904
11927
|
import fs7 from "fs";
|
|
10905
11928
|
import path6 from "path";
|
|
10906
11929
|
import * as acorn8 from "acorn";
|
|
10907
|
-
import { simple as walkSimple2 } from "acorn-walk";
|
|
11930
|
+
import { recursive as walkRecursive, simple as walkSimple2 } from "acorn-walk";
|
|
10908
11931
|
function walkPublicMaps(currentDir, rootOutDir, found) {
|
|
10909
11932
|
if (hasNextServerSegment(currentDir, rootOutDir)) {
|
|
10910
11933
|
return;
|
|
@@ -10980,11 +12003,13 @@ function isHitFromNodeModules(hit, map, allSourcesNodeModules) {
|
|
|
10980
12003
|
}
|
|
10981
12004
|
return allSourcesNodeModules;
|
|
10982
12005
|
}
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
12006
|
+
var MAX_PLAINTEXT_SECRET_FINDINGS_PER_FILE = 5;
|
|
12007
|
+
var UNPEEK_VAULT_IDENT_PREFIXES = ["_uP", "_uC", "_uD", "_uS", "_uSb", "_uDec"];
|
|
12008
|
+
var BINARY_DATA_URI_RE2 = /^data:(?:application\/(?:wasm|octet-stream|pdf|zip|gzip|(?:x-)?font-[a-z0-9-]+)|image\/|font\/|audio\/|video\/)/i;
|
|
12009
|
+
var SECRET_LIMIT_REACHED = {};
|
|
12010
|
+
function parseCheckAst(code) {
|
|
10986
12011
|
try {
|
|
10987
|
-
|
|
12012
|
+
return acorn8.parse(code, {
|
|
10988
12013
|
ecmaVersion: "latest",
|
|
10989
12014
|
sourceType: "module",
|
|
10990
12015
|
allowReturnOutsideFunction: true,
|
|
@@ -10992,16 +12017,137 @@ function findEvalOrFunctionCalls(code) {
|
|
|
10992
12017
|
});
|
|
10993
12018
|
} catch {
|
|
10994
12019
|
try {
|
|
10995
|
-
|
|
12020
|
+
return acorn8.parse(code, {
|
|
10996
12021
|
ecmaVersion: "latest",
|
|
10997
12022
|
sourceType: "script",
|
|
10998
12023
|
allowReturnOutsideFunction: true,
|
|
10999
12024
|
locations: true
|
|
11000
12025
|
});
|
|
11001
12026
|
} catch {
|
|
11002
|
-
return
|
|
12027
|
+
return null;
|
|
12028
|
+
}
|
|
12029
|
+
}
|
|
12030
|
+
}
|
|
12031
|
+
function isUnpeekVaultIdentifier(name) {
|
|
12032
|
+
return UNPEEK_VAULT_IDENT_PREFIXES.some((prefix) => name.startsWith(prefix));
|
|
12033
|
+
}
|
|
12034
|
+
function isUnpeekShaderVaultIife(init) {
|
|
12035
|
+
if (!init || init.type !== "CallExpression" || init.callee.type !== "FunctionExpression" || init.callee.id?.name !== "f" || init.callee.params.length !== 1 || init.arguments.length !== 1 || init.arguments[0]?.type !== "ArrayExpression") {
|
|
12036
|
+
return false;
|
|
12037
|
+
}
|
|
12038
|
+
const first = init.callee.body?.body?.[0];
|
|
12039
|
+
return first?.type === "VariableDeclaration" && first.declarations.some(
|
|
12040
|
+
(d) => d.id.type === "Identifier" && d.id.name === "h" && d.init?.type === "Literal" && d.init.value === 2166136261
|
|
12041
|
+
);
|
|
12042
|
+
}
|
|
12043
|
+
function isSkippedBinaryPayload(value) {
|
|
12044
|
+
return value.startsWith("AGFzbQE") || BINARY_DATA_URI_RE2.test(value);
|
|
12045
|
+
}
|
|
12046
|
+
function redactSecretPreview(value) {
|
|
12047
|
+
const singleLine = value.replace(/[\r\n\t]+/g, " ");
|
|
12048
|
+
if (singleLine.length <= 10) {
|
|
12049
|
+
return "[redacted]";
|
|
12050
|
+
}
|
|
12051
|
+
return `${singleLine.slice(0, 4)}...${singleLine.slice(-4)}`;
|
|
12052
|
+
}
|
|
12053
|
+
function findPlaintextSecrets(code, parsedAst) {
|
|
12054
|
+
const ast = parsedAst !== void 0 ? parsedAst : parseCheckAst(code);
|
|
12055
|
+
if (!ast) {
|
|
12056
|
+
return [];
|
|
12057
|
+
}
|
|
12058
|
+
const hits = [];
|
|
12059
|
+
const pushHit = (category, rawValue, node) => {
|
|
12060
|
+
hits.push({
|
|
12061
|
+
category,
|
|
12062
|
+
preview: redactSecretPreview(rawValue),
|
|
12063
|
+
line: node.loc ? node.loc.start.line : 1
|
|
12064
|
+
});
|
|
12065
|
+
if (hits.length >= MAX_PLAINTEXT_SECRET_FINDINGS_PER_FILE) {
|
|
12066
|
+
throw SECRET_LIMIT_REACHED;
|
|
12067
|
+
}
|
|
12068
|
+
};
|
|
12069
|
+
const inspectString = (value, node) => {
|
|
12070
|
+
if (!value || isSkippedBinaryPayload(value)) return;
|
|
12071
|
+
const match = classifyPlaintextSecret(value);
|
|
12072
|
+
if (match) {
|
|
12073
|
+
pushHit(match.category, value, node);
|
|
12074
|
+
}
|
|
12075
|
+
};
|
|
12076
|
+
try {
|
|
12077
|
+
walkRecursive(ast, void 0, {
|
|
12078
|
+
VariableDeclarator(node, state, c) {
|
|
12079
|
+
if (node.id.type === "Identifier" && isUnpeekVaultIdentifier(node.id.name) || isUnpeekShaderVaultIife(node.init)) {
|
|
12080
|
+
return;
|
|
12081
|
+
}
|
|
12082
|
+
c(node.id, state);
|
|
12083
|
+
if (node.init) {
|
|
12084
|
+
c(node.init, state);
|
|
12085
|
+
}
|
|
12086
|
+
},
|
|
12087
|
+
FunctionDeclaration(node, state, c) {
|
|
12088
|
+
if (node.id && isUnpeekVaultIdentifier(node.id.name)) {
|
|
12089
|
+
return;
|
|
12090
|
+
}
|
|
12091
|
+
for (const param of node.params) {
|
|
12092
|
+
c(param, state);
|
|
12093
|
+
}
|
|
12094
|
+
c(node.body, state);
|
|
12095
|
+
},
|
|
12096
|
+
ExpressionStatement(node, state, c) {
|
|
12097
|
+
if (node.directive) {
|
|
12098
|
+
return;
|
|
12099
|
+
}
|
|
12100
|
+
c(node.expression, state);
|
|
12101
|
+
},
|
|
12102
|
+
ImportDeclaration() {
|
|
12103
|
+
},
|
|
12104
|
+
ExportNamedDeclaration(node, state, c) {
|
|
12105
|
+
if (node.declaration) {
|
|
12106
|
+
c(node.declaration, state);
|
|
12107
|
+
}
|
|
12108
|
+
},
|
|
12109
|
+
ExportAllDeclaration() {
|
|
12110
|
+
},
|
|
12111
|
+
ImportExpression(node, state, c) {
|
|
12112
|
+
if (node.options) {
|
|
12113
|
+
c(node.options, state);
|
|
12114
|
+
}
|
|
12115
|
+
},
|
|
12116
|
+
ImportSpecifier() {
|
|
12117
|
+
},
|
|
12118
|
+
ExportSpecifier() {
|
|
12119
|
+
},
|
|
12120
|
+
ImportAttribute() {
|
|
12121
|
+
},
|
|
12122
|
+
Literal(node) {
|
|
12123
|
+
if (typeof node.value === "string") {
|
|
12124
|
+
inspectString(node.value, node);
|
|
12125
|
+
} else if (node.regex && typeof node.regex.pattern === "string") {
|
|
12126
|
+
if (hasRegexSecretRun(node.regex.pattern)) {
|
|
12127
|
+
pushHit("regex-secret", node.regex.pattern, node);
|
|
12128
|
+
}
|
|
12129
|
+
}
|
|
12130
|
+
},
|
|
12131
|
+
TemplateElement(node) {
|
|
12132
|
+
const val = node.value.cooked ?? node.value.raw;
|
|
12133
|
+
if (typeof val === "string") {
|
|
12134
|
+
inspectString(val, node);
|
|
12135
|
+
}
|
|
12136
|
+
}
|
|
12137
|
+
});
|
|
12138
|
+
} catch (err) {
|
|
12139
|
+
if (err !== SECRET_LIMIT_REACHED) {
|
|
12140
|
+
throw err;
|
|
11003
12141
|
}
|
|
11004
12142
|
}
|
|
12143
|
+
return hits;
|
|
12144
|
+
}
|
|
12145
|
+
function findEvalOrFunctionCalls(code, parsedAst) {
|
|
12146
|
+
const hits = [];
|
|
12147
|
+
const ast = parsedAst !== void 0 ? parsedAst : parseCheckAst(code);
|
|
12148
|
+
if (!ast) {
|
|
12149
|
+
return hits;
|
|
12150
|
+
}
|
|
11005
12151
|
walkSimple2(ast, {
|
|
11006
12152
|
CallExpression(node) {
|
|
11007
12153
|
if (node.callee.type === "Identifier") {
|
|
@@ -11151,7 +12297,8 @@ async function checkProject(options = {}) {
|
|
|
11151
12297
|
file: rel
|
|
11152
12298
|
});
|
|
11153
12299
|
}
|
|
11154
|
-
const
|
|
12300
|
+
const ast = parseCheckAst(content);
|
|
12301
|
+
const evalHits = findEvalOrFunctionCalls(content, ast);
|
|
11155
12302
|
if (evalHits.length > 0) {
|
|
11156
12303
|
if (!requireZeroEval) {
|
|
11157
12304
|
const kinds = Array.from(new Set(evalHits.map((h) => h.kind)));
|
|
@@ -11213,6 +12360,20 @@ async function checkProject(options = {}) {
|
|
|
11213
12360
|
}
|
|
11214
12361
|
}
|
|
11215
12362
|
}
|
|
12363
|
+
const secretHits = findPlaintextSecrets(content, ast);
|
|
12364
|
+
if (secretHits.length > 0) {
|
|
12365
|
+
const failOnSecrets = options.failOnPlaintextSecrets === true;
|
|
12366
|
+
const targetBucket = failOnSecrets ? violations : warnings;
|
|
12367
|
+
const severity = failOnSecrets ? "error" : "warning";
|
|
12368
|
+
for (const hit of secretHits) {
|
|
12369
|
+
targetBucket.push({
|
|
12370
|
+
rule: "plaintext-secret",
|
|
12371
|
+
severity,
|
|
12372
|
+
message: `Plaintext secret (${hit.category}) "${hit.preview}" detected in "${rel}" at line ${hit.line}.`,
|
|
12373
|
+
file: rel
|
|
12374
|
+
});
|
|
12375
|
+
}
|
|
12376
|
+
}
|
|
11216
12377
|
}
|
|
11217
12378
|
const relVault = path6.relative(cwd, vaultDir).replace(/\\/g, "/");
|
|
11218
12379
|
const ignoreEntry = relVault && !relVault.startsWith("..") ? `${relVault}/` : ".unpeek-maps/";
|
|
@@ -11283,7 +12444,7 @@ async function checkProject(options = {}) {
|
|
|
11283
12444
|
}
|
|
11284
12445
|
|
|
11285
12446
|
// src/cli/index.ts
|
|
11286
|
-
var VERSION = "4.
|
|
12447
|
+
var VERSION = "4.2.0";
|
|
11287
12448
|
var cachedPackageVersion;
|
|
11288
12449
|
function getPackageVersion() {
|
|
11289
12450
|
if (cachedPackageVersion !== void 0) {
|