HydraHook
Direct3D and Core Audio hooking library for Windows
Loading...
Searching...
No Matches
Hook< cc, retn, args > Class Template Reference

RAII Detours hook wrapper for function interception. More...

#include <Hook.h>

Public Member Functions

 Hook ()
 Constructs an unapplied hook.
 ~Hook () noexcept
 Destroys hook; removes if applied. Never throws.
template<typename T>
void apply (T pFunc, type detour)
 Attaches detour to target function.
void remove ()
 Removes hook if applied.
bool remove_nothrow () noexcept
 Removes hook if applied. Never throws; safe to call under loader lock.
retn call_orig (args ... p)
 Calls the original (unhooked) function.
bool is_applied () const
 Returns true if hook is currently applied.
type original () const
 Trampoline while applied; otherwise the address last passed to apply.

Detailed Description

template<CallConvention cc, typename retn, typename ... args>
class Hook< cc, retn, args >

RAII Detours hook wrapper for function interception.

Template Parameters
ccCalling convention (stdcall_t or cdecl_t).
retnReturn type.
argsArgument types.

Definition at line 85 of file Hook.h.

Constructor & Destructor Documentation

◆ Hook()

template<CallConvention cc, typename retn, typename ... args>
Hook< cc, retn, args >::Hook ( )
inline

Constructs an unapplied hook.

Definition at line 187 of file Hook.h.

◆ ~Hook()

template<CallConvention cc, typename retn, typename ... args>
Hook< cc, retn, args >::~Hook ( )
inlinenoexcept

Destroys hook; removes if applied. Never throws.

Definition at line 192 of file Hook.h.

References g_hookDestructorDetachSuppressed, and remove_nothrow().

Member Function Documentation

◆ apply()

template<CallConvention cc, typename retn, typename ... args>
template<typename T>
void Hook< cc, retn, args >::apply ( T pFunc,
type detour )
inline

Attaches detour to target function.

Parameters
pFuncPointer to target function (address to patch).
detourDetour function (same signature as target).
Exceptions
DetourExceptionon Detours API failure.

Definition at line 208 of file Hook.h.

Referenced by HydraHookMainThread().

◆ call_orig()

template<CallConvention cc, typename retn, typename ... args>
retn Hook< cc, retn, args >::call_orig ( args ... p)
inline

Calls the original (unhooked) function.

Definition at line 354 of file Hook.h.

Referenced by HydraHookMainThread().

◆ is_applied()

template<CallConvention cc, typename retn, typename ... args>
bool Hook< cc, retn, args >::is_applied ( ) const
inline

Returns true if hook is currently applied.

Definition at line 360 of file Hook.h.

◆ original()

template<CallConvention cc, typename retn, typename ... args>
type Hook< cc, retn, args >::original ( ) const
inline

Trampoline while applied; otherwise the address last passed to apply.

While the detour is attached, this is the Detours trampoline. A saved copy of that trampoline is valid only until detachment commits (remove, remove_nothrow, or a destructor that is not suppressed). Detours frees the trampoline at that commit. If destruction is suppressed, the trampoline stays valid until a later detach.

Definition at line 374 of file Hook.h.

◆ remove()

template<CallConvention cc, typename retn, typename ... args>
void Hook< cc, retn, args >::remove ( )
inline

Removes hook if applied.

Exceptions
DetourExceptionon Detours API failure.

Definition at line 265 of file Hook.h.

◆ remove_nothrow()

template<CallConvention cc, typename retn, typename ... args>
bool Hook< cc, retn, args >::remove_nothrow ( )
inlinenoexcept

Removes hook if applied. Never throws; safe to call under loader lock.

Returns
true if successfully removed or hook was not applied; false on error.

Definition at line 321 of file Hook.h.

Referenced by ~Hook().


The documentation for this class was generated from the following file: