Home > database >  WriteProcessMemory, program's value user's input value at the same time
WriteProcessMemory, program's value user's input value at the same time

Time:06-15

There is a program that stores a value in memory, like 100. I read that value using ReadProcessMemory():

ReadProcessMemory(processHandle, (LPVOID)(programBaseAddress   offsetProgramToBaseAdress), &baseAddress, sizeof(baseAddress), NULL);

After ReadProcessMemory(), baseaddress contains 100.

With this code:

int value{};
cin >> value;
WriteProcessMemory(processHandle, (LPVOID)(pointsAddress), &value, 4, 0);

I can change the value in the other program.

But I don't want to set the other program's value to just any value. I want to add the user's input to that value. I mean, the user inputs a number like 50, the result should be 150, not 50.

I tried this but it didn't work:

WriteProcessMemory(processHandle, (LPVOID)(pointsAddress), &baseAddress   value, 4, 0);

CodePudding user response:

You need to read the value first, then add the user's input to the value, then write the value back. Those are separate operations, don't try to mix them together (ie, &baseAddress value doesn't do what you think it does).

Try something like this instead:

int32_t value{};
ReadProcessMemory(processHandle, (LPVOID)(programBaseAddress   offsetProgramToBaseAdress), &value, sizeof(value), NULL);

int input{};
cin >> input;
value  = input;

WriteProcessMemory(processHandle, (LPVOID)pointsAddress, &value, sizeof(value), 0);
  • Related