能力值:
( LV2,RANK:10 )
|
-
-
2 楼
#include "windows.h"
#include "stdio.h"
PROC g_orgFunc = (PROC)MessageBoxA;
BOOL bMessage = 0;
typedef int (WINAPI *PFNMESSAGEBOX)(HWND,LPCSTR,LPCSTR,UINT);
int WINAPI MyMessageBox(HWND hWnd,LPCSTR lpContent,LPCSTR lpTitle,UINT uType);
int main()
{
HMODULE hMod = GetModuleHandle(NULL);
IMAGE_DOS_HEADER* pDosHeader = (IMAGE_DOS_HEADER*)(BYTE*)hMod;
IMAGE_OPTIONAL_HEADER* pOptHeader = (IMAGE_OPTIONAL_HEADER*)((BYTE*)hMod + pDosHeader->e_lfanew + 24);
IMAGE_IMPORT_DESCRIPTOR* pImportDesc = (IMAGE_IMPORT_DESCRIPTOR*)((BYTE*)hMod + pOptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
while(pImportDesc->FirstThunk)
{
char* pDllName = (char*)(pImportDesc->Name + (BYTE*)hMod);
if(strcmp(strupr(pDllName),"USER32.DLL") == 0)
{
puts("user32.dll find success");
break;
}
pImportDesc++;
}
IMAGE_THUNK_DATA* pThunk = (IMAGE_THUNK_DATA*)(pImportDesc->FirstThunk + (BYTE*)hMod);
while(pThunk->u1.Function)
{
DWORD* lpAddr = (DWORD*)&pThunk->u1.Function;
if(*lpAddr == (DWORD)g_orgFunc)
{
bMessage = 1;
DWORD* lpNewAddr = (DWORD*)MyMessageBox;
BOOL bRet = ::WriteProcessMemory(GetCurrentProcess(),lpAddr,&lpNewAddr,sizeof(DWORD),NULL);
if(bRet)
puts("WriteProcessMemory success");
}
pThunk++;
}
if(bMessage)
MessageBoxA(NULL,"这是老函数!","提示!",0);
getchar();
}
int WINAPI MyMessageBox(HWND hWnd,LPCSTR lpContent,LPCSTR lpTitle,UINT uType)
{
return ((PFNMESSAGEBOX)g_orgFunc)(hWnd,"老函数退休了,今天我值班!",lpTitle,uType);
}
|
|
|