Files
fastfetch/src/detection/bios/bios_apple.c
T

58 lines
2.5 KiB
C
Raw Normal View History

2022-12-29 01:24:34 +08:00
#include "bios.h"
2026-01-06 09:48:38 +08:00
#include "common/apple/cf_helpers.h"
2022-12-29 01:24:34 +08:00
#include <IOKit/IOKitLib.h>
2026-03-29 09:28:49 +08:00
const char* ffDetectBios(FFBiosResult* bios) {
#ifndef __aarch64__
2022-12-29 01:24:34 +08:00
2026-03-29 09:28:49 +08:00
// https://github.com/osquery/osquery/blob/master/osquery/tables/system/darwin/smbios_tables.cpp
// For Intel
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t deviceRom = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/rom");
2026-03-29 09:28:49 +08:00
if (!deviceRom) {
return "IODeviceTree:/rom not found";
2026-03-29 09:28:49 +08:00
}
2022-12-29 01:24:34 +08:00
2026-07-10 18:08:04 +08:00
FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef deviceRomProps = nullptr;
2026-03-29 09:28:49 +08:00
if (IORegistryEntryCreateCFProperties(deviceRom, &deviceRomProps, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) {
return "IORegistryEntryCreateCFProperties(deviceRom) failed";
2026-03-29 09:28:49 +08:00
}
2022-12-29 01:24:34 +08:00
ffCfDictGetString(deviceRomProps, CFSTR("vendor"), &bios->vendor);
ffCfDictGetString(deviceRomProps, CFSTR("version"), &bios->version);
ffCfDictGetString(deviceRomProps, CFSTR("release-date"), &bios->date);
ffStrbufSetStatic(&bios->type, "UEFI");
2022-12-29 01:24:34 +08:00
2026-03-29 09:28:49 +08:00
#else
2022-12-29 01:24:34 +08:00
2026-03-29 09:28:49 +08:00
// For arm64
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t device = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/");
2026-03-29 09:28:49 +08:00
if (!device) {
return "IODeviceTree:/ not found";
2026-03-29 09:28:49 +08:00
}
2026-03-24 14:33:48 +08:00
FF_CFTYPE_AUTO_RELEASE CFDataRef manufacturer = IORegistryEntryCreateCFProperty(device, CFSTR("manufacturer"), kCFAllocatorDefault, kNilOptions);
ffCfStrGetString(manufacturer, &bios->vendor);
FF_CFTYPE_AUTO_RELEASE CFDataRef timeStamp = IORegistryEntryCreateCFProperty(device, CFSTR("time-stamp"), kCFAllocatorDefault, kNilOptions);
ffCfStrGetString(timeStamp, &bios->date);
2022-12-29 01:24:34 +08:00
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t deviceChosen = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen");
2026-03-29 09:28:49 +08:00
if (deviceChosen) {
FF_CFTYPE_AUTO_RELEASE CFStringRef tag = IORegistryEntryCreateCFProperty(deviceChosen, CFSTR("iboot-stage-one-tag"), kCFAllocatorDefault, kNilOptions)
?: IORegistryEntryCreateCFProperty(deviceChosen, CFSTR("system-firmware-version"), kCFAllocatorDefault, kNilOptions);
if (tag) {
ffCfStrGetString(tag, &bios->version);
2023-06-29 11:16:07 +08:00
uint32_t index = ffStrbufFirstIndexC(&bios->version, '-');
2026-03-29 09:28:49 +08:00
if (index != bios->version.length) {
2023-11-06 11:10:26 +08:00
ffStrbufAppendNS(&bios->type, index, bios->version.chars);
2023-06-29 11:16:07 +08:00
ffStrbufRemoveSubstr(&bios->version, 0, index + 1);
}
2022-12-29 01:24:34 +08:00
}
}
2026-03-29 09:28:49 +08:00
if (!bios->type.length) {
ffStrbufSetStatic(&bios->type, "iBoot");
2026-03-29 09:28:49 +08:00
}
#endif
2023-06-16 16:40:43 +08:00
2026-07-10 18:08:04 +08:00
return nullptr;
2022-12-29 01:24:34 +08:00
}