Reputation: 1483
As written up there (^), I've got a problem with C++ and WriteProcessMemory(). I opened the Windows- Calc.exe, stored a number with and opened CheatEngine. I found the number (changed it e.t.c.) and put it in this program: (Note: I'm german; "Rechner" is equal to "Calculator")
#include <iostream>
#include <Windows.h>
using namespace std;
int main (){
int Value = 500;
HWND hWnd = FindWindow(0, L"Rechner");
if (!hWnd) {
cerr << "Can't find window" << endl;
return 0;
}
DWORD PID;
GetWindowThreadProcessId(hWnd, &PID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
if (!hProcess) {
cerr << "Process handle error" << endl;
return 0;
}
int iSuccess = WriteProcessMemory(hProcess, (LPVOID)0x899FC6F60C , &Value, (DWORD)sizeof(Value), NULL);
int i = 0;
while (iSuccess == 0){
i = i+1;
cerr << "Failed " << i << " Error: " << GetLastError() << endl;
iSuccess = WriteProcessMemory(hProcess, (LPVOID)0x899FC6F60C , &Value, (DWORD)sizeof(Value), NULL); //Here all begins
}
clog << "Done" << endl;
CloseHandle(hProcess);
return 0;
}
Window got found, Process got found (No errors there..) But then, the "//Here all begins" line returns 0, and sets GetLastError() to 487. Like all of the followings. If you know, what I've done wrong, please describe it noob-friendly, I began C++ yesterday.
Upvotes: 0
Views: 1087
Reputation: 8992
See this link for a description of what the GetLastError codes mean.
In this case ERROR_INVALID_ADDRESS
, Attempt to access invalid address.
This is due to the fact, that you are writing to a 'random' memory address. You cannot just take a number and hope that there will be memory in the other process at this address.
Upvotes: 1