Reputation: 14194
I am currently working with DLL injection and need to have a single hybrid binary that could act as both an executable and a DLL. I thought of maybe writing a DllMain and WinMain function and then compiling it as an executable but I don't know what would happen if I did that. I know that it is posssible to combine a dll and exe by using something like thinstall or extracting the dll to a temporary location then going from there but I don't want to mess with any of that stuff. So basically, is it possible to define a WinMain and Dll Main and then use the resulting executable as both, and if not, is this even possible? Thanks in advance!
Upvotes: 1
Views: 741
Reputation: 6200
It is possible to export functions from a exe too. So you should be able to LoadLibrary("foo.exe") followed by GetProcAddress(hFoo,"bar")
Upvotes: 0
Reputation: 11
You could create a temporary copy of your executable, patch the PE header and inject this copy. Another way is to put the DLL as binary resource to the executable. On runtime you can write this binary resource to a temporary file and use this for injection.
Upvotes: 1
Reputation: 179799
No.
Both a DLL and an EXE have a PE (Portable Executable) header. That header has a field IMAGE_FILE_HEADER::Characteristics
. Bit 14 of that field is either 0 (for an EXE) or 1 (for a DLL).
Upvotes: 3
Reputation: 76500
Why don't you put all the common code into a static library (.lib) and have both DLL project and EXE project as a very thin wrapper around the static library?
Upvotes: 1