Skip to main content
GameDev.net gamedev.net
🔒 Locked

ReadProcessMemory()

Started by HIPOPO Jun 26, 2005 at 12:35 AM 1 replies 5.8k views
Original Post
HIPOPO
HIPOPO
I am programming in C++, and I was wanting to use ReadProcessMemory() function to retrieve information on another program. I have tried using it and it can't read from the process, which leads me to believe that there is more code needed then just ReadProcessMemory() function. Googling it confused the heck out of me. I was woundering if anyone could help me on using ReadProcessMemory() to read a memory address from another program. Thanks for the help once again.
Drew_Benton
Drew_Benton
Sure, take a look at my post here (last entry), it shows my code for a program that uses that function to track variables in another user made program. Take a look at it and see if you can get what you need, if not, feel free to ask for clarifications! The basic gist of it though is this:

1. Get the Process ID (PID) of the program you want to read memory from.

EX: (Program to read from)
ProcessID = GetCurrentProcessId();


2. Get the process handle of the program you want to read memory by calling OpenProcess.

EX: (Program to read to)
HWND clientHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID );


3. Read in a block of memory based on size

EX:
// Stores the address we want to read from, must be known from client program ahead of time!
int address = (0x040000);
// Need this to store bytes read
DWORD bytesRead = 0;
// Since I was reading in an integer
int buffer = -1;
ReadProcessMemory( clientHandle, (int*)(address), &buffer, sizeof(int), &bytesRead );


That's aboit it really.
HIPOPO
HIPOPO
Wow, thanks for the fast reply. I didn't know it was that easy. My problem was I was using a HWND instead of the HANDLE :/. Thanks again for the help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.