4 Replies - 13014 Views - Last Post: 24 August 2008 - 11:46 AM Rate Topic: -----

#1 TheRofl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 13-August 08

ReadProcessMemory help

Posted 22 August 2008 - 08:17 PM

I have a code here that reads the value of an address, i would like to know if there is any way of reading the amount of bytes instead of the value.

#include <windows.h>
#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
	int address = 0x1005194;
	int value;
	DWORD pid;
	HWND hwnd = FindWindow(NULL,"Minesweeper");
	if(!hwnd)
	{
			 cout <<"Window not found!";
			 } else {
					GetWindowThreadProcessId(hwnd,&pid);
					HANDLE phandle = OpenProcess(PROCESS_ALL_ACCESS,0,pid);
					if(!phandle)
					{
								cout <<"Could not get handle!";
								} else {
									   ReadProcessMemory(phandle,(LPVOID)address,&value,2,0);
									   cout << value;
									   getch();
									   return 0;
									   }
									   }
									   }



Is This A Good Question/Topic? 0
  • +

Replies To: ReadProcessMemory help

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: ReadProcessMemory help

Posted 22 August 2008 - 09:17 PM

well you could find the number of bytes read... it is after all one of the parameters. However, you also tell it how many bytes to READ... so I am not sure how much help this is -- its purpose is to tell you if the function was successful.

So... basically, and I don't mean any offense by this, your question is a stupid one. YOU tell it how many bytes to read... if it can not read that many it does not read any.
Was This Post Helpful? 0
  • +
  • -

#3 TheRofl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 13-August 08

Re: ReadProcessMemory help

Posted 22 August 2008 - 09:38 PM

and how do i do that?
Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: ReadProcessMemory help

Posted 22 August 2008 - 09:47 PM

Quote

BOOL WINAPI ReadProcessMemory(
__in HANDLE hProcess,
__in LPCVOID lpBaseAddress,
__out LPVOID lpBuffer,
__in SIZE_T nSize,
__out SIZE_T *lpNumberOfBytesRead
);


Here is the function, it takes 5 parameters... the 4th is the number of bytes to read (you pass in 2), the last parameter would be a pointer to an int.

Generally the nSize parameter is calculated using the sizeof operator

so say lpBuffer pointed to an int, the nSize would be sizeof(int).
Was This Post Helpful? 0
  • +
  • -

#5 TheRofl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 13-August 08

Re: ReadProcessMemory help

Posted 24 August 2008 - 11:46 AM

Thx man,this helps alot.
Was This Post Helpful? 1

Page 1 of 1