【发布时间】:2014-07-19 08:25:08
【问题描述】:
给定一个非常简单的 IO 驱动:
class com_osxkernel_driver_IOKitTest : public IOService
{
OSDeclareDefaultStructors(com_osxkernel_driver_IOKitTest)
public:
virtual bool init (OSDictionary* dictionary = nullptr);
virtual void free(void);
virtual IOService* probe (IOService* provider, SInt32* score);
virtual bool start (IOService* provider);
virtual void stop (IOService* provider);
};
这是 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>IOKitTest</key>
<dict>
<key>CFBundleIdentifier</key>
<string>com.osxkernel.${PRODUCT_NAME:rfc1034identifier}</string>
<key>IOClass</key>
<string>com_osxkernel_driver_IOKitTest</string>
<key>IOMatchCategory</key>
<string>com_osxkernel_driver_IOKitTest</string>
<key>IOProviderClass</key>
<string>IOResources</string>
<key>IOResourceMatch</key>
<string>IOKit</string>
</dict>
<?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>com.apple.kpi.iokit</key>
<string>9.0.0</string>
<key>com.apple.kpi.libkern</key>
<string>9.0.0</string>
</dict>
</plist>
驱动程序运行得非常好,我可以使用“内核日志”以及在键入时看到它:
kextstat | grep -v com.apple
问题是我不知道如何使用用户空间应用程序进行通信,我如何找到它? 我知道它与字典有关,我尝试使用以下代码找到它但没有运气(使用苹果开发者网站):
int search_driver ()
{
io_iterator_t iter = 0;
io_service_t service = 0;
kern_return_t kr;
CFDictionaryRef matchingDict = IOServiceMatching("IOResources");
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
if (kr != KERN_SUCCESS) {
printf("Nothing found. \n");
return -1;
}
// Iterate over all matching objects.
while ((service = IOIteratorNext(iter)) != 0)
{
CFStringRef className;
io_name_t name;
// List all IOUSBDevice objects, ignoring objects that subclass IOUSBDevice.
className = IOObjectCopyClass(service);
IORegistryEntryGetName(service, name);
printf("Found device with name: %s\n", name);
CFRelease(className);
IOObjectRelease(service);
// Release the iterator.
IOObjectRelease(iter);
}
return 0;
}
我试过了:
CFDictionaryRef matchingDict = IOServiceMatching("IOResources");
CFDictionaryRef matchingDict = IOServiceMatching("IOService");
还有更多。
但仍然没有运气。第一个发现:IOResources 第二个发现:Macbook Air 5,2
我做错了什么?如何使用简单的用户空间应用程序找到正在运行的驱动程序并与之通信?
【问题讨论】: