I'm calling a virtual method on the vmt by dereferencing until I get the pointer to the method.
This is all good however, how would I completely change the pointer to the VM table on the object?
Example:
PP A; // points to its default VM table
PP B; // points to a completely different VM table
A->MethodOne() // calls as mentioned above
B->MethodOne() // calls a completely different method since we override its pointer to the VM table to an alternate table with different method pointers
How would I accomplish this?
My Code:
#include <Windows.h>
#include <iostream>
class PP
{
public:
PP() { }
~PP() { }
virtual void MethodOne() { std::cout << "1" << std::endl; }
virtual void MethodTwo() { std::cout << "2" << std::endl; }
};
typedef void (*MyFunc)(void);
int main()
{
PP* A = new PP();
//(*(void(**)(void))(*(DWORD*)A + (4*1)))();
( *(MyFunc*) ( *(DWORD*)A + (4*0) ) )(); // call index 0 (4bytes*0)
A->MethodOne();
A->MethodTwo();
system("PAUSE");
delete A;
return 0;
}