通过IOKIt命令传递CFDictionary [英] Passing CFDictionary via IOKIt command
问题描述
我正在寻找一种从用户空间代理到内核配置参数的通用方法,因为没有Mac等效于Windows注册表,在Windows注册表中,驱动程序可以使用ZwQueryValueKey
命令直接访问此表中的任何键.
I'm looking for a universal method to configure parameters from userspace agent to kernel since there is no Mac equivalent to windows registry where driver can directly access any key in this table using ZwQueryValueKey
command.
因此,我想通过CFDictionary
传递动态变量列表.
Therefore, I'd like to pass a dynamic list of variables through CFDictionary
.
在IOConnectCallMethod
中有一种传递输入指针的方法,但是问题是我是否可以传递CFDictionary
或CFDictionaryRef
而不是简单的结构.
In IOConnectCallMethod
there's a way to pass input pointer, but the question is if I can pass a CFDictionary
or CFDictionaryRef
instead of just a simple struct.
我看到有一些IOkit命令可以使您直接传递CFDictionaryRef,例如IOServiceGetMatchingService
,但是这些命令不是用于驱动程序模块的,而是用于管理驱动程序的实体的.
I saw that there are some IOkit commands that enable you to pass CFDictionaryRef directly, such as IOServiceGetMatchingService
but these are not intended for the driver module but for the entity that manages the drivers.
推荐答案
您可以使用I/O Kit属性机制在用户空间和内核空间之间交换类似plist的数据.要从用户空间设置它们,您将需要使用以下一个或多个IOKitLib函数:
You can use the I/O Kit property mechanism to exchange plist-like data between user space and kernel space. For setting them from userspace, you'll want to use one or more of the following IOKitLib functions:
-
IORegistryEntrySetCFProperty
-
IORegistryEntrySetCFProperties
-
IOConnectSetCFProperty
-
IOConnectSetCFProperties
IORegistryEntrySetCFProperty
IORegistryEntrySetCFProperties
IOConnectSetCFProperty
IOConnectSetCFProperties
在内核方面,您的IOService或IOUserClient子类应覆盖virtual IOReturn setProperties( OSObject * properties );
函数.不要忘记将接收到的任何数据都视为潜在的敌对对象,因此请确保检查nullptr
,在期望具体的OSData
/OSNumber
/OSString
/OSArray
/etc等时使用OSDynamicCast()
.对象,并清理数据本身.
On the kernel side, your IOService or IOUserClient subclass should override the virtual IOReturn setProperties( OSObject * properties );
function. Don't forget to treat any data received as potentially hostile, so make sure you check for nullptr
s, use OSDynamicCast()
when expecting concrete OSData
/OSNumber
/OSString
/OSArray
/etc. objects, and sanitise the data itself.
请注意,setProperties()
不会自动更新IORegistryEntry
对象的属性,在检查每个属性键/值键之后,仍然需要为每个属性键/值键调用this->setProperty()
.
Note that setProperties()
does not automatically update the properties of the IORegistryEntry
object, you still need to call this->setProperty()
for every property key/value key after it's been checked.
Apple提供有关此机制的一些基本的高级文档.
这篇关于通过IOKIt命令传递CFDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!