PVOID* GetVtpl(PVOID lpThis, int nIndex)
{
return *(PVOID**)lpThis + nIndex;
}
PVOID HookVtpl(PVOID* lpAddr, PVOID lpNewAddr)
{
DWORD dwOldProtect;
PVOID lpResult = NULL;
if ( VirtualProtect(lpAddr, sizeof (PVOID), PAGE_READWRITE, &dwOldProtect) )
{
lpResult = *lpAddr;
*lpAddr = lpNewAddr;
VirtualProtect(lpAddr, sizeof (PVOID), dwOldProtect, &dwOldProtect);
}
return lpResult;
}
void UnhookVtpl(PVOID* lpAddr, PVOID lpOldAddr)
{
HookVtpl(lpAddr, lpOldAddr);
}