Jump to content
Tuts 4 You



Recommended Posts


I´m trying to create an .exe file, which can be used as a dll file at the same time. :)

Take, for example, this piece of code:

#include <Windows.h>BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
int main()

Just executing it like any other exe will run int main(). Now, the idea is that when this .exe file is loaded via LoadLibrary DllMain is called as if it was a dll.

Is this actually possible? ;)

Or is there any other way the exe gets notified when it is LoadLibrary loaded?

deep :)

Edited by deepzero
Link to comment

hi k11,

very nice blog, bookmarked! :yes:

However, as far as i understood the article, the malicious file crates a copy of itself, then blows the DllCharacteristic flag in the PE header. Is a PE header manipulation necessary?

Forcing said flag in my example code from post #1 didnt change anything, except for that the file cant be treated as an exe anymore. :(

deep :)

Link to comment

yes you need to change the pe header

compile this as dll:

#include <windows.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{ if (hinstDLL == GetModuleHandle(0) && fdwReason == DLL_PROCESS_ATTACH && lpvReserved == 0)
MessageBox(0,L"dll dynamic load",L"dd",MB_OK);


sorry it is not GetModuleHandle(0)... it is GetModuleHandle("yourdllname.dll")

Edited by k11
Link to comment
I´m trying to create an .exe file, which can be used as a dll file at the same time.

Getting back to your original question, I would create a dynamic *.dll app from the *.exe

export the functions that you wish to share as a dll.

In the function calls, the parameters can be used to determine

whatever you wish. This can be loaded and exports getprocaddressed.

Link to comment
  • 3 weeks later...

So magical idea!If you created a win32 console application. ,but,there are two "main" funcation,,,inconceivable!

just like %systemroot%\system32\ntoskrnl.exe

Edited by ErrorShow
Link to comment
  • 2 months later...

ooops, again i forogt to reply to one of my threads...sorry. :)

As i found out a while ago, this is how you do it in VS:

1) create a new .dll project

2) set DllMain as EntryPoint in "project->settings->linker->advanced"

3) dll-characteristic flag decides about dll/exe

thanks to everyone involved :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...