injecting a DLL

Programming, for all ages and all languages.
Post Reply
icealys
Member
Member
Posts: 60
Joined: Mon Feb 17, 2014 3:54 pm

injecting a DLL

Post by icealys »

when you inject a dll and dllmain gets called, how does your full dll code get executed? where does dllmain return to?
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

Re: injecting a DLL

Post 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?
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: injecting a DLL

Post 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.
Post Reply