vic4key / Cpp-Hooking

Cpp Hooking - Set up function hooking easily and writing less code (P.S You can also find the python version @ https://github.com/vic4key/py-hooking.git)

Home Page:https://vic.onl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cpp Hooking (C++17 or later required)

With this library, you can set up function hooking easily and write less code.

It supports both Inline hooking & IAT hooking on both 32-bit & 64-bit.

Note: This library uses the Vutils INL/IAT Hooking backend.

Demo & Example

Eg. To hook/un-hook a function with the Inline Hooking technique, you only need to write codes as the following

#include "cpp-hooking/hooking.h"

// Define the hooking function
int WINAPI hkMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
  lpText = L"INL Hooked";
  return INLHookingManager::instance().invoke<int>(MessageBoxW, hWnd, lpText, lpCaption, uType);
}

// Perform hooking
INLHookingManager::instance().hook(MessageBoxW, hkMessageBoxW);

// Perform un-hooking
INLHookingManager::instance().unhook(MessageBoxW);

Eg. To hook/un-hook a function with the IAT Hooking technique, you only need to write codes as the following

#include "cpp-hooking/hooking.h"

// Define the hooking entry
#define Entry_MessageBoxW { "cpp-hooking.exe"s, "user32.dll"s, "MessageBoxW"s }

// Define the hooking function
int WINAPI hkMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
  lpText = L"IAT Hooked";
  return IATHookingManager::instance().invoke<int>(Entry_MessageBoxW, hWnd, lpText, lpCaption, uType);
}

// Perform hooking
IATHookingManager::instance().hook(Entry_MessageBoxW, hkMessageBoxW);

// Perform un-hooking
IATHookingManager::instance().unhook(Entry_MessageBoxW);

Documentation

See doc comments in the code files inside the cpp-hooking folder.

Installation

  1. Installed Vutils library
  2. Copy the cpp-hooking folder to your solution then #include "cpp-hooking\hooking.h"
  3. Enjoy

ToDo

Contact

Feel free to contact via Twitter / Gmail / Blog / Website

About

Cpp Hooking - Set up function hooking easily and writing less code (P.S You can also find the python version @ https://github.com/vic4key/py-hooking.git)

https://vic.onl

License:MIT License


Languages

Language:C++ 98.5%Language:C 1.5%