COM method offsets in Delphi

前端 未结 4 436
天涯浪人
天涯浪人 2021-01-02 09:56

In Delphi, 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(poi         


        
4条回答
  •  旧时难觅i
    2021-01-02 10:22

    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
    

    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.

    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.

提交回复
热议问题