summaryrefslogtreecommitdiffstats
path: root/src/detection/host/host_apple.c
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/host/host_apple.c
Add the files
Diffstat (limited to 'src/detection/host/host_apple.c')
-rw-r--r--src/detection/host/host_apple.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/detection/host/host_apple.c b/src/detection/host/host_apple.c
new file mode 100644
index 0000000..a177bf4
--- /dev/null
+++ b/src/detection/host/host_apple.c
@@ -0,0 +1,68 @@
+#include "host.h"
+#include "common/sysctl.h"
+#include "common/apple/cf_helpers.h"
+
+#include <IOKit/IOKitLib.h>
+
+const char* getProductNameWithIokit(FFstrbuf* result) {
+ FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/product");
+ if (!registryEntry) {
+ return "IOServiceGetMatchingService() failed";
+ }
+
+ FF_CFTYPE_AUTO_RELEASE CFStringRef productName = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("product-name"), kCFAllocatorDefault, kNilOptions);
+ if (!productName) {
+ return "IORegistryEntryCreateCFProperty() failed";
+ }
+
+ return ffCfStrGetString(productName, result);
+}
+
+const char* getOthersByIokit(FFHostResult* host) {
+ FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("IOPlatformExpertDevice"));
+ if (!registryEntry) {
+ return "IOServiceGetMatchingService() failed";
+ }
+
+ FF_CFTYPE_AUTO_RELEASE CFStringRef serialNumber = IORegistryEntryCreateCFProperty(registryEntry, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, kNilOptions);
+ if (serialNumber) {
+ ffCfStrGetString(serialNumber, &host->serial);
+ }
+
+ FF_CFTYPE_AUTO_RELEASE CFStringRef uuid = IORegistryEntryCreateCFProperty(registryEntry, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, kNilOptions);
+ if (uuid) {
+ ffCfStrGetString(uuid, &host->uuid);
+ }
+
+ FF_CFTYPE_AUTO_RELEASE CFStringRef manufacturer = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("manufacturer"), kCFAllocatorDefault, kNilOptions);
+ if (manufacturer) {
+ ffCfStrGetString(manufacturer, &host->vendor);
+ }
+
+ FF_CFTYPE_AUTO_RELEASE CFStringRef version = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("version"), kCFAllocatorDefault, kNilOptions);
+ if (version) {
+ ffCfStrGetString(version, &host->version);
+ }
+
+ return NULL;
+}
+
+const char* ffDetectHost(FFHostResult* host) {
+ const char* error = ffSysctlGetString("hw.product", &host->family);
+ if (error) {
+ error = ffSysctlGetString("hw.model", &host->family);
+ }
+ if (error) {
+ return error;
+ }
+
+ ffStrbufSetStatic(&host->name, ffHostGetMacProductNameWithHwModel(&host->family));
+ if (host->name.length == 0) {
+ getProductNameWithIokit(&host->name);
+ }
+ if (host->name.length == 0) {
+ ffStrbufSet(&host->name, &host->family);
+ }
+ getOthersByIokit(host);
+ return NULL;
+}