Git Product home page Git Product logo

monohook's Introduction

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

monohook's People

Contributors

friuns2 avatar misaka-mikoto-tech avatar newbiegamecoder avatar saneor avatar

Stargazers

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

Watchers

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

monohook's Issues

Hook doesn't work On GenericMethod

for example : UnityEngine.Object Api: public static T Instantiate(T original) where T : Object;
when i Get the this GenericMethod, and then us
"MethodInfo miTarget = genericMethod.MakeGenericMethod(typeof(UnityEngine.Object)",

and then Code:

[MethodImpl(MethodImplOptions.NoOptimization)]
private static UnityEngine.Object GameInstanceNew(UnityEngine.Object go)
{
    Debug.LogFormat("【自定义实现】Object.Instantiate(Object original), Prefab名称:{0}", go.name);
    UnityEngine.Object  obj= GameInstanceProxy(go);
    return obj;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
private static UnityEngine.Object GameInstanceProxy(UnityEngine.Object go)
{
    // 此处的函数实现永远不会起作用,随便写
    Debug.Log("something" + go.ToString());
    return null;
}
MethodInfo miReplacement = new Func<UnityEngine.Object, UnityEngine.Object>(GameInstanceNew).Method;
MethodInfo miProxy = new Func<UnityEngine.Object, UnityEngine.Object>(GameInstanceProxy).Method;
_hook_Instance = new MethodHook(miTarget, miReplacement, miProxy);
_hook_Instance.Install();

And when Call UnityEngine.Object:Instance() Again , then Unity crash~!

Code no Error in Runtime, but hook doesn.t work, who know reason

建议改名为MonoHook

hook已经有名次和动词此意,hooker跟钩子没有关系,反而有prostitute之意

2019.4.40编辑器下gameobject.setactive不好用

image
调用MonoHook.Test.GameObject_SetActive_HookTest.Test(gameObject)好用
调用gameObject.SetActive(false)不好用
GameObject_SetActive_HookTest已经使用了InitializeOnLoad

是我工程设置或者脚本写错了吗

How to hook the property of an interface?

Here for example has a interface called A

public interface A{
    int p1{get;set;}
}

and I what to hook it, but it throw an error:

Missing or incorrect header for method set_MuzzleEular
[17:26:35.726] [BobH_ATRI2] [ERROR]   at (wrapper managed-to-native) System.RuntimeMethodHandle:GetFunctionPointer (intptr)
  at System.RuntimeMethodHandle.GetFunctionPointer () [0x00000] in <filename unknown>:0
  at MethodHook.GetFunctionAddr (System.Reflection.MethodBase method) [0x00000] in <filename unknown>:0
  at MethodHook..ctor (System.Reflection.MethodBase targetMethod, System.Reflection.MethodBase replacementMethod, System.Reflection.MethodBase proxyMethod) [0x00000] in <filename unknown>:0

能否支持对运行时动态创建的函数

需求场景:
有一个函数A:输出A
需要在程序运行时:替换函数A的输出内容 输出B 然后在执行函数A 再输出B
目前实现方式:遍历函数A的参数 属性 返回值等 写入cs代码文件中重新编译 然后进行HOOK
理想实现方式:遍历函数A的参数 属性 返回值等 创建一个动态函数 作为绑定代理 然后进行HOOK

崩溃

unity 2021.3.x unity2022.3.x启动界面就崩溃 unity2020正常

Begin MonoManager ReloadAssembly
Native extension for UWP target not found
Native extension for WindowsStandalone target not found
Native extension for iOS target not found
Native extension for Android target not found
Refreshing native plugins compatible for Editor in 0.30 ms, found 0 plugins.
Preloading 0 native plugins for Editor in 0.00 ms.
flush_icache delegate is not null
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
MonoHook.HookUtils:SetupFlushICacheFunc () (at Assets/Scripts/UnityHook/HookUtils.cs:138)
MonoHook.HookUtils:.cctor () (at Assets/Scripts/UnityHook/HookUtils.cs:25)
MonoHook.MethodHook:DoInstall () (at Assets/Scripts/UnityHook/MethodHook.cs:164)
MonoHook.MethodHook:Install () (at Assets/Scripts/UnityHook/MethodHook.cs:135)
MonoHook.Test.BuildPipeline_StripDll_HookTest:InstallHook () (at Assets/Scripts/UnityHook/TestCase/Editor/BuildPipeline_StripDll_HookTest.cs:155)
MonoHook.Test.BuildPipeline_StripDll_HookTest:.cctor () (at Assets/Scripts/UnityHook/TestCase/Editor/BuildPipeline_StripDll_HookTest.cs:65)
System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (System.RuntimeTypeHandle)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])

(Filename: Assets/Scripts/UnityHook/HookUtils.cs Line: 138)

Original [PostprocessBuildPlayer.PostProcessCompletedBuild]: addr:0x191972a3c00

0x191972a3bf0: 01040205 04030150 00000000 00000000
0x191972a3c00: 55488bec 4881ec30 01000048 8975f848
0x191972a3c10: 898d10ff ffff49bb 18349f74 fb7f0000
0x191972a3c20: 4c895de8 49bb6833 9f74fb7f 00004c89
0x191972a3c30: 5df033f6 41bb0000 00004d85 db74074c
0x191972a3c40:
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
MonoHook.MethodHook:DoInstall () (at Assets/Scripts/UnityHook/MethodHook.cs:164)
MonoHook.MethodHook:Install () (at Assets/Scripts/UnityHook/MethodHook.cs:135)
MonoHook.Test.BuildPipeline_StripDll_HookTest:InstallHook () (at Assets/Scripts/UnityHook/TestCase/Editor/BuildPipeline_StripDll_HookTest.cs:155)
MonoHook.Test.BuildPipeline_StripDll_HookTest:.cctor () (at Assets/Scripts/UnityHook/TestCase/Editor/BuildPipeline_StripDll_HookTest.cs:65)
System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (System.RuntimeTypeHandle)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])

(Filename: Assets/Scripts/UnityHook/MethodHook.cs Line: 164)

Original [BuildPipeline_StripDll_HookTest.PostprocessBuildPlayer_CompleteBuild_Replace]: addr:0x191972a3fb0

0x191972a3fa0: 01040205 04030150 00000000 00000000
0x191972a3fb0: 55488bec 4881ecf0 01000048 8975f048
0x191972a3fc0: 897df848 898d38fe ffff49bb 18349f74
0x191972a3fd0: fb7f0000 4c895de0 49bb6833 9f74fb7f
0x191972a3fe0: 00004c89 5de841bb 00000000 4d85db74
0x191972a3ff0:
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
MonoHook.MethodHook:DoInstall () (at Assets/Scripts/UnityHook/MethodHook.cs:165)
MonoHook.MethodHook:Install () (at Assets/Scripts/UnityHook/MethodHook.cs:135)
MonoHook.Test.BuildPipeline_StripDll_HookTest:InstallHook () (at Assets/Scripts/UnityHook/TestCase/Editor/BuildPipeline_StripDll_HookTest.cs:155)
MonoHook.Test.BuildPipeline_StripDll_HookTest:.cctor () (at Assets/Scripts/UnityHook/TestCase/Editor/BuildPipeline_StripDll_HookTest.cs:65)
System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (System.RuntimeTypeHandle)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])

(Filename: Assets/Scripts/UnityHook/MethodHook.cs Line: 165)

Original [BuildPipeline_StripDll_HookTest.PostprocessBuildPlayer_CompleteBuild_Proxy]: addr:0x191972a4350

0x191972a4340: 30538e73 91010000 00000000 00000000
0x191972a4350: 55488bec 4883ec50 48894de0 49bb1834
0x191972a4360: 9f74fb7f 00004c89 5df049bb 68339f74
0x191972a4370: fb7f0000 4c895df8 c745e800 00000041
0x191972a4380: bb000000 004d85db 74074c8b 5df841ff
0x191972a4390:
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
MonoHook.MethodHook:DoInstall () (at Assets/Scripts/UnityHook/MethodHook.cs:167)
MonoHook.MethodHook:Install () (at Assets/Scripts/UnityHook/MethodHook.cs:135)
MonoHook.Test.BuildPipeline_StripDll_HookTest:InstallHook () (at Assets/Scripts/UnityHook/TestCase/Editor/BuildPipeline_StripDll_HookTest.cs:155)
MonoHook.Test.BuildPipeline_StripDll_HookTest:.cctor () (at Assets/Scripts/UnityHook/TestCase/Editor/BuildPipeline_StripDll_HookTest.cs:65)
System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (System.RuntimeTypeHandle)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])

(Filename: Assets/Scripts/UnityHook/MethodHook.cs Line: 167)

=================================================================
Native Crash Reporting

Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.

