Search code examples
c++memoryoffset

C++ memory address and offset writing / read


Hello sorry for my bad English. I want to calculate an address with offset.

The example I have got a base address: 0x00D2038 with offset 0x1c

I have tried this.

DWORD address = 0x004D2038;
DWORD offset = 0x1c;

DWORD base = (DWORD)(address + offset);
int old_value = 0;
int value = 3000;

//Obtain new address form the address whit offset.
DWORD addr2 =  ReadProcessMemory(phandle,(void*)base,&old_value,sizeof(old_value),0);

//Write Memory
WriteProcessMemory(phandle,(void*)addr2,&value,(DWORD)sizeof(value),NULL);

But it does not work. Memory is not changed. what is my error?


Solution

  • Think you have a simple typo -- Try;

    //Write Memory
    WriteProcessMemory(phandle,(void*)base,&value,(DWORD)sizeof(value),NULL);