master ohmu/fastfetch-openbsd / src / detection / bios / bios_apple.c
ohmu  ·  2026-10-15
 1#include "bios.h"
 2#include "common/apple/cf_helpers.h"
 3#include "common/debug.h"
 4
 5#include <IOKit/IOKitLib.h>
 6
 7const char* ffDetectBios(FFBiosResult* bios) {
 8#ifndef __aarch64__
 9
10    // https://github.com/osquery/osquery/blob/master/osquery/tables/system/darwin/smbios_tables.cpp
11    // For Intel
12    FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t deviceRom = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/rom");
13    if (!deviceRom) {
14        FF_DEBUG("IODeviceTree:/rom not found");
15        return "IODeviceTree:/rom not found";
16    }
17
18    FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef deviceRomProps = nullptr;
19    if (IORegistryEntryCreateCFProperties(deviceRom, &deviceRomProps, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) {
20        FF_DEBUG("IORegistryEntryCreateCFProperties(deviceRom) failed");
21        return "IORegistryEntryCreateCFProperties(deviceRom) failed";
22    }
23
24    ffCfDictGetString(deviceRomProps, CFSTR("vendor"), &bios->vendor);
25    ffCfDictGetString(deviceRomProps, CFSTR("version"), &bios->version);
26    ffCfDictGetString(deviceRomProps, CFSTR("release-date"), &bios->date);
27    ffStrbufSetStatic(&bios->type, "UEFI");
28
29#else
30
31    // For arm64
32    FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t device = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/");
33    if (!device) {
34        FF_DEBUG("IODeviceTree:/ not found");
35        return "IODeviceTree:/ not found";
36    }
37
38    FF_CFTYPE_AUTO_RELEASE CFDataRef manufacturer = IORegistryEntryCreateCFProperty(device, CFSTR("manufacturer"), kCFAllocatorDefault, kNilOptions);
39    ffCfStrGetString(manufacturer, &bios->vendor);
40    FF_CFTYPE_AUTO_RELEASE CFDataRef timeStamp = IORegistryEntryCreateCFProperty(device, CFSTR("time-stamp"), kCFAllocatorDefault, kNilOptions);
41    ffCfStrGetString(timeStamp, &bios->date);
42
43    FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t deviceChosen = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen");
44    if (deviceChosen) {
45        FF_CFTYPE_AUTO_RELEASE CFStringRef tag = IORegistryEntryCreateCFProperty(deviceChosen, CFSTR("iboot-stage-one-tag"), kCFAllocatorDefault, kNilOptions)
46            ?: IORegistryEntryCreateCFProperty(deviceChosen, CFSTR("system-firmware-version"), kCFAllocatorDefault, kNilOptions);
47        if (tag) {
48            ffCfStrGetString(tag, &bios->version);
49            uint32_t index = ffStrbufFirstIndexC(&bios->version, '-');
50            if (index != bios->version.length) {
51                ffStrbufAppendNS(&bios->type, index, bios->version.chars);
52                ffStrbufRemoveSubstr(&bios->version, 0, index + 1);
53            }
54        }
55    }
56    if (!bios->type.length) {
57        ffStrbufSetStatic(&bios->type, "iBoot");
58    }
59#endif
60
61    return nullptr;
62}