=================================================================
Managed Stacktrace:

  at <unknown> <0xffffffff>
  at System.Object:wrapper_native_000001919B8C41C0 <0x0012c>
  at MonoHook.HookUtils:FlushICache <0x00111>
  at MonoHook.CodePatcher:FlushICache <0x00092>
  at MonoHook.CodePatcher:ApplyPatch <0x00162>
  at MonoHook.MethodHook:DoInstall <0x00e82>
  at MonoHook.MethodHook:Install <0x00162>
  at MonoHook.Test.BuildPipeline_StripDll_HookTest:InstallHook <0x0055a>
  at MonoHook.Test.BuildPipeline_StripDll_HookTest:.cctor <0x000d2>
  at System.Object:runtime_invoke_void <0x00184>
  at <unknown> <0xffffffff>
  at System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor <0x000c1>
  at System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor <0x0019a>
  at UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes <0x00602>
  at <Module>:runtime_invoke_void_object <0x0018a>

=================================================================
Received signal SIGSEGV
Obtained 2 stack frames
RtlLookupFunctionEntry returned NULL function. Aborting stack walk.

获取属性时不能正确Hook

参考DotNetDetour 中解释的,关于属性其实是 get_XXX的格式,在MonoHook中确实能够正确找到这个函数,Install也没什么问题,但是测试发现并不能正确Hook到,想向大佬请教一下。

//这是需要Hook的目标
public class HookTarget : MonoBehaviour
{
// 这是随便挂在场景里的一个MonoBehaviour类,挂了一个Text用来输出
    public Text Log;

    public static string TestStaticString
    {
        get
        {
            return "This is original,not hook.";
        }
    }

//场景中挂了一个按钮来触发这个函数
    public void CheckTestString()
    {
        Console.WriteLine("CheckTestString Start");
        Log.text = TestStaticString;
        Console.WriteLine("CheckTestString Over");
    }

}

然后随便用了个注入器,应该是叫MInjector,注入之后可以运行一个入口函数,入口函数中进行Install的逻辑大体如下:

    public class HookClass
    {
      /// <summary>
        /// Hook类型的属性
        /// </summary>
        public static void HookPropertyMethod()
        {
            Console.WriteLine("HookPropertyMethod Start.");
            //获取需要Hook的类型
            Type type = Type.GetType("HookTarget,Assembly-CSharp.dll");

            //获取类型上的目标方法,这里打印过日志,确认是找到了对应方法的
            MethodInfo miTarget = type.GetMethod("get_TestStaticString", BindingFlags.Static | BindingFlags.Public);

            //Hook后重新定向的新方法,这里直接指向本类
            type = typeof(HookClass);

            // 找到本类上 名为 NewMethod 的方法,准备替换目标方法
            MethodInfo miReplacement = type.GetMethod("NewStaticString", BindingFlags.Static | BindingFlags.Public);

            // 创建一个 Hook 并 Install ,这样就能把方法都重定向到新方法来
            MethodHook _hook = new MethodHook(miTarget, miReplacement, null);

            _hook.Install();
            Console.WriteLine("HookPropertyMethod Over.");
        }

        public static string NewStaticString()
        {
            return "Hello,Hook!";
        }

//这里也试过添加参数(觉得可能和实例化的类一样会把自身作为第一个参数),但是还是不行
        public static string NewStaticString_2(object target)
        {
            return "Hello,Hook!";
        }
}

大体的方法和流程如上,对于类普通方法和静态方法的Hook试过可行,但是不知道属性是否也可以Hook?

先谢过!

使用注入Hook的方式运行时,无法正确运行原函数

我fork了一份进行了修改,配合注入工具能够成功注入到运行时的 Unity 程序中,大部分功能也都正常,但是有几个问题,不知道大佬能不能给点思路(对汇编不是很熟悉):

  1. 能够Hook到指定的函数,也确实能够跳转到新函数,但是调用占位原函数时失效,没有效果
  2. Hook带有参数的方法时无效,Hook不到具体的参数

大概的逻辑在这里:https://github.com/pgw00k/MonoHook

proxy method bug

Hello there is bug with proxy method

this output should print

TestPatch
Test
TestPatch
Test2

but it prints this
TestPatch
Test2
TestPatch
Test2

using System;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UI;

public class Test3 : MonoBehaviour
{
   public unsafe void Start()
   {
       Application.logMessageReceived+= ApplicationOnlogMessageReceived;

       Hook(Test, TestPatch, TestProxy);
       Hook(Test2, TestPatch, TestProxy);
       
       Test();
       Test2();

   }
   private void Hook(Action a, Action to, Action proxy)
   {
       var _hook = new MethodHook((a).Method, (to).Method, (proxy).Method);
       _hook.Install();
   }
   private static unsafe int* GetAddr(void* pointer)
   {
       return (int*) ((byte*)pointer + 1);
   }
   private void ApplicationOnlogMessageReceived(string condition, string stacktrace, LogType type)
   {
       text.text += condition + "\n";
   }
   [MethodImpl(MethodImplOptions.NoOptimization)]
   public void TestProxy()
   {
       Debug.Log("TestProxy");
   }
   
   
   [MethodImpl(MethodImplOptions.NoOptimization)]
   public void Test()
   {
       Debug.Log("Test");
   }
   
