ReadProcessMemory

Posts 15 of 5 · Page 1 of 1
ReadProcessMemory
Not sure why but all of a sudden ReadProcessMemory isn't reading the amount of bytes I'm asking it to.
Code:
byte[] ReadBytes(uint address, int len) // (0x0D000000, 0x08000000) is what I pass through this
{
    int buffer = 0;
    byte[] output = new byte[len];
    ReadProcessMemory(HO_Process, (IntPtr)address, output, len, out buffer); // this makes buffers value 0x0031E000
    return output;
}
EDIT: Just so you know, ReadProcessMemory is returning false and GetLastError returns 0.
make sure the code is running at the same level or higher for access. I ran into this also.
Quote Originally Posted by Chaoscode View Post
make sure the code is running at the same level or higher for access. I ran into this also.
I don't know what was causing the issue but I restarted my PC and it started working again lol.
You should implement some sort of error checking. ReadProcessMemory returns 0 if it fails. Combine it with GetLastError() to get an error code you can look up on google. I had trouble with a remote thread, got the error code, was able to find it and see that I didn't have sufficient permissions.

Code:
if (ReadProcessMemory(HO_Process, (IntPtr)address, output, len, out buffer) ==0)
{
MessageBox.Show(NULL, "Error Reading Memory" +GetLastError(), "Error", MB_OK);
}
Return value

If the function succeeds, the return value is nonzero.
If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError.

The function fails if the requested read operation crosses into an area of the process that is inaccessible.
You're reading from 0x0 to 0x08000000, and it's extremely unlikely that the target process actually has all of that allocated...you're trying to read an address (many) that hasn't been allocated yet.

Use VirtualQueryEx() if you want to find all allocated memory regions.

edit: nvm, apparently it works. ? Not sure how, but ok.
Posts 15 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?