sekant-intercept-js 1.0.2 → 1.0.4
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 +1 -0
- package/dist/sekant-intercept.browser.mjs +12 -8
- package/dist/sekant-intercept.node.mjs +12 -8
- package/package.json +1 -1
- package/src/ahocorasickEngine.mjs +209 -104
- package/src/interceptScanner.mjs +473 -19
- package/src/yaraConditionParser.mjs +38 -1
- package/src/yaraConditionsMatch.mjs +16 -0
- package/src/yaraRuleCompiler.mjs +326 -9
- package/src/yaraStringMatch.mjs +413 -93
|
@@ -4,14 +4,18 @@
|
|
|
4
4
|
* Licensed under Apache 2.0
|
|
5
5
|
* Includes third-party code from pe-library and spark-md5 (MIT)
|
|
6
6
|
*/
|
|
7
|
-
var xt=Object.create;var pe=Object.defineProperty;var Ot=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var Et=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty;var It=(n,e)=>()=>{try{return e||n((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},zt=(n,e)=>{for(var t in e)pe(n,t,{get:e[t],enumerable:!0})},$t=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of St(e))!Ct.call(n,i)&&i!==t&&pe(n,i,{get:()=>e[i],enumerable:!(r=Ot(e,i))||r.enumerable});return n};var Rt=(n,e,t)=>(t=n!=null?xt(Et(n)):{},$t(e||!n||!n.__esModule?pe(t,"default",{value:n,enumerable:!0}):t,n));var dt=It((pt,gt)=>{(function(n){if(typeof pt=="object")gt.exports=n();else if(typeof define=="function"&&define.amd)define(n);else{var e;try{e=window}catch{e=self}e.SparkMD5=n()}})(function(n){"use strict";var e=function(y,g){return y+g&4294967295},t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function r(y,g,f,l,c,h){return g=e(e(g,y),e(l,h)),e(g<<c|g>>>32-c,f)}function i(y,g){var f=y[0],l=y[1],c=y[2],h=y[3];f+=(l&c|~l&h)+g[0]-680876936|0,f=(f<<7|f>>>25)+l|0,h+=(f&l|~f&c)+g[1]-389564586|0,h=(h<<12|h>>>20)+f|0,c+=(h&f|~h&l)+g[2]+606105819|0,c=(c<<17|c>>>15)+h|0,l+=(c&h|~c&f)+g[3]-1044525330|0,l=(l<<22|l>>>10)+c|0,f+=(l&c|~l&h)+g[4]-176418897|0,f=(f<<7|f>>>25)+l|0,h+=(f&l|~f&c)+g[5]+1200080426|0,h=(h<<12|h>>>20)+f|0,c+=(h&f|~h&l)+g[6]-1473231341|0,c=(c<<17|c>>>15)+h|0,l+=(c&h|~c&f)+g[7]-45705983|0,l=(l<<22|l>>>10)+c|0,f+=(l&c|~l&h)+g[8]+1770035416|0,f=(f<<7|f>>>25)+l|0,h+=(f&l|~f&c)+g[9]-1958414417|0,h=(h<<12|h>>>20)+f|0,c+=(h&f|~h&l)+g[10]-42063|0,c=(c<<17|c>>>15)+h|0,l+=(c&h|~c&f)+g[11]-1990404162|0,l=(l<<22|l>>>10)+c|0,f+=(l&c|~l&h)+g[12]+1804603682|0,f=(f<<7|f>>>25)+l|0,h+=(f&l|~f&c)+g[13]-40341101|0,h=(h<<12|h>>>20)+f|0,c+=(h&f|~h&l)+g[14]-1502002290|0,c=(c<<17|c>>>15)+h|0,l+=(c&h|~c&f)+g[15]+1236535329|0,l=(l<<22|l>>>10)+c|0,f+=(l&h|c&~h)+g[1]-165796510|0,f=(f<<5|f>>>27)+l|0,h+=(f&c|l&~c)+g[6]-1069501632|0,h=(h<<9|h>>>23)+f|0,c+=(h&l|f&~l)+g[11]+643717713|0,c=(c<<14|c>>>18)+h|0,l+=(c&f|h&~f)+g[0]-373897302|0,l=(l<<20|l>>>12)+c|0,f+=(l&h|c&~h)+g[5]-701558691|0,f=(f<<5|f>>>27)+l|0,h+=(f&c|l&~c)+g[10]+38016083|0,h=(h<<9|h>>>23)+f|0,c+=(h&l|f&~l)+g[15]-660478335|0,c=(c<<14|c>>>18)+h|0,l+=(c&f|h&~f)+g[4]-405537848|0,l=(l<<20|l>>>12)+c|0,f+=(l&h|c&~h)+g[9]+568446438|0,f=(f<<5|f>>>27)+l|0,h+=(f&c|l&~c)+g[14]-1019803690|0,h=(h<<9|h>>>23)+f|0,c+=(h&l|f&~l)+g[3]-187363961|0,c=(c<<14|c>>>18)+h|0,l+=(c&f|h&~f)+g[8]+1163531501|0,l=(l<<20|l>>>12)+c|0,f+=(l&h|c&~h)+g[13]-1444681467|0,f=(f<<5|f>>>27)+l|0,h+=(f&c|l&~c)+g[2]-51403784|0,h=(h<<9|h>>>23)+f|0,c+=(h&l|f&~l)+g[7]+1735328473|0,c=(c<<14|c>>>18)+h|0,l+=(c&f|h&~f)+g[12]-1926607734|0,l=(l<<20|l>>>12)+c|0,f+=(l^c^h)+g[5]-378558|0,f=(f<<4|f>>>28)+l|0,h+=(f^l^c)+g[8]-2022574463|0,h=(h<<11|h>>>21)+f|0,c+=(h^f^l)+g[11]+1839030562|0,c=(c<<16|c>>>16)+h|0,l+=(c^h^f)+g[14]-35309556|0,l=(l<<23|l>>>9)+c|0,f+=(l^c^h)+g[1]-1530992060|0,f=(f<<4|f>>>28)+l|0,h+=(f^l^c)+g[4]+1272893353|0,h=(h<<11|h>>>21)+f|0,c+=(h^f^l)+g[7]-155497632|0,c=(c<<16|c>>>16)+h|0,l+=(c^h^f)+g[10]-1094730640|0,l=(l<<23|l>>>9)+c|0,f+=(l^c^h)+g[13]+681279174|0,f=(f<<4|f>>>28)+l|0,h+=(f^l^c)+g[0]-358537222|0,h=(h<<11|h>>>21)+f|0,c+=(h^f^l)+g[3]-722521979|0,c=(c<<16|c>>>16)+h|0,l+=(c^h^f)+g[6]+76029189|0,l=(l<<23|l>>>9)+c|0,f+=(l^c^h)+g[9]-640364487|0,f=(f<<4|f>>>28)+l|0,h+=(f^l^c)+g[12]-421815835|0,h=(h<<11|h>>>21)+f|0,c+=(h^f^l)+g[15]+530742520|0,c=(c<<16|c>>>16)+h|0,l+=(c^h^f)+g[2]-995338651|0,l=(l<<23|l>>>9)+c|0,f+=(c^(l|~h))+g[0]-198630844|0,f=(f<<6|f>>>26)+l|0,h+=(l^(f|~c))+g[7]+1126891415|0,h=(h<<10|h>>>22)+f|0,c+=(f^(h|~l))+g[14]-1416354905|0,c=(c<<15|c>>>17)+h|0,l+=(h^(c|~f))+g[5]-57434055|0,l=(l<<21|l>>>11)+c|0,f+=(c^(l|~h))+g[12]+1700485571|0,f=(f<<6|f>>>26)+l|0,h+=(l^(f|~c))+g[3]-1894986606|0,h=(h<<10|h>>>22)+f|0,c+=(f^(h|~l))+g[10]-1051523|0,c=(c<<15|c>>>17)+h|0,l+=(h^(c|~f))+g[1]-2054922799|0,l=(l<<21|l>>>11)+c|0,f+=(c^(l|~h))+g[8]+1873313359|0,f=(f<<6|f>>>26)+l|0,h+=(l^(f|~c))+g[15]-30611744|0,h=(h<<10|h>>>22)+f|0,c+=(f^(h|~l))+g[6]-1560198380|0,c=(c<<15|c>>>17)+h|0,l+=(h^(c|~f))+g[13]+1309151649|0,l=(l<<21|l>>>11)+c|0,f+=(c^(l|~h))+g[4]-145523070|0,f=(f<<6|f>>>26)+l|0,h+=(l^(f|~c))+g[11]-1120210379|0,h=(h<<10|h>>>22)+f|0,c+=(f^(h|~l))+g[2]+718787259|0,c=(c<<15|c>>>17)+h|0,l+=(h^(c|~f))+g[9]-343485551|0,l=(l<<21|l>>>11)+c|0,y[0]=f+y[0]|0,y[1]=l+y[1]|0,y[2]=c+y[2]|0,y[3]=h+y[3]|0}function s(y){var g=[],f;for(f=0;f<64;f+=4)g[f>>2]=y.charCodeAt(f)+(y.charCodeAt(f+1)<<8)+(y.charCodeAt(f+2)<<16)+(y.charCodeAt(f+3)<<24);return g}function o(y){var g=[],f;for(f=0;f<64;f+=4)g[f>>2]=y[f]+(y[f+1]<<8)+(y[f+2]<<16)+(y[f+3]<<24);return g}function u(y){var g=y.length,f=[1732584193,-271733879,-1732584194,271733878],l,c,h,x,S,I;for(l=64;l<=g;l+=64)i(f,s(y.substring(l-64,l)));for(y=y.substring(l-64),c=y.length,h=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],l=0;l<c;l+=1)h[l>>2]|=y.charCodeAt(l)<<(l%4<<3);if(h[l>>2]|=128<<(l%4<<3),l>55)for(i(f,h),l=0;l<16;l+=1)h[l]=0;return x=g*8,x=x.toString(16).match(/(.*?)(.{0,8})$/),S=parseInt(x[2],16),I=parseInt(x[1],16)||0,h[14]=S,h[15]=I,i(f,h),f}function a(y){var g=y.length,f=[1732584193,-271733879,-1732584194,271733878],l,c,h,x,S,I;for(l=64;l<=g;l+=64)i(f,o(y.subarray(l-64,l)));for(y=l-64<g?y.subarray(l-64):new Uint8Array(0),c=y.length,h=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],l=0;l<c;l+=1)h[l>>2]|=y[l]<<(l%4<<3);if(h[l>>2]|=128<<(l%4<<3),l>55)for(i(f,h),l=0;l<16;l+=1)h[l]=0;return x=g*8,x=x.toString(16).match(/(.*?)(.{0,8})$/),S=parseInt(x[2],16),I=parseInt(x[1],16)||0,h[14]=S,h[15]=I,i(f,h),f}function p(y){var g="",f;for(f=0;f<4;f+=1)g+=t[y>>f*8+4&15]+t[y>>f*8&15];return g}function d(y){var g;for(g=0;g<y.length;g+=1)y[g]=p(y[g]);return y.join("")}d(u("hello"))!=="5d41402abc4b2a76b9719d911017c592"&&(e=function(y,g){var f=(y&65535)+(g&65535),l=(y>>16)+(g>>16)+(f>>16);return l<<16|f&65535}),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&(function(){function y(g,f){return g=g|0||0,g<0?Math.max(g+f,0):Math.min(g,f)}ArrayBuffer.prototype.slice=function(g,f){var l=this.byteLength,c=y(g,l),h=l,x,S,I,V;return f!==n&&(h=y(f,l)),c>h?new ArrayBuffer(0):(x=h-c,S=new ArrayBuffer(x),I=new Uint8Array(S),V=new Uint8Array(this,c,x),I.set(V),S)}})();function m(y){return/[\u0080-\uFFFF]/.test(y)&&(y=unescape(encodeURIComponent(y))),y}function b(y,g){var f=y.length,l=new ArrayBuffer(f),c=new Uint8Array(l),h;for(h=0;h<f;h+=1)c[h]=y.charCodeAt(h);return g?c:l}function _(y){return String.fromCharCode.apply(null,new Uint8Array(y))}function U(y,g,f){var l=new Uint8Array(y.byteLength+g.byteLength);return l.set(new Uint8Array(y)),l.set(new Uint8Array(g),y.byteLength),f?l:l.buffer}function v(y){var g=[],f=y.length,l;for(l=0;l<f-1;l+=2)g.push(parseInt(y.substr(l,2),16));return String.fromCharCode.apply(String,g)}function w(){this.reset()}return w.prototype.append=function(y){return this.appendBinary(m(y)),this},w.prototype.appendBinary=function(y){this._buff+=y,this._length+=y.length;var g=this._buff.length,f;for(f=64;f<=g;f+=64)i(this._hash,s(this._buff.substring(f-64,f)));return this._buff=this._buff.substring(f-64),this},w.prototype.end=function(y){var g=this._buff,f=g.length,l,c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],h;for(l=0;l<f;l+=1)c[l>>2]|=g.charCodeAt(l)<<(l%4<<3);return this._finish(c,f),h=d(this._hash),y&&(h=v(h)),this.reset(),h},w.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},w.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},w.prototype.setState=function(y){return this._buff=y.buff,this._length=y.length,this._hash=y.hash,this},w.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},w.prototype._finish=function(y,g){var f=g,l,c,h;if(y[f>>2]|=128<<(f%4<<3),f>55)for(i(this._hash,y),f=0;f<16;f+=1)y[f]=0;l=this._length*8,l=l.toString(16).match(/(.*?)(.{0,8})$/),c=parseInt(l[2],16),h=parseInt(l[1],16)||0,y[14]=c,y[15]=h,i(this._hash,y)},w.hash=function(y,g){return w.hashBinary(m(y),g)},w.hashBinary=function(y,g){var f=u(y),l=d(f);return g?v(l):l},w.ArrayBuffer=function(){this.reset()},w.ArrayBuffer.prototype.append=function(y){var g=U(this._buff.buffer,y,!0),f=g.length,l;for(this._length+=y.byteLength,l=64;l<=f;l+=64)i(this._hash,o(g.subarray(l-64,l)));return this._buff=l-64<f?new Uint8Array(g.buffer.slice(l-64)):new Uint8Array(0),this},w.ArrayBuffer.prototype.end=function(y){var g=this._buff,f=g.length,l=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],c,h;for(c=0;c<f;c+=1)l[c>>2]|=g[c]<<(c%4<<3);return this._finish(l,f),h=d(this._hash),y&&(h=v(h)),this.reset(),h},w.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},w.ArrayBuffer.prototype.getState=function(){var y=w.prototype.getState.call(this);return y.buff=_(y.buff),y},w.ArrayBuffer.prototype.setState=function(y){return y.buff=b(y.buff,!0),w.prototype.setState.call(this,y)},w.ArrayBuffer.prototype.destroy=w.prototype.destroy,w.ArrayBuffer.prototype._finish=w.prototype._finish,w.ArrayBuffer.hash=function(y,g){var f=a(new Uint8Array(y)),l=d(f);return g?v(l):l},w})});var se=class{constructor(){this.children={},this.fail=null,this.outputs=[],this.nocase=!1}},Y=class{constructor(e){this.root=new se,this.addRules(e)}addRules(e){let t=[],r=new TextDecoder;for(let i of e){let{id:s,strings:o}=i;for(let u of Object.keys(o)){let a=o[u];if(a.type==="text")for(let p of a.patterns){let d=p.bytes,m=r.decode(d);t.push({id:s,varName:u,pattern:m,matcher:a.matcher,xor:a.xor,nocase:a.nocase})}else a.type==="regex"&&a.literalPrefix&&a.literalPrefix.length>0&&t.push({id:s,varName:u,pattern:a.literalPrefix,matcher:a.matcher,nocase:a.nocase})}}this.generateAtoms(t),this.buildTrie(t),this.buildFailures()}generateAtoms(e,t=3){let r=[];for(let i of e){if(i.pattern.length<=t)i.atom=i.pattern,i.atomOffset=0;else{let s=Math.floor(Math.random()*(i.pattern.length-t));i.atom=i.pattern.slice(s,s+t),i.atomOffset=s}if(i.atomLength=i.atom.length,i.length=i.pattern.length,i.xor){let[s,o]=i.xor,u=Array.from(i.atom);for(let a=s;a<=o;a++){let p=u.map(d=>String.fromCharCode(d.charCodeAt(0)^a)).join("");a===s?(i.atom=p,i.xorKey=a):r.push({...i,atom:p,xorKey:a})}}}e.push(...r)}buildTrie(e){for(let t of e){let r=this.root;for(let i=0;i<t.atom.length;i++){let s=t.atom[i];r.children[s]||(r.children[s]=new se),r=r.children[s],r.nocase=t.nocase??!1}r.outputs.push(t)}}printTrie(){let e=(t,r)=>{for(let[i,s]of Object.entries(t.children))console.log(`${r}${i} (nocase: ${s.nocase}) (children: [${Object.keys(s.children)}]) (outputs: ${s.outputs.length})`),e(s,r+" ")};e(this.root,"")}buildFailures(){let e=[];for(let t in this.root.children){let r=this.root.children[t];r.fail=this.root,e.push(r)}for(;e.length>0;){let t=e.shift();for(let[r,i]of Object.entries(t.children)){e.push(i);let s=t.fail;for(;s&&!s.children[r];)s=s.fail;i.fail=s?s.children[r]:this.root,i.outputs=i.outputs.concat(i.fail.outputs)}}}search(e){let t=[],r=this.root;for(let i=0;i<e.length;i++){let s=e[i],o=typeof s=="number"?String.fromCharCode(s):s,u=o.toLowerCase();for(;r&&!(r.children[o]||r.children[u]&&r.children[u].nocase);)r=r.fail;if(r?r.children[o]?r=r.children[o]:r.children[u]?.nocase?r=r.children[u]:r=this.root:r=this.root,r!==this.root)for(let a of r.outputs){let p=i-(a.atomLength||0)+1;p-a.atomOffset<0||p-a.atomOffset+a.length>e.length||t.push({id:a.id,varName:a.varName,offset:p-a.atomOffset,index:p,xorKey:a.xorKey,matcher:a.matcher})}}return t}};function He(n){n=n.trim();let e=n.startsWith("/"),t=n.startsWith("{"),r=n.match(/^"(.*)"(.*)$/);if(e)return Tt(n);if(t){let i=n.slice(n.lastIndexOf("}")+1);return Bt(n.slice(1,n.lastIndexOf("}")).trim(),i)}else if(r){let[,i,s]=r,o=s.toLowerCase(),u={wide:/\bwide\b/.test(o),xor:Ht(o),allowKey0:!0,ascii:/\bascii\b/.test(o)||!/\bwide\b/.test(o),base64:/\bbase64\b/.test(o),base64wide:/\bbase64wide\b/.test(o),fullword:/\bfullword\b/.test(o),nocase:/\bnocase\b/.test(o),private:/\bprivate\b/.test(o)};return Nt(i,u)}throw new Error("Unsupported definition: "+n)}function Le(n){let e=(t,r=-1,i=2048,s=-1)=>{if(r<0)return n(t,-1);let o=Math.max(0,r-1);return n(t.slice(o,o+i),o,s<0?-1:s-o)};return e.verifyAt=(t,r)=>e(t,r,2048,r),e}function Tt(n){let e=n.split("/").pop().toLowerCase()??"",t=e.split(" ")[0],r=/\bprivate\b/.test(e),i=n.slice(1,n.lastIndexOf("/")),s=t.includes("i"),o="g"+(t.includes("s")?"s":"")+(s?"i":""),u=Dt(i,s),a=new RegExp(i,o);return{matcher:Le((d,m=-1,b=-1)=>{let _=new TextEncoder,U=new TextDecoder().decode(d),v=[],w=m>=0,y=b>=0,g=y?b:0;m=m<0?0:m,a.lastIndex=g;let f;for(;(f=a.exec(U))!==null&&v.length<100&&!(y&&f.index!==g);){let l=_.encode(U.slice(0,f.index)).length;if(v.push({offset:l+m,length:_.encode(f[0]).length}),a.lastIndex=f.index+1,w)break}return v}),literalPrefix:u,type:"regex",nocase:s,private:r}}function Dt(n,e=!1){n=n.replace(/^\^/,""),n=e?n.toLowerCase():n;let t=n.match(/^((?:\\[^bBdDwWsSAZzGnrtfv0u]|[^\\[\]()|*+?{}.])+)/);return!t||t.length<2?"":t[1].replace(/\\x([0-9A-Fa-f]{2})/g,(i,s)=>String.fromCharCode(parseInt(s,16))).replace(/\\(.)/g,"$1")}function Nt(n,e){let t=new TextEncoder,r=[];e.wide||(e.ascii=!0),(e.base64||e.base64wide)&&(e.nocase=!1,e.fullword=!1,e.xor=null);let i=n.replace(/\\n/g,`
|
|
8
|
-
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\x([0-9A-Fa-f]{2})/g,(
|
|
7
|
+
var nn=Object.create;var Ue=Object.defineProperty;var rn=Object.getOwnPropertyDescriptor;var sn=Object.getOwnPropertyNames;var on=Object.getPrototypeOf,an=Object.prototype.hasOwnProperty;var un=(n,e)=>()=>{try{return e||n((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},fn=(n,e)=>{for(var t in e)Ue(n,t,{get:e[t],enumerable:!0})},cn=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of sn(e))!an.call(n,i)&&i!==t&&Ue(n,i,{get:()=>e[i],enumerable:!(r=rn(e,i))||r.enumerable});return n};var ln=(n,e,t)=>(t=n!=null?nn(on(n)):{},cn(e||!n||!n.__esModule?Ue(t,"default",{value:n,enumerable:!0}):t,n));var qt=un((Vt,kt)=>{(function(n){if(typeof Vt=="object")kt.exports=n();else if(typeof define=="function"&&define.amd)define(n);else{var e;try{e=window}catch{e=self}e.SparkMD5=n()}})(function(n){"use strict";var e=function(y,m){return y+m&4294967295},t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function r(y,m,f,c,d,g){return m=e(e(m,y),e(c,g)),e(m<<d|m>>>32-d,f)}function i(y,m){var f=y[0],c=y[1],d=y[2],g=y[3];f+=(c&d|~c&g)+m[0]-680876936|0,f=(f<<7|f>>>25)+c|0,g+=(f&c|~f&d)+m[1]-389564586|0,g=(g<<12|g>>>20)+f|0,d+=(g&f|~g&c)+m[2]+606105819|0,d=(d<<17|d>>>15)+g|0,c+=(d&g|~d&f)+m[3]-1044525330|0,c=(c<<22|c>>>10)+d|0,f+=(c&d|~c&g)+m[4]-176418897|0,f=(f<<7|f>>>25)+c|0,g+=(f&c|~f&d)+m[5]+1200080426|0,g=(g<<12|g>>>20)+f|0,d+=(g&f|~g&c)+m[6]-1473231341|0,d=(d<<17|d>>>15)+g|0,c+=(d&g|~d&f)+m[7]-45705983|0,c=(c<<22|c>>>10)+d|0,f+=(c&d|~c&g)+m[8]+1770035416|0,f=(f<<7|f>>>25)+c|0,g+=(f&c|~f&d)+m[9]-1958414417|0,g=(g<<12|g>>>20)+f|0,d+=(g&f|~g&c)+m[10]-42063|0,d=(d<<17|d>>>15)+g|0,c+=(d&g|~d&f)+m[11]-1990404162|0,c=(c<<22|c>>>10)+d|0,f+=(c&d|~c&g)+m[12]+1804603682|0,f=(f<<7|f>>>25)+c|0,g+=(f&c|~f&d)+m[13]-40341101|0,g=(g<<12|g>>>20)+f|0,d+=(g&f|~g&c)+m[14]-1502002290|0,d=(d<<17|d>>>15)+g|0,c+=(d&g|~d&f)+m[15]+1236535329|0,c=(c<<22|c>>>10)+d|0,f+=(c&g|d&~g)+m[1]-165796510|0,f=(f<<5|f>>>27)+c|0,g+=(f&d|c&~d)+m[6]-1069501632|0,g=(g<<9|g>>>23)+f|0,d+=(g&c|f&~c)+m[11]+643717713|0,d=(d<<14|d>>>18)+g|0,c+=(d&f|g&~f)+m[0]-373897302|0,c=(c<<20|c>>>12)+d|0,f+=(c&g|d&~g)+m[5]-701558691|0,f=(f<<5|f>>>27)+c|0,g+=(f&d|c&~d)+m[10]+38016083|0,g=(g<<9|g>>>23)+f|0,d+=(g&c|f&~c)+m[15]-660478335|0,d=(d<<14|d>>>18)+g|0,c+=(d&f|g&~f)+m[4]-405537848|0,c=(c<<20|c>>>12)+d|0,f+=(c&g|d&~g)+m[9]+568446438|0,f=(f<<5|f>>>27)+c|0,g+=(f&d|c&~d)+m[14]-1019803690|0,g=(g<<9|g>>>23)+f|0,d+=(g&c|f&~c)+m[3]-187363961|0,d=(d<<14|d>>>18)+g|0,c+=(d&f|g&~f)+m[8]+1163531501|0,c=(c<<20|c>>>12)+d|0,f+=(c&g|d&~g)+m[13]-1444681467|0,f=(f<<5|f>>>27)+c|0,g+=(f&d|c&~d)+m[2]-51403784|0,g=(g<<9|g>>>23)+f|0,d+=(g&c|f&~c)+m[7]+1735328473|0,d=(d<<14|d>>>18)+g|0,c+=(d&f|g&~f)+m[12]-1926607734|0,c=(c<<20|c>>>12)+d|0,f+=(c^d^g)+m[5]-378558|0,f=(f<<4|f>>>28)+c|0,g+=(f^c^d)+m[8]-2022574463|0,g=(g<<11|g>>>21)+f|0,d+=(g^f^c)+m[11]+1839030562|0,d=(d<<16|d>>>16)+g|0,c+=(d^g^f)+m[14]-35309556|0,c=(c<<23|c>>>9)+d|0,f+=(c^d^g)+m[1]-1530992060|0,f=(f<<4|f>>>28)+c|0,g+=(f^c^d)+m[4]+1272893353|0,g=(g<<11|g>>>21)+f|0,d+=(g^f^c)+m[7]-155497632|0,d=(d<<16|d>>>16)+g|0,c+=(d^g^f)+m[10]-1094730640|0,c=(c<<23|c>>>9)+d|0,f+=(c^d^g)+m[13]+681279174|0,f=(f<<4|f>>>28)+c|0,g+=(f^c^d)+m[0]-358537222|0,g=(g<<11|g>>>21)+f|0,d+=(g^f^c)+m[3]-722521979|0,d=(d<<16|d>>>16)+g|0,c+=(d^g^f)+m[6]+76029189|0,c=(c<<23|c>>>9)+d|0,f+=(c^d^g)+m[9]-640364487|0,f=(f<<4|f>>>28)+c|0,g+=(f^c^d)+m[12]-421815835|0,g=(g<<11|g>>>21)+f|0,d+=(g^f^c)+m[15]+530742520|0,d=(d<<16|d>>>16)+g|0,c+=(d^g^f)+m[2]-995338651|0,c=(c<<23|c>>>9)+d|0,f+=(d^(c|~g))+m[0]-198630844|0,f=(f<<6|f>>>26)+c|0,g+=(c^(f|~d))+m[7]+1126891415|0,g=(g<<10|g>>>22)+f|0,d+=(f^(g|~c))+m[14]-1416354905|0,d=(d<<15|d>>>17)+g|0,c+=(g^(d|~f))+m[5]-57434055|0,c=(c<<21|c>>>11)+d|0,f+=(d^(c|~g))+m[12]+1700485571|0,f=(f<<6|f>>>26)+c|0,g+=(c^(f|~d))+m[3]-1894986606|0,g=(g<<10|g>>>22)+f|0,d+=(f^(g|~c))+m[10]-1051523|0,d=(d<<15|d>>>17)+g|0,c+=(g^(d|~f))+m[1]-2054922799|0,c=(c<<21|c>>>11)+d|0,f+=(d^(c|~g))+m[8]+1873313359|0,f=(f<<6|f>>>26)+c|0,g+=(c^(f|~d))+m[15]-30611744|0,g=(g<<10|g>>>22)+f|0,d+=(f^(g|~c))+m[6]-1560198380|0,d=(d<<15|d>>>17)+g|0,c+=(g^(d|~f))+m[13]+1309151649|0,c=(c<<21|c>>>11)+d|0,f+=(d^(c|~g))+m[4]-145523070|0,f=(f<<6|f>>>26)+c|0,g+=(c^(f|~d))+m[11]-1120210379|0,g=(g<<10|g>>>22)+f|0,d+=(f^(g|~c))+m[2]+718787259|0,d=(d<<15|d>>>17)+g|0,c+=(g^(d|~f))+m[9]-343485551|0,c=(c<<21|c>>>11)+d|0,y[0]=f+y[0]|0,y[1]=c+y[1]|0,y[2]=d+y[2]|0,y[3]=g+y[3]|0}function s(y){var m=[],f;for(f=0;f<64;f+=4)m[f>>2]=y.charCodeAt(f)+(y.charCodeAt(f+1)<<8)+(y.charCodeAt(f+2)<<16)+(y.charCodeAt(f+3)<<24);return m}function o(y){var m=[],f;for(f=0;f<64;f+=4)m[f>>2]=y[f]+(y[f+1]<<8)+(y[f+2]<<16)+(y[f+3]<<24);return m}function u(y){var m=y.length,f=[1732584193,-271733879,-1732584194,271733878],c,d,g,A,E,$;for(c=64;c<=m;c+=64)i(f,s(y.substring(c-64,c)));for(y=y.substring(c-64),d=y.length,g=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],c=0;c<d;c+=1)g[c>>2]|=y.charCodeAt(c)<<(c%4<<3);if(g[c>>2]|=128<<(c%4<<3),c>55)for(i(f,g),c=0;c<16;c+=1)g[c]=0;return A=m*8,A=A.toString(16).match(/(.*?)(.{0,8})$/),E=parseInt(A[2],16),$=parseInt(A[1],16)||0,g[14]=E,g[15]=$,i(f,g),f}function a(y){var m=y.length,f=[1732584193,-271733879,-1732584194,271733878],c,d,g,A,E,$;for(c=64;c<=m;c+=64)i(f,o(y.subarray(c-64,c)));for(y=c-64<m?y.subarray(c-64):new Uint8Array(0),d=y.length,g=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],c=0;c<d;c+=1)g[c>>2]|=y[c]<<(c%4<<3);if(g[c>>2]|=128<<(c%4<<3),c>55)for(i(f,g),c=0;c<16;c+=1)g[c]=0;return A=m*8,A=A.toString(16).match(/(.*?)(.{0,8})$/),E=parseInt(A[2],16),$=parseInt(A[1],16)||0,g[14]=E,g[15]=$,i(f,g),f}function l(y){var m="",f;for(f=0;f<4;f+=1)m+=t[y>>f*8+4&15]+t[y>>f*8&15];return m}function p(y){var m;for(m=0;m<y.length;m+=1)y[m]=l(y[m]);return y.join("")}p(u("hello"))!=="5d41402abc4b2a76b9719d911017c592"&&(e=function(y,m){var f=(y&65535)+(m&65535),c=(y>>16)+(m>>16)+(f>>16);return c<<16|f&65535}),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&(function(){function y(m,f){return m=m|0||0,m<0?Math.max(m+f,0):Math.min(m,f)}ArrayBuffer.prototype.slice=function(m,f){var c=this.byteLength,d=y(m,c),g=c,A,E,$,U;return f!==n&&(g=y(f,c)),d>g?new ArrayBuffer(0):(A=g-d,E=new ArrayBuffer(A),$=new Uint8Array(E),U=new Uint8Array(this,d,A),$.set(U),E)}})();function h(y){return/[\u0080-\uFFFF]/.test(y)&&(y=unescape(encodeURIComponent(y))),y}function w(y,m){var f=y.length,c=new ArrayBuffer(f),d=new Uint8Array(c),g;for(g=0;g<f;g+=1)d[g]=y.charCodeAt(g);return m?d:c}function _(y){return String.fromCharCode.apply(null,new Uint8Array(y))}function x(y,m,f){var c=new Uint8Array(y.byteLength+m.byteLength);return c.set(new Uint8Array(y)),c.set(new Uint8Array(m),y.byteLength),f?c:c.buffer}function v(y){var m=[],f=y.length,c;for(c=0;c<f-1;c+=2)m.push(parseInt(y.substr(c,2),16));return String.fromCharCode.apply(String,m)}function b(){this.reset()}return b.prototype.append=function(y){return this.appendBinary(h(y)),this},b.prototype.appendBinary=function(y){this._buff+=y,this._length+=y.length;var m=this._buff.length,f;for(f=64;f<=m;f+=64)i(this._hash,s(this._buff.substring(f-64,f)));return this._buff=this._buff.substring(f-64),this},b.prototype.end=function(y){var m=this._buff,f=m.length,c,d=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],g;for(c=0;c<f;c+=1)d[c>>2]|=m.charCodeAt(c)<<(c%4<<3);return this._finish(d,f),g=p(this._hash),y&&(g=v(g)),this.reset(),g},b.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},b.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},b.prototype.setState=function(y){return this._buff=y.buff,this._length=y.length,this._hash=y.hash,this},b.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},b.prototype._finish=function(y,m){var f=m,c,d,g;if(y[f>>2]|=128<<(f%4<<3),f>55)for(i(this._hash,y),f=0;f<16;f+=1)y[f]=0;c=this._length*8,c=c.toString(16).match(/(.*?)(.{0,8})$/),d=parseInt(c[2],16),g=parseInt(c[1],16)||0,y[14]=d,y[15]=g,i(this._hash,y)},b.hash=function(y,m){return b.hashBinary(h(y),m)},b.hashBinary=function(y,m){var f=u(y),c=p(f);return m?v(c):c},b.ArrayBuffer=function(){this.reset()},b.ArrayBuffer.prototype.append=function(y){var m=x(this._buff.buffer,y,!0),f=m.length,c;for(this._length+=y.byteLength,c=64;c<=f;c+=64)i(this._hash,o(m.subarray(c-64,c)));return this._buff=c-64<f?new Uint8Array(m.buffer.slice(c-64)):new Uint8Array(0),this},b.ArrayBuffer.prototype.end=function(y){var m=this._buff,f=m.length,c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],d,g;for(d=0;d<f;d+=1)c[d>>2]|=m[d]<<(d%4<<3);return this._finish(c,f),g=p(this._hash),y&&(g=v(g)),this.reset(),g},b.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},b.ArrayBuffer.prototype.getState=function(){var y=b.prototype.getState.call(this);return y.buff=_(y.buff),y},b.ArrayBuffer.prototype.setState=function(y){return y.buff=w(y.buff,!0),b.prototype.setState.call(this,y)},b.ArrayBuffer.prototype.destroy=b.prototype.destroy,b.ArrayBuffer.prototype._finish=b.prototype._finish,b.ArrayBuffer.hash=function(y,m){var f=a(new Uint8Array(y)),c=p(f);return m?v(c):c},b})});var he=class{constructor(){this.children=new Map,this.fail=null,this.outputs=null}},it=n=>n>=97&&n<=122||n>=65&&n<=90;function hn(n){let e=[n];for(let t=0;t<n.length;t++){let r=n[t];if(!it(r))continue;let i=r>=97?r-32:r+32,s=e.length;for(let o=0;o<s;o++){let u=e[o].slice();u[t]=i,e.push(u)}}return e}function pn(n,e,t){let r=n.length-e,i=new Int32Array(256),s=0,o=0,u=-1/0;for(let a=0;a<=r;a++){s+=1;let l=0,p=0,h=0;for(let _=a;_<a+e;_++){let x=n[_];i[x]!==s&&(i[x]=s,l+=1),x===0?p+=1:t&&it(x)&&(h+=1)}let w=l*8-p*4-h*2;w>u&&(u=w,o=a)}return o}var rt=new TextEncoder,ne=class{constructor(e){this.root=new he,this.groupCount=0,this.lastOffsets=new Float64Array(0),this.addRules(e)}addRules(e){let t=[];for(let r of e){let{id:i,strings:s}=r;for(let o of Object.keys(s)){let u=s[o];if(u.type==="text")for(let a of u.patterns??[]){let l=a.bytes;!l||l.length===0||t.push({group:this.groupCount++,id:i,varName:o,bytes:l,matcher:u.matcher,xor:u.xor??null,nocase:u.nocase===!0})}else if(u.type==="regex"&&u.literalPrefix){let a=rt.encode(u.literalPrefix);if(a.length===0)continue;t.push({group:this.groupCount++,id:i,varName:o,bytes:a,matcher:u.matcher,xor:null,nocase:u.nocase===!0})}}}this.buildTrie(this.buildAtoms(t)),this.buildFailures()}buildAtoms(e,t=3){let r=[];for(let i of e){let s=i.bytes,o=s.length,u=o<=t,a=u?0:pn(s,t,i.nocase),l=u?o:t,p=s.subarray(a,a+l),h={group:i.group,id:i.id,varName:i.varName,matcher:i.matcher,atomOffset:a,atomLength:l,length:o};if(i.nocase&&!i.xor)for(let w of hn(p))r.push({...h,atom:w});else if(i.xor){let[w,_]=i.xor;for(let x=w;x<=_;x++){let v=new Uint8Array(l);for(let b=0;b<l;b++)v[b]=p[b]^x;r.push({...h,atom:v,xorKey:x})}}else r.push({...h,atom:p})}return r}buildTrie(e){for(let t of e){let r=this.root,i=t.atom;for(let s=0;s<i.length;s++){let o=i[s],u=r.children.get(o);u===void 0&&(u=new he,r.children.set(o,u)),r=u}r.outputs===null?r.outputs=[t]:r.outputs.push(t)}}printTrie(){let e=(t,r)=>{for(let[i,s]of t.children){let o=[...s.children.keys()].map(a=>String.fromCharCode(a)),u=s.outputs===null?0:s.outputs.length;console.log(`${r}${String.fromCharCode(i)} (children: [${o}]) (outputs: ${u})`),e(s,r+" ")}};e(this.root,"")}buildFailures(){let e=[];for(let t of this.root.children.values())t.fail=this.root,e.push(t);for(let t=0;t<e.length;t++){let r=e[t];for(let[i,s]of r.children){e.push(s);let o=r.fail;for(;o&&!o.children.has(i);)o=o.fail;s.fail=o?o.children.get(i):this.root;let u=s.fail.outputs;u!==null&&(s.outputs=s.outputs===null?u.slice():s.outputs.concat(u))}}}resetGroupState(){this.lastOffsets.length<this.groupCount&&(this.lastOffsets=new Float64Array(this.groupCount)),this.lastOffsets.fill(-1,0,this.groupCount)}search(e){typeof e=="string"&&(e=rt.encode(e));let t=[],r=this.root,i=this.lastOffsets,s=e.length,o=r;this.resetGroupState();for(let u=0;u<s;u++){let a=e[u],l=o.children.get(a);for(;l===void 0&&o!==r;)o=o.fail,l=o.children.get(a);if(o=l===void 0?r:l,o===r)continue;let p=o.outputs;if(p!==null)for(let h=0;h<p.length;h++){let w=p[h],_=u-w.atomLength+1,x=_-w.atomOffset;x<0||x+w.length>s||x<=i[w.group]||(i[w.group]=x,t.push({id:w.id,varName:w.varName,offset:x,index:_,xorKey:w.xorKey,matcher:w.matcher}))}}return t}};var dn={maxMatches:100};function Ie(n){let e=[],t=[];if(!n)return{reject:e,rejectCapture:t,modifiers:n??""};let r=/\breject(RECapture)?\s*\(([^)]*)\)/gi,i;for(;(i=r.exec(n))!==null;){let s=i[1]?t:e;for(let o of i[2].split(",")){let u=o.trim();u&&!s.includes(u)&&s.push(u)}}return{reject:e,rejectCapture:t,modifiers:n.replace(/\breject(RECapture)?\s*\([^)]*\)/gi," ")}}var gn=(()=>{try{return new RegExp("","d"),!0}catch{return!1}})();function mn(n){let e=new Uint32Array(n.length+1),t=0;for(let r=0;r<n.length;r++){e[r]=t;let i=n.codePointAt(r);t+=i<128?1:i<2048?2:i<65536?3:4,i>65535&&(e[r+1]=t,r+=1)}return e[n.length]=t,e}function yn(n){let e=!1;for(let t=0;t<n.length;t++){let r=n[t];if(r==="\\"){t+=1;continue}if(e){r==="]"&&(e=!1);continue}if(r==="["){e=!0;continue}if(r!=="(")continue;if(n[t+1]!=="?")return;if(!(n[t+2]==="<"&&n[t+3]!=="="&&n[t+3]!=="!"))continue;let s=n.indexOf(">",t+3);return s===-1?void 0:n.slice(t+3,s)}}function lt(n,e=dn,t={}){n=n.trim();let r=n.startsWith("/"),i=n.startsWith("{"),s=n.match(/^"(.*)"(.*)$/);if(r)return vn(n,e,t);if(i){let o=n.slice(n.lastIndexOf("}")+1);return Cn(n.slice(1,n.lastIndexOf("}")).trim(),o,e)}else if(s){let[,o,u]=s,{reject:a,rejectCapture:l,modifiers:p}=Ie(u),h=p.toLowerCase(),w={wide:/\bwide\b/.test(h),xor:Un(h),allowKey0:!0,ascii:/\bascii\b/.test(h)||!/\bwide\b/.test(h),base64:/\bbase64\b/.test(h),base64wide:/\bbase64wide\b/.test(h),fullword:/\bfullword\b/.test(h),nocase:/\bnocase\b/.test(h),private:/\bprivate\b/.test(h),reject:a,rejectCapture:l};return _n(o,w)}throw new Error("Unsupported definition: "+n)}function ht(n,e){let t=(r,i=-1)=>n(r,i,-1);return t.verifyAt=e??((r,i)=>n(r,i,i)),t}var pt=new TextDecoder,st=new WeakMap,ot=new WeakMap;function at(n){let e=ot.get(n);if(e===void 0){e=!0;for(let t=0;t<n.length;t++)if(n[t]>=128){e=!1;break}ot.set(n,e)}return e}function dt(n,e){return{text:n,identity:n.length===e,byteOf:null}}function Oe(n){let e=st.get(n);return e===void 0&&(e=dt(pt.decode(n),n.length),st.set(n,e)),e}function ut(n,e){let t=Math.min(n.length,e+4096);return dt(pt.decode(n.subarray(e,t)),t-e)}function wn(n){return!n.identity&&n.byteOf===null&&(n.byteOf=mn(n.text)),n}function pe(n,e){return n.identity?e:wn(n).byteOf[e]}function vn(n,e,t={}){let r=n.lastIndexOf("/"),i=n.slice(r+1),{reject:s,rejectCapture:o,modifiers:u}=Ie(i),a=o.length>0,l=t.includeCaptures===!0,p=l&&gn,h=u.toLowerCase(),w=h.match(/^([a-z]*)/)?.[1]??"",_=/\bprivate\b/.test(h),x=n.slice(1,r),v=w.includes("i")||/\bnocase\b/.test(h),b=(w.includes("s")?"s":"")+(v?"i":"")+(p?"d":""),y=bn(x,v),m=l?yn(x):void 0,f=new RegExp(x,"g"+b),c=new RegExp(x,"y"+b),d=(U,C,z=0)=>{let H=z+pe(C,U.index),B={offset:H,length:z+pe(C,U.index+U[0].length)-H};if(a&&typeof U[1]=="string"&&U[1]!==""&&Object.defineProperty(B,"capture",{value:U[1],enumerable:!1}),l)if(U.length>1){let W=m===void 0?{index:1,value:typeof U[1]=="string"?U[1]:null}:{index:1,name:m,value:typeof U[1]=="string"?U[1]:null},Z=p?U.indices?.[1]:null;if(Z){let nt=z+pe(C,Z[0]);W.offset=nt,W.length=z+pe(C,Z[1])-nt}else W.offset=null,W.length=null;B.captures=[W]}else B.captures=[];return B},g=(U,C)=>{if(at(U)){let B=Oe(U);c.lastIndex=C;let W=c.exec(B.text);return W===null?[]:[d(W,B)]}let z=ut(U,C);c.lastIndex=0;let H=c.exec(z.text);return H===null?[]:[d(H,z,C)]},A=(U,C)=>{if(at(U)){let B=Oe(U),W=C+4096;f.lastIndex=C;let Z=f.exec(B.text);return Z===null||Z.index>W?[]:[d(Z,B)]}let z=ut(U,C);f.lastIndex=0;let H=f.exec(z.text);return H===null?[]:[d(H,z,C)]},E=U=>{let C=Oe(U),z=[];f.lastIndex=0;let H;for(;(H=f.exec(C.text))!==null&&z.length<e.maxMatches;)z.push(d(H,C)),f.lastIndex=H.index+1;return z};return{matcher:ht((U,C=-1,z=-1)=>z>=0?g(U,z):C<0?E(U):A(U,C),g),literalPrefix:y,type:"regex",nocase:v,private:_,reject:s,rejectCapture:o}}function bn(n,e=!1){if(n.startsWith("^"))return"";let t=e?n.toLowerCase():n,r=t.match(/^((?:\\[^bBdDwWsSAZzGnrtfv0u]|[^\\[\]()|*+?{}.^$])+)/);if(!r||r.length<2)return"";let i=r[1],s=t.slice(i.length);return s.startsWith("$")||s.startsWith("^")||s.startsWith("|")?"":((/^[?*]/.test(s)||/^\{0[,}]/.test(s))&&(i=i.slice(0,-1)),i.replace(/\\x([0-9A-Fa-f]{2})/g,(u,a)=>String.fromCharCode(parseInt(a,16))).replace(/\\(.)/g,"$1"))}function _n(n,e){let t=new TextEncoder,r=[];e.wide||(e.ascii=!0),(e.base64||e.base64wide)&&(e.nocase=!1,e.fullword=!1,e.xor=null);let i=n.replace(/\\n/g,`
|
|
8
|
+
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\x([0-9A-Fa-f]{2})/g,(a,l)=>String.fromCharCode(parseInt(l,16))).replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\'/g,"'"),s=e.nocase?[i.toLowerCase()]:[i];for(let a of s)e.base64||e.base64wide?(e.base64&&(e.ascii&&r.push(...de(a,!1).map(l=>({bytes:l,isWide:!1}))),e.wide&&r.push(...de(ge(a),!1).map(l=>({bytes:l,isWide:!0})))),e.base64wide&&(e.ascii&&r.push(...de(a,!0).map(l=>({bytes:l,isWide:!0}))),e.wide&&r.push(...de(ge(a),!0).map(l=>({bytes:l,isWide:!0}))))):(e.ascii&&r.push({bytes:t.encode(a),isWide:!1}),e.wide&&r.push({bytes:ge(a),isWide:!0}));let o=(a,l=-1,p=-1)=>{let h=l>=0,w=l<0?0:l,_=l<0?a.length:Math.min(a.length,l+4096),x=[];for(let{bytes:v,isWide:b}of r){let y=e.xor?xn(a,v,e.xor,e.allowKey0,w,_,h,p):An(a,v,e.nocase,w,_,h,p);x.push(...y.map(m=>({...m,length:v.length,isWide:b})))}return e.fullword&&(x=x.filter(v=>ft(a,v.offset,v.length))),x};return{matcher:ht(o,(a,l,p)=>{let h=p===void 0?void 0:p.xorKey;if(e.xor&&h===void 0)return o(a,l,l);let w=[];for(let{bytes:_,isWide:x}of r)if(!(_.length===0||l+_.length>a.length))if(e.xor){if(!Ee(a,l,_,h))continue;w.push({offset:l,key:h,length:_.length,isWide:x})}else Ce(a,l,_,e.nocase)&&w.push({offset:l,length:_.length,isWide:x});return e.fullword?w.filter(_=>ft(a,_.offset,_.length)):w}),patterns:r,type:"text",xor:e.xor,nocase:e.nocase,private:e.private,reject:e.reject??[],rejectCapture:e.rejectCapture??[]}}function xn(n,e,t,r=!0,i=0,s=n.length,o=!1,u=-1){let[a,l]=t,p=[],h=e.length;if(h===0||h>n.length)return p;if(u>=0){for(let w=a;w<=l;w++)Ee(n,u,e,w)&&p.push({offset:u,key:w});return p}for(let w=a;w<=l;w++)for(let _=i;_+h<=s&&!(Ee(n,_,e,w)&&(p.push({offset:_,key:w}),o));_++);return p}function An(n,e,t=!1,r=0,i=n.length,s=!1,o=-1){let u=[],a=e.length;if(a>n.length)return u;if(o>=0)return Ce(n,o,e,t)&&u.push({offset:o}),u;for(let l=r;l+a<=i&&!(Ce(n,l,e,t)&&(u.push({offset:l}),s));l++);return u}function Ce(n,e,t,r){let i=t.length;if(e+i>n.length)return!1;for(let s=0;s<i;s++){let o=n[e+s];if((r?Sn(o):o)!==t[s])return!1}return!0}function Ee(n,e,t,r){let i=t.length;if(e+i>n.length)return!1;for(let s=0;s<i;s++)if((n[e+s]^r)!==t[s])return!1;return!0}function Sn(n){return n>=65&&n<=90?n+32:n}function ft(n,e,t){let r=o=>o>=48&&o<=57||o>=65&&o<=90||o>=97&&o<=122,i=e===0||!r(n[e-1]),s=e+t>=n.length||!r(n[e+t]);return i&&s}function ge(n){let e=new Uint8Array(n.length*2);for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);e[t*2]=r&255,e[t*2+1]=r>>8}return e}function Un(n){let e=n.match(/xor(?:\((0x[0-9a-f]+|\d+)(?:-(0x[0-9a-f]+|\d+))?\))?/i);if(!e)return null;let[,t,r]=e;if(!t&&!r)return[0,255];let i=t?parseInt(t,t.startsWith("0x")?16:10):null,s=r?parseInt(r,r.startsWith("0x")?16:10):null;return i!==null&&s===null?[i,i]:s!==null&&i===null?[s,s]:[i,s]}var On=1e4;function Cn(n,e,t){let r="";n=n?.toUpperCase().replace(/[^0-9A-F?~|()[\-\]]/g,"")||"";let i=n.match(/\[\d*(-\d*)?\]|\(.*\)|~?[0-9A-F?]{2}/g)||[],{reject:s,rejectCapture:o,modifiers:u}=Ie(e),a=/\bprivate\b/.test(u);if(i.length===0)return{matcher:w=>[],type:"hex",private:a,reject:s,rejectCapture:o};for(let h of i)if(h.startsWith("["))if(h.indexOf("-")===-1){let _=parseInt(h.slice(1,-1));r+=`(?:[0-9A-F]{2}){${_}}`}else{let _=/\[(\d*)-(\d*)\]/.exec(h),x=parseInt(_[1])||0,v=parseInt(_[2])||On;r+=`(?:[0-9A-F]{2}){${x},${v}}`}else h.startsWith("(")?r+=ct(h).replace(/\?/g,"[0-9A-F]"):h.startsWith("~")?r+=ct(h):r+=h.replace(/\?/g,"[0-9A-F]");let l=new RegExp(r,"g");return{matcher:h=>{let w=typeof h=="string"?h:Array.from(h).map(v=>v.toString(16).toUpperCase().padStart(2,"0")).join(""),_=[],x;for(l.lastIndex=0;(x=l.exec(w))!==null&&_.length<t.maxMatches;){if(x.index%2!==0){l.lastIndex=x.index+1;continue}_.push({offset:x.index/2,length:Math.ceil(x[0].length/2)}),l.lastIndex=x.index+2}return _},type:"hex",private:a,reject:s,rejectCapture:o}}function ct(n){if(!n||!n.includes("~"))return n;let e=n.split("~"),t=e[0];for(let r=1;r<e.length;r++){let i=e[r].slice(0,2).split("");i[0]=i[0]==="?"?"[0-9A-F]":`${i[0]}`,i[1]=i[1]==="?"?"[0-9A-F]":`${i[1]}`,t+=`(?!${i[0]}${i[1]})[0-9A-F]{2}${e[r].slice(2)}`}return t}function de(n,e=!1){let t=new TextEncoder,r;typeof n=="string"?r=t.encode(n):r=n;let i=[],s=[0,2,3];for(let o=0;o<3;o++){let u=new Uint8Array(o+r.length);u.set(r,o);let a=btoa(String.fromCharCode(...u)),l=s[o],p=/=*$/.exec(a??[0])[0].length,h=a.slice(l,a.length-(p?p+1:0));i.push(e?ge(h):t.encode(h))}return i.filter(o=>o.length>=1)}var Re="__LITERAL_",wt="__REGEX_";var En=[{name:"uint8",bits:8,signed:!1,endian:"little"},{name:"uint16",bits:16,signed:!1,endian:"little"},{name:"uint32",bits:32,signed:!1,endian:"little"},{name:"int8",bits:8,signed:!0,endian:"little"},{name:"int16",bits:16,signed:!0,endian:"little"},{name:"int32",bits:32,signed:!0,endian:"little"},{name:"uint16be",bits:16,signed:!1,endian:"big"},{name:"uint32be",bits:32,signed:!1,endian:"big"},{name:"int16be",bits:16,signed:!0,endian:"big"},{name:"int32be",bits:32,signed:!0,endian:"big"}];function gt(n,e){let t=e;for(;t<n.length&&/\s/.test(n[t]);)t++;return t}function In(n){if(!n.startsWith("(")||!n.endsWith(")"))return!1;let e=0;for(let t=0;t<n.length;t++)if(n[t]==="("&&e++,n[t]===")"&&e--,e===0&&t<n.length-1)return!1;return!0}function zn(n,e,t){let r=!1;for(let i=e+1;i<n.length;i++){let s=n[i];if(r){r=!1;continue}if(s==="\\"){r=!0;continue}if(s===t)return i}return-1}function $n(n,e){let t="",r=!1,i=!1;for(let s=e+1;s<n.length;s++){let o=n[s];if(i){t+=o,i=!1;continue}if(o==="\\"){t+=o,i=!0;continue}if(o===`
|
|
9
|
+
`)return null;if(o==="[")r=!0;else if(o==="]")r=!1;else if(o==="/"&&!r){if(!t)return null;let u=s+1,a="";for(;u<n.length&&/[a-z]/.test(n[u]);)a+=n[u],u+=1;return{pattern:t,flags:a,end:u}}t+=o}return null}var Rn=new Set(["i","s"]);function Dn(n,e){let t=[...new Set(e)].filter(r=>!Rn.has(r));if(t.length>0)return`unsupported flag(s) "${t.join("")}" (YARA allows only "i" and "s")`;try{new RegExp(n,e)}catch(r){return r.message}return null}function Mn(n,e){if(n[e+1]==="/"){let r=n.indexOf(`
|
|
10
|
+
`,e+2);return r===-1?n.length:r}let t=n.indexOf("*/",e+2);return t===-1?n.length:t+2}function jn(n){let e=[],t=[],r=0,i=0,s=!1,o=0,u=0,a=l=>{t.push(n.slice(o,l)),o=l};for(;u<n.length;){let l=n[u];if(l==='"'||l==="'"){let p=zn(n,u,l);if(p!==-1){let h=`${Re}${r}__`;e.push({id:h,type:"string",value:n.slice(u+1,p)}),r+=1,a(u),t.push(h),u=p+1,o=u;continue}u+=1;continue}if(l==="/"){let p=n[u+1];if(p==="/"||p==="*"){u=Mn(n,u);continue}let h=$n(n,u);if(h){let w=`${wt}${i}__`,_=Dn(h.pattern,h.flags);_&&console.warn(`yaraConditionParser: invalid regex literal /${h.pattern}/${h.flags} - ${_}`),e.push({id:w,type:"regex",pattern:h.pattern,flags:h.flags,error:_}),i+=1,a(u),t.push(w),u=h.end,o=u;continue}s||(s=!0,console.warn(`yaraConditionParser: "/" does not start a regex literal in condition "${n.slice(0,80)}" - integer division is "\\"`)),u+=1;continue}u+=1}return a(n.length),{processed:t.join(""),literals:e}}function mt(n){return typeof n=="string"&&(n.startsWith(Re)||n.startsWith(wt))}function yt(n){let e={type:"regex",pattern:n.pattern,flags:n.flags??""};return n.error&&(e.error=n.error),e}function Fn(n){return!n||typeof n!="object"?typeof n:n.type==="string"?`string literal "${n.value}"`:n.type==="identifier"?`"${n.name}"`:n.type==="memberAccess"?"a module/property value":n.type==="functionCall"?"a function call":n.type==="number"||n.type==="boolean"?`${n.type} ${n.value}`:`a "${n.type}" expression`}function ze(n,e,t=""){if(!n||typeof n!="object")return n;if(n.type==="identifier"&&n.name&&mt(n.name)){let i=e.find(s=>s.id===n.name);if(i)return i.type==="regex"?yt(i):{type:"string",value:i.value}}let r={...n};for(let i in r)Object.prototype.hasOwnProperty.call(r,i)&&(Array.isArray(r[i])?r[i]=r[i].map(s=>{if(typeof s=="string"&&mt(s)){let o=e.find(u=>u.id===s);return o?o.type==="regex"?yt(o):o.value:s}return typeof s=="object"?ze(s,e,t):s}):typeof r[i]=="object"&&(r[i]=ze(r[i],e,t)));return r.type==="matches"&&r.right?.type!=="regex"&&(r.error=`right operand of "matches" must be a regex literal, got ${Fn(r.right)}`,console.warn(`yaraConditionParser: invalid "matches" in condition "${t.slice(0,80)}" - ${r.error}`)),r}function me(n,e={}){n=n.trim();let{processed:t,literals:r}=jn(n),i=Q(t,e),s=ze(i,r,n);return Tn(s,e)}function Tn(n,e){return Object.prototype.hasOwnProperty.call(e??{},"$_")?n:$e(n,t=>t.type==="stringIdentifier"&&t.identifier==="$_"?{type:"buffer"}:t)}function $e(n,e){if(!n||typeof n!="object")return n;if(Array.isArray(n))return n.map(r=>$e(r,e));let t=e(n);if(t!==n)return t;for(let r of Object.keys(n)){let i=n[r];i&&typeof i=="object"&&(n[r]=$e(i,e))}return n}function Nn(n){let e=/^(any|all|none|\d+|\d+%|\d+\.\.\d+)\s+of\s+(them|\([^)]+\))$/,t=n.match(e);if(!t)return null;let[,r,i]=t,s,o;if(r==="any")o="any";else if(r==="all")o="all";else if(r==="none")o="none";else if(r.includes("..")){let[a,l]=r.split("..").map(p=>parseInt(p));o="quantified",s={type:"range",min:a,max:l}}else r.endsWith("%")?(o="quantified",s={type:"percentage",value:parseInt(r)}):(o="quantified",s={type:"number",value:parseInt(r)});let u;return i==="them"?u="them":u=i.slice(1,-1).split(",").map(l=>l.trim()),{type:o,...s&&{quantifier:s},items:u}}function Q(n,e={}){for(n=n.trim();In(n);)n=n.slice(1,-1).trim();let t=Nn(n);if(t)return t;let r=(_,x)=>{let v=G(n,` ${_} `);if(v===-1)return null;let b=gt(n,v);return b+=x,b=gt(n,b),{type:_,left:Q(n.substring(0,v),e),right:Q(n.substring(b),e)}},i=r("or",2);if(i)return i;let s=r("and",3);if(s)return s;if(n.trim().startsWith("for ")){let _=n.indexOf(":");if(_!==-1){let x=_+1;for(;x<n.length&&n[x]!=="(";)x++;if(x<n.length){let v=1,b=x+1;for(;b<n.length&&v>0;)n[b]==="("&&v++,n[b]===")"&&v--,b++;if(v===0){let y=n.substring(0,_).trim(),m=n.substring(x+1,b-1).trim(),f=g=>["all","any","none"].includes(g)?g:g.endsWith("%")?{type:"percentage",value:parseInt(g)}:{type:"number",value:parseInt(g)},c=g=>{let A=g.match(/^(\w+)\s+in\s+\((.+?)\.\.(.+?)\)$/);if(A)return{variable:A[1],set:{type:"range",start:S(A[2].trim()),end:S(A[3].trim())}};let E=g.match(/^of\s+(.+)$/);if(E){let $=E[1].trim(),U;return $==="them"?U="them":$.startsWith("(")&&$.endsWith(")")?U=$.slice(1,-1).split(",").map(C=>C.trim()):U=$,{variable:"$",set:{type:"stringSet",items:U}}}return{variable:null,set:null}},d=y.match(/^for\s+(all|any|none|\d+|(\d+)%)\s+(.+)$/);if(d){let g=f(d[1]),{variable:A,set:E}=c(d[3]);return{type:"for",quantifier:g,variable:A,set:E,condition:Q(m,e)}}}}}}let o=n.match(/^not\s+([\s\S]+)$/);if(o)return{type:"not",operand:Q(o[1],e)};let u=n.match(/^defined\s+([\s\S]+)$/);if(u)return{type:"defined",operand:Q(u[1],e)};let a=n.match(/^(\$\w*|\w+)\s+at\s+(.+)$/);if(a){let _=a[1];if(_.startsWith("$"))return{type:"at",identifier:_,offset:S(a[2])};if(_.startsWith(Re))return{type:"at",identifier:S(_),offset:S(a[2])}}let l=n.match(/^(\$\w*)\s+in\s+\((.+)\.\.(.+)\)$/);if(l)return{type:"inRange",identifier:l[1],range:{type:"range",start:S(l[2]),end:S(l[3])}};let p=n.match(/^(\$\w*)\s+within\s+(.+?)(?:\s+bytes)?\s+of\s+(\$\w*)$/);if(p)return{type:"within",identifier:p[1],distance:S(p[2]),reference:p[3]};let h=[{pattern:"matches",type:"matches"},{pattern:"iequals",type:"iequals"},{pattern:"icontains",type:"icontains"},{pattern:"contains",type:"contains"},{pattern:"istartswith",type:"istartswith"},{pattern:"startswith",type:"startswith"},{pattern:"iendswith",type:"iendswith"},{pattern:"endswith",type:"endswith"}];for(let _ of h){let x=G(n,` ${_.pattern} `);if(x!==-1){let v=x;for(;v<n.length&&/\s/.test(n[v]);)v++;for(v+=_.pattern.length;v<n.length&&/\s/.test(n[v]);)v++;return{type:_.type,left:S(n.substring(0,x)),right:S(n.substring(v))}}}let w=[{pattern:"==",type:"equal"},{pattern:"!=",type:"notEqual"},{pattern:"<=",type:"lessThanOrEqual"},{pattern:">=",type:"greaterThanOrEqual"},{pattern:"<",type:"lessThan"},{pattern:">",type:"greaterThan"}];for(let _ of w){let x=G(n,_.pattern);if(x!==-1)return{type:_.type,left:S(n.substring(0,x)),right:S(n.substring(x+_.pattern.length))}}return S(n)}function S(n){if(n=n.trim(),n==="true")return{type:"boolean",value:!0};if(n==="false")return{type:"boolean",value:!1};let e=n.match(/^(\d+)(KB|MB|GB)$/i);if(e){let v=parseInt(e[1]),b=e[2].toUpperCase(),y={KB:1024,MB:1024*1024,GB:1024*1024*1024};return{type:"number",value:v*y[b]}}if(/^-?\d+\.\d+$/.test(n))return{type:"number",value:parseFloat(n)};if(/^-?\d+$/.test(n))return{type:"number",value:parseInt(n)};if(/^0x[0-9a-fA-F]+$/.test(n))return{type:"number",value:parseInt(n,16)};if(/^\$\w*$/.test(n))return{type:"stringIdentifier",identifier:n};let t=n.match(/^\$(\w*)\[([^\]]+)\]$/);if(t){let[,v,b]=t,y=b.trim();return{type:"stringOccurrence",identifier:`$${v}`,index:/^\d+$/.test(y)?parseInt(y):S(y)}}if(/^#\w*$/.test(n))return{type:"stringCount",identifier:n.replace("#","$")};if(/^@\w*$/.test(n))return{type:"stringOffset",identifier:n.replace("@","$"),index:0};let r=(v,b,y)=>{let m=new RegExp(`^\\${b}([\\w$]+)\\[([^\\]]+)\\]$`),f=v.match(m);if(!f)return null;let c=f[1],d=f[2].trim(),g=c.startsWith("$")?c:`$${c}`,A=/^\d+$/.test(d)?parseInt(d):S(d);return{type:y,identifier:g,index:A}},i=r(n,"@","stringOffset");if(i)return i;if(/^![\w$]*$/.test(n)){let v=n.slice(1);return{type:"stringLength",identifier:v?v.startsWith("$")?v:`$${v}`:"$",index:0}}let s=r(n,"!","stringLength");if(s)return s;if(n==="filesize")return{type:"identifier",name:"filesize"};if(n==="entrypoint")return{type:"identifier",name:"entrypoint"};for(let v of En){let b=new RegExp(`^${v.name}\\((.+)\\)$`),y=n.match(b);if(y)return{type:"dataAccess",dataType:v.name.replace("be",""),offset:S(y[1]),endian:v.endian}}let o=n.match(/^(\w+)\.(\w+)\((.*)\)$/);if(o){let[,v,b,y]=o,m=[];if(y.trim()){let f=0,c="";for(let d=0;d<y.length;d++){let g=y[d];g==="("&&f++,g===")"&&f--,g===","&&f===0?(m.push(S(c.trim())),c=""):c+=g}c.trim()&&m.push(S(c.trim()))}return{type:"moduleFunction",module:v,function:b,args:m}}let u=n.match(/^(\w+)\.(\w+)\[([^\]]+)\]\.?(\w*)$/);if(u){let[,v,b,y,m]=u,f={type:"arrayAccess",object:{type:"memberAccess",object:{type:"identifier",name:v},property:b},index:S(y.trim())};if(m){let c=m.split(".");for(let d of c)d&&(f={type:"memberAccess",object:f,property:d})}return f}let a=n.match(/^(\w+)\.(\w+)$/);if(a){let[,v,b]=a;return{type:"memberAccess",object:{type:"identifier",name:v},property:b}}if(n.startsWith("~")){let v=n.substring(1).trim(),b;if(v.startsWith("(")){let f=1;for(b=1;b<v.length&&f>0;)v[b]==="("&&f++,v[b]===")"&&f--,b++}else if(v.startsWith("~")){let f=0;for(;f<v.length&&v[f]==="~";)f++;let c=v.substring(f).trim(),d=0;if(c.startsWith("(")){let g=1;for(d=1;d<c.length&&g>0;)c[d]==="("&&g++,c[d]===")"&&g--,d++}else{let g=c.match(/^([a-zA-Z_$]\w*)\s*\(/);if(g){let A=1;for(d=g[0].length;d<c.length&&A>0;)c[d]==="("&&A++,c[d]===")"&&A--,d++}else{let A=c.match(/^(0x[0-9a-fA-F]+|\d+|[a-zA-Z_$]\w*)/);A&&(d=A[0].length)}}b=f+d}else{let f=v.match(/^([a-zA-Z_$]\w*)\s*\(/);if(f){let c=1;for(b=f[0].length;b<v.length&&c>0;)v[b]==="("&&c++,v[b]===")"&&c--,b++}else{let c=v.match(/^(0x[0-9a-fA-F]+|\d+|[a-zA-Z_$]\w*)/);if(c)b=c[0].length;else return{type:"bitwiseNot",operand:S(v)}}}let y=S(v.substring(0,b)),m=v.substring(b).trim();if(m){let f="("+n.substring(0,b+1)+")"+m;return S(f)}return{type:"bitwiseNot",operand:y}}let l=G(n,"|");if(l!==-1)return{type:"bitwiseOr",left:S(n.substring(0,l)),right:S(n.substring(l+1))};let p=G(n,"^");if(p!==-1)return{type:"bitwiseXor",left:S(n.substring(0,p)),right:S(n.substring(p+1))};let h=G(n,"&");if(h!==-1)return{type:"bitwiseAnd",left:S(n.substring(0,h)),right:S(n.substring(h+1))};let w=G(n,"<<");if(w!==-1)return{type:"shiftLeft",left:S(n.substring(0,w)),right:S(n.substring(w+2))};let _=G(n,">>");if(_!==-1)return{type:"shiftRight",left:S(n.substring(0,_)),right:S(n.substring(_+2))};let x=[{pattern:"+",type:"add"},{pattern:"-",type:"subtract"},{pattern:"*",type:"multiply"},{pattern:"\\",type:"divide"},{pattern:"%",type:"modulo"}];for(let v of x){let b=G(n,v.pattern);if(b!==-1)return{type:v.type,left:S(n.substring(0,b)),right:S(n.substring(b+v.pattern.length))}}if(n.startsWith("(")&&n.endsWith(")")){let v=0,b=!0;for(let y=0;y<n.length;y++)if(n[y]==="("&&v++,n[y]===")"&&v--,v===0&&y<n.length-1){b=!1;break}if(b)return S(n.slice(1,-1))}return/^[A-Z][a-zA-Z0-9_]*$/.test(n)?{type:"ruleIdentifier",name:n}:(/^#\w*\[[^\]]*\]$/.test(n)&&console.warn(`yaraConditionParser: "${n}" is not valid YARA - "#${n.slice(1).split("[")[0]}" is the total count and takes no index`),{type:"identifier",name:n})}function G(n,e){let t=e.trim(),r=/^[a-z]+$/.test(t),i=0,s=0;for(let o=0;o<n.length;o++)if(n[o]==="("&&i++,n[o]===")"&&i--,n[o]==="["&&s++,n[o]==="]"&&s--,i===0&&s===0){if(r){if(!(o===0||/\s/.test(n[o-1])))continue;let a=o;for(;a<n.length&&/\s/.test(n[a]);)a++;if(n.substring(a,a+t.length)===t){let l=a+t.length;if(l>=n.length||/\s/.test(n[l]))return o}}else if(n.substring(o,o+e.length)===e)return o}return-1}var _t=/^\s*(?:\s*(?:private|global)\s+)*rule\b/i,xt=/^\s*(?:\s*(?:private|global)\s+)*filter\s+rule\b/i,Pn=new Set(["pe","elf","math","hash","string","time"]),vt=["pe","elf","math","hash","time","string"];function At(n){let e=[],t=/^\s*import\s+"(\w+)"\s*$/gm,r;for(;(r=t.exec(n))!==null;){let i=r[1];if(!vt.includes(i))throw new Error(`Unsupported module import: "${i}". Supported modules are: ${vt.join(", ")}. Note: All supported modules are automatically available; the import statement is only for validation.`);e.push(i)}return e}function Hn(n,e){let t=e-1;for(;t>=0&&(n[t]===" "||n[t]===" ");)t--;if(t<0)return!1;if(n[t]==="=")return!0;let r=t;for(;r>=0&&/[A-Za-z_]/.test(n[r]);)r--;return n.slice(r+1,t+1)==="matches"}function Ln(n,e){for(let t=e+1;t<n.length;t++)if(n[t]==="\\")t+=1;else{if(n[t]==="/")return t;if(n[t]===`
|
|
11
|
+
`)return-1}return-1}function St(n){let e="",t=0,r=n.length;for(;t<r;)if(n[t]==='"'||n[t]==="'"){let i=n[t];for(e+=n[t++];t<r;)if(n[t]==="\\"&&t+1<r)e+=n[t++],e+=n[t++];else if(n[t]===i){e+=n[t++];break}else e+=n[t++]}else if(n[t]==="/"&&n[t+1]!=="/"&&n[t+1]!=="*"&&Hn(n,t)){let i=Ln(n,t);i<0?e+=n[t++]:(e+=n.slice(t,i+1),t=i+1)}else if(n[t]==="/"&&t+1<r&&n[t+1]==="/"){for(t+=2;t<r&&n[t]!==`
|
|
9
12
|
`;)t++;t<r&&n[t]===`
|
|
10
13
|
`&&(e+=n[t++])}else if(n[t]==="/"&&t+1<r&&n[t+1]==="*")for(t+=2;t<r-1;){if(n[t]==="*"&&n[t+1]==="/"){t+=2;break}n[t]===`
|
|
11
14
|
`&&(e+=`
|
|
12
|
-
`),t++}else e+=n[t++];return e}function
|
|
13
|
-
`);for(let
|
|
14
|
-
`;let
|
|
15
|
-
`;let a=We(u);i+=a.openCount-a.closeCount,i===0&&(t.push(Ve(r)),s=!1,r="")}return t.forEach((u,a)=>{u.id=a+1}),t}function Ve(n){n=Vt(n).trim();let e=/^.*\bprivate\b.*rule\s+/i.test(n),t=/^.*\bglobal\b.*rule\s+/i.test(n),r=n.match(/^(?:.*)?rule\s+(\w+)(?:\s*:\s*([\w\s]+))?\s*\{/);if(!r)throw new Error("Invalid YARA rule: missing rule declaration");let i=r[1],s=r[2]?r[2].trim().split(/\s+/):[],o=n.match(/\{([\s\S]*)\}/);if(!o)throw new Error("Invalid YARA rule: missing rule body");let u=o[1],a=qt(u),p=kt(u),d=Gt(u);return{name:i,tags:s,metadata:a,strings:p,condition:d,private:e,global:t}}function qt(n){let e=n.match(/meta:\s*([\s\S]*?)(?=strings:|condition:|$)/);if(!e)return{};let t=e[1],r={},i=t.match(/(\w+)\s*=\s*("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|(-)?\d+(\.\d+)?|true|false)/g);if(i)for(let s of i){let[,o,u]=s.match(/(\w+)\s*=\s*(.+)/);u.startsWith('"')||u.startsWith("'")?r[o]=u.slice(1,-1):u==="true"||u==="false"?r[o]=u==="true":isNaN(u)?r[o]=u:r[o]=Number(u)}return r}function kt(n){let e=n.match(/strings:\s*([\s\S]*?)(?=condition:|$)/);if(!e)return{};let t=e[1],r={},i=t.match(/\$\w*\s*=\s*(.*)?/g);if(i){let s=0;for(let o of i){let u=o.match(/\$(\w*)\s*=\s*(.+)/);if(!u)continue;let[,a,p]=u;!a||a===""?a=`.anon_${s++}`:a.startsWith("$")||(a="$"+a);try{let d=He(p.trim());r[a]={definition:p.trim(),...d}}catch(d){console.warn(`Warning: Failed to compile string $${a}: ${d.message}`),console.warn(`Definition: ${p.trim()}`),console.warn(o),console.warn(e),console.warn(n),r[a]={definition:p.trim(),type:null,matcher:null,error:d.message}}}}return r}function Gt(n){let e=n.match(/condition:\s*([\s\S]*?)$/);if(!e)throw new Error("Invalid YARA rule: missing condition");return e[1].trim().replace(/\}\s*$/,"").trim()}function Ge(n,e={},t={},r={}){let i={};for(let[s,o]of Object.entries(e))Array.isArray(o)?i[s]={identifier:s,matched:o.length>0,count:o.length,matches:o,offsets:o.map(u=>u.offset)}:typeof o=="object"&&o!==null&&(i[s]={identifier:s,matched:o.matched??o.count>0,count:o.count??0,matches:o.matches??[],offsets:o.offsets??(o.matches||[]).map(u=>u.offset),...o});return{data:n,filesize:n.length,entrypoint:r.entrypoint??0,isFileSizeCapped:r.isFileSizeCapped??!1,maxFileSize:r.maxFileSize??1024*1024,strings:i,modules:t||{},matchedRules:r.matchedRules||{},metadata:r.metadata||{}}}var ke=new WeakMap;function Xt(n){if(n.error)throw new Error(`Invalid regex literal /${n.pattern}/${n.flags??""} - ${n.error}`);let e=ke.get(n);return e||(e=new RegExp(n.pattern,(n.flags??"").replace(/[gy]/g,"")),ke.set(n,e)),e}var ge=class{constructor(e){this.facts=e,this.data=e.data,this.filesize=e.filesize,this.entrypoint=e.entrypoint,this.isFileSizeCapped=e.isFileSizeCapped??!1,this.maxFileSize=e.maxFileSize??1024*1024,this.strings=e.strings,this.modules=e.modules,this.matchedRules=e.matchedRules||{}}isAnyUndefined(...e){return e.some(t=>t===void 0)}async evaluate(e){return typeof e=="string"&&(e=this.parseCondition(e)),await this.evaluateNode(e)}parseCondition(){throw new Error("String parsing not implemented - pass AST directly")}async evaluateNode(e){if(e==null)return!1;let t=e.type;switch(t){case"boolean":return e.value;case"number":return e.value;case"string":return e.value;case"regex":return Xt(e);case"identifier":return this.resolveIdentifier(e.name);case"ruleIdentifier":return this.evaluateRuleIdentifier(e);case"stringIdentifier":return this.evaluateStringIdentifier(e);case"stringCount":return this.getStringCount(e.identifier);case"stringOffset":{let r=e.index;return typeof r=="object"&&(r=await this.evaluateNode(r)),this.getStringOffset(e.identifier,r)}case"stringLength":{let r=e.index;return typeof r=="object"&&(r=await this.evaluateNode(r)),this.getStringLength(e.identifier,r)}case"stringOccurrence":{let r=e.index;typeof r=="object"&&r!==null&&(r=await this.evaluateNode(r));let i=this.getStringOffset(e.identifier,r),s=this.getStringLength(e.identifier,r);return i===void 0||s===void 0||!this.data||typeof this.data.subarray!="function"?void 0:new TextDecoder().decode(this.data.subarray(i,i+s))}case"and":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return!(r===void 0||r===!1||i===void 0||i===!1)}case"or":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return(r===void 0?!1:r)||(i===void 0?!1:i)}case"not":{let r=await this.evaluateNode(e.operand);return this.isAnyUndefined(r)?void 0:!r}case"defined":return await this.evaluateDefined(e.operand);case"equal":return await this.evaluateEqual(e);case"notEqual":return await this.evaluateNotEqual(e);case"lessThan":return await this.evaluateLessThan(e);case"greaterThan":return await this.evaluateGreaterThan(e);case"lessThanOrEqual":return await this.evaluateLessThanOrEqual(e);case"greaterThanOrEqual":return await this.evaluateGreaterThanOrEqual(e);case"add":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r+i}case"subtract":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r-i}case"multiply":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r*i}case"divide":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:Math.floor(r/i)}case"modulo":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r%i}case"bitwiseAnd":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r&i}case"bitwiseOr":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r|i}case"bitwiseXor":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r^i}case"bitwiseNot":{let r=await this.evaluateNode(e.operand);return this.isAnyUndefined(r)?void 0:~r}case"shiftLeft":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r<<i}case"shiftRight":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r>>i}case"contains":return await this.stringContains(e.left,e.right,!1);case"icontains":return await this.stringContains(e.left,e.right,!0);case"startswith":return await this.stringStartsWith(e.left,e.right,!1);case"istartswith":return await this.stringStartsWith(e.left,e.right,!0);case"endswith":return await this.stringEndsWith(e.left,e.right,!1);case"iendswith":return await this.stringEndsWith(e.left,e.right,!0);case"iequals":return await this.stringEquals(e.left,e.right,!0);case"matches":if(e.error)throw new Error(`Invalid "matches" comparison - ${e.error}`);return await this.stringMatches(e.left,e.right);case"in":return await this.evaluateInOperator(e);case"range":return{start:await this.evaluateNode(e.start),end:await this.evaluateNode(e.end)};case"all":return await this.evaluateAll(e.items);case"any":return await this.evaluateAny(e.items);case"none":return await this.evaluateNone(e.items);case"quantified":return await this.evaluateQuantified(e);case"for":return await this.evaluateFor(e);case"memberAccess":return await this.evaluateMemberAccess(e);case"arrayAccess":return await this.evaluateArrayAccess(e);case"functionCall":return await this.evaluateFunctionCall(e);case"dataAccess":return this.evaluateDataAccess(e);case"at":return await this.evaluateAt(e);case"inRange":return await this.evaluateInRange(e);case"within":return await this.evaluateWithin(e);case"moduleFunction":return await this.evaluateModuleFunction(e);default:throw new Error(`Unknown node type: ${t}`)}}resolveIdentifier(e){if(this.forContext&&e in this.forContext)return this.forContext[e];let t=e?.split(".");switch(e=t[0],e){case"filesize":return this.filesize;case"entrypoint":if(typeof this.entrypoint!="number")throw new Error("Entrypoint is not defined");return this.entrypoint;default:if(this.modules&&e in this.modules){if(!this.modules[e])return this.modules[e];let r=this.modules;for(let i of t)if(r=r[i],!r)return r;return r}if(["pe","elf","hash","math","string","time"].includes(e))return;throw new Error(`Unknown identifier: ${e}`)}}isFilesizeNode(e){return e&&e.type==="identifier"&&e.name==="filesize"}async evaluateEqual(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return this.isFilesizeNode(e.left)&&this.isFileSizeCapped&&r>=this.maxFileSize||this.isFilesizeNode(e.right)&&this.isFileSizeCapped&&t>=this.maxFileSize?!0:t===r}async evaluateNotEqual(e){let t=await this.evaluateEqual(e);if(!this.isAnyUndefined(t))return!t}async evaluateLessThan(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return t<r}async evaluateGreaterThan(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return this.isFilesizeNode(e.left)&&this.isFileSizeCapped&&r>=this.maxFileSize?!0:t>r}async evaluateLessThanOrEqual(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return t<=r}async evaluateGreaterThanOrEqual(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return this.isFilesizeNode(e.left)&&this.isFileSizeCapped&&r>=this.maxFileSize?!0:t>=r}evaluateStringIdentifier(e){let t=e.identifier;t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$);let r=this.strings[t];return r?r.matched&&r.count>0:!1}evaluateRuleIdentifier(e){let t=e.name;return t in this.matchedRules?this.matchedRules[t]===!0:!1}getStringCount(e){e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$);let t=this.strings[e];return t?t.count:0}getStringOffset(e,t=0){e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$),typeof t=="string"&&this.forContext&&t in this.forContext&&(t=this.forContext[t]);let r=this.strings[e];if(!r||!r.offsets||r.offsets.length===0)return;let i=t===0?0:t-1;return r.offsets[i]}getStringLength(e,t=0){e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$),typeof t=="string"&&this.forContext&&t in this.forContext&&(t=this.forContext[t]);let r=this.strings[e];if(!r||!r.matches||r.matches.length===0)return;let i=t===0?0:t-1,s=r.matches[i];return s?s.length:void 0}evaluateAll(e){let t=this.resolveStringSet(e);return t.length===0?!1:t.every(r=>{let i=this.strings[r];return i&&i.matched&&i.count>0})}evaluateAny(e){let t=this.resolveStringSet(e);return t.length===0?!1:t.some(r=>{let i=this.strings[r];return i&&i.matched&&i.count>0})}evaluateNone(e){let t=this.resolveStringSet(e);return t.length===0?!0:t.every(r=>{let i=this.strings[r];return!i||!i.matched||i.count===0})}evaluateQuantified(e){let t=this.resolveStringSet(e.items);if(t.length===0)return!1;let r=t.filter(s=>{let o=this.strings[s];return o&&o.matched&&o.count>0}).length,i=e.quantifier;if(i.type==="number")return r>=i.value;if(i.type==="percentage"){let s=Math.ceil(t.length*i.value/100);return r>=s}else if(i.type==="range"){let s=i.min,o=i.max;return r>=s&&r<=o}return!1}resolveStringSet(e){if(e==="them")return Object.keys(this.strings);if(Array.isArray(e)){let t=[];for(let r of e)if(r.includes("*")){let i=r.replace(/\*/g,".*").replace(/\$/g,"\\$"),s=new RegExp("^"+i+"$"),o=Object.keys(this.strings).filter(u=>s.test(u));t.push(...o)}else t.push(r);return t}if(typeof e=="string"){if(e.includes("*")){let t=e.replace(/\*/g,".*").replace(/\$/g,"\\$"),r=new RegExp("^"+t+"$");return Object.keys(this.strings).filter(i=>r.test(i))}return[e]}return[]}async evaluateFor(e){let t=e.quantifier,r=e.variable,i=e.set,s=e.condition,o=[];if(i.type==="stringSet"){if(o=this.resolveStringSet(i.items),o.length===0)return t==="all"}else if(i.type==="range"){let d=await this.evaluateNode(i.start),m=await this.evaluateNode(i.end);if(typeof d!="number"||typeof m!="number")throw new Error(`Invalid range values: ${d} to ${m}`);for(let b=d;b<=m;b++)o.push(b);if(o.length===0)return t==="all"}else{let d=await this.evaluateNode(i);Array.isArray(d)?o=d:o=[d]}if(o.length===0)return t==="all";let u=this.forContext||{},a=[];for(let d of o){this.forContext={...u,[r]:d};try{let m=await this.evaluateNode(s);a.push(!!m)}catch(m){console.warn(`For loop condition evaluation failed for item ${d}:`,m.message),a.push(!1)}}this.forContext=u;let p=a.filter(d=>d).length;if(t==="any")return p>0;if(t==="all")return p===o.length;if(t==="none")return p===0;if(typeof t=="number")return p>=t;if(t&&t.type==="percentage"){let d=Math.ceil(o.length*t.value/100);return p>=d}else if(t&&t.type==="number")return p>=t.value;return!1}async evaluateMemberAccess(e){let t=await this.evaluateNode(e.object),r=e.property;if(t!=null){if(typeof r=="string")return t[r];{let i=await this.evaluateNode(r);return t[i]}}}async evaluateArrayAccess(e){let t=await this.evaluateNode(e.object),r=await this.evaluateNode(e.index);if(t==null||!Array.isArray(t))return;let i=r<0?t.length+r:r;if(!(i<0||i>=t.length))return t[i]}async evaluateFunctionCall(e){let t=await this.evaluateNode(e.function),r=await Promise.all(e.arguments.map(s=>this.evaluateNode(s)));if(typeof t!="function")throw new Error(`Not a function: ${e.function}`);let i=t(...r);return i instanceof Promise?await i:i}async evaluateDataAccess(e){let t=await this.evaluateNode(e.offset),r=e.dataType,i=e.endian||"little";if(t<0||t>=this.data.length)return;let s=new DataView(this.data.buffer,this.data.byteOffset,this.data.byteLength),o=i==="little";try{switch(r){case"uint8":return s.getUint8(t);case"uint16":return s.getUint16(t,o);case"uint32":return s.getUint32(t,o);case"int8":return s.getInt8(t);case"int16":return s.getInt16(t,o);case"int32":return s.getInt32(t,o);default:throw new Error(`Unknown data type: ${r}`)}}catch{return}}async evaluateDefined(e){try{let t=await this.evaluateNode(e);return t!=null}catch{return!1}}async evaluateAt(e){let t=e.identifier;if(typeof t=="object"&&t.type==="string"){let s=await this.evaluateNode(e.offset),o=t.value,u=new TextEncoder().encode(o);if(s<0||s+u.length>this.data.length)return!1;for(let a=0;a<u.length;a++)if(this.data[s+a]!==u[a])return!1;return!0}t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$);let r=await this.evaluateNode(e.offset),i=this.strings[t];return!i||!i.offsets?!1:i.offsets.includes(r)}async evaluateInRange(e){let t=e.identifier;t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$);let r=await this.evaluateNode(e.range),i=this.strings[t];return!i||!i.offsets?!1:i.offsets.some(s=>s>=r.start&&s<=r.end)}async evaluateWithin(e){let t=e.identifier,r=e.reference;t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$),r==="$"&&this.forContext&&this.forContext.$&&(r=this.forContext.$);let i=await this.evaluateNode(e.distance),s=this.strings[t],o=this.strings[r];if(!s||!s.offsets||s.offsets.length===0||!o||!o.offsets||o.offsets.length===0)return!1;for(let u of s.offsets)for(let a of o.offsets)if(Math.abs(u-a)<=i)return!0;return!1}async evaluateModuleFunction(e){let{module:t,function:r,args:i}=e,s=this.modules[t];if(!s)return;let o=s[r];if(typeof o!="function")return;let u=await Promise.all(i.map(async a=>{let p=await this.evaluateNode(a);if(a.type==="stringIdentifier"){let d=this.strings[a.identifier];if(d&&d.matches&&d.matches.length>0){let m=d.matches[0];if(m.value)return m.value;if(this.data&&m.offset!==void 0&&m.length!==void 0){let b=this.data.slice(m.offset,m.offset+m.length);return new TextDecoder().decode(b)}}return""}return p}));try{let a=o.apply(s,u);return a instanceof Promise?await a:a}catch(a){throw new Error(`Error calling ${t}.${r}: ${a.message}`,{cause:a})}}async evaluateInOperator(e){let t=await this.evaluateNode(e.value),r=await this.evaluateNode(e.set);if(!this.isAnyUndefined(t,r))return Array.isArray(r)?r.includes(t):r&&typeof r=="object"&&r.start!==void 0&&r.end!==void 0?t>=r.start&&t<=r.end:!1}async stringContains(e,t,r=!1){let i=await this.evaluateNode(e),s=await this.evaluateNode(t);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(r&&(i=i.toLowerCase(),s=s.toLowerCase()),i.includes(s))}async stringStartsWith(e,t,r=!1){let i=await this.evaluateNode(e),s=await this.evaluateNode(t);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(r&&(i=i.toLowerCase(),s=s.toLowerCase()),i.startsWith(s))}async stringEndsWith(e,t,r=!1){let i=await this.evaluateNode(e),s=await this.evaluateNode(t);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(r&&(i=i.toLowerCase(),s=s.toLowerCase()),i.endsWith(s))}async stringEquals(e,t,r=!1){let i=await this.evaluateNode(e),s=await this.evaluateNode(t);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(r&&(i=i.toLowerCase(),s=s.toLowerCase()),i===s)}async stringMatches(e,t){let r=await this.evaluateNode(e),i=await this.evaluateNode(t);if(!this.isAnyUndefined(r,i)){if(!(i instanceof RegExp))throw new Error(`"matches" requires a regex literal as its right operand, got ${typeof i}`);return typeof r!="string"?!1:i.test(r)}}};async function Xe(n,e){return new ge(e).evaluate(n)}var me="__LITERAL_",Qe="__REGEX_";var Yt=[{name:"uint8",bits:8,signed:!1,endian:"little"},{name:"uint16",bits:16,signed:!1,endian:"little"},{name:"uint32",bits:32,signed:!1,endian:"little"},{name:"int8",bits:8,signed:!0,endian:"little"},{name:"int16",bits:16,signed:!0,endian:"little"},{name:"int32",bits:32,signed:!0,endian:"little"},{name:"uint16be",bits:16,signed:!1,endian:"big"},{name:"uint32be",bits:32,signed:!1,endian:"big"},{name:"int16be",bits:16,signed:!0,endian:"big"},{name:"int32be",bits:32,signed:!0,endian:"big"}];function Ye(n,e){let t=e;for(;t<n.length&&/\s/.test(n[t]);)t++;return t}function Kt(n){if(!n.startsWith("(")||!n.endsWith(")"))return!1;let e=0;for(let t=0;t<n.length;t++)if(n[t]==="("&&e++,n[t]===")"&&e--,e===0&&t<n.length-1)return!1;return!0}function Zt(n,e,t){let r=!1;for(let i=e+1;i<n.length;i++){let s=n[i];if(r){r=!1;continue}if(s==="\\"){r=!0;continue}if(s===t)return i}return-1}function Qt(n,e){let t="",r=!1,i=!1;for(let s=e+1;s<n.length;s++){let o=n[s];if(i){t+=o,i=!1;continue}if(o==="\\"){t+=o,i=!0;continue}if(o===`
|
|
16
|
-
`)
|
|
17
|
-
`,e+2);return r===-1?n.length:r}let t=n.indexOf("*/",e+2);return t===-1?n.length:t+2}function rr(n){let e=[],t=[],r=0,i=0,s=!1,o=0,u=0,a=p=>{t.push(n.slice(o,p)),o=p};for(;u<n.length;){let p=n[u];if(p==='"'||p==="'"){let d=Zt(n,u,p);if(d!==-1){let m=`${me}${r}__`;e.push({id:m,type:"string",value:n.slice(u+1,d)}),r+=1,a(u),t.push(m),u=d+1,o=u;continue}u+=1;continue}if(p==="/"){let d=n[u+1];if(d==="/"||d==="*"){u=tr(n,u);continue}let m=Qt(n,u);if(m){let b=`${Qe}${i}__`,_=er(m.pattern,m.flags);_&&console.warn(`yaraConditionParser: invalid regex literal /${m.pattern}/${m.flags} - ${_}`),e.push({id:b,type:"regex",pattern:m.pattern,flags:m.flags,error:_}),i+=1,a(u),t.push(b),u=m.end,o=u;continue}s||(s=!0,console.warn(`yaraConditionParser: "/" does not start a regex literal in condition "${n.slice(0,80)}" - integer division is "\\"`)),u+=1;continue}u+=1}return a(n.length),{processed:t.join(""),literals:e}}function Ke(n){return typeof n=="string"&&(n.startsWith(me)||n.startsWith(Qe))}function Ze(n){let e={type:"regex",pattern:n.pattern,flags:n.flags??""};return n.error&&(e.error=n.error),e}function nr(n){return!n||typeof n!="object"?typeof n:n.type==="string"?`string literal "${n.value}"`:n.type==="identifier"?`"${n.name}"`:n.type==="memberAccess"?"a module/property value":n.type==="functionCall"?"a function call":n.type==="number"||n.type==="boolean"?`${n.type} ${n.value}`:`a "${n.type}" expression`}function de(n,e,t=""){if(!n||typeof n!="object")return n;if(n.type==="identifier"&&n.name&&Ke(n.name)){let i=e.find(s=>s.id===n.name);if(i)return i.type==="regex"?Ze(i):{type:"string",value:i.value}}let r={...n};for(let i in r)Object.prototype.hasOwnProperty.call(r,i)&&(Array.isArray(r[i])?r[i]=r[i].map(s=>{if(typeof s=="string"&&Ke(s)){let o=e.find(u=>u.id===s);return o?o.type==="regex"?Ze(o):o.value:s}return typeof s=="object"?de(s,e,t):s}):typeof r[i]=="object"&&(r[i]=de(r[i],e,t)));return r.type==="matches"&&r.right?.type!=="regex"&&(r.error=`right operand of "matches" must be a regex literal, got ${nr(r.right)}`,console.warn(`yaraConditionParser: invalid "matches" in condition "${t.slice(0,80)}" - ${r.error}`)),r}function Je(n,e={}){n=n.trim();let{processed:t,literals:r}=rr(n),i=q(t,e);return de(i,r,n)}function ir(n){let e=/^(any|all|none|\d+|\d+%|\d+\.\.\d+)\s+of\s+(them|\([^)]+\))$/,t=n.match(e);if(!t)return null;let[,r,i]=t,s,o;if(r==="any")o="any";else if(r==="all")o="all";else if(r==="none")o="none";else if(r.includes("..")){let[a,p]=r.split("..").map(d=>parseInt(d));o="quantified",s={type:"range",min:a,max:p}}else r.endsWith("%")?(o="quantified",s={type:"percentage",value:parseInt(r)}):(o="quantified",s={type:"number",value:parseInt(r)});let u;return i==="them"?u="them":u=i.slice(1,-1).split(",").map(p=>p.trim()),{type:o,...s&&{quantifier:s},items:u}}function q(n,e={}){for(n=n.trim();Kt(n);)n=n.slice(1,-1).trim();let t=ir(n);if(t)return t;let r=(_,U)=>{let v=L(n,` ${_} `);if(v===-1)return null;let w=Ye(n,v);return w+=U,w=Ye(n,w),{type:_,left:q(n.substring(0,v),e),right:q(n.substring(w),e)}},i=r("or",2);if(i)return i;let s=r("and",3);if(s)return s;if(n.trim().startsWith("for ")){let _=n.indexOf(":");if(_!==-1){let U=_+1;for(;U<n.length&&n[U]!=="(";)U++;if(U<n.length){let v=1,w=U+1;for(;w<n.length&&v>0;)n[w]==="("&&v++,n[w]===")"&&v--,w++;if(v===0){let y=n.substring(0,_).trim(),g=n.substring(U+1,w-1).trim(),f=h=>["all","any","none"].includes(h)?h:h.endsWith("%")?{type:"percentage",value:parseInt(h)}:{type:"number",value:parseInt(h)},l=h=>{let x=h.match(/^(\w+)\s+in\s+\((.+?)\.\.(.+?)\)$/);if(x)return{variable:x[1],set:{type:"range",start:A(x[2].trim()),end:A(x[3].trim())}};let S=h.match(/^of\s+(.+)$/);if(S){let I=S[1].trim(),V;return I==="them"?V="them":I.startsWith("(")&&I.endsWith(")")?V=I.slice(1,-1).split(",").map(At=>At.trim()):V=I,{variable:"$",set:{type:"stringSet",items:V}}}return{variable:null,set:null}},c=y.match(/^for\s+(all|any|none|\d+|(\d+)%)\s+(.+)$/);if(c){let h=f(c[1]),{variable:x,set:S}=l(c[3]);return{type:"for",quantifier:h,variable:x,set:S,condition:q(g,e)}}}}}}let o=n.match(/^not\s+([\s\S]+)$/);if(o)return{type:"not",operand:q(o[1],e)};let u=n.match(/^defined\s+([\s\S]+)$/);if(u)return{type:"defined",operand:q(u[1],e)};let a=n.match(/^(\$\w*|\w+)\s+at\s+(.+)$/);if(a){let _=a[1];if(_.startsWith("$"))return{type:"at",identifier:_,offset:A(a[2])};if(_.startsWith(me))return{type:"at",identifier:A(_),offset:A(a[2])}}let p=n.match(/^(\$\w*)\s+in\s+\((.+)\.\.(.+)\)$/);if(p)return{type:"inRange",identifier:p[1],range:{type:"range",start:A(p[2]),end:A(p[3])}};let d=n.match(/^(\$\w*)\s+within\s+(.+?)(?:\s+bytes)?\s+of\s+(\$\w*)$/);if(d)return{type:"within",identifier:d[1],distance:A(d[2]),reference:d[3]};let m=[{pattern:"matches",type:"matches"},{pattern:"iequals",type:"iequals"},{pattern:"icontains",type:"icontains"},{pattern:"contains",type:"contains"},{pattern:"istartswith",type:"istartswith"},{pattern:"startswith",type:"startswith"},{pattern:"iendswith",type:"iendswith"},{pattern:"endswith",type:"endswith"}];for(let _ of m){let U=L(n,` ${_.pattern} `);if(U!==-1){let v=U;for(;v<n.length&&/\s/.test(n[v]);)v++;for(v+=_.pattern.length;v<n.length&&/\s/.test(n[v]);)v++;return{type:_.type,left:A(n.substring(0,U)),right:A(n.substring(v))}}}let b=[{pattern:"==",type:"equal"},{pattern:"!=",type:"notEqual"},{pattern:"<=",type:"lessThanOrEqual"},{pattern:">=",type:"greaterThanOrEqual"},{pattern:"<",type:"lessThan"},{pattern:">",type:"greaterThan"}];for(let _ of b){let U=L(n,_.pattern);if(U!==-1)return{type:_.type,left:A(n.substring(0,U)),right:A(n.substring(U+_.pattern.length))}}return A(n)}function A(n){if(n=n.trim(),n==="true")return{type:"boolean",value:!0};if(n==="false")return{type:"boolean",value:!1};let e=n.match(/^(\d+)(KB|MB|GB)$/i);if(e){let v=parseInt(e[1]),w=e[2].toUpperCase(),y={KB:1024,MB:1024*1024,GB:1024*1024*1024};return{type:"number",value:v*y[w]}}if(/^-?\d+\.\d+$/.test(n))return{type:"number",value:parseFloat(n)};if(/^-?\d+$/.test(n))return{type:"number",value:parseInt(n)};if(/^0x[0-9a-fA-F]+$/.test(n))return{type:"number",value:parseInt(n,16)};if(/^\$\w*$/.test(n))return{type:"stringIdentifier",identifier:n};let t=n.match(/^\$(\w*)\[([^\]]+)\]$/);if(t){let[,v,w]=t,y=w.trim();return{type:"stringOccurrence",identifier:`$${v}`,index:/^\d+$/.test(y)?parseInt(y):A(y)}}if(/^#\w*$/.test(n))return{type:"stringCount",identifier:n.replace("#","$")};if(/^@\w*$/.test(n))return{type:"stringOffset",identifier:n.replace("@","$"),index:0};let r=(v,w,y)=>{let g=new RegExp(`^\\${w}([\\w$]+)\\[([^\\]]+)\\]$`),f=v.match(g);if(!f)return null;let l=f[1],c=f[2].trim(),h=l.startsWith("$")?l:`$${l}`,x=/^\d+$/.test(c)?parseInt(c):A(c);return{type:y,identifier:h,index:x}},i=r(n,"@","stringOffset");if(i)return i;if(/^![\w$]*$/.test(n)){let v=n.slice(1);return{type:"stringLength",identifier:v?v.startsWith("$")?v:`$${v}`:"$",index:0}}let s=r(n,"!","stringLength");if(s)return s;if(n==="filesize")return{type:"identifier",name:"filesize"};if(n==="entrypoint")return{type:"identifier",name:"entrypoint"};for(let v of Yt){let w=new RegExp(`^${v.name}\\((.+)\\)$`),y=n.match(w);if(y)return{type:"dataAccess",dataType:v.name.replace("be",""),offset:A(y[1]),endian:v.endian}}let o=n.match(/^(\w+)\.(\w+)\((.*)\)$/);if(o){let[,v,w,y]=o,g=[];if(y.trim()){let f=0,l="";for(let c=0;c<y.length;c++){let h=y[c];h==="("&&f++,h===")"&&f--,h===","&&f===0?(g.push(A(l.trim())),l=""):l+=h}l.trim()&&g.push(A(l.trim()))}return{type:"moduleFunction",module:v,function:w,args:g}}let u=n.match(/^(\w+)\.(\w+)\[([^\]]+)\]\.?(\w*)$/);if(u){let[,v,w,y,g]=u,f={type:"arrayAccess",object:{type:"memberAccess",object:{type:"identifier",name:v},property:w},index:A(y.trim())};if(g){let l=g.split(".");for(let c of l)c&&(f={type:"memberAccess",object:f,property:c})}return f}let a=n.match(/^(\w+)\.(\w+)$/);if(a){let[,v,w]=a;return{type:"memberAccess",object:{type:"identifier",name:v},property:w}}if(n.startsWith("~")){let v=n.substring(1).trim(),w;if(v.startsWith("(")){let f=1;for(w=1;w<v.length&&f>0;)v[w]==="("&&f++,v[w]===")"&&f--,w++}else if(v.startsWith("~")){let f=0;for(;f<v.length&&v[f]==="~";)f++;let l=v.substring(f).trim(),c=0;if(l.startsWith("(")){let h=1;for(c=1;c<l.length&&h>0;)l[c]==="("&&h++,l[c]===")"&&h--,c++}else{let h=l.match(/^([a-zA-Z_$]\w*)\s*\(/);if(h){let x=1;for(c=h[0].length;c<l.length&&x>0;)l[c]==="("&&x++,l[c]===")"&&x--,c++}else{let x=l.match(/^(0x[0-9a-fA-F]+|\d+|[a-zA-Z_$]\w*)/);x&&(c=x[0].length)}}w=f+c}else{let f=v.match(/^([a-zA-Z_$]\w*)\s*\(/);if(f){let l=1;for(w=f[0].length;w<v.length&&l>0;)v[w]==="("&&l++,v[w]===")"&&l--,w++}else{let l=v.match(/^(0x[0-9a-fA-F]+|\d+|[a-zA-Z_$]\w*)/);if(l)w=l[0].length;else return{type:"bitwiseNot",operand:A(v)}}}let y=A(v.substring(0,w)),g=v.substring(w).trim();if(g){let f="("+n.substring(0,w+1)+")"+g;return A(f)}return{type:"bitwiseNot",operand:y}}let p=L(n,"|");if(p!==-1)return{type:"bitwiseOr",left:A(n.substring(0,p)),right:A(n.substring(p+1))};let d=L(n,"^");if(d!==-1)return{type:"bitwiseXor",left:A(n.substring(0,d)),right:A(n.substring(d+1))};let m=L(n,"&");if(m!==-1)return{type:"bitwiseAnd",left:A(n.substring(0,m)),right:A(n.substring(m+1))};let b=L(n,"<<");if(b!==-1)return{type:"shiftLeft",left:A(n.substring(0,b)),right:A(n.substring(b+2))};let _=L(n,">>");if(_!==-1)return{type:"shiftRight",left:A(n.substring(0,_)),right:A(n.substring(_+2))};let U=[{pattern:"+",type:"add"},{pattern:"-",type:"subtract"},{pattern:"*",type:"multiply"},{pattern:"\\",type:"divide"},{pattern:"%",type:"modulo"}];for(let v of U){let w=L(n,v.pattern);if(w!==-1)return{type:v.type,left:A(n.substring(0,w)),right:A(n.substring(w+v.pattern.length))}}if(n.startsWith("(")&&n.endsWith(")")){let v=0,w=!0;for(let y=0;y<n.length;y++)if(n[y]==="("&&v++,n[y]===")"&&v--,v===0&&y<n.length-1){w=!1;break}if(w)return A(n.slice(1,-1))}return/^[A-Z][a-zA-Z0-9_]*$/.test(n)?{type:"ruleIdentifier",name:n}:(/^#\w*\[[^\]]*\]$/.test(n)&&console.warn(`yaraConditionParser: "${n}" is not valid YARA - "#${n.slice(1).split("[")[0]}" is the total count and takes no index`),{type:"identifier",name:n})}function L(n,e){let t=e.trim(),r=/^[a-z]+$/.test(t),i=0,s=0;for(let o=0;o<n.length;o++)if(n[o]==="("&&i++,n[o]===")"&&i--,n[o]==="["&&s++,n[o]==="]"&&s--,i===0&&s===0){if(r){if(!(o===0||/\s/.test(n[o-1])))continue;let a=o;for(;a<n.length&&/\s/.test(n[a]);)a++;if(n.substring(a,a+t.length)===t){let p=a+t.length;if(p>=n.length||/\s/.test(n[p]))return o}}else if(n.substring(o,o+e.length)===e)return o}return-1}var fe={};zt(fe,{ArrayFormatBase:()=>k,FormatBase:()=>z,ImageDataDirectoryArray:()=>R,ImageDirectoryEntry:()=>M,ImageDosHeader:()=>C,ImageFileHeader:()=>T,ImageNtHeaders:()=>W,ImageOptionalHeader:()=>j,ImageOptionalHeader64:()=>$,ImageSectionHeaderArray:()=>F,findImageSectionBlockByDirectoryEntry:()=>Or,getImageDosHeader:()=>Ur,getImageNtHeadersByDosHeader:()=>Ar,getImageSectionHeadersByNtHeaders:()=>xr});var sr=(function(){function n(e){this.view=e}return n.prototype.copyTo=function(e,t){new Uint8Array(e,t,this.view.byteLength).set(new Uint8Array(this.view.buffer,this.view.byteOffset,this.view.byteLength))},Object.defineProperty(n.prototype,"byteLength",{get:function(){return this.view.byteLength},enumerable:!1,configurable:!0}),n})(),z=sr;var or=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),ye=(function(n){or(e,n);function e(t){return n.call(this,t)||this}return e.prototype.forEach=function(t){var r=this.length,i=[];i.length=r;for(var s=0;s<r;++s)i[s]=this.get(s);for(var s=0;s<r;++s)t(i[s],s,this)},e.prototype._iterator=function(){return new((function(){function t(r){this.base=r,this.i=0}return t.prototype.next=function(){return this.i===this.base.length?{value:void 0,done:!0}:{value:this.base.get(this.i++),done:!1}},t})())(this)},e})(z);typeof Symbol<"u"&&(ye.prototype[Symbol.iterator]=ye.prototype._iterator);var k=ye;var ar=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),ur=(function(n){ar(e,n);function e(t){var r=n.call(this,t)||this;return r.length=16,r}return e.from=function(t,r){return r===void 0&&(r=0),new e(new DataView(t,r,128))},e.prototype.get=function(t){return{virtualAddress:this.view.getUint32(t*8,!0),size:this.view.getUint32(4+t*8,!0)}},e.prototype.set=function(t,r){this.view.setUint32(t*8,r.virtualAddress,!0),this.view.setUint32(4+t*8,r.size,!0)},e.prototype.findIndexByVirtualAddress=function(t){for(var r=0;r<16;++r){var i=this.view.getUint32(r*8,!0),s=this.view.getUint32(4+r*8,!0);if(t>=i&&t<i+s)return r}return null},e.size=128,e.itemSize=8,e})(k),R=ur;var fr={Export:0,Import:1,Resource:2,Exception:3,Certificate:4,Security:4,BaseRelocation:5,Debug:6,Architecture:7,GlobalPointer:8,Tls:9,TLS:9,LoadConfig:10,BoundImport:11,Iat:12,IAT:12,DelayImport:13,ComDescriptor:14,COMDescriptor:14},M=fr;function K(n){var e={};return Object.keys(n).forEach(function(t){e[t]=n[t]}),e}function Z(n,e,t){if("buffer"in n){var r=n.byteOffset,i=n.byteLength;return typeof e<"u"&&(r+=e,i-=e),typeof t<"u"&&(i=t),new DataView(n.buffer,r,i)}else return new DataView(n,e,t)}function we(n,e){for(var t=C.from(n),r=new DataView(n),i=t.newHeaderAddress+88,s=0,o=4294967296,u=function(_){s+=_,s>=o&&(s=s%o+(s/o|0))},a=r.byteLength,p=a%4,d=a-p,m=0;m<d;m+=4)m!==i&&u(r.getUint32(m,!0));if(p!==0){for(var b=0,m=0;m<p;m++)b|=r.getUint8(d+m)<<(3-m)*8;u(b)}return s=(s&65535)+(s>>>16),s+=s>>>16,s=(s&65535)+a,e&&r.setUint32(i,s,!0),s}function O(n,e){return Math.floor((n+e-1)/e)*e}function Q(n,e,t,r,i){var s="buffer"in n?new Uint8Array(n.buffer,n.byteOffset+(e||0),i):new Uint8Array(n,e,i),o="buffer"in t?new Uint8Array(t.buffer,t.byteOffset+(r||0),i):new Uint8Array(t,r,i);s.set(o)}function J(n,e,t){var r=new ArrayBuffer(t);return Q(r,0,n,e,t),r}function ue(n){if("buffer"in n){var e=new ArrayBuffer(n.byteLength);return new Uint8Array(e).set(new Uint8Array(n.buffer,n.byteOffset,n.byteLength)),e}else{var e=new ArrayBuffer(n.byteLength);return new Uint8Array(e).set(new Uint8Array(n)),e}}function et(n,e,t){for(var r=0,i=0;i<t&&n.getUint8(e+i)!==0;++i)++r;if(typeof Buffer<"u")return Buffer.from(n.buffer,n.byteOffset+e,r).toString("utf8");if(typeof decodeURIComponent<"u"){for(var s="",i=0;i<r;++i){var o=n.getUint8(e+i);o<16?s+="%0"+o.toString(16):s+="%"+o.toString(16)}return decodeURIComponent(s)}else{for(var s="",i=0;i<r;++i){var o=n.getUint8(e+i);s+=String.fromCharCode(o)}return s}}function tt(n,e,t,r){if(typeof Buffer<"u"){var i=new Uint8Array(n.buffer,n.byteOffset+e,t);i.set(new Uint8Array(t)),i.set(Buffer.from(r,"utf8").subarray(0,t))}else if(typeof encodeURIComponent<"u")for(var s=encodeURIComponent(r),o=0,u=0;o<t;++o)if(u>=s.length)n.setUint8(o+e,0);else{var a=s.charCodeAt(u);if(a===37){var p=parseInt(s.substr(u+1,2),16);typeof p=="number"&&!isNaN(p)?n.setUint8(o+e,p):n.setUint8(o+e,0),u+=3}else n.setUint8(o+e,a)}else for(var o=0,u=0;o<t;++o)if(u>=r.length)n.setUint8(o+e,0);else{var a=r.charCodeAt(u);n.setUint8(o+e,a&255)}}function rt(n){if(typeof TextDecoder<"u"){var e=new TextDecoder;return e.decode(n)}else if(typeof Buffer<"u"){var t=void 0;return"buffer"in n?t=Buffer.from(n.buffer,n.byteOffset,n.byteLength):t=Buffer.from(n),t.toString("utf8")}else{var r=void 0;if("buffer"in n?r=new Uint8Array(n.buffer,n.byteOffset,n.byteLength):r=new Uint8Array(n),typeof decodeURIComponent<"u"){for(var i="",s=0;s<r.length;++s){var o=r[s];o<16?i+="%0"+o.toString(16):i+="%"+o.toString(16)}return decodeURIComponent(i)}else{for(var i="",s=0;s<r.length;++s){var o=r[s];i+=String.fromCharCode(o)}return i}}}function nt(n){if(typeof TextEncoder<"u"){var e=new TextEncoder;return ue(e.encode(n))}else{if(typeof Buffer<"u")return ue(Buffer.from(n,"utf8"));if(typeof encodeURIComponent<"u"){for(var t=encodeURIComponent(n),r=0,i=0;i<t.length;++r){var s=t.charCodeAt(i);s===37?i+=3:++i}for(var o=new ArrayBuffer(r),u=new Uint8Array(o),i=0,a=0;i<t.length;++a){var s=t.charCodeAt(i);if(s===37){var p=parseInt(t.substring(i+1,i+3),16);u[a]=p,i+=3}else u[a]=s,++i}return o}else{var o=new ArrayBuffer(n.length);return new Uint8Array(o).set([].map.call(n,function(m){return m.charCodeAt(0)})),o}}}var lr=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),cr=(function(n){lr(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){return r===void 0&&(r=0),new e(Z(t,r,64))},e.prototype.isValid=function(){return this.magic===e.DEFAULT_MAGIC},Object.defineProperty(e.prototype,"magic",{get:function(){return this.view.getUint16(0,!0)},set:function(t){this.view.setUint16(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lastPageSize",{get:function(){return this.view.getUint16(2,!0)},set:function(t){this.view.setUint16(2,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"pages",{get:function(){return this.view.getUint16(4,!0)},set:function(t){this.view.setUint16(4,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"relocations",{get:function(){return this.view.getUint16(6,!0)},set:function(t){this.view.setUint16(6,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"headerSizeInParagraph",{get:function(){return this.view.getUint16(8,!0)},set:function(t){this.view.setUint16(8,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minAllocParagraphs",{get:function(){return this.view.getUint16(10,!0)},set:function(t){this.view.setUint16(10,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxAllocParagraphs",{get:function(){return this.view.getUint16(12,!0)},set:function(t){this.view.setUint16(12,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"initialSS",{get:function(){return this.view.getUint16(14,!0)},set:function(t){this.view.setUint16(14,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"initialSP",{get:function(){return this.view.getUint16(16,!0)},set:function(t){this.view.setUint16(16,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"checkSum",{get:function(){return this.view.getUint16(18,!0)},set:function(t){this.view.setUint16(18,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"initialIP",{get:function(){return this.view.getUint16(20,!0)},set:function(t){this.view.setUint16(20,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"initialCS",{get:function(){return this.view.getUint16(22,!0)},set:function(t){this.view.setUint16(22,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"relocationTableAddress",{get:function(){return this.view.getUint16(24,!0)},set:function(t){this.view.setUint16(24,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"overlayNum",{get:function(){return this.view.getUint16(26,!0)},set:function(t){this.view.setUint16(26,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"oemId",{get:function(){return this.view.getUint16(36,!0)},set:function(t){this.view.setUint16(36,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"oemInfo",{get:function(){return this.view.getUint16(38,!0)},set:function(t){this.view.setUint16(38,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"newHeaderAddress",{get:function(){return this.view.getUint32(60,!0)},set:function(t){this.view.setUint32(60,t,!0)},enumerable:!1,configurable:!0}),e.size=64,e.DEFAULT_MAGIC=23117,e})(z),C=cr;var hr=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),pr=(function(n){hr(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){return r===void 0&&(r=0),new e(new DataView(t,r,20))},Object.defineProperty(e.prototype,"machine",{get:function(){return this.view.getUint16(0,!0)},set:function(t){this.view.setUint16(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numberOfSections",{get:function(){return this.view.getUint16(2,!0)},set:function(t){this.view.setUint16(2,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"timeDateStamp",{get:function(){return this.view.getUint32(4,!0)},set:function(t){this.view.setUint32(4,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"pointerToSymbolTable",{get:function(){return this.view.getUint32(8,!0)},set:function(t){this.view.setUint32(8,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numberOfSymbols",{get:function(){return this.view.getUint32(12,!0)},set:function(t){this.view.setUint32(12,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfOptionalHeader",{get:function(){return this.view.getUint16(16,!0)},set:function(t){this.view.setUint16(16,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"characteristics",{get:function(){return this.view.getUint16(18,!0)},set:function(t){this.view.setUint16(18,t,!0)},enumerable:!1,configurable:!0}),e.size=20,e})(z),T=pr;var gr=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),dr=(function(n){gr(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){return r===void 0&&(r=0),new e(new DataView(t,r,96))},Object.defineProperty(e.prototype,"magic",{get:function(){return this.view.getUint16(0,!0)},set:function(t){this.view.setUint16(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorLinkerVersion",{get:function(){return this.view.getUint8(2)},set:function(t){this.view.setUint8(2,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorLinkerVersion",{get:function(){return this.view.getUint8(3)},set:function(t){this.view.setUint8(3,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfCode",{get:function(){return this.view.getUint32(4,!0)},set:function(t){this.view.setUint32(4,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfInitializedData",{get:function(){return this.view.getUint32(8,!0)},set:function(t){this.view.setUint32(8,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfUninitializedData",{get:function(){return this.view.getUint32(12,!0)},set:function(t){this.view.setUint32(12,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"addressOfEntryPoint",{get:function(){return this.view.getUint32(16,!0)},set:function(t){this.view.setUint32(16,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"baseOfCode",{get:function(){return this.view.getUint32(20,!0)},set:function(t){this.view.setUint32(20,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"baseOfData",{get:function(){return this.view.getUint32(24,!0)},set:function(t){this.view.setUint32(24,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"imageBase",{get:function(){return this.view.getUint32(28,!0)},set:function(t){this.view.setUint32(28,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sectionAlignment",{get:function(){return this.view.getUint32(32,!0)},set:function(t){this.view.setUint32(32,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fileAlignment",{get:function(){return this.view.getUint32(36,!0)},set:function(t){this.view.setUint32(36,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorOperatingSystemVersion",{get:function(){return this.view.getUint16(40,!0)},set:function(t){this.view.setUint16(40,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorOperatingSystemVersion",{get:function(){return this.view.getUint16(42,!0)},set:function(t){this.view.setUint16(42,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorImageVersion",{get:function(){return this.view.getUint16(44,!0)},set:function(t){this.view.setUint16(44,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorImageVersion",{get:function(){return this.view.getUint16(46,!0)},set:function(t){this.view.setUint16(46,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorSubsystemVersion",{get:function(){return this.view.getUint16(48,!0)},set:function(t){this.view.setUint16(48,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorSubsystemVersion",{get:function(){return this.view.getUint16(50,!0)},set:function(t){this.view.setUint16(50,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"win32VersionValue",{get:function(){return this.view.getUint32(52,!0)},set:function(t){this.view.setUint32(52,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfImage",{get:function(){return this.view.getUint32(56,!0)},set:function(t){this.view.setUint32(56,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeaders",{get:function(){return this.view.getUint32(60,!0)},set:function(t){this.view.setUint32(60,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"checkSum",{get:function(){return this.view.getUint32(64,!0)},set:function(t){this.view.setUint32(64,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subsystem",{get:function(){return this.view.getUint16(68,!0)},set:function(t){this.view.setUint16(68,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dllCharacteristics",{get:function(){return this.view.getUint16(70,!0)},set:function(t){this.view.setUint16(70,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackReserve",{get:function(){return this.view.getUint32(72,!0)},set:function(t){this.view.setUint32(72,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackCommit",{get:function(){return this.view.getUint32(76,!0)},set:function(t){this.view.setUint32(76,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapReserve",{get:function(){return this.view.getUint32(80,!0)},set:function(t){this.view.setUint32(80,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapCommit",{get:function(){return this.view.getUint32(84,!0)},set:function(t){this.view.setUint32(84,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loaderFlags",{get:function(){return this.view.getUint32(88,!0)},set:function(t){this.view.setUint32(88,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numberOfRvaAndSizes",{get:function(){return this.view.getUint32(92,!0)},set:function(t){this.view.setUint32(92,t,!0)},enumerable:!1,configurable:!0}),e.size=96,e.DEFAULT_MAGIC=267,e})(z),j=dr;var mr=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})();function ee(n,e){return n.getUint32(e+4,!0)*4294967296+n.getUint32(e,!0)}function te(n,e,t){n.setUint32(e,t&4294967295,!0),n.setUint32(e+4,Math.floor(t/4294967296),!0)}function re(n,e){if(typeof BigInt>"u")throw new Error("BigInt not supported");return BigInt(4294967296)*BigInt(n.getUint32(e+4,!0))+BigInt(n.getUint32(e,!0))}function ne(n,e,t){if(typeof BigInt>"u")throw new Error("BigInt not supported");n.setUint32(e,Number(t&BigInt(4294967295)),!0),n.setUint32(e+4,Math.floor(Number(t/BigInt(4294967296)&BigInt(4294967295))),!0)}var yr=(function(n){mr(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){return r===void 0&&(r=0),new e(new DataView(t,r,112))},Object.defineProperty(e.prototype,"magic",{get:function(){return this.view.getUint16(0,!0)},set:function(t){this.view.setUint16(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorLinkerVersion",{get:function(){return this.view.getUint8(2)},set:function(t){this.view.setUint8(2,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorLinkerVersion",{get:function(){return this.view.getUint8(3)},set:function(t){this.view.setUint8(3,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfCode",{get:function(){return this.view.getUint32(4,!0)},set:function(t){this.view.setUint32(4,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfInitializedData",{get:function(){return this.view.getUint32(8,!0)},set:function(t){this.view.setUint32(8,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfUninitializedData",{get:function(){return this.view.getUint32(12,!0)},set:function(t){this.view.setUint32(12,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"addressOfEntryPoint",{get:function(){return this.view.getUint32(16,!0)},set:function(t){this.view.setUint32(16,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"baseOfCode",{get:function(){return this.view.getUint32(20,!0)},set:function(t){this.view.setUint32(20,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"imageBase",{get:function(){return ee(this.view,24)},set:function(t){te(this.view,24,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"imageBaseBigInt",{get:function(){return re(this.view,24)},set:function(t){ne(this.view,24,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sectionAlignment",{get:function(){return this.view.getUint32(32,!0)},set:function(t){this.view.setUint32(32,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fileAlignment",{get:function(){return this.view.getUint32(36,!0)},set:function(t){this.view.setUint32(36,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorOperatingSystemVersion",{get:function(){return this.view.getUint16(40,!0)},set:function(t){this.view.setUint16(40,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorOperatingSystemVersion",{get:function(){return this.view.getUint16(42,!0)},set:function(t){this.view.setUint16(42,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorImageVersion",{get:function(){return this.view.getUint16(44,!0)},set:function(t){this.view.setUint16(44,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorImageVersion",{get:function(){return this.view.getUint16(46,!0)},set:function(t){this.view.setUint16(46,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorSubsystemVersion",{get:function(){return this.view.getUint16(48,!0)},set:function(t){this.view.setUint16(48,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorSubsystemVersion",{get:function(){return this.view.getUint16(50,!0)},set:function(t){this.view.setUint16(50,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"win32VersionValue",{get:function(){return this.view.getUint32(52,!0)},set:function(t){this.view.setUint32(52,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfImage",{get:function(){return this.view.getUint32(56,!0)},set:function(t){this.view.setUint32(56,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeaders",{get:function(){return this.view.getUint32(60,!0)},set:function(t){this.view.setUint32(60,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"checkSum",{get:function(){return this.view.getUint32(64,!0)},set:function(t){this.view.setUint32(64,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subsystem",{get:function(){return this.view.getUint16(68,!0)},set:function(t){this.view.setUint16(68,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dllCharacteristics",{get:function(){return this.view.getUint16(70,!0)},set:function(t){this.view.setUint16(70,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackReserve",{get:function(){return ee(this.view,72)},set:function(t){te(this.view,72,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackReserveBigInt",{get:function(){return re(this.view,72)},set:function(t){ne(this.view,72,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackCommit",{get:function(){return ee(this.view,80)},set:function(t){te(this.view,80,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackCommitBigInt",{get:function(){return re(this.view,80)},set:function(t){ne(this.view,80,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapReserve",{get:function(){return ee(this.view,88)},set:function(t){te(this.view,88,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapReserveBigInt",{get:function(){return re(this.view,88)},set:function(t){ne(this.view,88,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapCommit",{get:function(){return ee(this.view,96)},set:function(t){te(this.view,96,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapCommitBigInt",{get:function(){return re(this.view,96)},set:function(t){ne(this.view,96,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loaderFlags",{get:function(){return this.view.getUint32(104,!0)},set:function(t){this.view.setUint32(104,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numberOfRvaAndSizes",{get:function(){return this.view.getUint32(108,!0)},set:function(t){this.view.setUint32(108,t,!0)},enumerable:!1,configurable:!0}),e.size=112,e.DEFAULT_MAGIC=523,e})(z),$=yr;var wr=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),vr=(function(n){wr(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){r===void 0&&(r=0);var i=Z(t,r+T.size,6).getUint16(4,!0),s=4+T.size+R.size;return i===$.DEFAULT_MAGIC?s+=$.size:s+=j.size,new e(Z(t,r,s))},e.prototype.isValid=function(){return this.signature===e.DEFAULT_SIGNATURE},e.prototype.is32bit=function(){return this.view.getUint16(T.size+4,!0)===j.DEFAULT_MAGIC},Object.defineProperty(e.prototype,"signature",{get:function(){return this.view.getUint32(0,!0)},set:function(t){this.view.setUint32(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fileHeader",{get:function(){return T.from(this.view.buffer,this.view.byteOffset+4)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"optionalHeader",{get:function(){var t=T.size+4,r=this.view.getUint16(t,!0);return r===$.DEFAULT_MAGIC?$.from(this.view.buffer,this.view.byteOffset+t):j.from(this.view.buffer,this.view.byteOffset+t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"optionalHeaderDataDirectory",{get:function(){return R.from(this.view.buffer,this.view.byteOffset+this.getDataDirectoryOffset())},enumerable:!1,configurable:!0}),e.prototype.getDataDirectoryOffset=function(){var t=T.size+4,r=this.view.getUint16(t,!0);return r===$.DEFAULT_MAGIC?t+=$.size:t+=j.size,t},e.prototype.getSectionHeaderOffset=function(){return this.getDataDirectoryOffset()+R.size},e.DEFAULT_SIGNATURE=17744,e})(z),W=vr;var br=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),_r=(function(n){br(e,n);function e(t,r){var i=n.call(this,t)||this;return i.length=r,i}return e.from=function(t,r,i){i===void 0&&(i=0);var s=r*40;return new e(new DataView(t,i,s),r)},e.prototype.get=function(t){return{name:et(this.view,t*40,8),virtualSize:this.view.getUint32(8+t*40,!0),virtualAddress:this.view.getUint32(12+t*40,!0),sizeOfRawData:this.view.getUint32(16+t*40,!0),pointerToRawData:this.view.getUint32(20+t*40,!0),pointerToRelocations:this.view.getUint32(24+t*40,!0),pointerToLineNumbers:this.view.getUint32(28+t*40,!0),numberOfRelocations:this.view.getUint16(32+t*40,!0),numberOfLineNumbers:this.view.getUint16(34+t*40,!0),characteristics:this.view.getUint32(36+t*40,!0)}},e.prototype.set=function(t,r){tt(this.view,t*40,8,r.name),this.view.setUint32(8+t*40,r.virtualSize,!0),this.view.setUint32(12+t*40,r.virtualAddress,!0),this.view.setUint32(16+t*40,r.sizeOfRawData,!0),this.view.setUint32(20+t*40,r.pointerToRawData,!0),this.view.setUint32(24+t*40,r.pointerToRelocations,!0),this.view.setUint32(28+t*40,r.pointerToLineNumbers,!0),this.view.setUint16(32+t*40,r.numberOfRelocations,!0),this.view.setUint16(34+t*40,r.numberOfLineNumbers,!0),this.view.setUint32(36+t*40,r.characteristics,!0)},e.itemSize=40,e})(k),F=_r;function Ur(n){return C.from(n)}function Ar(n,e){return W.from(n,e.newHeaderAddress)}function xr(n,e,t){return F.from(n,t.fileHeader.numberOfSections,e.newHeaderAddress+t.byteLength)}function Or(n,e,t,r){for(var i=F.from(n,t.fileHeader.numberOfSections,e.newHeaderAddress+t.byteLength),s=i.length,o=t.optionalHeaderDataDirectory.get(r).virtualAddress,u=0;u<s;++u){var a=i.get(u),p=a.virtualAddress+a.virtualSize;if(o>=a.virtualAddress&&o<p){var d=a.pointerToRawData;return d?n.slice(d,d+a.sizeOfRawData):null}if(o<a.virtualAddress)return null}return null}var ve=new Uint8Array([14,31,186,14,0,180,9,205,33,184,1,76,205,33,68,79,83,32,109,111,100,101,32,110,111,116,32,115,117,112,112,111,114,116,101,100,46,13,13,10,36,0,0,0,0,0,0,0]),ie=O(C.size+ve.length,128),it=512;function Sr(n){var e=C.from(n);e.magic=C.DEFAULT_MAGIC,e.lastPageSize=ie%512,e.pages=Math.ceil(ie/512),e.relocations=0,e.headerSizeInParagraph=Math.ceil(C.size/16),e.minAllocParagraphs=0,e.maxAllocParagraphs=65535,e.initialSS=0,e.initialSP=128,e.relocationTableAddress=C.size,e.newHeaderAddress=ie,Q(n,C.size,ve,0,ve.length)}function Er(n){return 4+T.size+(n?j.size:$.size)+R.size}function Cr(n,e,t,r,i){var s,o;"buffer"in n?(s=n.buffer,o=n.byteOffset+e):(s=n,o=e),new DataView(s,o).setUint32(0,W.DEFAULT_SIGNATURE,!0);var u=T.from(s,o+4);u.machine=r?332:34404,u.numberOfSections=0,u.timeDateStamp=0,u.pointerToSymbolTable=0,u.numberOfSymbols=0,u.sizeOfOptionalHeader=(r?j.size:$.size)+R.size,u.characteristics=i?8450:258;var a=(r?j:$).from(s,o+4+T.size);a.magic=r?j.DEFAULT_MAGIC:$.DEFAULT_MAGIC,a.sizeOfCode=0,a.sizeOfInitializedData=0,a.sizeOfUninitializedData=0,a.addressOfEntryPoint=0,a.baseOfCode=4096,a.imageBase=r?16777216:6442450944,a.sectionAlignment=4096,a.fileAlignment=it,a.majorOperatingSystemVersion=6,a.minorOperatingSystemVersion=0,a.majorSubsystemVersion=6,a.minorSubsystemVersion=0,a.sizeOfHeaders=O(t,a.fileAlignment),a.subsystem=2,a.dllCharacteristics=(r?0:32)+64+256,a.sizeOfStackReserve=1048576,a.sizeOfStackCommit=4096,a.sizeOfHeapReserve=1048576,a.sizeOfHeapCommit=4096,a.numberOfRvaAndSizes=R.size/R.itemSize}function st(n,e){var t=O(ie+Er(n),it),r=new ArrayBuffer(t);return Sr(r),Cr(r,ie,t,n,e),r}var Ir=(function(){function n(e,t,r){this._headers=e,this._sections=t,this._ex=r;var i=C.from(e),s=W.from(e,i.newHeaderAddress);this._dh=i,this._nh=s,this._dda=s.optionalHeaderDataDirectory,t.sort(function(o,u){var a=o.info.pointerToRawData,p=o.info.pointerToRawData;if(a!==p)return a-p;var d=o.info.virtualAddress,m=u.info.virtualAddress;return d===m?o.info.virtualSize-u.info.virtualSize:d-m})}return n.createEmpty=function(e,t){return e===void 0&&(e=!1),t===void 0&&(t=!0),this.from(st(e,t))},n.from=function(e,t){var r=C.from(e),i=W.from(e,r.newHeaderAddress);if(!r.isValid()||!i.isValid())throw new TypeError("Invalid binary format");if(i.fileHeader.numberOfSymbols>0)throw new Error("Binary with symbols is not supported now");var s=i.optionalHeader.fileAlignment,o=i.optionalHeaderDataDirectory.get(M.Certificate);if(o.size>0&&!t?.ignoreCert)throw new Error("Parsing signed executable binary is not allowed by default.");var u=r.newHeaderAddress+i.getSectionHeaderOffset(),a=i.fileHeader.numberOfSections,p=[],d=J(e,u,a*F.itemSize),m=F.from(d,a,0),b=O(u+a*F.itemSize,s);m.forEach(function(w){if(!w.pointerToRawData||!w.sizeOfRawData)w.pointerToRawData=0,w.sizeOfRawData=0,p.push({info:w,data:null});else{var y=J(e,w.pointerToRawData,w.sizeOfRawData);p.push({info:w,data:y});var g=O(w.pointerToRawData+w.sizeOfRawData,s);g>b&&(b=g)}});var _=J(e,0,u),U=null,v=e.byteLength;return o.size>0&&(v=o.virtualAddress),b<v&&(U=J(e,b,v-b)),new n(_,p,U)},n.prototype.is32bit=function(){return this._nh.is32bit()},n.prototype.getTotalHeaderSize=function(){return this._headers.byteLength},Object.defineProperty(n.prototype,"dosHeader",{get:function(){return this._dh},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"newHeader",{get:function(){return this._nh},enumerable:!1,configurable:!0}),n.prototype.getRawHeader=function(){return this._headers},n.prototype.getImageBase=function(){return this._nh.optionalHeader.imageBase},n.prototype.getFileAlignment=function(){return this._nh.optionalHeader.fileAlignment},n.prototype.getSectionAlignment=function(){return this._nh.optionalHeader.sectionAlignment},n.prototype.getAllSections=function(){return this._sections},n.prototype.getSectionByEntry=function(e){var t=this._dda.get(e),r=this._sections.filter(function(i){var s=i.info.virtualAddress+i.info.virtualSize;return t.virtualAddress>=i.info.virtualAddress&&t.virtualAddress<s}).shift();return r!==void 0?r:null},n.prototype.setSectionByEntry=function(e,t){var r=t?{data:t.data,info:t.info}:null,i=this._dda.get(e),s=i.size>0;if(r){var m=r.data?r.data.byteLength:0,b=this._nh.optionalHeader.fileAlignment,_=this._nh.optionalHeader.sectionAlignment,U=r.data?O(m,b):0,v=r.data?O(r.info.virtualSize,_):0;if(r.info.sizeOfRawData<U?r.info.sizeOfRawData=U:U=r.info.sizeOfRawData,s)this.replaceSectionImpl(i.virtualAddress,r.info,r.data);else{var w=0,y=O(this._headers.byteLength,b);this._sections.forEach(function(g){g.info.pointerToRawData&&y<=g.info.pointerToRawData&&(y=g.info.pointerToRawData+g.info.sizeOfRawData),w<=g.info.virtualAddress&&(w=g.info.virtualAddress+g.info.virtualSize)}),U||(y=0),w||(w=this.newHeader.optionalHeader.baseOfCode),w=O(w,_),r.info.pointerToRawData=y,r.info.virtualAddress=w,this._dda.set(e,{size:m,virtualAddress:w}),this._sections.push(r),this._nh.fileHeader.numberOfSections=this._sections.length,this._nh.optionalHeader.sizeOfImage=O(w+v,this._nh.optionalHeader.sectionAlignment)}}else if(s){this._dda.set(e,{size:0,virtualAddress:0});for(var o=this._sections.length,u=0;u<o;++u){var a=this._sections[u],p=a.info.virtualAddress,d=p+a.info.virtualSize;if(i.virtualAddress>=p&&i.virtualAddress<d){this._sections.splice(u,1),this._nh.fileHeader.numberOfSections=this._sections.length;break}}}},n.prototype.getExtraData=function(){return this._ex},n.prototype.setExtraData=function(e){e===null?this._ex=null:this._ex=ue(e)},n.prototype.generate=function(e){var t=this._dh,r=this._nh,i=t.newHeaderAddress+r.getSectionHeaderOffset(),s=i;s+=this._sections.length*F.itemSize;var o=r.optionalHeader.fileAlignment;s=O(s,o),this._sections.forEach(function(m){if(m.info.pointerToRawData){var b=m.info.pointerToRawData+m.info.sizeOfRawData;s<b&&(s=b,s=O(s,o))}});var u=s;this._ex!==null&&(s+=this._ex.byteLength),typeof e=="number"&&(s+=e);var a=new ArrayBuffer(s),p=new Uint8Array(a);p.set(new Uint8Array(this._headers,0,i)),R.from(a,t.newHeaderAddress+r.getDataDirectoryOffset()).set(M.Certificate,{size:0,virtualAddress:0});var d=F.from(a,this._sections.length,i);return this._sections.forEach(function(m,b){m.data||(m.info.pointerToRawData=0,m.info.sizeOfRawData=0),d.set(b,m.info),!(!m.data||!m.info.pointerToRawData)&&p.set(new Uint8Array(m.data),m.info.pointerToRawData)}),this._ex!==null&&p.set(new Uint8Array(this._ex),u),r.optionalHeader.checkSum!==0&&we(a,!0),a},n.prototype.rearrangeSections=function(e,t,r,i){if(!(!t&&!i)){for(var s=this._nh,o=s.optionalHeader.sectionAlignment,u=this._dda,a=this._sections.length,p=0,d=0;d<a;++d){var m=this._sections[d],b=m.info.virtualAddress;if(i&&b>=r){var _=u.findIndexByVirtualAddress(b);b+=i,_!==null&&u.set(_,{virtualAddress:b,size:m.info.virtualSize}),m.info.virtualAddress=b}var U=m.info.pointerToRawData;t&&U>=e&&(m.info.pointerToRawData=U+t),p=O(m.info.virtualAddress+m.info.virtualSize,o)}s.optionalHeader.sizeOfImage=p}},n.prototype.replaceSectionImpl=function(e,t,r){for(var i=this._sections.length,s=0;s<i;++s){var o=this._sections[s];if(o.info.virtualAddress===e){var u=this._nh.optionalHeader.sectionAlignment,a=o.info.pointerToRawData,p=a+o.info.sizeOfRawData,d=e+O(o.info.virtualSize,u);o.info=K(t),o.info.virtualAddress=e,o.info.pointerToRawData=a,o.data=r;var m=a+t.sizeOfRawData,b=e+O(t.virtualSize,u);this.rearrangeSections(p,m-p,d,b-d);{var _=this._dda,U=_.findIndexByVirtualAddress(e);U!==null&&_.set(U,{virtualAddress:e,size:t.virtualSize})}break}}},n})(),be=Ir;function zr(n){return n.reduce(function(e,t){return e.indexOf(t)>=0?e:e.concat(t)},[])}function _e(n,e){var t=n.getUint16(e,!0),r="";e+=2;for(var i=0;i<t;++i)r+=String.fromCharCode(n.getUint16(e,!0)),e+=2;return r}function ot(n,e,t,r,i){var s=r,o={name:t,languageTable:r,characteristics:n.getUint32(s,!0),dateTime:n.getUint32(s+4,!0),majorVersion:n.getUint16(s+8,!0),minorVersion:n.getUint16(s+10,!0)},u=n.getUint16(s+12,!0),a=n.getUint16(s+14,!0);s+=16;for(var p=0;p<u;++p){var d=n.getUint32(s,!0)&2147483647,m=n.getUint32(s+4,!0);if((m&2147483648)!==0){s+=8;continue}var b=_e(n,d);i(e,o,{lang:b,dataOffset:m}),s+=8}for(var p=0;p<a;++p){var _=n.getUint32(s,!0)&2147483647,m=n.getUint32(s+4,!0);if((m&2147483648)!==0){s+=8;continue}i(e,o,{lang:_,dataOffset:m}),s+=8}}function at(n,e,t,r){var i=t,s={type:e,nameTable:t,characteristics:n.getUint32(i,!0),dateTime:n.getUint32(i+4,!0),majorVersion:n.getUint16(i+8,!0),minorVersion:n.getUint16(i+10,!0)},o=n.getUint16(i+12,!0),u=n.getUint16(i+14,!0);i+=16;for(var a=0;a<o;++a){var p=n.getUint32(i,!0)&2147483647,d=n.getUint32(i+4,!0);if(!(d&2147483648)){i+=8;continue}d&=2147483647;var m=_e(n,p);ot(n,s,m,d,r),i+=8}for(var a=0;a<u;++a){var b=n.getUint32(i,!0)&2147483647,d=n.getUint32(i+4,!0);if(!(d&2147483648)){i+=8;continue}d&=2147483647,ot(n,s,b,d,r),i+=8}}function ut(n,e,t){var r={},i={};t.forEach(function(u){typeof u.lang=="string"?(r[u.lang]=u,e.push(u.lang)):i[u.lang]=u});var s=Object.keys(r);s.sort().forEach(function(u){n.s.push(r[u])});var o=Object.keys(i);return o.map(function(u){return Number(u)}).sort(function(u,a){return u-a}).forEach(function(u){n.n.push(i[u])}),16+8*(s.length+o.length)}function ft(n,e,t){var r={},i={};t.forEach(function(u){var a,p;if(typeof u.id=="string"){var d=(a=r[u.id])!==null&&a!==void 0?a:r[u.id]=[];e.push(u.id),d.push(u)}else{var d=(p=i[u.id])!==null&&p!==void 0?p:i[u.id]=[];d.push(u)}});var s=Object.keys(r).sort().map(function(u){var a={id:u,s:[],n:[]};return n.s.push(a),ut(a,e,r[u])}).reduce(function(u,a){return u+8+a},0),o=Object.keys(i).map(function(u){return Number(u)}).sort(function(u,a){return u-a}).map(function(u){var a={id:u,s:[],n:[]};return n.n.push(a),ut(a,e,i[u])}).reduce(function(u,a){return u+8+a},0);return 16+s+o}function $r(n,e,t){var r={},i={};t.forEach(function(u){var a,p;if(typeof u.type=="string"){var d=(a=r[u.type])!==null&&a!==void 0?a:r[u.type]=[];e.push(u.type),d.push(u)}else{var d=(p=i[u.type])!==null&&p!==void 0?p:i[u.type]=[];d.push(u)}});var s=Object.keys(r).sort().map(function(u){var a={type:u,s:[],n:[]};return n.s.push(a),ft(a,e,r[u])}).reduce(function(u,a){return u+8+a},0),o=Object.keys(i).map(function(u){return Number(u)}).sort(function(u,a){return u-a}).map(function(u){var a={type:u,s:[],n:[]};return n.n.push(a),ft(a,e,i[u])}).reduce(function(u,a){return u+8+a},0);return 16+s+o}function ht(n){var e=n.length;return e>65535?65535:e}function Ue(n,e){for(var t=e.length,r=0;r<t;++r){var i=e[r];if(i.text===n)return i.offset}throw new Error("Unexpected")}function Rr(n,e,t){var r=ht(t);n.setUint16(e,r,!0),e+=2;for(var i=0;i<r;++i)n.setUint16(e,t.charCodeAt(i),!0),e+=2;return e}function lt(n,e,t,r){return n.setUint32(e,0,!0),n.setUint32(e+4,0,!0),n.setUint32(e+8,0,!0),n.setUint16(e+12,r.s.length,!0),n.setUint16(e+14,r.n.length,!0),e+=16,r.s.forEach(function(i){var s=Ue(i.lang,t);n.setUint32(e,s,!0),n.setUint32(e+4,i.offset,!0),e+=8}),r.n.forEach(function(i){n.setUint32(e,i.lang,!0),n.setUint32(e+4,i.offset,!0),e+=8}),e}function ct(n,e,t,r,i){return n.setUint32(e,0,!0),n.setUint32(e+4,0,!0),n.setUint32(e+8,0,!0),n.setUint16(e+12,i.s.length,!0),n.setUint16(e+14,i.n.length,!0),e+=16,i.s.forEach(function(s){s.offset=t,t=lt(n,t,r,s)}),i.n.forEach(function(s){s.offset=t,t=lt(n,t,r,s)}),i.s.forEach(function(s){var o=Ue(s.id,r);n.setUint32(e,o+2147483648,!0),n.setUint32(e+4,s.offset+2147483648,!0),e+=8}),i.n.forEach(function(s){n.setUint32(e,s.id,!0),n.setUint32(e+4,s.offset+2147483648,!0),e+=8}),t}function Tr(n,e,t,r){n.setUint32(e,0,!0),n.setUint32(e+4,0,!0),n.setUint32(e+8,0,!0),n.setUint16(e+12,r.s.length,!0),n.setUint16(e+14,r.n.length,!0),e+=16;var i=e+8*(r.s.length+r.n.length);return r.s.forEach(function(s){s.offset=i,i+=16+8*(s.s.length+s.n.length)}),r.n.forEach(function(s){s.offset=i,i+=16+8*(s.s.length+s.n.length)}),r.s.forEach(function(s){var o=Ue(s.type,t);n.setUint32(e,o+2147483648,!0),n.setUint32(e+4,s.offset+2147483648,!0),e+=8,i=ct(n,s.offset,i,t,s)}),r.n.forEach(function(s){n.setUint32(e,s.type,!0),n.setUint32(e+4,s.offset+2147483648,!0),e+=8,i=ct(n,s.offset,i,t,s)}),i}var Ui=(function(){function n(){this.dateTime=0,this.majorVersion=0,this.minorVersion=0,this.entries=[],this.sectionDataHeader=null,this.originalSize=0}return n.prototype.parse=function(e,t){if(e.data){var r=new DataView(e.data);this.dateTime=r.getUint32(4,!0),this.majorVersion=r.getUint16(8,!0),this.minorVersion=r.getUint16(10,!0);for(var i=r.getUint16(12,!0),s=r.getUint16(14,!0),o=16,u=[],a=function(U,v,w){var y=r.getUint32(w.dataOffset,!0)-e.info.virtualAddress,g=r.getUint32(w.dataOffset+4,!0),f=r.getUint32(w.dataOffset+8,!0);if(y>=0){var l=new Uint8Array(g);l.set(new Uint8Array(e.data,y,g)),u.push({type:U.type,id:v.name,lang:w.lang,codepage:f,bin:l.buffer})}else{if(!t)throw new Error("Cannot parse resource directory entry; RVA seems to be invalid.");u.push({type:U.type,id:v.name,lang:w.lang,codepage:f,bin:new ArrayBuffer(0),rva:w.dataOffset})}},p=0;p<i;++p){var d=r.getUint32(o,!0)&2147483647,m=r.getUint32(o+4,!0);if(!(m&2147483648)){o+=8;continue}m&=2147483647;var b=_e(r,d);at(r,b,m,a),o+=8}for(var p=0;p<s;++p){var _=r.getUint32(o,!0)&2147483647,m=r.getUint32(o+4,!0);if(!(m&2147483648)){o+=8;continue}m&=2147483647,at(r,_,m,a),o+=8}this.entries=u,this.originalSize=e.data.byteLength}},n.from=function(e,t){t===void 0&&(t=!1);var r=[].concat(e.getAllSections()).sort(function(d,m){return d.info.virtualAddress-m.info.virtualAddress}),i=e.getSectionByEntry(M.Resource);if(i)for(var s=e.getSectionByEntry(M.BaseRelocation),o=0;o<r.length;++o){var u=r[o];if(u===i){for(var a=o+1;a<r.length;++a)if(!s||r[a]!==s)throw new Error("After Resource section, sections except for relocation are not supported");break}}var p=new n;return p.sectionDataHeader=i?K(i.info):null,i&&p.parse(i,t),p},n.prototype.replaceResourceEntry=function(e){for(var t=this.entries.length,r=0;r<t;++r){var i=this.entries[r];if(i.type===e.type&&i.id===e.id&&i.lang===e.lang){this.entries[r]=e;return}}this.entries.push(e)},n.prototype.getResourceEntriesAsString=function(e,t){return this.entries.filter(function(r){return r.type===e&&r.id===t}).map(function(r){return[r.lang,rt(r.bin)]})},n.prototype.replaceResourceEntryFromString=function(e,t,r,i){var s={type:e,id:t,lang:r,codepage:1200,bin:nt(i)};this.replaceResourceEntry(s)},n.prototype.removeResourceEntry=function(e,t,r){this.entries=this.entries.filter(function(i){return!(i.type===e&&i.id===t&&(typeof r>"u"||i.lang===r))})},n.prototype.generateResourceData=function(e,t,r,i){r===void 0&&(r=!1),i===void 0&&(i=!1);var s={s:[],n:[]},o=[],u=$r(s,o,this.entries);o=zr(o);var a=u;u+=o.reduce(function(c,h){return c+2+ht(h)*2},0),u=O(u,8);var p=u;u=this.entries.reduce(function(c,h){return h.offset=c,c+16},p);var d=u;u=this.entries.reduce(function(c,h){return O(c,8)+h.bin.byteLength},d);var m=O(u,t),b=O(this.originalSize,t);if(r&&m>b)throw new Error("New resource data is larger than original");i||m<b&&(m=b);var _=new ArrayBuffer(m),U=new DataView(_),v=p,w=e+d;this.entries.forEach(function(c){var h=c.bin.byteLength;typeof c.rva<"u"?U.setUint32(v,c.rva,!0):(w=O(w,8),U.setUint32(v,w,!0),w+=h),U.setUint32(v+4,h,!0),U.setUint32(v+8,c.codepage,!0),U.setUint32(v+12,0,!0),v+=16}),v=d,this.entries.forEach(function(c){var h=c.bin.byteLength;Q(_,v,c.bin,0,h),v+=O(h,8)});var y=[];if(v=a,o.forEach(function(c){y.push({offset:v,text:c}),v=Rr(U,v,c)}),Tr(U,0,y,s),m>u)for(var g="PADDINGX",f=u,l=0;f<m;++f,++l)l===8&&(l=0),U.setUint8(f,g.charCodeAt(l));return{bin:_,rawSize:u,dataOffset:d,descEntryOffset:p,descEntryCount:this.entries.length}},n.prototype.outputResource=function(e,t,r){t===void 0&&(t=!1),r===void 0&&(r=!1);var i=e.getFileAlignment(),s;this.sectionDataHeader?s={data:null,info:K(this.sectionDataHeader)}:s={data:null,info:{name:".rsrc",virtualSize:0,virtualAddress:0,sizeOfRawData:0,pointerToRawData:0,pointerToRelocations:0,pointerToLineNumbers:0,numberOfRelocations:0,numberOfLineNumbers:0,characteristics:1073741888}};var o=this.generateResourceData(0,i,t,r);s.data=o.bin,s.info.sizeOfRawData=o.bin.byteLength,s.info.virtualSize=o.rawSize,e.setSectionByEntry(M.Resource,s);for(var u=e.getSectionByEntry(M.Resource),a=new DataView(u.data),p=o.descEntryOffset,d=u.info.virtualAddress+o.dataOffset,m=0;m<o.descEntryCount;++m){var b=a.getUint32(p+4,!0);d=O(d,8),a.setUint32(p,d,!0),d+=b,p+=16}},n})();var mt=Rt(dt(),1),Nr=typeof crypto<"u",Pr=typeof globalThis.process<"u"&&globalThis.process.versions&&globalThis.process.versions.node;function jr(){if(Nr)return crypto;if(Pr)return globalThis.crypto;throw new Error("Crypto API not available in this environment")}function le(n){let e=new Uint32Array(256);for(let i=0;i<n.length;i++)e[n[i]]++;let t=0,r=n.length;if(r===0)return 0;for(let i=0;i<256;i++){if(e[i]===0)continue;let s=e[i]/r;t-=s*Math.log2(s)}return t}function Mr(n){return Array.from(n).map(e=>e.toString(16).padStart(2,"0")).join("")}async function D(n,e){let r=await jr().subtle.digest(n,e);return Mr(new Uint8Array(r))}function B(n){let e=new mt.default.ArrayBuffer;return e.append(n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength)),e.end()}function N(n,e,t){return n.getUint16(e,t)}function E(n,e,t){return n.getUint32(e,t)}function P(n,e,t){let r=n.getUint32(e+(t?0:4),t);return n.getUint32(e+(t?4:0),t)*2**32+r}function G(n,e,t=1024){let r=Math.min(n.length,e+t),i="";for(let s=e;s<r&&n[s]!==0;s++)i+=String.fromCharCode(n[s]);return i}function yt(n,e){let t=n.length,r=e.length;for(let i=0;i<=t-r;i++){let s=!0;for(let o=0;o<r;o++)if(n[i+o]!==e[o]){s=!1;break}if(s)return i}return-1}async function Fr(n,e){let t=[],r=n.getAllSections?.()||n.sections||[];for(let i of r){let s=i.info||i,o=i.data?new Uint8Array(i.data):i.data??new Uint8Array,u=B(o),a=await D("SHA-1",o),p=await D("SHA-256",o),d={md5:u,sha1:a,sha256:p};t.push({name:(s.name||i.name||"")?.replace(/\0.*$/,""),raw_data:o,entropy:le(o),virtual_address:s.virtualAddress??s.VirtualAddress??i.VirtualAddress??0,virtual_size:s.virtualSize??s.VirtualSize??i.VirtualSize??0,raw_data_offset:s.pointerToRawData??s.PointerToRawData??i.PointerToRawData??0,raw_data_size:s.sizeOfRawData??s.SizeOfRawData??i.SizeOfRawData??0,characteristics:(s.characteristics??s.Characteristics??i.Characteristics??0)>>>0,...d})}return t}function Hr(n){return(n.imports||[]).map(e=>({dll:e.name||"",functions:(e.functions||[]).map(t=>({name:t.name||null,ordinal:t.ordinal||null}))}))}function Lr(n){return(n.exports||[]).map(e=>e.name||e).filter(Boolean)}function Br(n){let e=[];for(let r of n){let i=(r.dll||"").toLowerCase();if(Array.isArray(r.functions))for(let s of r.functions){let o=(s.name||`ordinal${s.ordinal||""}`).toLowerCase();e.push(`${i}.${o}`)}}let t=new TextEncoder;return B(t.encode(e.join(",")))}function Wr(n){let e=n.optionalHeader?.dataDirectory?.[fe.ImageDirectoryEntry.Security];return!e||!e.virtualAddress||!e.size?{has_signature:!1}:{has_signature:!0,certificate_table:{offset:e.virtualAddress,size:e.size}}}function Vr(n){let e=new Uint8Array([82,105,99,104]),t=yt(n,e);return t!==-1?{offset:t}:null}function qr(n){let e=n.newHeader?.optionalHeader||n.optionalHeader;return e?{size_of_code:e.sizeOfCode??0,size_of_initialized_data:e.sizeOfInitializedData??0,size_of_uninitialized_data:e.sizeOfUninitializedData??0,address_of_entry_point:e.addressOfEntryPoint??0,base_of_code:e.baseOfCode??0,base_of_data:e.baseOfData??0,image_base:e.imageBase??0,section_alignment:e.sectionAlignment??0,file_alignment:e.fileAlignment??0,subsystem:e.subsystem??0,dll_characteristics:e.dllCharacteristics??0,size_of_stack_reserve:e.sizeOfStackReserve??0,size_of_stack_commit:e.sizeOfStackCommit??0,size_of_heap_reserve:e.sizeOfHeapReserve??0,size_of_heap_commit:e.sizeOfHeapCommit??0}:{}}async function Ae(n){n instanceof ArrayBuffer&&(n=new Uint8Array(n));let e;try{e=be.from(n)}catch(U){return{error:"Failed to parse PE",message:U.message}}let t=await Fr(e,n),r=Hr(e),i=Lr(e),s=Br(r),o=Wr(e),u=Vr(n),a=qr(e),p=e.newHeader?.optionalHeader||e.optionalHeader,d=e.newHeader?.fileHeader||e.coffHeader,m=p?.addressOfEntryPoint??0,b=m;if(m>0&&t.length>0)for(let U of t){let v=U.virtual_address,w=v+U.virtual_size;if(m>=v&&m<w){b=m-U.virtual_address+U.raw_data_offset;break}}let _={machine:d?.machine??0,entry_point:b,image_base:p?.imageBase??0,number_of_sections:t.length,sections:t,imports:r,exports:i,imphash:s,digital_signature:o,rich_signature:u,...a,file_size:n.length};return _.is_dll=()=>((d?.characteristics??0)&8192)!==0,_.is_32bit=()=>(p?.magic??0)===267,_.is_64bit=()=>(p?.magic??0)===523,_}function xe(n){return!n||n.error?null:{machine:n.machine,entry_point:n.entry_point,image_base:n.image_base,number_of_sections:n.number_of_sections,sections:n.sections,imports:n.imports,exports:n.exports,imphash:n.imphash,rich_signature:n.rich_signature,digital_signature:n.digital_signature,size_of_code:n.size_of_code,size_of_initialized_data:n.size_of_initialized_data,size_of_uninitialized_data:n.size_of_uninitialized_data,address_of_entry_point:n.address_of_entry_point,base_of_code:n.base_of_code,base_of_data:n.base_of_data,section_alignment:n.section_alignment,file_alignment:n.file_alignment,subsystem:n.subsystem,dll_characteristics:n.dll_characteristics,is_dll:n.is_dll,is_32bit:n.is_32bit,is_64bit:n.is_64bit,imports_dll:e=>{let t=e.toLowerCase();return n.imports.some(r=>r.dll.toLowerCase()===t)},importsFunction:(e,t)=>{let r=e.toLowerCase(),i=n.imports.find(o=>o.dll.toLowerCase()===r);if(!i)return!1;if(!t)return!0;let s=t.toLowerCase();return i.functions.some(o=>o.name&&o.name.toLowerCase()===s)},exports_function:e=>{let t=e.toLowerCase();return n.exports.some(r=>r.toLowerCase()===t)},MACHINE_I386:332,MACHINE_AMD64:34404,MACHINE_ARM:448,MACHINE_ARM64:43620,SUBSYSTEM_NATIVE:1,SUBSYSTEM_WINDOWS_GUI:2,SUBSYSTEM_WINDOWS_CUI:3,SECTION_CNT_CODE:32,SECTION_CNT_INITIALIZED_DATA:64,SECTION_CNT_UNINITIALIZED_DATA:128,SECTION_MEM_EXECUTE:536870912,SECTION_MEM_READ:1073741824,SECTION_MEM_WRITE:2147483648}}var kr=[127,69,76,70],Gr=1,Xr=14,Yr=15,Kr=29;function Zr(n){let e=new DataView(n.buffer,n.byteOffset,n.byteLength);for(let s=0;s<4;s++)if(n[s]!==kr[s])throw new Error("Not ELF");let t=n[4],r=n[5]===1,i={is64bit:t===2,littleEndian:r};return i.type=N(e,16,r),i.machine=N(e,18,r),i.entry_point=i.is64bit?P(e,24,r):E(e,24,r),i.phoff=i.is64bit?P(e,32,r):E(e,28,r),i.shoff=i.is64bit?P(e,40,r):E(e,32,r),i.phentsize=i.is64bit?N(e,54,r):N(e,42,r),i.phnum=i.is64bit?N(e,56,r):N(e,44,r),i.shentsize=i.is64bit?N(e,58,r):N(e,46,r),i.shnum=i.is64bit?N(e,60,r):N(e,48,r),i.shstrndx=i.is64bit?N(e,62,r):N(e,50,r),i}function Qr(n,e){let t=[],r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=e.phoff;for(let s=0;s<e.phnum;s++){let o,u,a,p,d,m,b;e.is64bit?(o=E(r,i,e.littleEndian),m=E(r,i+4,e.littleEndian),u=P(r,i+8,e.littleEndian),a=P(r,i+16,e.littleEndian),p=P(r,i+32,e.littleEndian),d=P(r,i+40,e.littleEndian),b=P(r,i+48,e.littleEndian),i+=56):(o=E(r,i,e.littleEndian),u=E(r,i+4,e.littleEndian),a=E(r,i+8,e.littleEndian),p=E(r,i+16,e.littleEndian),d=E(r,i+20,e.littleEndian),m=E(r,i+24,e.littleEndian),b=E(r,i+28,e.littleEndian),i+=32),t.push({type:o,offset:u,vaddr:a,filesz:p,memsz:d,flags:m,align:b})}return t}async function Jr(n,e){let t=[],r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=e.shoff;for(let s=0;s<e.shnum;s++){let o=e.is64bit?P(r,i+24,e.littleEndian):E(r,i+16,e.littleEndian),u=e.is64bit?P(r,i+32,e.littleEndian):E(r,i+20,e.littleEndian),a=o+u<=n.length?n.slice(o,o+u):new Uint8Array,p=B(a),d=await D("SHA-1",a),m=await D("SHA-256",a);t.push({offset:o,size:u,entropy:le(a),raw_data:a,md5:p,sha1:d,sha256:m}),i+=e.is64bit?64:40}return t}function en(n,e,t){let r=e.find(_=>_.raw_data&&_.raw_data.length>0&&_.name===".dynamic"),i=e.find(_=>_.raw_data&&_.raw_data.length>0&&_.name===".dynstr");if(!r||!i)return{needed_libraries:[],soname:null,rpath:null,runpath:null};let s=r.raw_data,o=i.raw_data,u=new DataView(s.buffer,s.byteOffset,s.byteLength),a=t.is64bit?16:8,p=[],d=null,m=null,b=null;for(let _=0;_+a<=s.length;_+=a){let U=t.is64bit?P(u,_,t.littleEndian):E(u,_,t.littleEndian),v=t.is64bit?P(u,_+8,t.littleEndian):E(u,_+4,t.littleEndian);U===Gr?p.push(G(o,v)):U===Xr?d=G(o,v):U===Yr?m=G(o,v):U===Kr&&(b=G(o,v))}return{needed_libraries:p,soname:d,rpath:m,runpath:b}}function tn(n,e,t){let r=[],i=e.find(d=>d.name===".dynsym"),s=e.find(d=>d.name===".dynstr");if(!i||!s)return r;let o=i.raw_data,u=s.raw_data,a=new DataView(o.buffer,o.byteOffset,o.byteLength),p=t.is64bit?24:16;for(let d=0;d+p<=o.length;d+=p){let m=E(a,d,t.littleEndian);if(m>=u.length)continue;let b=G(u,m);b&&r.push(b)}return r}async function Oe(n){n instanceof ArrayBuffer&&(n=new Uint8Array(n));let e=n.length,t;try{t=Zr(n)}catch(b){return{error:"Invalid ELF file",message:b.message}}let r=Qr(n,t),i=await Jr(n,t),{needed_libraries:s,soname:o,rpath:u,runpath:a}=en(n,i,t),p=tn(n,i,t),d=(r?.map(b=>b.vaddr)||[0])[0],m=(r?.map(b=>b.offset)||[0])[0];return{type:t.type,machine:t.machine,entry_point:t.entry_point-d+m,is_64bit:t.is64bit,endianness:t.littleEndian?"little":"big",file_size:e,program_headers:r,sections:i,imports:s.map(b=>({dll:b,functions:[]})),exports:p,needed_libraries:s,soname:o,rpath:u,runpath:a,hashes:{}}}function Se(n){return!n||n.error?null:{type:n.type||0,machine:n.machine||0,entry_point:n.entry_point||0,file_size:n.file_size||0,is_64bit:n.is_64bit||!1,endianness:n.endianness||"little",sections:n.sections||[],number_of_sections:(n.sections||[]).length,program_headers:n.program_headers||[],segments:n.program_headers||[],number_of_segments:(n.program_headers||[]).length,imports:n.needed_libraries||[],exports:n.exports||[],needed_libraries:n.needed_libraries||[],soname:n.soname||null,rpath:n.rpath||null,runpath:n.runpath||null,is_32bit(){return!this.is_64bit},is_little_endian(){return this.endianness==="little"},is_big_endian(){return this.endianness==="big"},imports_library(t){return this.needed_libraries.some(r=>r.toLowerCase().includes(t.toLowerCase()))},exports_function(t){return this.exports.some(r=>r===t)},get_section_by_name(t){return this.sections.find(r=>r.name===t)},ET_NONE:0,ET_REL:1,ET_EXEC:2,ET_DYN:3,ET_CORE:4,EM_NONE:0,EM_386:3,EM_X86_64:62,EM_ARM:40,EM_AARCH64:183,ARCH_X86:3,ARCH_X86_64:62,ARCH_ARM:40,ARCH_AARCH64:183,TYPE_EXEC:2,TYPE_DYN:3,TYPE_CORE:4}}function X(n){return new TextEncoder().encode(n)}function Ee(n){if(n.length===0)return 0;let e=new Uint32Array(256);for(let i=0;i<n.length;i++)e[n[i]]++;let t=0,r=n.length;for(let i=0;i<256;i++)if(e[i]>0){let s=e[i]/r;t-=s*Math.log2(s)}return t}function Ce(n){if(n.length===0)return 0;let e=0;for(let t=0;t<n.length;t++)e+=n[t];return e/n.length}function wt(n,e){if(n.length===0)return 0;let t=0;for(let r=0;r<n.length;r++){let i=n[r]-e;t+=i*i}return Math.sqrt(t/n.length)}function vt(n){if(n.length<2)return 0;let e=0,t=0;for(let r=0;r<n.length-1;r+=2){let i=n[r]/255*2-1,s=n[r+1]/255*2-1;i*i+s*s<=1&&e++,t++}return t===0?0:4*e/t}function bt(n){if(n.length<2)return 0;let e=Ce(n),t=0,r=0;for(let i=0;i<n.length-1;i++)t+=(n[i]-e)*(n[i+1]-e);for(let i=0;i<n.length;i++){let s=n[i]-e;r+=s*s}return r===0?0:t/r}function rn(...n){if(n.length===0)throw new Error("No data provided");return Math.min(...n)}function nn(...n){if(n.length===0)throw new Error("No data provided");return Math.max(...n)}function sn(n,e){let t=0;for(let r=0;r<e.length;r++)e[r]===n&&t++;return t}function on(n){if(n.length===0)return 0;let e=new Uint32Array(256);for(let i=0;i<n.length;i++)e[n[i]]++;let t=0,r=0;for(let i=0;i<256;i++)e[i]>t&&(t=e[i],r=i);return r}function Ie(n){if(!n||!(n instanceof Uint8Array))throw new Error("Math module requires a Uint8Array data buffer");return{entropy:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=X(e[0]);return Ee(t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let i=n.slice(t,t+r);return i.length===0?0:Ee(i)}else throw new Error("entropy() requires either (offset, size) or (string)")},monte_carlo_pi:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=X(e[0]);return vt(t)}else if(e.length===2){let[t,r]=e;if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let i=n.slice(t,t+r);return i.length===0?0:vt(i)}else throw new Error("monte_carlo_pi() requires (offset, size)")},serial_correlation:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=X(e[0]);return bt(t)}else if(e.length===2){let[t,r]=e;if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let i=n.slice(t,t+r);return i.length===0?0:bt(i)}else throw new Error("serial_correlation() requires (offset, size)")},mean:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=X(e[0]);return Ce(t)}else if(e.length===2){let[t,r]=e;if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let i=n.slice(t,t+r);return i.length===0?0:Ce(i)}else throw new Error("mean() requires (offset, size)")},deviation:function(...e){if(e.length===2&&typeof e[0]=="string"){let[t,r]=e,i=X(t);return wt(i,r)}else if(e.length===3){let[t,r,i]=e;if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let s=n.slice(t,t+r);return s.length===0?0:wt(s,i)}else throw new Error("deviation() requires (offset, size, mean)")},min:function(e,t){return rn(e,t)},max:function(e,t){return nn(e,t)},count:function(e,t,r){if(e<0||e>255)throw new Error(`Invalid byte value: ${e} (must be 0-255)`);if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return i.length===0?0:sn(e,i)},percentage:function(e,t,r){return this.count(e,t,r)/r},mode:function(e,t){if(e<0||t<0)throw new Error(`Invalid range: offset=${e}, size=${t}, data.length=${n.length}`);let r=n.slice(e,e+t);return r.length===0?0:on(r)},abs:function(e){return Math.abs(e)},to_number:function(e){return e?1:0},in_range:function(e,t,r){return e>=t&&e<=r}}}var an={entropy:function(n){let e=X(n);return Ee(e)},abs:function(n){return Math.abs(n)},to_number:function(n){return n?1:0},in_range:function(n,e,t){return n>=e&&n<=t}};function H(n){return new TextEncoder().encode(n)}function ze(n){let e=0;for(let t=0;t<n.length;t++)e=e+n[t]>>>0;return e&4294967295}var un=(()=>{let n=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let r=0;r<8;r++)t=t&1?3988292384^t>>>1:t>>>1;n[e]=t}return n})();function $e(n){let e=4294967295;for(let t=0;t<n.length;t++)e=e>>>8^un[(e^n[t])&255];return e=(e^4294967295)>>>0,e}function Re(n){if(!n||!(n instanceof Uint8Array))throw new Error("Hash module requires a Uint8Array data buffer");return{md5:async function(...e){if(e.length===1&&typeof e[0]=="string"){let t=H(e[0]);return B(t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return B(i)}else throw new Error("md5() requires either (offset, size) or (string)")},sha1:async function(...e){if(e.length===1&&typeof e[0]=="string"){let t=H(e[0]);return await D("SHA-1",t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0||t+r>n.length)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return await D("SHA-1",i)}else throw new Error("sha1() requires either (offset, size) or (string)")},sha256:async function(...e){if(e.length===1&&typeof e[0]=="string"){let t=H(e[0]);return await D("SHA-256",t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0||t+r>n.length)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return await D("SHA-256",i)}else throw new Error("sha256() requires either (offset, size) or (string)")},checksum32:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=H(e[0]);return ze(t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return i.length===0?0:ze(i)}else throw new Error("checksum32() requires either (offset, size) or (string)")},crc32:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=H(e[0]);return $e(t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return i.length===0?0:$e(i)}else throw new Error("crc32() requires either (offset, size) or (string)")}}}var fn={md5:async function(n){let e=H(n);return B(e)},sha1:async function(n){let e=H(n);return await D("SHA-1",e)},sha256:async function(n){let e=H(n);return await D("SHA-256",e)},checksum32:function(n){let e=H(n);return ze(e)},crc32:function(n){let e=H(n);return $e(e)}};var Te={now:()=>Date.now()};var De={to_int:(n,e=10)=>{if(typeof n!="string"&&!(n instanceof String))throw new Error("to_int() first argument must be a string");n.startsWith("0x")||n.startsWith("0X")?(e=16,n=n.slice(2)):(n.startsWith("O")||n.startsWith("o"))&&(e=8,n=n.slice(1));let t=parseInt(n,e);if(isNaN(t))throw new Error(`to_int() could not convert string '${n}' to integer`);return t},length:n=>typeof n=="string"||n instanceof String?n.length:0};var _t=typeof console<"u"&&typeof console.log=="function"?(...n)=>console.log(...n):()=>{},ln=typeof globalThis<"u"&&globalThis.performance&&typeof globalThis.performance.now=="function";function cn(){return ln?globalThis.performance.now():Date.now()}function hn(n){return n==null?n:JSON.parse(JSON.stringify(n))}var Ne=class{constructor(e={}){let t=e.enabled??e.enableTiming??!1,r=e.logger??_t,i=e.autoPrint??!1;this.options={enabled:!!t,logger:r,autoPrint:!!i},this.lastTiming={compile:null,scan:null}}isEnabled(){return!!this.options.enabled}now(){return cn()}updateOptions(e={}){(Object.prototype.hasOwnProperty.call(e,"enabled")||Object.prototype.hasOwnProperty.call(e,"enableTiming"))&&(this.options.enabled=!!(e.enabled??e.enableTiming)),Object.prototype.hasOwnProperty.call(e,"logger")&&(this.options.logger=e.logger??_t),Object.prototype.hasOwnProperty.call(e,"autoPrint")&&(this.options.autoPrint=!!e.autoPrint)}enable(e=!0,t){this.updateOptions({enabled:e,logger:t})}clearCompile(){this.lastTiming.compile=null}clearScan(){this.lastTiming.scan=null}recordCompile(e){let t={total:e};this.lastTiming.compile=t,this.printTiming("compile",t)}createScanTiming(){return{total:0,steps:{buildAutomaton:0,acSearch:0,deduplicate:0,verifyCandidates:0,buildMatches:0,evaluateConditions:0,filterStrings:0},modules:{total:0,pe:0,elf:0,math:0,hash:0},conditionParsing:{total:0,byRule:{}},matchCount:0}}finalizeScan(e){this.lastTiming.scan=e,this.printTiming("scan",e)}accumulateStep(e,t,r){!e||!Number.isFinite(r)||(e[t]=(e[t]||0)+r)}accumulateModule(e,t,r){!e||!Number.isFinite(r)||(e.total=(e.total||0)+r,e[t]=(e[t]||0)+r)}accumulateCondition(e,t,r){!e||!Number.isFinite(r)||(e.total=(e.total||0)+r,e.byRule||(e.byRule={}),e.byRule[t]=(e.byRule[t]||0)+r)}getSnapshot(){return hn(this.lastTiming)}printTiming(e,t){if(!this.options.enabled||!this.options.autoPrint||!this.options.logger||!t)return;let r=this.options.logger;if(e==="compile"){r(`[InterceptScanner] Compile completed in ${t.total.toFixed(3)}ms`);return}if(e==="scan"){let i=t.matchCount??"n/a";r(`[InterceptScanner] Scan completed in ${t.total.toFixed(3)}ms (matches: ${i})`),t.steps&&Object.entries(t.steps).forEach(([s,o])=>{o!=null&&r(` \u2022 ${s}: ${o.toFixed(3)}ms`)}),t.modules&&t.modules.total&&r(` \u2022 moduleCreation.total: ${t.modules.total.toFixed(3)}ms`),t.conditionParsing&&t.conditionParsing.total&&r(` \u2022 conditionParsing.total: ${t.conditionParsing.total.toFixed(3)}ms`)}}};function Ut(n={}){return new Ne(n)}var Pe=class{constructor(e){if(this._isLoaded=!1,this._name=e,!je(e))throw new Error(`Invalid module name: "${e}". It is either reserved or malformed.`)}getName(){return this._name}isLoaded(){return this._isLoaded}async load(){return this._isLoaded=!0,this._isLoaded}async initialize(e,t){throw new Error("CustomModule.initialize() must be implemented")}createModule(e){throw new Error("CustomModule.createModule() must be implemented")}},pn=["pe","elf","math","hash","string","time","filesize","entrypoint"];function je(n){if(!n||typeof n!="string")return!1;let e=n.toLowerCase();return!pn.includes(e)}var he=class{constructor(e={}){this.compiledRules=[],this.ac=null,this.autoParsePE=!0,this.autoParseELF=!0,this.maxFileSize=1024*1024,this.setModules(e.modules),this.customModules=e.modules||{};let t={enabled:e.timing?.enabled??e.timing?.enableTiming??e.enableTiming??!1,autoPrint:e.timing?.autoPrint??e.autoPrint??!1,logger:e.timing?.logger??e.timingLogger??e.logger};this.timingTracker=Ut(t)}compile(e){let t=this.timingTracker,r=t?.isEnabled(),i=r?t.now():0;this.compiledRules=qe(e,this.compiledRules||[]),this.ac=null,r?t.recordCompile(t.now()-i):t&&t.clearCompile()}addRules(e){this.compile(e)}clearRules(){this.compiledRules=[],this.ac=null}setModules(e){this.modules={string:De,time:Te,...e||{}}}setTiming(e={}){this.timingTracker.updateOptions(e)}enableTiming(e=!0,t){this.timingTracker.enable(e,t)}getTiming(){return this.timingTracker.getSnapshot()}deduplicateCandidates(e){let t=new Map;for(let r of e){let i=`${r.id}:${r.varName}:${r.offset}`;t.has(i)||t.set(i,r)}return Array.from(t.values())}verifyCandidates(e,t,r){let i=[];for(let s of e){let o=r.find(a=>a.id===s.id);if(!o)continue;let u=o.strings[s.varName];if(!(!u||!u.matcher))if(u.type==="text"||u.type==="regex"&&u.literalPrefix){let a=typeof u.matcher.verifyAt=="function"?u.matcher.verifyAt(t,s.offset):u.matcher(t,s.offset);a&&a.length>0&&i.push({...s,matches:a})}else i.push(s)}return i}buildStringMatches(e,t,r){let i={};for(let o of t){i[o.id]={};for(let u of Object.keys(o.strings)){let a=u.startsWith("$")||u.startsWith(".")?u:`$${u}`,p=a.startsWith(".")?`$${a}`:a,d=u.startsWith(".")?`$${u}`:a;i[o.id][d]={identifier:d,matched:!1,count:0,matches:[],offsets:[],private:o.strings[u].private}}}for(let o of e){let u=o.varName.startsWith(".")?`$${o.varName}`:o.varName,a=i[o.id][u]||u.startsWith("$")?u:`$${u}`,p=i[o.id][a];if(o.matches&&o.matches.length>0){let d=o.matches.length>100?o.matches.slice(0,100):o.matches;p.matched=!0,p.count+=d.length,p.matches.push(...d),p.offsets.push(...o.matches.map(m=>m.offset))}else p.matched=!0,p.count+=1,p.matches.push({offset:o.offset,length:o.length||0}),p.offsets.push(o.offset)}let s=null;for(let o of t)for(let[u,a]of Object.entries(o.strings)){if(a.type==="text"||a.type==="regex"&&a.literalPrefix?.length>0)continue;let p=u.startsWith(".")?`$${u}`:u,d=i[o.id][p]||p.startsWith("$")?p:`$${p}`,m=i[o.id][d];a.type==="hex"&&s===null&&(s=Array.from(r).map(_=>_.toString(16).toUpperCase().padStart(2,"0")).join(""));let b=a.type==="hex"&&s!==null?a.matcher(s,-1):a.matcher(r,-1);if(b&&b.length>0){let _=b.length>100?b.slice(0,100):b;m.matched=!0,m.count+=_.length,m.matches.length===0?m.matches=_:m.matches.push(..._),m.offsets.push(...b.map(U=>U.offset))}}return i}async evaluateConditions(e,t,r,i={},s=null){let o=[],u={},a=s?.tracker,p=s?.modules,d=this.modules.pe;if(this.autoParsePE&&!d){let g=a?a.now():0;try{if(r.length>2&&r[0]===77&&r[1]===90){let f=await Ae(r);f&&!f.error&&(d=xe(f))}}catch{}finally{a&&p&&a.accumulateModule(p,"pe",a.now()-g)}}let m=this.modules.elf;if(this.autoParseELF&&!m){let g=a?a.now():0;try{if(r.length>4&&r[0]===127&&r[1]===69&&r[2]===76&&r[3]===70){let f=await Oe(r);f&&!f.error&&(m=Se(f))}}catch{}finally{a&&p&&a.accumulateModule(p,"elf",a.now()-g)}}let b={...this.modules,...d&&{pe:d},...m&&{elf:m}},_=a?a.now():0;b.math=Ie(r),a&&p&&a.accumulateModule(p,"math",a.now()-_);let U=a?a.now():0;b.hash=Re(r),a&&p&&a.accumulateModule(p,"hash",a.now()-U);let v=new Set;for(let[g,f]of Object.entries(this.modules))try{if(typeof f?.getName=="function"){let l=f.getName();if(!je(l)){console.warn(`InterceptScanner: Custom module "${l}" has reserved name - skipping initialization`);continue}if(typeof f.isLoaded=="function"&&!f.isLoaded()){let S=a?a.now():0;typeof f.load=="function"&&await f.load(),a&&p&&a.accumulateModule(p,`${l}_load`,a.now()-S)}let c=a?a.now():0,h={...i,filesize:r.length,hasPE:!!d,hasELF:!!m,timestamp:Date.now()},x=f;if(typeof f.initialize=="function"&&typeof f.createModule=="function"){let S=await f.initialize(r,h);x=f.createModule(S)}a&&p&&a.accumulateModule(p,l,a.now()-c),v.has(l)&&console.warn(`InterceptScanner: duplicate custom module name "${l}" - the later instance replaces the earlier one`),v.add(l),b[l]=x}}catch(l){console.warn(`InterceptScanner: Error initializing custom module "${g}": ${l.message}`)}let w=t.filter(g=>g.global);for(let g of w){let f=await this.evaluateRuleCondition(e,g,r,u,{peModule:d,elfModule:m,modulesWithBinary:b},s);if(f)g.private||o.push(f);else return o}let y=t.filter(g=>!g.global);for(let g of y){let f=await this.evaluateRuleCondition(e,g,r,u,{peModule:d,elfModule:m,modulesWithBinary:b},s);f&&!g.private&&o.push(f)}for(let[g,f]of Object.entries(b))if(!["string","time","hash","math"].includes(g)){o[g]={};for(let[l,c]of Object.entries(f))!l.startsWith("_")&&typeof c!="function"&&!/[A-Z0-9]+/.test(l)&&(o[g][l]=typeof c=="object"?Me({...c},["raw_data","data"]):c)}return o}async evaluateRuleCondition(e,t,r,i,s={},o=null){let{peModule:u,elfModule:a,modulesWithBinary:p}=s,d=o?.tracker,m=o?.condition;try{let b=u?u.entry_point:a?a.entry_point:-1e6,_=r.length,U=_>=this.maxFileSize,v=Ge(r,e[t.id],p,{entrypoint:b,filesize:_,isFileSizeCapped:U,maxFileSize:this.maxFileSize,matchedRules:i,metadata:{ruleName:t.name}}),w,y=d?d.now():0;try{w=Je(t.condition,v.strings)}catch{w=this.parseSimpleCondition(t.condition,v.strings)}finally{d&&m&&d.accumulateCondition(m,t.name,d.now()-y)}let g=await Xe(w,v);if(i[t.name]=g,g){let f={};for(let[l,c]of Object.entries(e[t.id]))!l.startsWith("$.")&&!c.private&&(f[l]=c);return{rule:t.name,namespace:t.namespace||"default",tags:t.tags||[],metadata:t.metadata||{},strings:f}}}catch(b){console.debug("Failing rule: ",t),console.trace(b)}return!1}parseSimpleCondition(e,t){if(e=e.trim(),e==="any of them")return{type:"any",items:"them"};if(e==="all of them")return{type:"all",items:"them"};if(e==="none of them")return{type:"none",items:"them"};let r=e.match(/^(\d+)\s+of\s+them$/);if(r)return{type:"quantified",quantifier:{type:"number",value:parseInt(r[1])},items:"them"};let i=e.match(/^\$(\w+)$/);if(i)return{type:"stringIdentifier",identifier:`$${i[1]}`};let s=e.match(/^\(?(\$\w+)\s+and\s+(\$\w+)\)?$/);if(s)return{type:"and",left:{type:"stringIdentifier",identifier:s[1]},right:{type:"stringIdentifier",identifier:s[2]}};let o=e.match(/^\(?(\$\w+)\s+or\s+(\$\w+)\)?$/);return o?{type:"or",left:{type:"stringIdentifier",identifier:o[1]},right:{type:"stringIdentifier",identifier:o[2]}}:{type:"boolean",value:!1}}filterStringResults(e){Array.isArray(e)&&e.forEach(t=>{if(Object.keys(t.strings).length>0)for(let[r,i]of Object.entries(t.strings))i.matched||delete t.strings[r]})}async scan(e,t={}){let r=this.timingTracker,i=r?.isEnabled(),s=i?r.now():0,o=i?r.createScanTiming():null;if(typeof e=="string"&&(e=new TextEncoder().encode(e)),!this.compiledRules||this.compiledRules.length===0)return i&&o?(o.total=r.now()-s,o.matchCount=0,r.finalizeScan(o)):r&&r.clearScan(),[];if(!this.ac)if(i&&o){let f=r.now();this.ac=new Y(this.compiledRules),r.accumulateStep(o.steps,"buildAutomaton",r.now()-f)}else this.ac=new Y(this.compiledRules);let u=i?r.now():0,a=this.ac.search(e);i&&o&&r.accumulateStep(o.steps,"acSearch",r.now()-u);let p=i?r.now():0,d=this.deduplicateCandidates(a);i&&o&&r.accumulateStep(o.steps,"deduplicate",r.now()-p);let m=i?r.now():0,b=this.verifyCandidates(d,e,this.compiledRules);i&&o&&r.accumulateStep(o.steps,"verifyCandidates",r.now()-m);let _=i?r.now():0,U=this.buildStringMatches(b,this.compiledRules,e);i&&o&&r.accumulateStep(o.steps,"buildMatches",r.now()-_);let v=null,w=0;i&&o&&(v={tracker:r,modules:o.modules,condition:o.conditionParsing},w=r.now());let y=await this.evaluateConditions(U,this.compiledRules,e,t,v);i&&o&&r.accumulateStep(o.steps,"evaluateConditions",r.now()-w);let g=i?r.now():0;return this.filterStringResults(y),i&&o?(r.accumulateStep(o.steps,"filterStrings",r.now()-g),o.total=r.now()-s,o.matchCount=y.length,r.finalizeScan(o)):r&&r.clearScan(),y}setMaxFileSize(e){this.maxFileSize=e}getStats(){return{totalRules:this.compiledRules.length,ruleNames:this.compiledRules.map(e=>e.name),rulesWithStrings:this.compiledRules.filter(e=>Object.keys(e.strings).length>0).length,totalStrings:this.compiledRules.reduce((e,t)=>e+Object.keys(t.strings).length,0),totalPatterns:this.compiledRules.reduce((e,t)=>e+Object.values(t.strings).reduce((r,i)=>r+(i.patterns?i.patterns.length:0),0),0),acBuilt:this.ac!==null,maxFileSize:this.maxFileSize}}clear(){this.compiledRules=[],this.ac=null,this.setModules(this.customModules)}};function Me(n,e){return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||n===null?n:Array.isArray(n)?n.map(t=>Me(t,e)):n!==null&&typeof n=="object"?Object.fromEntries(Object.entries(n).filter(([t])=>!e.includes(t)).map(([t,r])=>[t,Me(r,e)])):n}export{Pe as BaseCustomModule,he as InterceptScanner,he as YaraScanner,Se as createELFModule,Re as createHashModule,Ie as createMathModule,xe as createPEModule,fn as hash,an as math,Oe as parseELFYaraFull,Ae as parsePEYara,De as string,Te as time};
|
|
15
|
+
`),t++}else e+=n[t++];return e}function K(n){let e=0,t=0,r=!1,i=null,s=0;for(;s<n.length;){let o=n[s];if(r&&o==="\\"&&s+1<n.length){s+=2;continue}(o==='"'||o==="'")&&!r?(r=!0,i=o):o===i&&r?(r=!1,i=null):r||(o==="{"?e++:o==="}"&&t++),s++}return{openCount:e,closeCount:t}}function Ut(n,e=[],t={}){At(n),n=n.replace(/^\s*import\s+"[^"]+"\s*$/gm,"");let r=e??[],i="",s=0,o=!1,u=0,a=n.split(`
|
|
16
|
+
`);for(let l of a){if(u>0){let p=K(l);u+=p.openCount-p.closeCount;continue}if(!o&&xt.test(l)){let p=K(l),h=p.openCount-p.closeCount;u=h>0?h:0;continue}if(!o&&_t.test(l)){o=!0,i=l+`
|
|
17
|
+
`;let p=K(l);s=p.openCount-p.closeCount;let h=p.openCount>0;s===0&&h&&(r.push(bt(i,t)),o=!1,i="")}else if(o){i+=l+`
|
|
18
|
+
`;let p=K(l);s+=p.openCount-p.closeCount,s===0&&(r.push(bt(i,t)),o=!1,i="")}}return r.forEach((l,p)=>{l.id=p+1}),r}function Ot(n,e=[],t={}){At(n),n=n.replace(/^\s*import\s+"[^"]+"\s*$/gm,"");let r=[...e??[]],i=[],s="",o=0,u=!1,a=0,l=p=>{let{rule:h,diagnostics:w}=Bn(p,t);i.push(...w);let _=r.findIndex(x=>x.name===h.name);_>=0?(i.push({code:"duplicate-filter-rule",severity:"warning",message:`Filter rule "${h.name}" redefined; the later definition replaces the earlier one`,filter:h.name}),r[_]=h):r.push(h)};for(let p of n.split(`
|
|
19
|
+
`)){if(a>0){let h=K(p);a+=h.openCount-h.closeCount;continue}if(!u&&xt.test(p)){u=!0,s=p+`
|
|
20
|
+
`;let h=K(p);o=h.openCount-h.closeCount,o===0&&h.openCount>0&&(l(s),u=!1,s="");continue}if(!u&&_t.test(p)){let h=K(p),w=h.openCount-h.closeCount;a=w>0?w:0;continue}if(u){s+=p+`
|
|
21
|
+
`;let h=K(p);o+=h.openCount-h.closeCount,o===0&&(l(s),u=!1,s="")}}return r.forEach(p=>{p.id=`filter:${p.name}`}),{rules:r,diagnostics:i}}function Bn(n,e={}){let t=St(n).trim(),r=[],i=t.search(/\brule\b/i),s=i>=0?t.slice(0,i):"";if(/\bglobal\b/i.test(s))throw new Error("Invalid Intercept filter rule: global filter rules are not supported");let o=t.match(/^(?:.*)?rule\s+(\w+)(?:\s*:\s*([\w\s]+))?\s*\{/);if(!o)throw new Error("Invalid Intercept filter rule: missing rule declaration");let u=o[1],a=o[2]?o[2].trim().split(/\s+/):[],l=t.match(/\{([\s\S]*)\}/);if(!l)throw new Error("Invalid Intercept filter rule: missing rule body");let p=l[1],h=Ct(p),w=Et(p,e);for(let[b,y]of Object.entries(w))if(y.reject?.length||y.rejectCapture?.length)throw new Error(`Invalid Intercept filter rule "${u}": reject(...) and rejectRECapture(...) are not allowed on string ${b}`);let _=It(p),x=null;try{x=me(_,w)}catch(b){r.push({code:"invalid-filter-condition",severity:"warning",message:`Filter rule "${u}" condition could not be parsed: ${b.message}`,filter:u})}let v=Wn(x,{availableModules:e.availableModules??[],filterName:u,diagnostics:r});return{rule:{name:u,tags:a,metadata:h,strings:w,condition:_,conditionAST:x,usedModules:v,filter:!0,private:!0},diagnostics:r}}function Wn(n,{availableModules:e=[],filterName:t,diagnostics:r}){if(!n)return[];let i=new Set,s=new Set;De(n,a=>{if(a.type==="ruleIdentifier")throw new Error(`Invalid Intercept filter rule "${t}": conditions cannot reference rules ("${a.name}")`);if(a.type==="for"){let l=a.variable;typeof l=="string"?i.add(l):l?.name&&i.add(l.name)}a.type==="moduleFunction"&&typeof a.module=="string"&&s.add(a.module),a.type==="memberAccess"&&a.object?.type==="identifier"&&typeof a.object.name=="string"&&s.add(a.object.name.split(".")[0]),a.type==="identifier"&&typeof a.name=="string"&&a.name.includes(".")&&s.add(a.name.split(".")[0])});let o=new Set([...Pn,...e]),u=[];for(let a of s)if(!i.has(a)){if(a==="pe"||a==="elf")throw new Error(`Invalid Intercept filter rule "${t}": the "${a}" module is not available for candidate buffers`);u.push(a),o.has(a)||r.push({code:"unknown-module",severity:"warning",message:`Filter rule "${t}" references unknown module "${a}"`,filter:t})}return u}function De(n,e){if(!(!n||typeof n!="object")){if(Array.isArray(n)){for(let t of n)De(t,e);return}e(n);for(let t of Object.values(n))t&&typeof t=="object"&&De(t,e)}}function bt(n,e={}){n=St(n).trim();let t=/^.*\bprivate\b.*rule\s+/i.test(n),r=/^.*\bglobal\b.*rule\s+/i.test(n),i=n.match(/^(?:.*)?rule\s+(\w+)(?:\s*:\s*([\w\s]+))?\s*\{/);if(!i)throw new Error("Invalid YARA rule: missing rule declaration");let s=i[1],o=i[2]?i[2].trim().split(/\s+/):[],u=n.match(/\{([\s\S]*)\}/);if(!u)throw new Error("Invalid YARA rule: missing rule body");let a=u[1],l=Ct(a),p=Et(a,e),h=It(a);return{name:s,tags:o,metadata:l,strings:p,condition:h,private:t,global:r}}function Ct(n){let e=n.match(/meta:\s*([\s\S]*?)(?=strings:|condition:|$)/);if(!e)return{};let t=e[1],r={},i=t.match(/(\w+)\s*=\s*("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|(-)?\d+(\.\d+)?|true|false)/g);if(i)for(let s of i){let[,o,u]=s.match(/(\w+)\s*=\s*(.+)/);u.startsWith('"')||u.startsWith("'")?r[o]=u.slice(1,-1):u==="true"||u==="false"?r[o]=u==="true":isNaN(u)?r[o]=u:r[o]=Number(u)}return r}function Et(n,e={}){let t=n.match(/strings:\s*([\s\S]*?)(?=condition:|$)/);if(!t)return{};let r=t[1],i={},s=r.match(/\$\w*\s*=\s*(.*)?/g);if(s){let o=0;for(let u of s){let a=u.match(/\$(\w*)\s*=\s*(.+)/);if(!a)continue;let[,l,p]=a;!l||l===""?l=`.anon_${o++}`:l.startsWith("$")||(l="$"+l);try{let h=lt(p.trim(),e.limits,{includeCaptures:e.includeCaptures});i[l]={definition:p.trim(),...h}}catch(h){console.warn(`Warning: Failed to compile string $${l}: ${h.message}`),console.warn(`Definition: ${p.trim()}`),console.warn(u),console.warn(t),console.warn(n),i[l]={definition:p.trim(),type:null,matcher:null,error:h.message}}}}return i}function It(n){let e=n.match(/condition:\s*([\s\S]*?)$/);if(!e)throw new Error("Invalid YARA rule: missing condition");return e[1].trim().replace(/\}\s*$/,"").trim()}function ye(n,e={},t={},r={}){let i={};for(let[s,o]of Object.entries(e))Array.isArray(o)?i[s]={identifier:s,matched:o.length>0,count:o.length,matches:o,offsets:o.map(u=>u.offset)}:typeof o=="object"&&o!==null&&(i[s]={identifier:s,matched:o.matched??o.count>0,count:o.count??0,matches:o.matches??[],offsets:o.offsets??(o.matches||[]).map(u=>u.offset),...o});return{data:n,filesize:n.length,entrypoint:r.entrypoint??0,isFileSizeCapped:r.isFileSizeCapped??!1,maxFileSize:r.maxFileSize??1024*1024,strings:i,modules:t||{},matchedRules:r.matchedRules||{},metadata:r.metadata||{}}}var zt=new WeakMap;function Vn(n){if(n.error)throw new Error(`Invalid regex literal /${n.pattern}/${n.flags??""} - ${n.error}`);let e=zt.get(n);return e||(e=new RegExp(n.pattern,(n.flags??"").replace(/[gy]/g,"")),zt.set(n,e)),e}var Me=class{constructor(e){this.facts=e,this.data=e.data,this.filesize=e.filesize,this.entrypoint=e.entrypoint,this.isFileSizeCapped=e.isFileSizeCapped??!1,this.maxFileSize=e.maxFileSize??1024*1024,this.strings=e.strings,this.modules=e.modules,this.matchedRules=e.matchedRules||{}}isAnyUndefined(...e){return e.some(t=>t===void 0)}async evaluate(e){return typeof e=="string"&&(e=this.parseCondition(e)),await this.evaluateNode(e)}parseCondition(){throw new Error("String parsing not implemented - pass AST directly")}async evaluateNode(e){if(e==null)return!1;let t=e.type;switch(t){case"boolean":return e.value;case"number":return e.value;case"string":return e.value;case"regex":return Vn(e);case"identifier":return this.resolveIdentifier(e.name);case"ruleIdentifier":return this.evaluateRuleIdentifier(e);case"stringIdentifier":return this.evaluateStringIdentifier(e);case"buffer":return this.bufferText();case"stringCount":return this.getStringCount(e.identifier);case"stringOffset":{let r=e.index;return typeof r=="object"&&(r=await this.evaluateNode(r)),this.getStringOffset(e.identifier,r)}case"stringLength":{let r=e.index;return typeof r=="object"&&(r=await this.evaluateNode(r)),this.getStringLength(e.identifier,r)}case"stringOccurrence":{let r=e.index;typeof r=="object"&&r!==null&&(r=await this.evaluateNode(r));let i=this.getStringOffset(e.identifier,r),s=this.getStringLength(e.identifier,r);return i===void 0||s===void 0||!this.data||typeof this.data.subarray!="function"?void 0:new TextDecoder().decode(this.data.subarray(i,i+s))}case"and":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return!(r===void 0||r===!1||i===void 0||i===!1)}case"or":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return(r===void 0?!1:r)||(i===void 0?!1:i)}case"not":{let r=await this.evaluateNode(e.operand);return this.isAnyUndefined(r)?void 0:!r}case"defined":return await this.evaluateDefined(e.operand);case"equal":return await this.evaluateEqual(e);case"notEqual":return await this.evaluateNotEqual(e);case"lessThan":return await this.evaluateLessThan(e);case"greaterThan":return await this.evaluateGreaterThan(e);case"lessThanOrEqual":return await this.evaluateLessThanOrEqual(e);case"greaterThanOrEqual":return await this.evaluateGreaterThanOrEqual(e);case"add":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r+i}case"subtract":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r-i}case"multiply":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r*i}case"divide":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:Math.floor(r/i)}case"modulo":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r%i}case"bitwiseAnd":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r&i}case"bitwiseOr":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r|i}case"bitwiseXor":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r^i}case"bitwiseNot":{let r=await this.evaluateNode(e.operand);return this.isAnyUndefined(r)?void 0:~r}case"shiftLeft":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r<<i}case"shiftRight":{let r=await this.evaluateNode(e.left),i=await this.evaluateNode(e.right);return this.isAnyUndefined(r,i)?void 0:r>>i}case"contains":return await this.stringContains(e.left,e.right,!1);case"icontains":return await this.stringContains(e.left,e.right,!0);case"startswith":return await this.stringStartsWith(e.left,e.right,!1);case"istartswith":return await this.stringStartsWith(e.left,e.right,!0);case"endswith":return await this.stringEndsWith(e.left,e.right,!1);case"iendswith":return await this.stringEndsWith(e.left,e.right,!0);case"iequals":return await this.stringEquals(e.left,e.right,!0);case"matches":if(e.error)throw new Error(`Invalid "matches" comparison - ${e.error}`);return await this.stringMatches(e.left,e.right);case"in":return await this.evaluateInOperator(e);case"range":return{start:await this.evaluateNode(e.start),end:await this.evaluateNode(e.end)};case"all":return await this.evaluateAll(e.items);case"any":return await this.evaluateAny(e.items);case"none":return await this.evaluateNone(e.items);case"quantified":return await this.evaluateQuantified(e);case"for":return await this.evaluateFor(e);case"memberAccess":return await this.evaluateMemberAccess(e);case"arrayAccess":return await this.evaluateArrayAccess(e);case"functionCall":return await this.evaluateFunctionCall(e);case"dataAccess":return this.evaluateDataAccess(e);case"at":return await this.evaluateAt(e);case"inRange":return await this.evaluateInRange(e);case"within":return await this.evaluateWithin(e);case"moduleFunction":return await this.evaluateModuleFunction(e);default:throw new Error(`Unknown node type: ${t}`)}}bufferText(){return this._bufferText===void 0&&(this._bufferText=this.data?new TextDecoder().decode(this.data):""),this._bufferText}resolveIdentifier(e){if(this.forContext&&e in this.forContext)return this.forContext[e];let t=e?.split(".");switch(e=t[0],e){case"filesize":return this.filesize;case"entrypoint":if(typeof this.entrypoint!="number")throw new Error("Entrypoint is not defined");return this.entrypoint;default:if(this.modules&&e in this.modules){if(!this.modules[e])return this.modules[e];let r=this.modules;for(let i of t)if(r=r[i],!r)return r;return r}if(["pe","elf","hash","math","string","time"].includes(e))return;throw new Error(`Unknown identifier: ${e}`)}}isFilesizeNode(e){return e&&e.type==="identifier"&&e.name==="filesize"}async evaluateEqual(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return this.isFilesizeNode(e.left)&&this.isFileSizeCapped&&r>=this.maxFileSize||this.isFilesizeNode(e.right)&&this.isFileSizeCapped&&t>=this.maxFileSize?!0:t===r}async evaluateNotEqual(e){let t=await this.evaluateEqual(e);if(!this.isAnyUndefined(t))return!t}async evaluateLessThan(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return t<r}async evaluateGreaterThan(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return this.isFilesizeNode(e.left)&&this.isFileSizeCapped&&r>=this.maxFileSize?!0:t>r}async evaluateLessThanOrEqual(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return t<=r}async evaluateGreaterThanOrEqual(e){let t=await this.evaluateNode(e.left),r=await this.evaluateNode(e.right);if(!this.isAnyUndefined(t,r))return this.isFilesizeNode(e.left)&&this.isFileSizeCapped&&r>=this.maxFileSize?!0:t>=r}evaluateStringIdentifier(e){let t=e.identifier;t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$);let r=this.strings[t];return r?r.matched&&r.count>0:!1}evaluateRuleIdentifier(e){let t=e.name;return t in this.matchedRules?this.matchedRules[t]===!0:!1}getStringCount(e){e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$);let t=this.strings[e];return t?t.count:0}getStringOffset(e,t=0){e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$),typeof t=="string"&&this.forContext&&t in this.forContext&&(t=this.forContext[t]);let r=this.strings[e];if(!r||!r.offsets||r.offsets.length===0)return;let i=t===0?0:t-1;return r.offsets[i]}getStringLength(e,t=0){e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$),typeof t=="string"&&this.forContext&&t in this.forContext&&(t=this.forContext[t]);let r=this.strings[e];if(!r||!r.matches||r.matches.length===0)return;let i=t===0?0:t-1,s=r.matches[i];return s?s.length:void 0}evaluateAll(e){let t=this.resolveStringSet(e);return t.length===0?!1:t.every(r=>{let i=this.strings[r];return i&&i.matched&&i.count>0})}evaluateAny(e){let t=this.resolveStringSet(e);return t.length===0?!1:t.some(r=>{let i=this.strings[r];return i&&i.matched&&i.count>0})}evaluateNone(e){let t=this.resolveStringSet(e);return t.length===0?!0:t.every(r=>{let i=this.strings[r];return!i||!i.matched||i.count===0})}evaluateQuantified(e){let t=this.resolveStringSet(e.items);if(t.length===0)return!1;let r=t.filter(s=>{let o=this.strings[s];return o&&o.matched&&o.count>0}).length,i=e.quantifier;if(i.type==="number")return r>=i.value;if(i.type==="percentage"){let s=Math.ceil(t.length*i.value/100);return r>=s}else if(i.type==="range"){let s=i.min,o=i.max;return r>=s&&r<=o}return!1}resolveStringSet(e){if(e==="them")return Object.keys(this.strings);if(Array.isArray(e)){let t=[];for(let r of e)if(r.includes("*")){let i=r.replace(/\*/g,".*").replace(/\$/g,"\\$"),s=new RegExp("^"+i+"$"),o=Object.keys(this.strings).filter(u=>s.test(u));t.push(...o)}else t.push(r);return t}if(typeof e=="string"){if(e.includes("*")){let t=e.replace(/\*/g,".*").replace(/\$/g,"\\$"),r=new RegExp("^"+t+"$");return Object.keys(this.strings).filter(i=>r.test(i))}return[e]}return[]}async evaluateFor(e){let t=e.quantifier,r=e.variable,i=e.set,s=e.condition,o=[];if(i.type==="stringSet"){if(o=this.resolveStringSet(i.items),o.length===0)return t==="all"}else if(i.type==="range"){let p=await this.evaluateNode(i.start),h=await this.evaluateNode(i.end);if(typeof p!="number"||typeof h!="number")throw new Error(`Invalid range values: ${p} to ${h}`);for(let w=p;w<=h;w++)o.push(w);if(o.length===0)return t==="all"}else{let p=await this.evaluateNode(i);Array.isArray(p)?o=p:o=[p]}if(o.length===0)return t==="all";let u=this.forContext||{},a=[];for(let p of o){this.forContext={...u,[r]:p};try{let h=await this.evaluateNode(s);a.push(!!h)}catch(h){console.warn(`For loop condition evaluation failed for item ${p}:`,h.message),a.push(!1)}}this.forContext=u;let l=a.filter(p=>p).length;if(t==="any")return l>0;if(t==="all")return l===o.length;if(t==="none")return l===0;if(typeof t=="number")return l>=t;if(t&&t.type==="percentage"){let p=Math.ceil(o.length*t.value/100);return l>=p}else if(t&&t.type==="number")return l>=t.value;return!1}async evaluateMemberAccess(e){let t=await this.evaluateNode(e.object),r=e.property;if(t!=null){if(typeof r=="string")return t[r];{let i=await this.evaluateNode(r);return t[i]}}}async evaluateArrayAccess(e){let t=await this.evaluateNode(e.object),r=await this.evaluateNode(e.index);if(t==null||!Array.isArray(t))return;let i=r<0?t.length+r:r;if(!(i<0||i>=t.length))return t[i]}async evaluateFunctionCall(e){let t=await this.evaluateNode(e.function),r=await Promise.all(e.arguments.map(s=>this.evaluateNode(s)));if(typeof t!="function")throw new Error(`Not a function: ${e.function}`);let i=t(...r);return i instanceof Promise?await i:i}async evaluateDataAccess(e){let t=await this.evaluateNode(e.offset),r=e.dataType,i=e.endian||"little";if(t<0||t>=this.data.length)return;let s=new DataView(this.data.buffer,this.data.byteOffset,this.data.byteLength),o=i==="little";try{switch(r){case"uint8":return s.getUint8(t);case"uint16":return s.getUint16(t,o);case"uint32":return s.getUint32(t,o);case"int8":return s.getInt8(t);case"int16":return s.getInt16(t,o);case"int32":return s.getInt32(t,o);default:throw new Error(`Unknown data type: ${r}`)}}catch{return}}async evaluateDefined(e){try{let t=await this.evaluateNode(e);return t!=null}catch{return!1}}async evaluateAt(e){let t=e.identifier;if(typeof t=="object"&&t.type==="string"){let s=await this.evaluateNode(e.offset),o=t.value,u=new TextEncoder().encode(o);if(s<0||s+u.length>this.data.length)return!1;for(let a=0;a<u.length;a++)if(this.data[s+a]!==u[a])return!1;return!0}t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$);let r=await this.evaluateNode(e.offset),i=this.strings[t];return!i||!i.offsets?!1:i.offsets.includes(r)}async evaluateInRange(e){let t=e.identifier;t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$);let r=await this.evaluateNode(e.range),i=this.strings[t];return!i||!i.offsets?!1:i.offsets.some(s=>s>=r.start&&s<=r.end)}async evaluateWithin(e){let t=e.identifier,r=e.reference;t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$),r==="$"&&this.forContext&&this.forContext.$&&(r=this.forContext.$);let i=await this.evaluateNode(e.distance),s=this.strings[t],o=this.strings[r];if(!s||!s.offsets||s.offsets.length===0||!o||!o.offsets||o.offsets.length===0)return!1;for(let u of s.offsets)for(let a of o.offsets)if(Math.abs(u-a)<=i)return!0;return!1}async evaluateModuleFunction(e){let{module:t,function:r,args:i}=e,s=this.modules[t];if(!s)return;let o=s[r];if(typeof o!="function")return;let u=await Promise.all(i.map(async a=>{let l=await this.evaluateNode(a);if(a.type==="stringIdentifier"){let p=this.strings[a.identifier];if(p&&p.matches&&p.matches.length>0){let h=p.matches[0];if(h.value)return h.value;if(this.data&&h.offset!==void 0&&h.length!==void 0){let w=this.data.slice(h.offset,h.offset+h.length);return new TextDecoder().decode(w)}}return""}return l}));try{let a=o.apply(s,u);return a instanceof Promise?await a:a}catch(a){throw new Error(`Error calling ${t}.${r}: ${a.message}`,{cause:a})}}async evaluateInOperator(e){let t=await this.evaluateNode(e.value),r=await this.evaluateNode(e.set);if(!this.isAnyUndefined(t,r))return Array.isArray(r)?r.includes(t):r&&typeof r=="object"&&r.start!==void 0&&r.end!==void 0?t>=r.start&&t<=r.end:!1}async stringContains(e,t,r=!1){let i=await this.evaluateNode(e),s=await this.evaluateNode(t);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(r&&(i=i.toLowerCase(),s=s.toLowerCase()),i.includes(s))}async stringStartsWith(e,t,r=!1){let i=await this.evaluateNode(e),s=await this.evaluateNode(t);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(r&&(i=i.toLowerCase(),s=s.toLowerCase()),i.startsWith(s))}async stringEndsWith(e,t,r=!1){let i=await this.evaluateNode(e),s=await this.evaluateNode(t);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(r&&(i=i.toLowerCase(),s=s.toLowerCase()),i.endsWith(s))}async stringEquals(e,t,r=!1){let i=await this.evaluateNode(e),s=await this.evaluateNode(t);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(r&&(i=i.toLowerCase(),s=s.toLowerCase()),i===s)}async stringMatches(e,t){let r=await this.evaluateNode(e),i=await this.evaluateNode(t);if(!this.isAnyUndefined(r,i)){if(!(i instanceof RegExp))throw new Error(`"matches" requires a regex literal as its right operand, got ${typeof i}`);return typeof r!="string"?!1:i.test(r)}}};async function we(n,e){return new Me(e).evaluate(n)}var be={};fn(be,{ArrayFormatBase:()=>J,FormatBase:()=>D,ImageDataDirectoryArray:()=>j,ImageDirectoryEntry:()=>V,ImageDosHeader:()=>R,ImageFileHeader:()=>F,ImageNtHeaders:()=>Y,ImageOptionalHeader:()=>L,ImageOptionalHeader64:()=>M,ImageSectionHeaderArray:()=>k,findImageSectionBlockByDirectoryEntry:()=>lr,getImageDosHeader:()=>ur,getImageNtHeadersByDosHeader:()=>fr,getImageSectionHeadersByNtHeaders:()=>cr});var kn=(function(){function n(e){this.view=e}return n.prototype.copyTo=function(e,t){new Uint8Array(e,t,this.view.byteLength).set(new Uint8Array(this.view.buffer,this.view.byteOffset,this.view.byteLength))},Object.defineProperty(n.prototype,"byteLength",{get:function(){return this.view.byteLength},enumerable:!1,configurable:!0}),n})(),D=kn;var qn=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),je=(function(n){qn(e,n);function e(t){return n.call(this,t)||this}return e.prototype.forEach=function(t){var r=this.length,i=[];i.length=r;for(var s=0;s<r;++s)i[s]=this.get(s);for(var s=0;s<r;++s)t(i[s],s,this)},e.prototype._iterator=function(){return new((function(){function t(r){this.base=r,this.i=0}return t.prototype.next=function(){return this.i===this.base.length?{value:void 0,done:!0}:{value:this.base.get(this.i++),done:!1}},t})())(this)},e})(D);typeof Symbol<"u"&&(je.prototype[Symbol.iterator]=je.prototype._iterator);var J=je;var Gn=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),Xn=(function(n){Gn(e,n);function e(t){var r=n.call(this,t)||this;return r.length=16,r}return e.from=function(t,r){return r===void 0&&(r=0),new e(new DataView(t,r,128))},e.prototype.get=function(t){return{virtualAddress:this.view.getUint32(t*8,!0),size:this.view.getUint32(4+t*8,!0)}},e.prototype.set=function(t,r){this.view.setUint32(t*8,r.virtualAddress,!0),this.view.setUint32(4+t*8,r.size,!0)},e.prototype.findIndexByVirtualAddress=function(t){for(var r=0;r<16;++r){var i=this.view.getUint32(r*8,!0),s=this.view.getUint32(4+r*8,!0);if(t>=i&&t<i+s)return r}return null},e.size=128,e.itemSize=8,e})(J),j=Xn;var Kn={Export:0,Import:1,Resource:2,Exception:3,Certificate:4,Security:4,BaseRelocation:5,Debug:6,Architecture:7,GlobalPointer:8,Tls:9,TLS:9,LoadConfig:10,BoundImport:11,Iat:12,IAT:12,DelayImport:13,ComDescriptor:14,COMDescriptor:14},V=Kn;function re(n){var e={};return Object.keys(n).forEach(function(t){e[t]=n[t]}),e}function ie(n,e,t){if("buffer"in n){var r=n.byteOffset,i=n.byteLength;return typeof e<"u"&&(r+=e,i-=e),typeof t<"u"&&(i=t),new DataView(n.buffer,r,i)}else return new DataView(n,e,t)}function Fe(n,e){for(var t=R.from(n),r=new DataView(n),i=t.newHeaderAddress+88,s=0,o=4294967296,u=function(_){s+=_,s>=o&&(s=s%o+(s/o|0))},a=r.byteLength,l=a%4,p=a-l,h=0;h<p;h+=4)h!==i&&u(r.getUint32(h,!0));if(l!==0){for(var w=0,h=0;h<l;h++)w|=r.getUint8(p+h)<<(3-h)*8;u(w)}return s=(s&65535)+(s>>>16),s+=s>>>16,s=(s&65535)+a,e&&r.setUint32(i,s,!0),s}function O(n,e){return Math.floor((n+e-1)/e)*e}function se(n,e,t,r,i){var s="buffer"in n?new Uint8Array(n.buffer,n.byteOffset+(e||0),i):new Uint8Array(n,e,i),o="buffer"in t?new Uint8Array(t.buffer,t.byteOffset+(r||0),i):new Uint8Array(t,r,i);s.set(o)}function oe(n,e,t){var r=new ArrayBuffer(t);return se(r,0,n,e,t),r}function ve(n){if("buffer"in n){var e=new ArrayBuffer(n.byteLength);return new Uint8Array(e).set(new Uint8Array(n.buffer,n.byteOffset,n.byteLength)),e}else{var e=new ArrayBuffer(n.byteLength);return new Uint8Array(e).set(new Uint8Array(n)),e}}function $t(n,e,t){for(var r=0,i=0;i<t&&n.getUint8(e+i)!==0;++i)++r;if(typeof Buffer<"u")return Buffer.from(n.buffer,n.byteOffset+e,r).toString("utf8");if(typeof decodeURIComponent<"u"){for(var s="",i=0;i<r;++i){var o=n.getUint8(e+i);o<16?s+="%0"+o.toString(16):s+="%"+o.toString(16)}return decodeURIComponent(s)}else{for(var s="",i=0;i<r;++i){var o=n.getUint8(e+i);s+=String.fromCharCode(o)}return s}}function Rt(n,e,t,r){if(typeof Buffer<"u"){var i=new Uint8Array(n.buffer,n.byteOffset+e,t);i.set(new Uint8Array(t)),i.set(Buffer.from(r,"utf8").subarray(0,t))}else if(typeof encodeURIComponent<"u")for(var s=encodeURIComponent(r),o=0,u=0;o<t;++o)if(u>=s.length)n.setUint8(o+e,0);else{var a=s.charCodeAt(u);if(a===37){var l=parseInt(s.substr(u+1,2),16);typeof l=="number"&&!isNaN(l)?n.setUint8(o+e,l):n.setUint8(o+e,0),u+=3}else n.setUint8(o+e,a)}else for(var o=0,u=0;o<t;++o)if(u>=r.length)n.setUint8(o+e,0);else{var a=r.charCodeAt(u);n.setUint8(o+e,a&255)}}function Dt(n){if(typeof TextDecoder<"u"){var e=new TextDecoder;return e.decode(n)}else if(typeof Buffer<"u"){var t=void 0;return"buffer"in n?t=Buffer.from(n.buffer,n.byteOffset,n.byteLength):t=Buffer.from(n),t.toString("utf8")}else{var r=void 0;if("buffer"in n?r=new Uint8Array(n.buffer,n.byteOffset,n.byteLength):r=new Uint8Array(n),typeof decodeURIComponent<"u"){for(var i="",s=0;s<r.length;++s){var o=r[s];o<16?i+="%0"+o.toString(16):i+="%"+o.toString(16)}return decodeURIComponent(i)}else{for(var i="",s=0;s<r.length;++s){var o=r[s];i+=String.fromCharCode(o)}return i}}}function Mt(n){if(typeof TextEncoder<"u"){var e=new TextEncoder;return ve(e.encode(n))}else{if(typeof Buffer<"u")return ve(Buffer.from(n,"utf8"));if(typeof encodeURIComponent<"u"){for(var t=encodeURIComponent(n),r=0,i=0;i<t.length;++r){var s=t.charCodeAt(i);s===37?i+=3:++i}for(var o=new ArrayBuffer(r),u=new Uint8Array(o),i=0,a=0;i<t.length;++a){var s=t.charCodeAt(i);if(s===37){var l=parseInt(t.substring(i+1,i+3),16);u[a]=l,i+=3}else u[a]=s,++i}return o}else{var o=new ArrayBuffer(n.length);return new Uint8Array(o).set([].map.call(n,function(h){return h.charCodeAt(0)})),o}}}var Yn=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),Zn=(function(n){Yn(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){return r===void 0&&(r=0),new e(ie(t,r,64))},e.prototype.isValid=function(){return this.magic===e.DEFAULT_MAGIC},Object.defineProperty(e.prototype,"magic",{get:function(){return this.view.getUint16(0,!0)},set:function(t){this.view.setUint16(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lastPageSize",{get:function(){return this.view.getUint16(2,!0)},set:function(t){this.view.setUint16(2,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"pages",{get:function(){return this.view.getUint16(4,!0)},set:function(t){this.view.setUint16(4,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"relocations",{get:function(){return this.view.getUint16(6,!0)},set:function(t){this.view.setUint16(6,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"headerSizeInParagraph",{get:function(){return this.view.getUint16(8,!0)},set:function(t){this.view.setUint16(8,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minAllocParagraphs",{get:function(){return this.view.getUint16(10,!0)},set:function(t){this.view.setUint16(10,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxAllocParagraphs",{get:function(){return this.view.getUint16(12,!0)},set:function(t){this.view.setUint16(12,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"initialSS",{get:function(){return this.view.getUint16(14,!0)},set:function(t){this.view.setUint16(14,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"initialSP",{get:function(){return this.view.getUint16(16,!0)},set:function(t){this.view.setUint16(16,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"checkSum",{get:function(){return this.view.getUint16(18,!0)},set:function(t){this.view.setUint16(18,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"initialIP",{get:function(){return this.view.getUint16(20,!0)},set:function(t){this.view.setUint16(20,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"initialCS",{get:function(){return this.view.getUint16(22,!0)},set:function(t){this.view.setUint16(22,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"relocationTableAddress",{get:function(){return this.view.getUint16(24,!0)},set:function(t){this.view.setUint16(24,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"overlayNum",{get:function(){return this.view.getUint16(26,!0)},set:function(t){this.view.setUint16(26,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"oemId",{get:function(){return this.view.getUint16(36,!0)},set:function(t){this.view.setUint16(36,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"oemInfo",{get:function(){return this.view.getUint16(38,!0)},set:function(t){this.view.setUint16(38,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"newHeaderAddress",{get:function(){return this.view.getUint32(60,!0)},set:function(t){this.view.setUint32(60,t,!0)},enumerable:!1,configurable:!0}),e.size=64,e.DEFAULT_MAGIC=23117,e})(D),R=Zn;var Qn=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),Jn=(function(n){Qn(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){return r===void 0&&(r=0),new e(new DataView(t,r,20))},Object.defineProperty(e.prototype,"machine",{get:function(){return this.view.getUint16(0,!0)},set:function(t){this.view.setUint16(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numberOfSections",{get:function(){return this.view.getUint16(2,!0)},set:function(t){this.view.setUint16(2,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"timeDateStamp",{get:function(){return this.view.getUint32(4,!0)},set:function(t){this.view.setUint32(4,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"pointerToSymbolTable",{get:function(){return this.view.getUint32(8,!0)},set:function(t){this.view.setUint32(8,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numberOfSymbols",{get:function(){return this.view.getUint32(12,!0)},set:function(t){this.view.setUint32(12,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfOptionalHeader",{get:function(){return this.view.getUint16(16,!0)},set:function(t){this.view.setUint16(16,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"characteristics",{get:function(){return this.view.getUint16(18,!0)},set:function(t){this.view.setUint16(18,t,!0)},enumerable:!1,configurable:!0}),e.size=20,e})(D),F=Jn;var er=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),tr=(function(n){er(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){return r===void 0&&(r=0),new e(new DataView(t,r,96))},Object.defineProperty(e.prototype,"magic",{get:function(){return this.view.getUint16(0,!0)},set:function(t){this.view.setUint16(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorLinkerVersion",{get:function(){return this.view.getUint8(2)},set:function(t){this.view.setUint8(2,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorLinkerVersion",{get:function(){return this.view.getUint8(3)},set:function(t){this.view.setUint8(3,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfCode",{get:function(){return this.view.getUint32(4,!0)},set:function(t){this.view.setUint32(4,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfInitializedData",{get:function(){return this.view.getUint32(8,!0)},set:function(t){this.view.setUint32(8,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfUninitializedData",{get:function(){return this.view.getUint32(12,!0)},set:function(t){this.view.setUint32(12,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"addressOfEntryPoint",{get:function(){return this.view.getUint32(16,!0)},set:function(t){this.view.setUint32(16,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"baseOfCode",{get:function(){return this.view.getUint32(20,!0)},set:function(t){this.view.setUint32(20,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"baseOfData",{get:function(){return this.view.getUint32(24,!0)},set:function(t){this.view.setUint32(24,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"imageBase",{get:function(){return this.view.getUint32(28,!0)},set:function(t){this.view.setUint32(28,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sectionAlignment",{get:function(){return this.view.getUint32(32,!0)},set:function(t){this.view.setUint32(32,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fileAlignment",{get:function(){return this.view.getUint32(36,!0)},set:function(t){this.view.setUint32(36,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorOperatingSystemVersion",{get:function(){return this.view.getUint16(40,!0)},set:function(t){this.view.setUint16(40,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorOperatingSystemVersion",{get:function(){return this.view.getUint16(42,!0)},set:function(t){this.view.setUint16(42,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorImageVersion",{get:function(){return this.view.getUint16(44,!0)},set:function(t){this.view.setUint16(44,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorImageVersion",{get:function(){return this.view.getUint16(46,!0)},set:function(t){this.view.setUint16(46,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorSubsystemVersion",{get:function(){return this.view.getUint16(48,!0)},set:function(t){this.view.setUint16(48,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorSubsystemVersion",{get:function(){return this.view.getUint16(50,!0)},set:function(t){this.view.setUint16(50,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"win32VersionValue",{get:function(){return this.view.getUint32(52,!0)},set:function(t){this.view.setUint32(52,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfImage",{get:function(){return this.view.getUint32(56,!0)},set:function(t){this.view.setUint32(56,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeaders",{get:function(){return this.view.getUint32(60,!0)},set:function(t){this.view.setUint32(60,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"checkSum",{get:function(){return this.view.getUint32(64,!0)},set:function(t){this.view.setUint32(64,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subsystem",{get:function(){return this.view.getUint16(68,!0)},set:function(t){this.view.setUint16(68,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dllCharacteristics",{get:function(){return this.view.getUint16(70,!0)},set:function(t){this.view.setUint16(70,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackReserve",{get:function(){return this.view.getUint32(72,!0)},set:function(t){this.view.setUint32(72,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackCommit",{get:function(){return this.view.getUint32(76,!0)},set:function(t){this.view.setUint32(76,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapReserve",{get:function(){return this.view.getUint32(80,!0)},set:function(t){this.view.setUint32(80,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapCommit",{get:function(){return this.view.getUint32(84,!0)},set:function(t){this.view.setUint32(84,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loaderFlags",{get:function(){return this.view.getUint32(88,!0)},set:function(t){this.view.setUint32(88,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numberOfRvaAndSizes",{get:function(){return this.view.getUint32(92,!0)},set:function(t){this.view.setUint32(92,t,!0)},enumerable:!1,configurable:!0}),e.size=96,e.DEFAULT_MAGIC=267,e})(D),L=tr;var nr=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})();function ae(n,e){return n.getUint32(e+4,!0)*4294967296+n.getUint32(e,!0)}function ue(n,e,t){n.setUint32(e,t&4294967295,!0),n.setUint32(e+4,Math.floor(t/4294967296),!0)}function fe(n,e){if(typeof BigInt>"u")throw new Error("BigInt not supported");return BigInt(4294967296)*BigInt(n.getUint32(e+4,!0))+BigInt(n.getUint32(e,!0))}function ce(n,e,t){if(typeof BigInt>"u")throw new Error("BigInt not supported");n.setUint32(e,Number(t&BigInt(4294967295)),!0),n.setUint32(e+4,Math.floor(Number(t/BigInt(4294967296)&BigInt(4294967295))),!0)}var rr=(function(n){nr(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){return r===void 0&&(r=0),new e(new DataView(t,r,112))},Object.defineProperty(e.prototype,"magic",{get:function(){return this.view.getUint16(0,!0)},set:function(t){this.view.setUint16(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorLinkerVersion",{get:function(){return this.view.getUint8(2)},set:function(t){this.view.setUint8(2,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorLinkerVersion",{get:function(){return this.view.getUint8(3)},set:function(t){this.view.setUint8(3,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfCode",{get:function(){return this.view.getUint32(4,!0)},set:function(t){this.view.setUint32(4,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfInitializedData",{get:function(){return this.view.getUint32(8,!0)},set:function(t){this.view.setUint32(8,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfUninitializedData",{get:function(){return this.view.getUint32(12,!0)},set:function(t){this.view.setUint32(12,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"addressOfEntryPoint",{get:function(){return this.view.getUint32(16,!0)},set:function(t){this.view.setUint32(16,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"baseOfCode",{get:function(){return this.view.getUint32(20,!0)},set:function(t){this.view.setUint32(20,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"imageBase",{get:function(){return ae(this.view,24)},set:function(t){ue(this.view,24,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"imageBaseBigInt",{get:function(){return fe(this.view,24)},set:function(t){ce(this.view,24,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sectionAlignment",{get:function(){return this.view.getUint32(32,!0)},set:function(t){this.view.setUint32(32,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fileAlignment",{get:function(){return this.view.getUint32(36,!0)},set:function(t){this.view.setUint32(36,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorOperatingSystemVersion",{get:function(){return this.view.getUint16(40,!0)},set:function(t){this.view.setUint16(40,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorOperatingSystemVersion",{get:function(){return this.view.getUint16(42,!0)},set:function(t){this.view.setUint16(42,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorImageVersion",{get:function(){return this.view.getUint16(44,!0)},set:function(t){this.view.setUint16(44,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorImageVersion",{get:function(){return this.view.getUint16(46,!0)},set:function(t){this.view.setUint16(46,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"majorSubsystemVersion",{get:function(){return this.view.getUint16(48,!0)},set:function(t){this.view.setUint16(48,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"minorSubsystemVersion",{get:function(){return this.view.getUint16(50,!0)},set:function(t){this.view.setUint16(50,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"win32VersionValue",{get:function(){return this.view.getUint32(52,!0)},set:function(t){this.view.setUint32(52,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfImage",{get:function(){return this.view.getUint32(56,!0)},set:function(t){this.view.setUint32(56,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeaders",{get:function(){return this.view.getUint32(60,!0)},set:function(t){this.view.setUint32(60,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"checkSum",{get:function(){return this.view.getUint32(64,!0)},set:function(t){this.view.setUint32(64,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subsystem",{get:function(){return this.view.getUint16(68,!0)},set:function(t){this.view.setUint16(68,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dllCharacteristics",{get:function(){return this.view.getUint16(70,!0)},set:function(t){this.view.setUint16(70,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackReserve",{get:function(){return ae(this.view,72)},set:function(t){ue(this.view,72,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackReserveBigInt",{get:function(){return fe(this.view,72)},set:function(t){ce(this.view,72,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackCommit",{get:function(){return ae(this.view,80)},set:function(t){ue(this.view,80,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfStackCommitBigInt",{get:function(){return fe(this.view,80)},set:function(t){ce(this.view,80,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapReserve",{get:function(){return ae(this.view,88)},set:function(t){ue(this.view,88,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapReserveBigInt",{get:function(){return fe(this.view,88)},set:function(t){ce(this.view,88,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapCommit",{get:function(){return ae(this.view,96)},set:function(t){ue(this.view,96,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sizeOfHeapCommitBigInt",{get:function(){return fe(this.view,96)},set:function(t){ce(this.view,96,t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loaderFlags",{get:function(){return this.view.getUint32(104,!0)},set:function(t){this.view.setUint32(104,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numberOfRvaAndSizes",{get:function(){return this.view.getUint32(108,!0)},set:function(t){this.view.setUint32(108,t,!0)},enumerable:!1,configurable:!0}),e.size=112,e.DEFAULT_MAGIC=523,e})(D),M=rr;var ir=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),sr=(function(n){ir(e,n);function e(t){return n.call(this,t)||this}return e.from=function(t,r){r===void 0&&(r=0);var i=ie(t,r+F.size,6).getUint16(4,!0),s=4+F.size+j.size;return i===M.DEFAULT_MAGIC?s+=M.size:s+=L.size,new e(ie(t,r,s))},e.prototype.isValid=function(){return this.signature===e.DEFAULT_SIGNATURE},e.prototype.is32bit=function(){return this.view.getUint16(F.size+4,!0)===L.DEFAULT_MAGIC},Object.defineProperty(e.prototype,"signature",{get:function(){return this.view.getUint32(0,!0)},set:function(t){this.view.setUint32(0,t,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fileHeader",{get:function(){return F.from(this.view.buffer,this.view.byteOffset+4)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"optionalHeader",{get:function(){var t=F.size+4,r=this.view.getUint16(t,!0);return r===M.DEFAULT_MAGIC?M.from(this.view.buffer,this.view.byteOffset+t):L.from(this.view.buffer,this.view.byteOffset+t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"optionalHeaderDataDirectory",{get:function(){return j.from(this.view.buffer,this.view.byteOffset+this.getDataDirectoryOffset())},enumerable:!1,configurable:!0}),e.prototype.getDataDirectoryOffset=function(){var t=F.size+4,r=this.view.getUint16(t,!0);return r===M.DEFAULT_MAGIC?t+=M.size:t+=L.size,t},e.prototype.getSectionHeaderOffset=function(){return this.getDataDirectoryOffset()+j.size},e.DEFAULT_SIGNATURE=17744,e})(D),Y=sr;var or=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}})(),ar=(function(n){or(e,n);function e(t,r){var i=n.call(this,t)||this;return i.length=r,i}return e.from=function(t,r,i){i===void 0&&(i=0);var s=r*40;return new e(new DataView(t,i,s),r)},e.prototype.get=function(t){return{name:$t(this.view,t*40,8),virtualSize:this.view.getUint32(8+t*40,!0),virtualAddress:this.view.getUint32(12+t*40,!0),sizeOfRawData:this.view.getUint32(16+t*40,!0),pointerToRawData:this.view.getUint32(20+t*40,!0),pointerToRelocations:this.view.getUint32(24+t*40,!0),pointerToLineNumbers:this.view.getUint32(28+t*40,!0),numberOfRelocations:this.view.getUint16(32+t*40,!0),numberOfLineNumbers:this.view.getUint16(34+t*40,!0),characteristics:this.view.getUint32(36+t*40,!0)}},e.prototype.set=function(t,r){Rt(this.view,t*40,8,r.name),this.view.setUint32(8+t*40,r.virtualSize,!0),this.view.setUint32(12+t*40,r.virtualAddress,!0),this.view.setUint32(16+t*40,r.sizeOfRawData,!0),this.view.setUint32(20+t*40,r.pointerToRawData,!0),this.view.setUint32(24+t*40,r.pointerToRelocations,!0),this.view.setUint32(28+t*40,r.pointerToLineNumbers,!0),this.view.setUint16(32+t*40,r.numberOfRelocations,!0),this.view.setUint16(34+t*40,r.numberOfLineNumbers,!0),this.view.setUint32(36+t*40,r.characteristics,!0)},e.itemSize=40,e})(J),k=ar;function ur(n){return R.from(n)}function fr(n,e){return Y.from(n,e.newHeaderAddress)}function cr(n,e,t){return k.from(n,t.fileHeader.numberOfSections,e.newHeaderAddress+t.byteLength)}function lr(n,e,t,r){for(var i=k.from(n,t.fileHeader.numberOfSections,e.newHeaderAddress+t.byteLength),s=i.length,o=t.optionalHeaderDataDirectory.get(r).virtualAddress,u=0;u<s;++u){var a=i.get(u),l=a.virtualAddress+a.virtualSize;if(o>=a.virtualAddress&&o<l){var p=a.pointerToRawData;return p?n.slice(p,p+a.sizeOfRawData):null}if(o<a.virtualAddress)return null}return null}var Te=new Uint8Array([14,31,186,14,0,180,9,205,33,184,1,76,205,33,68,79,83,32,109,111,100,101,32,110,111,116,32,115,117,112,112,111,114,116,101,100,46,13,13,10,36,0,0,0,0,0,0,0]),le=O(R.size+Te.length,128),jt=512;function hr(n){var e=R.from(n);e.magic=R.DEFAULT_MAGIC,e.lastPageSize=le%512,e.pages=Math.ceil(le/512),e.relocations=0,e.headerSizeInParagraph=Math.ceil(R.size/16),e.minAllocParagraphs=0,e.maxAllocParagraphs=65535,e.initialSS=0,e.initialSP=128,e.relocationTableAddress=R.size,e.newHeaderAddress=le,se(n,R.size,Te,0,Te.length)}function pr(n){return 4+F.size+(n?L.size:M.size)+j.size}function dr(n,e,t,r,i){var s,o;"buffer"in n?(s=n.buffer,o=n.byteOffset+e):(s=n,o=e),new DataView(s,o).setUint32(0,Y.DEFAULT_SIGNATURE,!0);var u=F.from(s,o+4);u.machine=r?332:34404,u.numberOfSections=0,u.timeDateStamp=0,u.pointerToSymbolTable=0,u.numberOfSymbols=0,u.sizeOfOptionalHeader=(r?L.size:M.size)+j.size,u.characteristics=i?8450:258;var a=(r?L:M).from(s,o+4+F.size);a.magic=r?L.DEFAULT_MAGIC:M.DEFAULT_MAGIC,a.sizeOfCode=0,a.sizeOfInitializedData=0,a.sizeOfUninitializedData=0,a.addressOfEntryPoint=0,a.baseOfCode=4096,a.imageBase=r?16777216:6442450944,a.sectionAlignment=4096,a.fileAlignment=jt,a.majorOperatingSystemVersion=6,a.minorOperatingSystemVersion=0,a.majorSubsystemVersion=6,a.minorSubsystemVersion=0,a.sizeOfHeaders=O(t,a.fileAlignment),a.subsystem=2,a.dllCharacteristics=(r?0:32)+64+256,a.sizeOfStackReserve=1048576,a.sizeOfStackCommit=4096,a.sizeOfHeapReserve=1048576,a.sizeOfHeapCommit=4096,a.numberOfRvaAndSizes=j.size/j.itemSize}function Ft(n,e){var t=O(le+pr(n),jt),r=new ArrayBuffer(t);return hr(r),dr(r,le,t,n,e),r}var gr=(function(){function n(e,t,r){this._headers=e,this._sections=t,this._ex=r;var i=R.from(e),s=Y.from(e,i.newHeaderAddress);this._dh=i,this._nh=s,this._dda=s.optionalHeaderDataDirectory,t.sort(function(o,u){var a=o.info.pointerToRawData,l=o.info.pointerToRawData;if(a!==l)return a-l;var p=o.info.virtualAddress,h=u.info.virtualAddress;return p===h?o.info.virtualSize-u.info.virtualSize:p-h})}return n.createEmpty=function(e,t){return e===void 0&&(e=!1),t===void 0&&(t=!0),this.from(Ft(e,t))},n.from=function(e,t){var r=R.from(e),i=Y.from(e,r.newHeaderAddress);if(!r.isValid()||!i.isValid())throw new TypeError("Invalid binary format");if(i.fileHeader.numberOfSymbols>0)throw new Error("Binary with symbols is not supported now");var s=i.optionalHeader.fileAlignment,o=i.optionalHeaderDataDirectory.get(V.Certificate);if(o.size>0&&!t?.ignoreCert)throw new Error("Parsing signed executable binary is not allowed by default.");var u=r.newHeaderAddress+i.getSectionHeaderOffset(),a=i.fileHeader.numberOfSections,l=[],p=oe(e,u,a*k.itemSize),h=k.from(p,a,0),w=O(u+a*k.itemSize,s);h.forEach(function(b){if(!b.pointerToRawData||!b.sizeOfRawData)b.pointerToRawData=0,b.sizeOfRawData=0,l.push({info:b,data:null});else{var y=oe(e,b.pointerToRawData,b.sizeOfRawData);l.push({info:b,data:y});var m=O(b.pointerToRawData+b.sizeOfRawData,s);m>w&&(w=m)}});var _=oe(e,0,u),x=null,v=e.byteLength;return o.size>0&&(v=o.virtualAddress),w<v&&(x=oe(e,w,v-w)),new n(_,l,x)},n.prototype.is32bit=function(){return this._nh.is32bit()},n.prototype.getTotalHeaderSize=function(){return this._headers.byteLength},Object.defineProperty(n.prototype,"dosHeader",{get:function(){return this._dh},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"newHeader",{get:function(){return this._nh},enumerable:!1,configurable:!0}),n.prototype.getRawHeader=function(){return this._headers},n.prototype.getImageBase=function(){return this._nh.optionalHeader.imageBase},n.prototype.getFileAlignment=function(){return this._nh.optionalHeader.fileAlignment},n.prototype.getSectionAlignment=function(){return this._nh.optionalHeader.sectionAlignment},n.prototype.getAllSections=function(){return this._sections},n.prototype.getSectionByEntry=function(e){var t=this._dda.get(e),r=this._sections.filter(function(i){var s=i.info.virtualAddress+i.info.virtualSize;return t.virtualAddress>=i.info.virtualAddress&&t.virtualAddress<s}).shift();return r!==void 0?r:null},n.prototype.setSectionByEntry=function(e,t){var r=t?{data:t.data,info:t.info}:null,i=this._dda.get(e),s=i.size>0;if(r){var h=r.data?r.data.byteLength:0,w=this._nh.optionalHeader.fileAlignment,_=this._nh.optionalHeader.sectionAlignment,x=r.data?O(h,w):0,v=r.data?O(r.info.virtualSize,_):0;if(r.info.sizeOfRawData<x?r.info.sizeOfRawData=x:x=r.info.sizeOfRawData,s)this.replaceSectionImpl(i.virtualAddress,r.info,r.data);else{var b=0,y=O(this._headers.byteLength,w);this._sections.forEach(function(m){m.info.pointerToRawData&&y<=m.info.pointerToRawData&&(y=m.info.pointerToRawData+m.info.sizeOfRawData),b<=m.info.virtualAddress&&(b=m.info.virtualAddress+m.info.virtualSize)}),x||(y=0),b||(b=this.newHeader.optionalHeader.baseOfCode),b=O(b,_),r.info.pointerToRawData=y,r.info.virtualAddress=b,this._dda.set(e,{size:h,virtualAddress:b}),this._sections.push(r),this._nh.fileHeader.numberOfSections=this._sections.length,this._nh.optionalHeader.sizeOfImage=O(b+v,this._nh.optionalHeader.sectionAlignment)}}else if(s){this._dda.set(e,{size:0,virtualAddress:0});for(var o=this._sections.length,u=0;u<o;++u){var a=this._sections[u],l=a.info.virtualAddress,p=l+a.info.virtualSize;if(i.virtualAddress>=l&&i.virtualAddress<p){this._sections.splice(u,1),this._nh.fileHeader.numberOfSections=this._sections.length;break}}}},n.prototype.getExtraData=function(){return this._ex},n.prototype.setExtraData=function(e){e===null?this._ex=null:this._ex=ve(e)},n.prototype.generate=function(e){var t=this._dh,r=this._nh,i=t.newHeaderAddress+r.getSectionHeaderOffset(),s=i;s+=this._sections.length*k.itemSize;var o=r.optionalHeader.fileAlignment;s=O(s,o),this._sections.forEach(function(h){if(h.info.pointerToRawData){var w=h.info.pointerToRawData+h.info.sizeOfRawData;s<w&&(s=w,s=O(s,o))}});var u=s;this._ex!==null&&(s+=this._ex.byteLength),typeof e=="number"&&(s+=e);var a=new ArrayBuffer(s),l=new Uint8Array(a);l.set(new Uint8Array(this._headers,0,i)),j.from(a,t.newHeaderAddress+r.getDataDirectoryOffset()).set(V.Certificate,{size:0,virtualAddress:0});var p=k.from(a,this._sections.length,i);return this._sections.forEach(function(h,w){h.data||(h.info.pointerToRawData=0,h.info.sizeOfRawData=0),p.set(w,h.info),!(!h.data||!h.info.pointerToRawData)&&l.set(new Uint8Array(h.data),h.info.pointerToRawData)}),this._ex!==null&&l.set(new Uint8Array(this._ex),u),r.optionalHeader.checkSum!==0&&Fe(a,!0),a},n.prototype.rearrangeSections=function(e,t,r,i){if(!(!t&&!i)){for(var s=this._nh,o=s.optionalHeader.sectionAlignment,u=this._dda,a=this._sections.length,l=0,p=0;p<a;++p){var h=this._sections[p],w=h.info.virtualAddress;if(i&&w>=r){var _=u.findIndexByVirtualAddress(w);w+=i,_!==null&&u.set(_,{virtualAddress:w,size:h.info.virtualSize}),h.info.virtualAddress=w}var x=h.info.pointerToRawData;t&&x>=e&&(h.info.pointerToRawData=x+t),l=O(h.info.virtualAddress+h.info.virtualSize,o)}s.optionalHeader.sizeOfImage=l}},n.prototype.replaceSectionImpl=function(e,t,r){for(var i=this._sections.length,s=0;s<i;++s){var o=this._sections[s];if(o.info.virtualAddress===e){var u=this._nh.optionalHeader.sectionAlignment,a=o.info.pointerToRawData,l=a+o.info.sizeOfRawData,p=e+O(o.info.virtualSize,u);o.info=re(t),o.info.virtualAddress=e,o.info.pointerToRawData=a,o.data=r;var h=a+t.sizeOfRawData,w=e+O(t.virtualSize,u);this.rearrangeSections(l,h-l,p,w-p);{var _=this._dda,x=_.findIndexByVirtualAddress(e);x!==null&&_.set(x,{virtualAddress:e,size:t.virtualSize})}break}}},n})(),Ne=gr;function mr(n){return n.reduce(function(e,t){return e.indexOf(t)>=0?e:e.concat(t)},[])}function Pe(n,e){var t=n.getUint16(e,!0),r="";e+=2;for(var i=0;i<t;++i)r+=String.fromCharCode(n.getUint16(e,!0)),e+=2;return r}function Tt(n,e,t,r,i){var s=r,o={name:t,languageTable:r,characteristics:n.getUint32(s,!0),dateTime:n.getUint32(s+4,!0),majorVersion:n.getUint16(s+8,!0),minorVersion:n.getUint16(s+10,!0)},u=n.getUint16(s+12,!0),a=n.getUint16(s+14,!0);s+=16;for(var l=0;l<u;++l){var p=n.getUint32(s,!0)&2147483647,h=n.getUint32(s+4,!0);if((h&2147483648)!==0){s+=8;continue}var w=Pe(n,p);i(e,o,{lang:w,dataOffset:h}),s+=8}for(var l=0;l<a;++l){var _=n.getUint32(s,!0)&2147483647,h=n.getUint32(s+4,!0);if((h&2147483648)!==0){s+=8;continue}i(e,o,{lang:_,dataOffset:h}),s+=8}}function Nt(n,e,t,r){var i=t,s={type:e,nameTable:t,characteristics:n.getUint32(i,!0),dateTime:n.getUint32(i+4,!0),majorVersion:n.getUint16(i+8,!0),minorVersion:n.getUint16(i+10,!0)},o=n.getUint16(i+12,!0),u=n.getUint16(i+14,!0);i+=16;for(var a=0;a<o;++a){var l=n.getUint32(i,!0)&2147483647,p=n.getUint32(i+4,!0);if(!(p&2147483648)){i+=8;continue}p&=2147483647;var h=Pe(n,l);Tt(n,s,h,p,r),i+=8}for(var a=0;a<u;++a){var w=n.getUint32(i,!0)&2147483647,p=n.getUint32(i+4,!0);if(!(p&2147483648)){i+=8;continue}p&=2147483647,Tt(n,s,w,p,r),i+=8}}function Pt(n,e,t){var r={},i={};t.forEach(function(u){typeof u.lang=="string"?(r[u.lang]=u,e.push(u.lang)):i[u.lang]=u});var s=Object.keys(r);s.sort().forEach(function(u){n.s.push(r[u])});var o=Object.keys(i);return o.map(function(u){return Number(u)}).sort(function(u,a){return u-a}).forEach(function(u){n.n.push(i[u])}),16+8*(s.length+o.length)}function Ht(n,e,t){var r={},i={};t.forEach(function(u){var a,l;if(typeof u.id=="string"){var p=(a=r[u.id])!==null&&a!==void 0?a:r[u.id]=[];e.push(u.id),p.push(u)}else{var p=(l=i[u.id])!==null&&l!==void 0?l:i[u.id]=[];p.push(u)}});var s=Object.keys(r).sort().map(function(u){var a={id:u,s:[],n:[]};return n.s.push(a),Pt(a,e,r[u])}).reduce(function(u,a){return u+8+a},0),o=Object.keys(i).map(function(u){return Number(u)}).sort(function(u,a){return u-a}).map(function(u){var a={id:u,s:[],n:[]};return n.n.push(a),Pt(a,e,i[u])}).reduce(function(u,a){return u+8+a},0);return 16+s+o}function yr(n,e,t){var r={},i={};t.forEach(function(u){var a,l;if(typeof u.type=="string"){var p=(a=r[u.type])!==null&&a!==void 0?a:r[u.type]=[];e.push(u.type),p.push(u)}else{var p=(l=i[u.type])!==null&&l!==void 0?l:i[u.type]=[];p.push(u)}});var s=Object.keys(r).sort().map(function(u){var a={type:u,s:[],n:[]};return n.s.push(a),Ht(a,e,r[u])}).reduce(function(u,a){return u+8+a},0),o=Object.keys(i).map(function(u){return Number(u)}).sort(function(u,a){return u-a}).map(function(u){var a={type:u,s:[],n:[]};return n.n.push(a),Ht(a,e,i[u])}).reduce(function(u,a){return u+8+a},0);return 16+s+o}function Wt(n){var e=n.length;return e>65535?65535:e}function He(n,e){for(var t=e.length,r=0;r<t;++r){var i=e[r];if(i.text===n)return i.offset}throw new Error("Unexpected")}function wr(n,e,t){var r=Wt(t);n.setUint16(e,r,!0),e+=2;for(var i=0;i<r;++i)n.setUint16(e,t.charCodeAt(i),!0),e+=2;return e}function Lt(n,e,t,r){return n.setUint32(e,0,!0),n.setUint32(e+4,0,!0),n.setUint32(e+8,0,!0),n.setUint16(e+12,r.s.length,!0),n.setUint16(e+14,r.n.length,!0),e+=16,r.s.forEach(function(i){var s=He(i.lang,t);n.setUint32(e,s,!0),n.setUint32(e+4,i.offset,!0),e+=8}),r.n.forEach(function(i){n.setUint32(e,i.lang,!0),n.setUint32(e+4,i.offset,!0),e+=8}),e}function Bt(n,e,t,r,i){return n.setUint32(e,0,!0),n.setUint32(e+4,0,!0),n.setUint32(e+8,0,!0),n.setUint16(e+12,i.s.length,!0),n.setUint16(e+14,i.n.length,!0),e+=16,i.s.forEach(function(s){s.offset=t,t=Lt(n,t,r,s)}),i.n.forEach(function(s){s.offset=t,t=Lt(n,t,r,s)}),i.s.forEach(function(s){var o=He(s.id,r);n.setUint32(e,o+2147483648,!0),n.setUint32(e+4,s.offset+2147483648,!0),e+=8}),i.n.forEach(function(s){n.setUint32(e,s.id,!0),n.setUint32(e+4,s.offset+2147483648,!0),e+=8}),t}function vr(n,e,t,r){n.setUint32(e,0,!0),n.setUint32(e+4,0,!0),n.setUint32(e+8,0,!0),n.setUint16(e+12,r.s.length,!0),n.setUint16(e+14,r.n.length,!0),e+=16;var i=e+8*(r.s.length+r.n.length);return r.s.forEach(function(s){s.offset=i,i+=16+8*(s.s.length+s.n.length)}),r.n.forEach(function(s){s.offset=i,i+=16+8*(s.s.length+s.n.length)}),r.s.forEach(function(s){var o=He(s.type,t);n.setUint32(e,o+2147483648,!0),n.setUint32(e+4,s.offset+2147483648,!0),e+=8,i=Bt(n,s.offset,i,t,s)}),r.n.forEach(function(s){n.setUint32(e,s.type,!0),n.setUint32(e+4,s.offset+2147483648,!0),e+=8,i=Bt(n,s.offset,i,t,s)}),i}var cs=(function(){function n(){this.dateTime=0,this.majorVersion=0,this.minorVersion=0,this.entries=[],this.sectionDataHeader=null,this.originalSize=0}return n.prototype.parse=function(e,t){if(e.data){var r=new DataView(e.data);this.dateTime=r.getUint32(4,!0),this.majorVersion=r.getUint16(8,!0),this.minorVersion=r.getUint16(10,!0);for(var i=r.getUint16(12,!0),s=r.getUint16(14,!0),o=16,u=[],a=function(x,v,b){var y=r.getUint32(b.dataOffset,!0)-e.info.virtualAddress,m=r.getUint32(b.dataOffset+4,!0),f=r.getUint32(b.dataOffset+8,!0);if(y>=0){var c=new Uint8Array(m);c.set(new Uint8Array(e.data,y,m)),u.push({type:x.type,id:v.name,lang:b.lang,codepage:f,bin:c.buffer})}else{if(!t)throw new Error("Cannot parse resource directory entry; RVA seems to be invalid.");u.push({type:x.type,id:v.name,lang:b.lang,codepage:f,bin:new ArrayBuffer(0),rva:b.dataOffset})}},l=0;l<i;++l){var p=r.getUint32(o,!0)&2147483647,h=r.getUint32(o+4,!0);if(!(h&2147483648)){o+=8;continue}h&=2147483647;var w=Pe(r,p);Nt(r,w,h,a),o+=8}for(var l=0;l<s;++l){var _=r.getUint32(o,!0)&2147483647,h=r.getUint32(o+4,!0);if(!(h&2147483648)){o+=8;continue}h&=2147483647,Nt(r,_,h,a),o+=8}this.entries=u,this.originalSize=e.data.byteLength}},n.from=function(e,t){t===void 0&&(t=!1);var r=[].concat(e.getAllSections()).sort(function(p,h){return p.info.virtualAddress-h.info.virtualAddress}),i=e.getSectionByEntry(V.Resource);if(i)for(var s=e.getSectionByEntry(V.BaseRelocation),o=0;o<r.length;++o){var u=r[o];if(u===i){for(var a=o+1;a<r.length;++a)if(!s||r[a]!==s)throw new Error("After Resource section, sections except for relocation are not supported");break}}var l=new n;return l.sectionDataHeader=i?re(i.info):null,i&&l.parse(i,t),l},n.prototype.replaceResourceEntry=function(e){for(var t=this.entries.length,r=0;r<t;++r){var i=this.entries[r];if(i.type===e.type&&i.id===e.id&&i.lang===e.lang){this.entries[r]=e;return}}this.entries.push(e)},n.prototype.getResourceEntriesAsString=function(e,t){return this.entries.filter(function(r){return r.type===e&&r.id===t}).map(function(r){return[r.lang,Dt(r.bin)]})},n.prototype.replaceResourceEntryFromString=function(e,t,r,i){var s={type:e,id:t,lang:r,codepage:1200,bin:Mt(i)};this.replaceResourceEntry(s)},n.prototype.removeResourceEntry=function(e,t,r){this.entries=this.entries.filter(function(i){return!(i.type===e&&i.id===t&&(typeof r>"u"||i.lang===r))})},n.prototype.generateResourceData=function(e,t,r,i){r===void 0&&(r=!1),i===void 0&&(i=!1);var s={s:[],n:[]},o=[],u=yr(s,o,this.entries);o=mr(o);var a=u;u+=o.reduce(function(d,g){return d+2+Wt(g)*2},0),u=O(u,8);var l=u;u=this.entries.reduce(function(d,g){return g.offset=d,d+16},l);var p=u;u=this.entries.reduce(function(d,g){return O(d,8)+g.bin.byteLength},p);var h=O(u,t),w=O(this.originalSize,t);if(r&&h>w)throw new Error("New resource data is larger than original");i||h<w&&(h=w);var _=new ArrayBuffer(h),x=new DataView(_),v=l,b=e+p;this.entries.forEach(function(d){var g=d.bin.byteLength;typeof d.rva<"u"?x.setUint32(v,d.rva,!0):(b=O(b,8),x.setUint32(v,b,!0),b+=g),x.setUint32(v+4,g,!0),x.setUint32(v+8,d.codepage,!0),x.setUint32(v+12,0,!0),v+=16}),v=p,this.entries.forEach(function(d){var g=d.bin.byteLength;se(_,v,d.bin,0,g),v+=O(g,8)});var y=[];if(v=a,o.forEach(function(d){y.push({offset:v,text:d}),v=wr(x,v,d)}),vr(x,0,y,s),h>u)for(var m="PADDINGX",f=u,c=0;f<h;++f,++c)c===8&&(c=0),x.setUint8(f,m.charCodeAt(c));return{bin:_,rawSize:u,dataOffset:p,descEntryOffset:l,descEntryCount:this.entries.length}},n.prototype.outputResource=function(e,t,r){t===void 0&&(t=!1),r===void 0&&(r=!1);var i=e.getFileAlignment(),s;this.sectionDataHeader?s={data:null,info:re(this.sectionDataHeader)}:s={data:null,info:{name:".rsrc",virtualSize:0,virtualAddress:0,sizeOfRawData:0,pointerToRawData:0,pointerToRelocations:0,pointerToLineNumbers:0,numberOfRelocations:0,numberOfLineNumbers:0,characteristics:1073741888}};var o=this.generateResourceData(0,i,t,r);s.data=o.bin,s.info.sizeOfRawData=o.bin.byteLength,s.info.virtualSize=o.rawSize,e.setSectionByEntry(V.Resource,s);for(var u=e.getSectionByEntry(V.Resource),a=new DataView(u.data),l=o.descEntryOffset,p=u.info.virtualAddress+o.dataOffset,h=0;h<o.descEntryCount;++h){var w=a.getUint32(l+4,!0);p=O(p,8),a.setUint32(l,p,!0),p+=w,l+=16}},n})();var Gt=ln(qt(),1),_r=typeof crypto<"u",xr=typeof globalThis.process<"u"&&globalThis.process.versions&&globalThis.process.versions.node;function Ar(){if(_r)return crypto;if(xr)return globalThis.crypto;throw new Error("Crypto API not available in this environment")}function _e(n){let e=new Uint32Array(256);for(let i=0;i<n.length;i++)e[n[i]]++;let t=0,r=n.length;if(r===0)return 0;for(let i=0;i<256;i++){if(e[i]===0)continue;let s=e[i]/r;t-=s*Math.log2(s)}return t}function Sr(n){return Array.from(n).map(e=>e.toString(16).padStart(2,"0")).join("")}async function T(n,e){let r=await Ar().subtle.digest(n,e);return Sr(new Uint8Array(r))}function X(n){let e=new Gt.default.ArrayBuffer;return e.append(n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength)),e.end()}function N(n,e,t){return n.getUint16(e,t)}function I(n,e,t){return n.getUint32(e,t)}function P(n,e,t){let r=n.getUint32(e+(t?0:4),t);return n.getUint32(e+(t?4:0),t)*2**32+r}function ee(n,e,t=1024){let r=Math.min(n.length,e+t),i="";for(let s=e;s<r&&n[s]!==0;s++)i+=String.fromCharCode(n[s]);return i}function Xt(n,e){let t=n.length,r=e.length;for(let i=0;i<=t-r;i++){let s=!0;for(let o=0;o<r;o++)if(n[i+o]!==e[o]){s=!1;break}if(s)return i}return-1}async function Ur(n,e){let t=[],r=n.getAllSections?.()||n.sections||[];for(let i of r){let s=i.info||i,o=i.data?new Uint8Array(i.data):i.data??new Uint8Array,u=X(o),a=await T("SHA-1",o),l=await T("SHA-256",o),p={md5:u,sha1:a,sha256:l};t.push({name:(s.name||i.name||"")?.replace(/\0.*$/,""),raw_data:o,entropy:_e(o),virtual_address:s.virtualAddress??s.VirtualAddress??i.VirtualAddress??0,virtual_size:s.virtualSize??s.VirtualSize??i.VirtualSize??0,raw_data_offset:s.pointerToRawData??s.PointerToRawData??i.PointerToRawData??0,raw_data_size:s.sizeOfRawData??s.SizeOfRawData??i.SizeOfRawData??0,characteristics:(s.characteristics??s.Characteristics??i.Characteristics??0)>>>0,...p})}return t}function Or(n){return(n.imports||[]).map(e=>({dll:e.name||"",functions:(e.functions||[]).map(t=>({name:t.name||null,ordinal:t.ordinal||null}))}))}function Cr(n){return(n.exports||[]).map(e=>e.name||e).filter(Boolean)}function Er(n){let e=[];for(let r of n){let i=(r.dll||"").toLowerCase();if(Array.isArray(r.functions))for(let s of r.functions){let o=(s.name||`ordinal${s.ordinal||""}`).toLowerCase();e.push(`${i}.${o}`)}}let t=new TextEncoder;return X(t.encode(e.join(",")))}function Ir(n){let e=n.optionalHeader?.dataDirectory?.[be.ImageDirectoryEntry.Security];return!e||!e.virtualAddress||!e.size?{has_signature:!1}:{has_signature:!0,certificate_table:{offset:e.virtualAddress,size:e.size}}}function zr(n){let e=new Uint8Array([82,105,99,104]),t=Xt(n,e);return t!==-1?{offset:t}:null}function $r(n){let e=n.newHeader?.optionalHeader||n.optionalHeader;return e?{size_of_code:e.sizeOfCode??0,size_of_initialized_data:e.sizeOfInitializedData??0,size_of_uninitialized_data:e.sizeOfUninitializedData??0,address_of_entry_point:e.addressOfEntryPoint??0,base_of_code:e.baseOfCode??0,base_of_data:e.baseOfData??0,image_base:e.imageBase??0,section_alignment:e.sectionAlignment??0,file_alignment:e.fileAlignment??0,subsystem:e.subsystem??0,dll_characteristics:e.dllCharacteristics??0,size_of_stack_reserve:e.sizeOfStackReserve??0,size_of_stack_commit:e.sizeOfStackCommit??0,size_of_heap_reserve:e.sizeOfHeapReserve??0,size_of_heap_commit:e.sizeOfHeapCommit??0}:{}}async function Le(n){n instanceof ArrayBuffer&&(n=new Uint8Array(n));let e;try{e=Ne.from(n)}catch(x){return{error:"Failed to parse PE",message:x.message}}let t=await Ur(e,n),r=Or(e),i=Cr(e),s=Er(r),o=Ir(e),u=zr(n),a=$r(e),l=e.newHeader?.optionalHeader||e.optionalHeader,p=e.newHeader?.fileHeader||e.coffHeader,h=l?.addressOfEntryPoint??0,w=h;if(h>0&&t.length>0)for(let x of t){let v=x.virtual_address,b=v+x.virtual_size;if(h>=v&&h<b){w=h-x.virtual_address+x.raw_data_offset;break}}let _={machine:p?.machine??0,entry_point:w,image_base:l?.imageBase??0,number_of_sections:t.length,sections:t,imports:r,exports:i,imphash:s,digital_signature:o,rich_signature:u,...a,file_size:n.length};return _.is_dll=()=>((p?.characteristics??0)&8192)!==0,_.is_32bit=()=>(l?.magic??0)===267,_.is_64bit=()=>(l?.magic??0)===523,_}function Be(n){return!n||n.error?null:{machine:n.machine,entry_point:n.entry_point,image_base:n.image_base,number_of_sections:n.number_of_sections,sections:n.sections,imports:n.imports,exports:n.exports,imphash:n.imphash,rich_signature:n.rich_signature,digital_signature:n.digital_signature,size_of_code:n.size_of_code,size_of_initialized_data:n.size_of_initialized_data,size_of_uninitialized_data:n.size_of_uninitialized_data,address_of_entry_point:n.address_of_entry_point,base_of_code:n.base_of_code,base_of_data:n.base_of_data,section_alignment:n.section_alignment,file_alignment:n.file_alignment,subsystem:n.subsystem,dll_characteristics:n.dll_characteristics,is_dll:n.is_dll,is_32bit:n.is_32bit,is_64bit:n.is_64bit,imports_dll:e=>{let t=e.toLowerCase();return n.imports.some(r=>r.dll.toLowerCase()===t)},importsFunction:(e,t)=>{let r=e.toLowerCase(),i=n.imports.find(o=>o.dll.toLowerCase()===r);if(!i)return!1;if(!t)return!0;let s=t.toLowerCase();return i.functions.some(o=>o.name&&o.name.toLowerCase()===s)},exports_function:e=>{let t=e.toLowerCase();return n.exports.some(r=>r.toLowerCase()===t)},MACHINE_I386:332,MACHINE_AMD64:34404,MACHINE_ARM:448,MACHINE_ARM64:43620,SUBSYSTEM_NATIVE:1,SUBSYSTEM_WINDOWS_GUI:2,SUBSYSTEM_WINDOWS_CUI:3,SECTION_CNT_CODE:32,SECTION_CNT_INITIALIZED_DATA:64,SECTION_CNT_UNINITIALIZED_DATA:128,SECTION_MEM_EXECUTE:536870912,SECTION_MEM_READ:1073741824,SECTION_MEM_WRITE:2147483648}}var Rr=[127,69,76,70],Dr=1,Mr=14,jr=15,Fr=29;function Tr(n){let e=new DataView(n.buffer,n.byteOffset,n.byteLength);for(let s=0;s<4;s++)if(n[s]!==Rr[s])throw new Error("Not ELF");let t=n[4],r=n[5]===1,i={is64bit:t===2,littleEndian:r};return i.type=N(e,16,r),i.machine=N(e,18,r),i.entry_point=i.is64bit?P(e,24,r):I(e,24,r),i.phoff=i.is64bit?P(e,32,r):I(e,28,r),i.shoff=i.is64bit?P(e,40,r):I(e,32,r),i.phentsize=i.is64bit?N(e,54,r):N(e,42,r),i.phnum=i.is64bit?N(e,56,r):N(e,44,r),i.shentsize=i.is64bit?N(e,58,r):N(e,46,r),i.shnum=i.is64bit?N(e,60,r):N(e,48,r),i.shstrndx=i.is64bit?N(e,62,r):N(e,50,r),i}function Nr(n,e){let t=[],r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=e.phoff;for(let s=0;s<e.phnum;s++){let o,u,a,l,p,h,w;e.is64bit?(o=I(r,i,e.littleEndian),h=I(r,i+4,e.littleEndian),u=P(r,i+8,e.littleEndian),a=P(r,i+16,e.littleEndian),l=P(r,i+32,e.littleEndian),p=P(r,i+40,e.littleEndian),w=P(r,i+48,e.littleEndian),i+=56):(o=I(r,i,e.littleEndian),u=I(r,i+4,e.littleEndian),a=I(r,i+8,e.littleEndian),l=I(r,i+16,e.littleEndian),p=I(r,i+20,e.littleEndian),h=I(r,i+24,e.littleEndian),w=I(r,i+28,e.littleEndian),i+=32),t.push({type:o,offset:u,vaddr:a,filesz:l,memsz:p,flags:h,align:w})}return t}async function Pr(n,e){let t=[],r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=e.shoff;for(let s=0;s<e.shnum;s++){let o=e.is64bit?P(r,i+24,e.littleEndian):I(r,i+16,e.littleEndian),u=e.is64bit?P(r,i+32,e.littleEndian):I(r,i+20,e.littleEndian),a=o+u<=n.length?n.slice(o,o+u):new Uint8Array,l=X(a),p=await T("SHA-1",a),h=await T("SHA-256",a);t.push({offset:o,size:u,entropy:_e(a),raw_data:a,md5:l,sha1:p,sha256:h}),i+=e.is64bit?64:40}return t}function Hr(n,e,t){let r=e.find(_=>_.raw_data&&_.raw_data.length>0&&_.name===".dynamic"),i=e.find(_=>_.raw_data&&_.raw_data.length>0&&_.name===".dynstr");if(!r||!i)return{needed_libraries:[],soname:null,rpath:null,runpath:null};let s=r.raw_data,o=i.raw_data,u=new DataView(s.buffer,s.byteOffset,s.byteLength),a=t.is64bit?16:8,l=[],p=null,h=null,w=null;for(let _=0;_+a<=s.length;_+=a){let x=t.is64bit?P(u,_,t.littleEndian):I(u,_,t.littleEndian),v=t.is64bit?P(u,_+8,t.littleEndian):I(u,_+4,t.littleEndian);x===Dr?l.push(ee(o,v)):x===Mr?p=ee(o,v):x===jr?h=ee(o,v):x===Fr&&(w=ee(o,v))}return{needed_libraries:l,soname:p,rpath:h,runpath:w}}function Lr(n,e,t){let r=[],i=e.find(p=>p.name===".dynsym"),s=e.find(p=>p.name===".dynstr");if(!i||!s)return r;let o=i.raw_data,u=s.raw_data,a=new DataView(o.buffer,o.byteOffset,o.byteLength),l=t.is64bit?24:16;for(let p=0;p+l<=o.length;p+=l){let h=I(a,p,t.littleEndian);if(h>=u.length)continue;let w=ee(u,h);w&&r.push(w)}return r}async function We(n){n instanceof ArrayBuffer&&(n=new Uint8Array(n));let e=n.length,t;try{t=Tr(n)}catch(w){return{error:"Invalid ELF file",message:w.message}}let r=Nr(n,t),i=await Pr(n,t),{needed_libraries:s,soname:o,rpath:u,runpath:a}=Hr(n,i,t),l=Lr(n,i,t),p=(r?.map(w=>w.vaddr)||[0])[0],h=(r?.map(w=>w.offset)||[0])[0];return{type:t.type,machine:t.machine,entry_point:t.entry_point-p+h,is_64bit:t.is64bit,endianness:t.littleEndian?"little":"big",file_size:e,program_headers:r,sections:i,imports:s.map(w=>({dll:w,functions:[]})),exports:l,needed_libraries:s,soname:o,rpath:u,runpath:a,hashes:{}}}function Ve(n){return!n||n.error?null:{type:n.type||0,machine:n.machine||0,entry_point:n.entry_point||0,file_size:n.file_size||0,is_64bit:n.is_64bit||!1,endianness:n.endianness||"little",sections:n.sections||[],number_of_sections:(n.sections||[]).length,program_headers:n.program_headers||[],segments:n.program_headers||[],number_of_segments:(n.program_headers||[]).length,imports:n.needed_libraries||[],exports:n.exports||[],needed_libraries:n.needed_libraries||[],soname:n.soname||null,rpath:n.rpath||null,runpath:n.runpath||null,is_32bit(){return!this.is_64bit},is_little_endian(){return this.endianness==="little"},is_big_endian(){return this.endianness==="big"},imports_library(t){return this.needed_libraries.some(r=>r.toLowerCase().includes(t.toLowerCase()))},exports_function(t){return this.exports.some(r=>r===t)},get_section_by_name(t){return this.sections.find(r=>r.name===t)},ET_NONE:0,ET_REL:1,ET_EXEC:2,ET_DYN:3,ET_CORE:4,EM_NONE:0,EM_386:3,EM_X86_64:62,EM_ARM:40,EM_AARCH64:183,ARCH_X86:3,ARCH_X86_64:62,ARCH_ARM:40,ARCH_AARCH64:183,TYPE_EXEC:2,TYPE_DYN:3,TYPE_CORE:4}}function te(n){return new TextEncoder().encode(n)}function ke(n){if(n.length===0)return 0;let e=new Uint32Array(256);for(let i=0;i<n.length;i++)e[n[i]]++;let t=0,r=n.length;for(let i=0;i<256;i++)if(e[i]>0){let s=e[i]/r;t-=s*Math.log2(s)}return t}function qe(n){if(n.length===0)return 0;let e=0;for(let t=0;t<n.length;t++)e+=n[t];return e/n.length}function Kt(n,e){if(n.length===0)return 0;let t=0;for(let r=0;r<n.length;r++){let i=n[r]-e;t+=i*i}return Math.sqrt(t/n.length)}function Yt(n){if(n.length<2)return 0;let e=0,t=0;for(let r=0;r<n.length-1;r+=2){let i=n[r]/255*2-1,s=n[r+1]/255*2-1;i*i+s*s<=1&&e++,t++}return t===0?0:4*e/t}function Zt(n){if(n.length<2)return 0;let e=qe(n),t=0,r=0;for(let i=0;i<n.length-1;i++)t+=(n[i]-e)*(n[i+1]-e);for(let i=0;i<n.length;i++){let s=n[i]-e;r+=s*s}return r===0?0:t/r}function Br(...n){if(n.length===0)throw new Error("No data provided");return Math.min(...n)}function Wr(...n){if(n.length===0)throw new Error("No data provided");return Math.max(...n)}function Vr(n,e){let t=0;for(let r=0;r<e.length;r++)e[r]===n&&t++;return t}function kr(n){if(n.length===0)return 0;let e=new Uint32Array(256);for(let i=0;i<n.length;i++)e[n[i]]++;let t=0,r=0;for(let i=0;i<256;i++)e[i]>t&&(t=e[i],r=i);return r}function xe(n){if(!n||!(n instanceof Uint8Array))throw new Error("Math module requires a Uint8Array data buffer");return{entropy:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=te(e[0]);return ke(t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let i=n.slice(t,t+r);return i.length===0?0:ke(i)}else throw new Error("entropy() requires either (offset, size) or (string)")},monte_carlo_pi:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=te(e[0]);return Yt(t)}else if(e.length===2){let[t,r]=e;if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let i=n.slice(t,t+r);return i.length===0?0:Yt(i)}else throw new Error("monte_carlo_pi() requires (offset, size)")},serial_correlation:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=te(e[0]);return Zt(t)}else if(e.length===2){let[t,r]=e;if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let i=n.slice(t,t+r);return i.length===0?0:Zt(i)}else throw new Error("serial_correlation() requires (offset, size)")},mean:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=te(e[0]);return qe(t)}else if(e.length===2){let[t,r]=e;if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let i=n.slice(t,t+r);return i.length===0?0:qe(i)}else throw new Error("mean() requires (offset, size)")},deviation:function(...e){if(e.length===2&&typeof e[0]=="string"){let[t,r]=e,i=te(t);return Kt(i,r)}else if(e.length===3){let[t,r,i]=e;if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);if(t>=n.length||t+r>n.length)return 0;let s=n.slice(t,t+r);return s.length===0?0:Kt(s,i)}else throw new Error("deviation() requires (offset, size, mean)")},min:function(e,t){return Br(e,t)},max:function(e,t){return Wr(e,t)},count:function(e,t,r){if(e<0||e>255)throw new Error(`Invalid byte value: ${e} (must be 0-255)`);if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return i.length===0?0:Vr(e,i)},percentage:function(e,t,r){return this.count(e,t,r)/r},mode:function(e,t){if(e<0||t<0)throw new Error(`Invalid range: offset=${e}, size=${t}, data.length=${n.length}`);let r=n.slice(e,e+t);return r.length===0?0:kr(r)},abs:function(e){return Math.abs(e)},to_number:function(e){return e?1:0},in_range:function(e,t,r){return e>=t&&e<=r}}}var qr={entropy:function(n){let e=te(n);return ke(e)},abs:function(n){return Math.abs(n)},to_number:function(n){return n?1:0},in_range:function(n,e,t){return n>=e&&n<=t}};function q(n){return new TextEncoder().encode(n)}function Ge(n){let e=0;for(let t=0;t<n.length;t++)e=e+n[t]>>>0;return e&4294967295}var Gr=(()=>{let n=new Uint32Array(256);for(let e=0;e<256;e++){let t=e;for(let r=0;r<8;r++)t=t&1?3988292384^t>>>1:t>>>1;n[e]=t}return n})();function Xe(n){let e=4294967295;for(let t=0;t<n.length;t++)e=e>>>8^Gr[(e^n[t])&255];return e=(e^4294967295)>>>0,e}function Ae(n){if(!n||!(n instanceof Uint8Array))throw new Error("Hash module requires a Uint8Array data buffer");return{md5:async function(...e){if(e.length===1&&typeof e[0]=="string"){let t=q(e[0]);return X(t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return X(i)}else throw new Error("md5() requires either (offset, size) or (string)")},sha1:async function(...e){if(e.length===1&&typeof e[0]=="string"){let t=q(e[0]);return await T("SHA-1",t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0||t+r>n.length)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return await T("SHA-1",i)}else throw new Error("sha1() requires either (offset, size) or (string)")},sha256:async function(...e){if(e.length===1&&typeof e[0]=="string"){let t=q(e[0]);return await T("SHA-256",t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0||t+r>n.length)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return await T("SHA-256",i)}else throw new Error("sha256() requires either (offset, size) or (string)")},checksum32:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=q(e[0]);return Ge(t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return i.length===0?0:Ge(i)}else throw new Error("checksum32() requires either (offset, size) or (string)")},crc32:function(...e){if(e.length===1&&typeof e[0]=="string"){let t=q(e[0]);return Xe(t)}else if(e.length===2){let t=e[0],r=e[1];if(t<0||r<0)throw new Error(`Invalid range: offset=${t}, size=${r}, data.length=${n.length}`);let i=n.slice(t,t+r);return i.length===0?0:Xe(i)}else throw new Error("crc32() requires either (offset, size) or (string)")}}}var Xr={md5:async function(n){let e=q(n);return X(e)},sha1:async function(n){let e=q(n);return await T("SHA-1",e)},sha256:async function(n){let e=q(n);return await T("SHA-256",e)},checksum32:function(n){let e=q(n);return Ge(e)},crc32:function(n){let e=q(n);return Xe(e)}};var Ke={now:()=>Date.now()};var Ye={to_int:(n,e=10)=>{if(typeof n!="string"&&!(n instanceof String))throw new Error("to_int() first argument must be a string");n.startsWith("0x")||n.startsWith("0X")?(e=16,n=n.slice(2)):(n.startsWith("O")||n.startsWith("o"))&&(e=8,n=n.slice(1));let t=parseInt(n,e);if(isNaN(t))throw new Error(`to_int() could not convert string '${n}' to integer`);return t},length:n=>typeof n=="string"||n instanceof String?n.length:0};var Qt=typeof console<"u"&&typeof console.log=="function"?(...n)=>console.log(...n):()=>{},Kr=typeof globalThis<"u"&&globalThis.performance&&typeof globalThis.performance.now=="function";function Yr(){return Kr?globalThis.performance.now():Date.now()}function Zr(n){return n==null?n:JSON.parse(JSON.stringify(n))}var Ze=class{constructor(e={}){let t=e.enabled??e.enableTiming??!1,r=e.logger??Qt,i=e.autoPrint??!1;this.options={enabled:!!t,logger:r,autoPrint:!!i},this.lastTiming={compile:null,scan:null}}isEnabled(){return!!this.options.enabled}now(){return Yr()}updateOptions(e={}){(Object.prototype.hasOwnProperty.call(e,"enabled")||Object.prototype.hasOwnProperty.call(e,"enableTiming"))&&(this.options.enabled=!!(e.enabled??e.enableTiming)),Object.prototype.hasOwnProperty.call(e,"logger")&&(this.options.logger=e.logger??Qt),Object.prototype.hasOwnProperty.call(e,"autoPrint")&&(this.options.autoPrint=!!e.autoPrint)}enable(e=!0,t){this.updateOptions({enabled:e,logger:t})}clearCompile(){this.lastTiming.compile=null}clearScan(){this.lastTiming.scan=null}recordCompile(e){let t={total:e};this.lastTiming.compile=t,this.printTiming("compile",t)}createScanTiming(){return{total:0,steps:{buildAutomaton:0,acSearch:0,deduplicate:0,verifyCandidates:0,buildMatches:0,evaluateConditions:0,filterStrings:0},modules:{total:0,pe:0,elf:0,math:0,hash:0},conditionParsing:{total:0,byRule:{}},matchCount:0}}finalizeScan(e){this.lastTiming.scan=e,this.printTiming("scan",e)}accumulateStep(e,t,r){!e||!Number.isFinite(r)||(e[t]=(e[t]||0)+r)}accumulateModule(e,t,r){!e||!Number.isFinite(r)||(e.total=(e.total||0)+r,e[t]=(e[t]||0)+r)}accumulateCondition(e,t,r){!e||!Number.isFinite(r)||(e.total=(e.total||0)+r,e.byRule||(e.byRule={}),e.byRule[t]=(e.byRule[t]||0)+r)}getSnapshot(){return Zr(this.lastTiming)}printTiming(e,t){if(!this.options.enabled||!this.options.autoPrint||!this.options.logger||!t)return;let r=this.options.logger;if(e==="compile"){r(`[InterceptScanner] Compile completed in ${t.total.toFixed(3)}ms`);return}if(e==="scan"){let i=t.matchCount??"n/a";r(`[InterceptScanner] Scan completed in ${t.total.toFixed(3)}ms (matches: ${i})`),t.steps&&Object.entries(t.steps).forEach(([s,o])=>{o!=null&&r(` \u2022 ${s}: ${o.toFixed(3)}ms`)}),t.modules&&t.modules.total&&r(` \u2022 moduleCreation.total: ${t.modules.total.toFixed(3)}ms`),t.conditionParsing&&t.conditionParsing.total&&r(` \u2022 conditionParsing.total: ${t.conditionParsing.total.toFixed(3)}ms`)}}};function Jt(n={}){return new Ze(n)}var Qe=class{constructor(e){if(this._isLoaded=!1,this._name=e,!Je(e))throw new Error(`Invalid module name: "${e}". It is either reserved or malformed.`)}getName(){return this._name}isLoaded(){return this._isLoaded}async load(){return this._isLoaded=!0,this._isLoaded}async initialize(e,t){throw new Error("CustomModule.initialize() must be implemented")}createModule(e){throw new Error("CustomModule.createModule() must be implemented")}},Qr=["pe","elf","math","hash","string","time","filesize","entrypoint"];function Je(n){if(!n||typeof n!="string")return!1;let e=n.toLowerCase();return!Qr.includes(e)}var en=4096,ei=new Set(["string","time","math","hash"]);function et(n){return!!(n?.reject?.length||n?.rejectCapture?.length)}function tn(n){let e=2166136261;for(let t=0;t<n.length;t++)e^=n[t],e=Math.imul(e,16777619)>>>0;return e}var Se=class n{constructor(e={}){this.compiledRules=[],this.compiledFilterRules=[],this.filterIndex=new Map,this.filterDiagnostics=[],this.filterScanDiagnostics=null,this.filterDecisionCache=new Map,this.filterModuleCache=new Map,this.ac=null,this.needsCandidateDedupe=!1,this.autoParsePE=!0,this.autoParseELF=!0,this.maxFileSize=1024*1024,this.setModules(e.modules),this.customModules=e.modules||{},this.matchLimits={maxMatches:e.maxMatches??100},this.includeCaptures=e.includeCaptures===!0;let t={enabled:e.timing?.enabled??e.timing?.enableTiming??e.enableTiming??!1,autoPrint:e.timing?.autoPrint??e.autoPrint??!1,logger:e.timing?.logger??e.timingLogger??e.logger};this.timingTracker=Jt(t)}compile(e){let t=this.timingTracker,r=t?.isEnabled(),i=r?t.now():0,s=Ot(e,this.compiledFilterRules||[],{limits:this.matchLimits,availableModules:this.getAvailableModuleNames(),includeCaptures:this.includeCaptures});this.compiledFilterRules=s.rules,this.filterDiagnostics=s.diagnostics||[],this.compiledRules=Ut(e,this.compiledRules||[],{limits:this.matchLimits,includeCaptures:this.includeCaptures}),this.validateFilterRegistry(),this.rebuildFilterIndex(),this.ac=null,this.needsCandidateDedupe=n.hasMultiPatternStrings(this.compiledRules),r?t.recordCompile(t.now()-i):t&&t.clearCompile()}addRules(e){this.compile(e)}clearRules(){this.compiledRules=[],this.compiledFilterRules=[],this.filterIndex=new Map,this.filterDiagnostics=[],this.filterScanDiagnostics=null,this.filterDecisionCache=new Map,this.filterModuleCache=new Map,this.ac=null,this.needsCandidateDedupe=!1}setModules(e){this.modules={string:Ye,time:Ke,...e||{}}}setTiming(e={}){this.timingTracker.updateOptions(e)}enableTiming(e=!0,t){this.timingTracker.enable(e,t)}getTiming(){return this.timingTracker.getSnapshot()}deduplicateCandidates(e){let t=new Map;for(let r of e){let i=`${r.id}:${r.varName}:${r.offset}`;t.has(i)||t.set(i,r)}return Array.from(t.values())}static hasMultiPatternStrings(e){return e.some(t=>Object.values(t.strings??{}).some(r=>(r.patterns?.length??0)>1))}verifyCandidates(e,t,r){let i=[],s=new Map(r.map(o=>[o.id,o]));for(let o of e){let u=s.get(o.id);if(!u)continue;let a=u.strings[o.varName];if(!(!a||!a.matcher))if(a.type==="text"||a.type==="regex"&&a.literalPrefix){let l=typeof a.matcher.verifyAt=="function"?a.matcher.verifyAt(t,o.offset,o):a.matcher(t,o.offset);l&&l.length>0&&i.push({...o,matches:l})}else i.push(o)}return i}async buildStringMatches(e,t,r,i={}){let s={},o=new Map(t.map(a=>[a.id,a]));for(let a of t){s[a.id]={};for(let l of Object.keys(a.strings)){let p=l.startsWith("$")||l.startsWith(".")?l:`$${l}`,h=p.startsWith(".")?`$${p}`:p,w=l.startsWith(".")?`$${l}`:p;s[a.id][w]={identifier:w,matched:!1,count:0,matches:[],offsets:[],private:a.strings[l].private}}}for(let a of e){let l=a.varName.startsWith(".")?`$${a.varName}`:a.varName,p=s[a.id][l]||l.startsWith("$")?l:`$${l}`,h=s[a.id][p],w=o.get(a.id),_=w?.strings?.[a.varName];if(a.matches&&a.matches.length>0){let x=et(_)?await this.filterMatches(_,a.matches,r,i,{ruleName:w?.name,varName:a.varName}):a.matches;if(x.length===0)continue;let v=x.length>this.maxMatches?x.slice(0,this.maxMatches):x;h.matched=!0,h.count+=v.length,h.matches.push(...v),h.offsets.push(...v.map(b=>b.offset))}else h.matched=!0,h.count+=1,h.matches.push({offset:a.offset,length:a.length||0}),h.offsets.push(a.offset)}let u=null;for(let a of t)for(let[l,p]of Object.entries(a.strings)){if(p.type==="text"||p.type==="regex"&&p.literalPrefix?.length>0||!p.matcher)continue;let h=l.startsWith(".")?`$${l}`:l,w=s[a.id][h]||h.startsWith("$")?h:`$${h}`,_=s[a.id][w];p.type==="hex"&&u===null&&(u=Array.from(r).map(v=>v.toString(16).toUpperCase().padStart(2,"0")).join(""));let x=p.type==="hex"&&u!==null?p.matcher(u,-1):p.matcher(r,-1);if(et(p)&&x&&x.length>0&&(x=await this.filterMatches(p,x,r,i,{ruleName:a.name,varName:l})),x&&x.length>0){let v=x.length>this.maxMatches?x.slice(0,this.maxMatches):x;_.matched=!0,_.count+=v.length,_.matches.length===0?_.matches=v:_.matches.push(...v),_.offsets.push(...v.map(b=>b.offset))}}return s}validateFilterRegistry(){let e=new Set(this.compiledRules.map(r=>r.name));for(let r of this.compiledFilterRules)if(e.has(r.name))throw new Error(`Filter rule "${r.name}" collides with a rule of the same name`);let t=new Set(this.compiledFilterRules.map(r=>r.name));for(let r of this.compiledRules)for(let[i,s]of Object.entries(r.strings||{}))for(let o of[...s.reject??[],...s.rejectCapture??[]])t.has(o)||this.filterDiagnostics.push({code:"unknown-filter-rule",severity:"warning",message:`String ${i} in rule "${r.name}" references unknown filter rule "${o}"`,rule:r.name,string:i,filter:o})}rebuildFilterIndex(){this.filterIndex=new Map(this.compiledFilterRules.map(e=>[e.name,e]))}getAvailableModuleNames(){let e=new Set(Object.keys(this.modules||{}));for(let t of Object.values(this.modules||{}))typeof t?.getName=="function"&&e.add(t.getName());return[...e]}ensureFilterScanDiagnostics(){return this.filterScanDiagnostics||(this.filterScanDiagnostics={oversized:new Map,errors:new Map,rejections:new Map}),this.filterScanDiagnostics}resetFilterScanState(){this.filterScanDiagnostics={oversized:new Map,errors:new Map,rejections:new Map},this.filterDecisionCache=new Map,this.filterModuleCache=new Map}async filterMatches(e,t,r,i,s={}){if(!et(e))return t;let o=[];for(let u of t)await this.isRejectedMatch(e,u,r,i,s)||o.push(u);return o}async isRejectedMatch(e,t,r,i,{ruleName:s,varName:o}={}){let u=[...(e?.reject??[]).map(h=>({name:h,capture:!1})),...(e?.rejectCapture??[]).map(h=>({name:h,capture:!0}))];if(u.length===0)return!1;let a=t?.length??0;if(a<=0)return!1;let l=this.ensureFilterScanDiagnostics();if(a>en){let h=`${s}:${o}:${t.offset}:${a}`;return l.oversized.has(h)||l.oversized.set(h,{code:"filter-buffer-too-large",severity:"warning",message:`Candidate for ${o} in rule "${s}" is ${a} bytes, exceeding MAX_FILTER_RULE_BUFFER_SIZE (${en}); filters were skipped`,rule:s,string:o}),!1}let p=r.subarray(t.offset,t.offset+a);for(let{name:h,capture:w}of u){let _=this.filterIndex.get(h);if(!_)continue;let x=w&&typeof t.capture=="string"?new TextEncoder().encode(t.capture):p;if(await this.getFilterDecision(_,x,i))return l.rejections.set(h,(l.rejections.get(h)??0)+1),!0}return!1}async getFilterDecision(e,t,r){let i=`${e.name}:${t.length}:${tn(t)}`,s=this.filterDecisionCache.get(i);if(s&&s.buffer.length===t.length&&s.buffer.every((u,a)=>u===t[a]))return s.rejected;let o=await this.evaluateFilterRule(e,t,r);return this.filterDecisionCache.set(i,{buffer:t,rejected:o}),o}async evaluateFilterRule(e,t,r={}){try{let i=this.matchFilterStrings(e,t),s=await this.createFilterModules(e,t,r),o=ye(t,i,s,{entrypoint:0,filesize:t.length,isFileSizeCapped:!1,maxFileSize:this.maxFileSize,matchedRules:{},metadata:{ruleName:e.name}}),u=e.conditionAST;if(!u){try{u=this.parseSimpleCondition(e.condition,o.strings)}catch{u={type:"boolean",value:!1}}e.conditionAST=u}return await we(u,o)===!0}catch(i){return this.recordFilterError(e.name,i),!1}}matchFilterStrings(e,t){let r={};for(let[i,s]of Object.entries(e.strings||{})){if(typeof s.matcher!="function"){r[i]=[];continue}try{let o=s.matcher(t,-1);r[i]=Array.isArray(o)?o:[]}catch(o){this.recordFilterError(e.name,o),r[i]=[]}}return r}async createFilterModules(e,t,r={}){let i={string:this.modules.string,time:this.modules.time,math:xe(t),hash:Ae(t)},s=e.usedModules??[];if(s.length===0)return i;let o=new Map;for(let u of Object.values(this.modules||{}))typeof u?.getName=="function"&&o.set(u.getName(),u);for(let u of s){if(ei.has(u))continue;let a=o.get(u);if(!a)continue;let l=`${u}:${t.length}:${tn(t)}`;if(this.filterModuleCache.has(l)){i[u]=this.filterModuleCache.get(l);continue}typeof a.isLoaded=="function"&&!a.isLoaded()&&typeof a.load=="function"&&await a.load();let p=a;if(typeof a.initialize=="function"&&typeof a.createModule=="function"){let h=await a.initialize(t,{...r||{},filesize:t.length,hasPE:!1,hasELF:!1,timestamp:Date.now()});p=a.createModule(h)}this.filterModuleCache.set(l,p),i[u]=p}return i}recordFilterError(e,t){let r=this.ensureFilterScanDiagnostics(),i=t?.message??String(t),s=`${e}:${i}`;r.errors.has(s)||r.errors.set(s,{code:"filter-error",severity:"warning",message:`Filter rule "${e}" failed and was treated as not rejecting: ${i}`,filter:e})}attachResultDiagnostics(e){let t=[...this.filterDiagnostics];if(this.filterScanDiagnostics){t.push(...this.filterScanDiagnostics.errors.values()),t.push(...this.filterScanDiagnostics.oversized.values());for(let[r,i]of this.filterScanDiagnostics.rejections)t.push({code:"filter-rejection-count",severity:"info",message:`Filter rule "${r}" rejected ${i} candidate(s)`,filter:r})}return Object.defineProperty(e,"diagnostics",{value:t,enumerable:!1,configurable:!0}),e}async scanFilterRules(e,t={},r=[]){typeof e=="string"&&(e=new TextEncoder().encode(e)),this.resetFilterScanState();let i=[];for(let s of Array.isArray(r)?r:[]){let o=this.filterIndex.get(s);if(!o)continue;let u=null,a=!1;try{let l=this.matchFilterStrings(o,e),p=await this.createFilterModules(o,e,t);u=ye(e,l,p,{entrypoint:0,filesize:e.length,isFileSizeCapped:e.length>=this.maxFileSize,maxFileSize:this.maxFileSize,matchedRules:{},metadata:{ruleName:o.name}});let h=o.conditionAST;if(!h){try{h=this.parseSimpleCondition(o.condition,u.strings)}catch{h={type:"boolean",value:!1}}o.conditionAST=h}a=await we(h,u)===!0}catch(l){this.recordFilterError(o.name,l),a=!1}if(a&&u){let l={};for(let[p,h]of Object.entries(u.strings))p.startsWith(".")||p.startsWith("$.")||h.private||o.strings[p]?.private||(l[p]=h);i.push({rule:o.name,namespace:"default",tags:o.tags||[],metadata:o.metadata||{},strings:l})}}return this.attachResultDiagnostics(i)}async evaluateConditions(e,t,r,i={},s=null){let o=[],u={},a=s?.tracker,l=s?.modules,p=this.modules.pe;if(this.autoParsePE&&!p){let m=a?a.now():0;try{if(r.length>2&&r[0]===77&&r[1]===90){let f=await Le(r);f&&!f.error&&(p=Be(f))}}catch{}finally{a&&l&&a.accumulateModule(l,"pe",a.now()-m)}}let h=this.modules.elf;if(this.autoParseELF&&!h){let m=a?a.now():0;try{if(r.length>4&&r[0]===127&&r[1]===69&&r[2]===76&&r[3]===70){let f=await We(r);f&&!f.error&&(h=Ve(f))}}catch{}finally{a&&l&&a.accumulateModule(l,"elf",a.now()-m)}}let w={...this.modules,...p&&{pe:p},...h&&{elf:h}},_=a?a.now():0;w.math=xe(r),a&&l&&a.accumulateModule(l,"math",a.now()-_);let x=a?a.now():0;w.hash=Ae(r),a&&l&&a.accumulateModule(l,"hash",a.now()-x);let v=new Set;for(let[m,f]of Object.entries(this.modules))try{if(typeof f?.getName=="function"){let c=f.getName();if(!Je(c)){console.warn(`InterceptScanner: Custom module "${c}" has reserved name - skipping initialization`);continue}if(typeof f.isLoaded=="function"&&!f.isLoaded()){let E=a?a.now():0;typeof f.load=="function"&&await f.load(),a&&l&&a.accumulateModule(l,`${c}_load`,a.now()-E)}let d=a?a.now():0,g={...i,filesize:r.length,hasPE:!!p,hasELF:!!h,timestamp:Date.now()},A=f;if(typeof f.initialize=="function"&&typeof f.createModule=="function"){let E=await f.initialize(r,g);A=f.createModule(E)}a&&l&&a.accumulateModule(l,c,a.now()-d),v.has(c)&&console.warn(`InterceptScanner: duplicate custom module name "${c}" - the later instance replaces the earlier one`),v.add(c),w[c]=A}}catch(c){console.warn(`InterceptScanner: Error initializing custom module "${m}": ${c.message}`)}let b=t.filter(m=>m.global);for(let m of b){let f=await this.evaluateRuleCondition(e,m,r,u,{peModule:p,elfModule:h,modulesWithBinary:w},s);if(f)m.private||o.push(f);else return o}let y=t.filter(m=>!m.global);for(let m of y){let f=await this.evaluateRuleCondition(e,m,r,u,{peModule:p,elfModule:h,modulesWithBinary:w},s);f&&!m.private&&o.push(f)}for(let[m,f]of Object.entries(w))if(!["string","time","hash","math"].includes(m)){o[m]={};for(let[c,d]of Object.entries(f))!c.startsWith("_")&&typeof d!="function"&&!/[A-Z0-9]+/.test(c)&&(o[m][c]=typeof d=="object"?tt({...d},["raw_data","data"]):d)}return o}async evaluateRuleCondition(e,t,r,i,s={},o=null){let{peModule:u,elfModule:a,modulesWithBinary:l}=s,p=o?.tracker,h=o?.condition;try{let w=u?u.entry_point:a?a.entry_point:-1e6,_=r.length,x=_>=this.maxFileSize,v=ye(r,e[t.id],l,{entrypoint:w,filesize:_,isFileSizeCapped:x,maxFileSize:this.maxFileSize,matchedRules:i,metadata:{ruleName:t.name}}),b,y=p?p.now():0;try{b=me(t.condition,v.strings)}catch{b=this.parseSimpleCondition(t.condition,v.strings)}finally{p&&h&&p.accumulateCondition(h,t.name,p.now()-y)}let m=await we(b,v);if(i[t.name]=m,m){let f={};for(let[c,d]of Object.entries(e[t.id]))!c.startsWith("$.")&&!d.private&&(f[c]=d);return{rule:t.name,namespace:t.namespace||"default",tags:t.tags||[],metadata:t.metadata||{},strings:f}}}catch(w){console.debug("Failing rule: ",t),console.trace(w)}return!1}parseSimpleCondition(e,t){if(e=e.trim(),e==="any of them")return{type:"any",items:"them"};if(e==="all of them")return{type:"all",items:"them"};if(e==="none of them")return{type:"none",items:"them"};let r=e.match(/^(\d+)\s+of\s+them$/);if(r)return{type:"quantified",quantifier:{type:"number",value:parseInt(r[1])},items:"them"};let i=e.match(/^\$(\w+)$/);if(i)return{type:"stringIdentifier",identifier:`$${i[1]}`};let s=e.match(/^\(?(\$\w+)\s+and\s+(\$\w+)\)?$/);if(s)return{type:"and",left:{type:"stringIdentifier",identifier:s[1]},right:{type:"stringIdentifier",identifier:s[2]}};let o=e.match(/^\(?(\$\w+)\s+or\s+(\$\w+)\)?$/);return o?{type:"or",left:{type:"stringIdentifier",identifier:o[1]},right:{type:"stringIdentifier",identifier:o[2]}}:{type:"boolean",value:!1}}filterStringResults(e){Array.isArray(e)&&e.forEach(t=>{if(Object.keys(t.strings).length>0)for(let[r,i]of Object.entries(t.strings))i.matched||delete t.strings[r]})}async scan(e,t={}){let r=this.timingTracker,i=r?.isEnabled(),s=i?r.now():0,o=i?r.createScanTiming():null;if(typeof e=="string"&&(e=new TextEncoder().encode(e)),this.resetFilterScanState(),!this.compiledRules||this.compiledRules.length===0)return i&&o?(o.total=r.now()-s,o.matchCount=0,r.finalizeScan(o)):r&&r.clearScan(),this.attachResultDiagnostics([]);if(!this.ac)if(i&&o){let f=r.now();this.ac=new ne(this.compiledRules),r.accumulateStep(o.steps,"buildAutomaton",r.now()-f)}else this.ac=new ne(this.compiledRules);let u=i?r.now():0,a=this.ac.search(e);i&&o&&r.accumulateStep(o.steps,"acSearch",r.now()-u);let l=i?r.now():0,p=this.needsCandidateDedupe?this.deduplicateCandidates(a):a;i&&o&&r.accumulateStep(o.steps,"deduplicate",r.now()-l);let h=i?r.now():0,w=this.verifyCandidates(p,e,this.compiledRules);i&&o&&r.accumulateStep(o.steps,"verifyCandidates",r.now()-h);let _=i?r.now():0,x=await this.buildStringMatches(w,this.compiledRules,e,t);i&&o&&r.accumulateStep(o.steps,"buildMatches",r.now()-_);let v=null,b=0;i&&o&&(v={tracker:r,modules:o.modules,condition:o.conditionParsing},b=r.now());let y=await this.evaluateConditions(x,this.compiledRules,e,t,v);i&&o&&r.accumulateStep(o.steps,"evaluateConditions",r.now()-b);let m=i?r.now():0;return this.filterStringResults(y),i&&o?(r.accumulateStep(o.steps,"filterStrings",r.now()-m),o.total=r.now()-s,o.matchCount=y.length,r.finalizeScan(o)):r&&r.clearScan(),this.attachResultDiagnostics(y)}setMaxFileSize(e){this.maxFileSize=e}get maxMatches(){return this.matchLimits.maxMatches}set maxMatches(e){this.matchLimits.maxMatches=e}getStats(){return{totalRules:this.compiledRules.length,totalFilterRules:this.compiledFilterRules.length,ruleNames:this.compiledRules.map(e=>e.name),rulesWithStrings:this.compiledRules.filter(e=>Object.keys(e.strings).length>0).length,totalStrings:this.compiledRules.reduce((e,t)=>e+Object.keys(t.strings).length,0),totalPatterns:this.compiledRules.reduce((e,t)=>e+Object.values(t.strings).reduce((r,i)=>r+(i.patterns?i.patterns.length:0),0),0),acBuilt:this.ac!==null,maxFileSize:this.maxFileSize}}clear(){this.clearRules(),this.setModules(this.customModules)}};function tt(n,e){return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||n===null?n:Array.isArray(n)?n.map(t=>tt(t,e)):n!==null&&typeof n=="object"?Object.fromEntries(Object.entries(n).filter(([t])=>!e.includes(t)).map(([t,r])=>[t,tt(r,e)])):n}export{Qe as BaseCustomModule,Se as InterceptScanner,Se as YaraScanner,Ve as createELFModule,Ae as createHashModule,xe as createMathModule,Be as createPEModule,Xr as hash,qr as math,We as parseELFYaraFull,Le as parsePEYara,Ye as string,Ke as time};
|