I am trying to write to the memory of another process, I open it with permission 38h (VM_OPERATION, VM_READ, VM_WRITE), then i use VirtualProtectEx with permission 4h(PAGE_READWRITE), but i also tried PAGE_EXECUTEREADWRITE - same error later.
Then I invoke ReadProcessMemory, and successfully read out the value of a fix address. But as I try to write to that address with WriteProcessMemory i get the Errorcode 299 - ERROR_PARTIAL_COPY.
Does anyone know how to solve this?
EDIT: SOLVED - didnt pass the buffer to write as a reference but as a value
WriteProcessMemory is giving the error ERROR_PARTIAL_COPY
299 because the third argument, lpBuffer
, needs to be a pointer. Specifically a pointer to a local buffer that contains the data you intend to write to the target process. If for instance, the buffer is let's say an integer like:
int x = 5;
Then you would use &x
as the lpBuffer
argument. &
is the "address of` operator that returns a pointer to the variable.
Normally if you don't pass a pointer for this argument you would get a compiler error. Regardless, ERROR_PARTIAL_COPY means not all the bytes from the source buffer were written to the target process. This could happen for several reasons, especially if the lpBuffer argument did not point to a committed memory address with the correct permissions. Same things go if you messed up the 2nd argument of WriteProcessMemory also
Using VirtualProtectEx to get write permissions to the target memory page is also a recommended step like I do here:
void PatchEx(HANDLE hProcess, char* dst, char* src, int size)
{
DWORD oldprotect;
VirtualProtectEx(hProcess, dst, size, PAGE_EXECUTE_READWRITE, &oldprotect);
WriteProcessMemory(hProcess, dst, src, size, NULL);
VirtualProtectEx(hProcess, dst, size, oldprotect, &oldprotect);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With