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 


Cheat engine data parsing speed

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Source
View previous topic :: View next topic  
Author Message
Tris
How do I cheat?
Reputation: 0

Joined: 15 Jun 2008
Posts: 3

PostPosted: Mon Aug 08, 2011 8:13 am    Post subject: Cheat engine data parsing speed Reply with quote

I recently started coding a memory scanner. I itterate through all of the memory regions using VirtualQueryEx and store each memory region along with all of its data into a dictionary of <int, byte[]>. Everything in that part seems fine and is relitively fast.

When it comes to processing the data to find values it can take anywhere between 6 - 12 seconds to find a full list of values in a process that takes roughly 300mb memory usage. This isn't really ideal, especially for pointer scanning.

Essentially what I'm doing is:

Code:

foreach (KeyValuePair<int, byte[]> region in memoryRegions)
{
   for (int i = 0; i < region.Value.Length - dataSize; i++)
   {
      int value = BitConverter.ToInt32(region.Value, i);//(array, offset)
      if(value == desiredValue)
      {
         addies.Add(region.Key + i);
      }
   }
}


If I use bit shifting instead of BitConverter.ToInt32 the time is roughly the same.

If I convert desiredValue to a byte array before itteration then compare that to region.Value at the offset "i" it cuts the time in half but that's still roughly 3 - 6 seconds per scan which isn't acceptable for a pointer scan.

If I don't do any address comparison at all it still takes about 1-2 seconds just to loop through each byte in every memory region.

I assume I'm reading too many memory regions which aren't required or something like that. In VirtualQueryEx I do:

if ((meminfo.State & 0x1000) > 0 && (meminfo.Protect & (0x04 | 0x08 | 0x40 | 0x80)) > 0)

I also discard any memory region that fails ReadProcessMemory.

Is it a memory region issue or do I need to come up with a decent algorithm for parsing the data faster?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25791
Location: The netherlands

PostPosted: Tue Aug 09, 2011 8:52 am    Post subject: Reply with quote

it helps if you use defines instead of 0x1000, 0x04, 0x08, etc...
anyhow, The regions to scan for seem to be alright

One tip: After creating the region map split it up into smaller chunks and pass that to worker threads that do the reading (if you have a multicore system that can speed it up a bit)

if you want to make a pointerscan you will have to come up with a better algorithm.

Cheat Engine's pointerscanner for example doesn't really store the memory, but only the pointer values it encounters.
Each pointer value gets stored in a map, and for each pointer value I store which addresses contain that pointervalue (hence the occasional 4GB+ map database in memory...)

After building that list (that is the progresbar at the beginning) it checks which pointers have a value that point between the given address and the given address-structsize

Then for each address with that value it does the same until the maximum level is found and then continues with the next result

And to increase the speed the workload is split up between several threads that make use of the same pointermap map (it's read only anyhow so no slowdown by locks)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Source 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