summaryrefslogtreecommitdiffstats
path: root/src/detection/bootmgr/bootmgr_apple.c
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/bootmgr/bootmgr_apple.c
Add the files
Diffstat (limited to 'src/detection/bootmgr/bootmgr_apple.c')
-rw-r--r--src/detection/bootmgr/bootmgr_apple.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/detection/bootmgr/bootmgr_apple.c b/src/detection/bootmgr/bootmgr_apple.c
new file mode 100644
index 0000000..d2b24e0
--- /dev/null
+++ b/src/detection/bootmgr/bootmgr_apple.c
@@ -0,0 +1,69 @@
+#include "bootmgr.h"
+#include "common/io.h"
+#include "common/apple/cf_helpers.h"
+
+#include <IOKit/IOKitLib.h>
+
+static const char* detectSecureBoot(bool* result) {
+#if __aarch64__
+ FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen");
+ if (!entryDevice) {
+ return "IORegistryEntryFromPath() failed";
+ }
+
+ FF_CFTYPE_AUTO_RELEASE CFTypeRef prop = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("secure-boot"), kCFAllocatorDefault, kNilOptions);
+ if (!prop) {
+ return "IORegistryEntryCreateCFProperty() failed";
+ }
+
+ if (CFGetTypeID(prop) != CFDataGetTypeID() || CFDataGetLength((CFDataRef) prop) == 0) {
+ return "Invalid secure-boot property";
+ }
+
+ *result = (bool) *CFDataGetBytePtr((CFDataRef) prop);
+#else
+ FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/options");
+ if (!entryDevice) {
+ return "IORegistryEntryFromPath() failed";
+ }
+
+ FF_CFTYPE_AUTO_RELEASE CFTypeRef prop = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("94b73556-2197-4702-82a8-3e1337dafbfb:AppleSecureBootPolicy"), kCFAllocatorDefault, 0);
+ if (!prop) {
+ return "IORegistryEntryCreateCFProperty() failed";
+ }
+
+ if (CFGetTypeID(prop) != CFDataGetTypeID() || CFDataGetLength((CFDataRef) prop) == 0) {
+ return "Invalid secure-boot property";
+ }
+
+ *result = *CFDataGetBytePtr((CFDataRef) prop) != 0x02 /* Permissive Security */;
+#endif
+
+ return NULL;
+}
+
+const char* ffDetectBootmgr(FFBootmgrResult* result) {
+ if (ffPathExists("/System/Library/CoreServices/boot.efi", FF_PATHTYPE_FILE)) {
+ ffStrbufSetStatic(&result->firmware, "/System/Library/CoreServices/boot.efi");
+ }
+
+ #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");
+ }
+
+ detectSecureBoot(&result->secureBoot);
+
+ return NULL;
+}