/// <summary> /// 获取方法指令地址 /// </summary> /// <param name="method"></param> /// <returns></returns> private IntPtr GetFunctionAddr(MethodBase method) { if (!LDasm.IsIL2CPP()) { return(method.MethodHandle.GetFunctionPointer()); } else { __ForCopy __forCopy = new __ForCopy() { method = method }; long *ptr = &__forCopy.__dummy; ptr++; // addr of _forCopy.method IntPtr methodAddr = IntPtr.Zero; if (sizeof(IntPtr) == 8) { long methodDataAddr = *(long *)ptr; byte *ptrData = (byte *)methodDataAddr + sizeof(IntPtr) * 2; // offset of Il2CppReflectionMethod::const MethodInfo *method; long methodPtr = 0; methodPtr = *(long *)ptrData; methodAddr = new IntPtr(*(long *)methodPtr); // MethodInfo::Il2CppMethodPointer methodPointer; } else { int methodDataAddr = *(int *)ptr; byte *ptrData = (byte *)methodDataAddr + sizeof(IntPtr) * 2; // offset of Il2CppReflectionMethod::const MethodInfo *method; int methodPtr = 0; methodPtr = *(int *)ptrData; methodAddr = new IntPtr(*(int *)methodPtr); } return(methodAddr); } }
/// <summary> /// 获取方法指令地址 /// </summary> /// <param name="method"></param> /// <returns></returns> private IntPtr GetFunctionAddr(MethodBase method) { if (!LDasm.IsIL2CPP()) { return(method.MethodHandle.GetFunctionPointer()); } else { /* * // System.Reflection.MonoMethod * typedef struct Il2CppReflectionMethod * { * Il2CppObject object; * const MethodInfo *method; * Il2CppString *name; * Il2CppReflectionType *reftype; * } Il2CppReflectionMethod; * * typedef Il2CppClass Il2CppVTable; * typedef struct Il2CppObject * { * union * { * Il2CppClass *klass; * Il2CppVTable *vtable; * }; * MonitorData *monitor; * } Il2CppObject; * * typedef struct MethodInfo * { * Il2CppMethodPointer methodPointer; // this is the pointer to native code of method * InvokerMethod invoker_method; * const char* name; * Il2CppClass *klass; * const Il2CppType *return_type; * const ParameterInfo* parameters; * // ... * } */ __ForCopy __forCopy = new __ForCopy() { method = method }; long *ptr = &__forCopy.__dummy; ptr++; // addr of _forCopy.method IntPtr methodAddr = IntPtr.Zero; if (sizeof(IntPtr) == 8) { long methodDataAddr = *(long *)ptr; byte *ptrData = (byte *)methodDataAddr + sizeof(IntPtr) * 2; // offset of Il2CppReflectionMethod::const MethodInfo *method; long methodPtr = 0; methodPtr = *(long *)ptrData; methodAddr = new IntPtr(*(long *)methodPtr); // MethodInfo::Il2CppMethodPointer methodPointer; } else { int methodDataAddr = *(int *)ptr; byte *ptrData = (byte *)methodDataAddr + sizeof(IntPtr) * 2; // offset of Il2CppReflectionMethod::const MethodInfo *method; int methodPtr = 0; methodPtr = *(int *)ptrData; methodAddr = new IntPtr(*(int *)methodPtr); } return(methodAddr); } }