Search code examples
c++readprocessmemory

c++, read and write memory,


so i am new to c++ (very new) , and i have been trying with this code for 7 hours, and i dont know why its not working , its compiled fine but it look like its writing to a wrong address,i have a feeling i got something wrong, thanks.

      #include<iostream>
#include<windows.h>
#include<stdlib.h>
using namespace std;

int main() {
DWORD id;
HANDLE handle;
HWND wnd;

unsigned int baseadd = {0x021da060};
unsigned int ptemp;
unsigned int pointer;

unsigned  int newdata = 5000;

wnd = FindWindow(NULL, "AssaultCube");
GetWindowThreadProcessId(wnd,&id);



handle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,id);

ReadProcessMemory(handle,(LPVOID)baseadd,&ptemp,sizeof(ptemp),0);
pointer =ptemp + 0x384;

ReadProcessMemory(handle,(LPVOID)pointer,&ptemp,sizeof(ptemp),0);
pointer =ptemp + 0x14;

ReadProcessMemory(handle,(LPVOID)baseadd,&ptemp,sizeof(ptemp),0);
pointer =ptemp + 0x0;

cout << &pointer;                     // just to check if it was the right address , its not

WriteProcessMemory(handle,(LPVOID)pointer,&newdata,sizeof(newdata),NULL);
}

Solution

  • The problem is probably that you don't actually print the value of the pointer variable, instead you print its location. The address-of operator & returns a pointer to the variable.