以下為 關鍵代碼
SetWindowText("植物大戰殭屍太陽修改器--斯人"); //設定視窗標題
GameHwnd=::FindWindow("MainWindow","植物大戰殭屍中文版"); //擷取控制代碼
GetWindowThreadProcessId(GameHwnd,&hProcId); //擷取進程ID
mProcID=OpenProcess(PROCESS_ALL_ACCESS,false,hProcId); //開啟進程
if(mProcID==0){ //如果進程ID等於0 退出
MessageBox("先運行 植物大戰殭屍遊戲 ");
PostQuitMessage(0);
return false;
}
//0x006a9ec0為 遊戲基址 768,5560為位移量 真真實位址等於 遊戲基址+位移量
ReadProcessMemory(mProcID,LPCVOID(0x006a9ec0),&eax,sizeof(DWORD),0);
ReadProcessMemory(mProcID,LPCVOID(eax+0x00000768),&ecx,sizeof(DWORD),0);
ReadProcessMemory(mProcID,LPCVOID(ecx+0x00005560),&HP,sizeof(DWORD),0);
CString str;
str.Format("%d",HP);
GetDlgItem(IDC_EDIT1)->SetWindowText(str);
===============================================================
//寫記憶體資料
void CObjectChiDlg::WriteMemory(){
int sunNum;
CString str;
//擷取 輸入框的值
GetDlgItem(IDC_EDIT2)->GetWindowText(str);
//轉換成整型
sunNum=atoi(str);
//寫記憶體
BOOL RC=WriteProcessMemory(mProcID,(LPVOID)(ecx+0x00005560),&sunNum,4,NULL);
if(RC){
MessageBox(" 修改成功");
GetDlgItem(IDC_EDIT1)->SetWindowText(str);
}else{
int nCode = GetLastError();
CString errorInfo;
errorInfo.Format("%d 錯語碼:%d", &HP, nCode);
MessageBox(errorInfo);
}
}