Skip to content

Commit

Permalink
Added: Basic test for FindAtOffset Overload
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Jul 8, 2022
1 parent 616bb59 commit 4e2785f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 27 additions & 0 deletions Reloaded.Memory.SigScan.Tests/ScannerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using Reloaded.Memory.Sigscan;
using Reloaded.Memory.Sigscan.Definitions.Structs;
using Xunit;

namespace Reloaded.Memory.SigScan.Tests
Expand Down Expand Up @@ -148,5 +149,31 @@ public void PatternNotFound()
Assert.False(resultCompiled.Found);
Assert.Equal(-1, resultCompiled.Offset);
}

[Fact]
public void FindAtOffset()
{
var scanner = new Scanner(_data);
var expectedOffsets = new int[]
{
2,
254
};

var numFound = 0;
var lastOffset = -1;

while (true)
{

lastOffset = scanner.FindPattern("7A", lastOffset + 1).Offset;
if (lastOffset == -1)
break;

Assert.Equal(expectedOffsets[numFound++], lastOffset);
}

Assert.Equal(2, numFound);
}
}
}
6 changes: 3 additions & 3 deletions Reloaded.Memory.Sigscan/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public PatternScanResult FindPattern(string pattern, int offset)
{
#if SIMD_INTRINSICS
if (Avx2.IsSupported)
return FindPatternAvx2(_dataPtr + offset, _dataLength - offset, pattern);
return FindPatternAvx2(_dataPtr + offset, _dataLength - offset, pattern).AddOffset(offset);

if (Sse2.IsSupported)
return FindPatternSse2(_dataPtr + offset, _dataLength - offset, pattern);
return FindPatternSse2(_dataPtr + offset, _dataLength - offset, pattern).AddOffset(offset);
#endif

return FindPatternCompiled(_dataPtr + offset, _dataLength - offset, pattern);
return FindPatternCompiled(_dataPtr + offset, _dataLength - offset, pattern).AddOffset(offset);
}

/// <inheritdoc/>
Expand Down

0 comments on commit 4e2785f

Please sign in to comment.