Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
C# Java Assembly

This branch is 26 commits ahead of fday:master

README.md

dotnet-dll-injector

Tool for injecting managed .NET DLL libraries into native process (or not native with some limitations). Support both x86 and x64. Tested on v2.0.50727 and v4.0.30319 runtimes. For loading runtime was used interface marked as obsolete from 4.0 and later.

This project is based on original NDLLInjector by fday.

How To Use

You can either use dependency manager like Maven, Grendle or Ivy or download precompiled JARs and include them in your project's classpath.

The JAR is being releases as OSGi bundle and therefore it can be used in such OSGi frameworks like Equinox, Apache Felix or FUSE ESB.

Maven Users

Maven dependency to be added into the POM:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>dotnet-dll-injector</artifactId>
    <version>0.2.1</version>
</dependency>

Non-Maven Users

If you are not using Maven (nor any other dependency manager), then you have to download precompiled binaries available here along with all required dependencies (~1MB zip file).

Code Sample

Use this code to inject DLL into any process (this is Java code, not C#):

public class Main {

    public static void main(String[] args) {

        String procName = "someprocess.exe";     // process name
        File dll = new File("path/to/some.dll"); // injectee DLL path

        // signature of method to be run after DLL is injected
        Signature signature = new Signature("TestNamespace", "Program", "Main"); 

        int pid = InjectorUtils.getProcessID(procName);     // get process ID
        Injector.getInstance().inject(pid, dll, signature); // inject DLL into process
    }
}

The DLL file which you want to inject has to define method with the following signature:

public static int MethodNameHere(string arg) {
    // code
}

For example (this is C# code, not Java):

namespace TestNamespace {
    class Program {
        public static int Main(string arg) {
            MessageBox.Show("Hello World from Injectee!");
            return 0;
        }
    }
}

It's important to note that if you want to read / write to the process memory classes / objects, the DLL file should be build with the same framework version as the process into which you want to inject it.

If you do not want to mess with process runtime, then you can use any framework you need.

How To Build

If everything is configured, then it's enough to run:

mvn clean install

Follow the next points to understand how to configure build if your environment has not been configured.

Configure .NET

Sonar maven-dotnet-plugin is not able to take parameters for MSBuild, so you have to change all *.csproj files from the project top reflect correct path to .NET framework home directory. I've already created ticket for this problem in Sonar JIRA - SONARPLUGINS-2133. Because of that you have to edit each *.csproj file and align this path to point existing file:

<Import Project="C:\WINNT\Microsoft.NET\Framework\v2.0.50727\Microsoft.CSharp.targets" />
Something went wrong with that request. Please try again.