Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Start C# console application from Byte Array

I want to start a C# Console Application by loading it from a byte array. if I write the application to disk and start the program manually, it starts, so it means that the bytes were read correctly. I tried various snippets that I found online, for example:
Code
Assembly a = Assembly.Load(programma);
             MethodInfo method = a.EntryPoint;
             if (method != null)
             {
                 object o = a.CreateInstance(method.Name);
                 method.Invoke(o, null);
             }

or:

Code
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;
        }

These codes actually work with visual application c# (Winforms), but not with those console applications.
How can i make it works?
Code
var appDomain = AppDomain.CreateDomain("ExecutionDomain");
appDomain.ExecuteAssembly("Program.exe");
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by opsecJun 17, 2022 02:11 PM 2 227 Jun 17, 2022 02:11 PM
Last Post: benio2
[C#] by Julius013Mar 2, 2022 05:12 PM 4 311 Mar 2, 2022 05:12 PM
Last Post: Julius013
[C#] by madeha elsayedxxxxJun 16, 2020 05:44 PM 7 232 Jun 16, 2020 05:44 PM
Last Post: XaXBioX