Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WriteProcessMemory/ReadProcessMemory fail

Tags:

winapi

I tried using both ReadProcessMemory() and WriteProcessMemory() in my application,but in both cases I get one result - Only part of a ReadProcessMemory or WriteProcessMemory request was completed.

Has anyone met that error code before? I'm using Vista SP2,I tried to run as admistrator,but I till get that erorcode.

like image 248
Ivan Prodanov Avatar asked Apr 14 '26 05:04

Ivan Prodanov


1 Answers

Make sure you call VirtualProtectEx to set the correct protection level on the memory you want to read/write.

After thinking about it, it's probably not the problem since most memory has read access enabled, but to set the protection level do something like this (in C++)

(no error checking and just using a random memory address, but you should get the idea)

char buffer[256];
DWORD oldProtect = 0;
DWORD numRead = 0;
VirtualProtectEx( hProc, (LPVOID)0x77810F34, 256, PAGE_EXECUTE_READWRITE, &oldProtect );
ReadProcessMemory( hProc, (LPVOID)0x77810F34, buffer, 256, &numRead );
VirtualProtectEx( hProc, (LPVOID)0x77810F34, 256, oldProtect, NULL ); //restore the original protection when you're done
like image 103
Gerald Avatar answered Apr 16 '26 23:04

Gerald