Hook/Detour 虚拟函数

发布于 2024-12-04 00:51:15 字数 358 浏览 1 评论 0原文

我一直在尝试正确地挂钩/绕行类对象中的虚拟函数,并且在调用不同的函数方面取得了成功,但就 this 的方式而言,我必须做一些不正确的事情 关键字被传递给函数。

我读过一篇关于以类似方式挂钩 D3D 函数的文章,其中提到编译器会将诸如 int Class::method(int) 之类的函数转换为 int method(Class* this , int),但是如果我用这样定义的函数替换 vtable 中的地址,则“this”的地址不正确,因此这可能不正确。

编译器如何布置成员函数,是否可以以非成员函数形式表示它,以便我可以将 vtable 中的地址设置为这样的函数并能够引用适当的对象?

I've been trying to properly hook/detour a virtual function in a class object, and I've had success in terms of having a different function called, but I must be doing something that's incorrect in terms of how the this keyword is passed to the function.

I read an article about hooking D3D functions in a similar fashion, and it mentioned that the compiler will turn a function such as int Class::method(int) into int method(Class* this, int), but if I replace the address in the vtable with a function that is defined as such, the address for 'this' is incorrect, so that's probably not right.

How are member functions laid out by the compiler, and is it possible to represent it in non-member-function form so that I can set the address in the vtable to such a function and be able to refer to the appropriate object?

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

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

发布评论

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

评论(1

蝶…霜飞 2024-12-11 00:51:15

您需要将函数定义为 此调用。它将 this 传递到 ecx 寄存器上。按照您的方式,该函数期望在堆栈上出现 this 并读取可能属于另一个参数的错误值。

You need to define your function as thiscall. It passes this on the ecx register. The way you've done it, the function was expecting this on the stack and reading the wrong value which probably belonged to another argument.

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