2024-05-16 16:27:37 +08:00
|
|
|
#include "bootmgr.h"
|
2026-01-06 09:48:38 +08:00
|
|
|
#include "common/io.h"
|
|
|
|
|
#include "common/apple/cf_helpers.h"
|
2025-12-27 16:11:16 +08:00
|
|
|
|
|
|
|
|
#include <IOKit/IOKitLib.h>
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
static const char* detectSecureBoot(bool* result) {
|
|
|
|
|
#if __aarch64__
|
2026-01-13 10:12:14 +08:00
|
|
|
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen");
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!entryDevice) {
|
2025-12-27 16:11:16 +08:00
|
|
|
return "IORegistryEntryFromPath() failed";
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-12-27 16:11:16 +08:00
|
|
|
|
2026-06-03 09:45:52 +08:00
|
|
|
FF_CFTYPE_AUTO_RELEASE CFTypeRef prop = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("secure-boot"), kCFAllocatorDefault, kNilOptions);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!prop) {
|
2025-12-27 16:11:16 +08:00
|
|
|
return "IORegistryEntryCreateCFProperty() failed";
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-12-27 16:11:16 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (CFGetTypeID(prop) != CFDataGetTypeID() || CFDataGetLength((CFDataRef) prop) == 0) {
|
2025-12-27 16:11:16 +08:00
|
|
|
return "Invalid secure-boot property";
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-12-27 16:11:16 +08:00
|
|
|
|
2025-12-27 18:12:23 +08:00
|
|
|
*result = (bool) *CFDataGetBytePtr((CFDataRef) prop);
|
2026-03-29 09:28:49 +08:00
|
|
|
#else
|
2026-01-13 10:12:14 +08:00
|
|
|
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/options");
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!entryDevice) {
|
2025-12-27 18:12:23 +08:00
|
|
|
return "IORegistryEntryFromPath() failed";
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-12-27 18:12:23 +08:00
|
|
|
|
|
|
|
|
FF_CFTYPE_AUTO_RELEASE CFTypeRef prop = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("94b73556-2197-4702-82a8-3e1337dafbfb:AppleSecureBootPolicy"), kCFAllocatorDefault, 0);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!prop) {
|
2025-12-27 18:12:23 +08:00
|
|
|
return "IORegistryEntryCreateCFProperty() failed";
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-12-27 18:12:23 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (CFGetTypeID(prop) != CFDataGetTypeID() || CFDataGetLength((CFDataRef) prop) == 0) {
|
2025-12-27 18:12:23 +08:00
|
|
|
return "Invalid secure-boot property";
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-12-27 18:12:23 +08:00
|
|
|
|
|
|
|
|
*result = *CFDataGetBytePtr((CFDataRef) prop) != 0x02 /* Permissive Security */;
|
2026-03-29 09:28:49 +08:00
|
|
|
#endif
|
2025-12-27 18:12:23 +08:00
|
|
|
|
2026-07-10 18:08:04 +08:00
|
|
|
return nullptr;
|
2025-12-27 16:11:16 +08:00
|
|
|
}
|
2024-05-16 16:27:37 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
const char* ffDetectBootmgr(FFBootmgrResult* result) {
|
|
|
|
|
if (ffPathExists("/System/Library/CoreServices/boot.efi", FF_PATHTYPE_FILE)) {
|
2024-05-16 16:27:37 +08:00
|
|
|
ffStrbufSetStatic(&result->firmware, "/System/Library/CoreServices/boot.efi");
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2024-05-16 16:27:37 +08:00
|
|
|
|
2026-06-03 09:45:52 +08:00
|
|
|
#ifdef __aarch64__
|
|
|
|
|
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t deviceChosen = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen");
|
|
|
|
|
if (deviceChosen) {
|
|
|
|
|
FF_CFTYPE_AUTO_RELEASE CFStringRef tag = IORegistryEntryCreateCFProperty(deviceChosen, CFSTR("iboot-stage-two-tag"), kCFAllocatorDefault, kNilOptions)
|
|
|
|
|
?: IORegistryEntryCreateCFProperty(deviceChosen, CFSTR("system-firmware-version"), kCFAllocatorDefault, kNilOptions);
|
|
|
|
|
if (tag) {
|
|
|
|
|
ffCfStrGetString(tag, &result->name);
|
|
|
|
|
ffStrbufSubstrBeforeFirstC(&result->name, '-');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (!result->name.length) {
|
|
|
|
|
ffStrbufSetStatic(&result->name, "iBoot");
|
|
|
|
|
}
|
2024-05-16 16:27:37 +08:00
|
|
|
|
2025-12-27 18:12:23 +08:00
|
|
|
detectSecureBoot(&result->secureBoot);
|
2025-12-27 16:11:16 +08:00
|
|
|
|
2026-07-10 18:08:04 +08:00
|
|
|
return nullptr;
|
2024-05-16 16:27:37 +08:00
|
|
|
}
|