From 3310e2eea1516045873dff89615d4fb4d56d217a Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 27 Apr 2017 02:25:37 +0200 Subject: [PATCH] Don't store size in patternie structure --- SilentPatch/Patterns.cpp | 11 +++++------ SilentPatch/Patterns.h | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/SilentPatch/Patterns.cpp b/SilentPatch/Patterns.cpp index 9c692b9..f4aebce 100644 --- a/SilentPatch/Patterns.cpp +++ b/SilentPatch/Patterns.cpp @@ -144,8 +144,6 @@ void pattern::Initialize(const char* pattern, size_t length) // transform the base pattern from IDA format to canonical format TransformPattern(std::string_view(pattern, length), m_bytes, m_mask); - m_size = m_mask.size(); - #if PATTERNS_USE_HINTS // if there's hints, try those first if (m_module == GetModuleHandle(nullptr)) @@ -193,13 +191,14 @@ void pattern::EnsureMatches(uint32_t maxCount) const uint8_t* pattern = reinterpret_cast(m_bytes.c_str()); const char* mask = m_mask.c_str(); + size_t maskSize = m_mask.size(); size_t lastWild = m_mask.find_last_of('?'); ptrdiff_t Last[256]; std::fill(std::begin(Last), std::end(Last), lastWild == std::string::npos ? -1 : static_cast(lastWild) ); - for ( ptrdiff_t i = 0; i < static_cast(m_size); ++i ) + for ( ptrdiff_t i = 0; i < static_cast(maskSize); ++i ) { if ( Last[ pattern[i] ] < i ) { @@ -207,10 +206,10 @@ void pattern::EnsureMatches(uint32_t maxCount) } } - for (uintptr_t i = executable.begin(), end = executable.end() - m_size; i <= end;) + for (uintptr_t i = executable.begin(), end = executable.end() - maskSize; i <= end;) { uint8_t* ptr = reinterpret_cast(i); - ptrdiff_t j = m_size - 1; + ptrdiff_t j = maskSize - 1; while((j >= 0) && (mask[j] == '?' || pattern[j] == ptr[j])) j--; @@ -237,7 +236,7 @@ bool pattern::ConsiderMatch(uintptr_t offset) char* ptr = reinterpret_cast(offset); - for (size_t i = 0; i < m_size; i++) + for (size_t i = 0, j = m_mask.size(); i < j; i++) { if (mask[i] == '?') { diff --git a/SilentPatch/Patterns.h b/SilentPatch/Patterns.h index 0fb3473..4085b3e 100644 --- a/SilentPatch/Patterns.h +++ b/SilentPatch/Patterns.h @@ -75,8 +75,6 @@ namespace hook uint64_t m_hash; #endif - size_t m_size; - std::vector m_matches; bool m_matched;