QuestionHelp with writeProcessMemory/openProcess

Posts 1–3 of 3 · Page 1 of 1
Help with writeProcessMemory/openProcess
I am trying to transition from just using cheat engine for my hacks to also using c++, but I am having difficulty learning the writeProcessMemory command. I have read through the MSDN documentation on writeProcessMemory and openProcess but I can't seem to figure out what I am doing wrong.

Can't get it to work on the cheat engine tutorial even (step 2).
Seems when I run the code (without debugging) in visual studio, the HP address goes unchanged, even when I update it by hitting "Hit me"

Code:
#include <iostream>
#include <Windows.h>
using namespace std;

int main() {
	
	int number = 50;

	HWND hwnd = FindWindowA(NULL, "Step 2");  //"Step 2" is the window title
	DWORD procID;
	GetWindowThreadProcessId(hwnd, &procID);
	
	HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
	WriteProcessMemory(handle, (LPVOID)0x3860710, &number, sizeof(number), NULL); //the second argument is the address of the hp value
}
step 2.PNG34 KB · 23 downloads CEwindso.png32 KB · 19 downloads
You might be affected by the same as me, I made a hack for Black Ops Zombies, it doesn't work on my computer, but it works on my second computer. And it is not the anti virus blocking it, cuz it works with Cheat Engine.
I have asked on a couple of forums, I will reach back to you if I find an answer
https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspxⓘ
try changing permissions on restricted memory location.

Also use the GetLastError() to find the last error code.

edit:
OK the cheat engine is forced to run as admininstrator, I made very subtle modification but if you compile this and run as admin it will work, obviously change the memory location
Code:
#include <iostream>
#include <Windows.h>
using namespace std;

int main() {

    int number = 50;
    SetLastError(0);
    HWND hwnd = FindWindow(nullptr, "Step 2");  //"Step 2" is the window title
    DWORD procID;
    GetWindowThreadProcessId(hwnd, &procID);
    HANDLE handle = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, procID);
    cout << GetLastError() << endl;
    SetLastError(0);
    if(!WriteProcessMemory(handle, (LPVOID)0x036D1AA8, &number, sizeof(number), nullptr)){
        cout << "write failed";
    } //the second argument is the address of the hp value
    cout << GetLastError();
    cin.get();
}
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?