Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
enkomio committed Dec 21, 2018
2 parents b4a93b3 + 390cd52 commit 203eabd
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
# Managed Injector
This project implements a .NET Assembly injection library. The method used to inject the Assembly is by using the _SetWindowsHookEx_ method.
This project implements a .NET Assembly injection library (it is inspired by the <a href="https://github.com/cplotts/snoopwpf">snoopwpf</a> project).

## Download
- [Source code][1]
- [Download binary][2]

## Usage
When you want to inject an assembly in a remote project you have to consider the following aspects:
When you want to inject an assembly in a remote process you have to consider the following aspects:

* The project currently supports only 32 bit process
* The ManagedInjector project currently supports only 32 bit process
* The remote process must be a windows application (it must process messages in a message loop)
* If the CLR version is different, you will not be able to use reflection to inspect the loaded assemblies

If the above pre-conditions are satisfiedm you can inject an assembly and invoke an activation method. There are three possibilities to invoke the activation method:
If the above pre-conditions are satisfied you can inject an assembly and invoke an activation method. There are three possibilities to invoke the activation method:

* You have to specify the full method name to invoke (eg. _this.is.my.namespace.class.method_)
* You can inject an executable that defines an _EntryPoint_ method to execute
* You must specify the full method name to invoke (eg. _this.is.my.namespace.class.method_)
* You can inject an executable that defines an _EntryPoint_ method to execute (like a _Console_ project)
* You can define a method with the following signatue: _<public|private> static void Inject()_

For practical examples see the <a href="https://github.com/enkomio/ManagedInjector/blob/master/Src/Examples/TestRunner/Program.cs">TestRunner project</a>.

### Adding dependencies
If the injected assembly has any dependencies on not standard .NET Assembly, you can add those dependencies with the ``AddDependency`` method.
If the injected assembly has any dependencies on not standard .NET assemblies, you can add those dependencies with the ``AddDependency`` method.

### Adding external files
If the injected assembly needs to load some external file in order to work correctly (like a configuration file) you can specify them with the ``AddFile`` method. This method will copy the specified file in the working directory of the injected process.

### Example

Let's consider the following code:

using System;

namespace InjectedAssembly
{
public class Main
{
// we use a default injection method name in order to execute our code in the remote process
private static void Inject()
{
Console.WriteLine("Hello world from the injected process!");
}
}
}

in order to inject the Assembly generated from the above code it is enough to use the following code:

var pid = 1234;
var injector = new Injector(pid, Assembly.LoadFile("AssemblyToInject.dll"));
var injectionResult = injector.Inject();


## Build
_ManagedInjector_ is currently developed by using VisualStudio 2017 Community Edition (be sure to have the latest version installed). To build the source code be sure you have to:
* install <a href="https://www.microsoft.com/net/download">.NET Core SDK</a>
Expand Down

0 comments on commit 203eabd

Please sign in to comment.