mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 12:14:19 +01:00
Host / Chassis (Windows): parse SMBIOS data directly
This commit is contained in:
@@ -47,4 +47,22 @@ void ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf*
|
||||
|
||||
ffStrbufClear(buffer);
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
#include <windows.h>
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wmultichar"
|
||||
|
||||
const FFRawSmbiosData* ffGetSmbiosData()
|
||||
{
|
||||
static FFRawSmbiosData* buffer;
|
||||
if (!buffer)
|
||||
{
|
||||
const DWORD signature = 'RSMB';
|
||||
uint32_t bufSize = GetSystemFirmwareTable(signature, 0, NULL, 0);
|
||||
assert(bufSize > sizeof(FFRawSmbiosData));
|
||||
buffer = (FFRawSmbiosData*) malloc(bufSize);
|
||||
GetSystemFirmwareTable(signature, 0, buffer, bufSize);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,6 +14,66 @@ static inline void ffCleanUpSmbiosValue(FFstrbuf* value)
|
||||
|
||||
#ifdef __linux__
|
||||
void ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer);
|
||||
#elif defined(_WIN32)
|
||||
// https://github.com/KunYi/DumpSMBIOS
|
||||
// https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.7.0.pdf
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFSmbiosType // : uint8_t
|
||||
{
|
||||
FF_SMBIOS_TYPE_BIOS = 0,
|
||||
FF_SMBIOS_TYPE_SYSTEM_INFO = 1,
|
||||
FF_SMBIOS_TYPE_BASEBOARD_INFO = 2,
|
||||
FF_SMBIOS_TYPE_SYSTEM_ENCLOSURE = 3,
|
||||
FF_SMBIOS_TYPE_PROCESSOR_INFO = 4,
|
||||
FF_SMBIOS_TYPE_MEMORY_MODULE_INFO = 6,
|
||||
FF_SMBIOS_TYPE_CACHE_INFO = 7,
|
||||
FF_SMBIOS_TYPE_OEM_STRING = 11,
|
||||
FF_SMBIOS_TYPE_MEMORY_DEVICE = 17,
|
||||
FF_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS = 19,
|
||||
FF_SMBIOS_TYPE_BUILTIN_POINT_DEVICE = 21,
|
||||
FF_SMBIOS_TYPE_PORTABLE_BATTERY = 22,
|
||||
FF_SMBIOS_TYPE_LAST = 127,
|
||||
} FFSmbiosType;
|
||||
static_assert(sizeof(FFSmbiosType) == 1, "FFSmbiosType should be 1 byte");
|
||||
|
||||
typedef struct FFSmbiosHeader
|
||||
{
|
||||
FFSmbiosType Type;
|
||||
uint8_t Length;
|
||||
uint16_t Handle;
|
||||
uint8_t Data[];
|
||||
} FFSmbiosHeader;
|
||||
static_assert(sizeof(FFSmbiosHeader) == 4, "FFSmbiosHeader should be 4 bytes");
|
||||
|
||||
typedef struct FFRawSmbiosData
|
||||
{
|
||||
uint8_t Used20CallingMethod;
|
||||
uint8_t SMBIOSMajorVersion;
|
||||
uint8_t SMBIOSMinorVersion;
|
||||
uint8_t DmiRevision;
|
||||
uint32_t Length;
|
||||
uint8_t SMBIOSTableData[];
|
||||
} FFRawSmbiosData;
|
||||
|
||||
static inline const char* ffSmbiosLocateString(const char* start, uint8_t index /* start from 1 */)
|
||||
{
|
||||
if (index == 0 || *start == '\0')
|
||||
return NULL;
|
||||
while (--index)
|
||||
start += strlen(start) + 1;
|
||||
return start;
|
||||
}
|
||||
|
||||
static inline const FFSmbiosHeader* ffSmbiosSkipLastStr(const FFSmbiosHeader* header)
|
||||
{
|
||||
const char* p = ((const char*) header) + header->Length;
|
||||
while (*p)
|
||||
p += strlen(p) + 1;
|
||||
|
||||
return (const FFSmbiosHeader*) (p + 1);
|
||||
}
|
||||
|
||||
const FFRawSmbiosData* ffGetSmbiosData();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user