| 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?
|
Posted: Sun Jun 01, 2008 4:25 pm Post subject: ReadProcessMemory |
|
|
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 |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sun Jun 01, 2008 4:29 pm Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Sun Jun 01, 2008 4:36 pm Post subject: |
|
|
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 |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Mon Jun 02, 2008 12:23 am Post subject: |
|
|
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 |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Mon Jun 02, 2008 12:34 am Post subject: |
|
|
| 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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon Jun 02, 2008 8:18 am Post subject: |
|
|
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 |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Mon Jun 02, 2008 8:23 pm Post subject: |
|
|
| 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 |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Tue Jun 03, 2008 10:01 am Post subject: |
|
|
| 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 |
|
 |
|