Example #1
0
        public SMBIOS()
        {
            int p = (int)Environment.OSVersion.Platform;

            if ((p == 4) || (p == 128))
            {
                this.raw   = null;
                this.table = null;

                string boardVendor  = ReadSysFS("/sys/class/dmi/id/board_vendor");
                string boardName    = ReadSysFS("/sys/class/dmi/id/board_name");
                string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
                this.baseBoardInformation = new BaseBoardInformation(
                    boardVendor, boardName, boardVersion, null);

                string systemVendor   = ReadSysFS("/sys/class/dmi/id/sys_vendor");
                string productName    = ReadSysFS("/sys/class/dmi/id/product_name");
                string productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
                this.systemInformation = new SystemInformation(systemVendor,
                                                               productName, productVersion, null, null);

                string biosVendor  = ReadSysFS("/sys/class/dmi/id/bios_vendor");
                string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
                this.biosInformation = new BIOSInformation(biosVendor, biosVersion);
            }
            else
            {
                List <Structure> structureList = new List <Structure>();

                raw = null;
                byte majorVersion = 0;
                byte minorVersion = 0;
                try {
                    ManagementObjectCollection collection;
                    using (ManagementObjectSearcher searcher =
                               new ManagementObjectSearcher("root\\WMI",
                                                            "SELECT * FROM MSSMBios_RawSMBiosTables")) {
                        collection = searcher.Get();
                    }

                    foreach (ManagementObject mo in collection)
                    {
                        raw          = (byte[])mo["SMBiosData"];
                        majorVersion = (byte)mo["SmbiosMajorVersion"];
                        minorVersion = (byte)mo["SmbiosMinorVersion"];
                        break;
                    }
                } catch { }

                if (majorVersion > 0 || minorVersion > 0)
                {
                    version = new Version(majorVersion, minorVersion);
                }

                if (raw != null && raw.Length > 0)
                {
                    int  offset = 0;
                    byte type   = raw[offset];
                    while (offset + 4 < raw.Length && type != 127)
                    {
                        type = raw[offset];
                        int    length = raw[offset + 1];
                        ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);

                        if (offset + length > raw.Length)
                        {
                            break;
                        }
                        byte[] data = new byte[length];
                        Array.Copy(raw, offset, data, 0, length);
                        offset += length;

                        List <string> stringsList = new List <string>();
                        if (offset < raw.Length && raw[offset] == 0)
                        {
                            offset++;
                        }

                        while (offset < raw.Length && raw[offset] != 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            while (offset < raw.Length && raw[offset] != 0)
                            {
                                sb.Append((char)raw[offset]); offset++;
                            }
                            offset++;
                            stringsList.Add(sb.ToString());
                        }
                        offset++;
                        switch (type)
                        {
                        case 0x00:
                            this.biosInformation = new BIOSInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.biosInformation); break;

                        case 0x01:
                            this.systemInformation = new SystemInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.systemInformation); break;

                        case 0x02: this.baseBoardInformation = new BaseBoardInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.baseBoardInformation); break;

                        default: structureList.Add(new Structure(
                                                       type, handle, data, stringsList.ToArray())); break;
                        }
                    }
                }

                table = structureList.ToArray();
            }
        }
Example #2
0
        public SMBIOS()
        {
            int p = (int)Environment.OSVersion.Platform;
            if ((p == 4) || (p == 128))
            {
                this.raw = null;
                this.table = null;

                string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor");
                string boardName = ReadSysFS("/sys/class/dmi/id/board_name");
                string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
                this.baseBoardInformation = new BaseBoardInformation(
                  boardVendor, boardName, boardVersion, null);

                string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor");
                string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
                this.biosInformation = new BIOSInformation(biosVendor, biosVersion);

            }
            else
            {
                List<Structure> structureList = new List<Structure>();

                raw = null;
                byte majorVersion = 0;
                byte minorVersion = 0;
                try
                {
                    ManagementObjectCollection collection;
                    using (ManagementObjectSearcher searcher =
                      new ManagementObjectSearcher("root\\WMI",
                        "SELECT * FROM MSSMBios_RawSMBiosTables"))
                    {
                        collection = searcher.Get();
                    }

                    foreach (ManagementObject mo in collection)
                    {
                        raw = (byte[])mo["SMBiosData"];
                        majorVersion = (byte)mo["SmbiosMajorVersion"];
                        minorVersion = (byte)mo["SmbiosMinorVersion"];
                        break;
                    }
                }
                catch { }

                if (majorVersion > 0 || minorVersion > 0)
                    version = new Version(majorVersion, minorVersion);

                if (raw != null && raw.Length > 0)
                {
                    int offset = 0;
                    byte type = raw[offset];
                    while (offset + 4 < raw.Length && type != 127)
                    {

                        type = raw[offset];
                        int length = raw[offset + 1];
                        ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);

                        if (offset + length > raw.Length)
                            break;
                        byte[] data = new byte[length];
                        Array.Copy(raw, offset, data, 0, length);
                        offset += length;

                        List<string> stringsList = new List<string>();
                        if (offset < raw.Length && raw[offset] == 0)
                            offset++;

                        while (offset < raw.Length && raw[offset] != 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            while (offset < raw.Length && raw[offset] != 0)
                            {
                                sb.Append((char)raw[offset]); offset++;
                            }
                            offset++;
                            stringsList.Add(sb.ToString());
                        }
                        offset++;
                        switch (type)
                        {
                            case 0x00:
                                this.biosInformation = new BIOSInformation(
                                  type, handle, data, stringsList.ToArray());
                                structureList.Add(this.biosInformation); break;
                            case 0x02: this.baseBoardInformation = new BaseBoardInformation(
                                type, handle, data, stringsList.ToArray());
                                structureList.Add(this.baseBoardInformation); break;
                            default: structureList.Add(new Structure(
                              type, handle, data, stringsList.ToArray())); break;
                        }
                    }
                }

                table = structureList.ToArray();
            }
        }
