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

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

问题描述

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

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

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