就是将虚表中的函数地址修改为我们的想要的,使得程序运行我们的代码
#include "stdafx.h"
#include<windows.h>
class test{
public:
virtual void t(){
printf("Hello!!\n");
}
};
void Hello(){
printf("HOOKED!!!!\n");
}
int main(int argc, char* argv[])
{
test* a = new test();
DWORD* pFun = (DWORD*)*(DWORD*)(a);
//修改访问属性
DWORD pOldProc=0; //要将原属性保存,否则会执行失败
VirtualProtect(pFun,4,PAGE_EXECUTE_READWRITE,&pOldProc);
a->t();
*pFun = (DWORD)Hello;
a->t();
return 0;
}