AnyHook 1.0.0.7

.NET 6.0 .NET Framework 4.7.2
dotnet add package AnyHook --version 1.0.0.7
NuGet\Install-Package AnyHook -Version 1.0.0.7
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="AnyHook" Version="1.0.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AnyHook --version 1.0.0.7
#r "nuget: AnyHook, 1.0.0.7"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install AnyHook as a Cake Addin
#addin nuget:?package=AnyHook&version=1.0.0.7

// Install AnyHook as a Cake Tool
#tool nuget:?package=AnyHook&version=1.0.0.7

This library gives you a possibility to hook any Windows x64 functions from any code: native C++, managed .NET Framework and managed .NET Core (.NET 6.0). You can set local hooks (hooking functions calls of local process), remote hooks (hooking functions calls of remote process by process ID) and global hooks (hooking functions calls of any process which uses Windows GetMessage call). Callback functions could be set by their addresses, names (module name plus function name) and as delegate instances (managed code).

C# example (.NET 6.0)

using System.Diagnostics;

AnyHook.AnyHook.SetLocalHook("kernel32.dll", "TerminateProcess", new ShadowTerminateProcessDelegate(ShadowTerminateProcess)); Process.GetCurrentProcess().Kill(); Console.ReadKey();

public delegate bool ShadowTerminateProcessDelegate(IntPtr handle, int exitCode);

partial class Program { public static bool ShadowTerminateProcess(IntPtr handle, int exitCode) { Console.WriteLine(handle.ToString()); return true; } }

C++ example (native)

__declspec(dllimport) extern BOOL SetRemoteHook(LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, DWORD);

int wmain() { SetRemoteHook(L"kernel32.dll", L"TerminateProcess", "C:\Users\kacha\source\repos\AnyHook\ManagedShadow\bin\Debug\ManagedShadow.dll", L"ShadowTerminateProcess", 8780); TerminateProcess(GetCurrentProcess(), 0); WaitForSingleObject(GetCurrentProcess(), INFINITE); return 0; }

Author parially used ideas proposed and implemented:

here: https://github.com/EasyHook/EasyHook and here: https://github.com/williammortl/Prochook64

Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Framework net472 net48
native native
Compatible target framework(s)
Additional computed target framework(s)
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.0.0.7 143 9/12/2022
1.0.0.4 143 9/4/2022