I'm writing a 64-bit Windows DLL using MSVS that is loaded by a 3rd party executable. The 3rd party exe has an API that includes some classes with pure virtual functions. Example:
//3rdPartyAPI.h
class foo
{
virtual void doWork() = 0;
};
__declspec(dllimport) foo* GetFOO(); //returns an instance of foo created by the executable that I can access
Once my DLL is loaded, I can call doWork from my own code like so:
GetFOO()->doWork();
However I want to use Microsoft's detours library to intercept calls to doWork and call my own function "doMyWork". So far, by manually stepping through the vtable of "foo" at runtime I've been able to find the vtable index of doWork (just through trial and error), then from there I can get its address and use that address in a call to DetourAttach and the detour works as intended.
But I would like to know: is there a way to programmatically (at runtime) find the vtable index/address of a pure virtual function?