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 


[C++] Help with a byte-search code.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Cx
Master Cheater
Reputation: 0

Joined: 27 Jul 2007
Posts: 367

PostPosted: Tue Jan 01, 2008 6:24 pm    Post subject: [C++] Help with a byte-search code. Reply with quote

Wanted to make a byte-search that uses arrays, which was harder.
I'm a bad coder, so the result was messy, probably dysfunctional code.
Help!

Code:
VOID SearchBytes(BYTE BytePattern[], DWORD NumberOfBytes, DWORD StartAddress, DWORD EndAddress, DWORD ResultList[])
{
   DWORD ResultListSlot = 0;
   for (DWORD CurrentAddress = StartAddress; CurrentAddress <= EndAddress; CurrentAddress++)
   {
      for (DWORD CurrentByte = 0; CurrentByte <= NumberOfBytes; CurrentByte++)
      {
         if (*(BYTE*)CurrentAddress+CurrentByte != BytePattern[CurrentByte])
            break;
         if (CurrentByte == NumberOfBytes)
         {
            ResultList[ResultListSlot] = CurrentAddress;
            ResultListSlot++;
         }
            
      }

   }
}

Also, the break would only break out of the "for (DWORD CurrentByte = 0; CurrentByte <= NumberOfBytes; CurrentByte++)" loop, right?
And I asked and don't think that the return value of a proc can be an array, so I make it a prerequisite param. ;(

_________________

armed with this small butterfly net
i will face the world alone
& never be lonely.
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Tue Jan 01, 2008 6:34 pm    Post subject: Reply with quote

You can return an array, you just need to allocate memory for it and not make it a local variable (because those are destroyed when the function ends)
_________________
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: Wed Jan 02, 2008 1:37 am    Post subject: Reply with quote

I wrote a DLL to do this (not fully the way you are doing it) but to scan for a byte pattern (with masks) and such which you can find here:

http://forum.cheatengine.org/viewtopic.php?t=168493

Maybe it will help push you in the right direction for what you need. As appal said aswell, your return needs to be copied to a non-local variable since anything local in the function is destroyed when the function is done. So your return param should be a pointer to a variable to hold the return information.

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

Joined: 27 Jul 2007
Posts: 367

PostPosted: Wed Jan 02, 2008 1:47 am    Post subject: Reply with quote

Ah, right.
Thanks.

I won't make it a pointer to use it as a param... I'll just return the array... which seems a bit weird, but whatever.

_________________

armed with this small butterfly net
i will face the world alone
& never be lonely.
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