Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
vic4key committed Nov 11, 2023
1 parent 758afb9 commit 146320d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 67 deletions.
134 changes: 67 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
# 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](https://github.com/vic4key/Vutils/tree/54c7da0d9e1933932d357d0802a8e691b005388a) backend.*

## Demo & Example

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

```cpp
#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
```cpp
#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](cpp-hooking) folder.

## Installation

1. Installed [Vutils (revision 54c7da0)](https://github.com/vic4key/Vutils/tree/54c7da0d9e1933932d357d0802a8e691b005388a) library
2. Copy the [cpp-hooking](cpp-hooking) folder to your solution then `#include "cpp-hooking\hooking.h"`
3. Enjoy

## ToDo

- [ ] Merge to [Vutils](https://github.com/vic4key/Vutils.git) library

## Contact
Feel free to contact via [Twitter](https://twitter.com/vic4key) / [Gmail](mailto:vic4key@gmail.com) / [Blog](https://blog.vic.onl/) / [Website](https://vic.onl/)
# 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](https://github.com/vic4key/Vutils/tree/54c7da0d9e1933932d357d0802a8e691b005388a) backend.*

## Demo & Example

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

```cpp
#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
```cpp
#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](cpp-hooking) folder.

## Installation

1. Installed [Vutils](https://github.com/vic4key/Vutils.git) library
2. Copy the [cpp-hooking](cpp-hooking) folder to your solution then `#include "cpp-hooking\hooking.h"`
3. Enjoy

## ToDo

- [x] Merge to [Vutils](https://github.com/vic4key/Vutils.git) library

## Contact
Feel free to contact via [Twitter](https://twitter.com/vic4key) / [Gmail](mailto:vic4key@gmail.com) / [Blog](https://blog.vic.onl/) / [Website](https://vic.onl/)
2 changes: 2 additions & 0 deletions cpp-hooking/invokable.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

#pragma once

#ifndef _ANY_
#include <any>
#include <functional>
#endif // _ANY_

/**
* @brief The function-container that can hold any function prototype.
Expand Down
5 changes: 5 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// main.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <vu>
using namespace vu;

#ifndef VU_HAS_CPP_HOOKING
#include "cpp-hooking/hooking.h"
#endif

// Inline Hooking

Expand Down

0 comments on commit 146320d

Please sign in to comment.