Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created October 7, 2020 00:18
Show Gist options
  • Save pudquick/5925d024795666e09a4b95200edcd3fc to your computer and use it in GitHub Desktop.
Save pudquick/5925d024795666e09a4b95200edcd3fc to your computer and use it in GitHub Desktop.
IOKit IOUSBDevice enumeration
import objc
from Foundation import NSBundle
IOKit_bundle = NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit')
functions = [
("IORegistryEntryCreateCFProperties", b"IIo^@II"),
("IOServiceMatching", b"@*"),
("IOServiceGetMatchingServices", b"II@o^I"),
("IOIteratorNext", b"II"),
]
objc.loadBundleFunctions(IOKit_bundle, globals(), functions)
kIOMasterPortDefault = 0
kCFAllocatorDefault = 0
kNilOptions = 0
match_dictionary = IOServiceMatching("IOUSBDevice")
err, usb_iter = IOServiceGetMatchingServices(kIOMasterPortDefault, match_dictionary, None)
if err == 0:
next_item = IOIteratorNext(usb_iter)
while (next_item != 0):
err, details = IORegistryEntryCreateCFProperties(next_item, None, kCFAllocatorDefault, kNilOptions)
print details
next_item = IOIteratorNext(usb_iter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment