From 5c01685d69fb72d0ca348906077cc38c68b838a3 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 8 Dec 2024 23:23:51 +0800 Subject: [PATCH] Host: detect mac model in FreeBSD & Windows --- CMakeLists.txt | 2 ++ src/detection/host/host.h | 2 ++ src/detection/host/host_apple.c | 2 -- src/detection/host/host_bsd.c | 4 ++++ src/detection/host/host_linux.c | 14 ++------------ src/detection/host/host_mac.c | 20 +++++++++++++++++++- src/detection/host/host_windows.c | 4 ++++ 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac2067b99..f4b167c2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -650,6 +650,7 @@ elseif(FreeBSD) src/detection/gpu/gpu_pci.c src/detection/gtk_qt/gtk.c src/detection/host/host_bsd.c + src/detection/host/host_mac.c src/detection/lm/lm_linux.c src/detection/icons/icons_linux.c src/detection/initsystem/initsystem_linux.c @@ -951,6 +952,7 @@ elseif(WIN32) src/detection/dns/dns_windows.c src/detection/font/font_windows.c src/detection/gpu/gpu_windows.c + src/detection/host/host_mac.c src/detection/host/host_windows.c src/detection/icons/icons_windows.c src/detection/initsystem/initsystem_nosupport.c diff --git a/src/detection/host/host.h b/src/detection/host/host.h index 1b0c61187..e55a004e4 100644 --- a/src/detection/host/host.h +++ b/src/detection/host/host.h @@ -13,4 +13,6 @@ typedef struct FFHostResult FFstrbuf vendor; } FFHostResult; +const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel); +bool ffHostDetectMac(FFHostResult* host); const char* ffDetectHost(FFHostResult* host); diff --git a/src/detection/host/host_apple.c b/src/detection/host/host_apple.c index 84ea947b7..c83b09684 100644 --- a/src/detection/host/host_apple.c +++ b/src/detection/host/host_apple.c @@ -39,8 +39,6 @@ const char* getOthersByIokit(FFHostResult* host) return NULL; } -const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel); - const char* ffDetectHost(FFHostResult* host) { const char* error = ffSysctlGetString("hw.model", &host->family); diff --git a/src/detection/host/host_bsd.c b/src/detection/host/host_bsd.c index 334b04cab..5de12117e 100644 --- a/src/detection/host/host_bsd.c +++ b/src/detection/host/host_bsd.c @@ -19,5 +19,9 @@ const char* ffDetectHost(FFHostResult* host) ffSettingsGetFreeBSDKenv("smbios.system.maker", &host->vendor); ffCleanUpSmbiosValue(&host->vendor); + #ifdef __x86_64__ + ffHostDetectMac(host); + #endif + return NULL; } diff --git a/src/detection/host/host_linux.c b/src/detection/host/host_linux.c index 9c87abc1e..2ed4d71ad 100644 --- a/src/detection/host/host_linux.c +++ b/src/detection/host/host_linux.c @@ -5,8 +5,6 @@ #include -const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel); - static void getHostProductName(FFstrbuf* name) { if (ffReadFileBuffer("/sys/firmware/devicetree/base/model", name)) @@ -64,17 +62,9 @@ const char* ffDetectHost(FFHostResult* host) if (ffStrbufStartsWithS(&host->name, "Apple ")) ffStrbufSetStatic(&host->vendor, "Apple Inc."); } + #ifdef __x86_64__ - else if (ffStrbufEqualS(&host->family, "Mac") && ffStrbufEqualS(&host->vendor, "Apple Inc.")) - { - const char* productName = ffHostGetMacProductNameWithHwModel(&host->name); - if (productName) - { - ffStrbufDestroy(&host->family); - ffStrbufInitMove(&host->family, &host->name); - ffStrbufSetStatic(&host->name, productName); - } - } + ffHostDetectMac(host); #endif //KVM/Qemu virtual machine diff --git a/src/detection/host/host_mac.c b/src/detection/host/host_mac.c index ed299ae4b..c595dc9f0 100644 --- a/src/detection/host/host_mac.c +++ b/src/detection/host/host_mac.c @@ -1,4 +1,4 @@ -#include "util/FFstrbuf.h" +#include "host.h" #include "util/stringUtils.h" const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel) @@ -173,3 +173,21 @@ const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel) } return NULL; } + +bool ffHostDetectMac(FFHostResult* host) +{ + #ifdef __x86_64__ + if (ffStrbufEqualS(&host->family, "Mac") && ffStrbufEqualS(&host->vendor, "Apple Inc.")) + { + const char* productName = ffHostGetMacProductNameWithHwModel(&host->name); + if (productName) + { + ffStrbufDestroy(&host->family); + ffStrbufInitMove(&host->family, &host->name); + ffStrbufSetStatic(&host->name, productName); + return true; + } + } + #endif + return false; +} diff --git a/src/detection/host/host_windows.c b/src/detection/host/host_windows.c index c505d9071..c2a64066f 100644 --- a/src/detection/host/host_windows.c +++ b/src/detection/host/host_windows.c @@ -72,5 +72,9 @@ const char* ffDetectHost(FFHostResult* host) ffCleanUpSmbiosValue(&host->family); } + #ifdef __x86_64__ + ffHostDetectMac(host); + #endif + return NULL; }