A mid function hook.
More...
#include <mid_hook.hpp>
|
| MidHook (const MidHook &)=delete |
| MidHook (MidHook &&other) noexcept |
MidHook & | operator= (const MidHook &)=delete |
MidHook & | operator= (MidHook &&other) noexcept |
void | reset () |
| Reset the hook.
|
uint8_t * | target () const |
| Get a pointer to the target.
|
uintptr_t | target_address () const |
| Get the address of the target.
|
MidHookFn | destination () const |
| Get the destination function.
|
const auto & | original_bytes () const |
| Returns a vector containing the original bytes of the target function.
|
| operator bool () const |
| Tests if the hook is valid.
|
std::expected< void, Error > | enable () |
| Enable the hook.
|
std::expected< void, Error > | disable () |
| Disable the hook.
|
bool | enabled () const |
| Check if the hook is enabled.
|
|
static std::expected< MidHook, Error > | create (void *target, MidHookFn destination_fn, Flags flags=Default) |
| Creates a new MidHook object.
|
template<typename T> |
static std::expected< MidHook, Error > | create (T target, MidHookFn destination_fn, Flags flags=Default) |
| Creates a new MidHook object.
|
static std::expected< MidHook, Error > | create (const std::shared_ptr< Allocator > &allocator, void *target, MidHookFn destination_fn, Flags flags=Default) |
| Creates a new MidHook object with a given Allocator.
|
template<typename T> |
static std::expected< MidHook, Error > | create (const std::shared_ptr< Allocator > &allocator, T target, MidHookFn destination_fn, Flags flags=Default) |
| Creates a new MidHook object with a given Allocator.
|
◆ Flags
Flags for MidHook.
Enumerator |
---|
Default | Default flags.
|
StartDisabled | Start the hook disabled.
|
◆ create() [1/4]
template<typename T>
std::expected< MidHook, Error > safetyhook::MidHook::create |
( |
const std::shared_ptr< Allocator > & | allocator, |
|
|
T | target, |
|
|
MidHookFn | destination_fn, |
|
|
Flags | flags = Default ) |
|
inlinestaticnodiscard |
Creates a new MidHook object with a given Allocator.
- Template Parameters
-
T | The type of the function to hook. |
- Parameters
-
allocator | The Allocator to use. |
target | The address of the function to hook. |
destination_fn | The destination function. |
flags | The flags to use. |
- Returns
- The MidHook object or a MidHook::Error if an error occurred.
- Note
- If you don't care about error handling, use the easy API (safetyhook::create_mid).
◆ create() [2/4]
std::expected< MidHook, Error > safetyhook::MidHook::create |
( |
const std::shared_ptr< Allocator > & | allocator, |
|
|
void * | target, |
|
|
MidHookFn | destination_fn, |
|
|
Flags | flags = Default ) |
|
staticnodiscard |
Creates a new MidHook object with a given Allocator.
- Parameters
-
allocator | The Allocator to use. |
target | The address of the function to hook. |
destination_fn | The destination function. |
flags | The flags to use. |
- Returns
- The MidHook object or a MidHook::Error if an error occurred.
- Note
- If you don't care about error handling, use the easy API (safetyhook::create_mid).
◆ create() [3/4]
template<typename T>
std::expected< MidHook, Error > safetyhook::MidHook::create |
( |
T | target, |
|
|
MidHookFn | destination_fn, |
|
|
Flags | flags = Default ) |
|
inlinestaticnodiscard |
Creates a new MidHook object.
- Parameters
-
target | The address of the function to hook. |
destination_fn | The destination function. |
flags | The flags to use. |
- Returns
- The MidHook object or a MidHook::Error if an error occurred.
- Note
- This will use the default global Allocator.
-
If you don't care about error handling, use the easy API (safetyhook::create_mid).
◆ create() [4/4]
std::expected< MidHook, Error > safetyhook::MidHook::create |
( |
void * | target, |
|
|
MidHookFn | destination_fn, |
|
|
Flags | flags = Default ) |
|
staticnodiscard |
Creates a new MidHook object.
- Parameters
-
target | The address of the function to hook. |
destination_fn | The destination function. |
flags | The flags to use. |
- Returns
- The MidHook object or a MidHook::Error if an error occurred.
- Note
- This will use the default global Allocator.
-
If you don't care about error handling, use the easy API (safetyhook::create_mid).
◆ destination()
MidHookFn safetyhook::MidHook::destination |
( |
| ) |
const |
|
inlinenodiscard |
Get the destination function.
- Returns
- The destination function.
◆ operator bool()
safetyhook::MidHook::operator bool |
( |
| ) |
const |
|
inlineexplicit |
Tests if the hook is valid.
- Returns
- true if the hook is valid, false otherwise.
◆ original_bytes()
const auto & safetyhook::MidHook::original_bytes |
( |
| ) |
const |
|
inlinenodiscard |
Returns a vector containing the original bytes of the target function.
- Returns
- A vector of the original bytes of the target function.
◆ reset()
void safetyhook::MidHook::reset |
( |
| ) |
|
Reset the hook.
This will remove the hook and free the stub.
- Note
- This is called automatically in the destructor.
◆ target()
uint8_t * safetyhook::MidHook::target |
( |
| ) |
const |
|
inlinenodiscard |
Get a pointer to the target.
- Returns
- A pointer to the target.
◆ target_address()
uintptr_t safetyhook::MidHook::target_address |
( |
| ) |
const |
|
inlinenodiscard |
Get the address of the target.
- Returns
- The address of the target.
The documentation for this class was generated from the following file: