ColdHook is a mini and simple open source memory hooking library for Windows x86/x64 made in C++. This library is mainly intended for a simple usage and especially for whoever has a small knowlegde of how hooks actually works. If you find any issue, feel free to report.
Read the functions documentation just below to understand how ColdHook must be used.
- Function hooking (Wrap mode, Function emulation mode).
- Custom bytes hooking (Ability to hook custom bytes provided by the user to a specified memory address).
- Ability to unhook/hook again with a single call once the hooking procedure is initialized.
- Ability to return the error ID if any error occurs during the library execution.
- Ability to re-calculate special instructions if needed.
- MSVC 2019 or higher build tools are required to compile this project.
-
This function Initializes a new hook by name.
-
int32_t InitFunctionHookByName( Hook_Info** OutputInfo, bool WrapFunction, bool CheckKBase, const char* ModulName, const char* FName, void* HookedF, int32_t* OutErrorCode);
-
-
OutputInfoA pointer to a variable pointer that will receive the Hook_Info structure to retrieve hook informations.
-
WrapFunctionIf this argument is false, the function will only pass the control to the provided function without the returning back option. Intended if you need to emulate the target function, otherwise set to true if you still need to call the original hooked function once you handled what you had to.
-
CheckKBaseIf this argument is true and the requested module name is kernel32.dll, the function will check if the kernelbase.dll module is present, if yes, the hook will be placed to the requested function on the kernelbase.dll module instead.
-
ModulNameA string buffer pointer of the module name that the hook target function is present at. If this paramater is NULL, the considered module will be the executable one.
-
FNameA string buffer pointer of the target desired function name where the hook must be installed to.
-
HookedFA function pointer where you wish to redirect the target function.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is an ID of the new hook that can be registered to the system later. If the function fails the return value is NULL. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function Initializes a new hook by addresses.
-
int32_t InitFunctionHookByAddress( Hook_Info** OutputInfo, bool WrapFunction, void* Target, void* HookedF, int32_t* OutErrorCode);
-
-
OutputInfoA pointer to a variable pointer that will receive the Hook_Info structure to retrieve hook informations.
-
WrapFunctionIf this argument is false, the function will only pass the control to the provided function without the returning back option. Intended if you need to emulate the target function, otherwise set to true if you still need to call the original hooked function once you handled what you had to.
-
TargetA pointer to the function that should be hooked.
-
HookedFA function pointer where you wish to redirect the target function.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is an ID of the new hook that can be registered to the system later. If the function fails the return value is NULL. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function Initializes a new hook using custom bytes provided by the user.
-
int32_t InitHookCustomData( Hook_Info** OutputInfo, void* Target, void* CustomData, size_t CSize, int32_t* OutErrorCode);
-
-
OutputInfoA pointer to a variable pointer that will receive the Hook_Info structure to retrieve hook informations.
-
TargetA pointer to the buffer that should be hooked.
-
CustomDataA function pointer where you wish to redirect the target function.
-
CSizeThe size in bytes that should be hooked.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is an ID of the new hook that can be registered to the system later. If the function fails the return value is NULL. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function restores the original bytes to the requested hook ID
-
bool UnHookRegisteredData( int32_t HookID, int32_t* OutErrorCode);
-
-
HookIDThe hook ID returned by the hook initializers functions.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is true. If the function fails the return value is false. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function restores the hook bytes to the requested hook ID
-
bool HookAgainRegisteredData( int32_t HookID, int32_t* OutErrorCode);
-
-
HookIDThe hook ID returned by the hook initializers functions.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is true. If the function fails the return value is false. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function initializes the ColdHook service
-
bool ServiceGlobalInit(int32_t* OutErrorCode);
-
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is true. If the function fails the return value is false. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function stops the ColdHook service and unhooks the data if any
-
bool ServiceGlobalShutDown(bool UnHook, int32_t* OutErrorCode);
-
-
UnHookIf this argument is set to true, every registered hooked function/address bytes will be restored, otherwise set it to false.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is true. If the function fails the return value is false. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function retrieves the registered Hook_Info structure by the ID.
-
bool RetrieveHookInfoByID( Hook_Info** OutputInfo, int32_t HookID, int32_t* OutErrorCode);
-
-
OutputInfoA pointer to a variable pointer that will receive the Hook_Info structure to retrieve hook informations.
-
HookIDThe hook ID returned by the hook initializers functions.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is true. If the function fails the return value is false. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function retrieves the registered hook ID structure by the Hook_Info structure.
-
bool RetrieveHookIDByInfo( Hook_Info* InputInfo, int32_t* OutHookID, int32_t* OutErrorCode);
-
-
InputInfoA pointer to the Hook_Info structure to give hook informations.
-
OutHookIDA pointer to a variable that will receive the registered hook ID.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is true. If the function fails the return value is false. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function stores on the ColdHook service the returned hook ID and the Hook_Info structure. This must be called when a new hook is initialized
-
bool ServiceRegisterHookInformation( Hook_Info* InputInfo, int32_t HookID, int32_t* OutErrorCode);
-
-
InputInfoA pointer to the Hook_Info structure to give the hook informations.
-
HookIDThe hook ID returned by the hook initializers functions.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is true. If the function fails the return value is false. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function removes on the ColdHook service the returned hook ID and the Hook_Info structure. This must be called when a new hook is initialized, this must not be called if the Hook ID status is still hooked
-
bool ServiceUnRegisterHookInformation( int32_t HookID, int32_t* OutErrorCode);
-
-
HookIDThe hook ID returned by the hook initializers functions.
-
OutErrorCodeA pointer to a variable that will receive the error id if the function fails. This paramater can be NULL.
-
-
If the function succeeds, the return value is true. If the function fails the return value is false. For more informations check the error ID stored in the variable provided in the
OutErrorCodeargument.
-
-
This function retrieves the string of the requested error code ID
-
const char* CHRetrieveErrorCodeString(int32_t InErrorCode);
-
-
InErrorCodeAn int32_t value which contains the error code ID.
-
-
If the function succeeds, the return value is the string of the requested error code ID. If the function fails the return value is Unknown error as string.
-
- Zydis disassembler for the hook trampoline
- MSDN: Documentation style.
- This project is also used on ColdAPI project, maybe something insteresting to look at.