简体   繁体   中英

Overriding a method defined by another kext?

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM