Page 1 of 1

injecting a DLL

Posted: Wed Mar 12, 2014 10:03 am
by icealys
when you inject a dll and dllmain gets called, how does your full dll code get executed? where does dllmain return to?

Re: injecting a DLL

Posted: Wed Mar 12, 2014 10:59 am
by Rusky
Dllmain is just for initialization and such. The rest of the library can be called into by the application.

What does this have to do with osdev?

Re: injecting a DLL

Posted: Wed Mar 12, 2014 11:43 am
by jnc100
You load up a DLL with LoadLibrary which loads it into your process' address space and calls DllMain and then returns to the code which called LoadLibrary. To actually call functions in the DLL, you need to get their addresses with GetProcAddress and call the returned function pointer.

Calling FreeLibrary will also call DllMain, before unloading the DLL, but this time will pass a different value as the fdwReason parameter to DllMain (for a list of these, see here).

Regards,
John.