Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute program from MemoryStream

How can I execute a program that is in a MemoryStream so I don't have to save it first to the harddisk. The file may not be saved temperally to the harddisk. The program has to be 100% functional from in memory.

        static   string strTemplate = "MyAPP.SOMEprogram.exe";
        byte[] template;
        int len = 0;

        Assembly assembly = Assembly.GetExecutingAssembly();
        using (Stream stream = assembly.GetManifestResourceStream(strTemplate))
        {

            len = (int)stream.Length;
            BinaryReader reader = new BinaryReader(stream);
            template = reader.ReadBytes(len);


        }

        MemoryStream ms = new MemoryStream(template, true);

Now all 100% working program in MemoryStream (on RAM), can i execute that program? Many Thanks

like image 446
Armen Khachatryan Avatar asked Jun 05 '26 21:06

Armen Khachatryan


1 Answers

I cannot think of an obviouse way to do this. The closest I can think of is using a RAM disc - you will have no hard disc access (besides maybe paging) but this is still very different from what you are asking.

Just to note, I am talking about running arbitrary programs, not loading managed assemblies.

like image 161
Daniel Brückner Avatar answered Jun 08 '26 09:06

Daniel Brückner