I have a pointer to IDirect3DDevice9 inteface with 119 methods (include 3 standart), implemented in d3d9.dll:
I need to get in my Delphi code offsets (in bytes) on methods EndScene() and Present() of the interface relative to the beginning of the library (DLL pointer).
var:
g_pD3DDevice: IDirect3DDevice9;
ProcAddr: Pointer;
hD3D9: HMODULE;
Present9 : DWORD;
EndScene9: DWORD;
implemenation:
hD3D9 := LoadLibrary('d3d9');
ProcAddr := GetProcAddress(hD3D9, 'Direct3DCreate9');
...
pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, TargetHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, @D3DPP, g_pD3DDevice);
I guess, in the VMT the Present() method is number 17 (0-based), and EndScene() is 42, because it's written in the library header file.
But I think it is not good idea to calculate offsets like:
Present9 := DWORD(g_pD3DDevice) + (17 * 4) - DWORD(hD3D9);
EndScene9 := DWORD(g_pD3DDevice) + (42 * 4) - DWORD(hD3D9);
I'm making a hook injector for Direct3D by loading the DLL into the foreign process. I want to know what offset the Present () method has in the process, to make interception
Tell please, what is best practices how to realize the solution?
UDP 30/04/2017:
I have found one more solution described in docwiki.embarcadero.com:
function GetPresentMethodPointer(const IntRef: IInterface): Pointer; assembler;
asm
mov eax, [IntRef]
add eax, vmtoffset IDirect3DDevice9.Present
mov eax, [eax]
end;