Invested * .exe in dll

Does anyone know how I can insert an exe file into a dll?

I have a tool that is an exe file that I call from C # code.

The thing is, I want to have 1 dll containing this tool (exe file) and dll containing my C # code.

Is it possible to embed this exe file in resources?

thanks in advance

+6
exe c # dll
source share
5 answers

Of course. You can add any file as RC_DATA as a resource. But I believe that you will need to first eject it to disk before calling it!

What IDE / language are you using?

[EDIT]

Sorry! You mentioned that you are using C #.

  • Add the resource file to your application (right-click the application in the IDE and select "Add New Item".
  • Use the toolbar in the resource editor to add an existing file.
  • Then extract exe if necessary by calling the code: System.IO.File.WriteAllBytes (@ "C: \ MyEXE \", Resource1.MyEXE);
+9
source share

Do not forget that your use may not be too happy if you do. Embedding an executable file in which they have no control over the DLL that you will extract and run will probably make people worry about running the trojan on their machine.

It is better to leave .EXE in the file system and be transparent about what your application does.

+7
source share

You can load the assembly from bytes []. This can be obtained using the ManifestResourceStream embedded resource.

+2
source share

An alternative might not be embedding the .exe itself, but rather including its functions in the dll and using rundll32 [ 1 ] to execute it.

+1
source share

Note that when you pull a file from your resources onto a disk and then execute code on it, you can run Windows “Data Execution Prevention” - basically, Windows tries to automatically determine if something should be code or data, and if it looks like data (which will have resources), then this will prevent the data from being executed as code.

This becomes a particularly sticky problem if your .NET assembly is used over the network instead of a local disk - there are all kinds of .NET security configurations that might prevent this from working correctly.

Another option and without knowing the details of your project, take this with salt: add the .exe.readme file to your installation, which describes any curious user or IT staff, why there is an executable file that is waiting in the installation directory :)

-one
source share

All Articles