Skip to content

Commit

Permalink
Enhancement: Preparing for cpu features check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceiridge committed Aug 1, 2021
1 parent 9b1e614 commit c4c9ef9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
14 changes: 10 additions & 4 deletions ChromePatcherDll/patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,15 @@ namespace ChromePatch {
}


auto simpleSearcher = std::make_unique<SimplePatternSearcher>();

// TODO: Externalize this function in different implementations (traditional and with SIMD support) and add multithreading
// TODO: Externalize this function in different implementations (traditional and with SIMD support) and add multi-threading
int Patches::ApplyPatches() {
std::unique_ptr<PatternSearcher> patternSearcher;
if(SimdPatternSearcher::IsCpuSupported()) {
patternSearcher = std::make_unique<SimdPatternSearcher>();
} else {
patternSearcher = std::make_unique<SimplePatternSearcher>();
}

int successfulPatches = 0;
std::cout << "Applying patches, please wait..." << std::endl;
HANDLE proc = GetCurrentProcess();
Expand All @@ -163,7 +168,8 @@ namespace ChromePatch {
continue;
}

byte* searchResult = simpleSearcher->SearchBytePattern(patch, static_cast<byte*>(mbi.BaseAddress), mbi.RegionSize);
// TODO: Check for cpu features and use the respective searcher & multi-threading
byte* searchResult = patternSearcher->SearchBytePattern(patch, static_cast<byte*>(mbi.BaseAddress), mbi.RegionSize);

if(searchResult == nullptr) {
std::cerr << "Pattern not found for patch " << patch << std::endl;
Expand Down
5 changes: 5 additions & 0 deletions ChromePatcherDll/simdpatternsearcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ namespace ChromePatch {
// TODO
return nullptr;
}

bool SimdPatternSearcher::IsCpuSupported() {
// TODO
return IsProcessorFeaturePresent(PF_AVX2_INSTRUCTIONS_AVAILABLE);
}
}
3 changes: 2 additions & 1 deletion ChromePatcherDll/simdpatternsearcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ namespace ChromePatch {
#ifdef _DEBUG
__declspec(dllexport)
#endif
SimdPatternSearcher : PatternSearcher {
SimdPatternSearcher : public PatternSearcher {
public:
byte* SearchBytePattern(Patch& patch, byte* startAddr, size_t length) override;
static bool IsCpuSupported();
};
}
2 changes: 1 addition & 1 deletion ChromePatcherDll/simplepatternsearcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ChromePatch {
#ifdef _DEBUG
__declspec(dllexport)
#endif
SimplePatternSearcher : PatternSearcher {
SimplePatternSearcher : public PatternSearcher {
public:
byte* SearchBytePattern(Patch& patch, byte* startAddr, size_t length) override;
};
Expand Down

0 comments on commit c4c9ef9

Please sign in to comment.