From 0801e22dce0f51abf0a368e92d649b2bd64602d1 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 29 Dec 2022 01:24:34 +0800 Subject: [PATCH] Bios: support macOS --- CHANGELOG.md | 1 + CMakeLists.txt | 2 +- src/detection/bios/bios_apple.c | 70 +++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/detection/bios/bios_apple.c diff --git a/CHANGELOG.md b/CHANGELOG.md index e77568852..6d6c7a710 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Features: * Supports GPU detection on Android * Supports Kitty Terminal terminal font * Supports bar output for percentage values +* Supports Bios module on macOS * Supports eopkg package manager detection * Supports iTerm image logo protocol * Supports image logo printing on macOS diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f65fca70..4d654b9d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -420,7 +420,7 @@ elseif(APPLE) src/common/processing_linux.c src/common/sysctl.c src/detection/battery/battery_apple.c - src/detection/bios/bios_nosupport.c + src/detection/bios/bios_apple.c src/detection/board/board_nosupport.c src/detection/chassis/chassis_nosupport.c src/detection/cpu/cpu_apple.c diff --git a/src/detection/bios/bios_apple.c b/src/detection/bios/bios_apple.c new file mode 100644 index 000000000..9d7ff75cc --- /dev/null +++ b/src/detection/bios/bios_apple.c @@ -0,0 +1,70 @@ +#include "bios.h" +#include "util/apple/cf_helpers.h" + +#include + +void ffDetectBios(FFBiosResult* bios) +{ + ffStrbufInit(&bios->error); + ffStrbufInit(&bios->biosDate); + ffStrbufInit(&bios->biosRelease); + ffStrbufInit(&bios->biosVendor); + ffStrbufInit(&bios->biosVersion); + + io_registry_entry_t registryEntry; + + #ifndef __aarch64__ + + //https://github.com/osquery/osquery/blob/master/osquery/tables/system/darwin/smbios_tables.cpp + //For Intel + if((registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/rom"))) + { + CFMutableDictionaryRef properties; + if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) + { + IOObjectRelease(registryEntry); + ffStrbufAppendS(&bios->error, "IORegistryEntryCreateCFProperties(registryEntry) failed"); + return; + } + + ffCfDictGetString(properties, CFSTR("vendor"), &bios->biosVendor); + ffCfDictGetString(properties, CFSTR("version"), &bios->biosVersion); + ffCfDictGetString(properties, CFSTR("release-date"), &bios->biosDate); + if(!ffStrbufContainC(&bios->biosDate, '-')) + ffStrbufAppendS(&bios->biosRelease, "Efi-"); + ffStrbufAppend(&bios->biosRelease, &bios->biosVersion); + + CFRelease(properties); + IOObjectRelease(registryEntry); + return; + } + + #else + + //For arm64 + if((registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/"))) + { + CFMutableDictionaryRef properties; + if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) == kIOReturnSuccess) + { + ffCfDictGetString(properties, CFSTR("manufacturer"), &bios->biosVendor); + CFRelease(properties); + } + IOObjectRelease(registryEntry); + } + + if((registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen"))) + { + CFMutableDictionaryRef properties; + if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) == kIOReturnSuccess) + { + ffCfDictGetString(properties, CFSTR("system-firmware-version"), &bios->biosRelease); + ffStrbufAppend(&bios->biosVersion, &bios->biosRelease); + ffStrbufSubstrAfterFirstC(&bios->biosVersion, '-'); + CFRelease(properties); + } + IOObjectRelease(registryEntry); + } + + #endif +}