I need to convert an executable to Bytes, and then start a process with it.
What im using now is like:
using System.Reflection;
using System.Threading;
public static class MemoryUtils
{
public static Thread RunFromMemory(byte[] bytes)
{
var thread = new Thread(new ThreadStart(() =>
{
var assembly = Assembly.Load(bytes);
MethodInfo method = assembly.EntryPoint;
if (method != null)
{
method.Invoke(null, null);
}
}));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
return thread;
}
}
Implementation:
var bytes = File.ReadAllBytes(@"C:\myexecutable.exe");
MemoryUtils.RunFromMemory(bytes).Join();
But the problem is, it only works with 32bit executables, and the executable is 64bit. Any idea of how I could do it, any suggestions? Thank you
The error I'm getting:
System.BadImageFormatException: 'Bad IL format.'