Code Monkey home page Code Monkey logo

dotnetvmthook's Introduction

DotNetVmtHook DotNetVmtHook NuGet

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.

dotnetvmthook's People

Contributors

trojaner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.