feat: added capability for finding handle from target pointer

This commit is contained in:
nexusverypro
2026-07-04 00:33:21 +01:00
parent 72c5d321f1
commit edf088f071
3 changed files with 56 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ enum class RadHookResult : int {
InvalidHandle,
TrampolineTooFar,
TargetTooSmall,
UnknownTarget,
Unknown,
};
@@ -412,4 +413,46 @@ RADHOOK_API
RadHookResult
RadHookApplyQueued();
_Success_(return == RadHookResult::Success)
/**
* @brief Finds a hook handle from a specified target.
*
* @param target Target.
* @param outHandle Receives the hook handle on success.
*
* @return Operation result.
*/
RADHOOK_API
RadHookResult
RadHookGetHandleFromTarget(
_In_ void* target,
_Out_ RadHookHandle* outHandle
);
_Success_(return == RadHookResult::Success)
/**
* @brief Finds a hook handle from a specified target function pointer.
*
* Convenience overload that accepts a typed function pointer for the target.
*
* @tparam TargetFn Target function pointer type.
* @param target Target function.
* @param outHandle Receives the hook handle on success.
*
* @return Operation result.
*/
template <typename TargetFn>
requires std::is_function_v<std::remove_pointer_t<TargetFn>>
RadHookResult
RadHookGetHandleFromTarget(
TargetFn target,
_Out_ RadHookHandle* outHandle
)
{
return RadHookGetHandleFromTarget(
reinterpret_cast<void*>(target),
outHandle
);
}
#endif // __LIBRADHOOK_API_H__

View File

@@ -30,10 +30,8 @@
#if defined(_WIN32)
# if defined(RADHOOK_BUILD)
# define RADHOOK_API __declspec(dllexport)
# elif defined(RADHOOK_SHARED)
# define RADHOOK_API __declspec(dllimport)
# else
# define RADHOOK_API
# define RADHOOK_API __declspec(dllimport)
# endif
#else
# if defined(__GNUC__) || defined(__clang__)