mirror of
https://git.recroomarchive.org/Radium/libradhook.git
synced 2026-08-07 09:10:59 +00:00
feat: added capability for finding handle from target pointer
This commit is contained in:
@@ -42,6 +42,7 @@ enum class RadHookResult : int {
|
|||||||
InvalidHandle,
|
InvalidHandle,
|
||||||
TrampolineTooFar,
|
TrampolineTooFar,
|
||||||
TargetTooSmall,
|
TargetTooSmall,
|
||||||
|
UnknownTarget,
|
||||||
Unknown,
|
Unknown,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -412,4 +413,46 @@ RADHOOK_API
|
|||||||
RadHookResult
|
RadHookResult
|
||||||
RadHookApplyQueued();
|
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__
|
#endif // __LIBRADHOOK_API_H__
|
||||||
@@ -30,10 +30,8 @@
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
# if defined(RADHOOK_BUILD)
|
# if defined(RADHOOK_BUILD)
|
||||||
# define RADHOOK_API __declspec(dllexport)
|
# define RADHOOK_API __declspec(dllexport)
|
||||||
# elif defined(RADHOOK_SHARED)
|
|
||||||
# define RADHOOK_API __declspec(dllimport)
|
|
||||||
# else
|
# else
|
||||||
# define RADHOOK_API
|
# define RADHOOK_API __declspec(dllimport)
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# if defined(__GNUC__) || defined(__clang__)
|
# if defined(__GNUC__) || defined(__clang__)
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const char* RadHookResultToString(RadHookResult result) {
|
|||||||
case RadHookResult::InvalidHandle: return "InvalidHandle";
|
case RadHookResult::InvalidHandle: return "InvalidHandle";
|
||||||
case RadHookResult::TrampolineTooFar: return "TrampolineTooFar";
|
case RadHookResult::TrampolineTooFar: return "TrampolineTooFar";
|
||||||
case RadHookResult::TargetTooSmall: return "TargetTooSmall";
|
case RadHookResult::TargetTooSmall: return "TargetTooSmall";
|
||||||
|
case RadHookResult::UnknownTarget: return "UnknownTarget";
|
||||||
default: return "Unknown";
|
default: return "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -519,4 +520,15 @@ RadHookResult RadHookApplyQueued() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return last;
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
|
RadHookResult RadHookGetHandleFromTarget(void* target, RadHookHandle* outHandle) {
|
||||||
|
for (auto const& h : g_hooks) {
|
||||||
|
auto p = h.get();
|
||||||
|
if (p->target == target) {
|
||||||
|
*outHandle = p;
|
||||||
|
return RadHookResult::Success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return RadHookResult::UnknownTarget;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user