Example #3
0
        public SMBIOS()
        {
            if (OperatingSystem.IsUnix)
            {
                this.raw   = null;
                this.table = null;

                string boardVendor  = ReadSysFS("/sys/class/dmi/id/board_vendor");
                string boardName    = ReadSysFS("/sys/class/dmi/id/board_name");
                string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
                this.baseBoardInformation = new BaseBoardInformation(
                    boardVendor, boardName, boardVersion, null);

                string systemVendor   = ReadSysFS("/sys/class/dmi/id/sys_vendor");
                string productName    = ReadSysFS("/sys/class/dmi/id/product_name");
                string productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
                this.systemInformation = new SystemInformation(systemVendor,
                                                               productName, productVersion, null, null);

                string biosVendor  = ReadSysFS("/sys/class/dmi/id/bios_vendor");
                string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
                this.biosInformation = new BIOSInformation(biosVendor, biosVersion);

                this.memoryDevices = new MemoryDevice[0];
            }
            else
            {
                List <Structure>    structureList    = new List <Structure>();
                List <MemoryDevice> memoryDeviceList = new List <MemoryDevice>();

                raw = null;
                byte majorVersion = 0;
                byte minorVersion = 0;
                try {
                    // Get bios raw information
                    ManagementObjectCollection collection;
                    using (ManagementObjectSearcher searcher =
                               new ManagementObjectSearcher("root\\WMI",
                                                            "SELECT * FROM MSSMBios_RawSMBiosTables")) {
                        collection = searcher.Get();
                    }

                    foreach (ManagementObject mo in collection)
                    {
                        raw          = (byte[])mo["SMBiosData"];
                        majorVersion = (byte)mo["SmbiosMajorVersion"];
                        minorVersion = (byte)mo["SmbiosMinorVersion"];
                        break;
                    }
                } catch { }

                if (majorVersion > 0 || minorVersion > 0)
                {
                    version = new Version(majorVersion, minorVersion);
                }

                if (raw != null && raw.Length > 0)
                {
                    int  offset = 0;
                    byte type   = raw[offset];
                    while (offset + 4 < raw.Length && type != 127)
                    {
                        // each iteration finds the structure inforamtion which are seperated by two zero bytes

                        // first byte in structure is the type of information
                        type = raw[offset];
                        // second byte in structure is the length of the structure header
                        int    length = raw[offset + 1];
                        ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);

                        if (offset + length > raw.Length)
                        {
                            break;
                        }
                        // data is the structure header not the actual values
                        byte[] data = new byte[length];
                        Array.Copy(raw, offset, data, 0, length);
                        // moves offset to the start of the structure values
                        offset += length;

                        // moves over all the zeros after the structure header
                        List <string> stringsList = new List <string>();
                        if (offset < raw.Length && raw[offset] == 0)
                        {
                            offset++;
                        }

                        // Convert bytes to strings seperated by one zero byte, puts them in 'stringsList'
                        // Structure ends at two successive zero bytes
                        while (offset < raw.Length && raw[offset] != 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            while (offset < raw.Length && raw[offset] != 0)
                            {
                                sb.Append((char)raw[offset]); offset++;
                            }
                            offset++;
                            stringsList.Add(sb.ToString());
                        }
                        offset++;
                        switch (type)
                        {
                        case 0x00:
                            this.biosInformation = new BIOSInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.biosInformation); break;

                        case 0x01:
                            this.systemInformation = new SystemInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.systemInformation); break;

                        case 0x02: this.baseBoardInformation = new BaseBoardInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.baseBoardInformation); break;

                        case 0x04: this.processorInformation = new ProcessorInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.processorInformation); break;

                        case 0x07: //CPU Internal
                            //LCachenum = (data[5] ^ 0x80) + 1 //LCacheNum = data[16] - 3 //LCacheNum = (data[16] ^ 0x04) + 1
                            //LCacheSize = data[8] << 8 //LCacheSize = data[10] << 8
                            //LCacheAssociativity = 0
                            //switch (data[18]) {
                            //case 5: LCacheAssociativity = 4; break;
                            //case 7: LCacheAssociativity = 8; break;
                            //case 9: LCacheAssociativity = 12; break;
                            //}
                            break;

                        case 0x11: MemoryDevice m = new MemoryDevice(
                                type, handle, data, stringsList.ToArray());
                            memoryDeviceList.Add(m);
                            structureList.Add(m); break;

                        default: structureList.Add(new Structure(
                                                       type, handle, data, stringsList.ToArray())); break;
                            // type 8 = peripherals
                        }
                    }
                }

                memoryDevices = memoryDeviceList.ToArray();
                table         = structureList.ToArray();
            }
        }
        public SMBIOSGroup()
        {
            int p = (int)System.Environment.OSVersion.Platform;

            if ((p == 4) || (p == 128))
            {
                return;
            }

            List <Structure> structureList = new List <Structure>();

            try {
                ManagementObjectCollection collection = new ManagementObjectSearcher(
                    "root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();

                byte[] raw = null;
                foreach (ManagementObject mo in collection)
                {
                    raw = (byte[])mo["SMBiosData"];
                    break;
                }

                if (raw != null && raw.Length > 0)
                {
                    int  offset = 0;
                    byte type   = raw[offset];
                    while (offset < raw.Length && type != 127)
                    {
                        type = raw[offset]; offset++;
                        int    length = raw[offset]; offset++;
                        ushort handle = (ushort)((raw[offset] << 8) | raw[offset + 1]);
                        offset += 2;

                        byte[] data = new byte[length];
                        Array.Copy(raw, offset - 4, data, 0, length); offset += length - 4;

                        List <string> stringsList = new List <string>();
                        if (raw[offset] == 0)
                        {
                            offset++;
                        }
                        while (raw[offset] != 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            while (raw[offset] != 0)
                            {
                                sb.Append((char)raw[offset]); offset++;
                            }
                            offset++;
                            stringsList.Add(sb.ToString());
                        }
                        offset++;
                        switch (type)
                        {
                        case 0x00:
                            this.biosInformation = new BIOSInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.biosInformation); break;

                        case 0x02: this.baseBoardInformation = new BaseBoardInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(this.baseBoardInformation); break;

                        default: structureList.Add(new Structure(
                                                       type, handle, data, stringsList.ToArray())); break;
                        }
                    }
                }
            } catch (NotImplementedException) { } catch (ManagementException) { }

            table = structureList.ToArray();
        }
