C++11 c++;从进程的内存中获取值
我试图得到进程内存地址的int值 我已经能够写入内存地址,无法读取内存地址值C++11 c++;从进程的内存中获取值,c++11,memory,C++11,Memory,我试图得到进程内存地址的int值 我已经能够写入内存地址,无法读取内存地址值 #include <iostream> #include <windows.h> #include <chrono> #include <ctime> using namespace std; int main(void) { int nVal = 40000; HWND hWnd = FindWindowA(0, "Crusader");
#include <iostream>
#include <windows.h>
#include <chrono>
#include <ctime>
using namespace std;
int main(void) {
int nVal = 40000;
HWND hWnd = FindWindowA(0, "Crusader");
if(hWnd == 0){
cerr << "Could not find window." << endl;
} else {
DWORD PID;
GetWindowThreadProcessId(hWnd, &PID);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, PID);
if(!hProc) {
cerr << "Cannot open process." << endl;
} else {
int buffer = 0;
int stat = WriteProcessMemory(hProc, (LPVOID)0x0115FCF8, &nVal, (DWORD)sizeof(nVal), NULL);
SIZE_T NumberOfBytesToRead = sizeof(buffer); //this is equal to 4
SIZE_T NumberOfBytesActuallyRead;
int stat2 = ReadProcessMemory(hProc, (LPVOID)0x0115FCF8, &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
std:cout<< *stat2;
/* if(stat > 0){
clog << "Memory written to process." << endl;
} else {
cerr << "Memory couldn't be written to process." << endl;
}
*/
CloseHandle(hProc);
cin.get();
}
}
return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
内部主(空){
int nVal=40000;
HWND HWND=FindWindowA(0,“十字军”);
如果(hWnd==0){
cerrstat和stat2表示读/写进程内存调用的返回值,这些调用用于错误检查。您似乎认为它们是您试图读和写的地址的值
假设您的目标进程是x86,您是为x86编译的,您是以管理员身份运行的,并且您的所有地址都是正确的,那么只需将最后一行更改为:
std:ou可能知道值返回到缓冲区,而不是stat2
,对吗?