Created
July 6, 2020 15:17
-
-
Save Muirey03/5774406f238bc7eb15c05b637120f8bb to your computer and use it in GitHub Desktop.
Get the class name of IOKit userclient connections using mach_port_kobject_description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kern_return_t classForConnection(io_connect_t client, io_name_t cls) | |
{ | |
kern_return_t (*mach_port_kobject_description)(mach_port_t, mach_port_t, uint32_t*, mach_vm_address_t*, char*); | |
void* handle = dlopen("/usr/lib/system/libsystem_kernel.dylib", RTLD_NOLOAD); | |
mach_port_kobject_description = (__typeof mach_port_kobject_description)dlsym(handle, "mach_port_kobject_description"); | |
if (!mach_port_kobject_description) | |
return KERN_NOT_SUPPORTED; | |
char desc[512] = {0}; | |
uint32_t type = 0; | |
mach_vm_address_t addr = 0; | |
kern_return_t kr = mach_port_kobject_description(mach_task_self(), client, &type, &addr, desc); | |
if (kr != KERN_SUCCESS) | |
return kr; | |
strlcpy(cls, desc, strchr(desc, '(') - desc + 1); | |
return KERN_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment