Skip to content

Commit

Permalink
Host: detect mac model in FreeBSD & Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Dec 9, 2024
1 parent d897472 commit 5c01685
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/detection/host/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 0 additions & 2 deletions src/detection/host/host_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/detection/host/host_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
14 changes: 2 additions & 12 deletions src/detection/host/host_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include <stdlib.h>

const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel);

static void getHostProductName(FFstrbuf* name)
{
if (ffReadFileBuffer("/sys/firmware/devicetree/base/model", name))
Expand Down Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion src/detection/host/host_mac.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "util/FFstrbuf.h"
#include "host.h"
#include "util/stringUtils.h"

const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel)
Expand Down Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions src/detection/host/host_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@ const char* ffDetectHost(FFHostResult* host)
ffCleanUpSmbiosValue(&host->family);
}

#ifdef __x86_64__
ffHostDetectMac(host);
#endif

return NULL;
}

0 comments on commit 5c01685

Please sign in to comment.