Skip to content

Instantly share code, notes, and snippets.

@sbingner
Last active July 17, 2018 08:38
Show Gist options
  • Save sbingner/5f530006b3b6cd7cd0385e3c8fb2dabd to your computer and use it in GitHub Desktop.
Save sbingner/5f530006b3b6cd7cd0385e3c8fb2dabd to your computer and use it in GitHub Desktop.
copyBootHash
char *copyBootHash(void) {
unsigned char buf[1024];
uint32_t length = 1024;
io_registry_entry_t chosen = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/chosen");
if (!MACH_PORT_VALID(chosen)) {
printf("Unable to get IODeviceTree:/chosen port\n");
return NULL;
}
kern_return_t ret = IORegistryEntryGetProperty(chosen, "boot-manifest-hash", (void*)buf, &length);
IOObjectRelease(chosen);
if (ret != ERR_SUCCESS) {
printf("Unable to read boot-manifest-hash\n");
return NULL;
}
// Make a hex string out of the hash
char manifestHash[length*2+1];
bzero(manifestHash, sizeof(manifestHash));
int i;
for (i=0; i<length; i++) {
sprintf(manifestHash+i*2, "%02X", buf[i]);
}
printf("Hash: %s\n", manifestHash);
return strdup(manifestHash);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment