1

Hi Engineers, i made a login panel with c# form. I coded everything but now I am in a section that I'm still searching about 1 week and I did not get any result.

I want to add a exe file (rather not .NET) to my resources. and run it when login button press

»»»»IMPORTANT: but I don't want it to copy my exe resources to HDD (simple security :D) so I think I should run it from memory

I dont know this code is true or no but i use this

                    FileStream fs = new FileStream(filepath, FileMode.Open);
                BinaryReader br = new BinaryReader(fs);
                byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));
                fs.Close();
                br.Close();

                Assembly a = Assembly.Load(bin);

                MethodInfo method = a.EntryPoint;
                if (method != null) {
                    object o = a.CreateInstance(method.Name);
                    // invoke the application starting point
                    method.Invoke(o, null);

                }

but I get this error

Could not load file or assembly '8237056 bytes loaded

can anybody help me?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Farhang
  • 13
  • 6
  • 3
    You said the exe is not a .NET one - how would you expect it to run from BCL framework? Assembly and Reflection works with .NET code binaries only. For launching other exe you have Process.Start() – Prateek Shrivastava Mar 09 '20 at 00:48
  • [Does this answer your question?](https://stackoverflow.com/questions/3277711/running-executable-from-memory) – ProgrammingLlama Mar 09 '20 at 00:58
  • So i need something simple to prevent copying by someone. just little security – Farhang Mar 09 '20 at 10:30
  • If you consider paid solutions, look at BoxedApp SDK. If you need little security, may be your exe would require some important data that can be provided a "legal" host... – Artem Razin Mar 10 '20 at 10:15

0 Answers0