-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
/* | ||
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved. | ||
* | ||
* This file is part of System Informer. | ||
* | ||
* Authors: | ||
* | ||
* jxy-s 2025 | ||
* | ||
*/ | ||
|
||
#include <ph.h> | ||
|
||
#include <phfirmware.h> | ||
#include <ntintsafe.h> | ||
|
||
typedef struct _PH_SMBIOS_STRINGREF | ||
{ | ||
UCHAR Length; | ||
PSTR Buffer; | ||
} PH_SMBIOS_STRINGREF, *PPH_SMBIOS_STRINGREF; | ||
|
||
typedef struct _PH_SMBIOS_PARSE_CONTEXT | ||
{ | ||
PRAW_SMBIOS_DATA Data; | ||
PVOID End; | ||
PH_SMBIOS_STRINGREF Strings[256]; | ||
} PH_SMBIOS_PARSE_CONTEXT, *PPH_SMBIOS_PARSE_CONTEXT; | ||
|
||
NTSTATUS PhpParseSMBIOS( | ||
_In_ PPH_SMBIOS_PARSE_CONTEXT Context, | ||
_In_ PSMBIOS_HEADER Current, | ||
_Out_ PSMBIOS_HEADER* Next | ||
) | ||
{ | ||
NTSTATUS status; | ||
PSTR pointer; | ||
PSTR string; | ||
UCHAR nulls; | ||
UCHAR length; | ||
UCHAR count; | ||
|
||
*Next = NULL; | ||
|
||
memset(Context->Strings, 0, sizeof(Context->Strings)); | ||
|
||
pointer = SMBIOS_STRING_TABLE(Current); | ||
string = pointer; | ||
|
||
if ((ULONG_PTR)pointer >= (ULONG_PTR)Context->End) | ||
return STATUS_BUFFER_OVERFLOW; | ||
|
||
nulls = 0; | ||
length = 0; | ||
count = 0; | ||
|
||
while ((ULONG_PTR)pointer < (ULONG_PTR)Context->End) | ||
{ | ||
if (*pointer++ != ANSI_NULL) | ||
{ | ||
if (!NT_SUCCESS(status = RtlUInt8Add(length, 1, &length))) | ||
return status; | ||
|
||
nulls = 0; | ||
continue; | ||
} | ||
|
||
if (nulls++) | ||
break; | ||
|
||
Context->Strings[count].Length = length; | ||
Context->Strings[count].Buffer = string; | ||
|
||
count++; | ||
string = pointer; | ||
length = 0; | ||
} | ||
|
||
if (nulls != 2) | ||
return STATUS_INVALID_ADDRESS; | ||
|
||
if (Current->Type != SMBIOS_END_OF_TABLE_TYPE) | ||
*Next = (PSMBIOS_HEADER)pointer; | ||
|
||
return STATUS_SUCCESS; | ||
} | ||
|
||
NTSTATUS PhpEnumSMBIOS( | ||
_In_ PRAW_SMBIOS_DATA Data, | ||
_In_ PPH_ENUM_SMBIOS_CALLBACK Callback, | ||
_In_opt_ PVOID Context | ||
) | ||
{ | ||
NTSTATUS status; | ||
PH_SMBIOS_PARSE_CONTEXT context; | ||
PSMBIOS_HEADER current; | ||
PSMBIOS_HEADER next; | ||
|
||
memset(&context, 0, sizeof(context)); | ||
|
||
context.Data = Data; | ||
context.End = PTR_ADD_OFFSET(Data->SMBIOSTableData, Data->Length); | ||
|
||
current = (PSMBIOS_HEADER)Data->SMBIOSTableData; | ||
next = NULL; | ||
|
||
while (NT_SUCCESS(status = PhpParseSMBIOS(&context, current, &next))) | ||
{ | ||
if (Callback( | ||
(ULONG_PTR)&context, | ||
Data->SMBIOSMajorVersion, | ||
Data->SMBIOSMinorVersion, | ||
(PPH_SMBIOS_ENTRY)current, | ||
Context | ||
)) | ||
break; | ||
|
||
if (!next) | ||
break; | ||
|
||
current = next; | ||
} | ||
|
||
return status; | ||
} | ||
|
||
NTSTATUS PhEnumSMBIOS( | ||
_In_ PPH_ENUM_SMBIOS_CALLBACK Callback, | ||
_In_opt_ PVOID Context | ||
) | ||
{ | ||
NTSTATUS status; | ||
ULONG length; | ||
PSYSTEM_FIRMWARE_TABLE_INFORMATION info; | ||
|
||
length = 1024; | ||
info = PhAllocateZero(length); | ||
|
||
info->ProviderSignature = 'RSMB'; | ||
info->TableID = 0; | ||
info->Action = SystemFirmwareTableGet; | ||
info->TableBufferLength = length - sizeof(SYSTEM_FIRMWARE_TABLE_INFORMATION); | ||
|
||
status = NtQuerySystemInformation( | ||
SystemFirmwareTableInformation, | ||
info, | ||
length, | ||
&length | ||
); | ||
if (status == STATUS_BUFFER_TOO_SMALL) | ||
{ | ||
PhFree(info); | ||
info = PhAllocateZero(length); | ||
|
||
info->ProviderSignature = 'RSMB'; | ||
info->TableID = 0; | ||
info->Action = SystemFirmwareTableGet; | ||
info->TableBufferLength = length - sizeof(SYSTEM_FIRMWARE_TABLE_INFORMATION); | ||
|
||
status = NtQuerySystemInformation( | ||
SystemFirmwareTableInformation, | ||
info, | ||
length, | ||
&length | ||
); | ||
} | ||
|
||
if (NT_SUCCESS(status)) | ||
{ | ||
status = PhpEnumSMBIOS( | ||
(PRAW_SMBIOS_DATA)info->TableBuffer, | ||
Callback, | ||
Context | ||
); | ||
} | ||
|
||
PhFree(info); | ||
|
||
return status; | ||
} | ||
|
||
NTSTATUS PhGetSMBIOSString( | ||
_In_ ULONG_PTR EnumHandle, | ||
_In_ UCHAR Index, | ||
_Out_ PPH_STRING* String | ||
) | ||
{ | ||
PPH_SMBIOS_PARSE_CONTEXT context; | ||
PPH_SMBIOS_STRINGREF string; | ||
|
||
context = (PPH_SMBIOS_PARSE_CONTEXT)EnumHandle; | ||
|
||
*String = NULL; | ||
|
||
if (Index == SMBIOS_INVALID_STRING) | ||
return STATUS_INVALID_PARAMETER; | ||
|
||
string = &context->Strings[Index - 1]; | ||
if (!string->Buffer) | ||
return STATUS_INVALID_PARAMETER; | ||
|
||
*String = PhConvertUtf8ToUtf16Ex(string->Buffer, string->Length); | ||
|
||
return STATUS_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved. | ||
* | ||
* This file is part of System Informer. | ||
* | ||
* Authors: | ||
* | ||
* jxy-s 2025 | ||
* | ||
*/ | ||
|
||
#ifndef _PH_PHSMBIOS_H | ||
#define _PH_PHSMBIOS_H | ||
|
||
#include <smbios.h> | ||
|
||
EXTERN_C_START | ||
|
||
typedef union _PH_SMBIOS_ENTRY | ||
{ | ||
SMBIOS_HEADER Header; | ||
SMBIOS_FIRMWARE_INFORMATION Firmware; | ||
SMBIOS_SYSTEM_INFORMATION System; | ||
SMBIOS_BASEBOARD_INFORMATION Baseboard; | ||
SMBIOS_CHASSIS_INFORMATION Chassis; | ||
SMBIOS_PROCESSOR_INFORMATION Processor; | ||
SMBIOS_MEMORY_CONTROLLER_INFORMATION MemoryController; | ||
SMBIOS_MEMORY_MODULE_INFORMATION MemoryModule; | ||
SMBIOS_CACHE_INFORMATION Cache; | ||
SMBIOS_PORT_CONNECTOR_INFORMATION PortConnector; | ||
SMBIOS_SYSTEM_SLOT_INFORMATION SystemSlot; | ||
SMBIOS_ON_BOARD_DEVICE_INFORMATION OnBoardDevice; | ||
SMBIOS_OEM_STRING_INFORMATION OEMString; | ||
SMBIOS_FIRMWARE_LANGUAGE_INFORMATION FirmwareLanguage; | ||
SMBIOS_GROUP_ASSOCIATION_INFORMATION GroupAssociation; | ||
SMBIOS_SYSTEM_EVENT_LOG_INFORMATION EventLog; | ||
SMBIOS_PHYSICAL_MEMORY_ARRAY_INFORMATION PhysicalMemoryArray; | ||
SMBIOS_MEMORY_DEVICE_INFORMATION MemoryDevice; | ||
SMBIOS_32_BIT_MEMORY_ERROR_INFORMATION MemoryError32; | ||
SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS_INFORMATION MemoryArrayMappedAddress; | ||
SMBIOS_MEMORY_DEVICE_MAPPED_DATA_INFORMATION MemoryDeviceMappedData; | ||
SMBIOS_BUILT_IN_POINTING_DEVICE_INFORMATION BuiltInPointingDevice; | ||
SMBIOS_PORTABLE_BATTERY_INFORMATION PortableBattery; | ||
SMBIOS_SYSTEM_RESET_INFORMATION SystemReset; | ||
SMBIOS_HARDWARE_SECURITY_INFORMATION HardwareSecurity; | ||
SMBIOS_SYSTEM_POWER_CONTROLS_INFORMATION SystemPowerControls; | ||
SMBIOS_VOLTAGE_PROBE_INFORMATION VoltageProbe; | ||
SMBIOS_COOLING_DEVICE_INFORMATION CoolingDevice; | ||
SMBIOS_TEMPERATURE_PROBE_INFORMATION TemperatureProbe; | ||
SMBIOS_ELECTRICAL_CURRENT_PROBE_INFORMATION ElectricalCurrentProbe; | ||
SMBIOS_OUT_OF_BAND_REMOTE_ACCESS_INFORMATION OutOfBandRemoteAccess; | ||
SMBIOS_SYSTEM_BOOT_INFORMATION SystemBoot; | ||
SMBIOS_64_BIT_MEMORY_ERROR_INFORMATION MemoryError64; | ||
SMBIOS_MANAGEMENT_DEVICE_INFORMATION ManagementDevice; | ||
SMBIOS_MANAGEMENT_DEVICE_COMPONENT_INFORMATION ManagementDeviceComponent; | ||
SMBIOS_MANAGEMENT_DEVICE_THRESHOLD_INFORMATION ManagementDeviceThreshold; | ||
SMBIOS_MEMORY_CHANNEL_INFORMATION MemoryChannel; | ||
SMBIOS_IPMI_DEVICE_INFORMATION IPMIDevice; | ||
SMBIOS_SYSTEM_POWER_SUPPLY_INFORMATION SystemPowerSupply; | ||
SMBIOS_ADDITIONAL_INFORMATION AdditionalInformation; | ||
SMBIOS_ONBOARD_DEVICE_INFORMATION OnboardDevice; | ||
SMBIOS_MCHI_INFORMATION MCHInterface; | ||
SMBIOS_TPM_DEVICE_INFORMATION TPMDevice; | ||
SMBIOS_PROCESSOR_ADDITIONAL_INFORMATION ProcessorAdditional; | ||
SMBIOS_FIRMWARE_INVENTORY_INFORMATION FirmwareInventory; | ||
SMBIOS_STRING_PROPERTY StringProperty; | ||
SMBIOS_INACTIVE Inactive; | ||
SMBIOS_END_OF_TABLE EndOfTable; | ||
} PH_SMBIOS_ENTRY, *PPH_SMBIOS_ENTRY; | ||
|
||
typedef | ||
_Function_class_(PH_ENUM_SMBIOS_CALLBACK) | ||
BOOLEAN | ||
NTAPI | ||
PH_ENUM_SMBIOS_CALLBACK( | ||
_In_ ULONG_PTR EnumHandle, | ||
_In_ UCHAR MajorVersion, | ||
_In_ UCHAR MinorVersion, | ||
_In_ PPH_SMBIOS_ENTRY Entry, | ||
_In_opt_ PVOID Context | ||
); | ||
typedef PH_ENUM_SMBIOS_CALLBACK* PPH_ENUM_SMBIOS_CALLBACK; | ||
|
||
PHLIBAPI | ||
NTSTATUS | ||
NTAPI | ||
PhEnumSMBIOS( | ||
_In_ PPH_ENUM_SMBIOS_CALLBACK Callback, | ||
_In_opt_ PVOID Context | ||
); | ||
|
||
PHLIBAPI | ||
NTSTATUS | ||
NTAPI | ||
PhGetSMBIOSString( | ||
_In_ ULONG_PTR EnumHandle, | ||
_In_ UCHAR Index, | ||
_Out_ PPH_STRING* String | ||
); | ||
|
||
EXTERN_C_END | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters