From c12b8ab1008857fda0c303739f11246a6adec7b8 Mon Sep 17 00:00:00 2001 From: angelfor3v3r Date: Wed, 25 Oct 2023 02:53:20 -0400 Subject: [PATCH] Add a function to retrieve the original target bytes. --- include/safetyhook/inline_hook.hpp | 6 ++++++ include/safetyhook/mid_hook.hpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/include/safetyhook/inline_hook.hpp b/include/safetyhook/inline_hook.hpp index b773d99..a9c38da 100644 --- a/include/safetyhook/inline_hook.hpp +++ b/include/safetyhook/inline_hook.hpp @@ -149,6 +149,10 @@ class InlineHook final { /// @return The address of the trampoline to call the original function. template [[nodiscard]] T original() const { return reinterpret_cast(m_trampoline.address()); } + /// @brief Returns a vector containing the original bytes of the target function. + /// @return A vector of the original bytes of the target function. + [[nodiscard]] const auto& original_bytes() const { return m_original_bytes; } + /// @brief Calls the original function. /// @tparam RetT The return type of the function. /// @tparam ...Args The argument types of the function. @@ -265,6 +269,8 @@ class InlineHook final { } private: + friend class MidHook; + uint8_t* m_target{}; uint8_t* m_destination{}; Allocation m_trampoline{}; diff --git a/include/safetyhook/mid_hook.hpp b/include/safetyhook/mid_hook.hpp index 4aa927c..2d4fcaa 100644 --- a/include/safetyhook/mid_hook.hpp +++ b/include/safetyhook/mid_hook.hpp @@ -111,6 +111,10 @@ class MidHook final { /// @return The destination function. [[nodiscard]] MidHookFn destination() const { return m_destination; } + /// @brief Returns a vector containing the original bytes of the target function. + /// @return A vector of the original bytes of the target function. + [[nodiscard]] const auto& original_bytes() const { return m_hook.m_original_bytes; } + /// @brief Tests if the hook is valid. /// @return true if the hook is valid, false otherwise. explicit operator bool() const { return static_cast(m_stub); }