Skip to content

sarxos/dotnet-dll-injector

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotnet-dll-injector

This is a tool which can be used for injecting managed .NET DLL libraries into native process (or, with some limitations, into non-native process). Supports both x86 and x64 architectures. It was tested on v2.0.50727 and v4.0.30319 .NET runtimes. Please note that interface used for runtime loading is marked as obsolete and therefore it may stop working some day.

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 (this is C# code, not Java):

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" />

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 64.0%
  • Java 21.6%
  • Assembly 14.4%