[fix] fixed hook failed in version below MacOS 11

main
walon 2025-03-07 13:29:47 +08:00
parent 10dc749d7a
commit 4768c039d2
1 changed files with 15 additions and 1 deletions

View File

@ -16,7 +16,11 @@ namespace MonoHook
static HookUtils() static HookUtils()
{ {
jit_write_protect_supported = pthread_jit_write_protect_supported_np() != 0; try
{
jit_write_protect_supported = pthread_jit_write_protect_supported_np() != 0;
}
catch { }
PropertyInfo p_SystemPageSize = typeof(Environment).GetProperty("SystemPageSize"); PropertyInfo p_SystemPageSize = typeof(Environment).GetProperty("SystemPageSize");
if (p_SystemPageSize == null) if (p_SystemPageSize == null)
@ -35,6 +39,16 @@ namespace MonoHook
public static void MemCpy_Jit(void* pDst, byte[] src) public static void MemCpy_Jit(void* pDst, byte[] src)
{ {
if (!jit_write_protect_supported)
{
fixed(void * pSrc = &src[0])
{
MemCpy(pDst, pSrc, src.Length);
}
return;
}
fixed(void * p = &src[0]) fixed(void * p = &src[0])
{ {
memcpy_jit(new IntPtr(pDst), new IntPtr(p), src.Length); memcpy_jit(new IntPtr(pDst), new IntPtr(p), src.Length);