sekant-intercept-js 1.0.1 → 1.0.2
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 +3 -3
- package/dist/sekant-intercept.browser.mjs +11 -9
- package/dist/sekant-intercept.node.mjs +11 -9
- package/package.json +1 -1
- package/src/interceptScanner.mjs +17 -2
- package/src/yaraConditionParser.mjs +270 -142
- package/src/yaraConditionsMatch.mjs +56 -16
- package/src/yaraStringMatch.mjs +38 -18
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
* Licensed under Apache 2.0
|
|
5
5
|
* Includes third-party code from pe-library and spark-md5 (MIT)
|
|
6
6
|
*/
|
|
7
|
-
var ve=Object.create;var pt=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Ue=Object.getPrototypeOf,Ae=Object.prototype.hasOwnProperty;var xe=(r,t)=>()=>{try{return t||r((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}},Oe=(r,t)=>{for(var e in t)pt(r,e,{get:t[e],enumerable:!0})},Se=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of _e(t))!Ae.call(r,i)&&i!==e&&pt(r,i,{get:()=>t[i],enumerable:!(n=be(t,i))||n.enumerable});return r};var Ee=(r,t,e)=>(e=r!=null?ve(Ue(r)):{},Se(t||!r||!r.__esModule?pt(e,"default",{value:r,enumerable:!0}):e,r));var ce=xe((fe,le)=>{(function(r){if(typeof fe=="object")le.exports=r();else if(typeof define=="function"&&define.amd)define(r);else{var t;try{t=window}catch{t=self}t.SparkMD5=r()}})(function(r){"use strict";var t=function(y,c){return y+c&4294967295},e=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function n(y,c,l,f,h,p){return c=t(t(c,y),t(f,p)),t(c<<h|c>>>32-h,l)}function i(y,c){var l=y[0],f=y[1],h=y[2],p=y[3];l+=(f&h|~f&p)+c[0]-680876936|0,l=(l<<7|l>>>25)+f|0,p+=(l&f|~l&h)+c[1]-389564586|0,p=(p<<12|p>>>20)+l|0,h+=(p&l|~p&f)+c[2]+606105819|0,h=(h<<17|h>>>15)+p|0,f+=(h&p|~h&l)+c[3]-1044525330|0,f=(f<<22|f>>>10)+h|0,l+=(f&h|~f&p)+c[4]-176418897|0,l=(l<<7|l>>>25)+f|0,p+=(l&f|~l&h)+c[5]+1200080426|0,p=(p<<12|p>>>20)+l|0,h+=(p&l|~p&f)+c[6]-1473231341|0,h=(h<<17|h>>>15)+p|0,f+=(h&p|~h&l)+c[7]-45705983|0,f=(f<<22|f>>>10)+h|0,l+=(f&h|~f&p)+c[8]+1770035416|0,l=(l<<7|l>>>25)+f|0,p+=(l&f|~l&h)+c[9]-1958414417|0,p=(p<<12|p>>>20)+l|0,h+=(p&l|~p&f)+c[10]-42063|0,h=(h<<17|h>>>15)+p|0,f+=(h&p|~h&l)+c[11]-1990404162|0,f=(f<<22|f>>>10)+h|0,l+=(f&h|~f&p)+c[12]+1804603682|0,l=(l<<7|l>>>25)+f|0,p+=(l&f|~l&h)+c[13]-40341101|0,p=(p<<12|p>>>20)+l|0,h+=(p&l|~p&f)+c[14]-1502002290|0,h=(h<<17|h>>>15)+p|0,f+=(h&p|~h&l)+c[15]+1236535329|0,f=(f<<22|f>>>10)+h|0,l+=(f&p|h&~p)+c[1]-165796510|0,l=(l<<5|l>>>27)+f|0,p+=(l&h|f&~h)+c[6]-1069501632|0,p=(p<<9|p>>>23)+l|0,h+=(p&f|l&~f)+c[11]+643717713|0,h=(h<<14|h>>>18)+p|0,f+=(h&l|p&~l)+c[0]-373897302|0,f=(f<<20|f>>>12)+h|0,l+=(f&p|h&~p)+c[5]-701558691|0,l=(l<<5|l>>>27)+f|0,p+=(l&h|f&~h)+c[10]+38016083|0,p=(p<<9|p>>>23)+l|0,h+=(p&f|l&~f)+c[15]-660478335|0,h=(h<<14|h>>>18)+p|0,f+=(h&l|p&~l)+c[4]-405537848|0,f=(f<<20|f>>>12)+h|0,l+=(f&p|h&~p)+c[9]+568446438|0,l=(l<<5|l>>>27)+f|0,p+=(l&h|f&~h)+c[14]-1019803690|0,p=(p<<9|p>>>23)+l|0,h+=(p&f|l&~f)+c[3]-187363961|0,h=(h<<14|h>>>18)+p|0,f+=(h&l|p&~l)+c[8]+1163531501|0,f=(f<<20|f>>>12)+h|0,l+=(f&p|h&~p)+c[13]-1444681467|0,l=(l<<5|l>>>27)+f|0,p+=(l&h|f&~h)+c[2]-51403784|0,p=(p<<9|p>>>23)+l|0,h+=(p&f|l&~f)+c[7]+1735328473|0,h=(h<<14|h>>>18)+p|0,f+=(h&l|p&~l)+c[12]-1926607734|0,f=(f<<20|f>>>12)+h|0,l+=(f^h^p)+c[5]-378558|0,l=(l<<4|l>>>28)+f|0,p+=(l^f^h)+c[8]-2022574463|0,p=(p<<11|p>>>21)+l|0,h+=(p^l^f)+c[11]+1839030562|0,h=(h<<16|h>>>16)+p|0,f+=(h^p^l)+c[14]-35309556|0,f=(f<<23|f>>>9)+h|0,l+=(f^h^p)+c[1]-1530992060|0,l=(l<<4|l>>>28)+f|0,p+=(l^f^h)+c[4]+1272893353|0,p=(p<<11|p>>>21)+l|0,h+=(p^l^f)+c[7]-155497632|0,h=(h<<16|h>>>16)+p|0,f+=(h^p^l)+c[10]-1094730640|0,f=(f<<23|f>>>9)+h|0,l+=(f^h^p)+c[13]+681279174|0,l=(l<<4|l>>>28)+f|0,p+=(l^f^h)+c[0]-358537222|0,p=(p<<11|p>>>21)+l|0,h+=(p^l^f)+c[3]-722521979|0,h=(h<<16|h>>>16)+p|0,f+=(h^p^l)+c[6]+76029189|0,f=(f<<23|f>>>9)+h|0,l+=(f^h^p)+c[9]-640364487|0,l=(l<<4|l>>>28)+f|0,p+=(l^f^h)+c[12]-421815835|0,p=(p<<11|p>>>21)+l|0,h+=(p^l^f)+c[15]+530742520|0,h=(h<<16|h>>>16)+p|0,f+=(h^p^l)+c[2]-995338651|0,f=(f<<23|f>>>9)+h|0,l+=(h^(f|~p))+c[0]-198630844|0,l=(l<<6|l>>>26)+f|0,p+=(f^(l|~h))+c[7]+1126891415|0,p=(p<<10|p>>>22)+l|0,h+=(l^(p|~f))+c[14]-1416354905|0,h=(h<<15|h>>>17)+p|0,f+=(p^(h|~l))+c[5]-57434055|0,f=(f<<21|f>>>11)+h|0,l+=(h^(f|~p))+c[12]+1700485571|0,l=(l<<6|l>>>26)+f|0,p+=(f^(l|~h))+c[3]-1894986606|0,p=(p<<10|p>>>22)+l|0,h+=(l^(p|~f))+c[10]-1051523|0,h=(h<<15|h>>>17)+p|0,f+=(p^(h|~l))+c[1]-2054922799|0,f=(f<<21|f>>>11)+h|0,l+=(h^(f|~p))+c[8]+1873313359|0,l=(l<<6|l>>>26)+f|0,p+=(f^(l|~h))+c[15]-30611744|0,p=(p<<10|p>>>22)+l|0,h+=(l^(p|~f))+c[6]-1560198380|0,h=(h<<15|h>>>17)+p|0,f+=(p^(h|~l))+c[13]+1309151649|0,f=(f<<21|f>>>11)+h|0,l+=(h^(f|~p))+c[4]-145523070|0,l=(l<<6|l>>>26)+f|0,p+=(f^(l|~h))+c[11]-1120210379|0,p=(p<<10|p>>>22)+l|0,h+=(l^(p|~f))+c[2]+718787259|0,h=(h<<15|h>>>17)+p|0,f+=(p^(h|~l))+c[9]-343485551|0,f=(f<<21|f>>>11)+h|0,y[0]=l+y[0]|0,y[1]=f+y[1]|0,y[2]=h+y[2]|0,y[3]=p+y[3]|0}function s(y){var c=[],l;for(l=0;l<64;l+=4)c[l>>2]=y.charCodeAt(l)+(y.charCodeAt(l+1)<<8)+(y.charCodeAt(l+2)<<16)+(y.charCodeAt(l+3)<<24);return c}function o(y){var c=[],l;for(l=0;l<64;l+=4)c[l>>2]=y[l]+(y[l+1]<<8)+(y[l+2]<<16)+(y[l+3]<<24);return c}function u(y){var c=y.length,l=[1732584193,-271733879,-1732584194,271733878],f,h,p,x,C,j;for(f=64;f<=c;f+=64)i(l,s(y.substring(f-64,f)));for(y=y.substring(f-64),h=y.length,p=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=0;f<h;f+=1)p[f>>2]|=y.charCodeAt(f)<<(f%4<<3);if(p[f>>2]|=128<<(f%4<<3),f>55)for(i(l,p),f=0;f<16;f+=1)p[f]=0;return x=c*8,x=x.toString(16).match(/(.*?)(.{0,8})$/),C=parseInt(x[2],16),j=parseInt(x[1],16)||0,p[14]=C,p[15]=j,i(l,p),l}function a(y){var c=y.length,l=[1732584193,-271733879,-1732584194,271733878],f,h,p,x,C,j;for(f=64;f<=c;f+=64)i(l,o(y.subarray(f-64,f)));for(y=f-64<c?y.subarray(f-64):new Uint8Array(0),h=y.length,p=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=0;f<h;f+=1)p[f>>2]|=y[f]<<(f%4<<3);if(p[f>>2]|=128<<(f%4<<3),f>55)for(i(l,p),f=0;f<16;f+=1)p[f]=0;return x=c*8,x=x.toString(16).match(/(.*?)(.{0,8})$/),C=parseInt(x[2],16),j=parseInt(x[1],16)||0,p[14]=C,p[15]=j,i(l,p),l}function g(y){var c="",l;for(l=0;l<4;l+=1)c+=e[y>>l*8+4&15]+e[y>>l*8&15];return c}function m(y){var c;for(c=0;c<y.length;c+=1)y[c]=g(y[c]);return y.join("")}m(u("hello"))!=="5d41402abc4b2a76b9719d911017c592"&&(t=function(y,c){var l=(y&65535)+(c&65535),f=(y>>16)+(c>>16)+(l>>16);return f<<16|l&65535}),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&(function(){function y(c,l){return c=c|0||0,c<0?Math.max(c+l,0):Math.min(c,l)}ArrayBuffer.prototype.slice=function(c,l){var f=this.byteLength,h=y(c,f),p=f,x,C,j,Mt;return l!==r&&(p=y(l,f)),h>p?new ArrayBuffer(0):(x=p-h,C=new ArrayBuffer(x),j=new Uint8Array(C),Mt=new Uint8Array(this,h,x),j.set(Mt),C)}})();function d(y){return/[\u0080-\uFFFF]/.test(y)&&(y=unescape(encodeURIComponent(y))),y}function w(y,c){var l=y.length,f=new ArrayBuffer(l),h=new Uint8Array(f),p;for(p=0;p<l;p+=1)h[p]=y.charCodeAt(p);return c?h:f}function _(y){return String.fromCharCode.apply(null,new Uint8Array(y))}function v(y,c,l){var f=new Uint8Array(y.byteLength+c.byteLength);return f.set(new Uint8Array(y)),f.set(new Uint8Array(c),y.byteLength),l?f:f.buffer}function U(y){var c=[],l=y.length,f;for(f=0;f<l-1;f+=2)c.push(parseInt(y.substr(f,2),16));return String.fromCharCode.apply(String,c)}function b(){this.reset()}return b.prototype.append=function(y){return this.appendBinary(d(y)),this},b.prototype.appendBinary=function(y){this._buff+=y,this._length+=y.length;var c=this._buff.length,l;for(l=64;l<=c;l+=64)i(this._hash,s(this._buff.substring(l-64,l)));return this._buff=this._buff.substring(l-64),this},b.prototype.end=function(y){var c=this._buff,l=c.length,f,h=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],p;for(f=0;f<l;f+=1)h[f>>2]|=c.charCodeAt(f)<<(f%4<<3);return this._finish(h,l),p=m(this._hash),y&&(p=U(p)),this.reset(),p},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,c){var l=c,f,h,p;if(y[l>>2]|=128<<(l%4<<3),l>55)for(i(this._hash,y),l=0;l<16;l+=1)y[l]=0;f=this._length*8,f=f.toString(16).match(/(.*?)(.{0,8})$/),h=parseInt(f[2],16),p=parseInt(f[1],16)||0,y[14]=h,y[15]=p,i(this._hash,y)},b.hash=function(y,c){return b.hashBinary(d(y),c)},b.hashBinary=function(y,c){var l=u(y),f=m(l);return c?U(f):f},b.ArrayBuffer=function(){this.reset()},b.ArrayBuffer.prototype.append=function(y){var c=v(this._buff.buffer,y,!0),l=c.length,f;for(this._length+=y.byteLength,f=64;f<=l;f+=64)i(this._hash,o(c.subarray(f-64,f)));return this._buff=f-64<l?new Uint8Array(c.buffer.slice(f-64)):new Uint8Array(0),this},b.ArrayBuffer.prototype.end=function(y){var c=this._buff,l=c.length,f=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],h,p;for(h=0;h<l;h+=1)f[h>>2]|=c[h]<<(h%4<<3);return this._finish(f,l),p=m(this._hash),y&&(p=U(p)),this.reset(),p},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,c){var l=a(new Uint8Array(y)),f=m(l);return c?U(f):f},b})});var it=class{constructor(){this.children={},this.fail=null,this.outputs=[],this.nocase=!1}},Y=class{constructor(t){this.root=new it,this.addRules(t)}addRules(t){let e=[],n=new TextDecoder;for(let i of t){let{id:s,strings:o}=i;for(let u of Object.keys(o)){let a=o[u];if(a.type==="text")for(let g of a.patterns){let m=g.bytes,d=n.decode(m);e.push({id:s,varName:u,pattern:d,matcher:a.matcher,xor:a.xor,nocase:a.nocase})}else a.type==="regex"&&a.literalPrefix&&a.literalPrefix.length>0&&e.push({id:s,varName:u,pattern:a.literalPrefix,matcher:a.matcher,nocase:a.nocase})}}this.generateAtoms(e),this.buildTrie(e),this.buildFailures()}generateAtoms(t,e=3){let n=[];for(let i of t){if(i.pattern.length<=e)i.atom=i.pattern,i.atomOffset=0;else{let s=Math.floor(Math.random()*(i.pattern.length-e));i.atom=i.pattern.slice(s,s+e),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 g=u.map(m=>String.fromCharCode(m.charCodeAt(0)^a)).join("");a===s?(i.atom=g,i.xorKey=a):n.push({...i,atom:g,xorKey:a})}}}t.push(...n)}buildTrie(t){for(let e of t){let n=this.root;for(let i=0;i<e.atom.length;i++){let s=e.atom[i];n.children[s]||(n.children[s]=new it),n=n.children[s],n.nocase=e.nocase??!1}n.outputs.push(e)}}printTrie(){let t=(e,n)=>{for(let[i,s]of Object.entries(e.children))console.log(`${n}${i} (nocase: ${s.nocase}) (children: [${Object.keys(s.children)}]) (outputs: ${s.outputs.length})`),t(s,n+" ")};t(this.root,"")}buildFailures(){let t=[];for(let e in this.root.children){let n=this.root.children[e];n.fail=this.root,t.push(n)}for(;t.length>0;){let e=t.shift();for(let[n,i]of Object.entries(e.children)){t.push(i);let s=e.fail;for(;s&&!s.children[n];)s=s.fail;i.fail=s?s.children[n]:this.root,i.outputs=i.outputs.concat(i.fail.outputs)}}}search(t){let e=[],n=this.root;for(let i=0;i<t.length;i++){let s=t[i],o=typeof s=="number"?String.fromCharCode(s):s,u=o.toLowerCase();for(;n&&!(n.children[o]||n.children[u]&&n.children[u].nocase);)n=n.fail;if(n?n.children[o]?n=n.children[o]:n.children[u]?.nocase?n=n.children[u]:n=this.root:n=this.root,n!==this.root)for(let a of n.outputs){let g=i-(a.atomLength||0)+1;g-a.atomOffset<0||g-a.atomOffset+a.length>t.length||e.push({id:a.id,varName:a.varName,offset:g-a.atomOffset,index:g,xorKey:a.xorKey,matcher:a.matcher})}}return e}};function Ht(r){r=r.trim();let t=r.startsWith("/"),e=r.startsWith("{"),n=r.match(/^"(.*)"(.*)$/);if(t)return Ce(r);if(e){let i=r.slice(r.lastIndexOf("}")+1);return je(r.slice(1,r.lastIndexOf("}")).trim(),i)}else if(n){let[,i,s]=n,o=s.toLowerCase(),u={wide:/\bwide\b/.test(o),xor:Ne(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 ze(i,u)}throw new Error("Unsupported definition: "+r)}function Lt(r){return(t,e=-1,n=2048)=>{let i=e>=0;return e=Math.max(0,e-1),t=i?t.slice(e,e+n):t,r(t,i?e:-1)}}function Ce(r){let t=r.split("/").pop().toLowerCase()??"",e=t.split(" ")[0],n=/\bprivate\b/.test(t),i=r.slice(1,r.lastIndexOf("/")),s=e.includes("i"),o="g"+(e.includes("s")?"s":"")+(s?"i":""),u=Ie(i,s),a=new RegExp(i,o);return{matcher:Lt((m,d=-1)=>{let w=new TextEncoder,_=new TextDecoder().decode(m),v=[],U=d>=0;d=d<0?0:d;let b;for(;(b=a.exec(_))!==null&&v.length<100;){let y=w.encode(_.slice(0,b.index)).length;if(v.push({offset:y+d,length:w.encode(b[0]).length}),a.lastIndex=b.index+1,U)break}return v}),literalPrefix:u,type:"regex",nocase:s,private:n}}function Ie(r,t=!1){r=r.replace(/^\^/,""),r=t?r.toLowerCase():r;let e=r.match(/^((?:\\[^bBdDwWsSAZzGnrtfv0u]|[^\\[\]()|*+?{}.])+)/);return!e||e.length<2?"":e[1].replace(/\\x([0-9A-Fa-f]{2})/g,(i,s)=>String.fromCharCode(parseInt(s,16))).replace(/\\(.)/g,"$1")}function ze(r,t){let e=new TextEncoder,n=[];t.wide||(t.ascii=!0),(t.base64||t.base64wide)&&(t.nocase=!1,t.fullword=!1,t.xor=null);let i=r.replace(/\\n/g,`
|
|
8
|
-
`).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\x([0-9A-Fa-f]{2})/g,(u,a)=>String.fromCharCode(parseInt(a,16))).replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\'/g,"'"),s=
|
|
9
|
-
`;)
|
|
10
|
-
`&&(
|
|
11
|
-
`&&(
|
|
12
|
-
`),
|
|
13
|
-
`);for(let u of o)if(!s&&u.match(/^\s*(?:\s*(?:private|global)\s+)*rule\b/i)){s=!0,
|
|
14
|
-
`;let a=
|
|
15
|
-
`;let a=Wt(u);i+=a.openCount-a.closeCount,i===0&&(e.push(Vt(n)),s=!1,n="")}return e.forEach((u,a)=>{u.id=a+1}),e}function Vt(r){r=Fe(r).trim();let t=/^.*\bprivate\b.*rule\s+/i.test(r),e=/^.*\bglobal\b.*rule\s+/i.test(r),n=r.match(/^(?:.*)?rule\s+(\w+)(?:\s*:\s*([\w\s]+))?\s*\{/);if(!n)throw new Error("Invalid YARA rule: missing rule declaration");let i=n[1],s=n[2]?n[2].trim().split(/\s+/):[],o=r.match(/\{([\s\S]*)\}/);if(!o)throw new Error("Invalid YARA rule: missing rule body");let u=o[1],a=He(u),g=Le(u),m=Be(u);return{name:i,tags:s,metadata:a,strings:g,condition:m,private:t,global:e}}function He(r){let t=r.match(/meta:\s*([\s\S]*?)(?=strings:|condition:|$)/);if(!t)return{};let e=t[1],n={},i=e.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("'")?n[o]=u.slice(1,-1):u==="true"||u==="false"?n[o]=u==="true":isNaN(u)?n[o]=u:n[o]=Number(u)}return n}function Le(r){let t=r.match(/strings:\s*([\s\S]*?)(?=condition:|$)/);if(!t)return{};let e=t[1],n={},i=e.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,g]=u;!a||a===""?a=`.anon_${s++}`:a.startsWith("$")||(a="$"+a);try{let m=Ht(g.trim());n[a]={definition:g.trim(),...m}}catch(m){console.warn(`Warning: Failed to compile string $${a}: ${m.message}`),console.warn(`Definition: ${g.trim()}`),console.warn(o),console.warn(t),console.warn(r),n[a]={definition:g.trim(),type:null,matcher:null,error:m.message}}}}return n}function Be(r){let t=r.match(/condition:\s*([\s\S]*?)$/);if(!t)throw new Error("Invalid YARA rule: missing condition");return t[1].trim().replace(/\}\s*$/,"").trim()}function kt(r,t={},e={},n={}){let i={};for(let[s,o]of Object.entries(t))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:r,filesize:r.length,entrypoint:n.entrypoint??0,isFileSizeCapped:n.isFileSizeCapped??!1,maxFileSize:n.maxFileSize??1024*1024,strings:i,modules:e||{},matchedRules:n.matchedRules||{},metadata:n.metadata||{}}}var gt=class{constructor(t){this.facts=t,this.data=t.data,this.filesize=t.filesize,this.entrypoint=t.entrypoint,this.isFileSizeCapped=t.isFileSizeCapped??!1,this.maxFileSize=t.maxFileSize??1024*1024,this.strings=t.strings,this.modules=t.modules,this.matchedRules=t.matchedRules||{}}isAnyUndefined(...t){return t.some(e=>e===void 0)}async evaluate(t){return typeof t=="string"&&(t=this.parseCondition(t)),await this.evaluateNode(t)}parseCondition(t){throw new Error("String parsing not implemented - pass AST directly")}async evaluateNode(t){if(t==null)return!1;let e=t.type;switch(e){case"boolean":return t.value;case"number":return t.value;case"string":return t.value;case"identifier":return this.resolveIdentifier(t.name);case"ruleIdentifier":return this.evaluateRuleIdentifier(t);case"stringIdentifier":return this.evaluateStringIdentifier(t);case"stringCount":return this.getStringCount(t.identifier);case"stringOffset":{let n=t.index;return typeof n=="object"&&(n=await this.evaluateNode(n)),this.getStringOffset(t.identifier,n)}case"stringLength":{let n=t.index;return typeof n=="object"&&(n=await this.evaluateNode(n)),this.getStringLength(t.identifier,n)}case"and":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return!(n===void 0||n===!1||i===void 0||i===!1)}case"or":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return(n===void 0?!1:n)||(i===void 0?!1:i)}case"not":{let n=await this.evaluateNode(t.operand);return this.isAnyUndefined(n)?void 0:!n}case"defined":return await this.evaluateDefined(t.operand);case"equal":return await this.evaluateEqual(t);case"notEqual":return await this.evaluateNotEqual(t);case"lessThan":return await this.evaluateLessThan(t);case"greaterThan":return await this.evaluateGreaterThan(t);case"lessThanOrEqual":return await this.evaluateLessThanOrEqual(t);case"greaterThanOrEqual":return await this.evaluateGreaterThanOrEqual(t);case"add":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:n+i}case"subtract":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:n-i}case"multiply":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:n*i}case"divide":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:Math.floor(n/i)}case"modulo":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:n%i}case"bitwiseAnd":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:n&i}case"bitwiseOr":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:n|i}case"bitwiseXor":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:n^i}case"bitwiseNot":{let n=await this.evaluateNode(t.operand);return this.isAnyUndefined(n)?void 0:~n}case"shiftLeft":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:n<<i}case"shiftRight":{let n=await this.evaluateNode(t.left),i=await this.evaluateNode(t.right);return this.isAnyUndefined(n,i)?void 0:n>>i}case"contains":return await this.stringContains(t.left,t.right,!1);case"icontains":return await this.stringContains(t.left,t.right,!0);case"startswith":return await this.stringStartsWith(t.left,t.right,!1);case"istartswith":return await this.stringStartsWith(t.left,t.right,!0);case"endswith":return await this.stringEndsWith(t.left,t.right,!1);case"iendswith":return await this.stringEndsWith(t.left,t.right,!0);case"iequals":return await this.stringEquals(t.left,t.right,!0);case"matches":return await this.stringMatches(t.left,t.right);case"in":return await this.evaluateInOperator(t);case"range":return{start:await this.evaluateNode(t.start),end:await this.evaluateNode(t.end)};case"all":return await this.evaluateAll(t.items);case"any":return await this.evaluateAny(t.items);case"none":return await this.evaluateNone(t.items);case"quantified":return await this.evaluateQuantified(t);case"for":return await this.evaluateFor(t);case"memberAccess":return await this.evaluateMemberAccess(t);case"arrayAccess":return await this.evaluateArrayAccess(t);case"functionCall":return await this.evaluateFunctionCall(t);case"dataAccess":return this.evaluateDataAccess(t);case"at":return await this.evaluateAt(t);case"inRange":return await this.evaluateInRange(t);case"within":return await this.evaluateWithin(t);case"moduleFunction":return await this.evaluateModuleFunction(t);default:throw new Error(`Unknown node type: ${e}`)}}resolveIdentifier(t){if(this.forContext&&t in this.forContext)return this.forContext[t];let e=t?.split(".");switch(t=e[0],t){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&&t in this.modules){if(!this.modules[t])return this.modules[t];let n=this.modules;for(let i of e)if(n=n[i],!n)return n;return n}if(["pe","elf","hash","math","string","time"].includes(t))return;throw new Error(`Unknown identifier: ${t}`)}}isFilesizeNode(t){return t&&t.type==="identifier"&&t.name==="filesize"}async evaluateEqual(t){let e=await this.evaluateNode(t.left),n=await this.evaluateNode(t.right);if(!this.isAnyUndefined(e,n))return this.isFilesizeNode(t.left)&&this.isFileSizeCapped&&n>=this.maxFileSize||this.isFilesizeNode(t.right)&&this.isFileSizeCapped&&e>=this.maxFileSize?!0:e===n}async evaluateNotEqual(t){let e=await this.evaluateEqual(t);if(!this.isAnyUndefined(e))return!e}async evaluateLessThan(t){let e=await this.evaluateNode(t.left),n=await this.evaluateNode(t.right);if(!this.isAnyUndefined(e,n))return e<n}async evaluateGreaterThan(t){let e=await this.evaluateNode(t.left),n=await this.evaluateNode(t.right);if(!this.isAnyUndefined(e,n))return this.isFilesizeNode(t.left)&&this.isFileSizeCapped&&n>=this.maxFileSize?!0:e>n}async evaluateLessThanOrEqual(t){let e=await this.evaluateNode(t.left),n=await this.evaluateNode(t.right);if(!this.isAnyUndefined(e,n))return e<=n}async evaluateGreaterThanOrEqual(t){let e=await this.evaluateNode(t.left),n=await this.evaluateNode(t.right);if(!this.isAnyUndefined(e,n))return this.isFilesizeNode(t.left)&&this.isFileSizeCapped&&n>=this.maxFileSize?!0:e>=n}evaluateStringIdentifier(t){let e=t.identifier;e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$);let n=this.strings[e];return n?n.matched&&n.count>0:!1}evaluateRuleIdentifier(t){let e=t.name;return e in this.matchedRules?this.matchedRules[e]===!0:!1}getStringCount(t){t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$);let e=this.strings[t];return e?e.count:0}getStringOffset(t,e=0){t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$),typeof e=="string"&&this.forContext&&e in this.forContext&&(e=this.forContext[e]);let n=this.strings[t];if(!n||!n.offsets||n.offsets.length===0)return;let i=e===0?0:e-1;return n.offsets[i]}getStringLength(t,e=0){t==="$"&&this.forContext&&this.forContext.$&&(t=this.forContext.$),typeof e=="string"&&this.forContext&&e in this.forContext&&(e=this.forContext[e]);let n=this.strings[t];if(!n||!n.matches||n.matches.length===0)return;let i=e===0?0:e-1,s=n.matches[i];return s?s.length:void 0}evaluateAll(t){let e=this.resolveStringSet(t);return e.length===0?!1:e.every(n=>{let i=this.strings[n];return i&&i.matched&&i.count>0})}evaluateAny(t){let e=this.resolveStringSet(t);return e.length===0?!1:e.some(n=>{let i=this.strings[n];return i&&i.matched&&i.count>0})}evaluateNone(t){let e=this.resolveStringSet(t);return e.length===0?!0:e.every(n=>{let i=this.strings[n];return!i||!i.matched||i.count===0})}evaluateQuantified(t){let e=this.resolveStringSet(t.items);if(e.length===0)return!1;let n=e.filter(s=>{let o=this.strings[s];return o&&o.matched&&o.count>0}).length,i=t.quantifier;if(i.type==="number")return n>=i.value;if(i.type==="percentage"){let s=Math.ceil(e.length*i.value/100);return n>=s}else if(i.type==="range"){let s=i.min,o=i.max;return n>=s&&n<=o}return!1}resolveStringSet(t){if(t==="them")return Object.keys(this.strings);if(Array.isArray(t)){let e=[];for(let n of t)if(n.includes("*")){let i=n.replace(/\*/g,".*").replace(/\$/g,"\\$"),s=new RegExp("^"+i+"$"),o=Object.keys(this.strings).filter(u=>s.test(u));e.push(...o)}else e.push(n);return e}if(typeof t=="string"){if(t.includes("*")){let e=t.replace(/\*/g,".*").replace(/\$/g,"\\$"),n=new RegExp("^"+e+"$");return Object.keys(this.strings).filter(i=>n.test(i))}return[t]}return[]}async evaluateFor(t){let e=t.quantifier,n=t.variable,i=t.set,s=t.condition,o=[];if(i.type==="stringSet"){if(o=this.resolveStringSet(i.items),o.length===0)return e==="all"}else if(i.type==="range"){let m=await this.evaluateNode(i.start),d=await this.evaluateNode(i.end);if(typeof m!="number"||typeof d!="number")throw new Error(`Invalid range values: ${m} to ${d}`);for(let w=m;w<=d;w++)o.push(w);if(o.length===0)return e==="all"}else{let m=await this.evaluateNode(i);Array.isArray(m)?o=m:o=[m]}if(o.length===0)return e==="all";let u=this.forContext||{},a=[];for(let m of o){this.forContext={...u,[n]:m};try{let d=await this.evaluateNode(s);a.push(!!d)}catch(d){console.warn(`For loop condition evaluation failed for item ${m}:`,d.message),a.push(!1)}}this.forContext=u;let g=a.filter(m=>m).length;if(e==="any")return g>0;if(e==="all")return g===o.length;if(e==="none")return g===0;if(typeof e=="number")return g>=e;if(e&&e.type==="percentage"){let m=Math.ceil(o.length*e.value/100);return g>=m}else if(e&&e.type==="number")return g>=e.value;return!1}async evaluateMemberAccess(t){let e=await this.evaluateNode(t.object),n=t.property;if(e!=null){if(typeof n=="string")return e[n];{let i=await this.evaluateNode(n);return e[i]}}}async evaluateArrayAccess(t){let e=await this.evaluateNode(t.object),n=await this.evaluateNode(t.index);if(e==null||!Array.isArray(e))return;let i=n<0?e.length+n:n;if(!(i<0||i>=e.length))return e[i]}async evaluateFunctionCall(t){let e=await this.evaluateNode(t.function),n=await Promise.all(t.arguments.map(s=>this.evaluateNode(s)));if(typeof e!="function")throw new Error(`Not a function: ${t.function}`);let i=e(...n);return i instanceof Promise?await i:i}async evaluateDataAccess(t){let e=await this.evaluateNode(t.offset),n=t.dataType,i=t.endian||"little";if(e<0||e>=this.data.length)return;let s=new DataView(this.data.buffer,this.data.byteOffset,this.data.byteLength),o=i==="little";try{switch(n){case"uint8":return s.getUint8(e);case"uint16":return s.getUint16(e,o);case"uint32":return s.getUint32(e,o);case"int8":return s.getInt8(e);case"int16":return s.getInt16(e,o);case"int32":return s.getInt32(e,o);default:throw new Error(`Unknown data type: ${n}`)}}catch{return}}async evaluateDefined(t){try{let e=await this.evaluateNode(t);return e!=null}catch{return!1}}async evaluateAt(t){let e=t.identifier;if(typeof e=="object"&&e.type==="string"){let s=await this.evaluateNode(t.offset),o=e.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}e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$);let n=await this.evaluateNode(t.offset),i=this.strings[e];return!i||!i.offsets?!1:i.offsets.includes(n)}async evaluateInRange(t){let e=t.identifier;e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$);let n=await this.evaluateNode(t.range),i=this.strings[e];return!i||!i.offsets?!1:i.offsets.some(s=>s>=n.start&&s<=n.end)}async evaluateWithin(t){let e=t.identifier,n=t.reference;e==="$"&&this.forContext&&this.forContext.$&&(e=this.forContext.$),n==="$"&&this.forContext&&this.forContext.$&&(n=this.forContext.$);let i=await this.evaluateNode(t.distance),s=this.strings[e],o=this.strings[n];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(t){let{module:e,function:n,args:i}=t,s=this.modules[e];if(!s)return;let o=s[n];if(typeof o!="function")return;let u=await Promise.all(i.map(async a=>{let g=await this.evaluateNode(a);if(a.type==="stringIdentifier"){let m=this.strings[a.identifier];if(m&&m.matches&&m.matches.length>0){let d=m.matches[0];if(d.value)return d.value;if(this.data&&d.offset!==void 0&&d.length!==void 0){let w=this.data.slice(d.offset,d.offset+d.length);return new TextDecoder().decode(w)}}return""}return g}));try{let a=o.apply(s,u);return a instanceof Promise?await a:a}catch(a){throw new Error(`Error calling ${e}.${n}: ${a.message}`)}}async evaluateInOperator(t){let e=await this.evaluateNode(t.value),n=await this.evaluateNode(t.set);if(!this.isAnyUndefined(e,n))return Array.isArray(n)?n.includes(e):n&&typeof n=="object"&&n.start!==void 0&&n.end!==void 0?e>=n.start&&e<=n.end:!1}async stringContains(t,e,n=!1){let i=await this.evaluateNode(t),s=await this.evaluateNode(e);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(n&&(i=i.toLowerCase(),s=s.toLowerCase()),i.includes(s))}async stringStartsWith(t,e,n=!1){let i=await this.evaluateNode(t),s=await this.evaluateNode(e);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(n&&(i=i.toLowerCase(),s=s.toLowerCase()),i.startsWith(s))}async stringEndsWith(t,e,n=!1){let i=await this.evaluateNode(t),s=await this.evaluateNode(e);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(n&&(i=i.toLowerCase(),s=s.toLowerCase()),i.endsWith(s))}async stringEquals(t,e,n=!1){let i=await this.evaluateNode(t),s=await this.evaluateNode(e);if(!this.isAnyUndefined(i,s))return typeof i!="string"||typeof s!="string"?!1:(n&&(i=i.toLowerCase(),s=s.toLowerCase()),i===s)}async stringMatches(t,e){let n=await this.evaluateNode(t),i=await this.evaluateNode(e);if(this.isAnyUndefined(n,i))return;if(typeof n!="string")return!1;let s;if(i instanceof RegExp)s=i;else if(typeof i=="string")s=new RegExp(i);else return!1;return s.test(n)}};async function Gt(r,t){return new gt(t).evaluate(r)}var at="__LITERAL_";var We=[{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 Yt(r,t){let e=t;for(;e<r.length&&/\s/.test(r[e]);)e++;return e}function Ve(r){if(!r.startsWith("(")||!r.endsWith(")"))return!1;let t=0;for(let e=0;e<r.length;e++)if(r[e]==="("&&t++,r[e]===")"&&t--,t===0&&e<r.length-1)return!1;return!0}function qe(r,t){let e=!1;for(let n=1;n<r.length-1;n++){if(e){e=!1;continue}if(r[n]==="\\"){e=!0;continue}if(r[n]===t)return!0}return!1}function ke(r,t){return r.length===2?!0:!qe(r,t)}function Ge(r){let t=[],e=r,n=0,i=(s,o)=>{let u=new RegExp(`${o}(?:[^${o}\\\\]|\\\\.)*${o}`,"g");return s.replace(u,a=>{if(ke(a,o)){let g=`${at}${n}__`;return t.push({id:g,type:"string",value:a.slice(1,-1)}),n++,g}return a})};return e=i(e,'"'),e=i(e,"'"),{processed:e,literals:t}}function dt(r,t){if(!r||typeof r!="object")return r;if(r.type==="identifier"&&r.name&&r.name.startsWith(at)){let n=t.find(i=>i.id===r.name);if(n)return{type:"string",value:n.value}}let e={...r};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(Array.isArray(e[n])?e[n]=e[n].map(i=>{if(typeof i=="string"&&i.startsWith(at)){let s=t.find(o=>o.id===i);return s?s.value:i}return typeof i=="object"?dt(i,t):i}):typeof e[n]=="object"&&(e[n]=dt(e[n],t)));return e}function Kt(r,t={}){r=r.trim();let{processed:e,literals:n}=Ge(r),i=V(e,t);return dt(i,n)}function Ye(r){let t=/^(any|all|none|\d+|\d+%|\d+\.\.\d+)\s+of\s+(them|\([^)]+\))$/,e=r.match(t);if(!e)return null;let[,n,i]=e,s,o;if(n==="any")o="any";else if(n==="all")o="all";else if(n==="none")o="none";else if(n.includes("..")){let[a,g]=n.split("..").map(m=>parseInt(m));o="quantified",s={type:"range",min:a,max:g}}else n.endsWith("%")?(o="quantified",s={type:"percentage",value:parseInt(n)}):(o="quantified",s={type:"number",value:parseInt(n)});let u;return i==="them"?u="them":u=i.slice(1,-1).split(",").map(g=>g.trim()),{type:o,...s&&{quantifier:s},items:u}}function V(r,t={}){for(r=r.trim();Ve(r);)r=r.slice(1,-1).trim();let e=Ye(r);if(e)return e;let n=(d,w)=>{let _=L(r,` ${d} `);if(_===-1)return null;let v=Yt(r,_);return v+=w,v=Yt(r,v),{type:d,left:V(r.substring(0,_),t),right:V(r.substring(v),t)}},i=n("or",2);if(i)return i;let s=n("and",3);if(s)return s;if(r.trim().startsWith("for ")){let d=r.indexOf(":");if(d!==-1){let w=d+1;for(;w<r.length&&r[w]!=="(";)w++;if(w<r.length){let _=1,v=w+1;for(;v<r.length&&_>0;)r[v]==="("&&_++,r[v]===")"&&_--,v++;if(_===0){let U=r.substring(0,d).trim(),b=r.substring(w+1,v-1).trim(),y=f=>["all","any","none"].includes(f)?f:f.endsWith("%")?{type:"percentage",value:parseInt(f)}:{type:"number",value:parseInt(f)},c=f=>{let h=f.match(/^(\w+)\s+in\s+\((.+?)\.\.(.+?)\)$/);if(h)return{variable:h[1],set:{type:"range",start:A(h[2].trim()),end:A(h[3].trim())}};let p=f.match(/^of\s+(.+)$/);if(p){let x=p[1].trim(),C;return x==="them"?C="them":x.startsWith("(")&&x.endsWith(")")?C=x.slice(1,-1).split(",").map(j=>j.trim()):C=x,{variable:"$",set:{type:"stringSet",items:C}}}return{variable:null,set:null}},l=U.match(/^for\s+(all|any|none|\d+|(\d+)%)\s+(.+)$/);if(l){let f=y(l[1]),{variable:h,set:p}=c(l[3]);return{type:"for",quantifier:f,variable:h,set:p,condition:V(b,t)}}}}}}if(r.startsWith("not "))return{type:"not",operand:V(r.substring(4),t)};if(r.startsWith("defined "))return{type:"defined",operand:V(r.substring(8),t)};let o=r.match(/^(\$\w*|\w+)\s+at\s+(.+)$/);if(o){let d=o[1];if(d.startsWith("$"))return{type:"at",identifier:d,offset:A(o[2])};if(d.startsWith(at))return{type:"at",identifier:A(d),offset:A(o[2])}}let u=r.match(/^(\$\w*)\s+in\s+\((.+)\.\.(.+)\)$/);if(u)return{type:"inRange",identifier:u[1],range:{type:"range",start:A(u[2]),end:A(u[3])}};let a=r.match(/^(\$\w*)\s+within\s+(.+?)(?:\s+bytes)?\s+of\s+(\$\w*)$/);if(a)return{type:"within",identifier:a[1],distance:A(a[2]),reference:a[3]};let g=[{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 d of g){let w=L(r,` ${d.pattern} `);if(w!==-1){let _=w;for(;_<r.length&&/\s/.test(r[_]);)_++;for(_+=d.pattern.length;_<r.length&&/\s/.test(r[_]);)_++;return{type:d.type,left:A(r.substring(0,w)),right:A(r.substring(_))}}}let m=[{pattern:"==",type:"equal"},{pattern:"!=",type:"notEqual"},{pattern:"<=",type:"lessThanOrEqual"},{pattern:">=",type:"greaterThanOrEqual"},{pattern:"<",type:"lessThan"},{pattern:">",type:"greaterThan"}];for(let d of m){let w=L(r,d.pattern);if(w!==-1)return{type:d.type,left:A(r.substring(0,w)),right:A(r.substring(w+d.pattern.length))}}return A(r)}function A(r){if(r=r.trim(),r==="true")return{type:"boolean",value:!0};if(r==="false")return{type:"boolean",value:!1};let t=r.match(/^(\d+)(KB|MB|GB)$/i);if(t){let v=parseInt(t[1]),U=t[2].toUpperCase(),b={KB:1024,MB:1024*1024,GB:1024*1024*1024};return{type:"number",value:v*b[U]}}if(/^-?\d+\.\d+$/.test(r))return{type:"number",value:parseFloat(r)};if(/^-?\d+$/.test(r))return{type:"number",value:parseInt(r)};if(/^0x[0-9a-fA-F]+$/.test(r))return{type:"number",value:parseInt(r,16)};if(/^\$\w*$/.test(r))return{type:"stringIdentifier",identifier:r};if(/^#\w*$/.test(r))return{type:"stringCount",identifier:r.replace("#","$")};if(/^@\w*$/.test(r))return{type:"stringOffset",identifier:r.replace("@","$"),index:0};let e=(v,U,b)=>{let y=new RegExp(`^\\${U}([\\w$]+)\\[([^\\]]+)\\]$`),c=v.match(y);if(!c)return null;let l=c[1],f=c[2].trim(),h=l.startsWith("$")?l:`$${l}`,p=/^\d+$/.test(f)?parseInt(f):A(f);return{type:b,identifier:h,index:p}},n=e(r,"@","stringOffset");if(n)return n;if(/^![\w$]+$/.test(r)){let v=r.slice(1);return{type:"stringLength",identifier:v.startsWith("$")?v:`$${v}`,index:0}}let i=e(r,"!","stringLength");if(i)return i;if(r==="filesize")return{type:"identifier",name:"filesize"};if(r==="entrypoint")return{type:"identifier",name:"entrypoint"};for(let v of We){let U=new RegExp(`^${v.name}\\((.+)\\)$`),b=r.match(U);if(b)return{type:"dataAccess",dataType:v.name.replace("be",""),offset:A(b[1]),endian:v.endian}}let s=r.match(/^(\w+)\.(\w+)\((.*)\)$/);if(s){let[,v,U,b]=s,y=[];if(b.trim()){let c=0,l="";for(let f=0;f<b.length;f++){let h=b[f];h==="("&&c++,h===")"&&c--,h===","&&c===0?(y.push(A(l.trim())),l=""):l+=h}l.trim()&&y.push(A(l.trim()))}return{type:"moduleFunction",module:v,function:U,args:y}}let o=r.match(/^(\w+)\.(\w+)\[([^\]]+)\]\.?(\w*)$/);if(o){let[,v,U,b,y]=o,c={type:"arrayAccess",object:{type:"memberAccess",object:{type:"identifier",name:v},property:U},index:A(b.trim())};if(y){let l=y.split(".");for(let f of l)f&&(c={type:"memberAccess",object:c,property:f})}return c}let u=r.match(/^(\w+)\.(\w+)$/);if(u){let[,v,U]=u;return{type:"memberAccess",object:{type:"identifier",name:v},property:U}}if(r.startsWith("~")){let v=r.substring(1).trim(),U=0;if(v.startsWith("(")){let c=1;for(U=1;U<v.length&&c>0;)v[U]==="("&&c++,v[U]===")"&&c--,U++}else if(v.startsWith("~")){let c=0;for(;c<v.length&&v[c]==="~";)c++;let l=v.substring(c).trim(),f=0;if(l.startsWith("(")){let h=1;for(f=1;f<l.length&&h>0;)l[f]==="("&&h++,l[f]===")"&&h--,f++}else{let h=l.match(/^([a-zA-Z_$]\w*)\s*\(/);if(h){let p=1;for(f=h[0].length;f<l.length&&p>0;)l[f]==="("&&p++,l[f]===")"&&p--,f++}else{let p=l.match(/^(0x[0-9a-fA-F]+|\d+|[a-zA-Z_$]\w*)/);p&&(f=p[0].length)}}U=c+f}else{let c=v.match(/^([a-zA-Z_$]\w*)\s*\(/);if(c){let l=1;for(U=c[0].length;U<v.length&&l>0;)v[U]==="("&&l++,v[U]===")"&&l--,U++}else{let l=v.match(/^(0x[0-9a-fA-F]+|\d+|[a-zA-Z_$]\w*)/);if(l)U=l[0].length;else return{type:"bitwiseNot",operand:A(v)}}}let b=A(v.substring(0,U)),y=v.substring(U).trim();if(y){let c="("+r.substring(0,U+1)+")"+y;return A(c)}return{type:"bitwiseNot",operand:b}}let a=L(r,"|");if(a!==-1)return{type:"bitwiseOr",left:A(r.substring(0,a)),right:A(r.substring(a+1))};let g=L(r,"^");if(g!==-1)return{type:"bitwiseXor",left:A(r.substring(0,g)),right:A(r.substring(g+1))};let m=L(r,"&");if(m!==-1)return{type:"bitwiseAnd",left:A(r.substring(0,m)),right:A(r.substring(m+1))};let d=L(r,"<<");if(d!==-1)return{type:"shiftLeft",left:A(r.substring(0,d)),right:A(r.substring(d+2))};let w=L(r,">>");if(w!==-1)return{type:"shiftRight",left:A(r.substring(0,w)),right:A(r.substring(w+2))};let _=[{pattern:"+",type:"add"},{pattern:"-",type:"subtract"},{pattern:"*",type:"multiply"},{pattern:"\\",type:"divide"},{pattern:"%",type:"modulo"}];for(let v of _){let U=L(r,v.pattern);if(U!==-1)return{type:v.type,left:A(r.substring(0,U)),right:A(r.substring(U+v.pattern.length))}}if(r.startsWith("(")&&r.endsWith(")")){let v=0,U=!0;for(let b=0;b<r.length;b++)if(r[b]==="("&&v++,r[b]===")"&&v--,v===0&&b<r.length-1){U=!1;break}if(U)return A(r.slice(1,-1))}return/^[A-Z][a-zA-Z0-9_]*$/.test(r)?{type:"ruleIdentifier",name:r}:{type:"identifier",name:r}}function L(r,t){let e=t.trim(),n=/^(and|or|not)$/.test(e),i=0,s=0;for(let o=0;o<r.length;o++)if(r[o]==="("&&i++,r[o]===")"&&i--,r[o]==="["&&s++,r[o]==="]"&&s--,i===0&&s===0){if(n){if(!(o===0||/\s/.test(r[o-1])))continue;let a=o;for(;a<r.length&&/\s/.test(r[a]);)a++;if(r.substring(a,a+e.length)===e){let g=a+e.length;if(g>=r.length||/\s/.test(r[g]))return o}}else if(r.substring(o,o+t.length)===t)return o}return-1}var ft={};Oe(ft,{ArrayFormatBase:()=>q,FormatBase:()=>I,ImageDataDirectoryArray:()=>T,ImageDirectoryEntry:()=>M,ImageDosHeader:()=>E,ImageFileHeader:()=>R,ImageNtHeaders:()=>W,ImageOptionalHeader:()=>P,ImageOptionalHeader64:()=>z,ImageSectionHeaderArray:()=>F,findImageSectionBlockByDirectoryEntry:()=>mn,getImageDosHeader:()=>pn,getImageNtHeadersByDosHeader:()=>gn,getImageSectionHeadersByNtHeaders:()=>dn});var Ke=(function(){function r(t){this.view=t}return r.prototype.copyTo=function(t,e){new Uint8Array(t,e,this.view.byteLength).set(new Uint8Array(this.view.buffer,this.view.byteOffset,this.view.byteLength))},Object.defineProperty(r.prototype,"byteLength",{get:function(){return this.view.byteLength},enumerable:!1,configurable:!0}),r})(),I=Ke;var Xe=(function(){var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}})(),mt=(function(r){Xe(t,r);function t(e){return r.call(this,e)||this}return t.prototype.forEach=function(e){var n=this.length,i=[];i.length=n;for(var s=0;s<n;++s)i[s]=this.get(s);for(var s=0;s<n;++s)e(i[s],s,this)},t.prototype._iterator=function(){return new((function(){function e(n){this.base=n,this.i=0}return e.prototype.next=function(){return this.i===this.base.length?{value:void 0,done:!0}:{value:this.base.get(this.i++),done:!1}},e})())(this)},t})(I);typeof Symbol<"u"&&(mt.prototype[Symbol.iterator]=mt.prototype._iterator);var q=mt;var Ze=(function(){var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}})(),Qe=(function(r){Ze(t,r);function t(e){var n=r.call(this,e)||this;return n.length=16,n}return t.from=function(e,n){return n===void 0&&(n=0),new t(new DataView(e,n,128))},t.prototype.get=function(e){return{virtualAddress:this.view.getUint32(e*8,!0),size:this.view.getUint32(4+e*8,!0)}},t.prototype.set=function(e,n){this.view.setUint32(e*8,n.virtualAddress,!0),this.view.setUint32(4+e*8,n.size,!0)},t.prototype.findIndexByVirtualAddress=function(e){for(var n=0;n<16;++n){var i=this.view.getUint32(n*8,!0),s=this.view.getUint32(4+n*8,!0);if(e>=i&&e<i+s)return n}return null},t.size=128,t.itemSize=8,t})(q),T=Qe;var Je={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=Je;function K(r){var t={};return Object.keys(r).forEach(function(e){t[e]=r[e]}),t}function X(r,t,e){if("buffer"in r){var n=r.byteOffset,i=r.byteLength;return typeof t<"u"&&(n+=t,i-=t),typeof e<"u"&&(i=e),new DataView(r.buffer,n,i)}else return new DataView(r,t,e)}function yt(r,t){for(var e=E.from(r),n=new DataView(r),i=e.newHeaderAddress+88,s=0,o=4294967296,u=function(_){s+=_,s>=o&&(s=s%o+(s/o|0))},a=n.byteLength,g=a%4,m=a-g,d=0;d<m;d+=4)d!==i&&u(n.getUint32(d,!0));if(g!==0){for(var w=0,d=0;d<g;d++)w|=n.getUint8(m+d)<<(3-d)*8;u(w)}return s=(s&65535)+(s>>>16),s+=s>>>16,s=(s&65535)+a,t&&n.setUint32(i,s,!0),s}function O(r,t){return Math.floor((r+t-1)/t)*t}function Z(r,t,e,n,i){var s="buffer"in r?new Uint8Array(r.buffer,r.byteOffset+(t||0),i):new Uint8Array(r,t,i),o="buffer"in e?new Uint8Array(e.buffer,e.byteOffset+(n||0),i):new Uint8Array(e,n,i);s.set(o)}function Q(r,t,e){var n=new ArrayBuffer(e);return Z(n,0,r,t,e),n}function ut(r){if("buffer"in r){var t=new ArrayBuffer(r.byteLength);return new Uint8Array(t).set(new Uint8Array(r.buffer,r.byteOffset,r.byteLength)),t}else{var t=new ArrayBuffer(r.byteLength);return new Uint8Array(t).set(new Uint8Array(r)),t}}function Xt(r,t,e){for(var n=0,i=0;i<e&&r.getUint8(t+i)!==0;++i)++n;if(typeof Buffer<"u")return Buffer.from(r.buffer,r.byteOffset+t,n).toString("utf8");if(typeof decodeURIComponent<"u"){for(var s="",i=0;i<n;++i){var o=r.getUint8(t+i);o<16?s+="%0"+o.toString(16):s+="%"+o.toString(16)}return decodeURIComponent(s)}else{for(var s="",i=0;i<n;++i){var o=r.getUint8(t+i);s+=String.fromCharCode(o)}return s}}function Zt(r,t,e,n){if(typeof Buffer<"u"){var i=new Uint8Array(r.buffer,r.byteOffset+t,e);i.set(new Uint8Array(e)),i.set(Buffer.from(n,"utf8").subarray(0,e))}else if(typeof encodeURIComponent<"u")for(var s=encodeURIComponent(n),o=0,u=0;o<e;++o)if(u>=s.length)r.setUint8(o+t,0);else{var a=s.charCodeAt(u);if(a===37){var g=parseInt(s.substr(u+1,2),16);typeof g=="number"&&!isNaN(g)?r.setUint8(o+t,g):r.setUint8(o+t,0),u+=3}else r.setUint8(o+t,a)}else for(var o=0,u=0;o<e;++o)if(u>=n.length)r.setUint8(o+t,0);else{var a=n.charCodeAt(u);r.setUint8(o+t,a&255)}}function Qt(r){if(typeof TextDecoder<"u"){var t=new TextDecoder;return t.decode(r)}else if(typeof Buffer<"u"){var e=void 0;return"buffer"in r?e=Buffer.from(r.buffer,r.byteOffset,r.byteLength):e=Buffer.from(r),e.toString("utf8")}else{var n=void 0;if("buffer"in r?n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength):n=new Uint8Array(r),typeof decodeURIComponent<"u"){for(var i="",s=0;s<n.length;++s){var o=n[s];o<16?i+="%0"+o.toString(16):i+="%"+o.toString(16)}return decodeURIComponent(i)}else{for(var i="",s=0;s<n.length;++s){var o=n[s];i+=String.fromCharCode(o)}return i}}}function Jt(r){if(typeof TextEncoder<"u"){var t=new TextEncoder;return ut(t.encode(r))}else{if(typeof Buffer<"u")return ut(Buffer.from(r,"utf8"));if(typeof encodeURIComponent<"u"){for(var e=encodeURIComponent(r),n=0,i=0;i<e.length;++n){var s=e.charCodeAt(i);s===37?i+=3:++i}for(var o=new ArrayBuffer(n),u=new Uint8Array(o),i=0,a=0;i<e.length;++a){var s=e.charCodeAt(i);if(s===37){var g=parseInt(e.substring(i+1,i+3),16);u[a]=g,i+=3}else u[a]=s,++i}return o}else{var o=new ArrayBuffer(r.length);return new Uint8Array(o).set([].map.call(r,function(d){return d.charCodeAt(0)})),o}}}var tn=(function(){var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}})(),en=(function(r){tn(t,r);function t(e){return r.call(this,e)||this}return t.from=function(e,n){return n===void 0&&(n=0),new t(X(e,n,64))},t.prototype.isValid=function(){return this.magic===t.DEFAULT_MAGIC},Object.defineProperty(t.prototype,"magic",{get:function(){return this.view.getUint16(0,!0)},set:function(e){this.view.setUint16(0,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"lastPageSize",{get:function(){return this.view.getUint16(2,!0)},set:function(e){this.view.setUint16(2,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"pages",{get:function(){return this.view.getUint16(4,!0)},set:function(e){this.view.setUint16(4,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"relocations",{get:function(){return this.view.getUint16(6,!0)},set:function(e){this.view.setUint16(6,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"headerSizeInParagraph",{get:function(){return this.view.getUint16(8,!0)},set:function(e){this.view.setUint16(8,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minAllocParagraphs",{get:function(){return this.view.getUint16(10,!0)},set:function(e){this.view.setUint16(10,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxAllocParagraphs",{get:function(){return this.view.getUint16(12,!0)},set:function(e){this.view.setUint16(12,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"initialSS",{get:function(){return this.view.getUint16(14,!0)},set:function(e){this.view.setUint16(14,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"initialSP",{get:function(){return this.view.getUint16(16,!0)},set:function(e){this.view.setUint16(16,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"checkSum",{get:function(){return this.view.getUint16(18,!0)},set:function(e){this.view.setUint16(18,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"initialIP",{get:function(){return this.view.getUint16(20,!0)},set:function(e){this.view.setUint16(20,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"initialCS",{get:function(){return this.view.getUint16(22,!0)},set:function(e){this.view.setUint16(22,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"relocationTableAddress",{get:function(){return this.view.getUint16(24,!0)},set:function(e){this.view.setUint16(24,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"overlayNum",{get:function(){return this.view.getUint16(26,!0)},set:function(e){this.view.setUint16(26,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"oemId",{get:function(){return this.view.getUint16(36,!0)},set:function(e){this.view.setUint16(36,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"oemInfo",{get:function(){return this.view.getUint16(38,!0)},set:function(e){this.view.setUint16(38,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"newHeaderAddress",{get:function(){return this.view.getUint32(60,!0)},set:function(e){this.view.setUint32(60,e,!0)},enumerable:!1,configurable:!0}),t.size=64,t.DEFAULT_MAGIC=23117,t})(I),E=en;var nn=(function(){var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}})(),rn=(function(r){nn(t,r);function t(e){return r.call(this,e)||this}return t.from=function(e,n){return n===void 0&&(n=0),new t(new DataView(e,n,20))},Object.defineProperty(t.prototype,"machine",{get:function(){return this.view.getUint16(0,!0)},set:function(e){this.view.setUint16(0,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"numberOfSections",{get:function(){return this.view.getUint16(2,!0)},set:function(e){this.view.setUint16(2,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"timeDateStamp",{get:function(){return this.view.getUint32(4,!0)},set:function(e){this.view.setUint32(4,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"pointerToSymbolTable",{get:function(){return this.view.getUint32(8,!0)},set:function(e){this.view.setUint32(8,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"numberOfSymbols",{get:function(){return this.view.getUint32(12,!0)},set:function(e){this.view.setUint32(12,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfOptionalHeader",{get:function(){return this.view.getUint16(16,!0)},set:function(e){this.view.setUint16(16,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"characteristics",{get:function(){return this.view.getUint16(18,!0)},set:function(e){this.view.setUint16(18,e,!0)},enumerable:!1,configurable:!0}),t.size=20,t})(I),R=rn;var sn=(function(){var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}})(),on=(function(r){sn(t,r);function t(e){return r.call(this,e)||this}return t.from=function(e,n){return n===void 0&&(n=0),new t(new DataView(e,n,96))},Object.defineProperty(t.prototype,"magic",{get:function(){return this.view.getUint16(0,!0)},set:function(e){this.view.setUint16(0,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"majorLinkerVersion",{get:function(){return this.view.getUint8(2)},set:function(e){this.view.setUint8(2,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minorLinkerVersion",{get:function(){return this.view.getUint8(3)},set:function(e){this.view.setUint8(3,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfCode",{get:function(){return this.view.getUint32(4,!0)},set:function(e){this.view.setUint32(4,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfInitializedData",{get:function(){return this.view.getUint32(8,!0)},set:function(e){this.view.setUint32(8,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfUninitializedData",{get:function(){return this.view.getUint32(12,!0)},set:function(e){this.view.setUint32(12,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"addressOfEntryPoint",{get:function(){return this.view.getUint32(16,!0)},set:function(e){this.view.setUint32(16,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"baseOfCode",{get:function(){return this.view.getUint32(20,!0)},set:function(e){this.view.setUint32(20,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"baseOfData",{get:function(){return this.view.getUint32(24,!0)},set:function(e){this.view.setUint32(24,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"imageBase",{get:function(){return this.view.getUint32(28,!0)},set:function(e){this.view.setUint32(28,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sectionAlignment",{get:function(){return this.view.getUint32(32,!0)},set:function(e){this.view.setUint32(32,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"fileAlignment",{get:function(){return this.view.getUint32(36,!0)},set:function(e){this.view.setUint32(36,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"majorOperatingSystemVersion",{get:function(){return this.view.getUint16(40,!0)},set:function(e){this.view.setUint16(40,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minorOperatingSystemVersion",{get:function(){return this.view.getUint16(42,!0)},set:function(e){this.view.setUint16(42,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"majorImageVersion",{get:function(){return this.view.getUint16(44,!0)},set:function(e){this.view.setUint16(44,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minorImageVersion",{get:function(){return this.view.getUint16(46,!0)},set:function(e){this.view.setUint16(46,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"majorSubsystemVersion",{get:function(){return this.view.getUint16(48,!0)},set:function(e){this.view.setUint16(48,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minorSubsystemVersion",{get:function(){return this.view.getUint16(50,!0)},set:function(e){this.view.setUint16(50,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"win32VersionValue",{get:function(){return this.view.getUint32(52,!0)},set:function(e){this.view.setUint32(52,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfImage",{get:function(){return this.view.getUint32(56,!0)},set:function(e){this.view.setUint32(56,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfHeaders",{get:function(){return this.view.getUint32(60,!0)},set:function(e){this.view.setUint32(60,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"checkSum",{get:function(){return this.view.getUint32(64,!0)},set:function(e){this.view.setUint32(64,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"subsystem",{get:function(){return this.view.getUint16(68,!0)},set:function(e){this.view.setUint16(68,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dllCharacteristics",{get:function(){return this.view.getUint16(70,!0)},set:function(e){this.view.setUint16(70,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfStackReserve",{get:function(){return this.view.getUint32(72,!0)},set:function(e){this.view.setUint32(72,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfStackCommit",{get:function(){return this.view.getUint32(76,!0)},set:function(e){this.view.setUint32(76,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfHeapReserve",{get:function(){return this.view.getUint32(80,!0)},set:function(e){this.view.setUint32(80,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfHeapCommit",{get:function(){return this.view.getUint32(84,!0)},set:function(e){this.view.setUint32(84,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loaderFlags",{get:function(){return this.view.getUint32(88,!0)},set:function(e){this.view.setUint32(88,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"numberOfRvaAndSizes",{get:function(){return this.view.getUint32(92,!0)},set:function(e){this.view.setUint32(92,e,!0)},enumerable:!1,configurable:!0}),t.size=96,t.DEFAULT_MAGIC=267,t})(I),P=on;var an=(function(){var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}})();function J(r,t){return r.getUint32(t+4,!0)*4294967296+r.getUint32(t,!0)}function tt(r,t,e){r.setUint32(t,e&4294967295,!0),r.setUint32(t+4,Math.floor(e/4294967296),!0)}function et(r,t){if(typeof BigInt>"u")throw new Error("BigInt not supported");return BigInt(4294967296)*BigInt(r.getUint32(t+4,!0))+BigInt(r.getUint32(t,!0))}function nt(r,t,e){if(typeof BigInt>"u")throw new Error("BigInt not supported");r.setUint32(t,Number(e&BigInt(4294967295)),!0),r.setUint32(t+4,Math.floor(Number(e/BigInt(4294967296)&BigInt(4294967295))),!0)}var un=(function(r){an(t,r);function t(e){return r.call(this,e)||this}return t.from=function(e,n){return n===void 0&&(n=0),new t(new DataView(e,n,112))},Object.defineProperty(t.prototype,"magic",{get:function(){return this.view.getUint16(0,!0)},set:function(e){this.view.setUint16(0,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"majorLinkerVersion",{get:function(){return this.view.getUint8(2)},set:function(e){this.view.setUint8(2,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minorLinkerVersion",{get:function(){return this.view.getUint8(3)},set:function(e){this.view.setUint8(3,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfCode",{get:function(){return this.view.getUint32(4,!0)},set:function(e){this.view.setUint32(4,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfInitializedData",{get:function(){return this.view.getUint32(8,!0)},set:function(e){this.view.setUint32(8,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfUninitializedData",{get:function(){return this.view.getUint32(12,!0)},set:function(e){this.view.setUint32(12,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"addressOfEntryPoint",{get:function(){return this.view.getUint32(16,!0)},set:function(e){this.view.setUint32(16,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"baseOfCode",{get:function(){return this.view.getUint32(20,!0)},set:function(e){this.view.setUint32(20,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"imageBase",{get:function(){return J(this.view,24)},set:function(e){tt(this.view,24,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"imageBaseBigInt",{get:function(){return et(this.view,24)},set:function(e){nt(this.view,24,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sectionAlignment",{get:function(){return this.view.getUint32(32,!0)},set:function(e){this.view.setUint32(32,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"fileAlignment",{get:function(){return this.view.getUint32(36,!0)},set:function(e){this.view.setUint32(36,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"majorOperatingSystemVersion",{get:function(){return this.view.getUint16(40,!0)},set:function(e){this.view.setUint16(40,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minorOperatingSystemVersion",{get:function(){return this.view.getUint16(42,!0)},set:function(e){this.view.setUint16(42,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"majorImageVersion",{get:function(){return this.view.getUint16(44,!0)},set:function(e){this.view.setUint16(44,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minorImageVersion",{get:function(){return this.view.getUint16(46,!0)},set:function(e){this.view.setUint16(46,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"majorSubsystemVersion",{get:function(){return this.view.getUint16(48,!0)},set:function(e){this.view.setUint16(48,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minorSubsystemVersion",{get:function(){return this.view.getUint16(50,!0)},set:function(e){this.view.setUint16(50,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"win32VersionValue",{get:function(){return this.view.getUint32(52,!0)},set:function(e){this.view.setUint32(52,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfImage",{get:function(){return this.view.getUint32(56,!0)},set:function(e){this.view.setUint32(56,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfHeaders",{get:function(){return this.view.getUint32(60,!0)},set:function(e){this.view.setUint32(60,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"checkSum",{get:function(){return this.view.getUint32(64,!0)},set:function(e){this.view.setUint32(64,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"subsystem",{get:function(){return this.view.getUint16(68,!0)},set:function(e){this.view.setUint16(68,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dllCharacteristics",{get:function(){return this.view.getUint16(70,!0)},set:function(e){this.view.setUint16(70,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfStackReserve",{get:function(){return J(this.view,72)},set:function(e){tt(this.view,72,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfStackReserveBigInt",{get:function(){return et(this.view,72)},set:function(e){nt(this.view,72,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfStackCommit",{get:function(){return J(this.view,80)},set:function(e){tt(this.view,80,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfStackCommitBigInt",{get:function(){return et(this.view,80)},set:function(e){nt(this.view,80,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfHeapReserve",{get:function(){return J(this.view,88)},set:function(e){tt(this.view,88,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfHeapReserveBigInt",{get:function(){return et(this.view,88)},set:function(e){nt(this.view,88,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfHeapCommit",{get:function(){return J(this.view,96)},set:function(e){tt(this.view,96,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sizeOfHeapCommitBigInt",{get:function(){return et(this.view,96)},set:function(e){nt(this.view,96,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loaderFlags",{get:function(){return this.view.getUint32(104,!0)},set:function(e){this.view.setUint32(104,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"numberOfRvaAndSizes",{get:function(){return this.view.getUint32(108,!0)},set:function(e){this.view.setUint32(108,e,!0)},enumerable:!1,configurable:!0}),t.size=112,t.DEFAULT_MAGIC=523,t})(I),z=un;var fn=(function(){var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}})(),ln=(function(r){fn(t,r);function t(e){return r.call(this,e)||this}return t.from=function(e,n){n===void 0&&(n=0);var i=X(e,n+R.size,6).getUint16(4,!0),s=4+R.size+T.size;return i===z.DEFAULT_MAGIC?s+=z.size:s+=P.size,new t(X(e,n,s))},t.prototype.isValid=function(){return this.signature===t.DEFAULT_SIGNATURE},t.prototype.is32bit=function(){return this.view.getUint16(R.size+4,!0)===P.DEFAULT_MAGIC},Object.defineProperty(t.prototype,"signature",{get:function(){return this.view.getUint32(0,!0)},set:function(e){this.view.setUint32(0,e,!0)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"fileHeader",{get:function(){return R.from(this.view.buffer,this.view.byteOffset+4)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"optionalHeader",{get:function(){var e=R.size+4,n=this.view.getUint16(e,!0);return n===z.DEFAULT_MAGIC?z.from(this.view.buffer,this.view.byteOffset+e):P.from(this.view.buffer,this.view.byteOffset+e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"optionalHeaderDataDirectory",{get:function(){return T.from(this.view.buffer,this.view.byteOffset+this.getDataDirectoryOffset())},enumerable:!1,configurable:!0}),t.prototype.getDataDirectoryOffset=function(){var e=R.size+4,n=this.view.getUint16(e,!0);return n===z.DEFAULT_MAGIC?e+=z.size:e+=P.size,e},t.prototype.getSectionHeaderOffset=function(){return this.getDataDirectoryOffset()+T.size},t.DEFAULT_SIGNATURE=17744,t})(I),W=ln;var cn=(function(){var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(t,e)};return function(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}})(),hn=(function(r){cn(t,r);function t(e,n){var i=r.call(this,e)||this;return i.length=n,i}return t.from=function(e,n,i){i===void 0&&(i=0);var s=n*40;return new t(new DataView(e,i,s),n)},t.prototype.get=function(e){return{name:Xt(this.view,e*40,8),virtualSize:this.view.getUint32(8+e*40,!0),virtualAddress:this.view.getUint32(12+e*40,!0),sizeOfRawData:this.view.getUint32(16+e*40,!0),pointerToRawData:this.view.getUint32(20+e*40,!0),pointerToRelocations:this.view.getUint32(24+e*40,!0),pointerToLineNumbers:this.view.getUint32(28+e*40,!0),numberOfRelocations:this.view.getUint16(32+e*40,!0),numberOfLineNumbers:this.view.getUint16(34+e*40,!0),characteristics:this.view.getUint32(36+e*40,!0)}},t.prototype.set=function(e,n){Zt(this.view,e*40,8,n.name),this.view.setUint32(8+e*40,n.virtualSize,!0),this.view.setUint32(12+e*40,n.virtualAddress,!0),this.view.setUint32(16+e*40,n.sizeOfRawData,!0),this.view.setUint32(20+e*40,n.pointerToRawData,!0),this.view.setUint32(24+e*40,n.pointerToRelocations,!0),this.view.setUint32(28+e*40,n.pointerToLineNumbers,!0),this.view.setUint16(32+e*40,n.numberOfRelocations,!0),this.view.setUint16(34+e*40,n.numberOfLineNumbers,!0),this.view.setUint32(36+e*40,n.characteristics,!0)},t.itemSize=40,t})(q),F=hn;function pn(r){return E.from(r)}function gn(r,t){return W.from(r,t.newHeaderAddress)}function dn(r,t,e){return F.from(r,e.fileHeader.numberOfSections,t.newHeaderAddress+e.byteLength)}function mn(r,t,e,n){for(var i=F.from(r,e.fileHeader.numberOfSections,t.newHeaderAddress+e.byteLength),s=i.length,o=e.optionalHeaderDataDirectory.get(n).virtualAddress,u=0;u<s;++u){var a=i.get(u),g=a.virtualAddress+a.virtualSize;if(o>=a.virtualAddress&&o<g){var m=a.pointerToRawData;return m?r.slice(m,m+a.sizeOfRawData):null}if(o<a.virtualAddress)return null}return null}var wt=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]),rt=O(E.size+wt.length,128),te=512;function yn(r){var t=E.from(r);t.magic=E.DEFAULT_MAGIC,t.lastPageSize=rt%512,t.pages=Math.ceil(rt/512),t.relocations=0,t.headerSizeInParagraph=Math.ceil(E.size/16),t.minAllocParagraphs=0,t.maxAllocParagraphs=65535,t.initialSS=0,t.initialSP=128,t.relocationTableAddress=E.size,t.newHeaderAddress=rt,Z(r,E.size,wt,0,wt.length)}function wn(r){return 4+R.size+(r?P.size:z.size)+T.size}function vn(r,t,e,n,i){var s,o;"buffer"in r?(s=r.buffer,o=r.byteOffset+t):(s=r,o=t),new DataView(s,o).setUint32(0,W.DEFAULT_SIGNATURE,!0);var u=R.from(s,o+4);u.machine=n?332:34404,u.numberOfSections=0,u.timeDateStamp=0,u.pointerToSymbolTable=0,u.numberOfSymbols=0,u.sizeOfOptionalHeader=(n?P.size:z.size)+T.size,u.characteristics=i?8450:258;var a=(n?P:z).from(s,o+4+R.size);a.magic=n?P.DEFAULT_MAGIC:z.DEFAULT_MAGIC,a.sizeOfCode=0,a.sizeOfInitializedData=0,a.sizeOfUninitializedData=0,a.addressOfEntryPoint=0,a.baseOfCode=4096,a.imageBase=n?16777216:6442450944,a.sectionAlignment=4096,a.fileAlignment=te,a.majorOperatingSystemVersion=6,a.minorOperatingSystemVersion=0,a.majorSubsystemVersion=6,a.minorSubsystemVersion=0,a.sizeOfHeaders=O(e,a.fileAlignment),a.subsystem=2,a.dllCharacteristics=(n?0:32)+64+256,a.sizeOfStackReserve=1048576,a.sizeOfStackCommit=4096,a.sizeOfHeapReserve=1048576,a.sizeOfHeapCommit=4096,a.numberOfRvaAndSizes=T.size/T.itemSize}function ee(r,t){var e=O(rt+wn(r),te),n=new ArrayBuffer(e);return yn(n),vn(n,rt,e,r,t),n}var bn=(function(){function r(t,e,n){this._headers=t,this._sections=e,this._ex=n;var i=E.from(t),s=W.from(t,i.newHeaderAddress);this._dh=i,this._nh=s,this._dda=s.optionalHeaderDataDirectory,e.sort(function(o,u){var a=o.info.pointerToRawData,g=o.info.pointerToRawData;if(a!==g)return a-g;var m=o.info.virtualAddress,d=u.info.virtualAddress;return m===d?o.info.virtualSize-u.info.virtualSize:m-d})}return r.createEmpty=function(t,e){return t===void 0&&(t=!1),e===void 0&&(e=!0),this.from(ee(t,e))},r.from=function(t,e){var n=E.from(t),i=W.from(t,n.newHeaderAddress);if(!n.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&&!e?.ignoreCert)throw new Error("Parsing signed executable binary is not allowed by default.");var u=n.newHeaderAddress+i.getSectionHeaderOffset(),a=i.fileHeader.numberOfSections,g=[],m=Q(t,u,a*F.itemSize),d=F.from(m,a,0),w=O(u+a*F.itemSize,s);d.forEach(function(b){if(!b.pointerToRawData||!b.sizeOfRawData)b.pointerToRawData=0,b.sizeOfRawData=0,g.push({info:b,data:null});else{var y=Q(t,b.pointerToRawData,b.sizeOfRawData);g.push({info:b,data:y});var c=O(b.pointerToRawData+b.sizeOfRawData,s);c>w&&(w=c)}});var _=Q(t,0,u),v=null,U=t.byteLength;return o.size>0&&(U=o.virtualAddress),w<U&&(v=Q(t,w,U-w)),new r(_,g,v)},r.prototype.is32bit=function(){return this._nh.is32bit()},r.prototype.getTotalHeaderSize=function(){return this._headers.byteLength},Object.defineProperty(r.prototype,"dosHeader",{get:function(){return this._dh},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"newHeader",{get:function(){return this._nh},enumerable:!1,configurable:!0}),r.prototype.getRawHeader=function(){return this._headers},r.prototype.getImageBase=function(){return this._nh.optionalHeader.imageBase},r.prototype.getFileAlignment=function(){return this._nh.optionalHeader.fileAlignment},r.prototype.getSectionAlignment=function(){return this._nh.optionalHeader.sectionAlignment},r.prototype.getAllSections=function(){return this._sections},r.prototype.getSectionByEntry=function(t){var e=this._dda.get(t),n=this._sections.filter(function(i){var s=i.info.virtualAddress+i.info.virtualSize;return e.virtualAddress>=i.info.virtualAddress&&e.virtualAddress<s}).shift();return n!==void 0?n:null},r.prototype.setSectionByEntry=function(t,e){var n=e?{data:e.data,info:e.info}:null,i=this._dda.get(t),s=i.size>0;if(n){var d=n.data?n.data.byteLength:0,w=this._nh.optionalHeader.fileAlignment,_=this._nh.optionalHeader.sectionAlignment,v=n.data?O(d,w):0,U=n.data?O(n.info.virtualSize,_):0;if(n.info.sizeOfRawData<v?n.info.sizeOfRawData=v:v=n.info.sizeOfRawData,s)this.replaceSectionImpl(i.virtualAddress,n.info,n.data);else{var b=0,y=O(this._headers.byteLength,w);this._sections.forEach(function(c){c.info.pointerToRawData&&y<=c.info.pointerToRawData&&(y=c.info.pointerToRawData+c.info.sizeOfRawData),b<=c.info.virtualAddress&&(b=c.info.virtualAddress+c.info.virtualSize)}),v||(y=0),b||(b=this.newHeader.optionalHeader.baseOfCode),b=O(b,_),n.info.pointerToRawData=y,n.info.virtualAddress=b,this._dda.set(t,{size:d,virtualAddress:b}),this._sections.push(n),this._nh.fileHeader.numberOfSections=this._sections.length,this._nh.optionalHeader.sizeOfImage=O(b+U,this._nh.optionalHeader.sectionAlignment)}}else if(s){this._dda.set(t,{size:0,virtualAddress:0});for(var o=this._sections.length,u=0;u<o;++u){var a=this._sections[u],g=a.info.virtualAddress,m=g+a.info.virtualSize;if(i.virtualAddress>=g&&i.virtualAddress<m){this._sections.splice(u,1),this._nh.fileHeader.numberOfSections=this._sections.length;break}}}},r.prototype.getExtraData=function(){return this._ex},r.prototype.setExtraData=function(t){t===null?this._ex=null:this._ex=ut(t)},r.prototype.generate=function(t){var e=this._dh,n=this._nh,i=e.newHeaderAddress+n.getSectionHeaderOffset(),s=i;s+=this._sections.length*F.itemSize;var o=n.optionalHeader.fileAlignment;s=O(s,o),this._sections.forEach(function(d){if(d.info.pointerToRawData){var w=d.info.pointerToRawData+d.info.sizeOfRawData;s<w&&(s=w,s=O(s,o))}});var u=s;this._ex!==null&&(s+=this._ex.byteLength),typeof t=="number"&&(s+=t);var a=new ArrayBuffer(s),g=new Uint8Array(a);g.set(new Uint8Array(this._headers,0,i)),T.from(a,e.newHeaderAddress+n.getDataDirectoryOffset()).set(M.Certificate,{size:0,virtualAddress:0});var m=F.from(a,this._sections.length,i);return this._sections.forEach(function(d,w){d.data||(d.info.pointerToRawData=0,d.info.sizeOfRawData=0),m.set(w,d.info),!(!d.data||!d.info.pointerToRawData)&&g.set(new Uint8Array(d.data),d.info.pointerToRawData)}),this._ex!==null&&g.set(new Uint8Array(this._ex),u),n.optionalHeader.checkSum!==0&&yt(a,!0),a},r.prototype.rearrangeSections=function(t,e,n,i){if(!(!e&&!i)){for(var s=this._nh,o=s.optionalHeader.sectionAlignment,u=this._dda,a=this._sections.length,g=0,m=0;m<a;++m){var d=this._sections[m],w=d.info.virtualAddress;if(i&&w>=n){var _=u.findIndexByVirtualAddress(w);w+=i,_!==null&&u.set(_,{virtualAddress:w,size:d.info.virtualSize}),d.info.virtualAddress=w}var v=d.info.pointerToRawData;e&&v>=t&&(d.info.pointerToRawData=v+e),g=O(d.info.virtualAddress+d.info.virtualSize,o)}s.optionalHeader.sizeOfImage=g}},r.prototype.replaceSectionImpl=function(t,e,n){for(var i=this._sections.length,s=0;s<i;++s){var o=this._sections[s];if(o.info.virtualAddress===t){var u=this._nh.optionalHeader.sectionAlignment,a=o.info.pointerToRawData,g=a+o.info.sizeOfRawData,m=t+O(o.info.virtualSize,u);o.info=K(e),o.info.virtualAddress=t,o.info.pointerToRawData=a,o.data=n;var d=a+e.sizeOfRawData,w=t+O(e.virtualSize,u);this.rearrangeSections(g,d-g,m,w-m);{var _=this._dda,v=_.findIndexByVirtualAddress(t);v!==null&&_.set(v,{virtualAddress:t,size:e.virtualSize})}break}}},r})(),vt=bn;function _n(r){return r.reduce(function(t,e){return t.indexOf(e)>=0?t:t.concat(e)},[])}function bt(r,t){var e=r.getUint16(t,!0),n="";t+=2;for(var i=0;i<e;++i)n+=String.fromCharCode(r.getUint16(t,!0)),t+=2;return n}function ne(r,t,e,n,i){var s=n,o={name:e,languageTable:n,characteristics:r.getUint32(s,!0),dateTime:r.getUint32(s+4,!0),majorVersion:r.getUint16(s+8,!0),minorVersion:r.getUint16(s+10,!0)},u=r.getUint16(s+12,!0),a=r.getUint16(s+14,!0);s+=16;for(var g=0;g<u;++g){var m=r.getUint32(s,!0)&2147483647,d=r.getUint32(s+4,!0);if((d&2147483648)!==0){s+=8;continue}var w=bt(r,m);i(t,o,{lang:w,dataOffset:d}),s+=8}for(var g=0;g<a;++g){var _=r.getUint32(s,!0)&2147483647,d=r.getUint32(s+4,!0);if((d&2147483648)!==0){s+=8;continue}i(t,o,{lang:_,dataOffset:d}),s+=8}}function re(r,t,e,n){var i=e,s={type:t,nameTable:e,characteristics:r.getUint32(i,!0),dateTime:r.getUint32(i+4,!0),majorVersion:r.getUint16(i+8,!0),minorVersion:r.getUint16(i+10,!0)},o=r.getUint16(i+12,!0),u=r.getUint16(i+14,!0);i+=16;for(var a=0;a<o;++a){var g=r.getUint32(i,!0)&2147483647,m=r.getUint32(i+4,!0);if(!(m&2147483648)){i+=8;continue}m&=2147483647;var d=bt(r,g);ne(r,s,d,m,n),i+=8}for(var a=0;a<u;++a){var w=r.getUint32(i,!0)&2147483647,m=r.getUint32(i+4,!0);if(!(m&2147483648)){i+=8;continue}m&=2147483647,ne(r,s,w,m,n),i+=8}}function ie(r,t,e){var n={},i={};e.forEach(function(u){typeof u.lang=="string"?(n[u.lang]=u,t.push(u.lang)):i[u.lang]=u});var s=Object.keys(n);s.sort().forEach(function(u){r.s.push(n[u])});var o=Object.keys(i);return o.map(function(u){return Number(u)}).sort(function(u,a){return u-a}).forEach(function(u){r.n.push(i[u])}),16+8*(s.length+o.length)}function se(r,t,e){var n={},i={};e.forEach(function(u){var a,g;if(typeof u.id=="string"){var m=(a=n[u.id])!==null&&a!==void 0?a:n[u.id]=[];t.push(u.id),m.push(u)}else{var m=(g=i[u.id])!==null&&g!==void 0?g:i[u.id]=[];m.push(u)}});var s=Object.keys(n).sort().map(function(u){var a={id:u,s:[],n:[]};return r.s.push(a),ie(a,t,n[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 r.n.push(a),ie(a,t,i[u])}).reduce(function(u,a){return u+8+a},0);return 16+s+o}function Un(r,t,e){var n={},i={};e.forEach(function(u){var a,g;if(typeof u.type=="string"){var m=(a=n[u.type])!==null&&a!==void 0?a:n[u.type]=[];t.push(u.type),m.push(u)}else{var m=(g=i[u.type])!==null&&g!==void 0?g:i[u.type]=[];m.push(u)}});var s=Object.keys(n).sort().map(function(u){var a={type:u,s:[],n:[]};return r.s.push(a),se(a,t,n[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 r.n.push(a),se(a,t,i[u])}).reduce(function(u,a){return u+8+a},0);return 16+s+o}function ue(r){var t=r.length;return t>65535?65535:t}function _t(r,t){for(var e=t.length,n=0;n<e;++n){var i=t[n];if(i.text===r)return i.offset}throw new Error("Unexpected")}function An(r,t,e){var n=ue(e);r.setUint16(t,n,!0),t+=2;for(var i=0;i<n;++i)r.setUint16(t,e.charCodeAt(i),!0),t+=2;return t}function oe(r,t,e,n){return r.setUint32(t,0,!0),r.setUint32(t+4,0,!0),r.setUint32(t+8,0,!0),r.setUint16(t+12,n.s.length,!0),r.setUint16(t+14,n.n.length,!0),t+=16,n.s.forEach(function(i){var s=_t(i.lang,e);r.setUint32(t,s,!0),r.setUint32(t+4,i.offset,!0),t+=8}),n.n.forEach(function(i){r.setUint32(t,i.lang,!0),r.setUint32(t+4,i.offset,!0),t+=8}),t}function ae(r,t,e,n,i){return r.setUint32(t,0,!0),r.setUint32(t+4,0,!0),r.setUint32(t+8,0,!0),r.setUint16(t+12,i.s.length,!0),r.setUint16(t+14,i.n.length,!0),t+=16,i.s.forEach(function(s){s.offset=e,e=oe(r,e,n,s)}),i.n.forEach(function(s){s.offset=e,e=oe(r,e,n,s)}),i.s.forEach(function(s){var o=_t(s.id,n);r.setUint32(t,o+2147483648,!0),r.setUint32(t+4,s.offset+2147483648,!0),t+=8}),i.n.forEach(function(s){r.setUint32(t,s.id,!0),r.setUint32(t+4,s.offset+2147483648,!0),t+=8}),e}function xn(r,t,e,n){r.setUint32(t,0,!0),r.setUint32(t+4,0,!0),r.setUint32(t+8,0,!0),r.setUint16(t+12,n.s.length,!0),r.setUint16(t+14,n.n.length,!0),t+=16;var i=t+8*(n.s.length+n.n.length);return n.s.forEach(function(s){s.offset=i,i+=16+8*(s.s.length+s.n.length)}),n.n.forEach(function(s){s.offset=i,i+=16+8*(s.s.length+s.n.length)}),n.s.forEach(function(s){var o=_t(s.type,e);r.setUint32(t,o+2147483648,!0),r.setUint32(t+4,s.offset+2147483648,!0),t+=8,i=ae(r,s.offset,i,e,s)}),n.n.forEach(function(s){r.setUint32(t,s.type,!0),r.setUint32(t+4,s.offset+2147483648,!0),t+=8,i=ae(r,s.offset,i,e,s)}),i}var hi=(function(){function r(){this.dateTime=0,this.majorVersion=0,this.minorVersion=0,this.entries=[],this.sectionDataHeader=null,this.originalSize=0}return r.prototype.parse=function(t,e){if(t.data){var n=new DataView(t.data);this.dateTime=n.getUint32(4,!0),this.majorVersion=n.getUint16(8,!0),this.minorVersion=n.getUint16(10,!0);for(var i=n.getUint16(12,!0),s=n.getUint16(14,!0),o=16,u=[],a=function(v,U,b){var y=n.getUint32(b.dataOffset,!0)-t.info.virtualAddress,c=n.getUint32(b.dataOffset+4,!0),l=n.getUint32(b.dataOffset+8,!0);if(y>=0){var f=new Uint8Array(c);f.set(new Uint8Array(t.data,y,c)),u.push({type:v.type,id:U.name,lang:b.lang,codepage:l,bin:f.buffer})}else{if(!e)throw new Error("Cannot parse resource directory entry; RVA seems to be invalid.");u.push({type:v.type,id:U.name,lang:b.lang,codepage:l,bin:new ArrayBuffer(0),rva:b.dataOffset})}},g=0;g<i;++g){var m=n.getUint32(o,!0)&2147483647,d=n.getUint32(o+4,!0);if(!(d&2147483648)){o+=8;continue}d&=2147483647;var w=bt(n,m);re(n,w,d,a),o+=8}for(var g=0;g<s;++g){var _=n.getUint32(o,!0)&2147483647,d=n.getUint32(o+4,!0);if(!(d&2147483648)){o+=8;continue}d&=2147483647,re(n,_,d,a),o+=8}this.entries=u,this.originalSize=t.data.byteLength}},r.from=function(t,e){e===void 0&&(e=!1);var n=[].concat(t.getAllSections()).sort(function(m,d){return m.info.virtualAddress-d.info.virtualAddress}),i=t.getSectionByEntry(M.Resource);if(i)for(var s=t.getSectionByEntry(M.BaseRelocation),o=0;o<n.length;++o){var u=n[o];if(u===i){for(var a=o+1;a<n.length;++a)if(!s||n[a]!==s)throw new Error("After Resource section, sections except for relocation are not supported");break}}var g=new r;return g.sectionDataHeader=i?K(i.info):null,i&&g.parse(i,e),g},r.prototype.replaceResourceEntry=function(t){for(var e=this.entries.length,n=0;n<e;++n){var i=this.entries[n];if(i.type===t.type&&i.id===t.id&&i.lang===t.lang){this.entries[n]=t;return}}this.entries.push(t)},r.prototype.getResourceEntriesAsString=function(t,e){return this.entries.filter(function(n){return n.type===t&&n.id===e}).map(function(n){return[n.lang,Qt(n.bin)]})},r.prototype.replaceResourceEntryFromString=function(t,e,n,i){var s={type:t,id:e,lang:n,codepage:1200,bin:Jt(i)};this.replaceResourceEntry(s)},r.prototype.removeResourceEntry=function(t,e,n){this.entries=this.entries.filter(function(i){return!(i.type===t&&i.id===e&&(typeof n>"u"||i.lang===n))})},r.prototype.generateResourceData=function(t,e,n,i){n===void 0&&(n=!1),i===void 0&&(i=!1);var s={s:[],n:[]},o=[],u=Un(s,o,this.entries);o=_n(o);var a=u;u+=o.reduce(function(h,p){return h+2+ue(p)*2},0),u=O(u,8);var g=u;u=this.entries.reduce(function(h,p){return p.offset=h,h+16},g);var m=u;u=this.entries.reduce(function(h,p){return O(h,8)+p.bin.byteLength},m);var d=O(u,e),w=O(this.originalSize,e);if(n&&d>w)throw new Error("New resource data is larger than original");i||d<w&&(d=w);var _=new ArrayBuffer(d),v=new DataView(_),U=g,b=t+m;this.entries.forEach(function(h){var p=h.bin.byteLength;typeof h.rva<"u"?v.setUint32(U,h.rva,!0):(b=O(b,8),v.setUint32(U,b,!0),b+=p),v.setUint32(U+4,p,!0),v.setUint32(U+8,h.codepage,!0),v.setUint32(U+12,0,!0),U+=16}),U=m,this.entries.forEach(function(h){var p=h.bin.byteLength;Z(_,U,h.bin,0,p),U+=O(p,8)});var y=[];if(U=a,o.forEach(function(h){y.push({offset:U,text:h}),U=An(v,U,h)}),xn(v,0,y,s),d>u)for(var c="PADDINGX",l=u,f=0;l<d;++l,++f)f===8&&(f=0),v.setUint8(l,c.charCodeAt(f));return{bin:_,rawSize:u,dataOffset:m,descEntryOffset:g,descEntryCount:this.entries.length}},r.prototype.outputResource=function(t,e,n){e===void 0&&(e=!1),n===void 0&&(n=!1);var i=t.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,e,n);s.data=o.bin,s.info.sizeOfRawData=o.bin.byteLength,s.info.virtualSize=o.rawSize,t.setSectionByEntry(M.Resource,s);for(var u=t.getSectionByEntry(M.Resource),a=new DataView(u.data),g=o.descEntryOffset,m=u.info.virtualAddress+o.dataOffset,d=0;d<o.descEntryCount;++d){var w=a.getUint32(g+4,!0);m=O(m,8),a.setUint32(g,m,!0),m+=w,g+=16}},r})();var he=Ee(ce(),1),Sn=typeof crypto<"u",En=typeof globalThis.process<"u"&&globalThis.process.versions&&globalThis.process.versions.node;function Cn(){if(Sn)return crypto;if(En)return globalThis.crypto;throw new Error("Crypto API not available in this environment")}function lt(r){let t=new Uint32Array(256);for(let i=0;i<r.length;i++)t[r[i]]++;let e=0,n=r.length;if(n===0)return 0;for(let i=0;i<256;i++){if(t[i]===0)continue;let s=t[i]/n;e-=s*Math.log2(s)}return e}function In(r){return Array.from(r).map(t=>t.toString(16).padStart(2,"0")).join("")}async function $(r,t){let n=await Cn().subtle.digest(r,t);return In(new Uint8Array(n))}function B(r){let t=new he.default.ArrayBuffer;return t.append(r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength)),t.end()}function D(r,t,e){return r.getUint16(t,e)}function S(r,t,e){return r.getUint32(t,e)}function N(r,t,e){let n=r.getUint32(t+(e?0:4),e);return r.getUint32(t+(e?4:0),e)*2**32+n}function k(r,t,e=1024){let n=Math.min(r.length,t+e),i="";for(let s=t;s<n&&r[s]!==0;s++)i+=String.fromCharCode(r[s]);return i}function pe(r,t){let e=r.length,n=t.length;for(let i=0;i<=e-n;i++){let s=!0;for(let o=0;o<n;o++)if(r[i+o]!==t[o]){s=!1;break}if(s)return i}return-1}async function zn(r,t){let e=[],n=r.getAllSections?.()||r.sections||[];for(let i of n){let s=i.info||i,o=i.data?new Uint8Array(i.data):i.data??new Uint8Array,u=B(o),a=await $("SHA-1",o),g=await $("SHA-256",o),m={md5:u,sha1:a,sha256:g};e.push({name:(s.name||i.name||"")?.replace(/\0.*$/,""),raw_data:o,entropy:lt(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,...m})}return e}function Tn(r){return(r.imports||[]).map(t=>({dll:t.name||"",functions:(t.functions||[]).map(e=>({name:e.name||null,ordinal:e.ordinal||null}))}))}function Rn(r){return(r.exports||[]).map(t=>t.name||t).filter(Boolean)}function $n(r){let t=[];for(let n of r){let i=(n.dll||"").toLowerCase();if(Array.isArray(n.functions))for(let s of n.functions){let o=(s.name||`ordinal${s.ordinal||""}`).toLowerCase();t.push(`${i}.${o}`)}}let e=new TextEncoder;return B(e.encode(t.join(",")))}function Dn(r){let t=r.optionalHeader?.dataDirectory?.[ft.ImageDirectoryEntry.Security];return!t||!t.virtualAddress||!t.size?{has_signature:!1}:{has_signature:!0,certificate_table:{offset:t.virtualAddress,size:t.size}}}function Nn(r){let t=new Uint8Array([82,105,99,104]),e=pe(r,t);return e!==-1?{offset:e}:null}function Pn(r){let t=r.newHeader?.optionalHeader||r.optionalHeader;return t?{size_of_code:t.sizeOfCode??0,size_of_initialized_data:t.sizeOfInitializedData??0,size_of_uninitialized_data:t.sizeOfUninitializedData??0,address_of_entry_point:t.addressOfEntryPoint??0,base_of_code:t.baseOfCode??0,base_of_data:t.baseOfData??0,image_base:t.imageBase??0,section_alignment:t.sectionAlignment??0,file_alignment:t.fileAlignment??0,subsystem:t.subsystem??0,dll_characteristics:t.dllCharacteristics??0,size_of_stack_reserve:t.sizeOfStackReserve??0,size_of_stack_commit:t.sizeOfStackCommit??0,size_of_heap_reserve:t.sizeOfHeapReserve??0,size_of_heap_commit:t.sizeOfHeapCommit??0}:{}}async function Ut(r){r instanceof ArrayBuffer&&(r=new Uint8Array(r));let t;try{t=vt.from(r)}catch(v){return{error:"Failed to parse PE",message:v.message}}let e=await zn(t,r),n=Tn(t),i=Rn(t),s=$n(n),o=Dn(t),u=Nn(r),a=Pn(t),g=t.newHeader?.optionalHeader||t.optionalHeader,m=t.newHeader?.fileHeader||t.coffHeader,d=g?.addressOfEntryPoint??0,w=d;if(d>0&&e.length>0)for(let v of e){let U=v.virtual_address,b=U+v.virtual_size;if(d>=U&&d<b){w=d-v.virtual_address+v.raw_data_offset;break}}let _={machine:m?.machine??0,entry_point:w,image_base:g?.imageBase??0,number_of_sections:e.length,sections:e,imports:n,exports:i,imphash:s,digital_signature:o,rich_signature:u,...a,file_size:r.length};return _.is_dll=()=>((m?.characteristics??0)&8192)!==0,_.is_32bit=()=>(g?.magic??0)===267,_.is_64bit=()=>(g?.magic??0)===523,_}function At(r){return!r||r.error?null:{machine:r.machine,entry_point:r.entry_point,image_base:r.image_base,number_of_sections:r.number_of_sections,sections:r.sections,imports:r.imports,exports:r.exports,imphash:r.imphash,rich_signature:r.rich_signature,digital_signature:r.digital_signature,size_of_code:r.size_of_code,size_of_initialized_data:r.size_of_initialized_data,size_of_uninitialized_data:r.size_of_uninitialized_data,address_of_entry_point:r.address_of_entry_point,base_of_code:r.base_of_code,base_of_data:r.base_of_data,section_alignment:r.section_alignment,file_alignment:r.file_alignment,subsystem:r.subsystem,dll_characteristics:r.dll_characteristics,is_dll:r.is_dll,is_32bit:r.is_32bit,is_64bit:r.is_64bit,imports_dll:t=>{let e=t.toLowerCase();return r.imports.some(n=>n.dll.toLowerCase()===e)},importsFunction:(t,e)=>{let n=t.toLowerCase(),i=r.imports.find(o=>o.dll.toLowerCase()===n);if(!i)return!1;if(!e)return!0;let s=e.toLowerCase();return i.functions.some(o=>o.name&&o.name.toLowerCase()===s)},exports_function:t=>{let e=t.toLowerCase();return r.exports.some(n=>n.toLowerCase()===e)},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 jn=[127,69,76,70],Mn=1,Fn=14,Hn=15,Ln=29;function Bn(r){let t=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let s=0;s<4;s++)if(r[s]!==jn[s])throw new Error("Not ELF");let e=r[4],n=r[5]===1,i={is64bit:e===2,littleEndian:n};return i.type=D(t,16,n),i.machine=D(t,18,n),i.entry_point=i.is64bit?N(t,24,n):S(t,24,n),i.phoff=i.is64bit?N(t,32,n):S(t,28,n),i.shoff=i.is64bit?N(t,40,n):S(t,32,n),i.phentsize=i.is64bit?D(t,54,n):D(t,42,n),i.phnum=i.is64bit?D(t,56,n):D(t,44,n),i.shentsize=i.is64bit?D(t,58,n):D(t,46,n),i.shnum=i.is64bit?D(t,60,n):D(t,48,n),i.shstrndx=i.is64bit?D(t,62,n):D(t,50,n),i}function Wn(r,t){let e=[],n=new DataView(r.buffer,r.byteOffset,r.byteLength),i=t.phoff;for(let s=0;s<t.phnum;s++){let o,u,a,g,m,d,w;t.is64bit?(o=S(n,i,t.littleEndian),d=S(n,i+4,t.littleEndian),u=N(n,i+8,t.littleEndian),a=N(n,i+16,t.littleEndian),g=N(n,i+32,t.littleEndian),m=N(n,i+40,t.littleEndian),w=N(n,i+48,t.littleEndian),i+=56):(o=S(n,i,t.littleEndian),u=S(n,i+4,t.littleEndian),a=S(n,i+8,t.littleEndian),g=S(n,i+16,t.littleEndian),m=S(n,i+20,t.littleEndian),d=S(n,i+24,t.littleEndian),w=S(n,i+28,t.littleEndian),i+=32),e.push({type:o,offset:u,vaddr:a,filesz:g,memsz:m,flags:d,align:w})}return e}async function Vn(r,t){let e=[],n=new DataView(r.buffer,r.byteOffset,r.byteLength),i=t.shoff;for(let s=0;s<t.shnum;s++){let o=t.is64bit?N(n,i+24,t.littleEndian):S(n,i+16,t.littleEndian),u=t.is64bit?N(n,i+32,t.littleEndian):S(n,i+20,t.littleEndian),a=o+u<=r.length?r.slice(o,o+u):new Uint8Array,g=B(a),m=await $("SHA-1",a),d=await $("SHA-256",a);e.push({offset:o,size:u,entropy:lt(a),raw_data:a,md5:g,sha1:m,sha256:d}),i+=t.is64bit?64:40}return e}function qn(r,t,e){let n=t.find(_=>_.raw_data&&_.raw_data.length>0&&_.name===".dynamic"),i=t.find(_=>_.raw_data&&_.raw_data.length>0&&_.name===".dynstr");if(!n||!i)return{needed_libraries:[],soname:null,rpath:null,runpath:null};let s=n.raw_data,o=i.raw_data,u=new DataView(s.buffer,s.byteOffset,s.byteLength),a=e.is64bit?16:8,g=[],m=null,d=null,w=null;for(let _=0;_+a<=s.length;_+=a){let v=e.is64bit?N(u,_,e.littleEndian):S(u,_,e.littleEndian),U=e.is64bit?N(u,_+8,e.littleEndian):S(u,_+4,e.littleEndian);v===Mn?g.push(k(o,U)):v===Fn?m=k(o,U):v===Hn?d=k(o,U):v===Ln&&(w=k(o,U))}return{needed_libraries:g,soname:m,rpath:d,runpath:w}}function kn(r,t,e){let n=[],i=t.find(m=>m.name===".dynsym"),s=t.find(m=>m.name===".dynstr");if(!i||!s)return n;let o=i.raw_data,u=s.raw_data,a=new DataView(o.buffer,o.byteOffset,o.byteLength),g=e.is64bit?24:16;for(let m=0;m+g<=o.length;m+=g){let d=S(a,m,e.littleEndian);if(d>=u.length)continue;let w=k(u,d);w&&n.push(w)}return n}async function xt(r){r instanceof ArrayBuffer&&(r=new Uint8Array(r));let t=r.length,e;try{e=Bn(r)}catch(w){return{error:"Invalid ELF file",message:w.message}}let n=Wn(r,e),i=await Vn(r,e),{needed_libraries:s,soname:o,rpath:u,runpath:a}=qn(r,i,e),g=kn(r,i,e),m=(n?.map(w=>w.vaddr)||[0])[0],d=(n?.map(w=>w.offset)||[0])[0];return{type:e.type,machine:e.machine,entry_point:e.entry_point-m+d,is_64bit:e.is64bit,endianness:e.littleEndian?"little":"big",file_size:t,program_headers:n,sections:i,imports:s.map(w=>({dll:w,functions:[]})),exports:g,needed_libraries:s,soname:o,rpath:u,runpath:a,hashes:{}}}function Ot(r){return!r||r.error?null:{type:r.type||0,machine:r.machine||0,entry_point:r.entry_point||0,file_size:r.file_size||0,is_64bit:r.is_64bit||!1,endianness:r.endianness||"little",sections:r.sections||[],number_of_sections:(r.sections||[]).length,program_headers:r.program_headers||[],segments:r.program_headers||[],number_of_segments:(r.program_headers||[]).length,imports:r.needed_libraries||[],exports:r.exports||[],needed_libraries:r.needed_libraries||[],soname:r.soname||null,rpath:r.rpath||null,runpath:r.runpath||null,is_32bit(){return!this.is_64bit},is_little_endian(){return this.endianness==="little"},is_big_endian(){return this.endianness==="big"},imports_library(e){return this.needed_libraries.some(n=>n.toLowerCase().includes(e.toLowerCase()))},exports_function(e){return this.exports.some(n=>n===e)},get_section_by_name(e){return this.sections.find(n=>n.name===e)},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 G(r){return new TextEncoder().encode(r)}function St(r){if(r.length===0)return 0;let t=new Uint32Array(256);for(let i=0;i<r.length;i++)t[r[i]]++;let e=0,n=r.length;for(let i=0;i<256;i++)if(t[i]>0){let s=t[i]/n;e-=s*Math.log2(s)}return e}function Et(r){if(r.length===0)return 0;let t=0;for(let e=0;e<r.length;e++)t+=r[e];return t/r.length}function ge(r,t){if(r.length===0)return 0;let e=0;for(let n=0;n<r.length;n++){let i=r[n]-t;e+=i*i}return Math.sqrt(e/r.length)}function de(r){if(r.length<2)return 0;let t=0,e=0;for(let n=0;n<r.length-1;n+=2){let i=r[n]/255*2-1,s=r[n+1]/255*2-1;i*i+s*s<=1&&t++,e++}return e===0?0:4*t/e}function me(r){if(r.length<2)return 0;let t=Et(r),e=0,n=0;for(let i=0;i<r.length-1;i++)e+=(r[i]-t)*(r[i+1]-t);for(let i=0;i<r.length;i++){let s=r[i]-t;n+=s*s}return n===0?0:e/n}function Gn(...r){if(r.length===0)throw new Error("No data provided");return Math.min(...r)}function Yn(...r){if(r.length===0)throw new Error("No data provided");return Math.max(...r)}function Kn(r,t){let e=0;for(let n=0;n<t.length;n++)t[n]===r&&e++;return e}function Xn(r){if(r.length===0)return 0;let t=new Uint32Array(256);for(let i=0;i<r.length;i++)t[r[i]]++;let e=0,n=0;for(let i=0;i<256;i++)t[i]>e&&(e=t[i],n=i);return n}function Ct(r){if(!r||!(r instanceof Uint8Array))throw new Error("Math module requires a Uint8Array data buffer");return{entropy:function(...t){if(t.length===1&&typeof t[0]=="string"){let e=G(t[0]);return St(e)}else if(t.length===2){let e=t[0],n=t[1];if(e<0||n<0)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);if(e>=r.length||e+n>r.length)return 0;let i=r.slice(e,e+n);return i.length===0?0:St(i)}else throw new Error("entropy() requires either (offset, size) or (string)")},monte_carlo_pi:function(...t){if(t.length===1&&typeof t[0]=="string"){let e=G(t[0]);return de(e)}else if(t.length===2){let[e,n]=t;if(e<0||n<0)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);if(e>=r.length||e+n>r.length)return 0;let i=r.slice(e,e+n);return i.length===0?0:de(i)}else throw new Error("monte_carlo_pi() requires (offset, size)")},serial_correlation:function(...t){if(t.length===1&&typeof t[0]=="string"){let e=G(t[0]);return me(e)}else if(t.length===2){let[e,n]=t;if(e<0||n<0)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);if(e>=r.length||e+n>r.length)return 0;let i=r.slice(e,e+n);return i.length===0?0:me(i)}else throw new Error("serial_correlation() requires (offset, size)")},mean:function(...t){if(t.length===1&&typeof t[0]=="string"){let e=G(t[0]);return Et(e)}else if(t.length===2){let[e,n]=t;if(e<0||n<0)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);if(e>=r.length||e+n>r.length)return 0;let i=r.slice(e,e+n);return i.length===0?0:Et(i)}else throw new Error("mean() requires (offset, size)")},deviation:function(...t){if(t.length===2&&typeof t[0]=="string"){let[e,n]=t,i=G(e);return ge(i,n)}else if(t.length===3){let[e,n,i]=t;if(e<0||n<0)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);if(e>=r.length||e+n>r.length)return 0;let s=r.slice(e,e+n);return s.length===0?0:ge(s,i)}else throw new Error("deviation() requires (offset, size, mean)")},min:function(t,e){return Gn(t,e)},max:function(t,e){return Yn(t,e)},count:function(t,e,n){if(t<0||t>255)throw new Error(`Invalid byte value: ${t} (must be 0-255)`);if(e<0||n<0)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);let i=r.slice(e,e+n);return i.length===0?0:Kn(t,i)},percentage:function(t,e,n){return this.count(t,e,n)/n},mode:function(t,e){if(t<0||e<0)throw new Error(`Invalid range: offset=${t}, size=${e}, data.length=${r.length}`);let n=r.slice(t,t+e);return n.length===0?0:Xn(n)},abs:function(t){return Math.abs(t)},to_number:function(t){return t?1:0},in_range:function(t,e,n){return t>=e&&t<=n}}}var Zn={entropy:function(r){let t=G(r);return St(t)},abs:function(r){return Math.abs(r)},to_number:function(r){return r?1:0},in_range:function(r,t,e){return r>=t&&r<=e}};function H(r){return new TextEncoder().encode(r)}function It(r){let t=0;for(let e=0;e<r.length;e++)t=t+r[e]>>>0;return t&4294967295}var Qn=(()=>{let r=new Uint32Array(256);for(let t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;r[t]=e}return r})();function zt(r){let t=4294967295;for(let e=0;e<r.length;e++)t=t>>>8^Qn[(t^r[e])&255];return t=(t^4294967295)>>>0,t}function Tt(r){if(!r||!(r instanceof Uint8Array))throw new Error("Hash module requires a Uint8Array data buffer");return{md5:async function(...t){if(t.length===1&&typeof t[0]=="string"){let e=H(t[0]);return B(e)}else if(t.length===2){let e=t[0],n=t[1];if(e<0||n<0)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);let i=r.slice(e,e+n);return B(i)}else throw new Error("md5() requires either (offset, size) or (string)")},sha1:async function(...t){if(t.length===1&&typeof t[0]=="string"){let e=H(t[0]);return await $("SHA-1",e)}else if(t.length===2){let e=t[0],n=t[1];if(e<0||n<0||e+n>r.length)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);let i=r.slice(e,e+n);return await $("SHA-1",i)}else throw new Error("sha1() requires either (offset, size) or (string)")},sha256:async function(...t){if(t.length===1&&typeof t[0]=="string"){let e=H(t[0]);return await $("SHA-256",e)}else if(t.length===2){let e=t[0],n=t[1];if(e<0||n<0||e+n>r.length)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);let i=r.slice(e,e+n);return await $("SHA-256",i)}else throw new Error("sha256() requires either (offset, size) or (string)")},checksum32:function(...t){if(t.length===1&&typeof t[0]=="string"){let e=H(t[0]);return It(e)}else if(t.length===2){let e=t[0],n=t[1];if(e<0||n<0)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);let i=r.slice(e,e+n);return i.length===0?0:It(i)}else throw new Error("checksum32() requires either (offset, size) or (string)")},crc32:function(...t){if(t.length===1&&typeof t[0]=="string"){let e=H(t[0]);return zt(e)}else if(t.length===2){let e=t[0],n=t[1];if(e<0||n<0)throw new Error(`Invalid range: offset=${e}, size=${n}, data.length=${r.length}`);let i=r.slice(e,e+n);return i.length===0?0:zt(i)}else throw new Error("crc32() requires either (offset, size) or (string)")}}}var Jn={md5:async function(r){let t=H(r);return B(t)},sha1:async function(r){let t=H(r);return await $("SHA-1",t)},sha256:async function(r){let t=H(r);return await $("SHA-256",t)},checksum32:function(r){let t=H(r);return It(t)},crc32:function(r){let t=H(r);return zt(t)}};var Rt={now:()=>Date.now()};var $t={to_int:(r,t=10)=>{if(typeof r!="string"&&!(r instanceof String))throw new Error("to_int() first argument must be a string");r.startsWith("0x")||r.startsWith("0X")?(t=16,r=r.slice(2)):(r.startsWith("O")||r.startsWith("o"))&&(t=8,r=r.slice(1));let e=parseInt(r,t);if(isNaN(e))throw new Error(`to_int() could not convert string '${r}' to integer`);return e},length:r=>typeof r=="string"||r instanceof String?r.length:0};var ye=typeof console<"u"&&typeof console.log=="function"?(...r)=>console.log(...r):()=>{},tr=typeof globalThis<"u"&&globalThis.performance&&typeof globalThis.performance.now=="function";function er(){return tr?globalThis.performance.now():Date.now()}function nr(r){return r==null?r:JSON.parse(JSON.stringify(r))}var Dt=class{constructor(t={}){let e=t.enabled??t.enableTiming??!1,n=t.logger??ye,i=t.autoPrint??!1;this.options={enabled:!!e,logger:n,autoPrint:!!i},this.lastTiming={compile:null,scan:null}}isEnabled(){return!!this.options.enabled}now(){return er()}updateOptions(t={}){(Object.prototype.hasOwnProperty.call(t,"enabled")||Object.prototype.hasOwnProperty.call(t,"enableTiming"))&&(this.options.enabled=!!(t.enabled??t.enableTiming)),Object.prototype.hasOwnProperty.call(t,"logger")&&(this.options.logger=t.logger??ye),Object.prototype.hasOwnProperty.call(t,"autoPrint")&&(this.options.autoPrint=!!t.autoPrint)}enable(t=!0,e){this.updateOptions({enabled:t,logger:e})}clearCompile(){this.lastTiming.compile=null}clearScan(){this.lastTiming.scan=null}recordCompile(t){let e={total:t};this.lastTiming.compile=e,this.printTiming("compile",e)}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(t){this.lastTiming.scan=t,this.printTiming("scan",t)}accumulateStep(t,e,n){!t||!Number.isFinite(n)||(t[e]=(t[e]||0)+n)}accumulateModule(t,e,n){!t||!Number.isFinite(n)||(t.total=(t.total||0)+n,t[e]=(t[e]||0)+n)}accumulateCondition(t,e,n){!t||!Number.isFinite(n)||(t.total=(t.total||0)+n,t.byRule||(t.byRule={}),t.byRule[e]=(t.byRule[e]||0)+n)}getSnapshot(){return nr(this.lastTiming)}printTiming(t,e){if(!this.options.enabled||!this.options.autoPrint||!this.options.logger||!e)return;let n=this.options.logger;if(t==="compile"){n(`[InterceptScanner] Compile completed in ${e.total.toFixed(3)}ms`);return}if(t==="scan"){let i=e.matchCount??"n/a";n(`[InterceptScanner] Scan completed in ${e.total.toFixed(3)}ms (matches: ${i})`),e.steps&&Object.entries(e.steps).forEach(([s,o])=>{o!=null&&n(` \u2022 ${s}: ${o.toFixed(3)}ms`)}),e.modules&&e.modules.total&&n(` \u2022 moduleCreation.total: ${e.modules.total.toFixed(3)}ms`),e.conditionParsing&&e.conditionParsing.total&&n(` \u2022 conditionParsing.total: ${e.conditionParsing.total.toFixed(3)}ms`)}}};function we(r={}){return new Dt(r)}var Nt=class{constructor(t){if(this._isLoaded=!1,this._name=t,!Pt(t))throw new Error(`Invalid module name: "${t}". It is either reserved or malformed.`)}getName(){return this._name}isLoaded(){return this._isLoaded}async load(){return this._isLoaded=!0,this._isLoaded}async initialize(t,e){throw new Error("CustomModule.initialize() must be implemented")}createModule(t){throw new Error("CustomModule.createModule() must be implemented")}},rr=["pe","elf","math","hash","string","time","filesize","entrypoint"];function Pt(r){if(!r||typeof r!="string")return!1;let t=r.toLowerCase();return!rr.includes(t)}var ht=class{constructor(t={}){this.compiledRules=[],this.ac=null,this.autoParsePE=!0,this.autoParseELF=!0,this.maxFileSize=1024*1024,this.setModules(t.modules),this.customModules=t.modules||{};let e={enabled:t.timing?.enabled??t.timing?.enableTiming??t.enableTiming??!1,autoPrint:t.timing?.autoPrint??t.autoPrint??!1,logger:t.timing?.logger??t.timingLogger??t.logger};this.timingTracker=we(e)}compile(t){let e=this.timingTracker,n=e?.isEnabled(),i=n?e.now():0;this.compiledRules=qt(t,this.compiledRules||[]),this.ac=null,n?e.recordCompile(e.now()-i):e&&e.clearCompile()}addRules(t){this.compile(t)}clearRules(){this.compiledRules=[],this.ac=null}setModules(t){this.modules={string:$t,time:Rt,...t||{}}}setTiming(t={}){this.timingTracker.updateOptions(t)}enableTiming(t=!0,e){this.timingTracker.enable(t,e)}getTiming(){return this.timingTracker.getSnapshot()}deduplicateCandidates(t){let e=new Map;for(let n of t){let i=`${n.id}:${n.varName}:${n.offset}`;e.has(i)||e.set(i,n)}return Array.from(e.values())}verifyCandidates(t,e,n){let i=[];for(let s of t){let o=n.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=u.matcher(e,s.offset);a&&a.length>0&&i.push({...s,matches:a})}else i.push(s)}return i}buildStringMatches(t,e,n){let i={};for(let o of e){i[o.id]={};for(let u of Object.keys(o.strings)){let a=u.startsWith("$")||u.startsWith(".")?u:`$${u}`,g=a.startsWith(".")?`$${a}`:a,m=u.startsWith(".")?`$${u}`:a;i[o.id][m]={identifier:m,matched:!1,count:0,matches:[],offsets:[],private:o.strings[u].private}}}for(let o of t){let u=o.varName.startsWith(".")?`$${o.varName}`:o.varName,a=i[o.id][u]||u.startsWith("$")?u:`$${u}`,g=i[o.id][a];if(o.matches&&o.matches.length>0){let m=o.matches.length>100?o.matches.slice(0,100):o.matches;g.matched=!0,g.count+=m.length,g.matches.push(...m),g.offsets.push(...o.matches.map(d=>d.offset))}else g.matched=!0,g.count+=1,g.matches.push({offset:o.offset,length:o.length||0}),g.offsets.push(o.offset)}let s=null;for(let o of e)for(let[u,a]of Object.entries(o.strings)){if(a.type==="text"||a.type==="regex"&&a.literalPrefix?.length>0)continue;let g=u.startsWith(".")?`$${u}`:u,m=i[o.id][g]||g.startsWith("$")?g:`$${g}`,d=i[o.id][m];a.type==="hex"&&s===null&&(s=Array.from(n).map(_=>_.toString(16).toUpperCase().padStart(2,"0")).join(""));let w=a.type==="hex"&&s!==null?a.matcher(s,-1):a.matcher(n,-1);if(w&&w.length>0){let _=w.length>100?w.slice(0,100):w;d.matched=!0,d.count+=_.length,d.matches.length===0?d.matches=_:d.matches.push(..._),d.offsets.push(...w.map(v=>v.offset))}}return i}async evaluateConditions(t,e,n,i={},s=null){let o=[],u={},a=s?.tracker,g=s?.modules,m=this.modules.pe;if(this.autoParsePE&&!m){let y=a?a.now():0;try{if(n.length>2&&n[0]===77&&n[1]===90){let c=await Ut(n);c&&!c.error&&(m=At(c))}}catch{}finally{a&&g&&a.accumulateModule(g,"pe",a.now()-y)}}let d=this.modules.elf;if(this.autoParseELF&&!d){let y=a?a.now():0;try{if(n.length>4&&n[0]===127&&n[1]===69&&n[2]===76&&n[3]===70){let c=await xt(n);c&&!c.error&&(d=Ot(c))}}catch{}finally{a&&g&&a.accumulateModule(g,"elf",a.now()-y)}}let w={...this.modules,...m&&{pe:m},...d&&{elf:d}},_=a?a.now():0;w.math=Ct(n),a&&g&&a.accumulateModule(g,"math",a.now()-_);let v=a?a.now():0;w.hash=Tt(n),a&&g&&a.accumulateModule(g,"hash",a.now()-v);for(let[y,c]of Object.entries(this.modules))try{if(typeof c?.getName=="function"){let l=c.getName();if(!Pt(l)){console.warn(`InterceptScanner: Custom module "${l}" has reserved name - skipping initialization`);continue}if(typeof c.isLoaded=="function"&&!c.isLoaded()){let x=a?a.now():0;typeof c.load=="function"&&await c.load(),a&&g&&a.accumulateModule(g,`${l}_load`,a.now()-x)}let f=a?a.now():0,h={...i,filesize:n.length,hasPE:!!m,hasELF:!!d,timestamp:Date.now()},p=c;if(typeof c.initialize=="function"&&typeof c.createModule=="function"){let x=await c.initialize(n,h);p=c.createModule(x)}a&&g&&a.accumulateModule(g,l,a.now()-f),w[l]=p}}catch(l){console.warn(`InterceptScanner: Error initializing custom module "${y}": ${l.message}`)}let U=e.filter(y=>y.global);for(let y of U){let c=await this.evaluateRuleCondition(t,y,n,u,{peModule:m,elfModule:d,modulesWithBinary:w},s);if(c)y.private||o.push(c);else return o}let b=e.filter(y=>!y.global);for(let y of b){let c=await this.evaluateRuleCondition(t,y,n,u,{peModule:m,elfModule:d,modulesWithBinary:w},s);c&&!y.private&&o.push(c)}for(let[y,c]of Object.entries(w))if(!["string","time","hash","math"].includes(y)){o[y]={};for(let[l,f]of Object.entries(c))!l.startsWith("_")&&typeof f!="function"&&!/[A-Z0-9]+/.test(l)&&(o[y][l]=typeof f=="object"?jt({...f},["raw_data","data"]):f)}return o}async evaluateRuleCondition(t,e,n,i,s={},o=null){let{peModule:u,elfModule:a,modulesWithBinary:g}=s,m=o?.tracker,d=o?.condition;try{let w=u?u.entry_point:a?a.entry_point:-1e6,_=n.length,v=_>=this.maxFileSize,U=kt(n,t[e.id],g,{entrypoint:w,filesize:_,isFileSizeCapped:v,maxFileSize:this.maxFileSize,matchedRules:i,metadata:{ruleName:e.name}}),b,y=m?m.now():0;try{b=Kt(e.condition,U.strings)}catch{b=this.parseSimpleCondition(e.condition,U.strings)}finally{m&&d&&m.accumulateCondition(d,e.name,m.now()-y)}let c=await Gt(b,U);if(i[e.name]=c,c){let l={};for(let[f,h]of Object.entries(t[e.id]))!f.startsWith("$.")&&!h.private&&(l[f]=h);return{rule:e.name,namespace:e.namespace||"default",tags:e.tags||[],metadata:e.metadata||{},strings:l}}}catch(w){console.debug("Failing rule: ",e),console.trace(w)}return!1}parseSimpleCondition(t,e){if(t=t.trim(),t==="any of them")return{type:"any",items:"them"};if(t==="all of them")return{type:"all",items:"them"};if(t==="none of them")return{type:"none",items:"them"};let n=t.match(/^(\d+)\s+of\s+them$/);if(n)return{type:"quantified",quantifier:{type:"number",value:parseInt(n[1])},items:"them"};let i=t.match(/^\$(\w+)$/);if(i)return{type:"stringIdentifier",identifier:`$${i[1]}`};let s=t.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=t.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(t){Array.isArray(t)&&t.forEach(e=>{if(Object.keys(e.strings).length>0)for(let[n,i]of Object.entries(e.strings))i.matched||delete e.strings[n]})}async scan(t,e={}){let n=this.timingTracker,i=n?.isEnabled(),s=i?n.now():0,o=i?n.createScanTiming():null;if(typeof t=="string"&&(t=new TextEncoder().encode(t)),!this.compiledRules||this.compiledRules.length===0)return i&&o?(o.total=n.now()-s,o.matchCount=0,n.finalizeScan(o)):n&&n.clearScan(),[];if(!this.ac)if(i&&o){let l=n.now();this.ac=new Y(this.compiledRules),n.accumulateStep(o.steps,"buildAutomaton",n.now()-l)}else this.ac=new Y(this.compiledRules);let u=i?n.now():0,a=this.ac.search(t);i&&o&&n.accumulateStep(o.steps,"acSearch",n.now()-u);let g=i?n.now():0,m=this.deduplicateCandidates(a);i&&o&&n.accumulateStep(o.steps,"deduplicate",n.now()-g);let d=i?n.now():0,w=this.verifyCandidates(m,t,this.compiledRules);i&&o&&n.accumulateStep(o.steps,"verifyCandidates",n.now()-d);let _=i?n.now():0,v=this.buildStringMatches(w,this.compiledRules,t);i&&o&&n.accumulateStep(o.steps,"buildMatches",n.now()-_);let U=null,b=0;i&&o&&(U={tracker:n,modules:o.modules,condition:o.conditionParsing},b=n.now());let y=await this.evaluateConditions(v,this.compiledRules,t,e,U);i&&o&&n.accumulateStep(o.steps,"evaluateConditions",n.now()-b);let c=i?n.now():0;return this.filterStringResults(y),i&&o?(n.accumulateStep(o.steps,"filterStrings",n.now()-c),o.total=n.now()-s,o.matchCount=y.length,n.finalizeScan(o)):n&&n.clearScan(),y}setMaxFileSize(t){this.maxFileSize=t}getStats(){return{totalRules:this.compiledRules.length,ruleNames:this.compiledRules.map(t=>t.name),rulesWithStrings:this.compiledRules.filter(t=>Object.keys(t.strings).length>0).length,totalStrings:this.compiledRules.reduce((t,e)=>t+Object.keys(e.strings).length,0),totalPatterns:this.compiledRules.reduce((t,e)=>t+Object.values(e.strings).reduce((n,i)=>n+(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 jt(r,t){return typeof r=="string"||typeof r=="number"||typeof r=="boolean"||r===null?r:Array.isArray(r)?r.map(e=>jt(e,t)):r!==null&&typeof r=="object"?Object.fromEntries(Object.entries(r).filter(([e])=>!t.includes(e)).map(([e,n])=>[e,jt(n,t)])):r}export{Nt as BaseCustomModule,ht as InterceptScanner,ht as YaraScanner,Ot as createELFModule,Tt as createHashModule,Ct as createMathModule,At as createPEModule,Jn as hash,Zn as math,xt as parseELFYaraFull,Ut as parsePEYara,$t as string,Rt as time};
|
|
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,(u,a)=>String.fromCharCode(parseInt(a,16))).replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\'/g,"'"),s=e.nocase?[i.toLowerCase()]:[i];for(let u of s)e.base64||e.base64wide?(e.base64&&(e.ascii&&r.push(...oe(u,!1).map(a=>({bytes:a,isWide:!1}))),e.wide&&r.push(...oe(ae(u),!1).map(a=>({bytes:a,isWide:!0})))),e.base64wide&&(e.ascii&&r.push(...oe(u,!0).map(a=>({bytes:a,isWide:!0}))),e.wide&&r.push(...oe(ae(u),!0).map(a=>({bytes:a,isWide:!0}))))):(e.ascii&&r.push({bytes:t.encode(u),isWide:!1}),e.wide&&r.push({bytes:ae(u),isWide:!0}));return{matcher:Le((u,a=-1,p=-1)=>{let d=[],m=a>=0,b=p>=0?p:-1;a=a<0?0:a;for(let{bytes:_,isWide:U}of r)if(e.xor){let v=Pt(u,_,e.xor,e.allowKey0,m,b);d.push(...v.map(w=>({...w,length:_.length,isWide:U})))}else{let v=jt(u,_,e.nocase,m,b);d.push(...v.map(w=>({...w,length:_.length,isWide:U})))}return e.fullword&&(d=d.filter(_=>Ft(u,_.offset,_.length))),d.forEach(_=>{_.offset+=a}),d}),patterns:r,type:"text",xor:e.xor,nocase:e.nocase,private:e.private}}function Pt(n,e,t,r=!0,i=!1,s=-1){let[o,u]=t,a=[],p=e.length,d=n.length,m=s>=0?s:0;if(p===0||p>d)return a;for(let b=o;b<=u;b++)for(let _=m;_<=d-p;_++){let U=!0;for(let v=0;v<p;v++)if((n[_+v]^b)!==e[v]){U=!1;break}if(U&&((s<0||_===s)&&a.push({offset:_,key:b}),i))break}return a}function jt(n,e,t=!1,r=!1,i=-1){let s=[],o=e.length,u=n.length,a=i>=0?i:0;e:for(let p=a;p<=u-o;p++){for(let d=0;d<o;d++)if((t?Mt(n[p+d]):n[p+d])!==e[d])continue e;if((i<0||p===i)&&s.push({offset:p}),r)break}return s}function Mt(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 ae(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 Ht(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 Lt=1e4;function Bt(n,e){let t="";n=n?.toUpperCase().replace(/[^0-9A-F?~|()[\-\]]/g,"")||"";let r=n.match(/\[\d*(-\d*)?\]|\(.*\)|~?[0-9A-F?]{2}/g)||[],i=/\bprivate\b/.test(e);if(r.length===0)return{matcher:a=>[],type:"hex",private:i};for(let u of r)if(u.startsWith("["))if(u.indexOf("-")===-1){let p=parseInt(u.slice(1,-1));t+=`(?:[0-9A-F]{2}){${p}}`}else{let p=/\[(\d*)-(\d*)\]/.exec(u),d=parseInt(p[1])||0,m=parseInt(p[2])||Lt;t+=`(?:[0-9A-F]{2}){${d},${m}}`}else u.startsWith("(")?t+=Fe(u).replace(/\?/g,"[0-9A-F]"):u.startsWith("~")?t+=Fe(u):t+=u.replace(/\?/g,"[0-9A-F]");let s=new RegExp(t,"g");return{matcher:u=>{let a=typeof u=="string"?u:Array.from(u).map(m=>m.toString(16).toUpperCase().padStart(2,"0")).join(""),p=[],d;for(s.lastIndex=0;(d=s.exec(a))!==null&&p.length<100;){if(d.index%2!==0){s.lastIndex=d.index+1;continue}p.push({offset:d.index/2,length:Math.ceil(d[0].length/2)}),s.lastIndex=d.index+2}return p},type:"hex",private:i}}function Fe(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 oe(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)),p=s[o],d=/=*$/.exec(a??[0])[0].length,m=a.slice(p,a.length-(d?d+1:0));i.push(e?ae(m):t.encode(m))}return i.filter(o=>o.length>=1)}var Be=["pe","elf","math","hash","time","string"];function Wt(n){let e=[],t=/^\s*import\s+"(\w+)"\s*$/gm,r;for(;(r=t.exec(n))!==null;){let i=r[1];if(!Be.includes(i))throw new Error(`Unsupported module import: "${i}". Supported modules are: ${Be.join(", ")}. Note: All supported modules are automatically available; the import statement is only for validation.`);e.push(i)}return e}function Vt(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]==="/"&&t+1<r&&n[t+1]==="/"){for(t+=2;t<r&&n[t]!==`
|
|
9
|
+
`;)t++;t<r&&n[t]===`
|
|
10
|
+
`&&(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
|
+
`&&(e+=`
|
|
12
|
+
`),t++}else e+=n[t++];return e}function We(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 qe(n,e=[]){Wt(n),n=n.replace(/^\s*import\s+"[^"]+"\s*$/gm,"");let t=e??[],r="",i=0,s=!1,o=n.split(`
|
|
13
|
+
`);for(let u of o)if(!s&&u.match(/^\s*(?:\s*(?:private|global)\s+)*rule\b/i)){s=!0,r=u+`
|
|
14
|
+
`;let a=We(u);i=a.openCount-a.closeCount;let p=a.openCount>0;i===0&&p&&(t.push(Ve(r)),s=!1,r="")}else if(s){r+=u+`
|
|
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
|
+
`)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 Jt=new Set(["i","s"]);function er(n,e){let t=[...new Set(e)].filter(r=>!Jt.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 tr(n,e){if(n[e+1]==="/"){let r=n.indexOf(`
|
|
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};
|