Fixed Issue 269.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
12 using System.Collections.Generic;
14 using System.Management;
17 namespace OpenHardwareMonitor.Hardware.Mainboard {
19 internal class SMBIOS {
21 private readonly byte[] raw;
22 private readonly Structure[] table;
24 private readonly Version version;
25 private readonly BIOSInformation biosInformation;
26 private readonly SystemInformation systemInformation;
27 private readonly BaseBoardInformation baseBoardInformation;
29 private static string ReadSysFS(string path) {
31 if (File.Exists(path)) {
32 using (StreamReader reader = new StreamReader(path))
33 return reader.ReadLine();
43 int p = (int)Environment.OSVersion.Platform;
44 if ((p == 4) || (p == 128)) {
48 string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor");
49 string boardName = ReadSysFS("/sys/class/dmi/id/board_name");
50 string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
51 this.baseBoardInformation = new BaseBoardInformation(
52 boardVendor, boardName, boardVersion, null);
54 string systemVendor = ReadSysFS("/sys/class/dmi/id/sys_vendor");
55 string productName = ReadSysFS("/sys/class/dmi/id/product_name");
56 string productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
57 this.systemInformation = new SystemInformation(systemVendor,
58 productName, productVersion, null, null);
60 string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor");
61 string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
62 this.biosInformation = new BIOSInformation(biosVendor, biosVersion);
65 List<Structure> structureList = new List<Structure>();
68 byte majorVersion = 0;
69 byte minorVersion = 0;
71 ManagementObjectCollection collection;
72 using (ManagementObjectSearcher searcher =
73 new ManagementObjectSearcher("root\\WMI",
74 "SELECT * FROM MSSMBios_RawSMBiosTables")) {
75 collection = searcher.Get();
78 foreach (ManagementObject mo in collection) {
79 raw = (byte[])mo["SMBiosData"];
80 majorVersion = (byte)mo["SmbiosMajorVersion"];
81 minorVersion = (byte)mo["SmbiosMinorVersion"];
86 if (majorVersion > 0 || minorVersion > 0)
87 version = new Version(majorVersion, minorVersion);
89 if (raw != null && raw.Length > 0) {
91 byte type = raw[offset];
92 while (offset + 4 < raw.Length && type != 127) {
95 int length = raw[offset + 1];
96 ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);
98 if (offset + length > raw.Length)
100 byte[] data = new byte[length];
101 Array.Copy(raw, offset, data, 0, length);
104 List<string> stringsList = new List<string>();
105 if (offset < raw.Length && raw[offset] == 0)
108 while (offset < raw.Length && raw[offset] != 0) {
109 StringBuilder sb = new StringBuilder();
110 while (offset < raw.Length && raw[offset] != 0) {
111 sb.Append((char)raw[offset]); offset++;
114 stringsList.Add(sb.ToString());
119 this.biosInformation = new BIOSInformation(
120 type, handle, data, stringsList.ToArray());
121 structureList.Add(this.biosInformation); break;
123 this.systemInformation = new SystemInformation(
124 type, handle, data, stringsList.ToArray());
125 structureList.Add(this.systemInformation); break;
126 case 0x02: this.baseBoardInformation = new BaseBoardInformation(
127 type, handle, data, stringsList.ToArray());
128 structureList.Add(this.baseBoardInformation); break;
129 default: structureList.Add(new Structure(
130 type, handle, data, stringsList.ToArray())); break;
135 table = structureList.ToArray();
139 public string GetReport() {
140 StringBuilder r = new StringBuilder();
142 if (version != null) {
143 r.Append("SMBIOS Version: "); r.AppendLine(version.ToString(2));
148 r.Append("BIOS Vendor: "); r.AppendLine(BIOS.Vendor);
149 r.Append("BIOS Version: "); r.AppendLine(BIOS.Version);
153 if (System != null) {
154 r.Append("System Manufacturer: ");
155 r.AppendLine(System.ManufacturerName);
156 r.Append("System Name: ");
157 r.AppendLine(System.ProductName);
158 r.Append("System Version: ");
159 r.AppendLine(System.Version);
164 r.Append("Mainboard Manufacturer: ");
165 r.AppendLine(Board.ManufacturerName);
166 r.Append("Mainboard Name: ");
167 r.AppendLine(Board.ProductName);
168 r.Append("Mainboard Version: ");
169 r.AppendLine(Board.Version);
174 string base64 = Convert.ToBase64String(raw);
175 r.AppendLine("SMBIOS Table");
178 for (int i = 0; i < Math.Ceiling(base64.Length / 64.0); i++) {
180 for (int j = 0; j < 0x40; j++) {
181 int index = (i << 6) | j;
182 if (index < base64.Length) {
183 r.Append(base64[index]);
194 public BIOSInformation BIOS {
195 get { return biosInformation; }
198 public SystemInformation System {
199 get { return systemInformation; }
202 public BaseBoardInformation Board {
203 get { return baseBoardInformation; }
206 public class Structure {
207 private readonly byte type;
208 private readonly ushort handle;
210 private readonly byte[] data;
211 private readonly string[] strings;
213 protected string GetString(int offset) {
214 if (offset < data.Length && data[offset] > 0 &&
215 data[offset] <= strings.Length)
216 return strings[data[offset] - 1];
221 public Structure(byte type, ushort handle, byte[] data, string[] strings)
224 this.handle = handle;
226 this.strings = strings;
229 public byte Type { get { return type; } }
231 public ushort Handle { get { return handle; } }
234 public class BIOSInformation : Structure {
236 private readonly string vendor;
237 private readonly string version;
239 public BIOSInformation(string vendor, string version)
240 : base (0x00, 0, null, null)
242 this.vendor = vendor;
243 this.version = version;
246 public BIOSInformation(byte type, ushort handle, byte[] data,
248 : base(type, handle, data, strings)
250 this.vendor = GetString(0x04);
251 this.version = GetString(0x05);
254 public string Vendor { get { return vendor; } }
256 public string Version { get { return version; } }
259 public class SystemInformation : Structure {
261 private readonly string manufacturerName;
262 private readonly string productName;
263 private readonly string version;
264 private readonly string serialNumber;
265 private readonly string family;
267 public SystemInformation(string manufacturerName, string productName,
268 string version, string serialNumber, string family)
269 : base (0x01, 0, null, null)
271 this.manufacturerName = manufacturerName;
272 this.productName = productName;
273 this.version = version;
274 this.serialNumber = serialNumber;
275 this.family = family;
278 public SystemInformation(byte type, ushort handle, byte[] data,
280 : base(type, handle, data, strings)
282 this.manufacturerName = GetString(0x04);
283 this.productName = GetString(0x05);
284 this.version = GetString(0x06);
285 this.serialNumber = GetString(0x07);
286 this.family = GetString(0x1A);
289 public string ManufacturerName { get { return manufacturerName; } }
291 public string ProductName { get { return productName; } }
293 public string Version { get { return version; } }
295 public string SerialNumber { get { return serialNumber; } }
297 public string Family { get { return family; } }
301 public class BaseBoardInformation : Structure {
303 private readonly string manufacturerName;
304 private readonly string productName;
305 private readonly string version;
306 private readonly string serialNumber;
307 private readonly Manufacturer manufacturer;
308 private readonly Model model;
310 private static Manufacturer GetManufacturer(string name) {
313 return Manufacturer.Alienware;
315 return Manufacturer.Apple;
317 return Manufacturer.ASRock;
318 case "ASUSTeK Computer INC.":
319 case "ASUSTeK COMPUTER INC.":
320 return Manufacturer.ASUS;
322 return Manufacturer.Dell;
325 return Manufacturer.DFI;
327 return Manufacturer.ECS;
328 case "EPoX COMPUTER CO., LTD":
329 return Manufacturer.EPoX;
331 return Manufacturer.EVGA;
332 case "First International Computer, Inc.":
333 return Manufacturer.FIC;
335 case "FUJITSU SIEMENS":
336 return Manufacturer.Fujitsu;
337 case "Gigabyte Technology Co., Ltd.":
338 return Manufacturer.Gigabyte;
339 case "Hewlett-Packard":
340 return Manufacturer.HP;
342 return Manufacturer.IBM;
345 case "Intel Corporation":
346 case "INTEL Corporation":
347 return Manufacturer.Intel;
350 return Manufacturer.Lenovo;
351 case "Micro-Star International":
352 case "MICRO-STAR INTERNATIONAL CO., LTD":
353 case "MICRO-STAR INTERNATIONAL CO.,LTD":
355 return Manufacturer.MSI;
357 return Manufacturer.Shuttle;
359 return Manufacturer.Supermicro;
361 return Manufacturer.Toshiba;
363 return Manufacturer.XFX;
364 case "To be filled by O.E.M.":
365 return Manufacturer.Unknown;
367 return Manufacturer.Unknown;
371 private static Model GetModel(string name) {
374 return Model._880GMH_USB3;
375 case "ASRock AOD790GX/128M":
376 return Model.AOD790GX_128M;
378 return Model.P55_Deluxe;
379 case "Crosshair III Formula":
380 return Model.Crosshair_III_Formula;
381 case "M2N-SLI DELUXE":
382 return Model.M2N_SLI_DELUXE;
384 return Model.M4A79XTD_EVO;
385 case "P5W DH Deluxe":
386 return Model.P5W_DH_Deluxe;
390 return Model.P6X58D_E;
394 return Model.P8P67_EVO;
396 return Model.P8P67_PRO;
398 return Model.P8P67_M_PRO;
400 return Model.P8Z77_V;
403 case "Rampage Extreme":
404 return Model.Rampage_Extreme;
405 case "Rampage II GENE":
406 return Model.Rampage_II_GENE;
407 case "LP BI P45-T2RS Elite":
408 return Model.LP_BI_P45_T2RS_Elite;
409 case "LP DK P55-T3eH9":
410 return Model.LP_DK_P55_T3eH9;
412 return Model.A890GXM_A;
413 case "X58 SLI Classified":
414 return Model.X58_SLI_Classified;
416 return Model._965P_S3;
418 return Model.EP45_DS3R;
420 return Model.EP45_UD3R;
422 return Model.EX58_EXTREME;
424 return Model.EX58_UD3R;
426 return Model.G41M_Combo;
428 return Model.G41MT_S2;
430 return Model.G41MT_S2P;
431 case "GA-MA770T-UD3":
432 return Model.GA_MA770T_UD3;
433 case "GA-MA770T-UD3P":
434 return Model.GA_MA770T_UD3P;
435 case "GA-MA785GM-US2H":
436 return Model.GA_MA785GM_US2H;
437 case "GA-MA785GMT-UD2H":
438 return Model.GA_MA785GMT_UD2H;
439 case "GA-MA78LM-S2H":
440 return Model.GA_MA78LM_S2H;
441 case "GA-MA790X-UD3P":
442 return Model.GA_MA790X_UD3P;
444 return Model.H55_USB3;
446 return Model.H55N_USB3;
447 case "H61M-DS2 REV 1.2":
448 return Model.H61M_DS2_REV_1_2;
449 case "H61M-USB3-B3 REV 2.0":
450 return Model.H61M_USB3_B3_REV_2_0;
452 return Model.H67A_UD3H_B3;
454 return Model.H67A_USB3_B3;
456 return Model.P35_DS3;
458 return Model.P35_DS3L;
460 return Model.P55_UD4;
462 return Model.P55A_UD3;
464 return Model.P55M_UD4;
466 return Model.P67A_UD3_B3;
468 return Model.P67A_UD3R_B3;
470 return Model.P67A_UD4_B3;
472 return Model.P8Z68_V_PRO;
474 return Model.X38_DS5;
476 return Model.X58A_UD3R;
478 return Model.Z68A_D3H_B3;
480 return Model.Z68AP_D3;
482 return Model.Z68X_UD3H_B3;
484 return Model.Z68X_UD7_B3;
487 case "Base Board Product Name":
488 case "To be filled by O.E.M.":
489 return Model.Unknown;
491 return Model.Unknown;
495 public BaseBoardInformation(string manufacturerName, string productName,
496 string version, string serialNumber)
497 : base(0x02, 0, null, null)
499 this.manufacturerName = manufacturerName;
500 this.manufacturer = GetManufacturer(manufacturerName);
501 this.productName = productName;
502 this.model = GetModel(productName);
503 this.version = version;
504 this.serialNumber = serialNumber;
507 public BaseBoardInformation(byte type, ushort handle, byte[] data,
509 : base(type, handle, data, strings) {
511 this.manufacturerName = GetString(0x04).Trim();
512 this.manufacturer = GetManufacturer(this.manufacturerName);
513 this.productName = GetString(0x05).Trim();
514 this.model = GetModel(this.productName);
515 this.version = GetString(0x06).Trim();
516 this.serialNumber = GetString(0x07).Trim();
519 public string ManufacturerName { get { return manufacturerName; } }
521 public string ProductName { get { return productName; } }
523 public string Version { get { return version; } }
525 public string SerialNumber { get { return serialNumber; } }
527 public Manufacturer Manufacturer { get { return manufacturer; } }
529 public Model Model { get { return model; } }