Created
October 7, 2020 00:18
-
-
Save pudquick/5925d024795666e09a4b95200edcd3fc to your computer and use it in GitHub Desktop.
IOKit IOUSBDevice enumeration
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
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