All Projects → Misaka-Mikoto-Tech → Monohook

Misaka-Mikoto-Tech / Monohook

Licence: mit
hook C# method at runtime without modify dll file (such as UnityEditor.dll)

Projects that are alternatives of or similar to Monohook

PEDetour
modify binary Portable Executable to hook its export functions
Stars: ✭ 59 (-83.05%)
Mutual labels:  hook, dll
Facepunch.steamworks
Another fucking c# Steamworks implementation
Stars: ✭ 1,945 (+458.91%)
Mutual labels:  unity, dll
ProcessInjector.NET
Learning Process Injection and Hollowing techniques
Stars: ✭ 23 (-93.39%)
Mutual labels:  hook, dll
muparsersse
muparsersse a math parser for windows using just in time compilations of the expression
Stars: ✭ 14 (-95.98%)
Mutual labels:  dll, jit
Melonloader
The World's First Universal Mod Loader for Unity Games that is Compatible with both Il2Cpp and Mono
Stars: ✭ 306 (-12.07%)
Mutual labels:  unity, dll
Klakspout
Spout plugin for Unity
Stars: ✭ 332 (-4.6%)
Mutual labels:  unity
Numpile
A tiny 1000 line LLVM-based numeric specializer for scientific Python code.
Stars: ✭ 341 (-2.01%)
Mutual labels:  jit
Crystalai
A Utility AI for C# and Unity
Stars: ✭ 328 (-5.75%)
Mutual labels:  unity
Dungeongenerator
A dungeon generator for Unity
Stars: ✭ 324 (-6.9%)
Mutual labels:  unity
Navmeshplus
Unity NavMesh 2D Pathfinding
Stars: ✭ 347 (-0.29%)
Mutual labels:  unity
Opensmalltalk Vm
Cross-platform virtual machine for Squeak, Pharo, Cuis, and Newspeak.
Stars: ✭ 345 (-0.86%)
Mutual labels:  jit
Laspvfx
Audio reactive Unity VFX with LASP
Stars: ✭ 337 (-3.16%)
Mutual labels:  unity
Lively
Stars: ✭ 5,721 (+1543.97%)
Mutual labels:  unity
Iphonemocapios
Stars: ✭ 338 (-2.87%)
Mutual labels:  unity
Rcrl
Read-Compile-Run-Loop: tiny and powerful interactive C++ compiler (REPL)
Stars: ✭ 332 (-4.6%)
Mutual labels:  dll
Postprocessing
Post Processing Stack
Stars: ✭ 3,524 (+912.64%)
Mutual labels:  unity
Blendshapebuilder
tweak vertices and generate blend shapes in Unity
Stars: ✭ 328 (-5.75%)
Mutual labels:  unity
Toon Shader
A character focused Toon Shader for Unity using Shader Graph.
Stars: ✭ 338 (-2.87%)
Mutual labels:  unity
Gpu Physics Unity
Through this configuration, no per voxel data is transferred between the GPU and the CPU at runtime.
Stars: ✭ 342 (-1.72%)
Mutual labels:  unity
Dependencies
A rewrite of the old legacy software "depends.exe" in C# for Windows devs to troubleshoot dll load dependencies issues.
Stars: ✭ 4,391 (+1161.78%)
Mutual labels:  dll

MonoHook

本代码的功能是运行时修改C#函数

特点:

  • 运行时直接修改内存中的 jit 代码,不会修改 UnityEditor.dll 等文件,避免让别人修改文件的尴尬。
  • 不影响调试。
  • 同时支持 .net 2.x 与 .net 4.x。
  • 目前测试支持 unity4.7.2, unity5.x, unity 2017, unity 2018, unity 2019, unity2020。
  • 使用很方便,在C#内定义签名与原始方法相同的两个方法然后注册一下就能用了。
  • 目前已支持 Android Mono, Windows Mono/IL2CPP

预览

image

原理

  • MethodInfo.MethodHandle.GetFunctionPointer().ToPointer() 指向了 jit 后的 native 代码,因此修改此地址的代码即可以修改功能。
  • 通过一系列跳转就可以巧妙的替换原函数实现,同时也保留调用原函数的功能。
  • 本代码的实现与下面 reference 的实现略有不同,比其使用更少的字节,Hook 成功率更高,具体实现可以看代码。

使用方法

   [InitializeOnLoad] // 最好Editor启动及重新编译完毕就执行
   public static class HookTest
   {
        static HookTest()
        {
            if(_hook == null)
            {
                Type type = Type.GetType("UnityEditor.LogEntries,UnityEditor.dll");
                // 找到需要 Hook 的方法
                MethodInfo miTarget = type.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public);

                type = typeof(PinnedLog);

                // 找到被替换成的新方法
                MethodInfo miReplacement = type.GetMethod("NewClearLog", BindingFlags.Static | BindingFlags.NonPublic);

                // 这个方法是用来调用原始方法的
                MethodInfo miProxy = type.GetMethod("ProxyClearLog", BindingFlags.Static | BindingFlags.NonPublic);

                // 创建一个 Hook 并 Install 就OK啦, 之后无论哪个代码再调用原始方法都会重定向到
                //  我们写的方法ヾ(゚∀゚ゞ)
                _hook = new MethodHook(miTarget, miReplacement, miProxy);
                _hook.Install();
            }
        }
   }
    

存在问题

  • 运行时目前只支持 android jit 以及 windows IL2CPP, android il2cpp 需要增加一个 so 来调用 mprotect 方法,现在不准备搞。

reference

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].