ReadProcessMemory

Posts 1–15 of 28 · Page 1 of 2
ReadProcessMemory
This is used to read memory in a certain program

This is made for : wolfguardiann who asked me for help, and for anyone else who may need it

This is the entire code:

Now I will explain bit by bit.

Normal Everyday Stuff:
Code:
#include <windows.h>
#include <iostream>

using namespace std;
Declarations:
Code:
DWORD address = 0x100579C; // This is the address that we want to read from
int value = 0; // This will store our value. In my case, its an integer, which is the timer
DWORD pid; //This will store our Process ID, used to read/write into the memory
HWND hwnd; //Finally a handle to our window
Find the Window
Code:
hwnd = FindWindow(NULL,L"Minesweeper"); //Finds the Window called "Minesweeper"
	if(!hwnd) //If none, display an error
	{
	cout <<"Window not found!\n";
	cin.get();
	}
GetProcess
Code:
GetWindowThreadProcessId(hwnd,&pid); //Get the process id and place it in pid
	HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,pid); //Get permission to read
if(!phandle) //Once again, if it fails, tell us
		{
		cout <<"Could not get handle!\n";
		cin.get();
		}
Read
Code:
while(1)  //Forever, or until you force close the program
		{
		ReadProcessMemory(phandle,(void*)address,&value,sizeof(value),0); //Read what is in "address" and store it in "value", then what is the size of what we are going to read which is "value",and finally the number of bytes read, but I dont care about that so I put a 0, or NULL
		cout << value << "\n"; //Display it
		Sleep(1000); //I was reading the timer which increases every second, so I made my program go through that loop every second
Code:
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
	DWORD address = 0x100579C;
	int value = 0;
	DWORD pid;
	HWND hwnd;
        hwnd = FindWindow(NULL,L"Minesweeper");
	if(!hwnd)
	{
	cout <<"Window not found!\n";
	cin.get();
	}
	else
	{
	GetWindowThreadProcessId(hwnd,&pid);
	HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,pid);
		if(!phandle)
		{
		cout <<"Could not get handle!\n";
		cin.get();
		}
		else
		{
		while(1)
		{
		ReadProcessMemory(phandle,(void*)address,&value,sizeof(value),0);
		cout << value << "\n";
		Sleep(1000);
		}
		return 0;
		}
	}
}
This is basically it. If you still have issues or if I explained something wrong, please tell me. If you want a tutorial on how to write into memory, let me know as well.

Press Thanks!
Quote Originally Posted by Void View Post
Nice, but I say you should have explained the last parameter of ReadProcessMemory as well, it's useful sometimes.

PS: I've already taken ReadProcessMemory to the extreme.
http://www.mpgh.net/forum/31-c-c/200...tions-iat.html


How long did it take you to learn everything you know right now?
Quote Originally Posted by aanthonyz View Post


How long did it take you to learn everything you know right now?
8 years /short
Quote Originally Posted by Hell_Demon View Post
8 years /short
Wow I am only at 1.5 years max. Minimum would be 1 year.. I dont remember
Quote Originally Posted by Hell_Demon View Post
8 years /short
So,he started coding at 3?
Quote Originally Posted by Hell_Demon View Post
8 years /short
So around my age? Like when I started. You're 19 right?
Quote Originally Posted by fukojr2 View Post


So around my age? Like when I started. You're 19 right?
Nah, HD is 11, and Void is 8.
WDF, so your 11?
Are we talking about HD or me? o_O I haven't been programming for 8 years.
Quote Originally Posted by Void View Post
Are we talking about HD or me? o_O I haven't been programming for 8 years.
You.......
Quote Originally Posted by aanthonyz View Post
You.......
2 1/2 years about? idk.
Cool ,man , it worked , its showing the timer , so , if i acctualy wanna show the score, im only supposed to change

Code:
DWORD address = 0x100579C;
and here
Code:
  hwnd = FindWindow(NULL,L"Minesweeper");
so isntead of putting the adressdown there , i coudl only change it on DWORD and changing the Window name, Genious!!!

aanthonyz , TYVM for the support you gave me , i wont forget it , you will be on my respect list , everytime u need something , pm me , ill try my max to help you, tyvm for helping me till the end , Respect , peace , you are a good man , i hope some can hlep you with you Speech to Text , your a good man , someone will help you, anyways , Tyvm for helping me , you deserve much ... ill try for now on coding these things , and after , ill tryto make harder things , harder , and so on, if i have any probllems ill PM you , and if u need my help , pm me . tyvm once more!!!
Quote Originally Posted by wolfguardiann View Post
Cool ,man , it worked , its showing the timer , so , if i acctualy wanna show the score, im only supposed to change

Code:
DWORD address = 0x100579C;
and here
Code:
  hwnd = FindWindow(NULL,L"Minesweeper");
so isntead of putting the adressdown there , i coudl only change it on DWORD and changing the Window name, Genious!!!

aanthonyz , TYVM for the support you gave me , i wont forget it , you will be on my respect list , everytime u need something , pm me , ill try my max to help you, tyvm for helping me till the end , Respect , peace , you are a good man , i hope some can hlep you with you Speech to Text , your a good man , someone will help you, anyways , Tyvm for helping me , you deserve much ... ill try for now on coding these things , and after , ill tryto make harder things , harder , and so on, if i have any probllems ill PM you , and if u need my help , pm me . tyvm once more!!!
Thats it...
Quote Originally Posted by aanthonyz View Post
Thats it...
Nice , Thnak you very much , if you need someething else , pm me !!

also , if i have problems , you will be the first on the list!!
Posts 1–15 of 28 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?