0
给出一个非常简单的IO驱动:沟通与驱动 - OS X
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
我在做什么错了?如何找到正在运行的驱动程序并使用简单的用户空间应用程序与它进行通信?