diff --git a/SilentPatch/Patterns.cpp b/SilentPatch/Patterns.cpp index 0cfd8c4..f1c2215 100644 --- a/SilentPatch/Patterns.cpp +++ b/SilentPatch/Patterns.cpp @@ -45,12 +45,9 @@ typedef basic_fnv_1 fnv_1; namespace hook { - ptrdiff_t baseAddressDifference; - - // sets the base to the process main base - void set_base() + ptrdiff_t pattern::get_process_base() { - set_base((uintptr_t)GetModuleHandle(nullptr)); + return ptrdiff_t(GetModuleHandle(nullptr)); } @@ -112,13 +109,13 @@ private: uintptr_t m_begin; uintptr_t m_end; -public: template TReturn* getRVA(TOffset rva) { return (TReturn*)(m_begin + rva); } +public: explicit executable_meta(uintptr_t module) : m_begin(module) { diff --git a/SilentPatch/Patterns.h b/SilentPatch/Patterns.h index ba4de8c..7410707 100644 --- a/SilentPatch/Patterns.h +++ b/SilentPatch/Patterns.h @@ -16,34 +16,6 @@ namespace hook { - extern ptrdiff_t baseAddressDifference; - - // sets the base address difference based on an obtained pointer - inline void set_base(uintptr_t address) - { -#ifdef _M_IX86 - uintptr_t addressDiff = (address - 0x400000); -#elif defined(_M_AMD64) - uintptr_t addressDiff = (address - 0x140000000); -#endif - - // pointer-style cast to ensure unsigned overflow ends up copied directly into a signed value - baseAddressDifference = *(ptrdiff_t*)&addressDiff; - } - - // sets the base to the process main base - void set_base(); - - inline uintptr_t getRVA(uintptr_t rva) - { - set_base(); -#ifdef _M_IX86 - return static_cast(baseAddressDifference + 0x400000 + rva); -#elif defined(_M_AMD64) - return static_cast(baseAddressDifference(0x140000000 + rva); -#endif - } - class pattern_match { private: @@ -81,6 +53,8 @@ namespace hook uintptr_t m_rangeEnd; private: + static ptrdiff_t get_process_base(); + void Initialize(std::string_view pattern); bool ConsiderHint(uintptr_t offset); @@ -104,7 +78,7 @@ namespace hook public: pattern(std::string_view pattern) - : pattern(getRVA(0)) + : pattern(get_process_base()) { Initialize(std::move(pattern)); }