From 7e5765f37d426681b643bd7b9248b24305d0a7e7 Mon Sep 17 00:00:00 2001 From: iadgovuser29 <33426478+iadgovuser29@users.noreply.github.com> Date: Sun, 12 Jan 2025 18:11:35 -0500 Subject: [PATCH] yml 17 --- .../Smbios/src/Smbios.cs | 30 ++++++++++--------- .../SmbiosCli/src/Program.cs | 1 - 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/dotnet/ComponentClassRegistry/Smbios/src/Smbios.cs b/dotnet/ComponentClassRegistry/Smbios/src/Smbios.cs index a8dacc1..c28222e 100644 --- a/dotnet/ComponentClassRegistry/Smbios/src/Smbios.cs +++ b/dotnet/ComponentClassRegistry/Smbios/src/Smbios.cs @@ -103,8 +103,7 @@ public static Dictionary<int, IList<SmbiosTable>> ParseSmbiosData(byte[] smbiosD return structs; } - int pos = 0; - List<string> strings = new(); + int pos = 0; // start pos at 0 // Change pos if entry point information is included. if (smbiosData.Length > 4 && Encoding.ASCII.GetString(smbiosData[0..4]).Equals("_SM_")) { @@ -114,14 +113,18 @@ public static Dictionary<int, IList<SmbiosTable>> ParseSmbiosData(byte[] smbiosD pos = 0x18; } - while (pos < smbiosData.Length) { + while (pos+1 < smbiosData.Length) { int structureStart = pos; int structureLength = smbiosData[structureStart + 1]; - int structureEnd = structureStart + structureLength; - pos = structureEnd; + pos += structureLength; + int structureEnd = pos - 1; // Parse through strings section - while (smbiosData[pos] != 0) { + if (pos < smbiosData.Length && smbiosData[pos] == 0) { // no strings section + pos++; + } + List<string> strings = new(); + while (pos < smbiosData.Length && smbiosData[pos] != 0) { string newString = ""; while (smbiosData[pos] != 0) { @@ -131,20 +134,19 @@ public static Dictionary<int, IList<SmbiosTable>> ParseSmbiosData(byte[] smbiosD strings.Add(newString); pos++; } + pos++; // Save table to dictionary - SmbiosTable table = new(smbiosData[structureStart..structureEnd], strings.ToArray()); + byte[] tableData = smbiosData[structureStart..(structureEnd+1)]; // this range is open-ended + string[] tableStrings = [.. strings]; + SmbiosTable table = new(tableData, tableStrings); if (!structs.ContainsKey(table.Type)) { - structs.Add(table.Type, new List<SmbiosTable>()); + structs.Add(table.Type, []); } structs[table.Type].Add(table); - // new structure - strings = new List<string>(); - pos++; - - if (smbiosData[pos] == 0) { - pos++; + if (table.Type == 127) { // End-of-Table Structure + break; } } diff --git a/dotnet/ComponentClassRegistry/SmbiosCli/src/Program.cs b/dotnet/ComponentClassRegistry/SmbiosCli/src/Program.cs index 3a7a1a7..5b56c64 100644 --- a/dotnet/ComponentClassRegistry/SmbiosCli/src/Program.cs +++ b/dotnet/ComponentClassRegistry/SmbiosCli/src/Program.cs @@ -1,6 +1,5 @@ using CliLib; using Smbios; -using System.Reflection; using System.Runtime.InteropServices; namespace SmbiosCli;