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
96 lines (79 loc) · 2.64 KB
/
Copy pathScannerWorker.cs
File metadata and controls
96 lines (79 loc) · 2.64 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Threading;
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>
/// <param name="ct">The <see cref="CancellationToken"/> to stop the scan.</param>
/// <returns>An enumeration of all <see cref="ScanResult"/>s.</returns>
public IList<ScanResult> Search(byte[] data, int count, CancellationToken ct)
{
Contract.Requires(data != null);
var results = new List<ScanResult>();
var endIndex = count - comparer.ValueSize;
for (var i = 0; i < endIndex; i += settings.FastScanAlignment)
{
if (ct.IsCancellationRequested)
{
break;
}
if (comparer.Compare(data, i, out var result))
{
result.Address = (IntPtr)i;
results.Add(result);
}
}
return results;
}
/// <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="previousResults">The previous results to use.</param>
/// <param name="ct">The <see cref="CancellationToken"/> to stop the scan.</param>
/// <returns>An enumeration of all <see cref="ScanResult"/>s.</returns>
public IList<ScanResult> Search(byte[] data, int count, IEnumerable<ScanResult> previousResults, CancellationToken ct)
{
Contract.Requires(data != null);
Contract.Requires(previousResults != null);
var results = new List<ScanResult>();
var endIndex = count - comparer.ValueSize;
foreach (var previousResult in previousResults)
{
if (ct.IsCancellationRequested)
{
break;
}
var offset = previousResult.Address.ToInt32();
if (offset <= endIndex)
{
if (comparer.Compare(data, offset, previousResult, out var result))
{
result.Address = previousResult.Address;
results.Add(result);
}
}
}
return results;
}
}
}