#include <functional>
#include <../thirdparty/Detours/src/detours.h>
Go to the source code of this file.
|
| #define | FUNCTION_PTR(RETURN_TYPE, CALLING_CONVENTION, FUNCTION_NAME, ADDRESS, ...) |
| #define | IMPORT_FUNCTION_PTR(RETURN_TYPE, LIBRARY_NAME, FUNCTION_NAME, ...) |
| #define | HOOK(RETURN_TYPE, CALLING_CONVENTION, FUNCTION_NAME, ADDRESS, ...) |
| #define | STATIC_HOOK(RETURN_TYPE, CALLING_CONVENTION, FUNCTION_NAME, ADDRESS, ...) |
| #define | GET_STATIC_HOOK_RESULT(FUNCTION_NAME) |
| #define | VFTABLE_HOOK(RETURN_TYPE, CALLING_CONVENTION, CLASS_NAME, FUNCTION_NAME, ...) |
| #define | STATIC_VFTABLE_HOOK(RETURN_TYPE, CALLING_CONVENTION, CLASS_NAME, FUNCTION_NAME, ...) |
| #define | GET_STATIC_VFTABLE_HOOK_RESULT(CLASS_NAME, FUNCTION_NAME) |
| #define | INSTALL_HOOK(FUNCTION_NAME) |
| #define | INSTALL_HOOK_EXPLICIT(FUNCTION_NAME, ADDRESS) |
| #define | UNINSTALL_HOOK(FUNCTION_NAME) |
| #define | INSTALL_VFTABLE_HOOK(CLASS_NAME, INSTANCE, FUNCTION_NAME, FUNCTION_INDEX) |
| #define | UNINSTALL_VFTABLE_HOOK(CLASS_NAME, FUNCTION_NAME) |
◆ FUNCTION_PTR
| #define FUNCTION_PTR |
( |
| RETURN_TYPE, |
|
|
| CALLING_CONVENTION, |
|
|
| FUNCTION_NAME, |
|
|
| ADDRESS, |
|
|
| ... ) |
Value:RETURN_TYPE (CALLING_CONVENTION* FUNCTION_NAME)(__VA_ARGS__) = (RETURN_TYPE (CALLING_CONVENTION*)(__VA_ARGS__))(ADDRESS)
Declares a pointer to a function in memory.
- Parameters
-
| RETURN_TYPE | The return type of the function. |
| CALLING_CONVENTION | The calling convention of the function (e.g. __cdecl, __stdcall, __fastcall, etc). This does not support optimised calling conventions, such as __usercall or __userpurge. |
| FUNCTION_NAME | The name of the function. |
| ADDRESS | The address of the function. |
| __VA_ARGS__ | The parameters of the function. |
◆ GET_STATIC_HOOK_RESULT
| #define GET_STATIC_HOOK_RESULT |
( |
| FUNCTION_NAME | ) |
|
Value:Gets the installation result of a hook defined with STATIC_HOOK, STATIC_USER_HOOK or STATIC_ASM_HOOK.
- Parameters
-
| FUNCTION_NAME | The name of the function that was hooked. |
- Returns
- true if the installation succeeeded. Otherwise, false.
◆ GET_STATIC_VFTABLE_HOOK_RESULT
| #define GET_STATIC_VFTABLE_HOOK_RESULT |
( |
| CLASS_NAME, |
|
|
| FUNCTION_NAME ) |
Value:result_##CLASS_NAME##_##FUNCTION_NAME
Gets the installation result of a hook defined with STATIC_VFTABLE_HOOK.
- Parameters
-
| CLASS_NAME | The name of the class that contains the function that was hooked. |
| FUNCTION_NAME | The name of the function that was hooked. |
- Returns
- true if the installation succeeeded. Otherwise, false.
◆ HOOK
| #define HOOK |
( |
| RETURN_TYPE, |
|
|
| CALLING_CONVENTION, |
|
|
| FUNCTION_NAME, |
|
|
| ADDRESS, |
|
|
| ... ) |
Value:typedef RETURN_TYPE CALLING_CONVENTION FUNCTION_NAME(__VA_ARGS__); \
FUNCTION_NAME* x_##FUNCTION_NAME = (FUNCTION_NAME*)(ADDRESS); \
FUNCTION_NAME* original_##FUNCTION_NAME = x_##FUNCTION_NAME; \
FUNCTION_NAME* post_##FUNCTION_NAME{}; \
RETURN_TYPE CALLING_CONVENTION impl_##FUNCTION_NAME(__VA_ARGS__)
Defines the body of a hook for a function in memory.
- Parameters
-
| RETURN_TYPE | The return type of the function. |
| CALLING_CONVENTION | The calling convention of the function (e.g. __cdecl, __stdcall, __fastcall, etc). This does not support optimised calling conventions, such as __usercall or __userpurge. |
| FUNCTION_NAME | The name of the function. |
| ADDRESS | The address of the function. |
| __VA_ARGS__ | The parameters of the function. |
◆ IMPORT_FUNCTION_PTR
| #define IMPORT_FUNCTION_PTR |
( |
| RETURN_TYPE, |
|
|
| LIBRARY_NAME, |
|
|
| FUNCTION_NAME, |
|
|
| ... ) |
Value:typedef RETURN_TYPE _##FUNCTION_NAME(__VA_ARGS__); \
_##FUNCTION_NAME* FUNCTION_NAME = (_##FUNCTION_NAME*)
IMPORT_FUNC(LIBRARY_NAME, #FUNCTION_NAME);
#define IMPORT_FUNC(LIBRARY_NAME, FUNCTION_NAME)
Definition Preprocessor.h:3
Loads a dynamic link library into memory and declares a pointer to an exported function from it.
- Parameters
-
| RETURN_TYPE | The return type of the function. |
| LIBRARY_NAME | The name of the dynamic link library. |
| FUNCTION_NAME | The name of the exported function. |
| __VA_ARGS__ | The parameters of the exported function. |
◆ INSTALL_HOOK
| #define INSTALL_HOOK |
( |
| FUNCTION_NAME | ) |
|
Value:
#define INSTALL_HOOK_EXPLICIT(FUNCTION_NAME, ADDRESS)
Definition Hooking.h:239
Installs a hook defined with HOOK or ASM_HOOK.
- Parameters
-
| FUNCTION_NAME | The name of the function to call before the original. |
- Returns
- true if the installation succeeeded, or if the hook was already installed. Otherwise, false.
◆ INSTALL_HOOK_EXPLICIT
| #define INSTALL_HOOK_EXPLICIT |
( |
| FUNCTION_NAME, |
|
|
| ADDRESS ) |
Value:std::invoke([&]() \
{ \
if (!original_##FUNCTION_NAME && !(ADDRESS)) \
return false; \
\
*(void**)&original_##FUNCTION_NAME = (void*)(ADDRESS); \
\
DetourTransactionBegin(); \
DetourUpdateThread(GetCurrentThread()); \
DetourAttach((void**)&original_##FUNCTION_NAME, &impl_##FUNCTION_NAME); \
\
const auto result = DetourTransactionCommit() == NO_ERROR; \
\
if (result) \
\
return result; \
})
void * GetPostHookAddress(void *in_pHookStart)
Definition Hooking.h:322
Installs a hook defined with HOOK or ASM_HOOK at an explicit address.
- Parameters
-
| FUNCTION_NAME | The name of the function to call before the original. |
| ADDRESS | The address of the function to hook. |
- Returns
- true if the installation succeeeded, or if the hook was already installed. Otherwise, false.
◆ INSTALL_VFTABLE_HOOK
| #define INSTALL_VFTABLE_HOOK |
( |
| CLASS_NAME, |
|
|
| INSTANCE, |
|
|
| FUNCTION_NAME, |
|
|
| FUNCTION_INDEX ) |
Value:std::invoke([&]() \
{ \
if (original_##CLASS_NAME##_##FUNCTION_NAME) \
return true; \
\
original_##CLASS_NAME##FUNCTION_NAME = (*(CLASS_NAME##_##FUNCTION_NAME***)INSTANCE)[FUNCTION_INDEX]; \
\
DetourTransactionBegin(); \
DetourUpdateThread(GetCurrentThread()); \
DetourAttach((void**)&original##CLASS_NAME##_##FUNCTION_NAME, impl_##CLASS_NAME##_##FUNCTION_NAME); \
\
const auto result = DetourTransactionCommit() == NO_ERROR; \
\
if (result) \
\
return result; \
})
Installs a hook defined with VFTABLE_HOOK.
- Parameters
-
| CLASS_NAME | The name of the class that contains the function being hooked. |
| INSTANCE | A pointer to an instance of the class to extract the virtual function table pointer from. |
| FUNCTION_NAME | The name of the function to call before the original. |
| FUNCTION_INDEX | The index of the function to hook. |
- Returns
- true if the installation succeeeded, or if the hook was already installed. Otherwise, false.
◆ STATIC_HOOK
| #define STATIC_HOOK |
( |
| RETURN_TYPE, |
|
|
| CALLING_CONVENTION, |
|
|
| FUNCTION_NAME, |
|
|
| ADDRESS, |
|
|
| ... ) |
Value:HOOK(RETURN_TYPE, CALLING_CONVENTION, FUNCTION_NAME, ADDRESS, __VA_ARGS__); \
__CMNLIB_INTERNAL_STATIC_HOOK_IMPL(FUNCTION_NAME, ADDRESS,
INSTALL_HOOK) \
RETURN_TYPE CALLING_CONVENTION impl_##FUNCTION_NAME(__VA_ARGS__)
#define INSTALL_HOOK(FUNCTION_NAME)
Definition Hooking.h:228
#define HOOK(RETURN_TYPE, CALLING_CONVENTION, FUNCTION_NAME, ADDRESS,...)
Definition Hooking.h:54
Defines the body of a hook for a function in memory, and installs it upon initialisation.
- Parameters
-
| RETURN_TYPE | The return type of the function. |
| CALLING_CONVENTION | The calling convention of the function (e.g. __cdecl, __stdcall, __fastcall, etc). This does not support optimised calling conventions, such as __usercall or __userpurge. |
| FUNCTION_NAME | The name of the function. |
| ADDRESS | The address of the function. |
| __VA_ARGS__ | The parameters of the function. |
- Returns
- Use GET_STATIC_HOOK_RESULT.
◆ STATIC_VFTABLE_HOOK
| #define STATIC_VFTABLE_HOOK |
( |
| RETURN_TYPE, |
|
|
| CALLING_CONVENTION, |
|
|
| CLASS_NAME, |
|
|
| FUNCTION_NAME, |
|
|
| ... ) |
Value:STATIC_HOOK(RETURN_TYPE, CALLING_CONVENTION, CLASS_NAME##_##FUNCTION_NAME,
nullptr, __VA_ARGS__)
#define STATIC_HOOK(RETURN_TYPE, CALLING_CONVENTION, FUNCTION_NAME, ADDRESS,...)
Definition Hooking.h:73
Defines the body of a hook for a function in a virtual function table in memory, and installs it upon initialisation.
- Parameters
-
| RETURN_TYPE | The return type of the function. |
| CALLING_CONVENTION | The calling convention of the function (e.g. __cdecl, __stdcall, __fastcall, etc). This does not support optimised calling conventions, such as __usercall or __userpurge. |
| CLASS_NAME | The name of the class that contains the function being hooked. |
| FUNCTION_NAME | The name of the function. |
| __VA_ARGS__ | The parameters of the function. |
- Returns
- Use GET_STATIC_VFTABLE_HOOK_RESULT.
◆ UNINSTALL_HOOK
| #define UNINSTALL_HOOK |
( |
| FUNCTION_NAME | ) |
|
Value:std::invoke([&]() \
{ \
if (x_##FUNCTION_NAME == original_##FUNCTION_NAME) \
return true; \
\
DetourTransactionBegin(); \
DetourUpdateThread(GetCurrentThread()); \
DetourDetach((void**)&original_##FUNCTION_NAME, &impl_##FUNCTION_NAME); \
\
return DetourTransactionCommit() == NO_ERROR; \
})
Uninstalls a hook installed with INSTALL_HOOK.
- Parameters
-
| FUNCTION_NAME | The name of the function to unhook. |
- Returns
- true if the uninstallation succeeeded, or if the hook was already uninstalled. Otherwise, false.
◆ UNINSTALL_VFTABLE_HOOK
| #define UNINSTALL_VFTABLE_HOOK |
( |
| CLASS_NAME, |
|
|
| FUNCTION_NAME ) |
Value:
#define UNINSTALL_HOOK(FUNCTION_NAME)
Definition Hooking.h:266
Uninstalls a hook installed with INSTALL_VFTABLE_HOOK.
- Parameters
-
| CLASS_NAME | The name of the class that contains the function that was hooked. |
| FUNCTION_NAME | The name of the function to unhook. |
- Returns
- true if the uninstallation succeeeded, or if the hook was already uninstalled. Otherwise, false.
◆ VFTABLE_HOOK
| #define VFTABLE_HOOK |
( |
| RETURN_TYPE, |
|
|
| CALLING_CONVENTION, |
|
|
| CLASS_NAME, |
|
|
| FUNCTION_NAME, |
|
|
| ... ) |
Value:HOOK(RETURN_TYPE, CALLING_CONVENTION, CLASS_NAME##_##FUNCTION_NAME,
nullptr, __VA_ARGS__)
Defines the body of a hook for a function in a virtual function table in memory.
- Parameters
-
| RETURN_TYPE | The return type of the function. |
| CALLING_CONVENTION | The calling convention of the function (e.g. __cdecl, __stdcall, __fastcall, etc). This does not support optimised calling conventions, such as __usercall or __userpurge. |
| CLASS_NAME | The name of the class that contains the function being hooked. |
| FUNCTION_NAME | The name of the function. |
| __VA_ARGS__ | The parameters of the function. |