Allows injecting .NET code into a remote process in Windows
Перейти к файлу
Daniel Cazzulino efcb3e098b
Bump master version
2019-09-11 14:35:55 -03:00
src Make sure the assembly we end up referencing has the right package id 2019-09-11 14:26:52 -03:00
.editorconfig Allow pushing package to azure feed 2019-04-26 10:40:55 -03:00
.gitignore Upgrade injector to SDK style, infer package contents 2019-04-30 00:53:19 -03:00
GitInfo.txt Bump master version 2019-09-11 14:35:55 -03:00
Icon.png Add default icon 2017-11-15 16:41:30 -03:00
LICENSE.txt Initial commit of the reusable Windows/.NET code injector 2016-12-23 13:26:06 -03:00
README.md Update README.md 2019-08-27 14:17:48 -03:00
msbuild.rsp Allow the injector project to pack itself 2019-04-30 00:53:19 -03:00

README.md

Windows.Injector

Version Downloads Build Status

Allows injecting .NET code into a remote process on Windows

Heavily based on Cory Plott's Snoop.

Usage:

  • Install:
install-package Xamarin.Windows.Injector

The following properties are used to determine which version (x86 or x64) of the boostrap.dll assembly will be referenced: PlatformTarget, Platform and RuntimeIdentifier. If any of those specify either x86 or x64, the assembly will be automatically referenced. Note that you cannot invoke the injector via its API from an AnyCPU library, since it has to be of a specific bitness.

The targets automatically include as content both the assembly as well as a helper Injector.exe executable which you can use to inject into processes that have a different bitness than the calling one.

  • Launch:
var targetProcess = System.Diagnostics.Process.GetProcessesByName("devenv.exe")[0];

Injector.Launch(
    // IntPtr of the main window handle of the process to inject
    targetProcess.MainWindowHandle,
    // The full path to the .NET assembly to load in the remote process
    Assembly.GetExecutingAssembly().Location,
    // Full type name of the public static class to invoke in the remote process
    "MyApp.Startup",
    // Name of the static method in that class to invoke in the remote process
    "Start");

Optionally, the injected method call can also receive parameters, in a {method}:arg1:arg2:argN format:

var targetProcess = System.Diagnostics.Process.GetProcessesByName("devenv.exe")[0];

Injector.Launch(
    // IntPtr of the main window handle of the process to inject
    targetProcess.MainWindowHandle,
    // The full path to the .NET assembly to load in the remote process
    Assembly.GetExecutingAssembly().Location,
    // Full type name of the public static class to invoke in the remote process
    "MyApp.Startup",
    // Name of the static method in that class to invoke in the remote process
    "Start:hello:42:true");

See Program.cs for complete example.

When referencing the package from an AnyCPU project, the x86 and x64 folders will be included as content and copied to the project output path. This allows you to run the relevant Injector.exe for that matches the target process bitness. This executable receives the same parameters as the Launch method shown above.

NOTE: parameter type conversion is supported and happens via the TypeConverter associated with the parameter type.