Skip to content
Inject C# code into a running process
Branch: master
Clone or download
UsmanSabir and ChadSki bootstrapper clr loader fix (#8)
Fix: always return pClrRuntimeHost, regardless of whether the CLR was running
Latest commit b0f7432 Jul 18, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src bootstrapper clr loader fix (#8) Jul 18, 2018
.gitignore Convert to VS2015 project; ensure works on Windows 10. Mar 6, 2016
LICENSE Update license information Sep 6, 2013
SharpNeedle.sln Convert to VS2015 project; ensure works on Windows 10. Mar 6, 2016
readme.md Update readme.md Nov 7, 2017

readme.md

SharpNeedle

A project for properly injecting C# dlls into other processes.

Note: SharpNeedle currently only supports 32-bit processes. You are welcome to create a pull request which adds 64-bit support.

Rationale

While merely loading your custom dll injected into a target process' memory space is fun, that is only half of the story. Most dll injection tutorials will describe in detail the first half, but then leave you to run your code from within DllMain, a dangerous and limited proposition. For more information about why you should avoid doing anything interesting in your DllMain, read this thread by Raymond Chen.

This project aims to change that dearth of good dll-injection info, providing an open-source way of not only injecting a dll, but also walking the export address table and calling a method on your dll.

This project is specifically geared towards injecting managed code into another process. We will first inject the "Bootstrapper" module, then tell it to load the CLR and start our example managed project.

Usage

Developed in Visual Studio Community 2015 on Windows 10.

In src\Launcher\Launcher.cpp, specify the process name to inject into. In src\ExampleProject\Example.cs, customize EntryPoint() to do as you like. Ensure the process you are injecting into is running. Compile and run with appropriate permission levels. I use an unelevated Visual Studio, then run output from an Administrator command prompt.

Developers

The most interesting file is src\Launcher\Injection.cpp, which deals with walking DLL export tables and creating remote threads.

License

The entirety of my work on this project is released under the 2-clause BSD license.

'src\Launcher\HCommonEnsureCleanup.h' was provided courtesy of GameDeception.net and its license is unclear.

You can’t perform that action at this time.