   [MethodImpl(MethodImplOptions.NoOptimization)]
   public void Test2()
   {
       Debug.Log("Test2");
   }
   
   
   public Text text;
   [MethodImpl(MethodImplOptions.NoOptimization)]
   public void TestPatch()
   {
       Debug.Log("TestPatch");
       TestProxy();
   }   
}

关于IL2CPP

你好,看到readme里写的 “il2cpp 需要增加一个 so 来调用 mprotect 方法”
能否请教下大概要怎么做?
我打算给一个游戏做MOD支持(它是IL2CPP编译的)

Arm64下为什么不使用更短的绝对跳转?

LDR x17, #0x8
BR x17
addr

这里使用x16 x17 x18都可,前2个状态寄存器,后1个平台寄存器。在标准的情况下,arm64下几乎不会使用它们。它们完全可以随意使用,仅手写asm的情况下才会被占用

xcode 打包报错

报错信息是:error: 'pthread_jit_write_protect_np' is unavailable: not available on iOS

void Test<T>()

你好,我这边遇到一个问题,使用void Test()方法时,如果T是结构体,正常运行,如果T是类(Class),则会直接崩溃,有什么好的解决方案么?测试代码如下工程
MonoHooker-master.zip

Most likely you need to move your GUIStyle initialization code to OnGUI

Hi, untiy 2019.4 下测试报错

Unable to use a named GUIStyle without a current skin. Most likely you need to move your GUIStyle initialization code to OnGUI
System.RuntimeMethodHandle:GetFunctionPointer()
MethodHook:GetFunctionAddr(MethodBase) (at Assets/Framework/UnityHook/MethodHook.cs:301)
MethodHook:.ctor(MethodBase, MethodBase, MethodBase) (at Assets/Framework/UnityHook/MethodHook.cs:167)
SFrame.SceneHierarchyStageHandling_Hook:.cctor() (at Assets/Framework/UnityHook/TestCase/SceneHierarchyStageHandling_Hook.cs:22)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes(Type[]) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:114)
 [InitializeOnLoad]
    public static class SceneHierarchyStageHandling_Hook
    {
        private static MethodHook _hooker;
        static SceneHierarchyStageHandling_Hook()
        {
            if (_hooker == null)
            {
                Type type = Type.GetType("UnityEditor.SceneHierarchyStageHandling,UnityEditor.dll");
                var target = type.GetMethod("PrefabStageHeaderGUI", BindingFlags.Instance | BindingFlags.Public);
                var dst = typeof(SceneHierarchyStageHandling_Hook).GetMethod("PrefabStageHeaderGUINew",
                    BindingFlags.Static | BindingFlags.NonPublic);
                var old = typeof(SceneHierarchyStageHandling_Hook).GetMethod("PrefabStageHeaderGUIOld",
                    BindingFlags.Static | BindingFlags.NonPublic);
                _hooker = new MethodHook(target, dst, old);
                _hooker.Install();
            }
        }

        static void PrefabStageHeaderGUINew(object handle, Rect rect)
        {
            PrefabStageHeaderGUIOld(handle, rect);
            GUILayout.Button("xx");
            // GUI.Button(new Rect(rect.xMax - 100, rect.y, 16, rect.height), "x");
        }
        static void PrefabStageHeaderGUIOld(object handle, Rect rect)
        {
            // 随便乱写点东西以占据空间
            for (int i = 0; i < 100; i++)
            {
                UnityEngine.Debug.Log("something");
            }
            UnityEngine.Debug.Log(Application.targetFrameRate);
        }
    }

安卓v7不行

在unity中可以,v7打包出来不行了,2017.4版本

unity5.6打包成安卓apk后运行获取不到内存页大小

PropertyInfo p_SystemPageSize = typeof(Environment).GetProperty("SystemPageSize");
if (p_SystemPageSize == null)
throw new NotSupportedException("Unsupported runtime");
_Pagesize = (int) p_SystemPageSize.GetValue(null, new object[0]);
这段代码一直抛NotSupportedException("Unsupported runtime");

Hook时发生问题

2020-08-02 12-02-54 --- 捕获到未处理异常:System.MissingMethodException
异常信息:Method not found: 'System.Reflection.MethodBase.op_Inequality'.

