Advertisement
captmicro

hooking vtable

Dec 6th, 2012
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. /*returns pointer to pre-hook function*/
  2. /*pVTBL: vtable of the class, dwIdx: virtual function index you want to hook, pNewFunc: address of your function*/
  3. /*returns the pointer(aka address) of the original function*/
  4. MH_FUNC MH_VTBLHook(MH_VTBL pVTBL, DWORD dwIdx, MH_FUNC pNewFunc)
  5. {
  6.     MH_FUNC pOrigFunc; DWORD dwOldProt;
  7.     VirtualProtect((void*)&pVTBL[dwIdx], 4, PAGE_READWRITE, &dwOldProt);
  8.     pOrigFunc = (BYTE*)pVTBL[dwIdx]; //save old function
  9.     pVTBL[dwIdx] = (DWORD)pNewFunc; //set VTBL entry to new function
  10.     VirtualProtect((void*)&pVTBL[dwIdx], 4, dwOldProt, NULL);
  11.     return pOrigFunc;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement