MinHook.NET
1.1.1
dotnet add package MinHook.NET --version 1.1.1
NuGet\Install-Package MinHook.NET -Version 1.1.1
<PackageReference Include="MinHook.NET" Version="1.1.1" />
<PackageVersion Include="MinHook.NET" Version="1.1.1" />
<PackageReference Include="MinHook.NET" />
paket add MinHook.NET --version 1.1.1
#r "nuget: MinHook.NET, 1.1.1"
#:package MinHook.NET@1.1.1
#addin nuget:?package=MinHook.NET&version=1.1.1
#tool nuget:?package=MinHook.NET&version=1.1.1
MinHook.NET
Introduction
MinHook.NET is a pure managed C# port of the brilliant MinHook library by Tsuda Kageyu (https://github.com/TsudaKageyu/minhook). The library has the capability of inline hooking native API calls, utilising .NET delegates for both the detoured and original function that is commonly called with the detour.
The project has attempted to keep within the simplistic spirit of the original MinHook library.
Quick Start
Simple example demonstrating the hooking of the MessageBoxW Windows API
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int MessageBoxW(IntPtr hWnd, String text, String caption, uint type);
//We need to declare a delegate that matches the prototype of the hooked function
[UnmanagedFunctionPointer(CallingConvention.StdCall,CharSet=CharSet.Unicode)]
delegate int MessageBoxWDelegate(IntPtr hWnd, string text, string caption, uint type);
//A variable to store the original function so that we can call
//within our detoured MessageBoxW handler
MessageBoxWDelegate MessageBoxW_orig;
//Our actual detour handler function
int MessageBoxW_Detour(IntPtr hWnd, string text, string caption, uint type) {
return MessageBoxW_orig(hWnd, "HOOKED: " + text, caption, type);
}
void ChangeMessageBoxMessage() {
using (HookEngine engine = new HookEngine()) {
MessageBoxW_orig = engine.CreateHook("user32.dll", "MessageBoxW", new MessageBoxWDelegate(MessageBoxW_Detour));
engine.EnableHooks();
//Call the PInvoke import to test our hook is in place
MessageBoxW(IntPtr.Zero, "Text", "Caption", 0);
}
}
Thanks
- The original MinHook library that this project is based on - https://github.com/TsudaKageyu/minhook
- The SharpDisasm project and Udis86 disassembler that the project is ported from - https://github.com/spazzarama/SharpDisasm
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on MinHook.NET:
| Repository | Stars |
|---|---|
|
rasta-mouse/SharpC2
Command and Control Framework written in C#
|
|
|
jfmaes/AmsiHooker
Hookers are cooler than patches.
|