C++外挂 读写游戏内存

来源:互联网 发布:发送电子邮件的软件 编辑:程序博客网 时间:2024/06/05 12:07

以下为 关键代码

 

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

 

原创粉丝点击