-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
可以支持.net core吗 #21
Comments
同问,作者好像不在了?没有见到关于项目的任何回复 |
不出意外应该是不支持的。根据仓库动态我猜测这个最开始为.Net Framewrok设计的。然而,在dotnet/runtime仓库中, 如果想要支持需要改写目标地址,获取 see https://github.com/dotnet/runtime/blob/main/src/mono/mono/mini/mini-runtime.c#L1908 入口查找代码 好在发现了一个 最终的代码如下,可供参考: // Unity 编辑器环境
[DllImport("mono-2.0-bdwgc", EntryPoint = "mono_jit_info_table_find", CharSet = CharSet.Unicode)]
extern static IntPtr FindJitInfo(IntPtr ptrDomain, IntPtr ptrFunc);
[DllImport("mono-2.0-bdwgc", EntryPoint = "mono_domain_get", CharSet = CharSet.Unicode)]
extern static IntPtr GetDomain();
static unsafe void SetFunctionPtr(MethodInfo mi,nint addr)
{
RuntimeHelpers.PrepareMethod(mi.MethodHandle);
var monoDomain = GetDomain();
var funcPtr = mi.MethodHandle.GetFunctionPointer();
var jitInfoPtr = (int*)FindJitInfo(monoDomain, funcPtr).ToPointer();
jitInfoPtr += IntPtr.Size / 4 * 2;
*(nint*)jitInfoPtr = addr; // overwrite me!
} 测试代码: public static void Test1()
{
Debug.Log("Test1");
}
public static void Test2()
{
Debug.Log("Test2");
}
[InitializeOnLoadMethod]
static void HookMethods()
{
var mi1 = ((Action)Test1).Method;
var mi2 = ((Action)Test2).Method;
RuntimeHelpers.PrepareMethod(mi1.MethodHandle);
RuntimeHelpers.PrepareMethod(mi2.MethodHandle);
SetFunctionPtr(mi1, mi2.MethodHandle.GetFunctionPointer());
Test1(); // output: Test2
} 纯C#环境同理,需要判断下运行时类型,如果是mono或.net core,就执行此逻辑。需要根据实际情况修改入口点。 |
btw, 可以参考MonoHook的实现,不修改入口,直接修改originMethod jit code。也是一个可行的方法。 |
如题,需要在.net core中使用,可以发布.net core nuget包吗?
The text was updated successfully, but these errors were encountered: