mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-23 22:13:14 +03:00
1 line
7.0 KiB
JavaScript
1 line
7.0 KiB
JavaScript
try{Object.defineProperty(Array.prototype,"peek",{value:function(){return(this.length>0?this[this.length-1]:undefined)}})}catch(e){}try{Object.defineProperty(String.prototype,"replaceAll",{value:function replaceAll(b,a){return(this.split(b).join(a))}})}catch(e){}var RSMB=1381190978;var memoryLocation={1:"Other",2:"Unknown",3:"System Board",4:"ISA",5:"EISA",6:"PCI",7:"MCA",8:"PCMCIA",9:"Proprietary",10:"NuBus",160:"PC-98/C20",161:"PC-98/C24",162:"PC-98/E",163:"PC-98/LB"};var wakeReason=["Reserved","Other","Unknown","APM Timer","Modem Ring","LAN","Power Switch","PCI","AC Power"];function zeroLeftPad(c,b){if((b==null)&&(typeof(b)!="number")){return null}if(c==null){c=""}var d="";for(var a=0;a<b-c.length;a++){d+="0"}return d+c}function SMBiosTables(){this._ObjectID="SMBiosTable";if(process.platform=="win32"){this._marshal=require("_GenericMarshal");this._native=this._marshal.CreateNativeProxy("Kernel32.dll");this._native.CreateMethod("EnumSystemFirmwareTables");this._native.CreateMethod("GetSystemFirmwareTable")}if(process.platform=="linux"){this._canonicalizeData=function a(k){var n=k.toString().split("Header and Data:\x0A");var o=require("MemoryStream");var p=new o();for(var m=1;m<n.length;++m){var v=n[m].split("Strings:\x0A");var l=v[0].split("\x0A\x0A")[0].replaceAll("\x0A","").trim().replaceAll(" ","").replaceAll("\x09","");p.write(Buffer.from(l,"hex"));if(v.length>1){var r=v[1].split("\x0A\x0A")[0].split("\x0A");var s=[];for(var t in r){var u=r[t].trim().replaceAll(" ","").replaceAll("\x09","");if(!(u[0]=='"')){s.push(u)}}p.write(Buffer.from(s.join(""),"hex"));p.write(Buffer.from("00","hex"))}else{p.write(Buffer.from("0000","hex"))}}var q=p.buffer;q.ms=p;return(q)}}this._parse=function b(o){var n={};var m;var l=0;var o;var s=0;while(o&&l<o.length){var q=o[l];var p=o[l+1];if(!n[q]){n[q]=[]}n[q].push(o.slice(l+4,l+p));if(process.platform=="win32"){n[q].peek()._ext=m}l+=p;n[q].peek()._strings=[];while(o[l]!=0&&l<=o.length){var r=l;while(o[l++]!=0&&l<=o.length){}try{n[q].peek()._strings.push(o.slice(r,l).toString().trim())}catch(k){console.log("oops")}}l+=(n[q].peek()._strings.length==0)?2:1;++s}return(n)};this.get=function d(l){if(process.platform=="win32"){var q=this._native.GetSystemFirmwareTable(RSMB,0,0,0).Val;var o=this._marshal.CreatePointer()._size;var k=this._marshal.CreateVariable(q);var r=this._native.GetSystemFirmwareTable(RSMB,0,k,q).Val;var p=k.toBuffer();var m=k.Deref(4,4).toBuffer().readUInt32LE(0);pbyte=k.Deref(8,m);SMData=pbyte.toBuffer();if(l){l.apply(this,[this._parse(SMData)]);return}else{return(this._parse(SMData))}}if(process.platform=="linux"){var n=require("MemoryStream");this.child=require("child_process").execFile("/usr/sbin/dmidecode",["dmidecode","-u"]);this.child.SMBiosTable=this;this.child.ms=new n();this.child.ms.callback=l;this.child.ms.child=this.child;this.child.stdout.on("data",function(s){this.parent.ms.write(s)});this.child.on("exit",function(){this.ms.end()});this.child.ms.on("end",function(){if(this.buffer.length<300){if(this.callback){this.callback.apply(this.child.SMBiosTable,[])}}else{var t=this.child.SMBiosTable._canonicalizeData(this.buffer);var s=this.child.SMBiosTable._parse(t);if(this.callback){this.callback.apply(this.child.SMBiosTable,[s])}}});return}if(l){l.apply(this,[null]);return}else{return(null)}};this.parse=function g(k){var m={};try{m.processorInfo=this.processorInfo(k)}catch(l){}try{m.memoryInfo=this.memoryInfo(k)}catch(l){}try{m.systemInfo=this.systemInfo(k)}catch(l){}try{m.systemSlots=this.systemInfo(k)}catch(l){}try{m.amtInfo=this.amtInfo(k)}catch(l){}return m};this.processorInfo=function h(l){if(!l){throw ("no data")}var r=[];var q=["ERROR","Other","Unknown","CPU","ALU","DSP","GPU"];var t=["Unknown","Enabled","Disabled by user","Disabled by BIOS","Idle","Reserved","Reserved","Other"];var k=0;while(l[4]&&l[4].length>0){var n=l[4].pop();var o=n[20]&64;var s=n[20]&7;if(o){var m={_ObjectID:"SMBiosTables.processorInfo"};m.Processor=q[n[1]];m.MaxSpeed=n.readUInt16LE(16)+" Mhz";if(n[31]){m.Cores=n[31]}if(n[33]){m.Threads=n[33]}m.Populated=1;m.Status=t[s];m.Socket=n._strings[n[0]-1];m.Manufacturer=n._strings[n[3]-1];m.Version=n._strings[n[12]-1];r.push(m)}}return(r)};this.memoryInfo=function f(k){if(!k){throw ("no data")}var n={_ObjectID:"SMBiosTables.memoryInfo"};if(k[16]){var l=k[16].peek();n.location=memoryLocation[l[0]];if((n.maxCapacityKb=l.readUInt32LE(3))==2147483648){n.maxCapacityKb="A really big number"}}return(n)};this.systemInfo=function i(k){if(!k){throw ("no data")}var l={_ObjectID:"SMBiosTables.systemInfo"};if(k[1]){var m=k[1].peek();var n=m.slice(4,20);l.uuid=[zeroLeftPad(n.readUInt32LE(0).toString(16),8),zeroLeftPad(n.readUInt16LE(4).toString(16),4),zeroLeftPad(n.readUInt16LE(6).toString(16),4),zeroLeftPad(n.readUInt16BE(8).toString(16),4),zeroLeftPad(n.slice(10).toString("hex").toLowerCase(),12)].join("-");l.wakeReason=wakeReason[m[20]]}return(l)};this.systemSlots=function j(k){if(!k){throw ("no data")}var l=[];if(k[9]){while(k[9].length>0){var m=k[9].pop();l.push({name:m._strings[m[0]-1]})}}return(l)};this.amtInfo=function c(l){if(!l){throw ("no data")}var n={AMT:false};if(l[130]&&l[130].peek().slice(0,4).toString()=="$AMT"){var k=l[130].peek();n.AMT=k[4]?true:false;if(n.AMT){n.enabled=k[5]?true:false;n.storageRedirection=k[6]?true:false;n.serialOverLan=k[7]?true:false;n.kvm=k[14]?true:false;if(l[131].peek()&&l[131].peek().slice(52,56).toString()=="vPro"){var o=l[131].peek();if(o[0]&4){n.TXT=(o[0]&8)?true:false}if(o[0]&16){n.VMX=(o[0]&32)?true:false}n.MEBX=o.readUInt16LE(4).toString()+"."+o.readUInt16LE(6).toString()+"."+o.readUInt16LE(8).toString()+"."+o.readUInt16LE(10).toString();var m=o.slice(20,32);n.ManagementEngine=m.readUInt16LE(6).toString()+"."+m.readUInt16LE(4).toString()+"."+m.readUInt16LE(10).toString()+"."+m.readUInt16LE(8).toString()}}}return(n)};this.smTableTypes={0:"BIOS information",1:"System information",2:"Baseboard (or Module) information",4:"Processor information",5:"memory controller information",6:"Memory module information",7:"Cache information",8:"Port connector information",9:"System slots",10:"On board devices information",11:"OEM strings",12:"System configuration options",13:"BIOS language information",14:"Group associations",15:"System event log",16:"Physical memory array",17:"Memory device",18:"32bit memory error information",19:"Memory array mapped address",20:"Memory device mapped address",21:"Built-in pointing device",22:"Portable battery",23:"System reset",24:"Hardware security",25:"System power controls",26:"Voltage probe",27:"Cooling device",28:"Temperature probe",29:"Electrical current probe",30:"Out-of-band remote access",31:"Boot integrity services (BIS) entry point",32:"System boot information",33:"64bit memory error information",34:"Management device",35:"Management device component",36:"Management device threshold data",37:"Memory channel",38:"IPMI device information",39:"System power supply",40:"Additional information",41:"Onboard devices extended information",42:"Management controller host interface",126:"Inactive",127:"End-of-table"}}module.exports=new SMBiosTables(); |