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 


Searching good algorithm to scan Memory for strings.

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

Joined: 24 Jan 2014
Posts: 1
Location: ger

PostPosted: Fri Jan 24, 2014 11:51 am    Post subject: Searching good algorithm to scan Memory for strings. Reply with quote

Hey there,

I recently wrote a memory scanner which scans a process memory for a certain string. But itīs still not as fast as I wish. I would like to get a similar smooth speed as CE itself. May You ppl here can suggest me some pseudocode with a better algorithm for my scans.



Code:

                    if (bytesReadSize > 0)
                    {

                        //loop through the bytes one by one to look for the values
                        for (int j = 0; j < memory.Length - arraysDifference; j++)
                        {
                           
                            //if any value is equal to what we are looking for
                            if (memory[j] == sString[0])
                            {

                                //check char by char
                                for (int h = 1; h < sString.Length; h++)
                                {
                                    if (memory[j + h] != sString[h])
                                    {
                                        break;
                                    }
                                   
                                    if (h == (searchedByteArrayLenght - 1))
                                    {                                   
                                        Console.WriteLine(Convert.ToString(j + currentAdress, 16));
                                        rmAdress = j + currentAdress;                                     
                                    }
                                }
                            }
                        }
                    }
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jan 24, 2014 9:27 pm    Post subject: Reply with quote

Compare in chunks instead of byte by byte. Like 2 or 4 bytes at at a time. There's pretty much no reason to do single byte comparing.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Mon Jan 27, 2014 6:15 am    Post subject: Reply with quote

Wiccaan wrote:
Compare in chunks instead of byte by byte. Like 2 or 4 bytes at at a time. There's pretty much no reason to do single byte comparing.


Reading in chunks certainly makes sense, but if you're going to support wildcards it can be a lot easier to compare bytes vs a bunch of convoluted logic and bit manipulation. I'd say that if it's still too slow maybe look into multithreading or SIMD. Or, alternatively, look to eliminate entire scan regions with logic.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Mon Jan 27, 2014 8:22 am    Post subject: Reply with quote

Perhaps the memory reading part of the code is just slow.
E.g. reading mapped memory, reading blocks smaller than 4KB , reading readonly memory while the string is writable, etc...

_________________
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 -> 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