Skip to content

Commit

Permalink
Allow different target and destination types (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrackedMatter authored Dec 20, 2024
1 parent 3d0f378 commit de83823
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions include/safetyhook/easy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace safetyhook {
/// @param destination The address of the destination function.
/// @param flags The flags to use.
/// @return The InlineHook object.
template <typename T>
[[nodiscard]] InlineHook create_inline(T target, T destination, InlineHook::Flags flags = InlineHook::Default) {
template <typename T, typename U>
[[nodiscard]] InlineHook create_inline(T target, U destination, InlineHook::Flags flags = InlineHook::Default) {
return create_inline(reinterpret_cast<void*>(target), reinterpret_cast<void*>(destination), flags);
}

Expand All @@ -31,7 +31,7 @@ template <typename T>
/// @param destination The destination function.
/// @param flags The flags to use.
/// @return The MidHook object.
[[nodiscard]] MidHook create_mid(void* target, MidHookFn destination, MidHook::Flags = MidHook::Default);
[[nodiscard]] MidHook create_mid(void* target, MidHookFn destination, MidHook::Flags flags = MidHook::Default);

/// @brief Easy to use API for creating a MidHook.
/// @param target the address of the function to hook.
Expand Down
8 changes: 4 additions & 4 deletions include/safetyhook/inline_hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class InlineHook final {
/// @return The InlineHook or an InlineHook::Error if an error occurred.
/// @note This will use the default global Allocator.
/// @note If you don't care about error handling, use the easy API (safetyhook::create_inline).
template <typename T>
[[nodiscard]] static std::expected<InlineHook, Error> create(T target, T destination, Flags flags = Default) {
template <typename T, typename U>
[[nodiscard]] static std::expected<InlineHook, Error> create(T target, U destination, Flags flags = Default) {
return create(reinterpret_cast<void*>(target), reinterpret_cast<void*>(destination), flags);
}

Expand All @@ -132,9 +132,9 @@ class InlineHook final {
/// @param flags The flags to use.
/// @return The InlineHook or an InlineHook::Error if an error occurred.
/// @note If you don't care about error handling, use the easy API (safetyhook::create_inline).
template <typename T>
template <typename T, typename U>
[[nodiscard]] static std::expected<InlineHook, Error> create(
const std::shared_ptr<Allocator>& allocator, T target, T destination, Flags flags = Default) {
const std::shared_ptr<Allocator>& allocator, T target, U destination, Flags flags = Default) {
return create(allocator, reinterpret_cast<void*>(target), reinterpret_cast<void*>(destination), flags);
}

Expand Down

0 comments on commit de83823

Please sign in to comment.