MeshCentral/agents/modules_meshcore_min/smbios.min.js

1 line
6.9 KiB
JavaScript
Raw Normal View History

2019-01-28 18:49:08 -05:00
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(n){var m={};var l;var k=0;var n;var r=0;while(n&&k<n.length){var p=n[k];var o=n[k+1];if(!m[p]){m[p]=[]}m[p].push(n.slice(k+4,k+o));if(process.platform=="win32"){m[p].peek()._ext=l}k+=o;m[p].peek()._strings=[];while(n[k]!=0){var q=k;while(n[k++]!=0){}m[p].peek()._strings.push(n.slice(q,k).toString().trim())}k+=(m[p].peek()._strings.length==0)?2:1;++r}return(m)};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=