Skip to content

Commit

Permalink
yml 17
Browse files Browse the repository at this point in the history
  • Loading branch information
iadgovuser29 committed Jan 12, 2025
1 parent 12cfabf commit 7e5765f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
30 changes: 16 additions & 14 deletions dotnet/ComponentClassRegistry/Smbios/src/Smbios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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_")) {
Expand All @@ -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) {
Expand All @@ -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;
}
}

Expand Down
1 change: 0 additions & 1 deletion dotnet/ComponentClassRegistry/SmbiosCli/src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CliLib;
using Smbios;
using System.Reflection;
using System.Runtime.InteropServices;

namespace SmbiosCli;
Expand Down

0 comments on commit 7e5765f

Please sign in to comment.