1.1 --- a/Hardware/SMBIOS/SMBIOSGroup.cs Sat Feb 27 15:55:17 2010 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,204 +0,0 @@
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 - List<Structure> structureList = new List<Structure>();
1.62 -
1.63 - try {
1.64 - ManagementObjectCollection collection = new ManagementObjectSearcher(
1.65 - "root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
1.66 -
1.67 - byte[] raw = null;
1.68 - foreach (ManagementObject mo in collection) {
1.69 - raw = (byte[])mo["SMBiosData"];
1.70 - break;
1.71 - }
1.72 -
1.73 - if (raw != null && raw.Length > 0) {
1.74 - int offset = 0;
1.75 - byte type = raw[offset];
1.76 - while (offset < raw.Length && type != 127) {
1.77 -
1.78 - type = raw[offset]; offset++;
1.79 - int length = raw[offset]; offset++;
1.80 - ushort handle = (ushort)((raw[offset] << 8) | raw[offset + 1]);
1.81 - offset += 2;
1.82 -
1.83 - byte[] data = new byte[length];
1.84 - Array.Copy(raw, offset - 4, data, 0, length); offset += length - 4;
1.85 -
1.86 - List<string> stringsList = new List<string>();
1.87 - if (raw[offset] == 0)
1.88 - offset++;
1.89 - while (raw[offset] != 0) {
1.90 - StringBuilder sb = new StringBuilder();
1.91 - while (raw[offset] != 0) {
1.92 - sb.Append((char)raw[offset]); offset++;
1.93 - }
1.94 - offset++;
1.95 - stringsList.Add(sb.ToString());
1.96 - }
1.97 - offset++;
1.98 - switch (type) {
1.99 - case 0x00:
1.100 - this.biosInformation = new BIOSInformation(
1.101 - type, handle, data, stringsList.ToArray());
1.102 - structureList.Add(this.biosInformation); break;
1.103 - case 0x02: this.baseBoardInformation = new BaseBoardInformation(
1.104 - type, handle, data, stringsList.ToArray());
1.105 - structureList.Add(this.baseBoardInformation); break;
1.106 - default: structureList.Add(new Structure(
1.107 - type, handle, data, stringsList.ToArray())); break;
1.108 - }
1.109 - }
1.110 - }
1.111 - } catch (NotImplementedException) { } catch (ManagementException) { }
1.112 -
1.113 - table = structureList.ToArray();
1.114 - }
1.115 -
1.116 - public IHardware[] Hardware { get { return new IHardware[0]; } }
1.117 -
1.118 - public string GetReport() {
1.119 - StringBuilder r = new StringBuilder();
1.120 -
1.121 - r.AppendLine("SMBIOS");
1.122 - r.AppendLine();
1.123 -
1.124 - if (biosInformation != null) {
1.125 - r.Append("BIOS Vendor: "); r.AppendLine(biosInformation.Vendor);
1.126 - r.Append("BIOS Version: "); r.AppendLine(biosInformation.Version);
1.127 - r.AppendLine();
1.128 - }
1.129 -
1.130 - if (baseBoardInformation != null) {
1.131 - r.Append("Mainboard Manufacturer: ");
1.132 - r.AppendLine(baseBoardInformation.Manufacturer);
1.133 - r.Append("Mainboard Name: ");
1.134 - r.AppendLine(baseBoardInformation.ProductName);
1.135 - r.AppendLine();
1.136 - }
1.137 -
1.138 - return r.ToString();
1.139 - }
1.140 -
1.141 - public void Close() { }
1.142 -
1.143 - public class Structure {
1.144 - private byte type;
1.145 - private ushort handle;
1.146 -
1.147 - private byte[] data;
1.148 - private string[] strings;
1.149 -
1.150 - protected string GetString(int offset) {
1.151 - if (offset < data.Length && data[offset] > 0 &&
1.152 - data[offset] <= strings.Length)
1.153 - return strings[data[offset] - 1];
1.154 - else
1.155 - return "";
1.156 - }
1.157 -
1.158 - public Structure(byte type, ushort handle, byte[] data, string[] strings)
1.159 - {
1.160 - this.type = type;
1.161 - this.handle = handle;
1.162 - this.data = data;
1.163 - this.strings = strings;
1.164 - }
1.165 -
1.166 - public byte Type { get { return type; } }
1.167 -
1.168 - public ushort Handle { get { return handle; } }
1.169 - }
1.170 -
1.171 - public class BIOSInformation : Structure {
1.172 -
1.173 - private string vendor;
1.174 - private string version;
1.175 -
1.176 - public BIOSInformation(byte type, ushort handle, byte[] data,
1.177 - string[] strings)
1.178 - : base(type, handle, data, strings) {
1.179 -
1.180 - this.vendor = GetString(0x04);
1.181 - this.version = GetString(0x05);
1.182 - }
1.183 -
1.184 - public string Vendor { get { return vendor; } }
1.185 -
1.186 - public string Version { get { return version; } }
1.187 - }
1.188 -
1.189 - public class BaseBoardInformation : Structure {
1.190 -
1.191 - private string manufacturer;
1.192 - private string productName;
1.193 -
1.194 - public BaseBoardInformation(byte type, ushort handle, byte[] data,
1.195 - string[] strings)
1.196 - : base(type, handle, data, strings) {
1.197 -
1.198 - this.manufacturer = GetString(0x04);
1.199 - this.productName = GetString(0x05);
1.200 - }
1.201 -
1.202 - public string Manufacturer { get { return manufacturer; } }
1.203 -
1.204 - public string ProductName { get { return productName; } }
1.205 - }
1.206 - }
1.207 -}