ランキングに戻る

Misaka-Mikoto-Tech/MonoHook

C#

hook C# method at runtime without modify dll file (such as UnityEditor.dll), works on Windows, Mac, Android il2cpp(armv7a and armv8a)

unityhookjitdllunityeditoril2cppandroidmac
スター成長
スター
1.1k
フォーク
188
週間成長
Issue
8
5001k
2018年6月2021年2月2023年11月2026年7月
README

MonoHook

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

特性:

  • 运行时直接修改内存中的 jit / aot 代码,不会修改真实文件。
  • 不影响调试及堆栈回溯。
  • 同时支持 .net 2.x 与 .net 4.x。
  • 支持 unity4.7.2, unity5.x, unity 2017 ~ 2021 (只要Unity不更换 runtime 就可以自动支持以后的版本)。
  • 使用方便,在C#内定义签名与原始方法相同的两个方法注册后即可生效。

支持平台

  • Editor (Windows, Mac Intel/Silicon)
  • Android mono/il2cpp(armv7a, armv8a)
  • Windows mono/il2cpp(x86, x64)

预览

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);

                // 这个方法是用来调用原始方法的, 要求必须添加 [MethodImpl(MethodImplOptions.NoOptimization)],否则在 arm il2cpp 下会随机 crash
                MethodInfo miProxy = type.GetMethod("ProxyClearLog", BindingFlags.Static | BindingFlags.NonPublic);

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

reference

関連リポジトリ
icsharpcode/ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!

C#MIT Licensedecompilerdecompiler-engine
25.7k3.7k
Donchitos/Claude-Code-Game-Studios

Turn Claude Code into a full game dev studio — 49 AI agents, 72 workflow skills, and a complete coordination system mirroring real studio hierarchy.

ShellMIT Licenseai-agentsai-assisted-development
23.3k3.3k
lettier/3d-game-shaders-for-beginners

🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.

C++shaders3d
lettier.github.io/3d-game-shaders-for-beginners/index.html
19.8k1.5k
Unity-Technologies/ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.

C#Otherreinforcement-learningunity3d
unity.com/products/machine-learning-agents
19.6k4.5k
Perfare/AssetStudio

AssetStudio is a tool for exploring, extracting and exporting assets and assetbundles.

C#MIT Licenseunity3dunity
15.6k2.9k
heroiclabs/nakama

Scalable open-source game backend server: multiplayer, matchmaking, leaderboards, chat, and social features for games.

GoGo ModulesApache License 2.0multiplayerbackend
heroiclabs.com
12.9k1.4k
CoplayDev/unity-mcp

Unity MCP acts as a bridge between AI assistants and your Unity Editor. Give your LLM tools to manage assets, control scenes, edit scripts, and automate tasks within Unity.

C#MIT Licenseaiai-integration
coplaydev.github.io/unity-mcp/
12.7k1.3k
Cysharp/UniTask

Provides an efficient allocation free async/await integration for Unity.

C#MIT Licensecsharpunity
11.1k1k
Tencent/xLua

xLua is a lua programming solution for C# ( Unity, .Net, Mono) , it supports android, ios, windows, linux, osx, etc.

COtherluaunity
10.1k2.5k
egametang/ET

Unity3D Client And C# Server Framework

C#Otherc-sharpserver
9.9k3.2k
Perfare/Il2CppDumper

Unity il2cpp reverse engineer

C#MIT Licenseil2cppreverse-engineering
9.2k1.9k
jynew/jynew

JinYongLegend-like RPG Game Framework with full Modding support and 10+ hours playable samples of game.

C#Otherjinyongunity
8.9k1.9k