Example #5
0
        public Smbios()
        {
            var structureList    = new List <Structure>();
            var memoryDeviceList = new List <MemoryDevice>();

            _raw = null;
            byte majorVersion = 0;
            byte minorVersion = 0;

            try
            {
                foreach (var mo in SmBiosRawSmBiosTables.Retrieve())
                {
                    _raw         = mo.SmBiosData;
                    majorVersion = mo.SmbiosMajorVersion;
                    minorVersion = mo.SmbiosMinorVersion;
                    break;
                }
            }
            catch
            {
            }

            if (majorVersion > 0 || minorVersion > 0)
            {
                Version = new Version(majorVersion, minorVersion);
            }

            if (_raw != null && _raw.Length > 0)
            {
                var offset = 0;
                var type   = _raw[offset];
                while (offset + 4 < _raw.Length && type != 127)
                {
                    type = _raw[offset];
                    int length = _raw[offset + 1];
                    var handle = (ushort)((_raw[offset + 2] << 8) | _raw[offset + 3]);

                    if (offset + length > _raw.Length)
                    {
                        break;
                    }
                    var data = new byte[length];
                    Array.Copy(_raw, offset, data, 0, length);
                    offset += length;

                    var stringsList = new List <string>();
                    if (offset < _raw.Length && _raw[offset] == 0)
                    {
                        offset++;
                    }

                    while (offset < _raw.Length && _raw[offset] != 0)
                    {
                        var sb = new StringBuilder();
                        while (offset < _raw.Length && _raw[offset] != 0)
                        {
                            sb.Append((char)_raw[offset]);
                            offset++;
                        }

                        offset++;
                        stringsList.Add(sb.ToString());
                    }

                    offset++;
                    switch (type)
                    {
                    case 0x00:
                        Bios = new BiosInformation(type, handle, data, stringsList.ToArray());
                        structureList.Add(Bios);
                        break;

                    case 0x01:
                        System = new SystemInformation(type, handle, data, stringsList.ToArray());
                        structureList.Add(System);
                        break;

                    case 0x02:
                        Board = new BaseBoardInformation(type, handle, data, stringsList.ToArray());
                        structureList.Add(Board);
                        break;

                    case 0x04:
                        Processor = new ProcessorInformation(type, handle, data, stringsList.ToArray());
                        structureList.Add(Processor);
                        break;

                    case 0x11:
                        var m = new MemoryDevice(type, handle, data, stringsList.ToArray());
                        memoryDeviceList.Add(m);
                        structureList.Add(m);
                        break;

                    default:
                        structureList.Add(new Structure(type, handle, data, stringsList.ToArray()));
                        break;
                    }
                }
            }

            MemoryDevices = memoryDeviceList.ToArray();
            Table         = structureList.ToArray();
        }
