v86 0.5.44 → 0.5.64
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/build/libv86-debug.js +72 -46
- package/build/libv86-debug.mjs +105 -104
- package/build/libv86.js +13 -12
- package/build/libv86.mjs +99 -97
- package/build/v86-debug.wasm +0 -0
- package/build/v86-fallback.wasm +0 -0
- package/build/v86.wasm +0 -0
- package/package.json +1 -1
package/build/libv86.js
CHANGED
|
@@ -8,16 +8,16 @@ function ma(a){"number"===typeof a?this.view=new Uint8Array(a+7>>3):a instanceof
|
|
|
8
8
|
if("undefined"===typeof XMLHttpRequest||"undefined"!==typeof process&&process.versions&&process.versions.node){let a;pa=async function(b,c){a||(a=await import("node:fs/promises"));if(c.range){b=await a.open(b,"r");const d=Buffer.allocUnsafe(c.range.length);try{await b.read({buffer:d,position:c.range.start})}finally{await b.close()}c.done&&c.done(new Uint8Array(d))}else b=await a.readFile(b,{encoding:c.as_json?"utf-8":null}),b=c.as_json?JSON.parse(b):(new Uint8Array(b)).buffer,c.done(b)};qa=async function(b){a||
|
|
9
9
|
(a=await import("node:fs/promises"));return(await a.stat(b)).size}}else pa=async function(a,b,c){function d(){const l=c||0;setTimeout(()=>{pa(a,b,l+1)},1E3*([1,1,2,3,5,8,13,21][l]||34))}var e=new XMLHttpRequest;e.open(b.method||"get",a,!0);e.responseType=b.as_json?"json":"arraybuffer";if(b.headers)for(var f=Object.keys(b.headers),g=0;g<f.length;g++){var k=f[g];e.setRequestHeader(k,b.headers[k])}b.range&&(f=b.range.start,e.setRequestHeader("Range","bytes="+f+"-"+(f+b.range.length-1)),e.setRequestHeader("X-Accept-Encoding",
|
|
10
10
|
"identity"),e.onreadystatechange=function(){200===e.status&&(console.error("Server sent full file in response to ranged request, aborting",{filename:a}),e.abort())});e.onload=function(){if(4===e.readyState)if(200!==e.status&&206!==e.status)console.error("Loading the image "+a+" failed (status %d)",e.status),500<=e.status&&600>e.status&&d();else if(e.response){if(b.range){const l=e.getResponseHeader("Content-Encoding");l&&"identity"!==l&&console.error("Server sent Content-Encoding in response to ranged request",
|
|
11
|
-
{filename:a,enc:l})}b.done&&b.done(e.response,e)}};e.onerror=function(l){console.error("Loading the image "+a+" failed",l);d()};b.progress&&(e.onprogress=function(l){b.progress(l)});e.send(null)},qa=async function(a){return new Promise((b,c)=>{pa(a,{done:(d,e)=>{d=e.getResponseHeader("Content-Range")||"";(e=d.match(/\/(\d+)\s*$/))?b(+e[1]):c(Error("`Range: bytes=...` header not supported (Got `"+d+"`)"))},headers:{Range:"bytes=0-0","X-Accept-Encoding":"identity"}})})};function ra(){}function sa(){};function ta(a,b){function c(v){v=v.toString(16);return"#"+"0".repeat(6-v.length)+v}function d(v){var t=256*na,C=8*Q,I=Sa?Sa.canvas:null;I&&I.width===t&&I.height===C||(I?(I.width=t,I.height=C):(I=new OffscreenCanvas(t,C),Sa=I.getContext("2d")),Ab=Sa.createImageData(t,C));const O=Ab.data;let N=0,R;C=Bb?function(X){R=R||X;O[N+3]=X;O[N+7]=X;N+=8}:function(X){R=R||X;O[N+3]=X;N+=4};I=32-Q;const ka=t*(Q-1)*4;t=4*(na-t*Q);const ha=1020*na;for(let X=0,
|
|
12
|
-
ka);R=!1;for(let Ka=0;Ka<Q;++Ka,++
|
|
11
|
+
{filename:a,enc:l})}b.done&&b.done(e.response,e)}};e.onerror=function(l){console.error("Loading the image "+a+" failed",l);d()};b.progress&&(e.onprogress=function(l){b.progress(l)});e.send(null)},qa=async function(a){return new Promise((b,c)=>{pa(a,{done:(d,e)=>{d=e.getResponseHeader("Content-Range")||"";(e=d.match(/\/(\d+)\s*$/))?b(+e[1]):c(Error("`Range: bytes=...` header not supported (Got `"+d+"`)"))},headers:{Range:"bytes=0-0","X-Accept-Encoding":"identity"}})})};function ra(){}function sa(){};function ta(a,b){function c(v){v=v.toString(16);return"#"+"0".repeat(6-v.length)+v}function d(v){var t=256*na,C=8*Q,I=Sa?Sa.canvas:null;I&&I.width===t&&I.height===C||(I?(I.width=t,I.height=C):(I=new OffscreenCanvas(t,C),Sa=I.getContext("2d")),Ab=Sa.createImageData(t,C));const O=Ab.data;let N=0,R;C=Bb?function(X){R=R||X;O[N+3]=X;O[N+7]=X;N+=8}:function(X){R=R||X;O[N+3]=X;N+=4};I=32-Q;const ka=t*(Q-1)*4;t=4*(na-t*Q);const ha=1020*na;for(let X=0,Da=0;2048>X;++X,Da+=I,N+=t){const Ea=X%256;X&&!Ea&&(N+=
|
|
12
|
+
ka);R=!1;for(let Ka=0;Ka<Q;++Ka,++Da,N+=ha){const La=v[Da];for(let ua=128;0<ua;ua>>=1)C(La&ua?255:0);Cb&&C(Db&&192<=Ea&&223>=Ea&&La&1?255:0)}Ub[X]=R?1:0}Sa.putImageData(Ab,0,0)}function e(v,t,C,I){if(t&&C){v.style.width="";v.style.height="";I&&(v.style.transform="");var O=v.getBoundingClientRect();I?v.style.transform=(1===t?"":" scaleX("+t+")")+(1===C?"":" scaleY("+C+")"):(0===t%1&&0===C%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):
|
|
13
13
|
(g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),I=window.devicePixelRatio||1,0!==I%1&&(t/=I,C/=I));1!==t&&(v.style.width=O.width*t+"px");1!==C&&(v.style.height=O.height*C+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=1;this.FLAG_FONT_PAGE_B=2;var g=f.getElementsByTagName("canvas")[0],k=g.getContext("2d",{alpha:!1}),l=f.getElementsByTagName("div")[0],m=document.createElement("div"),n,p,q=void 0!==a.scale?
|
|
14
14
|
a.scale:1,r=void 0!==a.scale?a.scale:1,y=1,x,u,F,w,G,P,oa,Sa,Ab,Ub=new Int8Array(2048),Q,na,Cb,Bb,Db,Eb=0,Fb=0,mb,Vb=0,nb,Gb,ob,Hb=[],pb=Hb,qb=0,Ib=!1;this.init=function(){const v=new Uint16Array([32,9786,9787,9829,9830,9827,9824,8226,9688,9675,9689,9794,9792,9834,9835,9788,9658,9668,8597,8252,182,167,9644,8616,8593,8595,8594,8592,8735,8596,9650,9660]),t=new Uint16Array([8962,199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,162,163,165,8359,
|
|
15
15
|
402,225,237,243,250,241,209,170,186,191,8976,172,189,188,161,171,187,9617,9618,9619,9474,9508,9569,9570,9558,9557,9571,9553,9559,9565,9564,9563,9488,9492,9524,9516,9500,9472,9532,9566,9567,9562,9556,9577,9574,9568,9552,9580,9575,9576,9572,9573,9561,9560,9554,9555,9579,9578,9496,9484,9608,9604,9612,9616,9600,945,223,915,960,931,963,181,964,934,920,937,948,8734,966,949,8745,8801,177,8805,8804,8992,8993,247,8776,176,8729,183,8730,8319,178,9632,160]);for(var C=0,I;256>C;C++)I=126<C?t[C-127]:32>C?v[C]:
|
|
16
16
|
C,Hb.push(String.fromCharCode(I));m.classList.add("cursor");m.style.position="absolute";m.style.backgroundColor="#ccc";m.style.width="7px";m.style.display="inline-block";this.set_mode(!1);this.set_size_text(80,25);2===u&&this.set_size_graphical(720,400,720,400);this.set_scale(q,r);this.timer()};this.make_screenshot=function(){const v=new Image;if(1===u||2===u)v.src=g.toDataURL("image/png");else{const t=[9,16],C=document.createElement("canvas");C.width=w*t[0];C.height=G*t[1];const I=C.getContext("2d");
|
|
17
17
|
I.imageSmoothingEnabled=!1;I.font=window.getComputedStyle(l).font;I.textBaseline="top";for(let O=0;O<G;O++)for(let N=0;N<w;N++){const R=4*(O*w+N),ka=F[R+0],ha=F[R+3];I.fillStyle=c(F[R+2]);I.fillRect(N*t[0],O*t[1],t[0],t[1]);I.fillStyle=c(ha);I.fillText(pb[ka],N*t[0],O*t[1])}"none"!==m.style.display&&n<G&&p<w&&(I.fillStyle=m.style.backgroundColor,I.fillRect(p*t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));v.src=C.toDataURL("image/png")}return v};
|
|
18
18
|
this.put_char=function(v,t,C,I,O,N){t=4*(v*w+t);F[t+0]=C;F[t+1]=I;F[t+2]=O;F[t+3]=N;x[v]=1};this.timer=function(){qb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Ib||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());this.timer()};this.update_text=function(){for(var v=0;v<G;v++)x[v]&&(this.text_update_row(v),x[v]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(P){var v=performance.now();
|
|
19
|
-
if(266<v-Vb){mb=!mb;ob&&(x[n]=1);var t=4*w;for(let ka=0,ha=0;ka<G;++ka)if(x[ka])ha+=t;else for(var C=0;C<w;++C,ha+=4)if(F[ha+1]&1){x[ka]=1;ha+=t-4*C;break}Vb=v}v=Sa.canvas;t=oa.canvas;C=4*w;const O=w*na,N=Q;let R=0;for(let ka=0,ha=0,X=0;ka<G;++ka,ha+=Q){if(!x[ka]){X+=C;continue}++R;oa.clearRect(0,N,O,Q);let
|
|
20
|
-
ha,ua-La,Q)),Ka=Xb,La=ua);
|
|
19
|
+
if(266<v-Vb){mb=!mb;ob&&(x[n]=1);var t=4*w;for(let ka=0,ha=0;ka<G;++ka)if(x[ka])ha+=t;else for(var C=0;C<w;++C,ha+=4)if(F[ha+1]&1){x[ka]=1;ha+=t-4*C;break}Vb=v}v=Sa.canvas;t=oa.canvas;C=4*w;const O=w*na,N=Q;let R=0;for(let ka=0,ha=0,X=0;ka<G;++ka,ha+=Q){if(!x[ka]){X+=C;continue}++R;oa.clearRect(0,N,O,Q);let Da,Ea,Ka,La;for(let ua=0;ua<O;ua+=na,X+=4){const Wb=F[X+0];var I=F[X+1];const Xb=F[X+2],Yb=F[X+3],Zb=I&2?Fb:Eb;I=(!(I&1)||mb)&&Ub[(Zb<<8)+Wb];Ka!==Xb&&(void 0!==Ka&&(P.fillStyle=c(Ka),P.fillRect(La,
|
|
20
|
+
ha,ua-La,Q)),Ka=Xb,La=ua);Da!==Yb&&(void 0!==Da&&(oa.fillStyle=c(Da),oa.fillRect(Ea,0,ua-Ea,Q)),Da=Yb,Ea=ua);I&&oa.drawImage(v,Wb*na,Zb*Q,na,Q,ua,N,na,Q)}oa.fillStyle=c(Da);oa.fillRect(Ea,0,O-Ea,Q);oa.globalCompositeOperation="destination-in";oa.drawImage(t,0,N,O,Q,0,0,O,Q);oa.globalCompositeOperation="source-over";P.fillStyle=c(Ka);P.fillRect(La,ha,O-La,Q);P.drawImage(t,0,0,O,Q,0,ha,O,Q)}R&&(mb&&ob&&x[n]&&(P.fillStyle=c(F[4*(n*w+p)+3]),P.fillRect(p*na,n*Q+nb,na,Gb-nb+1)),x.fill(0));R&&k.drawImage(P.canvas,
|
|
21
21
|
0,0)}};this.destroy=function(){qb&&(cancelAnimationFrame(qb),qb=0)};this.pause=function(){Ib=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Ib=!1;m.classList.add("blinking-cursor")};this.set_mode=function(v){u=v?1:a.use_graphical_text?2:0;0===u?(l.style.display="block",g.style.display="none"):(l.style.display="none",g.style.display="block",2===u&&x&&x.fill(1))};this.set_font_bitmap=function(v,t,C,I,O,N){const R=C?16:t?9:8;if(Q!==v||na!==R||Cb!==t||Bb!==C||Db!==I||N)N=na!==R||Q!==
|
|
22
22
|
v,Q=v,na=R,Cb=t,Bb=C,Db=I,2===u&&(d(O),x.fill(1),N&&this.set_size_graphical_text())};this.set_font_page=function(v,t){if(Eb!==v||Fb!==t)Eb=v,Fb=t,x.fill(1)};this.clear_screen=function(){k.fillStyle="#000";k.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Sa){var v=na*w,t=Q*G,C=2*Q;P&&P.canvas.width===v&&P.canvas.height===t&&oa.canvas.height===C||(P?(P.canvas.width=v,P.canvas.height=t,oa.canvas.width=v,oa.canvas.height=C):(P=(new OffscreenCanvas(v,t)).getContext("2d",{alpha:!1}),
|
|
23
23
|
oa=(new OffscreenCanvas(v,C)).getContext("2d")),this.set_size_graphical(v,t,v,t),x.fill(1))}};this.set_size_text=function(v,t){if(v!==w||t!==G)if(x=new Int8Array(t),F=new Int32Array(v*t*4),w=v,G=t,0===u){for(;l.childNodes.length>t;)l.removeChild(l.firstChild);for(;l.childNodes.length<t;)l.appendChild(document.createElement("div"));for(v=0;v<t;v++)this.text_update_row(v);e(l,q,r,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(v,t){g.style.display="block";g.width=v;
|
|
@@ -65,8 +65,8 @@ B.prototype.port_write16=function(a,b){var c=this.ports[a];c.write16===this.empt
|
|
|
65
65
|
B.prototype.port_read8=function(a){var b=this.ports[a];b.read8===this.empty_port_read8&&(z(a,4),this.get_port_description(a));b=b.read8.call(b.device,a);z(a);return b};B.prototype.port_read16=function(a){var b=this.ports[a];b.read16===this.empty_port_read16&&(z(a,4),this.get_port_description(a));b=b.read16.call(b.device,a);z(a);return b};B.prototype.port_read32=function(a){var b=this.ports[a];b.read32===this.empty_port_read32&&(z(a,4),this.get_port_description(a));return b.read32.call(b.device,a)};
|
|
66
66
|
var Ba={4:"PORT_DMA_ADDR_2",5:"PORT_DMA_CNT_2",10:"PORT_DMA1_MASK_REG",11:"PORT_DMA1_MODE_REG",12:"PORT_DMA1_CLEAR_FF_REG",13:"PORT_DMA1_MASTER_CLEAR",32:"PORT_PIC1_CMD",33:"PORT_PIC1_DATA",64:"PORT_PIT_COUNTER0",65:"PORT_PIT_COUNTER1",66:"PORT_PIT_COUNTER2",67:"PORT_PIT_MODE",96:"PORT_PS2_DATA",97:"PORT_PS2_CTRLB",100:"PORT_PS2_STATUS",112:"PORT_CMOS_INDEX",113:"PORT_CMOS_DATA",128:"PORT_DIAG",129:"PORT_DMA_PAGE_2",146:"PORT_A20",160:"PORT_PIC2_CMD",161:"PORT_PIC2_DATA",178:"PORT_SMI_CMD",179:"PORT_SMI_STATUS",
|
|
67
67
|
212:"PORT_DMA2_MASK_REG",214:"PORT_DMA2_MODE_REG",218:"PORT_DMA2_MASTER_CLEAR",240:"PORT_MATH_CLEAR",368:"PORT_ATA2_CMD_BASE",496:"PORT_ATA1_CMD_BASE",632:"PORT_LPT2",744:"PORT_SERIAL4",760:"PORT_SERIAL2",884:"PORT_ATA2_CTRL_BASE",888:"PORT_LPT1",1E3:"PORT_SERIAL3",1008:"PORT_FD_BASE",1010:"PORT_FD_DOR",1012:"PORT_FD_STATUS",1013:"PORT_FD_DATA",1014:"PORT_HD_DATA",1015:"PORT_FD_DIR",1016:"PORT_SERIAL1",3320:"PORT_PCI_CMD",3321:"PORT_PCI_REBOOT",3324:"PORT_PCI_DATA",1026:"PORT_BIOS_DEBUG",1296:"PORT_QEMU_CFG_CTL",
|
|
68
|
-
1297:"PORT_QEMU_CFG_DATA",45056:"PORT_ACPI_PM_BASE",45312:"PORT_SMB_BASE",35072:"PORT_BIOS_APM"};B.prototype.get_port_description=function(a){return Ba[a]?" ("+Ba[a]+")":""};var
|
|
69
|
-
Fa.prototype.send_async=function(a,b){setTimeout(this.send.bind(this,a,b),0)};
|
|
68
|
+
1297:"PORT_QEMU_CFG_DATA",45056:"PORT_ACPI_PM_BASE",45312:"PORT_SMB_BASE",35072:"PORT_BIOS_APM"};B.prototype.get_port_description=function(a){return Ba[a]?" ("+Ba[a]+")":""};var Ca={};function Fa(){this.listeners={};this.pair=void 0}Fa.prototype.register=function(a,b,c){var d=this.listeners[a];void 0===d&&(d=this.listeners[a]=[]);d.push({fn:b,this_value:c})};Fa.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};Fa.prototype.send=function(a,b){if(this.pair&&(a=this.pair.listeners[a],void 0!==a))for(var c=0;c<a.length;c++){var d=a[c];d.fn.call(d.this_value,b)}};
|
|
69
|
+
Fa.prototype.send_async=function(a,b){setTimeout(this.send.bind(this,a,b),0)};Ca.create=function(){var a=new Fa,b=new Fa;a.pair=b;b.pair=a;return[a,b]};var Ga=new Uint8Array(256),Ha=[],Ia=[],Ja=[],Ma=new Uint8Array(256),Na=[];
|
|
70
70
|
function D(a,b){this.cpu=a;this.bus=b;this.write_buffer=new ja(64);this.read_buffer=new ja(64);this.mixer_current_address=this.command_size=this.command=this.read_buffer_lastvalue=0;this.mixer_registers=new Uint8Array(256);this.mixer_reset();this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers=[new la(65536),new la(65536)];this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=
|
|
71
71
|
this.dma_bytes_count=this.dma_sample_count=0;this.dma_channel_8bit=1;this.dma_channel_16bit=5;this.dma_autoinit=!1;this.dma_buffer=new ArrayBuffer(65536);this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_uint8=new Uint8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new va(this.dma_buffer);this.dma_paused=this.dma_waiting_transfer=!1;this.sampling_rate=22050;b.send("dac-tell-sampling-rate",
|
|
72
72
|
this.sampling_rate);this.bytes_per_sample=1;this.e2_value=170;this.e2_count=0;this.asp_registers=new Uint8Array(256);this.mpu_read_buffer=new ja(64);this.fm_current_address1=this.fm_current_address0=this.mpu_read_buffer_lastvalue=0;this.fm_waveform_select_enable=!1;this.irq=5;this.irq_triggered=new Uint8Array(16);a.io.register_read_consecutive(544,this,this.port2x0_read,this.port2x1_read,this.port2x2_read,this.port2x3_read);a.io.register_read_consecutive(904,this,this.port2x0_read,this.port2x1_read);
|
|
@@ -207,11 +207,12 @@ Rb.prototype.close=function(){if(!this.in_active_close){this.in_active_close=!0;
|
|
|
207
207
|
Rb.prototype.on_close=function(){this.emit("close")};Rb.prototype.release=function(){this.net.tcp_conn[this.tuple]&&(this.state="closed",delete this.net.tcp_conn[this.tuple])};Rb.prototype.pump=function(){if(this.send_buffer.length&&!this.pending){const a=this.send_chunk_buf,b=this.send_buffer.peek(a),c=this.ipv4_reply();c.tcp.psh=!0;c.tcp_data=a.subarray(0,b);this.net.receive(J(this.net.eth_encoder_buf,c));this.pending=!0}};function Tb(a,b){b=b||{};this.bus=a;this.id=b.id||0;this.router_mac=new Uint8Array((b.router_mac||"52:54:0:1:2:3").split(":").map(function(c){return parseInt(c,16)}));this.router_ip=new Uint8Array((b.router_ip||"192.168.86.1").split(".").map(function(c){return parseInt(c,10)}));this.vm_ip=new Uint8Array((b.vm_ip||"192.168.86.100").split(".").map(function(c){return parseInt(c,10)}));this.masquerade=void 0===b.masquerade||!!b.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=b.dns_method||"static";
|
|
208
208
|
this.doh_server=b.doh_server;this.tcp_conn={};this.eth_encoder_buf=Jb();this.fetch=(...c)=>fetch(...c);this.cors_proxy=b.cors_proxy;this.bus.register("net"+this.id+"-mac",function(c){this.vm_mac=new Uint8Array(c.split(":").map(function(d){return parseInt(d,16)}))},this);this.bus.register("net"+this.id+"-send",function(c){this.send(c)},this)}Tb.prototype.destroy=function(){};
|
|
209
209
|
Tb.prototype.on_tcp_connection=function(a,b){if(80===a.tcp.dport){let c=new Rb;c.state="syn-received";c.net=this;c.on("data",$b);c.tuple=b;c.accept(a);this.tcp_conn[b]=c;return!0}return!1};Tb.prototype.connect=function(a){return Qb(a,this)};Tb.prototype.tcp_probe=function(a){return Sb(a,this)};
|
|
210
|
-
async function $b(a){this.read=this.read||"";if((this.read+=(new TextDecoder).decode(a))&&-1!==this.read.indexOf("\r\n\r\n")){
|
|
211
|
-
if(!
|
|
212
|
-
|
|
213
|
-
this.close()})}).catch(
|
|
214
|
-
Tb.prototype.fetch=async function(a,b){this.cors_proxy&&(a=this.cors_proxy+encodeURIComponent(a));try{const c=await fetch(a,b),d=await c.arrayBuffer();return[c,d]}catch(c){return console.warn("Fetch Failed: "+a+"\n"+c),
|
|
210
|
+
async function $b(a){this.read=this.read||"";if((this.read+=(new TextDecoder).decode(a))&&-1!==this.read.indexOf("\r\n\r\n")){a=this.read.indexOf("\r\n\r\n");var b=this.read.substring(0,a).split(/\r\n/);a=this.read.substring(a+4);this.read="";let c=b[0].split(" "),d;d=/^https?:/.test(c[1])?new URL(c[1]):new URL("http://host"+c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");let e=new Headers;for(let k=1;k<b.length;++k){const l=this.net.parse_http_header(b[k]);
|
|
211
|
+
if(!l){console.warn('The request contains an invalid header: "%s"',b[k]);this.net.respond_text_and_close(this,400,"Bad Request",`Invalid header in request: ${b[k]}`);return}"host"===l.key.toLowerCase()?d.host=l.value:e.append(l.key,l.value)}if(!this.net.cors_proxy&&/^\d+\.external$/.test(d.hostname))if(b=parseInt(d.hostname.split(".")[0],10),!isNaN(b)&&0<b&&65536>b)d.protocol="http:",d.hostname="localhost",d.port=b.toString(10);else{console.warn('Unknown port for localhost: "%s"',d.href);this.net.respond_text_and_close(this,
|
|
212
|
+
400,"Bad Request",`Unknown port for localhost: ${d.href}`);return}this.name=d.href;b={method:c[0],headers:e};-1!==["put","post"].indexOf(b.method.toLowerCase())&&(b.body=a);const f=this.net.cors_proxy?this.net.cors_proxy+encodeURIComponent(d.href):d.href;new TextEncoder;let g=!1;this.net.fetch(f,b).then(k=>{let l=new Headers(k.headers);l.delete("content-encoding");l.delete("keep-alive");l.delete("content-length");l.delete("transfer-encoding");l.set("x-was-fetch-redirected",`${!!k.redirected}`);l.set("x-fetch-resp-url",
|
|
213
|
+
k.url);l.set("connection","close");this.write(this.net.form_response_head(k.status,k.statusText,l));g=!0;if(k.body&&k.body.getReader){const m=k.body.getReader(),n=({value:p,done:q})=>{p&&this.write(p);if(q)this.close();else return m.read().then(n)};m.read().then(n)}else k.arrayBuffer().then(m=>{this.write(new Uint8Array(m));this.close()})}).catch(k=>{console.warn("Fetch Failed: "+f+"\n"+k);g||this.net.respond_text_and_close(this,502,"Fetch Error",`Fetch ${f} failed:\n\n${k.stack||k.message}`);this.close()})}}
|
|
214
|
+
Tb.prototype.fetch=async function(a,b){this.cors_proxy&&(a=this.cors_proxy+encodeURIComponent(a));try{const c=await fetch(a,b),d=await c.arrayBuffer();return[c,d]}catch(c){return console.warn("Fetch Failed: "+a+"\n"+c),[{status:502,statusText:"Fetch Error",headers:new Headers({"Content-Type":"text/plain"})},(new TextEncoder).encode(`Fetch ${a} failed:\n\n${c.stack}`).buffer]}};
|
|
215
|
+
Tb.prototype.form_response_head=function(a,b,c){a=[`HTTP/1.1 ${a} ${b}`];for(const [d,e]of c.entries())a.push(`${d}: ${e}`);return(new TextEncoder).encode(a.join("\r\n")+"\r\n\r\n")};Tb.prototype.respond_text_and_close=function(a,b,c,d){const e=new Headers({"content-type":"text/plain","content-length":d.length.toString(10),connection:"close"});a.writev([this.form_response_head(b,c,e),(new TextEncoder).encode(d)]);a.close()};
|
|
215
216
|
Tb.prototype.parse_http_header=function(a){var b=a.match(/^([^:]*):(.*)$/);if(b&&(a=b[1],b=b[2].trim(),0!==a.length&&0!==b.length&&/^[\w-]+$/.test(a)&&/^[\x20-\x7E]+$/.test(b)))return{key:a,value:b}};Tb.prototype.send=function(a){Ob(a,this)};Tb.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};function ac(a,b,c){this.register_ws(a);this.last_stream=1;this.connections={0:{congestion:0}};this.congested_buffer=[];c=c||{};this.bus=b;this.id=c.id||0;this.router_mac=new Uint8Array((c.router_mac||"52:54:0:1:2:3").split(":").map(function(d){return parseInt(d,16)}));this.router_ip=new Uint8Array((c.router_ip||"192.168.86.1").split(".").map(function(d){return parseInt(d,10)}));this.vm_ip=new Uint8Array((c.vm_ip||"192.168.86.100").split(".").map(function(d){return parseInt(d,10)}));this.masquerade=
|
|
216
217
|
void 0===c.masquerade||!!c.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=c.dns_method||"doh";this.doh_server=c.doh_server;this.tcp_conn={};this.eth_encoder_buf=Jb();this.bus.register("net"+this.id+"-mac",function(d){this.vm_mac=new Uint8Array(d.split(":").map(function(e){return parseInt(e,16)}))},this);this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}
|
|
217
218
|
ac.prototype.register_ws=function(a){this.wispws=new WebSocket(a.replace("wisp://","ws://").replace("wisps://","wss://"));this.wispws.binaryType="arraybuffer";this.wispws.onmessage=b=>{this.process_incoming_wisp_frame(new Uint8Array(b.data))};this.wispws.onclose=()=>{setTimeout(()=>{this.register_ws(a)},1E4)}};
|
|
@@ -294,7 +295,7 @@ oc.prototype.conflicts_with=function(a){return this.proc_id===a.proc_id&&this.cl
|
|
|
294
295
|
M.prototype.DescribeLock=function(a,b,c,d,e){const f=new oc;f.type=a;f.start=b;f.length=c;f.proc_id=d;f.client_id=e;return f};M.prototype.GetLock=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){var c=a.foreign_id;return this.follow_fs(a).GetLock(c,b)}for(c of a.locks)if(b.conflicts_with(c))return c.clone();return null};
|
|
295
296
|
M.prototype.Lock=function(a,b,c){const d=this.inodes[a];if(this.is_forwarder(d))return a=d.foreign_id,this.follow_fs(d).Lock(a,b,c);b=b.clone();if(2!==b.type&&this.GetLock(a,b))return 1;for(c=0;c<d.locks.length;c++){a=d.locks[c];if(a.start+a.length<=b.start)continue;if(b.start+b.length<=a.start)break;if(a.proc_id!==b.proc_id||a.client_id!==b.client_id){a.conflicts_with(b);continue}var e=b.start+b.length;const f=b.start-a.start,g=a.start+a.length-e;if(0<f&&0<g&&a.type===b.type)return 0;0<f&&(a.length=
|
|
296
297
|
f);if(0>=f&&0<g)a.start=e,a.length=g;else if(0<g){for(;c<d.locks.length&&d.locks[c].start<e;)c++;d.locks.splice(c,0,this.DescribeLock(a.type,e,g,a.proc_id,a.client_id))}else 0>=f&&(d.locks.splice(c,1),c--)}if(2!==b.type){c=b;a=!1;for(e=0;e<d.locks.length&&!(c.may_merge_after(d.locks[e])&&(d.locks[e].length+=b.length,c=d.locks[e],a=!0),b.start<=d.locks[e].start);e++);a||(d.locks.splice(e,0,c),e++);for(;e<d.locks.length;e++)if(d.locks[e].is_alike(c)){d.locks[e].may_merge_after(c)&&(c.length+=d.locks[e].length,
|
|
297
|
-
d.locks.splice(e,1));break}}return 0};M.prototype.read_dir=function(a){a=this.SearchPath(a);if(-1!==a.id)return a=this.GetInode(a.id),Array.from(a.direntries.keys()).filter(b=>"."!==b&&".."!==b)};M.prototype.read_file=function(a){a=this.SearchPath(a);if(-1===a.id)return Promise.resolve(null);const b=this.GetInode(a.id);return this.Read(a.id,0,b.size)};function S(a){this.cpu_is_running=!1;this.cpu_exception_hook=function(){};var b=
|
|
298
|
+
d.locks.splice(e,1));break}}return 0};M.prototype.read_dir=function(a){a=this.SearchPath(a);if(-1!==a.id)return a=this.GetInode(a.id),Array.from(a.direntries.keys()).filter(b=>"."!==b&&".."!==b)};M.prototype.read_file=function(a){a=this.SearchPath(a);if(-1===a.id)return Promise.resolve(null);const b=this.GetInode(a.id);return this.Read(a.id,0,b.size)};function S(a){this.cpu_is_running=!1;this.cpu_exception_hook=function(){};var b=Ca.create();this.bus=b[0];this.emulator_bus=b[1];var c,d;const e=new WebAssembly.Table({element:"anyfunc",initial:1924});b={cpu_exception_hook:g=>this.cpu_exception_hook(g),run_hardware_timers:function(g,k){return c.run_hardware_timers(g,k)},cpu_event_halt:()=>{this.emulator_bus.send("cpu-event-halt")},abort:function(){},microtick:H.microtick,get_rand_int:function(){return ba()},apic_acknowledge_irq:function(){return c.devices.apic.acknowledge_irq()},
|
|
298
299
|
stop_idling:function(){return c.stop_idling()},io_port_read8:function(g){return c.io.port_read8(g)},io_port_read16:function(g){return c.io.port_read16(g)},io_port_read32:function(g){return c.io.port_read32(g)},io_port_write8:function(g,k){c.io.port_write8(g,k)},io_port_write16:function(g,k){c.io.port_write16(g,k)},io_port_write32:function(g,k){c.io.port_write32(g,k)},mmap_read8:function(g){return c.mmap_read8(g)},mmap_read16:function(g){return c.mmap_read16(g)},mmap_read32:function(g){return c.mmap_read32(g)},
|
|
299
300
|
mmap_write8:function(g,k){c.mmap_write8(g,k)},mmap_write16:function(g,k){c.mmap_write16(g,k)},mmap_write32:function(g,k){c.mmap_write32(g,k)},mmap_write64:function(g,k,l){c.mmap_write64(g,k,l)},mmap_write128:function(g,k,l,m,n){c.mmap_write128(g,k,l,m,n)},log_from_wasm:function(g,k){String.fromCharCode(...(new Uint8Array(d.buffer,g>>>0,k>>>0)))},console_log_from_wasm:function(g,k){g=String.fromCharCode(...(new Uint8Array(d.buffer,g>>>0,k>>>0)));console.error(g)},dbg_trace_from_wasm:function(){},codegen_finalize:(g,
|
|
300
301
|
k,l,m,n)=>{c.codegen_finalize(g,k,l,m,n)},jit_clear_func:g=>c.jit_clear_func(g),jit_clear_all_funcs:()=>c.jit_clear_all_funcs(),__indirect_function_table:e};let f=a.wasm_fn;f||(f=g=>new Promise(k=>{let l="v86.wasm",m="v86-fallback.wasm";a.wasm_path?(l=a.wasm_path,m=l.replace("v86.wasm","v86-fallback.wasm")):"undefined"===typeof window&&"string"===typeof __dirname?(l=__dirname+"/"+l,m=__dirname+"/"+m):(l="build/"+l,m="build/"+m);pa(l,{done:async n=>{try{const {instance:p}=await WebAssembly.instantiate(n,
|