1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Hardware/SMBIOS/SMBIOSGroup.cs Tue Jan 26 22:37:48 2010 +0000
1.3 @@ -0,0 +1,198 @@
1.4 +/*
1.5 +
1.6 + Version: MPL 1.1/GPL 2.0/LGPL 2.1
1.7 +
1.8 + The contents of this file are subject to the Mozilla Public License Version
1.9 + 1.1 (the "License"); you may not use this file except in compliance with
1.10 + the License. You may obtain a copy of the License at
1.11 +
1.12 + http://www.mozilla.org/MPL/
1.13 +
1.14 + Software distributed under the License is distributed on an "AS IS" basis,
1.15 + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1.16 + for the specific language governing rights and limitations under the License.
1.17 +
1.18 + The Original Code is the Open Hardware Monitor code.
1.19 +
1.20 + The Initial Developer of the Original Code is
1.21 + Michael Möller <m.moeller@gmx.ch>.
1.22 + Portions created by the Initial Developer are Copyright (C) 2009-2010
1.23 + the Initial Developer. All Rights Reserved.
1.24 +
1.25 + Contributor(s):
1.26 +
1.27 + Alternatively, the contents of this file may be used under the terms of
1.28 + either the GNU General Public License Version 2 or later (the "GPL"), or
1.29 + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
1.30 + in which case the provisions of the GPL or the LGPL are applicable instead
1.31 + of those above. If you wish to allow use of your version of this file only
1.32 + under the terms of either the GPL or the LGPL, and not to allow others to
1.33 + use your version of this file under the terms of the MPL, indicate your
1.34 + decision by deleting the provisions above and replace them with the notice
1.35 + and other provisions required by the GPL or the LGPL. If you do not delete
1.36 + the provisions above, a recipient may use your version of this file under
1.37 + the terms of any one of the MPL, the GPL or the LGPL.
1.38 +
1.39 +*/
1.40 +
1.41 +using System;
1.42 +using System.Collections.Generic;
1.43 +using System.Management;
1.44 +using System.Text;
1.45 +
1.46 +namespace OpenHardwareMonitor.Hardware.SMBIOS {
1.47 +
1.48 + public class SMBIOSGroup : IGroup {
1.49 +
1.50 + private Structure[] table;
1.51 +
1.52 + private BIOSInformation biosInformation = null;
1.53 +
1.54 + private BaseBoardInformation baseBoardInformation = null;
1.55 +
1.56 + public SMBIOSGroup() {
1.57 + int p = (int)System.Environment.OSVersion.Platform;
1.58 + if ((p == 4) || (p == 128))
1.59 + return;
1.60 +
1.61 + ManagementObjectCollection collection = new ManagementObjectSearcher(
1.62 + "root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
1.63 +
1.64 + byte[] raw = null;
1.65 + foreach (ManagementObject mo in collection) {
1.66 + raw = (byte[])mo["SMBiosData"];
1.67 + break;
1.68 + }
1.69 +
1.70 + List<Structure> structureList = new List<Structure>();
1.71 + if (raw != null && raw.Length > 0) {
1.72 + int offset = 0;
1.73 + byte type = raw[offset];
1.74 + while (offset < raw.Length && type != 127) {
1.75 +
1.76 + type = raw[offset]; offset++;
1.77 + int length = raw[offset]; offset++;
1.78 + ushort handle = (ushort)((raw[offset] << 8) | raw[offset + 1]);
1.79 + offset += 2;
1.80 +
1.81 + byte[] data = new byte[length];
1.82 + Array.Copy(raw, offset - 4, data, 0, length); offset += length - 4;
1.83 +
1.84 + List<string> stringsList = new List<string>();
1.85 + if (raw[offset] == 0)
1.86 + offset++;
1.87 + while (raw[offset] != 0) {
1.88 + StringBuilder sb = new StringBuilder();
1.89 + while (raw[offset] != 0) {
1.90 + sb.Append((char)raw[offset]); offset++;
1.91 + }
1.92 + offset++;
1.93 + stringsList.Add(sb.ToString());
1.94 + }
1.95 + offset++;
1.96 + switch (type) {
1.97 + case 0x00:
1.98 + this.biosInformation = new BIOSInformation(
1.99 + type, handle, data, stringsList.ToArray());
1.100 + structureList.Add(this.biosInformation); break;
1.101 + case 0x02: this.baseBoardInformation = new BaseBoardInformation(
1.102 + type, handle, data, stringsList.ToArray());
1.103 + structureList.Add(this.baseBoardInformation); break;
1.104 + default: structureList.Add(new Structure(
1.105 + type, handle, data, stringsList.ToArray())); break;
1.106 + }
1.107 + }
1.108 + }
1.109 + table = structureList.ToArray();
1.110 + }
1.111 +
1.112 + public IHardware[] Hardware { get { return new IHardware[0]; } }
1.113 +
1.114 + public string GetReport() {
1.115 + StringBuilder r = new StringBuilder();
1.116 +
1.117 + r.AppendLine("SMBIOS");
1.118 + r.AppendLine();
1.119 +
1.120 + if (biosInformation != null) {
1.121 + r.Append("BIOS Vendor: "); r.AppendLine(biosInformation.Vendor);
1.122 + r.Append("BIOS Version: "); r.AppendLine(biosInformation.Version);
1.123 + r.AppendLine();
1.124 + }
1.125 +
1.126 + if (baseBoardInformation != null) {
1.127 + r.Append("Mainboard Manufacturer: ");
1.128 + r.AppendLine(baseBoardInformation.Manufacturer);
1.129 + r.Append("Mainboard Name: ");
1.130 + r.AppendLine(baseBoardInformation.ProductName);
1.131 + r.AppendLine();
1.132 + }
1.133 +
1.134 + return r.ToString();
1.135 + }
1.136 +
1.137 + public void Close() { }
1.138 +
1.139 + public class Structure {
1.140 + private byte type;
1.141 + private ushort handle;
1.142 +
1.143 + private byte[] data;
1.144 + private string[] strings;
1.145 +
1.146 + public Structure(byte type, ushort handle, byte[] data, string[] strings)
1.147 + {
1.148 + this.type = type;
1.149 + this.handle = handle;
1.150 + this.data = data;
1.151 + this.strings = strings;
1.152 + }
1.153 +
1.154 + public byte Type { get { return type; } }
1.155 +
1.156 + public ushort Handle { get { return handle; } }
1.157 + }
1.158 +
1.159 + public class BIOSInformation : Structure {
1.160 +
1.161 + private string vendor = "";
1.162 + private string version = "";
1.163 +
1.164 + public BIOSInformation(byte type, ushort handle, byte[] data,
1.165 + string[] strings)
1.166 + : base(type, handle, data, strings) {
1.167 +
1.168 + if (data[0x04] > 0 && data[0x04] <= strings.Length)
1.169 + vendor = strings[data[0x04] - 1];
1.170 +
1.171 + if (data[0x05] > 0 && data[0x05] <= strings.Length)
1.172 + version = strings[data[0x05] - 1];
1.173 + }
1.174 +
1.175 + public string Vendor { get { return vendor; } }
1.176 +
1.177 + public string Version { get { return version; } }
1.178 + }
1.179 +
1.180 + public class BaseBoardInformation : Structure {
1.181 +
1.182 + private string manufacturer = "";
1.183 + private string productName = "";
1.184 +
1.185 + public BaseBoardInformation(byte type, ushort handle, byte[] data,
1.186 + string[] strings)
1.187 + : base(type, handle, data, strings) {
1.188 +
1.189 + if (data[0x04] > 0 && data[0x04] <= strings.Length)
1.190 + manufacturer = strings[data[0x04] - 1];
1.191 +
1.192 + if (data[0x05] > 0 && data[0x05] <= strings.Length)
1.193 + productName = strings[data[0x05] - 1];
1.194 + }
1.195 +
1.196 + public string Manufacturer { get { return manufacturer; } }
1.197 +
1.198 + public string ProductName { get { return productName; } }
1.199 + }
1.200 + }
1.201 +}