C++外掛 讀寫遊戲記憶體

來源:互聯網
上載者:User

以下為 關鍵代碼

 

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); 
    }
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.