重写另一个 kext 定义的方法?

发布于 2024-11-27 07:34:41 字数 543 浏览 3 评论 0原文

我需要覆盖由 kext 定义的方法来进行我自己的处理并返回我自己的值,因此每当 kext 调用该方法时,它都会路由到我的方法。所以我想做的就是在我自己的内核扩展中定义这个方法,然后加载它。 问题是我不知道如何交换方法所以我的方法被调用

/* basically, I need to override the isPinDigital method of AppleHDAPathSet */
AppleHDAPathSet::isPinDigital(void) 
{
     /* I also need to be able to call the superclass' method */

     /* return my own value */
     return 0;
}

有没有一种简单的方法可以做到这一点?我知道有一种方法可以通过 VTables 来实现这一点,因为所有内核扩展都在同一地址空间中运行(我认为这是唯一的方法,但我不确定如何做到这一点)。

I need to override a method defined by a kext to do my own processing and return my own value, so whenever the kext calls the method, it will get routed to mine. So what I want to do is to define this method in my own kernel extension, and then load it. The problem is that I don't know how to swap the methods so mine gets called instead.

/* basically, I need to override the isPinDigital method of AppleHDAPathSet */
AppleHDAPathSet::isPinDigital(void) 
{
     /* I also need to be able to call the superclass' method */

     /* return my own value */
     return 0;
}

Is there an easy way to do this? I know that there is a way of doing it via VTables as all kernel extensions run in the same address space (I think it's the only way, but I'm not sure on how to do it).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ弥猫深巷。 2024-12-04 07:34:41

你当然可以通过破解 vtable 来实现这一点,尽管我不知道你会如何去做。我知道C++ kext加载和卸载机制管理vtable和vtable版本控制;源应该是可用的,所以看一下。

然而,vtable 修补确实应该是最后的手段。您确定不能通过子类化 AppleHDAPathSet 来实现此目的吗?假设这不是 IOKit 个性类,您还必须对其进行子类化,并设置您的 info.plist,以便您的子类个性具有比基础个性更高的探测分数。在您的 probe() 方法中决定是否需要应用对 isPinDigital 的 hack。然后覆盖最初实例化 AppleHDAPathSet 对象的任何方法,并使其创建子类版本的实例。

You can certainly achieve this via hacking the vtable, though I don't have a specific idea of how you'd go about that. I know the C++ kext loading and unloading mechanism manages vtables and vtable versioning; the source should be available, so have a look at that.

However, vtable patching should really be a last resort. Are you sure you can't achieve this by subclassing AppleHDAPathSet? Assuming this isn't an IOKit personality class, you'll have to subclass that as well, and set your info.plist up such that your subclassed personality has a higher probe score than the base. Decide in your probe() method whether your hack to isPinDigital needs to be applied. Then override whatever method originally instantiates the AppleHDAPathSet object and make it create an instance of your subclassed version instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文