From 7d5a79c01919fa2b10c65d9a931582b32928d251 Mon Sep 17 00:00:00 2001 From: yuv420p10le <139547685+yuv420p10le@users.noreply.github.com> Date: Mon, 26 Aug 2024 21:58:44 +0300 Subject: [PATCH] Added str_holder to support <16 length strings. --- windows/hook.cpp | 12 ++++++++---- windows/hook.hpp | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/windows/hook.cpp b/windows/hook.cpp index 3f58704..becb052 100644 --- a/windows/hook.cpp +++ b/windows/hook.cpp @@ -376,9 +376,11 @@ bool process_feature(const char* guid, [[maybe_unused]] uintptr_t caller) return false; } -uint64_t hook_is_feature_available(uintptr_t user, const char** feature) +uint64_t hook_is_feature_available(uintptr_t user, str_holder* feature) { - if(process_feature(*feature, reinterpret_cast(_ReturnAddress()) - get_current_process_handle())) + std::string_view str(feature->obj.length >= 16 ? feature->obj.str : feature->str); + + if(process_feature(str.data(), reinterpret_cast(_ReturnAddress()) - get_current_process_handle())) { return true; } @@ -386,10 +388,12 @@ uint64_t hook_is_feature_available(uintptr_t user, const char** feature) return _is_feature_available.call(user, feature); } -uint64_t* hook_map_find(uintptr_t* rcx, uintptr_t rdx, const char** str) +uint64_t* hook_map_find(uintptr_t* rcx, uintptr_t rdx, str_holder* str) { + std::string_view feature(str->obj.length >= 16 ? str->obj.str : str->str); + if(_feature_manager != nullptr && rcx == &_feature_manager->m_feature_map() && - process_feature(*str, reinterpret_cast(_ReturnAddress()) - get_current_process_handle())) + process_feature(feature.data(), reinterpret_cast(_ReturnAddress()) - get_current_process_handle())) { static uint64_t FAKE_PTR = 0; diff --git a/windows/hook.hpp b/windows/hook.hpp index 27d120c..a9016d8 100644 --- a/windows/hook.hpp +++ b/windows/hook.hpp @@ -24,11 +24,23 @@ public: member_at(uintptr_t, m_map_offset, m_feature_map); }; +union str_holder +{ + struct + { + const char* str; + uintptr_t pad[2]; + size_t length; + } obj; + + const char str[16]; +}; + uintptr_t get_current_process_handle(); std::optional> get_section_info(std::string_view name); std::optional sig_scan(const uintptr_t start, const uintptr_t end, std::string_view pattern); -uint64_t hook_is_feature_available(uintptr_t rcx, const char** guid); -uint64_t* hook_map_find(uintptr_t* rcx, uintptr_t rdx, const char** str); +uint64_t hook_is_feature_available(uintptr_t rcx, str_holder* guid); +uint64_t* hook_map_find(uintptr_t* rcx, uintptr_t rdx, str_holder* str); void hook_bitset_init(uintptr_t rcx, uintptr_t rdx); FeatureManager* hook_feature_manager_init(FeatureManager* rcx); void hook();