Skip to content

Commit

Permalink
Add a function to retrieve the original target bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
angelfor3v3r committed Oct 25, 2023
1 parent 8f482ef commit c12b8ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/safetyhook/inline_hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ class InlineHook final {
/// @return The address of the trampoline to call the original function.
template <typename T> [[nodiscard]] T original() const { return reinterpret_cast<T>(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.
Expand Down Expand Up @@ -265,6 +269,8 @@ class InlineHook final {
}

private:
friend class MidHook;

uint8_t* m_target{};
uint8_t* m_destination{};
Allocation m_trampoline{};
Expand Down
4 changes: 4 additions & 0 deletions include/safetyhook/mid_hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(m_stub); }
Expand Down

0 comments on commit c12b8ab

Please sign in to comment.