
Injecting .Net Assemblies into Unmanaged Processes - el_duderino
https://movaxbx.ru/2018/10/23/injecting-net-assemblies-into-unmanaged-processes/
======
steeve
Indeed this has been possible since pretty much the beginning of .Net. And
it's pretty great imho.

The technique in the OP is slightly different but the end result should be the
same if you inject a IJW DLL into any process.

1\. [https://www.codeproject.com/Articles/10020/Using-managed-
cod...](https://www.codeproject.com/Articles/10020/Using-managed-code-in-an-
unmanaged-application)

------
rootw0rm
didn't click the link, but this has been possible since .Net 2.0. back when
EasyHook was still in alpha I was using it to inject the entire CLR into
unmanaged processes. My ridiculous self was writing intel ASM in C# byte
arrays, changing permissions on memory pages to make them executable, pausing
the process, then injecting my code. After that I discovered C and my life
became much simpler.

~~~
mandeepj
> After that I discovered C

I hope I’m reading it right - you knew intel asm but not C? I’m little
surprised. Sorry

~~~
evincarofautumn
It’s not so unusual. I learned assembly before I learned C, mostly because I
didn’t have a C compiler—or even know that I needed one! My family’s Windows
95 computer had QBASIC preinstalled (which amazingly I learned mostly by
browsing the interactive help) and I discovered that in order to speed up my
graphics routines, I had to write them in assembly in MASM (and DEBUG), also
preinstalled. The fact that they were just _there_ already, without requiring
any installation or configuration, was enormously helpful as a beginner.

At ~10 years old, I didn’t have any frame of reference for how difficult this
tack was compared to other languages, so I just accepted it as “this is what
programming is like”. I only picked up C several years later as I got into
programming languages and studied as many different languages as I could. Now
I work in programming language technology as both a career and a hobby. :)

------
tobi1449
What's the difference between this and simply exporting a method of a .net
assembly via
[https://www.nuget.org/packages/UnmanagedExports/](https://www.nuget.org/packages/UnmanagedExports/)
besides having more control over the CLR/.net environment with the method
posted here?

------
platz
So with this technique, could I say, develop a macro in my language of choice
to execute a snippet of .net code such that the clr runtime is created and the
snippet run in that context?

------
tomc1985
Oh man, I did something similar to inject controls into IE9's statusbar for a
BHO that never got released. As unholy as it seems, having to learn MFC seemed
worse

