QueryData genIOKitRegistry(QueryContext& context) { QueryData results; // Get the IO registry root node. auto service = IORegistryGetRootEntry(kIOMasterPortDefault); // Begin recursing along the IODeviceTree "plane". genIOKitDeviceChildren(service, kIOServicePlane, 0, results); IOObjectRelease(service); return results; }
int main(int argc, char **argv) { io_registry_entry_t root; char * plane; unsigned int options; kern_return_t status; ///na int arg; // Parse args plane = kIOServicePlane; options = kDoPropsOption; for(arg = 1; arg < argc; arg++) { if ('-' == argv[arg][0]) switch(argv[arg][1]) { case 'h': printf("%s [-p] [-r] [-h] [plane]\n", argv[0]); exit(0); break; case 'p': options &= ~kDoPropsOption; break; case 'r': options |= kDoRootOption; break; } else { plane = argv[arg]; } } // Obtain the I/O Kit communication handle. // status = IOGetMasterPort(&masterPort); status = IOMasterPort(bootstrap_port, &masterPort); assert(status == KERN_SUCCESS); // Obtain the registry root entry. root = IORegistryGetRootEntry(masterPort); assert(root); // Traverse below the root in the plane. traverse(options, plane, 0, root, 0, 0); // Quit. exit(0); }
int main(int argc, char **argv) { mach_port_t masterPort; io_registry_entry_t root; CFDictionaryRef props; kern_return_t status; // Obtain the I/O Kit communication handle. status = IOMasterPort(bootstrap_port, &masterPort); assert(status == KERN_SUCCESS); // Obtain the registry root entry. root = IORegistryGetRootEntry(masterPort); assert(root); status = IORegistryEntryCreateCFProperties(root, (CFTypeRef *) &props, kCFAllocatorDefault, kNilOptions ); assert( KERN_SUCCESS == status ); assert( CFDictionaryGetTypeID() == CFGetTypeID(props)); props = (CFDictionaryRef) CFDictionaryGetValue( props, CFSTR(kIOKitDiagnosticsKey)); assert( props ); assert( CFDictionaryGetTypeID() == CFGetTypeID(props)); printNumber(props, CFSTR("Instance allocation")); printNumber(props, CFSTR("Container allocation")); printNumber(props, CFSTR("IOMalloc allocation")); CFRelease(props); IOObjectRelease(root); exit(0); }
QueryData genKernelInfo(QueryContext& context) { QueryData results; mach_port_t master_port; auto kr = IOMasterPort(bootstrap_port, &master_port); if (kr != KERN_SUCCESS) { VLOG(1) << "Could not get the IOMaster port"; return {}; } // NVRAM registry entry is :/options. auto chosen = IORegistryEntryFromPath(master_port, kIODTChosenPath_); if (chosen == 0) { VLOG(1) << "Could not get IOKit boot device"; return {}; } // Parse the boot arguments, usually none. CFMutableDictionaryRef properties; kr = IORegistryEntryCreateCFProperties( chosen, &properties, kCFAllocatorDefault, 0); IOObjectRelease(chosen); if (kr != KERN_SUCCESS) { VLOG(1) << "Could not get IOKit boot device properties"; return {}; } Row r; CFTypeRef property; if (CFDictionaryGetValueIfPresent( properties, CFSTR("boot-args"), &property)) { r["arguments"] = stringFromCFData((CFDataRef)property); } if (CFDictionaryGetValueIfPresent( properties, CFSTR("boot-device-path"), &property)) { r["device"] = getCanonicalEfiDevicePath((CFDataRef)property); } if (CFDictionaryGetValueIfPresent( properties, CFSTR("boot-file"), &property)) { r["path"] = stringFromCFData((CFDataRef)property); std::replace(r["path"].begin(), r["path"].end(), '\\', '/'); boost::trim(r["path"]); if (!r["path"].empty() && r["path"][0] != '/') { r["path"] = "/" + r["path"]; } } // No longer need chosen properties. CFRelease(properties); // The kernel version, signature, and build information is stored in Root. auto root = IORegistryGetRootEntry(master_port); if (root != 0) { property = (CFDataRef)IORegistryEntryCreateCFProperty( root, CFSTR(kIOKitBuildVersionKey), kCFAllocatorDefault, 0); if (property != nullptr) { // The version is in the form: // Darwin Kernel Version VERSION: DATE; root:BUILD/TAG auto signature = stringFromCFString((CFStringRef)property); CFRelease(property); r["version"] = signature.substr(22, signature.find(":") - 22); } } results.push_back(r); return results; }