Execute byte array as an exe

I would like to execute a program stored in a byte array which is not necessarily a .NET executable without creating a new file. Currently I am using this code but it only works for .net exes :

var assembly = Assembly.Load(assemblyBuffer);
var entryPoint = assembly.EntryPoint;
var commandArgs = new string[0];
var returnValue = entryPoint.Invoke(null, new object[] { commandArgs });
Jon Skeet
people
quotationmark

Assembly.Load is used to load .NET assemblies.

It sounds like you just want to start a new process - so use the Process and ProcessStartInfo classes after saving the file to disk first:

File.WriteAllBytes("tmp.exe", assemblyBuffer);
Process process = Process.Start("tmp.exe", commandArgs);

I think you'll find it hard to launch an executable without saving it to a file system first, although that could be an in-memory file system.

people

See more on this question at Stackoverflow