From 56403bab5c893808f844e7797664afde90a447ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 13 May 2024 20:29:46 +0800 Subject: [PATCH] PhysicalMemory: try converting vendor ID to name --- CMakeLists.txt | 1 + src/detection/physicalmemory/physicalmemory.c | 42 +++++++++++++++++++ src/detection/physicalmemory/physicalmemory.h | 2 + .../physicalmemory/physicalmemory_apple.m | 2 +- .../physicalmemory/physicalmemory_linux.c | 2 +- 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/detection/physicalmemory/physicalmemory.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c75c6270..b68db9bda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,6 +297,7 @@ set(LIBFASTFETCH_SRC src/detection/opencl/opencl.c src/detection/os/os.c src/detection/packages/packages.c + src/detection/physicalmemory/physicalmemory.c src/detection/publicip/publicip.c src/detection/terminaltheme/terminaltheme.c src/detection/terminalfont/terminalfont.c diff --git a/src/detection/physicalmemory/physicalmemory.c b/src/detection/physicalmemory/physicalmemory.c new file mode 100644 index 000000000..f8137c7be --- /dev/null +++ b/src/detection/physicalmemory/physicalmemory.c @@ -0,0 +1,42 @@ +#include "physicalmemory.h" + +static inline const char* getVendorString(unsigned vendorId) +{ + switch (vendorId) + { + case 0x017A: return "Apacer"; + case 0x0198: return "HyperX"; + case 0x029E: return "Corsair"; + case 0x04CB: return "A-DATA"; + case 0x04CD: return "G-Skill"; + case 0x059B: case 0x859B: case 0x1315: return "Crucial"; + case 0x00CE: case 0x80CE: case 0xCE00: return "Samsung"; + case 0x014F: return "Transcend"; + case 0x2C00: case 0x802C: return "Micron"; + case 0xAD00: case 0x80AD: return "Hynix"; + case 0x5105: case 0x8551: return "Qimonda"; + case 0x02FE: return "Elpida"; + default: return NULL; + } +} + +void FFPhysicalMemoryUpdateVendorString(FFPhysicalMemoryResult* device) +{ + char vendorIdStr[5]; + if (ffStrbufStartsWithS(&device->vendor, "0x")) + { + if (device->vendor.length < 6) return; + memcpy(vendorIdStr, device->vendor.chars + 2, 4); + } + else + { + if (device->vendor.length < 4) return; + memcpy(vendorIdStr, device->vendor.chars, 4); + } + vendorIdStr[4] = '\0'; + char* pEnd = NULL; + uint32_t vendorId = (uint32_t) strtoul(vendorIdStr, &pEnd, 16); + if (*pEnd != '\0') return; + const char* vendorStr = getVendorString(vendorId); + if (vendorStr) ffStrbufSetStatic(&device->vendor, vendorStr); +} diff --git a/src/detection/physicalmemory/physicalmemory.h b/src/detection/physicalmemory/physicalmemory.h index 4d7465eba..2580295ca 100644 --- a/src/detection/physicalmemory/physicalmemory.h +++ b/src/detection/physicalmemory/physicalmemory.h @@ -17,3 +17,5 @@ typedef struct FFPhysicalMemoryResult } FFPhysicalMemoryResult; const char* ffDetectPhysicalMemory(FFlist* result); // list of FFPhysicalMemoryResult + +void FFPhysicalMemoryUpdateVendorString(FFPhysicalMemoryResult* device); diff --git a/src/detection/physicalmemory/physicalmemory_apple.m b/src/detection/physicalmemory/physicalmemory_apple.m index a965ee906..243b35aca 100644 --- a/src/detection/physicalmemory/physicalmemory_apple.m +++ b/src/detection/physicalmemory/physicalmemory_apple.m @@ -23,7 +23,7 @@ static void appendDevice( ffStrbufInit(&device->formFactor); ffStrbufInitS(&device->locator, locator.UTF8String); ffStrbufInitS(&device->vendor, vendor.UTF8String); - ffCleanUpSmbiosValue(&device->vendor); + FFPhysicalMemoryUpdateVendorString(device); ffStrbufInitS(&device->serial, serial.UTF8String); ffCleanUpSmbiosValue(&device->serial); ffStrbufInitS(&device->partNumber, partNumber.UTF8String); diff --git a/src/detection/physicalmemory/physicalmemory_linux.c b/src/detection/physicalmemory/physicalmemory_linux.c index 824464311..a773d3d93 100644 --- a/src/detection/physicalmemory/physicalmemory_linux.c +++ b/src/detection/physicalmemory/physicalmemory_linux.c @@ -183,7 +183,7 @@ const char* ffDetectPhysicalMemory(FFlist* result) device->maxSpeed = data->Speed == 0xFFFF ? data->ExtendedSpeed : data->Speed; ffStrbufSetStatic(&device->vendor, ffSmbiosLocateString(strings, data->Manufacturer)); - ffCleanUpSmbiosValue(&device->vendor); + FFPhysicalMemoryUpdateVendorString(device); ffStrbufSetStatic(&device->serial, ffSmbiosLocateString(strings, data->SerialNumber)); ffCleanUpSmbiosValue(&device->serial);