|
//定义全局变量
HANDLE h; //游戏进程句柄PID
LPVOID address;
void asm()
{
_asm
{
写 汇编代码
}
}
void CMyDlg::OnButton1()
{
// TODO: Add your control notification handler code here
HWND hwnd=::FindWindow(NULL,"MU");
if(hwnd==0){AfxMessageBox("获取窗口句柄失败!"); return;}
DWORD pid;
GetWindowThreadProcessId(hwnd,&pid);
if(pid==0){AfxMessageBox("获取游戏进程ID失败!");return;}
h=::OpenProcess(PROCESS_ALL_ACCESS,false,pid);
if(h==0){AfxMessageBox("打开进程失败!");return;}
//分配内存空间
address=::VirtualAllocEx(h,NULL,0x1000,MEM_COMMIT | MEM_RESERVE,PAGE_EXECUTE);
if(address==0){AfxMessageBox("申请内存空间失败!");return;}
m_address=(int)address;
UpdateData(false); //接受用户输入,为真,输出就为假
WriteProcessMemory(h,address,asm,0x1000,NULL);
//DWORD tid;
//CreateRemoteThread(h,NULL,0,(LPTHREAD_START_ROUTINE)address,0,0,&tid);
}
void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime) //设置时钟的回调函数
{
DWORD tid;
HANDLE yuanc=::CreateRemoteThread(h,NULL,0,(LPTHREAD_START_ROUTINE)address,0,0,&tid);
}
void CMyDlg::OnButton3()
{
// TODO: Add your control notification handler code here
// SetTimer( NULL,(UINT_PTR)1,(UINT) 500,(TIMERPROC) OnButton2);
SetTimer(1,300,TimerProc);
} |
|