forked from ReClassNET/ReClass.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScannerWorker.cs
More file actions
75 lines (64 loc) · 2.12 KB
/
Copy pathScannerWorker.cs
File metadata and controls
75 lines (64 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using ReClassNET.MemoryScanner.Comparer;
namespace ReClassNET.MemoryScanner
{
internal class ScannerWorker
{
private readonly ScanSettings settings;
private readonly IScanComparer comparer;
public ScannerWorker(ScanSettings settings, IScanComparer comparer)
{
Contract.Requires(settings != null);
Contract.Requires(comparer != null);
this.settings = settings;
this.comparer = comparer;
}
/// <summary>
/// Uses the <see cref="IScanComparer"/> to scan the byte array for results.
/// </summary>
/// <param name="data">The data to scan.</param>
/// <param name="count">The length of the <paramref name="data"/> parameter.</param>
/// <returns>An enumeration of all <see cref="ScanResult"/>s.</returns>
public IEnumerable<ScanResult> Search(byte[] data, int count)
{
Contract.Requires(data != null);
var endIndex = count - comparer.ValueSize;
for (var i = 0; i < endIndex; i += settings.FastScanAlignment)
{
if (comparer.Compare(data, i, out var result))
{
result.Address = (IntPtr)i;
yield return result;
}
}
}
/// <summary>
/// Uses the <see cref="IScanComparer"/> to scan the byte array for results.
/// The comparer uses the provided previous results to compare to the current value.
/// </summary>
/// <param name="data">The data to scan.</param>
/// <param name="count">The length of the <paramref name="data"/> parameter.</param>
/// <param name="results">The previous results to use.</param>
/// <returns>An enumeration of all <see cref="ScanResult"/>s.</returns>
public IEnumerable<ScanResult> Search(byte[] data, int count, IEnumerable<ScanResult> results)
{
Contract.Requires(data != null);
Contract.Requires(results != null);
var endIndex = count - comparer.ValueSize;
foreach (var previous in results)
{
var offset = previous.Address.ToInt32();
if (offset <= endIndex)
{
if (comparer.Compare(data, offset, previous, out var result))
{
result.Address = previous.Address;
yield return result;
}
}
}
}
}
}