|
5 | 5 |
|
6 | 6 | const char* ffDetectBios(FFBiosResult* bios) |
7 | 7 | { |
8 | | - io_registry_entry_t registryEntry; |
9 | | - |
10 | 8 | #ifndef __aarch64__ |
11 | 9 |
|
12 | 10 | //https://github.com/osquery/osquery/blob/master/osquery/tables/system/darwin/smbios_tables.cpp |
13 | 11 | //For Intel |
14 | | - if((registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/rom"))) |
15 | | - { |
16 | | - CFMutableDictionaryRef properties; |
17 | | - if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) |
18 | | - { |
19 | | - IOObjectRelease(registryEntry); |
20 | | - return "IORegistryEntryCreateCFProperties(registryEntry) failed"; |
21 | | - } |
| 12 | + FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t deviceRom = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/rom"); |
| 13 | + if (!deviceRom) |
| 14 | + return "IODeviceTree:/rom not found"; |
22 | 15 |
|
23 | | - ffCfDictGetString(properties, CFSTR("vendor"), &bios->vendor); |
24 | | - ffCfDictGetString(properties, CFSTR("version"), &bios->version); |
25 | | - ffCfDictGetString(properties, CFSTR("release-date"), &bios->date); |
26 | | - ffStrbufSetStatic(&bios->type, "UEFI"); |
| 16 | + FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef deviceRomProps = NULL; |
| 17 | + if(IORegistryEntryCreateCFProperties(deviceRom, &deviceRomProps, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) |
| 18 | + return "IORegistryEntryCreateCFProperties(deviceRom) failed"; |
27 | 19 |
|
28 | | - CFRelease(properties); |
29 | | - IOObjectRelease(registryEntry); |
30 | | - return NULL; |
31 | | - } |
| 20 | + ffCfDictGetString(deviceRomProps, CFSTR("vendor"), &bios->vendor); |
| 21 | + ffCfDictGetString(deviceRomProps, CFSTR("version"), &bios->version); |
| 22 | + ffCfDictGetString(deviceRomProps, CFSTR("release-date"), &bios->date); |
| 23 | + ffStrbufSetStatic(&bios->type, "UEFI"); |
32 | 24 |
|
33 | 25 | #else |
34 | 26 |
|
35 | 27 | //For arm64 |
36 | | - if((registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/"))) |
37 | | - { |
38 | | - CFMutableDictionaryRef properties; |
39 | | - if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) == kIOReturnSuccess) |
40 | | - { |
41 | | - ffCfDictGetString(properties, CFSTR("manufacturer"), &bios->vendor); |
42 | | - ffCfDictGetString(properties, CFSTR("time-stamp"), &bios->date); |
43 | | - CFRelease(properties); |
44 | | - } |
45 | | - IOObjectRelease(registryEntry); |
46 | | - } |
| 28 | + FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t device = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/"); |
| 29 | + if (!device) |
| 30 | + return "IODeviceTree:/ not found"; |
| 31 | + |
| 32 | + FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef deviceProps = NULL; |
| 33 | + if(IORegistryEntryCreateCFProperties(device, &deviceProps, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) |
| 34 | + return "IORegistryEntryCreateCFProperties(device) failed"; |
| 35 | + |
| 36 | + ffCfDictGetString(deviceProps, CFSTR("manufacturer"), &bios->vendor); |
| 37 | + ffCfDictGetString(deviceProps, CFSTR("time-stamp"), &bios->date); |
47 | 38 |
|
48 | | - if((registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen"))) |
| 39 | + FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t deviceChosen = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen"); |
| 40 | + if (deviceChosen) |
49 | 41 | { |
50 | | - CFMutableDictionaryRef properties; |
51 | | - if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) == kIOReturnSuccess) |
| 42 | + FF_CFTYPE_AUTO_RELEASE CFStringRef systemFirmWareVersion = IORegistryEntryCreateCFProperty(deviceChosen, CFSTR("system-firmware-version"), kCFAllocatorDefault, kNilOptions); |
| 43 | + if (systemFirmWareVersion) |
52 | 44 | { |
53 | | - ffCfDictGetString(properties, CFSTR("system-firmware-version"), &bios->version); |
| 45 | + ffCfStrGetString(systemFirmWareVersion, &bios->version); |
54 | 46 | uint32_t index = ffStrbufFirstIndexC(&bios->version, '-'); |
55 | 47 | if (index != bios->version.length) |
56 | 48 | { |
57 | 49 | ffStrbufAppendNS(&bios->type, index, bios->version.chars); |
58 | 50 | ffStrbufRemoveSubstr(&bios->version, 0, index + 1); |
59 | 51 | } |
60 | | - else |
61 | | - { |
62 | | - ffStrbufSetStatic(&bios->type, "iBoot"); |
63 | | - } |
64 | | - CFRelease(properties); |
65 | 52 | } |
66 | | - IOObjectRelease(registryEntry); |
67 | | - return NULL; |
68 | 53 | } |
69 | | - |
| 54 | + if (!bios->type.length) |
| 55 | + ffStrbufSetStatic(&bios->type, "iBoot"); |
70 | 56 | #endif |
71 | 57 |
|
72 | | - return "Failed to query bios info"; |
| 58 | + return NULL; |
73 | 59 | } |
0 commit comments