|
| 1 | +#include "bios.h" |
| 2 | +#include "util/apple/cf_helpers.h" |
| 3 | + |
| 4 | +#include <IOKit/IOKitLib.h> |
| 5 | + |
| 6 | +void ffDetectBios(FFBiosResult* bios) |
| 7 | +{ |
| 8 | + ffStrbufInit(&bios->error); |
| 9 | + ffStrbufInit(&bios->biosDate); |
| 10 | + ffStrbufInit(&bios->biosRelease); |
| 11 | + ffStrbufInit(&bios->biosVendor); |
| 12 | + ffStrbufInit(&bios->biosVersion); |
| 13 | + |
| 14 | + io_registry_entry_t registryEntry; |
| 15 | + |
| 16 | + #ifndef __aarch64__ |
| 17 | + |
| 18 | + //https://github.com/osquery/osquery/blob/master/osquery/tables/system/darwin/smbios_tables.cpp |
| 19 | + //For Intel |
| 20 | + if((registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/rom"))) |
| 21 | + { |
| 22 | + CFMutableDictionaryRef properties; |
| 23 | + if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) |
| 24 | + { |
| 25 | + IOObjectRelease(registryEntry); |
| 26 | + ffStrbufAppendS(&bios->error, "IORegistryEntryCreateCFProperties(registryEntry) failed"); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + ffCfDictGetString(properties, CFSTR("vendor"), &bios->biosVendor); |
| 31 | + ffCfDictGetString(properties, CFSTR("version"), &bios->biosVersion); |
| 32 | + ffCfDictGetString(properties, CFSTR("release-date"), &bios->biosDate); |
| 33 | + if(!ffStrbufContainC(&bios->biosDate, '-')) |
| 34 | + ffStrbufAppendS(&bios->biosRelease, "Efi-"); |
| 35 | + ffStrbufAppend(&bios->biosRelease, &bios->biosVersion); |
| 36 | + |
| 37 | + CFRelease(properties); |
| 38 | + IOObjectRelease(registryEntry); |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + #else |
| 43 | + |
| 44 | + //For arm64 |
| 45 | + if((registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/"))) |
| 46 | + { |
| 47 | + CFMutableDictionaryRef properties; |
| 48 | + if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) == kIOReturnSuccess) |
| 49 | + { |
| 50 | + ffCfDictGetString(properties, CFSTR("manufacturer"), &bios->biosVendor); |
| 51 | + CFRelease(properties); |
| 52 | + } |
| 53 | + IOObjectRelease(registryEntry); |
| 54 | + } |
| 55 | + |
| 56 | + if((registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen"))) |
| 57 | + { |
| 58 | + CFMutableDictionaryRef properties; |
| 59 | + if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) == kIOReturnSuccess) |
| 60 | + { |
| 61 | + ffCfDictGetString(properties, CFSTR("system-firmware-version"), &bios->biosRelease); |
| 62 | + ffStrbufAppend(&bios->biosVersion, &bios->biosRelease); |
| 63 | + ffStrbufSubstrAfterFirstC(&bios->biosVersion, '-'); |
| 64 | + CFRelease(properties); |
| 65 | + } |
| 66 | + IOObjectRelease(registryEntry); |
| 67 | + } |
| 68 | + |
| 69 | + #endif |
| 70 | +} |
0 commit comments