View previous topic :: View next topic |
Author |
Message |
Adversities Newbie cheater
Reputation: 0
Joined: 19 Aug 2016 Posts: 10
|
Posted: Wed Aug 31, 2016 10:28 pm Post subject: Can i improve my scan perfomance? |
|
|
Code: | int offSet = 0;
while ((offSet = Array.IndexOf(memoryBrick, pattern[0], offSet)) != -1)
{
if (pattern.Length > 1)
{
for (int i = 1; i < pattern.Length; i++)
{
if (memoryBrick.Length <= offSet + pattern.Length) break;
else if (pattern[i] != memoryBrick[offSet + i])
{
if (memoryBrick[offSet + i] == pattern[0])
{ offSet += (i - 1); break; }
else if (i == pattern.Length - 1)
{ offSet += i; break; }
break;
}
else if (i == pattern.Length - 1)
addresses.Add(new IntPtr((int)baseAddress + offSet));
}
}
else addresses.Add(new IntPtr((int)baseAddress + offSet));
offSet++;
} |
It searchs really fast, but it's atleast 10% slower than Cheat Engine, maybe i'm missing something in the logyc?
|
|
Back to top |
|
 |
Adversities Newbie cheater
Reputation: 0
Joined: 19 Aug 2016 Posts: 10
|
Posted: Sat Sep 03, 2016 9:20 pm Post subject: |
|
|
I'll anwer myself bcoz maybe there're some guys who wanna know the same.
The IndexOf function makes it slower than only using forloop so make sure to use for to get the matches indexers.
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
Back to top |
|
 |
Adversities Newbie cheater
Reputation: 0
Joined: 19 Aug 2016 Posts: 10
|
Posted: Sat Sep 03, 2016 9:27 pm Post subject: |
|
|
I've already implemented my own, but thanks. And also i've already asked to Dark Byte how he does it, just for know if i did the same.
Btw do you remember that SignatureScan class you translated to C#? i was wondering... currently do you've something better? i've my own but maybe i can improve it with yours.
GitHub > Adversities/Cheatool/blob/master/Cheatool/Memory/BoyerMoore.cs#L62 There's my wildcards shit, it's currently outdate, i've something better on IDE but let me know what you think.
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Sep 04, 2016 12:07 am Post subject: |
|
|
I have rewritten it for some personal projects that are not public. The main jist was making it dump all regions, scan within them in separate threads and use the lowest found value if multiples are found (or a specific count if the user gives a specific occurrence number).
The FindPattern function I rewrote though is:
Code: | public static uint FindPattern(byte[] data, string pattern)
{
try
{
// Trim the pattern from extra whitespace..
var trimPattern = pattern.Replace(" ", "").Trim();
// Convert the pattern to a byte array..
var patternMask = new List<bool>();
var patternData = Enumerable.Range(0, trimPattern.Length).Where(x => x % 2 == 0)
.Select(x =>
{
var bt = trimPattern.Substring(x, 2);
patternMask.Add(!bt.Contains('?'));
return bt.Contains('?') ? (byte)0 : Convert.ToByte(bt, 16);
}).ToArray();
// Scan the given data for our pattern..
for (var x = 0; x < data.Length; x++)
{
if (!patternData.Where((t, y) => patternMask[y] && t != data[x + y]).Any())
return (uint)x;
}
return 0;
}
catch
{
return 0;
}
} |
_________________
- Retired. |
|
Back to top |
|
 |
Adversities Newbie cheater
Reputation: 0
Joined: 19 Aug 2016 Posts: 10
|
Posted: Sun Sep 04, 2016 1:20 am Post subject: |
|
|
Looks nice, thank you. I got some ideas from this.
|
|
Back to top |
|
 |
|