public PlatformFuncs() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { OperatingSystem = OperatingSystem.Windows; // TryLoad ? _libHandle = NativeLibrary.Load("kernel32.dll"); // TryGetExport var loadlibp = NativeLibrary.GetExport(_libHandle, "LoadLibraryA"); _loadLibraryFunc = Marshal.GetDelegateForFunctionPointer <LoadLibraryDelegate>(loadlibp); // TryGetExport var getsymbolp = NativeLibrary.GetExport(_libHandle, "GetProcAddress"); _getSymbolFunc = Marshal.GetDelegateForFunctionPointer <GetSymbolDelegate>(getsymbolp); // TryGetExport var freelibraryp = NativeLibrary.GetExport(_libHandle, "FreeLibrary"); _freeLibraryFunc = Marshal.GetDelegateForFunctionPointer <FreeLibraryDelegate>(freelibraryp); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { OperatingSystem = OperatingSystem.Linux; // TryLoad ? _libHandle = NativeLibrary.Load("libdl.so"); // TryGetExport var loadlibp = NativeLibrary.GetExport(_libHandle, "dlopen"); var loadlibpf = Marshal.GetDelegateForFunctionPointer <DlOpenDelegate>(loadlibp); _loadLibraryFunc = (path) => loadlibpf(path, RTLD_NOW); // TryGetExport var getsymbolp = NativeLibrary.GetExport(_libHandle, "dlsym"); _getSymbolFunc = Marshal.GetDelegateForFunctionPointer <GetSymbolDelegate>(getsymbolp); // TryGetExport var freelibraryp = NativeLibrary.GetExport(_libHandle, "dlclose"); _freeLibraryFunc = Marshal.GetDelegateForFunctionPointer <FreeLibraryDelegate>(freelibraryp); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { OperatingSystem = OperatingSystem.OSX; throw new NotImplementedException("Dynamic library loading on OSX is not implemented"); } else { throw new NotImplementedException("Application is running on unknown operation system."); } }
internal static void InstallLoadLibraryHook() { var funcAddr = HookUtils.GetFunctionAddress("Kernel32.dll", "LoadLibraryA"); hookedInstance = HLoadLibrary; originalInstance = Marshal.GetDelegateForFunctionPointer <LoadLibraryDelegate>(funcAddr); dEngine = new DetourEngine(funcAddr, Marshal.GetFunctionPointerForDelegate(hookedInstance)); dEngine.Install(); Logger.Log("Installed LoadLibrary hook"); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. NativeLibrary.Free(_libHandle); _libHandle = IntPtr.Zero; _loadLibraryFunc = null; _getSymbolFunc = null; _freeLibraryFunc = null; disposedValue = true; } }
private void PatchGameAsync(string file, string patchFile, ListViewItem item) { PatchingMessage pm = msg => { UpdatePatchingMessageDelegate upmd = new UpdatePatchingMessageDelegate(UpdatePatchingMessage); this.BeginInvoke(upmd, item, msg.ToString()); }; VitaPackageHelper.Helper.PATCH_RESULT succ = VitaPackageHelper.Helper.patchPackage(file, patchFile, pm); if (succ == VitaPackageHelper.Helper.PATCH_RESULT.SUCCESS) { LoadLibraryDelegate lld = new LoadLibraryDelegate(initGameLibrary); this.BeginInvoke(lld); MessageBox.Show("Patching Successful."); } else if (succ == VitaPackageHelper.Helper.PATCH_RESULT.SFO_NOT_MATCH) { MessageBox.Show("Can not Patch this game,CONTENT_ID not match.Please check CONTENT_ID in param.sfo."); } else if (succ == VitaPackageHelper.Helper.PATCH_RESULT.VERSION_SAME) { MessageBox.Show("Can not Patch this game.APP_VER same.might be already patched?"); } }