mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-30 13:22:28 +03:00
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
var CreateAmtRemoteIder=function(){var l={};function f(){urlvars&&urlvars.idertrace&&console.log(...arguments)}l.protocol=3,l.bytesToAmt=0,l.bytesFromAmt=0,l.rx_timeout=3e4,l.tx_timeout=0,l.heartbeat=2e4,l.version=1,l.acc="",l.inSequence=0,l.outSequence=0,l.iderinfo=null,l.enabled=!1,l.iderStart=0,l.floppy=null,l.cdrom=null,l.floppyReady=!1,l.cdromReady=!1,l.pingTimer=null;var u=String.fromCharCode(0,38,49,128,0,0,0,0,5,30,16,169,8,32,2,0,3,195,0,0,0,0,0,0,0,0,0,0,40,0,0,0,0,0,0,0,2,208,0,0),h=String.fromCharCode(0,92,36,128,0,0,0,0,1,10,0,1,0,0,0,0,2,0,0,0,3,22,0,160,0,0,0,0,0,18,2,0,0,0,0,0,0,0,160,0,0,0,5,30,16,169,8,32,2,0,3,195,0,0,0,0,0,0,0,0,0,0,40,0,0,0,0,0,0,0,2,208,0,0,8,10,0,0,0,0,0,0,0,0,0,0,11,6,0,0,0,17,36,49),p=String.fromCharCode(0,38,36,128,0,0,0,0,5,30,4,176,2,18,2,0,0,80,0,0,0,0,0,0,0,0,0,0,40,0,0,0,0,0,0,0,2,208,0,0),R=String.fromCharCode(0,92,36,128,0,0,0,0,1,10,0,1,0,0,0,0,2,0,0,0,3,22,0,160,0,0,0,0,0,18,2,0,0,0,0,0,0,0,160,0,0,0,5,30,4,176,2,18,2,0,0,80,0,0,0,0,0,0,0,0,0,0,40,0,0,0,0,0,0,0,2,208,0,0,8,10,0,0,0,0,0,0,0,0,0,0,11,6,0,0,0,17,36,49),E=String.fromCharCode(0,18,1,128,0,0,0,0,26,10,0,0,0,0,0,0,0,0,0,0),I=String.fromCharCode(0,18,1,128,0,0,0,0,29,10,0,0,0,0,0,0,0,0,0,0),g=String.fromCharCode(0,32,1,128,0,0,0,0,42,24,0,0,0,0,32,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0),b=String.fromCharCode(0,40,1,128,0,0,0,0,1,6,0,255,0,0,0,0,42,24,0,0,0,0,2,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0),A=(String.fromCharCode(0,0,0,40,0,0,0,8),String.fromCharCode(0,0,3,4,0,8,1,0)),T=String.fromCharCode(0,1,3,4,0,0,0,2),D=String.fromCharCode(0,2,3,4,0,0,0,0),y=String.fromCharCode(0,3,3,4,41,0,0,2),_=String.fromCharCode(0,16,1,8,0,0,8,0,0,1,0,0),k=String.fromCharCode(0,30,3,0),v=String.fromCharCode(1,0,3,0),O=String.fromCharCode(1,5,3,0),X=String.fromCharCode(0,18,36,128,0,0,0,0,1,10,0,1,0,0,0,0,2,0,0,0),w=String.fromCharCode(0,18,49,128,0,0,0,0,1,10,0,1,0,0,0,0,2,0,0,0),F=String.fromCharCode(0,14,1,128,0,0,0,0,1,6,0,255,0,0,0,0);function H(e,r,n,a){var o=null,t=0;160==e&&(o=l.floppy,null!=l.floppy&&(t=l.floppy.size>>9)),176==e&&(o=l.cdrom,null!=l.cdrom&&(t=l.cdrom.size>>11)),n<0||t<r+n?l.SendCommandEndResponse(1,5,e,33,0):0!=n?null!=o&&(160==e?(r<<=9,n<<=9):(r<<=11,n<<=11),null!==i?(console.log("IDERERROR: Read while performing read"),l.Stop()):(i=o,d=e,S=r,c=n,function e(r){var n=c,a=S;c>l.iderinfo.readbfr&&(n=l.iderinfo.readbfr);c-=n;S+=n;var o=new FileReader;o.onload=function(){l.SendDataToHost(d,0==c,this.result,1&r),0<c&&0==C?e(r):(i=null,C&&(l.SendCommand(71),C=!1))};o.readAsBinaryString(i.slice(a,a+n))}(a))):l.SendCommandEndResponse(1,0,e,0,0)}l.xxStateChange=function(e){f("IDER-StateChange",e),0==e&&l.Stop(),3==e&&l.Start()},l.Start=function(){f("IDER-Start"),f(l.floppy,l.cdrom),l.bytesToAmt=0,l.bytesFromAmt=0,l.inSequence=0,l.outSequence=0,l.SendCommand(64,ShortToStrX(l.rx_timeout)+ShortToStrX(l.tx_timeout)+ShortToStrX(l.heartbeat)+IntToStrX(l.version))},l.Stop=function(){f("IDER-Stop"),l.pingTimer&&(clearInterval(l.pingTimer),l.pingTimer=null),l.parent.Stop()},l.ProcessData=function(e){for(l.bytesFromAmt+=e.length,l.acc+=e,f("IDER-ProcessData",l.acc.length,rstr2hex(l.acc));;){var r=l.ProcessDataEx();if(0==r)return;if(l.inSequence!=ReadIntX(l.acc,4))return f("ERROR: Out of sequence",l.inSequence,ReadIntX(l.acc,4)),void l.Stop();l.inSequence++,l.acc=l.acc.substring(r)}},l.SendCommand=function(e,r,n,a){null==r&&(r="");n=50<e&&1==n?2:0;a&&(n+=1);r=String.fromCharCode(e,0,0,n)+IntToStrX(l.outSequence++)+r;l.parent.xxSend(r),l.bytesToAmt+=r.length,75!=e&&f("IDER-SendData",r.length,rstr2hex(r))},l.SendCommandEndResponse=function(e,r,n,a,o){e?l.SendCommand(81,String.fromCharCode(0,0,0,0,0,0,0,0,0,0,0,0,197,0,3,0,0,0,n,80,0,0,0),!0):l.SendCommand(81,String.fromCharCode(0,0,0,0,0,0,0,0,0,0,0,0,135,r<<4,3,0,0,0,n,81,r,a,o),!0)},l.SendDataToHost=function(e,r,n,a){var o=a?0:n.length;1==r?l.SendCommand(84,String.fromCharCode(0,255&n.length,n.length>>8,0,a?180:181,0,2,0,255&o,o>>8,e,88,133,0,3,0,0,0,e,80,0,0,0,0,0,0)+n,r,a):l.SendCommand(84,String.fromCharCode(0,255&n.length,n.length>>8,0,a?180:181,0,2,0,255&o,o>>8,e,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0)+n,r,a)},l.SendGetDataFromHost=function(e,r){l.SendCommand(82,String.fromCharCode(0,255&r,r>>8,0,181,0,0,0,255&r,r>>8,e,88,0,0,0,0,0,0,0,0,0,0,0),!1)},l.SendDisableEnableFeatures=function(e,r){null==r&&(r=""),l.SendCommand(72,String.fromCharCode(e)+r)};var d,S,c,C=!(l.ProcessDataEx=function(){if(l.acc.length<8)return 0;switch(l.acc.charCodeAt(0)){case 65:if(l.acc.length<30)return 0;var e=l.acc.charCodeAt(29);return l.acc.length<30+e?0:(l.iderinfo={},l.iderinfo.major=l.acc.charCodeAt(8),l.iderinfo.minor=l.acc.charCodeAt(9),l.iderinfo.fwmajor=l.acc.charCodeAt(10),l.iderinfo.fwminor=l.acc.charCodeAt(11),l.iderinfo.readbfr=ReadShortX(l.acc,16),l.iderinfo.writebfr=ReadShortX(l.acc,18),l.iderinfo.proto=l.acc.charCodeAt(21),l.iderinfo.iana=ReadIntX(l.acc,25),f(l.iderinfo),0!=l.iderinfo.proto&&(f("Unknown proto",l.iderinfo.proto),l.Stop()),8192<l.iderinfo.readbfr&&(f("Illegal read buffer size",l.iderinfo.readbfr),l.Stop()),8192<l.iderinfo.writebfr&&(f("Illegal write buffer size",l.iderinfo.writebfr),l.Stop()),0==l.iderStart?l.SendDisableEnableFeatures(3,IntToStrX(9)):1==l.iderStart?l.SendDisableEnableFeatures(3,IntToStrX(17)):2==l.iderStart&&l.SendDisableEnableFeatures(3,IntToStrX(25)),30+e);case 67:return f("CLOSE"),l.Stop(),8;case 68:return l.SendCommand(69),8;case 69:return f("PONG"),8;case 70:if(l.acc.length<9)return 0;var r=l.acc.charCodeAt(8);return null===i?(l.SendCommand(71),f("RESETOCCURED1",r)):(C=!0,f("RESETOCCURED2",r)),9;case 73:if(l.acc.length<13)return 0;var n=l.acc.charCodeAt(8),a=ReadIntX(l.acc,9);switch(f("STATUS_DATA",n,a),n){case 1:1&a&&(0==l.iderStart?l.SendDisableEnableFeatures(3,IntToStrX(9)):1==l.iderStart?l.SendDisableEnableFeatures(3,IntToStrX(17)):2==l.iderStart&&l.SendDisableEnableFeatures(3,IntToStrX(25)));break;case 2:l.enabled=!!(2&a),f("IDER Status: "+l.enabled);break;case 3:1!=a&&f("Register toggle failure")}return 13;case 74:return l.acc.length<11?0:(f("IDER: ABORT",l.acc.charCodeAt(8)),11);case 75:return 8;case 80:if(l.acc.length<28)return 0;var o=16&l.acc.charCodeAt(14)?176:160,t=l.acc.charCodeAt(14),r=l.acc.substring(16,28),n=l.acc.charCodeAt(9);return f("SCSI_CMD",o,rstr2hex(r),n,t),function(e,r,n,a){switch(r.charCodeAt(0)){case 0:switch(f("SCSI: TEST_UNIT_READY",e),e){case 160:if(null==l.floppy)return l.SendCommandEndResponse(1,2,e,58,0);if(0==l.floppyReady)return l.floppyReady=!0,l.SendCommandEndResponse(1,6,e,40,0);break;case 176:if(null==l.cdrom)return l.SendCommandEndResponse(1,2,e,58,0);if(0==l.cdromReady)return l.cdromReady=!0,l.SendCommandEndResponse(1,6,e,40,0);break;default:return f("SCSI Internal error 3",e)}l.SendCommandEndResponse(1,0,e,0,0);break;case 8:C=((31&r.charCodeAt(1))<<16)+(r.charCodeAt(2)<<8)+r.charCodeAt(3),S=r.charCodeAt(4),f("SCSI: READ_6",e,C,S=0==S?256:S),H(e,C,S,n);break;case 10:return C=((31&r.charCodeAt(1))<<16)+(r.charCodeAt(2)<<8)+r.charCodeAt(3),S=r.charCodeAt(4),f("SCSI: WRITE_6",e,C,S=0==S?256:S),l.SendCommandEndResponse(1,2,e,58,0);case 26:if(f("SCSI: MODE_SENSE_6",e),63==r.charCodeAt(2)&&0==r.charCodeAt(3)){var o=0,t=0;switch(e){case 160:if(null==l.floppy)return l.SendCommandEndResponse(1,2,e,58,0);o=0,t=128;break;case 176:if(null==l.cdrom)return l.SendCommandEndResponse(1,2,e,58,0);o=5,t=128;break;default:return f("SCSI Internal error 6",e)}return l.SendDataToHost(e,!0,String.fromCharCode(0,o,t,0),1&n)}l.SendCommandEndResponse(1,5,e,36,0);break;case 27:l.SendCommandEndResponse(1,0,e);break;case 30:if(f("SCSI: ALLOW_MEDIUM_REMOVAL",e),160==e&&null==l.floppy)return l.SendCommandEndResponse(1,2,e,58,0);if(176==e&&null==l.cdrom)return l.SendCommandEndResponse(1,2,e,58,0);l.SendCommandEndResponse(1,0,e,0,0);break;case 35:f("SCSI: READ_FORMAT_CAPACITIES",e);var d=ReadShort(r,7);switch(e){case 160:if(null==l.floppy||0==l.floppy.size)return l.SendCommandEndResponse(0,5,e,36,0);l.floppy.size;break;case 176:if(null==l.cdrom||0==l.cdrom.size)return l.SendCommandEndResponse(0,5,e,36,0);l.cdrom.size;break;default:return f("SCSI Internal error 4",e)}l.SendDataToHost(e,!0,IntToStr(8)+String.fromCharCode(0,0,11,64,2,0,2,0),1&n);break;case 37:f("SCSI: READ_CAPACITY",e);var S=0;switch(e){case 160:if(null==l.floppy||0==l.floppy.size)return l.SendCommandEndResponse(0,2,e,58,0);f("DEV_FLOPPY",S=null!=l.floppy?(l.floppy.size>>9)-1:S);break;case 176:if(null==l.floppy||0==l.floppy.size)return l.SendCommandEndResponse(0,2,e,58,0);f("DEV_CDDVD",S=null!=l.cdrom?(l.cdrom.size>>11)-1:S);break;default:return f("SCSI Internal error 4",e)}f("SCSI: READ_CAPACITY2",e,a),l.SendDataToHost(a,!0,IntToStr(S)+String.fromCharCode(0,0,176==e?8:2,0),1&n);break;case 40:C=ReadInt(r,2),S=ReadShort(r,7),f("SCSI: READ_10",e,C,S),H(e,C,S,n);break;case 42:case 46:C=ReadInt(r,2),S=ReadShort(r,7),f("SCSI: WRITE_10",e,C,S),l.SendGetDataFromHost(e,512*S);break;case 67:var d=ReadShort(r,7),c=2&r.charCodeAt(1),C=7&r.charCodeAt(2);switch(0==C&&(C=r.charCodeAt(9)>>6),f("SCSI: READ_TOC, dev="+e+", buflen="+d+", msf="+c+", format="+C),e){case 160:return l.SendCommandEndResponse(1,5,e,32,0);case 176:break;default:return f("SCSI Internal error 9",e)}1==C?l.SendDataToHost(e,!0,String.fromCharCode(0,10,1,1,0,20,1,0,0,0,0,0),1&n):0==C&&(c?l.SendDataToHost(e,!0,String.fromCharCode(0,18,1,1,0,20,1,0,0,0,2,0,0,20,170,0,0,0,52,19),1&n):l.SendDataToHost(e,!0,String.fromCharCode(0,18,1,1,0,20,1,0,0,0,0,0,0,20,170,0,0,0,0,0),1&n));break;case 70:var c=2!=r.charCodeAt(1),i=ReadShort(r,2),d=ReadShort(r,7);if(f("SCSI: GET_CONFIGURATION",e,c,i,d),0==d)return l.SendDataToHost(e,!0,IntToStr(60)+IntToStr(8),1&n);var s=IntToStr(8);return 0==i&&(s+=A),(1==i||c&&i<1)&&(s+=T),(2==i||c&&i<2)&&(s+=D),(3==i||c&&i<3)&&(s+=y),(16==i||c&&i<16)&&(s+=_),(30==i||c&&i<30)&&(s+=k),(256==i||c&&i<256)&&(s+=v),(261==i||c&&i<261)&&(s+=O),(s=IntToStr(s.length)+s).length>d&&(s=s.substring(0,d)),l.SendDataToHost(e,!0,s,1&n);case 74:if(f("SCSI: GET_EVENT_STATUS_NOTIFICATION",e,r.charCodeAt(1),r.charCodeAt(4),r.charCodeAt(9)),1!=r.charCodeAt(1)&&16!=r.charCodeAt(4)){f("SCSI ERROR"),l.SendCommandEndResponse(1,5,e,38,1);break}i=0;(160==e&&null!=l.floppy||176==e&&null!=l.cdrom)&&(i=2),l.SendDataToHost(e,!0,String.fromCharCode(0,i,128,0),1&n);break;case 76:l.SendCommand(81,IntToStrX(0)+IntToStrX(0)+IntToStrX(0)+String.fromCharCode(135,80,3,0,0,0,176,81,5,32,0),!0);break;case 81:return f("SCSI READ_DISC_INFO",e),l.SendCommandEndResponse(0,5,e,32,0);case 85:return f("SCSI ERROR: MODE_SELECT_10",e),l.SendCommandEndResponse(1,5,e,32,0);case 90:f("SCSI: MODE_SENSE_10",e,63&r.charCodeAt(2));d=ReadShort(r,7),s=null;if(0==d)return l.SendDataToHost(e,!0,IntToStr(60)+IntToStr(8),1&n);var m=0;switch(160==e?null!=l.floppy&&(m=l.floppy.size>>9):null!=l.cdrom&&(m=l.cdrom.size>>11),63&r.charCodeAt(2)){case 1:s=160==e?m<=2880?X:w:F;break;case 5:160==e&&(s=m<=2880?p:u);break;case 63:s=160==e?m<=2880?R:h:b;break;case 26:176==e&&(s=E);break;case 29:176==e&&(s=I);break;case 42:176==e&&(s=g)}null==s?l.SendCommandEndResponse(0,5,e,32,0):l.SendDataToHost(e,!0,s,1&n);break;default:return f("IDER: Unknown SCSI command",r.charCodeAt(0)),l.SendCommandEndResponse(0,5,e,32,0)}}(o,r,n,t),28;case 83:if(l.acc.length<14)return 0;e=ReadShortX(l.acc,9);return l.acc.length<14+e?0:(f("SCSI_WRITE, len = "+(14+e)),l.SendCommand(81,String.fromCharCode(0,0,0,0,0,0,0,0,0,0,0,0,135,112,3,0,0,0,160,81,7,39,0),!0),14+e);default:f("Unknown IDER command",l.acc[0]),l.Stop()}return 0}),i=null;return l} |