Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/analogfeelings/hookplusplus
HookPlusPlus is a lightweight 2-file C++ library for hooking in Windows-based systems, licensed under GPL v3.0.
https://github.com/analogfeelings/hookplusplus
cpp easy-to-use example-code gpl3 gplv3 hooks library trampoline trampoline-hooking win32 windows
Last synced: 13 days ago
JSON representation
HookPlusPlus is a lightweight 2-file C++ library for hooking in Windows-based systems, licensed under GPL v3.0.
- Host: GitHub
- URL: https://github.com/analogfeelings/hookplusplus
- Owner: AnalogFeelings
- License: gpl-3.0
- Created: 2023-01-26T01:15:38.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-20T03:27:17.000Z (9 months ago)
- Last Synced: 2024-02-20T04:29:43.699Z (9 months ago)
- Topics: cpp, easy-to-use, example-code, gpl3, gplv3, hooks, library, trampoline, trampoline-hooking, win32, windows
- Language: C++
- Homepage:
- Size: 30.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# HookPlusPlus - Hooking made easy.
![Lines of code](https://img.shields.io/tokei/lines/github/AestheticalZ/hookplusplus?label=Lines%20of%20Code&style=flat-square)
![GitHub repo file count (custom path)](https://img.shields.io/github/directory-file-count/aestheticalz/hookplusplus/src?color=brightgreen&label=Library%20Files&style=flat-square)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/aestheticalz/hookplusplus?color=green&label=Code%20Size&style=flat-square)
![GitHub issues](https://img.shields.io/github/issues/aestheticalz/hookplusplus?label=Issues&style=flat-square)
![GitHub pull requests](https://img.shields.io/github/issues-pr/aestheticalz/hookplusplus?label=Pull%20Requests&style=flat-square)
![GitHub](https://img.shields.io/github/license/aestheticalz/hookplusplus?label=License&style=flat-square)
![GitHub Repo stars](https://img.shields.io/github/stars/aestheticalz/hookplusplus?label=Stargazers&style=flat-square)HookPlusPlus is a lightweight 2-file C++ library for hooking in Windows-based systems! No more looking around Google for any way to hook under both x86_64 and x86, because HookPlusPlus does both.
> [!IMPORTANT]
> Please read [SECURITY.md](SECURITY.md) before using.Usage is very simple, and below you can find some example code.
## Example
Say you have a DLL you want to attach whenever you want to debug something. In this case, here's the example code, with comments for your leisure.```cpp
#include "hookplusplus.h"// Define hooks.
HookPlusPlus::Hook* MessageBoxHookW = NULL;
HookPlusPlus::Hook* MessageBoxHookA = NULL;// REMEMBER! The impostor function's signature must match 1:1 the function you're trying to hook!
DWORD WINAPI HookedMessageBowW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
// Unperform patch to be able to call the original function.
MessageBoxHookW->UnperformPatch();DWORD returnCode = MessageBoxW(hWnd, L"Ah sorry mate, I just hooked this message box!\n- HookPlusPlus", L"Sorry!", uType);
// Perform it again.
MessageBoxHookW->PerformPatch();
return returnCode;
}// REMEMBER! The impostor function's signature must match 1:1 the function you're trying to hook!
DWORD WINAPI HookedMessageBowA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
// Unperform patch to be able to call the original function.
MessageBoxHookA->UnperformPatch();DWORD returnCode = MessageBoxA(hWnd, "Ah sorry mate, I just hooked this message box!\n- HookPlusPlus", "Sorry!", uType);
// Perform it again.
MessageBoxHookA->PerformPatch();return returnCode;
}BOOL APIENTRY DllMain(HMODULE hModule, DWORD callReason, LPVOID lpReserved)
{
switch (callReason)
{
case DLL_PROCESS_ATTACH:
// Create the hooks.
MessageBoxHookW = new HookPlusPlus::Hook("user32.dll", "MessageBoxW", &HookedMessageBowW);
MessageBoxHookA = new HookPlusPlus::Hook("user32.dll", "MessageBoxA", &HookedMessageBowA);// Perform the patches.
MessageBoxHookW->PerformPatch();
MessageBoxHookA->PerformPatch();break;
case DLL_PROCESS_DETACH:
// Remember: deleting hooks automatically unperforms patches.
delete MessageBoxHookW;
delete MessageBoxHookA;break;
}return TRUE;
}
```