DotNetVmtHook 1.0.0

dotnet add package DotNetVmtHook --version 1.0.0                
NuGet\Install-Package DotNetVmtHook -Version 1.0.0                
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="DotNetVmtHook" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetVmtHook --version 1.0.0                
#r "nuget: DotNetVmtHook, 1.0.0"                
#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.
// Install DotNetVmtHook as a Cake Addin
#addin nuget:?package=DotNetVmtHook&version=1.0.0

// Install DotNetVmtHook as a Cake Tool
#tool nuget:?package=DotNetVmtHook&version=1.0.0                

DotNetVmtHook

Allows you to hook a VMT of a native application from .NET Framework and .NET Core.

Performance appears to be good; but I didn't run any benchmarks yet and of course hooking natively will be much faster.

Note: this uses shadow VMT and does not modify the original VMT function addresses. Instead, it replaces the object's VMT pointer. If you plan to use this in any game for "cheating": Don't. Most anti-cheats will detect this anyway.

ONLY WORKS IF LOADED AS MODULE INTO TARGET PROCESS.

Example

    [SuppressUnmanagedCodeSecurity] //to make calls faster
    [UnmanagedFunctionPointer(CallingConvention.StdCall)] //depends on the native method
    [return: MarshalAs(UnmanagedType.I1)] //depends on the native method
    public unsafe delegate bool SomeMethodDelegate(void* data, int data2); //Adjust your signature to the native function
    
    public class SomeFunctionHook : VmtFunctionHook<SomeMethodDelegate>
    {
        public SomeFunctionHook(VmtTable vmt) : base(vmt, NATIVE_FUNCTION_INDEX_HERE) { }
    
        private unsafe bool SomeFunction_Hooked(data, data2)
        {
             //ANYTHING USED FROM OUTSIDE HERE NEEDS Gc.KeepAlive()!!!
             //Otherwise GC might loose track of it and collect it; resulting in native crash
             //...
             //Do Something
             return OriginalFunction(data, data2);
        }
 
        protected override unsafe SomeMethodDelegate GetCallback()
        {
            return SomeFunction_Hooked;
        }
    }    
    
    //Usage
    VmtTable vmt = new Vmt32Table(YOUR_NATIVE_INSTANCE_POINTER_HERE);
    var functionHook = new SomeFunctionHook(vmt);
    functionHook.Hook();
    
    // Somewhen later; when you want to clean up (restores original functions):
    functionHook.Dispose();
    vmt.Dispose();

Compatibility

Works with .NET 4.5 / .NET Standard 1.3 (Depends on Buffer.MemoryCopy)

Should work on Linux; afaik you have to +1 the function indexes there (e.g. if your function index is 0x03 on Windows, its 0x04 on Linux).

License

Everything is licensed MIT. Please provide credit if you use this.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net46 was computed.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.1

    • No dependencies.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETStandard 1.3

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 1,101 7/15/2018