this指针
源代码
#include <stdio.h>
#include <windows.h>
class Obj
{
public:
int a = 1;
virtual void showCount() {
printf("我是父类函数\n");
}
void showPrint1() {
printf("我是原本的函数\n");
}
private:
};
void showPrint2() {
printf("我是被替代的函数");
}
class child : public Obj
{
public:
void showCount() {
printf("我是子类函数\n");
}
private:
};
int main() {
Obj* ob = new Obj();
LPVOID funaddr = 0;
DWORD lpflOldProtect = 0;
_asm
{
mov eax, [ob];
mov eax, [eax];
mov funaddr, eax;
push eax;
}
if (funaddr)
{
VirtualProtect(funaddr,0x4,PAGE_EXECUTE_READWRITE,&lpflOldProtect);
}
_asm
{
pop eax;
mov edx, showPrint2;
mov[eax], edx;
}
if (funaddr)
{
VirtualProtect(funaddr, 0x4, lpflOldProtect, &lpflOldProtect);
}
ob->showCount();
//ob->showPrint1();
return 0;
}
图片: