您的位置:首页 > 其它

windows SDK/MFC读写目标进程的内存

2009-12-09 15:20 435 查看
DWORD BaseAddr = 0x420094;//操作地址
HWND hGame;
DWORD dwProcessID = 0;//获取线程ID
HANDLE PID;//操作线程的句柄
void Cmfc3Dlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
//MessageBox(TEXT("a"));
CString strItem;

DWORD d1=0,d2=0;
WCHAR name[128];
int max;
char* result = (char*)::calloc(2,2);
hGame = ::FindWindow(_T("#32770"),"mfc2"); //打开管理器的窗口

if(hGame){

::GetWindowThreadProcessId(hGame,&dwProcessID);//获取线程ID
PID=::OpenProcess(PROCESS_ALL_ACCESS,NULL,dwProcessID);//操作线程的句柄

ReadProcessMemory(PID, (LPCVOID)BaseAddr, &d1, 4, 0);//读取内存

::itoa(d1,result,10);

::TRACE("2222222");

SetDlgItemTextA(IDC_STATIC1,result);

SetDlgItemTextA(IDC_EDIT1,result);

//::CloseHandle(PID);
}else{
MessageBox("windows not found");
}
///	traceAppMsg("sdf");

}
void Cmfc3Dlg::OnBnClickedUpdate()
{
int strLen = ::GetWindowTextLength(::GetDlgItem(m_hWnd,IDC_EDIT1));
char* str = (char*)GlobalAlloc(GPTR, strLen + 1);
DWORD d1 = 0;
GetDlgItemTextA(IDC_EDIT1,str,strLen+1);
//MessageBox(str);
d1 = ::_atoi64(str);
if(WriteProcessMemory(PID,(LPVOID)BaseAddr,&d1,4,0)){
//MessageBox("success");
}else{
LPVOID  lpMsgBuf;
if(FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL))
//strShow.Format("GetLastError()=%s/r/n",lpMsgBuf);
//ShowMessage(strShow);
//ShowMessage("数据写入失败/r/n");
MessageBox((char*)lpMsgBuf);

}

SYSTEMTIME  time;
::GetSystemTime(&time);

CTime   t   =   CTime::GetCurrentTime();
CString t2 = t.Format("%Y-%m-%d %H:%M:%S");
//t2.Format(
char* axx = t2.GetBuffer();
//MessageBox(axx);
testList1.AddString(axx);
// TODO: 在此添加控件通知处理程序代码
std::string sss = "sdf";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