| View previous topic :: View next topic |
| Author |
Message |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
Posted: Tue Oct 07, 2008 2:05 am Post subject: memory scanner (slow) help |
|
|
im making a small memory editor but the scan is slow
well if i just scan with no result no problem it will be fast but when i get alot of result it will take time
i know the problem is that it take long time to write it to the hardware
thats why i wondering how i should save it in the memory and then save it to a file
there will be no difference if i save the result in a listbox than a txt file it will take the same time
| Code: |
ThreadId := GetWindowThreadProcessId(readfrom,@ProcessId);
HandleWindow := OpenProcess(PROCESS_ALL_ACCESS,False,ProcessId);
start := strtoint('$'+from.Text);
stop := strtoint('$'+scanto.Text);
valuetofind := strtoint(ScanValue.text);
AssignFile(WriteFile,ExtractFilePath(ParamStr(0))+FirstScanAddressTMP);
Rewrite(WriteFile) ;
if chooseScan = 0 then begin // if scan for exact value
while start < stop do begin
ReadProcessMemory(HandleWindow,Pointer(start),@value2,4,x);
if value2 = valuetofind then
WriteLn(WriteFile,inttohex(start,8) + '=' + inttostr(value2));
start := start+$1;
end;
end else // Stop Exact Scan;
|
_________________
dont complain about my english...
1*1 = 2?
Last edited by ups2000ups on Tue Oct 07, 2008 4:04 am; edited 1 time in total |
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Tue Oct 07, 2008 3:19 am Post subject: |
|
|
When writing the file, you're doing: inttohex(start, and also inttostr(value2).
An int takes up 4 bytes, but when you convert it to readable characters like you do it can take up much more. Just save it into the file as an int. Then you can also read it as an int when you open the file, and convert it to a string if nessecary.
|
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Tue Oct 07, 2008 4:07 am Post subject: |
|
|
About the speed. You're using ReadProcessMemory on every single byte of memory. ( start := start+$1; )
What you need to do is call RPM once on every section or so, and read that into a buffer. Then compare every byte of that buffer with what you're searching for.
And you could write int's to a text file but then you won't be able to view it with notepad or so.
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25975 Location: The netherlands
|
Posted: Tue Oct 07, 2008 5:17 am Post subject: |
|
|
yes, just read huge chunks of memory and then scan through that block
A ReadProcessMemory call takes time, so do as little of those calls as you can
Thats why you use virtualqueryex to find out which memory blocks are readable
Same for write operations. Instead of immediately writing to disk store the results in memory and only when full call the option to write. E.g have an array of 8196 dwords and when full write that.
I also don't recommend saving it as text but just as binary. This can later on help you make finding stuff faster. (No need to parse each single address back to a value)
Or (i know, it's unacceptable, but still):
look here: http://ce.colddot.nl/browser/Cheat%20Engine/memscan.pas
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Tue Oct 07, 2008 6:47 am Post subject: |
|
|
Yes I think CE's way is the fastest:
First VirtualQueryEx to find out the regions and make a list of those.
Then do ReadProcessMemory on every region.
After every region you should probably search for the desired value. If you first want to do all the RPM's and then search you'll need to allocate a lot of memory I guess.
Then when you've got a list of results write them to the file at once. (as binary)
It's probably even faster to have a dll injected into the process. Then tell the dll to search for a value and then the dll can either write the results to a file or give them back to your application. This is what hyperscan does in CE right?
Tombana
|
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25975 Location: The netherlands
|
Posted: Tue Oct 07, 2008 8:31 am Post subject: |
|
|
binary is just the way the computer stores values so no need for any conversion at all. (Only need to convert it to text using inttohex when displaying it on the screen, but internally it's just normal datatypes)
Just read the contents of the file into an array or a single dword. (if you care about speed, and your harddisk, go for an array)
let's say you have an array of dwords (e.g addresslist)
then just save addresslist as a block of bytes instead of converting it. And when loading it back you can also just load it back into memory without having to convert the text into bytes (so no need for a strtoint('$'+string))
It will require a slightly different way of filehandling though
e.g instead of usuign a textfile use a TFilestream or a normal "file" and then "Rewrite(WriteFile,1)" and using BlockRead/BlockWrite to read from it.
I recommend using TFileStream though, it makes the code more readable and still fast enough
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Thu Oct 09, 2008 2:48 am Post subject: |
|
|
I'm confused. You say | Quote: | | there will be no difference if i save the result in a listbox than a txt file it will take the same time | . That is false. Writing to a file takes orders of magnitude longer than writing to memory, unless you have used up all the available memory and are killing the swap space.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish |
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25975 Location: The netherlands
|
Posted: Thu Oct 09, 2008 9:17 am Post subject: |
|
|
about the found results,
CE doesn't actually put them all into the listbox.
The listbox just gets set how many lines big it should be so itr creates a valid scrollbox on the right, and then on scrolls it fetches only the items that are visible in the listbox (from first line visible to last line visible) and draws them on it
thats why when you have a huge list and scroll around you can see the harddisk led go up. (ce does cache in blocks of 1000 addresses so only on big scrollmovements it's noticable)
That's also why I use a addressfile in dword format, because the start of the needed address range can be found using (4*firstvisibleitemnr) instead of reading through each line until you've counted the correct number of lines
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Thu Oct 09, 2008 9:23 am Post subject: |
|
|
| Dark Byte wrote: | about the found results,
CE doesn't actually put them all into the listbox.
The listbox just gets set how many lines big it should be so itr creates a valid scrollbox on the right, and then on scrolls it fetches only the items that are visible in the listbox (from first line visible to last line visible) and draws them on it |
So does CE do the drawing manually like when it receives a WM_PAINT message? I know it's in delphi and there you don't have to handle the window messages yourself, but did you write your own drawing function?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25975 Location: The netherlands
|
Posted: Thu Oct 09, 2008 9:50 am Post subject: |
|
|
It's basically just a canvas.textout(x,y,text); (that's calling the windows api ExtTextOut)
In this case i'm only using a customdata listview and the only ownerdraw part is where I set the color of the canvas font to green or black depending if it's inside a module or not.
When using ondata it sends a request for each single item in the list where the data is requested for (e.g drawn) , which limits the processing a lot since it only has to read the memory of the visible items and only has to check if the visible items are inside a module. If it had to do that for a million addresses instead of only 20 then it would take several seconds to update each time
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Fri Oct 10, 2008 1:58 am Post subject: |
|
|
That's so clever
So when you would do this in 'normal' c++, so just win32api, you would create a listview with the 'ownerdraw' option set. Then when you receive a WM_PAINT you check what items are inside the visible region of the listbox and then call ExtTextOut with the correct color and stuff set.
I'm not sure about the ondata part. Is that a window message you receive?
Thanks,
Tombana
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25975 Location: The netherlands
|
Posted: Fri Oct 10, 2008 5:25 pm Post subject: |
|
|
ondata is based on a windows message after having been processed heavily by filters and what not (checked in the VCL sourcecode)
messages involved: CDDS_ITEMPREPAINT , CDDS_ITEMPOSTPAINT, CDDS_ITEMPREERASE, CDDS_ITEMPOSTERASE, LVN_GETDISPINFO
I use delphi because I hate gui coding a lot
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
|