Search code examples
.netvirtual-machineportable-executablemscorlib

Can .NET VM (mscorlib) be called from native Win32 program to execute IL/other internal compiled code format?


Old question: I have an .exe (PE) with IL (.NET) code in it. When it is started, a mscorlib.dll (.NET framework) function is called to start IL code. Can I extract .NET code segment and append it to other program (that calls mscorlib.dll to execute that segment)?

New question:

I want to append the compiled code from a C# .NET program to a native, pure Win32 application that can run without any .NET Runtimes, and execute it by dynamically calling mscorlib.dll's functions, if .NET is present. This is like a 'executable joiner' technique, not a native compilation.

I do not want to write some .NET .exe to a temp directory and execute it; it is already done and now want to get rid of temp folder by calling .NET vm directly on .NET code inside my file (by giving out an offset of found structure/session, or just by assigning correct PE .section name - know just a little about PortableExecutable format).

Reference: http://webcache.googleusercontent.com/search?q=cache:u9tTX2sfkhAJ:social.msdn.microsoft.com/Forums/en/clr/thread/2677c0b6-6b3c-4a51-9fcc-c2d8838c7b8b+compiled+IL


Solution

  • Perhaps you are looking for a linker that will take your .NET library and referenced assemblies, and create an executable or .dll that can run without requiring .NET to be installed.

    Two commercial options for this are

    It should also be possible with mono. It has utility called mkbundle which precompiles and add dependencies, but you would need Cygwin and a bit more expertise to get it to work. This question seems like a good start: How to convert a simple .Net console project a into portable exe with Mono and mkbundle?.