USB存储设备的无代码kext
Codeless kext for usb storage device
在一个项目中,我最近试图通过 osx 10.9.5 上的 libusb 访问 USB 存储设备。但显然一些默认驱动程序声明了该设备,我无法访问它。当我尝试通过 libusb 访问它时 returns 我会有 "insufficient permissions".
当我在 Ubuntu 中执行 (java) 应用程序时,一切正常。
我在 Internet 上的研究表明,提供与更高探测分数上的设备匹配的无代码 kext 将阻止默认驱动程序声明该设备。这将完全解决问题,因为卸载 IOUSBMassStorage kext 可以使用设备执行我们想要的操作。
我尝试创建一个无代码的 kext 并没有像我希望的那样成功,因为它似乎既不会在启动时加载,也不会在我使用 kextload
时加载。至少那是我的猜测,因为我无法卸载它,也无法在列出的任何地方找到它。
我的 Info.plist 的最新版本如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>OSBundleLibraries</key>
<dict/>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleGetInfoString</key>
<string>Test USB Stick</string>
<key>CFBundleIdentifier</key>
<string>de.mischok.testkext</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Test USB Device</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>IOKitPersonalities</key>
<dict>
<key>Device Driver</key>
<dict>
<key>CFBundleIdentifier</key>
<string>de.mischok.testkext</string>
<key>IOClass</key>
<string>IOUSBUserClientInit</string>
<key>IOProviderClass</key>
<string>IOUSBDevice</string>
<key>idProduct</key>
<integer>357</integer>
<key>idVendor</key>
<integer>4871</integer>
<key>bcdDevice</key>
<integer>4352</integer>
<key>bConfigurationValue</key>
<integer>1</integer>
<key>bInterfaceNumber</key>
<integer>0</integer>
</dict>
<key>Interface Driver</key>
<dict>
<key>CFBundleIdentifier</key>
<string>de.mischok.testkext</string>
<key>IOClass</key>
<string>IOUSBUserClientInit</string>
<key>IOProviderClass</key>
<string>IOUSBInterface</string>
<key>idProduct</key>
<integer>357</integer>
<key>idVendor</key>
<integer>4871</integer>
<key>bcdDevice</key>
<integer>4352</integer>
<key>bConfigurationValue</key>
<integer>1</integer>
<key>bInterfaceNumber</key>
<integer>0</integer>
</dict>
</dict>
<key>OSBundleRequired</key>
<string>Local-Root</string>
</dict>
</plist>
当 运行 sudo kextutil -t -n /path/to/my.kext
返回这些诊断时:
Diagnostics for /Users/user/Desktop/testv1-0.kext:
Warnings:
Personality CFBundleIdentifier names a kext that doesn't declare an executable:
'Interface Driver' -> 'de.mischok.testkext'
'Device Driver' -> 'de.mischok.testkext'
Code Signing Failure: not code signed
Warnings:
Personality CFBundleIdentifier names a kext that doesn't declare an executable:
'Interface Driver' -> 'de.mischok.testkext'
'Device Driver' -> 'de.mischok.testkext'
/Users/user/Desktop/testv1-0.kext appears to be loadable (including linkage for on-disk libraries).
正如它所说的 kext 应该是可加载的,我认为它应该可以工作。但是当使用 sudo kextload /path/to/my.kext
:
加载 kext 时,system.log 记录了这一点,而不是工作
Nov 5 12:28:58 users-MacBook-Pro.local sudo[528]: user : TTY=ttys000 ; PWD=/Users/user ; USER=root ; COMMAND=/sbin/kextload /Users/user/Desktop/testv1-0.kext
Nov 5 12:28:58 users-MacBook-Pro.local com.apple.kextd[12]: WARNING - Invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext "/Users/user/Desktop/testv1-0.kext"
由于只是警告,我以为加载成功了。但是只要我插入设备,usb prober 输出就如下所示:
Nov 5 12:57:11.911 [6] Device Descriptor Dump
Nov 5 12:57:11.911 [6] bLength 18
Nov 5 12:57:11.911 [6] bDescriptorType 1
Nov 5 12:57:11.911 [6] bcdUSB 768 (0x0300)
Nov 5 12:57:11.911 [6] bDeviceClass 0
Nov 5 12:57:11.911 [6] bDeviceSubClass 0
Nov 5 12:57:11.911 [6] bDeviceProtocol 0
Nov 5 12:57:11.911 [6] bMaxPacketSize0 9
Nov 5 12:57:11.911 [6] idVendor 4871 (0x1307)
Nov 5 12:57:11.911 [6] idProduct 357 (0x0165)
Nov 5 12:57:11.911 [6] bcdDevice 4352 (0x1100)
Nov 5 12:57:11.911 [6] iManufacturer 1
Nov 5 12:57:11.911 [6] iProduct 2
Nov 5 12:57:11.911 [6] iSerialNumber 3
Nov 5 12:57:11.911 [6] bNumConfigurations 1
Nov 5 12:57:11.916 [5] Finding device driver for DEVICE, matching personality using com.apple.iokit.IOUSBUserClient, score: 106999, wildCard = 3
Nov 5 12:57:11.916 [6] Matched: idVendor (4871) idProduct (357) bcdDevice (4352)
Nov 5 12:57:11.916 [6] Didn't Match: nothing
Nov 5 12:57:11.917 [5] Finding device driver for DEVICE, matching personality using com.apple.driver.AppleUSBComposite, score: 50000, wildCard = 0
Nov 5 12:57:11.917 [6] Matched: bDeviceClass (0) bDeviceSubClass (0)
Nov 5 12:57:11.917 [6] Didn't Match: nothing
Nov 5 12:57:11.918 [5] Finding device driver for DEVICE, matching personality using com.apple.driver.AppleUSBCDC, score: 60000, wildCard = 0
Nov 5 12:57:11.918 [6] Matched: bDeviceClass (0) bDeviceSubClass (0) bDeviceProtocol (0)
Nov 5 12:57:11.918 [6] Didn't Match: nothing
这些是唯一发生的个性匹配,所以我想知道,我应该怎么做才能使我的 kext 与我的设备匹配甚至加载?
- 使用
kextutil
,而不是 kextload
。它提供了更好的诊断。
- I/O 指定
IOUSBUserClientInit
IOClass 的套件个性必须指定 com.apple.iokit.IOUSBUserClient
的 CFBundleIdentifier
,因为那是 class 所在的位置。
- 要加载未签名的 kext,它必须位于 10.
/System/Library/Extensions
。9.x。
在一个项目中,我最近试图通过 osx 10.9.5 上的 libusb 访问 USB 存储设备。但显然一些默认驱动程序声明了该设备,我无法访问它。当我尝试通过 libusb 访问它时 returns 我会有 "insufficient permissions".
当我在 Ubuntu 中执行 (java) 应用程序时,一切正常。
我在 Internet 上的研究表明,提供与更高探测分数上的设备匹配的无代码 kext 将阻止默认驱动程序声明该设备。这将完全解决问题,因为卸载 IOUSBMassStorage kext 可以使用设备执行我们想要的操作。
我尝试创建一个无代码的 kext 并没有像我希望的那样成功,因为它似乎既不会在启动时加载,也不会在我使用 kextload
时加载。至少那是我的猜测,因为我无法卸载它,也无法在列出的任何地方找到它。
我的 Info.plist 的最新版本如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>OSBundleLibraries</key>
<dict/>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleGetInfoString</key>
<string>Test USB Stick</string>
<key>CFBundleIdentifier</key>
<string>de.mischok.testkext</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Test USB Device</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>IOKitPersonalities</key>
<dict>
<key>Device Driver</key>
<dict>
<key>CFBundleIdentifier</key>
<string>de.mischok.testkext</string>
<key>IOClass</key>
<string>IOUSBUserClientInit</string>
<key>IOProviderClass</key>
<string>IOUSBDevice</string>
<key>idProduct</key>
<integer>357</integer>
<key>idVendor</key>
<integer>4871</integer>
<key>bcdDevice</key>
<integer>4352</integer>
<key>bConfigurationValue</key>
<integer>1</integer>
<key>bInterfaceNumber</key>
<integer>0</integer>
</dict>
<key>Interface Driver</key>
<dict>
<key>CFBundleIdentifier</key>
<string>de.mischok.testkext</string>
<key>IOClass</key>
<string>IOUSBUserClientInit</string>
<key>IOProviderClass</key>
<string>IOUSBInterface</string>
<key>idProduct</key>
<integer>357</integer>
<key>idVendor</key>
<integer>4871</integer>
<key>bcdDevice</key>
<integer>4352</integer>
<key>bConfigurationValue</key>
<integer>1</integer>
<key>bInterfaceNumber</key>
<integer>0</integer>
</dict>
</dict>
<key>OSBundleRequired</key>
<string>Local-Root</string>
</dict>
</plist>
当 运行 sudo kextutil -t -n /path/to/my.kext
返回这些诊断时:
Diagnostics for /Users/user/Desktop/testv1-0.kext:
Warnings:
Personality CFBundleIdentifier names a kext that doesn't declare an executable:
'Interface Driver' -> 'de.mischok.testkext'
'Device Driver' -> 'de.mischok.testkext'
Code Signing Failure: not code signed
Warnings:
Personality CFBundleIdentifier names a kext that doesn't declare an executable:
'Interface Driver' -> 'de.mischok.testkext'
'Device Driver' -> 'de.mischok.testkext'
/Users/user/Desktop/testv1-0.kext appears to be loadable (including linkage for on-disk libraries).
正如它所说的 kext 应该是可加载的,我认为它应该可以工作。但是当使用 sudo kextload /path/to/my.kext
:
Nov 5 12:28:58 users-MacBook-Pro.local sudo[528]: user : TTY=ttys000 ; PWD=/Users/user ; USER=root ; COMMAND=/sbin/kextload /Users/user/Desktop/testv1-0.kext
Nov 5 12:28:58 users-MacBook-Pro.local com.apple.kextd[12]: WARNING - Invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext "/Users/user/Desktop/testv1-0.kext"
由于只是警告,我以为加载成功了。但是只要我插入设备,usb prober 输出就如下所示:
Nov 5 12:57:11.911 [6] Device Descriptor Dump
Nov 5 12:57:11.911 [6] bLength 18
Nov 5 12:57:11.911 [6] bDescriptorType 1
Nov 5 12:57:11.911 [6] bcdUSB 768 (0x0300)
Nov 5 12:57:11.911 [6] bDeviceClass 0
Nov 5 12:57:11.911 [6] bDeviceSubClass 0
Nov 5 12:57:11.911 [6] bDeviceProtocol 0
Nov 5 12:57:11.911 [6] bMaxPacketSize0 9
Nov 5 12:57:11.911 [6] idVendor 4871 (0x1307)
Nov 5 12:57:11.911 [6] idProduct 357 (0x0165)
Nov 5 12:57:11.911 [6] bcdDevice 4352 (0x1100)
Nov 5 12:57:11.911 [6] iManufacturer 1
Nov 5 12:57:11.911 [6] iProduct 2
Nov 5 12:57:11.911 [6] iSerialNumber 3
Nov 5 12:57:11.911 [6] bNumConfigurations 1
Nov 5 12:57:11.916 [5] Finding device driver for DEVICE, matching personality using com.apple.iokit.IOUSBUserClient, score: 106999, wildCard = 3
Nov 5 12:57:11.916 [6] Matched: idVendor (4871) idProduct (357) bcdDevice (4352)
Nov 5 12:57:11.916 [6] Didn't Match: nothing
Nov 5 12:57:11.917 [5] Finding device driver for DEVICE, matching personality using com.apple.driver.AppleUSBComposite, score: 50000, wildCard = 0
Nov 5 12:57:11.917 [6] Matched: bDeviceClass (0) bDeviceSubClass (0)
Nov 5 12:57:11.917 [6] Didn't Match: nothing
Nov 5 12:57:11.918 [5] Finding device driver for DEVICE, matching personality using com.apple.driver.AppleUSBCDC, score: 60000, wildCard = 0
Nov 5 12:57:11.918 [6] Matched: bDeviceClass (0) bDeviceSubClass (0) bDeviceProtocol (0)
Nov 5 12:57:11.918 [6] Didn't Match: nothing
这些是唯一发生的个性匹配,所以我想知道,我应该怎么做才能使我的 kext 与我的设备匹配甚至加载?
- 使用
kextutil
,而不是kextload
。它提供了更好的诊断。 - I/O 指定
IOUSBUserClientInit
IOClass 的套件个性必须指定com.apple.iokit.IOUSBUserClient
的CFBundleIdentifier
,因为那是 class 所在的位置。 - 要加载未签名的 kext,它必须位于 10.
/System/Library/Extensions
。9.x。