代码

public static void WriteLog(string strLog)
        {
            string sFilePath = "d:\\ssjj\\" + DateTime.Now.ToString("yyyyMM");
            string sFileName = "ssjj_hack_log_" + DateTime.Now.ToString("dd") + ".log";
            sFileName = sFilePath + "\\" + sFileName; //文件的绝对路径
            if (!Directory.Exists(sFilePath))//验证路径是否存在
            {
                Directory.CreateDirectory(sFilePath);
                //不存在则创建
            }
            FileStream fs;
            StreamWriter sw;
            if (File.Exists(sFileName))
            //验证文件是否存在,有则追加,无则创建
            {
                fs = new FileStream(sFileName, FileMode.Append, FileAccess.Write);
            }
            else
            {
                fs = new FileStream(sFileName, FileMode.Create, FileAccess.Write);
            }
            sw = new StreamWriter(fs);
            sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "   ---   " + strLog);
            sw.Close();
            fs.Close();
        }
        public static void ReWriteLog(string strLog)
        {
            WriteLogProxy("hh:" + strLog);
        }
        public static void WriteLogProxy(string strLog)
        { 
            
        }

MethodInfo miTarget = Type.GetType("BobHSSJJ.CheatManagement").GetMethod("WriteLog", BindingFlags.Static | BindingFlags.Public);
                WriteLog(miTarget.ToString());
                MethodInfo miReplace = Type.GetType("BobHSSJJ.CheatManagement").GetMethod("ReWriteLog", BindingFlags.Static | BindingFlags.Public);
                MethodInfo miProxy = Type.GetType("BobHSSJJ.CheatManagement").GetMethod("WriteLogProxy", BindingFlags.Static | BindingFlags.Public);
                WriteLog(miReplace.ToString());
                WriteLog(miProxy.ToString());
                WriteLog("开始hook..........");
                hooker = new MethodHook(miTarget, miReplace, miProxy);
                hooker.Install();

MonoHook makes Unity2021.3.6 crash

Upgraded my project from Unity2019 to 2021.3.6 recently, and MonoHook started making Unity crash when it calls the Monohook funcs(start unity; press Play Button in editor; modified script). It's not 100% crash, but once my computer randomly met this crash, i can repeat the crash by pressing Play Button until i removed the "new MethodHook()" invoking functions. And this type of crash can be repeated on other computers.
自从最近升级到2021.3.6后,开始遇到MonoHook的crash问题。只要是调用到了绑定hook的代码,无论是在启动unity、点击编辑器的play,修改了script,都会随机的遇到unity native crash。已经定位确实是monohook的绑定代码造成的(只要不调用,就必然不会crash)。在好几台电脑上都可以重现。保持projectSetting里ReloadDomon默认开启的状态下,通过点击play可以比较快速的,重现率高的,重现这个问题。
麻烦调查一下,否则就不能再用MonoHook了:(

crash info:
Obtained 2 stack frames
RtlLookupFunctionEntry returned NULL function. Aborting stack walk.

test env: scripting backend: mono. ApiCompatibilityLevel: .both .net framework or .net standard

would you please have a look at this issue? thanks a lot!

unity运行崩溃

unity版本:2022.3.8f1c1

ymbol file LoadedFromMemory is not a mono symbol file

  • Loaded All Assemblies, in 1.888 seconds
    Refreshing native plugins compatible for Editor in 44.14 ms, found 15 plugins.
    Preloading 1 native plugins for Editor in 0.18 ms.
    Refreshing native plugins compatible for Editor in 42.76 ms, found 15 plugins.
    Native extension for WindowsStandalone target not found

=================================================================
Native Crash Reporting

Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.

=================================================================
Managed Stacktrace:

      at <unknown> <0xffffffff>
      at System.Object:wrapper_native_0000027473AE21C0 <0x00094>
      at MonoHook.HookUtils:FlushICache <0x00047>
      at MonoHook.CodePatcher:FlushICache <0x0002a>
      at MonoHook.CodePatcher:ApplyPatch <0x00062>
      at MonoHook.MethodHook:DoInstall <0x000b2>
      at MonoHook.MethodHook:Install <0x00042>
      at HybridCLR.MonoHook.GetIl2CppFolderHook:.cctor <0x002ca>
      at System.Object:runtime_invoke_void <0x00084>
      at <unknown> <0xffffffff>
      at System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor <0x00069>
      at System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor <0x0003a>
      at UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes <0x008da>
      at <Module>:runtime_invoke_void_object <0x00087>

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.