COM方法偏移在Delphi中 [英] COM method offsets in Delphi

查看:195
本文介绍了COM方法偏移在Delphi中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi中,如何找出COM方法的地址?
我可以硬编码偏移量

In Delp how do I find out the the address of a COM method? I can hardcode the offsets

//0 is the offset of the QueryInterface method
p := TPonterArray(pointer(SomeInterface)^)[0];

但我宁愿使用符号名称。以下显然不行:

but I would prefer to use symbolic names. The folllowing obviously does not work:

var M : TMethod;
...
M := TMethod(SomeInterface.QueryInterface);

谢谢!

推荐答案

您可以使用 vmtoffset 汇编器指令来获取接口方法相对于接口方法表开头的字节偏移量。看看 System.pas 中的 _IntfCast 的实现,例如:

You can use the vmtoffset assembler directive to get the byte offset of an interface method relative to the start of the interface's method table. Take a look at the implementation of _IntfCast in System.pas, for example:

call dword ptr [eax] + vmtoffset IInterface.QueryInterface
...
call dword ptr [eax] + vmtoffset IInterface._Release

第一个表达式添加0;第二,8。

The first expression adds 0; the second, 8.

但是,您不能参数化这些表达式。它们是编译时常量,因此您无法在运行时选择所需的方法。您需要提前表示所有可能的方法名称。

You cannot parameterize those expressions, though. They're compile-time constants, so you cannot choose which method you want at run time. You need to have all possible method names represented in advance.

所有您真正需要挂钩的是 QueryInterface 。一旦你拥有了,你可以返回任何代理对象,你可以拦截所有其他方法的呼叫。

All you really need to hook is QueryInterface. Once you have that, you can return whatever proxy object you want that can intercept calls to all the other methods.

这篇关于COM方法偏移在Delphi中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