The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: n-w on February 27, 2005, 12:26:07 PM

Title: make a dll stay in memory
Post by: n-w on February 27, 2005, 12:26:07 PM
I wrote a programm, which loads a dll and installs a hook. But when the programm is terminated, the dll is unloaded -> the hook ist also terminated. Is it really neccessary to let the programm run all the time, or is it possible, that the dll stays in memory, but the exe not?
Title: Re: make a dll stay in memory
Post by: hutch-- on February 27, 2005, 03:20:18 PM
Run an EXE that keeps the DLL in memory. Note that some hooks are defeated with Ctrl+Alt+Del so it is not a successful way to log keystrokes secretly.
Title: Re: make a dll stay in memory
Post by: James Ladd on February 27, 2005, 08:01:38 PM
You can also look at the dll structure associated with the handle and change the use count.
I have done this in the past to force dll's to be unloaded because of cyclic references.
Like Hutch says, Note that some hooks are defeated with Ctrl+Alt+Del so it is not a successful way to log keystrokes secretly.

Title: Re: make a dll stay in memory
Post by: n-w on February 28, 2005, 10:54:08 AM
So how would you write a keyboard hook?

I took:

   invoke SetWindowsHookEx, WH_GETMESSAGE, addr hook, hInst, 0

In my hook function I checked, wheater a WM_CHAR message was sent.

@ striker

How do I get this dll structure?
Title: Re: make a dll stay in memory
Post by: James Ladd on March 12, 2005, 05:41:50 AM
The hinst returned by LoadLibrary is the structure.
At least the last time I did this it was.
Title: Re: make a dll stay in memory
Post by: pbrennick on March 12, 2005, 06:59:36 PM
n-w,
All you have to do is write a DLL that is loaded by the system and then it will always load when windows loads.  You must not load it from an exe not owned by 'system' which is the level above admin which may or may not be above you.  You cannot become system but it is relatively easy to coaxe it to load your dll (it all hangs on where you place it).

Paul
Title: Re: make a dll stay in memory
Post by: Ghirai on March 13, 2005, 12:21:55 AM
Try using a journal hook.