Example #6
0
        public Smbios()
        {
            if (OperatingSystem.IsLinux)
            {
                raw   = null;
                table = null;

                var boardVendor  = ReadSysFS("/sys/class/dmi/id/board_vendor");
                var boardName    = ReadSysFS("/sys/class/dmi/id/board_name");
                var boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
                Board = new BaseBoardInformation(
                    boardVendor, boardName, boardVersion, null);

                var systemVendor   = ReadSysFS("/sys/class/dmi/id/sys_vendor");
                var productName    = ReadSysFS("/sys/class/dmi/id/product_name");
                var productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
                System = new SystemInformation(systemVendor,
                                               productName, productVersion, null, null);

                var biosVendor  = ReadSysFS("/sys/class/dmi/id/bios_vendor");
                var biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
                BIOS = new BIOSInformation(biosVendor, biosVersion);

                MemoryDevices = new MemoryDevice[0];
            }
            else
            {
                var structureList    = new List <Structure>();
                var memoryDeviceList = new List <MemoryDevice>();

                raw = null;
                byte majorVersion = 0;
                byte minorVersion = 0;
                try
                {
                    ManagementObjectCollection collection;
                    using (var searcher =
                               new ManagementObjectSearcher("root\\WMI",
                                                            "SELECT * FROM MSSMBios_RawSMBiosTables"))
                    {
                        collection = searcher.Get();
                    }

                    foreach (ManagementObject mo in collection)
                    {
                        raw          = (byte[])mo["SMBiosData"];
                        majorVersion = (byte)mo["SmbiosMajorVersion"];
                        minorVersion = (byte)mo["SmbiosMinorVersion"];
                        break;
                    }
                }
                catch
                {
                }

                if (majorVersion > 0 || minorVersion > 0)
                {
                    version = new Version(majorVersion, minorVersion);
                }

                if (raw != null && raw.Length > 0)
                {
                    var offset = 0;
                    var type   = raw[offset];
                    while (offset + 4 < raw.Length && type != 127)
                    {
                        type = raw[offset];
                        int length = raw[offset + 1];
                        var handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);

                        if (offset + length > raw.Length)
                        {
                            break;
                        }
                        var data = new byte[length];
                        Array.Copy(raw, offset, data, 0, length);
                        offset += length;

                        var stringsList = new List <string>();
                        if (offset < raw.Length && raw[offset] == 0)
                        {
                            offset++;
                        }

                        while (offset < raw.Length && raw[offset] != 0)
                        {
                            var sb = new StringBuilder();
                            while (offset < raw.Length && raw[offset] != 0)
                            {
                                sb.Append((char)raw[offset]);
                                offset++;
                            }

                            offset++;
                            stringsList.Add(sb.ToString());
                        }

                        offset++;
                        switch (type)
                        {
                        case 0x00:
                            BIOS = new BIOSInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(BIOS);
                            break;

                        case 0x01:
                            System = new SystemInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(System);
                            break;

                        case 0x02:
                            Board = new BaseBoardInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(Board);
                            break;

                        case 0x04:
                            Processor = new ProcessorInformation(
                                type, handle, data, stringsList.ToArray());
                            structureList.Add(Processor);
                            break;

                        case 0x11:
                            var m = new MemoryDevice(
                                type, handle, data, stringsList.ToArray());
                            memoryDeviceList.Add(m);
                            structureList.Add(m);
                            break;

                        default:
                            structureList.Add(new Structure(
                                                  type, handle, data, stringsList.ToArray()));
                            break;
                        }
                    }
                }

                MemoryDevices = memoryDeviceList.ToArray();
                table         = structureList.ToArray();
            }
        }