VirtualTable Hook

2020-7-19 流沙 C/C++

关键是定位虚表的位置


#include "stdafx.h"
#include <windows.h>

class Base{
	
	public:
		virtual  void Print(){
			printf("gyarmy.com\n");
		}

};

void hookPrint(){
	printf("hook_gyarmy\n");
}


int main(int argc, char* argv[])
{	
	Base *pb = new Base();
	
	//关键定位虚表的位置
	DWORD *pVtAddr = (DWORD*)*(DWORD*)pb;

	DWORD dwOldProtect = 0;

	VirtualProtect(pVtAddr,4,PAGE_EXECUTE_READWRITE,&dwOldProtect);
	*pVtAddr = (DWORD)hookPrint;

	pb->Print();

	delete pb;
	
	return 0;
}

发表评论:

Powered by 流沙团

备案号:鄂ICP备15017378号-1