| View previous topic :: View next topic |
| Author |
Message |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Tue Jan 01, 2008 6:24 pm Post subject: [C++] Help with a byte-search code. |
|
|
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 |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Tue Jan 01, 2008 6:34 pm Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Wed Jan 02, 2008 1:37 am Post subject: |
|
|
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 |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Wed Jan 02, 2008 1:47 am Post subject: |
|
|
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 |
|
 |
|