Skip to content

Commit

Permalink
Enhancement: Preparing SIMD pattern search method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceiridge committed Aug 1, 2021
1 parent 7c2b178 commit 9b1e614
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChromePatcherDll/ChromePatcherDll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,15 @@
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="patches.cpp" />
<ClCompile Include="simdpatternsearcher.cpp" />
<ClCompile Include="simplepatternsearcher.cpp" />
<ClCompile Include="threads.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="dllmain.hpp" />
<ClInclude Include="patches.hpp" />
<ClInclude Include="resource.h" />
<ClInclude Include="simdpatternsearcher.hpp" />
<ClInclude Include="simplepatternsearcher.hpp" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="threads.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions ChromePatcherDll/ChromePatcherDll.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<ClCompile Include="simplepatternsearcher.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="simdpatternsearcher.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="patches.hpp">
Expand All @@ -47,6 +50,9 @@
<ClInclude Include="simplepatternsearcher.hpp">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="simdpatternsearcher.hpp">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ChromePatcherDll.rc">
Expand Down
1 change: 1 addition & 0 deletions ChromePatcherDll/patches.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "patches.hpp"
#include "simplepatternsearcher.hpp"
#include "simdpatternsearcher.hpp"

#define ReadVar(variable) file.read(reinterpret_cast<char*>(&variable), sizeof(variable)); // Makes everything easier to read

Expand Down
10 changes: 10 additions & 0 deletions ChromePatcherDll/simdpatternsearcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "stdafx.h"
#include "patches.hpp"
#include "simdpatternsearcher.hpp"

namespace ChromePatch {
byte* SimdPatternSearcher::SearchBytePattern(Patch& patch, byte* startAddr, size_t length) {
// TODO
return nullptr;
}
}
12 changes: 12 additions & 0 deletions ChromePatcherDll/simdpatternsearcher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

namespace ChromePatch {
class
#ifdef _DEBUG
__declspec(dllexport)
#endif
SimdPatternSearcher : PatternSearcher {
public:
byte* SearchBytePattern(Patch& patch, byte* startAddr, size_t length) override;
};
}
1 change: 1 addition & 0 deletions ChromePatcherDll/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
#include <TlHelp32.h>
#include <thread>
#include <iomanip>
#include <immintrin.h>

inline HMODULE module;
12 changes: 12 additions & 0 deletions ChromePatcherDllUnitTests/patterntests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "CppUnitTest.h"
#include "patches.hpp"
#include "simplepatternsearcher.hpp"
#include "simdpatternsearcher.hpp"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

Expand Down Expand Up @@ -39,6 +40,17 @@ namespace ChromePatch {
Assert::AreEqual(simpleSearcher->SearchBytePattern(createdPatches[1], testBytes.Bytes, testBytes.BytesLength), testBytes.Pattern2Ptr);
}

TEST_METHOD(SimdPatternSearcherTest) {
const TestBytes testBytes = CreateTestBytes();
Assert::AreEqual(testBytes.BytesLength, BYTE_ARRAY_SIZE);

auto simdSearcher = std::make_unique<SimdPatternSearcher>();
std::vector<Patch> createdPatches = CreatePatches();

Assert::AreEqual(simdSearcher->SearchBytePattern(createdPatches[0], testBytes.Bytes, testBytes.BytesLength), testBytes.Pattern1Ptr);
Assert::AreEqual(simdSearcher->SearchBytePattern(createdPatches[1], testBytes.Bytes, testBytes.BytesLength), testBytes.Pattern2Ptr);
}

private:
// Create two patches: Patch 1 has 2 patterns, of which one has a result. Patch 2 has 1 pattern with a result, but with offsets.
static std::vector<Patch> CreatePatches() {
Expand Down

0 comments on commit 9b1e614

Please sign in to comment.