KNSoft.SlimDetours 1.1.2-beta

This is a prerelease version of KNSoft.SlimDetours.
dotnet add package KNSoft.SlimDetours --version 1.1.2-beta
                    
NuGet\Install-Package KNSoft.SlimDetours -Version 1.1.2-beta
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KNSoft.SlimDetours" Version="1.1.2-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KNSoft.SlimDetours" Version="1.1.2-beta" />
                    
Directory.Packages.props
<PackageReference Include="KNSoft.SlimDetours" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KNSoft.SlimDetours --version 1.1.2-beta
                    
#r "nuget: KNSoft.SlimDetours, 1.1.2-beta"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=KNSoft.SlimDetours&version=1.1.2-beta&prerelease
                    
Install KNSoft.SlimDetours as a Cake Addin
#tool nuget:?package=KNSoft.SlimDetours&version=1.1.2-beta&prerelease
                    
Install KNSoft.SlimDetours as a Cake Tool
English (en-US) įŽ€äŊ“中文 (zh-CN)

<br>

KNSoft.SlimDetours

NuGet Downloads GitHub Actions Workflow Status PR Welcome GitHub License

SlimDetours is an improved Windows API hooking library base on Microsoft Detours.

Feature

Compared to the original Detours, the advantages are:

And here is a Todo List.

Usage

NuGet Downloads

TL;DR

KNSoft.SlimDetours package contains both of SlimDetours and the original Microsoft Detours.

Include header SlimDetours.h for KNSoft.SlimDetours, or header detours.h for the original Microsoft Detours, then link compiled library KNSoft.SlimDetours.lib.

NuGet package KNSoft.SlimDetours is out-of-the-box, install to project and the compiled library will be linked automatically.

#include <KNSoft/SlimDetours/SlimDetours.h> // KNSoft.SlimDetours
#include <KNSoft/SlimDetours/detours.h>     // Microsoft Detours

If your project configuration name is neither "Release" nor "Debug", MSBuild sheet in NuGet package cannot link compiled library automatically, link manually is required, for example:

#pragma comment(lib, "Debug/KNSoft.SlimDetours.lib")

The usage has been simplified, e.g. the hook only needs one line:

SlimDetoursInlineHook(TRUE, (PVOID*)&g_pfnXxx, Hooked_Xxx);  // Hook
...
SlimDetoursInlineHook(FALSE, (PVOID*)&g_pfnXxx, Hooked_Xxx); // Unhook

For more simplified API see InlineHook.c.

Details

The original Microsoft Detours style functions are also retained, but with a few differences:

hr = SlimDetoursTransactionBegin();
if (FAILED(hr))
{
    return hr;
}
hr = SlimDetoursAttach((PVOID*)&g_pfnXxx, Hooked_Xxx);
if (FAILED(hr))
{
    SlimDetoursTransactionAbort();
    return hr;
}
return SlimDetoursTransactionCommit();

Delay Hook

"Delay Hook" will set hooks automatically when target DLL loaded, supported on NT6+.

For example, call SlimDetoursDelayAttach to hook a.dll!FuncXxx automatically when a.dll loaded:

SlimDetoursDelayAttach((PVOID*)&g_pfnFuncXxx,
                       Hooked_FuncXxx,
                       L"a.dll",
                       L"FuncXxx",
                       NULL,
                       NULL);

Demo: DelayHook.c

Compatibility

Project building: support for the latest MSVC generation tools and SDKs is mainly considered. The code in this project is backwards compatible with the MSVC generation tool and GCC, but it depends on the NDK it depends on, see also SlimDetours.NDK.inl. Can be built with ReactOS.

Artifact integration: widely compatible with MSVC generation tools (support for VS2015 is known), and different compilation configurations (e.g., /MD, /MT).

Runtime environment: NT5 or above OS, x86/x64/ARM64 platforms.

[!CAUTION] In beta stage, should be used with caution. Some APIs may be altered frequently, please keep an eye out for the release notes.

License

GitHub License

KNSoft.SlimDetours is licensed under the MIT license.

Source is based on Microsoft Detours which is licensed under the MIT license.

Also uses KNSoft.NDK to access low-level Windows NT APIs and its Unit Test Framework.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.2-beta 65 2/27/2025
1.1.1-beta 85 2/10/2025
1.1.0-beta 82 10/31/2024
1.0.2-beta 71 10/11/2024
1.0.1-beta 89 8/13/2024
1.0.0-beta 70 7/25/2024