public static NativeLibraryPool GetLibraryPool(string libraryName) { NativeLibraryPool result = null; if (!s_dict.TryGetValue(libraryName, out result)) { result = new NativeLibraryPool(libraryName); } return(result); }
/// <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(); }