/// <summary> /// 创建一个 Hooker /// </summary> /// <param name="target">需要替换的目标方法</param> /// <param name="replace">准备好的替换方法</param> public CSharpMethodHooker(MethodBase target, MethodBase replace, MethodBase proxy) { SetupJmpBuff(); IntPtr targetPtr = NativeAPI.GetFunctionAddr(target); IntPtr replacePtr = NativeAPI.GetFunctionAddr(replace); IntPtr proxyPtr = NativeAPI.GetFunctionAddr(proxy); _headSize = (int)LDasm.SizeofMinNumByte(targetPtr.ToPointer(), s_jmpBuff.Length); _proxyBuffSize = _headSize + s_jmpBuff.Length; _proxyPtr = (byte *)proxyPtr.ToPointer(); Debug.Assert(_proxyPtr != null); _targetPtr = targetPtr; _replacPtr = replacePtr; Install(); }
/// <summary> /// 创建一个 native Hooker /// </summary> /// <param name="libraryName">C/C++ 本地库名字</param> /// <param name="symbol">方法符号</param> /// <param name="replace">替换委托</param> public NativeMethodHooker(string libraryName, string symbol, Delegate replace) { SetupJmpBuff(); _libraryPool = NativeLibraryPool.GetLibraryPool(libraryName); IntPtr targetPtr = NativeAPI.mono_hooker_get_address(libraryName, symbol); UnityEngine.Debug.Log(targetPtr); UnityEngine.Debug.Log(libraryName); _headSize = (int)LDasm.SizeofMinNumByte(targetPtr.ToPointer(), s_jmpBuff.Length); _proxyBuffSize = _headSize + s_jmpBuff.Length; _targetPtr = targetPtr; _replacPtr = Marshal.GetFunctionPointerForDelegate(replace); _proxyPtr = _libraryPool.Alloc(); Install(); }