Skip to content

A fully managed library for hosting the .NET runtime in remote processes.

License

Notifications You must be signed in to change notification settings

DetourSharp/DetourSharp.Hosting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DetourSharp.Hosting

DetourSharp.Hosting is a fully managed library for hosting the .NET runtime in remote processes.

Sample

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);
}

About

A fully managed library for hosting the .NET runtime in remote processes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages