I'm working in a project related with sandboxing technologies.
Currently I'm writing a C program that gets a small assembly .exe
binary (.NET)
from a remote web server. This binary is stored in memory (never touch disk) and my intention is to run this binary from memory. If my client was made in .NET
I would have no problem to run that assembly from memory (in fact, are many differents ways of getting this) but of course that's not possible with C
(not completely sure).
My questions is: having that assembly .exe
in the address space of my C
program, is there any way to run it from there? Is there any way to allow the CLR
to run it? At first I thought to invoke powershell to run it from there (using Reflection.Assembly) but that case involve writing the assembly to disk.
In any case, no doubt that the best and efficient way of getting this is by using a .NET
client.
If it's a exe. build from .net then it is possible, check http://www.codeproject.com/Articles/13897/Load-an-EXE-File-and-Run-It-from-Memory
If it is an unmanaged binary then I am not aware of a method to do this. If you cannot save it to the HDD, even in a temporary folder you could try some sort of ramdrive. The execution the is easy with the following code:
//this is using imports from System.Diagnostics and System.IO
byte[] exeBytes = GetBytesFromStream(stream); // Get the .exe file from a webstream or something
string tmpFilename = Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + ".exe";
string tmpFilePath = Path.Combine(Path.GetTempPath, tmpFilename);
File.WriteAllBytes(tmpFilePath, exeBytes);
Process.Start(tmpFilePath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With