3,882
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
typedef int (__stdcall * PFN_MESSAGEBOX)(HWND, LPCTSTR, LPCTSTR, DWORD);
struct RemoteParam
{
char sShow[12];
DWORD dwMessageBox;
};
DWORD WINAPI threadProc(LPVOID lpParameter)
{
RemoteParam *rp=(RemoteParam*)lpParameter;
PFN_MESSAGEBOX pfnMessageBox=(PFN_MESSAGEBOX)(rp->dwMessageBox);
pfnMessageBox(NULL,rp->sShow,rp->sShow,0);
return 0;
}
void main()
{
DWORD proId;
const DWORD dwThreadSize=4096;
HWND windHandle=::FindWindow(NULL,"MyGame");
::GetWindowThreadProcessId(windHandle,&proId);
HANDLE proHandle=::OpenProcess(PROCESS_ALL_ACCESS,false,proId);
void* allcAddr=::VirtualAllocEx(proHandle,0,dwThreadSize,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);
::WriteProcessMemory(proHandle,allcAddr,&threadProc,dwThreadSize,0);
HMODULE hUser32=::LoadLibrary("User32.dll");
RemoteParam RemoteData;
ZeroMemory(&RemoteData,sizeof(RemoteParam));
RemoteData.dwMessageBox=(DWORD)::GetProcAddress(hUser32,"MessageBoxA");
strcat(RemoteData.sShow,"Hello\0");
RemoteParam* paramAndFunc=(RemoteParam*)::VirtualAllocEx(proHandle,0,sizeof(RemoteData),MEM_COMMIT,PAGE_READWRITE);
::WriteProcessMemory(proHandle,paramAndFunc,&RemoteData,sizeof(RemoteData),0);
DWORD dwId;
HANDLE hRemoteHandle=::CreateRemoteThread(proHandle,NULL,0,(LPTHREAD_START_ROUTINE)allcAddr,paramAndFunc,0,&dwId);
CloseHandle(hRemoteHandle);
FreeLibrary(hUser32);
}
typedef int (__stdcall * PFN_MESSAGEBOX)(HWND, LPCTSTR, LPCTSTR, DWORD);
struct RemoteParam
{
char sShow[12];
DWORD dwMessageBox;
};
DWORD WINAPI threadProc(LPVOID lpParameter)
{
RemoteParam *rp=(RemoteParam*)lpParameter;
PFN_MESSAGEBOX pfnMessageBox=(PFN_MESSAGEBOX)(rp->dwMessageBox);
pfnMessageBox(NULL,rp->sShow,rp->sShow,0);
return 0;
}
void CMyDlg::OnButtonPourinto()
{
//enableDebugPriv();
DWORD proId;
const DWORD dwThreadSize=4096;
HWND windHandle=::FindWindow(NULL,"MyGame");
::GetWindowThreadProcessId(windHandle,&proId);
HANDLE proHandle=::OpenProcess(PROCESS_ALL_ACCESS,false,proId);
void* allcAddr=::VirtualAllocEx(proHandle,0,dwThreadSize,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE
);
::WriteProcessMemory(proHandle,allcAddr,&threadProc,dwThreadSize,0);
RemoteParam RemoteData;
ZeroMemory(&RemoteData,sizeof(RemoteParam));
HINSTANCE hUser32 = LoadLibrary("User32.dll");
RemoteData.dwMessageBox=(DWORD)::GetProcAddress(hUser32,"MessageBoxA");
strcat(RemoteData.sShow,"Hello\0");
RemoteParam* paramAndFunc=(RemoteParam*)::VirtualAllocEx(proHandle,0,sizeof(RemoteData),MEM_COMMIT,PAGE_READWRITE);
::WriteProcessMemory(proHandle,paramAndFunc,&RemoteData,sizeof(RemoteData),0);
DWORD dwId;
HANDLE hRemoteHandle=::CreateRemoteThread(proHandle,NULL,0,(LPTHREAD_START_ROUTINE)allcAddr,paramAndFunc,0,&dwId);
CloseHandle(hRemoteHandle);
FreeLibrary(hUser32);
}