Merge Native Dlls into Exe

Is it possible to merge multiple native dlls into an exe?

Yes, I'm aware that his is easily possible with .NET/Mono/Managed dlls, but can I do the same with native ones? I've found UPX, but as it seems it only can pack the files, not merge them.

2 Answers

Dynamic Link Libraries are designed to be used externally. While it should theoretically be possible to repackage the functions they contain, realistically, the best you can do reliably is to pack everything into a self-extracting archive that will extract the executable and its DLLs into a temp folder, then run the executable.

If you can get a hold of the source code, you can probably compile it with minimal changes to a static library (.lib) that could be linked with the program that needs the DLLs, rather than the DLLs being external.

2

Assuming that you have an executable that statically imports from a DLL, you could use the pefrmdllembed tool using the "-impinj" commandline option. It can merge native DLL files into native EXE files (of the same architecture) while resolving the imports.

Example: pefrmdllembed.exe -impinj myapp.exe ogg.dll myapp_injected.exe

It will work with most DLLs. Be careful about special NT loader features such as static TLS; unsupported under 64bit and might not produce good results under 32bit.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest