Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


ReadProcessMemory

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jun 01, 2008 4:25 pm    Post subject: ReadProcessMemory Reply with quote

I have a question about the ReadProcessMemory parameters. More specifically, nSize. I understand it's the size in bytes. But I don't understand how I would know that. I mean, if I had something like...

Code:

...
LPVOID BaseAddress = 0x6C4A15B8
ReadProcessMemory(hProcess, BaseAddress, lpBuffer, sizeof(BaseAddress), NULL);


Would that be correct. But what if I wanted to do wath CE was doing, it would be smart to take chunks of memory, but then do I designate a large amount of bytes, i.e. 500000 bytes, would it read 500k of memory from the address and beyond, or would the reamining bytes be unfilled, so to speak? And, same question to WriteProcessMemory.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Sun Jun 01, 2008 4:29 pm    Post subject: Reply with quote

the size os how many bytes you want to read. If you wanted to read an int, you'd do sizeof(int) which is 4.

If you wanted to take a chunk:
lpBuffer[9000]
ReadProcessMemory(hProcess, BaseAddress, lpBuffer, 9000, NULL);

EDIT:
or do you mean you don't know the size of the memory the program has allocated for itself?

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Sun Jun 01, 2008 4:36 pm    Post subject: Reply with quote

The size param is for how many bytes you want it to read. The buffer that is allocated needs to be the same size or bigger or you will get errors during the read. You can also check if the read was successful or if it read what was needed with the lpNumberOfBytesRead param return.

For example, if you wanted to read 5000 addresses as bytes you could do:

Code:
char szByteArray[ 5000 ] = {0};
ReadProcessMemory( hProcHandle, BaseAddrOfStruct, &szByteArray, sizeof( szByteArray ), NULL );


Which would read 5000 bytes into szByteArray starting from the address passed as BaseAddrOfStruct.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Mon Jun 02, 2008 12:23 am    Post subject: Reply with quote

Still you have to make sure you're reading valid memory.
You can't just fill in 0 for the start adress and 0x7fffffff for size to read the complete memory, because there will be parts inbetween which aren't allocated.
Back to top
View user's profile Send private message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Mon Jun 02, 2008 12:34 am    Post subject: Reply with quote

I'm proud of myself for understanding most of it. But how is the memory viewer of the Cheat Engine created? Memory dump?
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Mon Jun 02, 2008 8:18 am    Post subject: Reply with quote

Think CE dumps by region and updates based on the region that is currently visible in the memory viewer. Can't really say for sure though since I don't know Delphi enough to look through the code to find the exact code that does this.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Mon Jun 02, 2008 8:23 pm    Post subject: Reply with quote

If you look on MSDN's documentation for ReadProcessMemory, it says that it will fail if not all of the memory is readable. As a result, you must use VirtualQuery(Ex) to enumerate all the memory regions that are readable.
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue Jun 03, 2008 10:01 am    Post subject: Reply with quote

Code:
  while (Virtualqueryex(processhandle,pointer(address),mbi,sizeof(mbi))<>0) and (address<stop) and ((address+mbi.RegionSize)>address) do
  begin
    if (mbi.State=mem_commit) and ((mbi.Protect and page_guard)=0) and (mbi.protect<>PAGE_NOACCESS) then  //look if it is commited
    begin
      //Scan for something or add the address to an array of scannable area's and scan later.
      //You can put you're ReadProcessMemory here.
    end;
    address:=dword(mbi.baseaddress)+mbi.RegionSize;
  end;

That's a part of the delphi code CE uses (taken from CEFuncProc.pas)
That's an example on how you can scan the memory of a process.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites