From cb0a64e90c89e03cbeeda4e9d32ca0be24d49887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Fri, 29 Jan 2010 20:05:32 +0000 Subject: [PATCH] Added additional checks to SMBIOS parsing. New class HexStringArray is for debugging with report data. --- Hardware/LPC/{F71882FG.cs => F71882.cs} | 6 +-- Hardware/LPC/LPCGroup.cs | 2 +- Hardware/SMBIOS/SMBIOSGroup.cs | 30 +++++++------ OpenHardwareMonitor.csproj | 3 +- Utilities/HexStringArray.cs | 60 +++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 19 deletions(-) rename Hardware/LPC/{F71882FG.cs => F71882.cs} (95%) create mode 100644 Utilities/HexStringArray.cs diff --git a/Hardware/LPC/F71882FG.cs b/Hardware/LPC/F71882.cs similarity index 95% rename from Hardware/LPC/F71882FG.cs rename to Hardware/LPC/F71882.cs index 2eb4851..e9ee7c9 100644 --- a/Hardware/LPC/F71882FG.cs +++ b/Hardware/LPC/F71882.cs @@ -41,7 +41,7 @@ using System.Drawing; using System.Text; namespace OpenHardwareMonitor.Hardware.LPC { - public class F71882FG : IHardware { + public class F71882 : IHardware { private string name; private Image icon; @@ -70,10 +70,10 @@ namespace OpenHardwareMonitor.Hardware.LPC { return WinRing0.ReadIoPortByte((ushort)(address + DATA_REGISTER_OFFSET)); } - public F71882FG(ushort address) { + public F71882(ushort address) { this.address = address; - this.name = "Fintek F71882FG"; + this.name = "Fintek F71882"; temperatures = new Sensor[3]; for (int i = 0; i < temperatures.Length; i++) diff --git a/Hardware/LPC/LPCGroup.cs b/Hardware/LPC/LPCGroup.cs index 3ecabcd..457d107 100644 --- a/Hardware/LPC/LPCGroup.cs +++ b/Hardware/LPC/LPCGroup.cs @@ -176,7 +176,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { break; case Chip.F71882FG: if (vendorID == FINTEK_VENDOR_ID) - hardware.Add(new F71882FG(address)); + hardware.Add(new F71882(address)); break; default: break; } diff --git a/Hardware/SMBIOS/SMBIOSGroup.cs b/Hardware/SMBIOS/SMBIOSGroup.cs index 4f2420a..de1ea5f 100644 --- a/Hardware/SMBIOS/SMBIOSGroup.cs +++ b/Hardware/SMBIOS/SMBIOSGroup.cs @@ -144,6 +144,14 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS { private byte[] data; private string[] strings; + protected string GetString(int offset) { + if (offset < data.Length && data[offset] > 0 && + data[offset] <= strings.Length) + return strings[data[offset] - 1]; + else + return ""; + } + public Structure(byte type, ushort handle, byte[] data, string[] strings) { this.type = type; @@ -159,18 +167,15 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS { public class BIOSInformation : Structure { - private string vendor = ""; - private string version = ""; + private string vendor; + private string version; public BIOSInformation(byte type, ushort handle, byte[] data, string[] strings) : base(type, handle, data, strings) { - if (data[0x04] > 0 && data[0x04] <= strings.Length) - vendor = strings[data[0x04] - 1]; - - if (data[0x05] > 0 && data[0x05] <= strings.Length) - version = strings[data[0x05] - 1]; + this.vendor = GetString(0x04); + this.version = GetString(0x05); } public string Vendor { get { return vendor; } } @@ -180,18 +185,15 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS { public class BaseBoardInformation : Structure { - private string manufacturer = ""; - private string productName = ""; + private string manufacturer; + private string productName; public BaseBoardInformation(byte type, ushort handle, byte[] data, string[] strings) : base(type, handle, data, strings) { - if (data[0x04] > 0 && data[0x04] <= strings.Length) - manufacturer = strings[data[0x04] - 1]; - - if (data[0x05] > 0 && data[0x05] <= strings.Length) - productName = strings[data[0x05] - 1]; + this.manufacturer = GetString(0x04); + this.productName = GetString(0x05); } public string Manufacturer { get { return manufacturer; } } diff --git a/OpenHardwareMonitor.csproj b/OpenHardwareMonitor.csproj index 0a191d4..d3b582a 100644 --- a/OpenHardwareMonitor.csproj +++ b/OpenHardwareMonitor.csproj @@ -62,7 +62,7 @@ - + @@ -94,6 +94,7 @@ + UserControl diff --git a/Utilities/HexStringArray.cs b/Utilities/HexStringArray.cs new file mode 100644 index 0000000..eef4a26 --- /dev/null +++ b/Utilities/HexStringArray.cs @@ -0,0 +1,60 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenHardwareMonitor.Utilities { + public class HexStringArray { + + private byte[] array; + + public HexStringArray(string input) { + List list = new List(); + foreach (string str in input.Split(' ')) { + if (str.Trim().Length > 0) + list.Add(Convert.ToByte(str, 16)); + } + array = list.ToArray(); + } + + public byte this[int i] { + get { return array[i]; } + } + } +}