Run program from MemoryStream

How can I run a program that is in a MemoryStream, so I don’t need to save it to my hard drive first. Unable to save file to hard disk. The program must be 100% functional from 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 the whole 100% working program in MemoryStream (in RAM), can I execute this program? Many thanks

+3
source share
3 answers

I can not think of a way obviouse to do this. The closest I can think of is to use a RAM disk - you will not have access to the hard disk (except, possibly swapping), but it is still very different from what you are asking.

, , .

+2
+1

The key point here is the assembly / loading of the assembly in memory from an array of bytes see . When you have a link to an assembly, you can easily access its types and create them. Once you have type instances, call the method so that it starts your program.

+1
source

Source: https://habr.com/ru/post/1716290/


All Articles