https://github.com/detoursharp/detoursharp.hosting
A fully managed library for hosting the .NET runtime in remote processes.
https://github.com/detoursharp/detoursharp.hosting
csharp dotnet
Last synced: 5 months ago
JSON representation
A fully managed library for hosting the .NET runtime in remote processes.
- Host: GitHub
- URL: https://github.com/detoursharp/detoursharp.hosting
- Owner: DetourSharp
- License: mit
- Created: 2021-11-24T13:02:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-04T13:39:47.000Z (over 4 years ago)
- Last Synced: 2025-12-08T16:37:04.269Z (7 months ago)
- Topics: csharp, dotnet
- Language: C#
- Homepage:
- Size: 43 KB
- Stars: 32
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# DetourSharp.Hosting
DetourSharp.Hosting is a fully managed library for hosting the .NET runtime in remote processes.
# Sample
```cs
using System.Diagnostics;
using System.Runtime.InteropServices;
using DetourSharp.Hosting;
// Start a new Notepad process to load the runtime into.
var process = Process.Start(@"C:\Windows\System32\notepad.exe");
// Wait for the process to initialize.
process.WaitForInputIdle();
// The RemoteRuntime class will load the .NET runtime into the
// process but it will not perform initialization immediately.
using var runtime = new RemoteRuntime(process.Id);
// Initialize the runtime.
var config = $"{typeof(Program).Assembly.GetName().Name}.runtimeconfig.json";
runtime.Initialize(Path.Combine(AppContext.BaseDirectory, config));
// Invoke a method in the remote runtime.
runtime.Invoke(((Delegate)ShowMessageBox).Method, ("Hello, world!", "Success"));
// We can only pass one parameter, so we use a tuple to pass multiple values.
static void ShowMessageBox((string Message, string Caption) parameters)
{
_ = MessageBoxW(IntPtr.Zero, parameters.Message, parameters.Caption, 0);
[DllImport("user32", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
static extern int MessageBoxW(IntPtr hWnd, string lpText, string lpCaption, uint uType);
}
```