Was messing around my injection code and decided to give back. not sure if it will be useful to anyone. Comments are welcome.
Credit:
JuJuBoSc/Mike_ : Original idea
!@^^@! : Reflexion stuff
Shynd : I stole some Blackmagic code.
Goal, 1 source file, and no C++ stub dll to load the assembly.
*Yes it use the FASM library, but if your gonna use inject .NET CLR might aswell have it close if you need to inject some asm later on.
*If you realy do not want to use FASM as an additional library you'll have to generate the byte code with the .Assemble from FASM and add in the variables pointers. not hard just less practical.
how to:
-Just add DotNetInjector.cs to you project
The only tricky part is the Reflexion part to get the Entrypoint. In your DLL to inject, add this attribute class and add the attribute to your entrypoint method.
If you do not want to use this just change the Injection parameter to ask for the assembly path, the namespace.class and Method to call. The reflexion part include those 3.
Code:
namespace InjectedDll
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] //We don't want this to be used in more than one place
public class EntryPoint : Attribute
{
}
public class Startup
{
[EntryPoint]
[STAThread]
public static int EntryPoint(String pwzArgument)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main());
return 1;
}
}
}
Then in the main app you get the Type of the entrypoint to pass it to the Inject function
Code:
public static readonly Type InjectedDllEntryPoint = typeof(InjectedDll.Startup);
Then you can simply call the injection
Code:
DotNetInjector injector = new DotNetInjector(process);
injector.InjectAndWait(InjectedDllEntryPoint, "I'm injected param"); //Will stop till the Assembly finish
or
injector.InjectAndForget(InjectedDllEntryPoint, "I'm injected param"); //Will not stop
Mirror:
https://mega.nz/#!lxUHTa4C!tsnbCXlnW...XPsgn9ohKpn21Y