Problem with dll hooking

c++ / delphi package - dll injection and api hooking
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

madshi wrote:Thanks nildo for helping out... :wink:
:D
bparent
Posts: 7
Joined: Mon Mar 21, 2005 3:15 pm

Post by bparent »

Under the hooking rules for system wide hooking I thought one isn't supposed to use 'GUI' stuff like FindWindow, MessageBox, etc.

Does that not apply here? Isn't this GUI stuff in the dll which is then injected and run as a system service.

It seems to be stable enough in Delphi. However, when I convert this code to Builder it hooks the opendialog boxes and changes the title/view ok, but then gives an access violation.

Am I missing something?
uall
Posts: 254
Joined: Sun Feb 20, 2005 1:24 pm

Post by uall »

FindWindow & MessageBox isnt really GUI stuff
that are APIs from user32.dll
so if user32.dll is loaded in the target process u can use these functions without problems
madshi
Site Admin
Posts: 10765
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You must not use FindWindow inside of some system processes, otherwise the OS will reboot.

If you want to hook dialog boxes, it makes sense to not inject your dll into system processes, cause system processes usually don't show dialog boxes (at least not file open/save dialogs). You should inject into system processes only if you really need it.

uall is right, though, if user32.dll is loaded in a process, you can most probably also use it. Just make sure that you weren't the one who loaded it... :-)
bparent
Posts: 7
Joined: Mon Mar 21, 2005 3:15 pm

Post by bparent »

Thanks uall and madshi. It is just that the examples in this thread used:

if not InjectLibrary((ALL_SESSIONS or SYSTEM_PROCESSES), 'DllHook.dll') then
ShowMessage('Fehler beim Inject von DllHook.dll');

and used findwindow and messagebox.

Just wanted clarification on this usage and the rules for hooking. Should the injectlibrary parameter just be for SYSTEM_PROCESSES?
madshi
Site Admin
Posts: 10765
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Only SYSTEM_PROCESS doesn't work. You need to combine it with another flag. I think it's vice versa. You should think about dropping SYSTEM_PROCESSES, if your hook dll is all about open/save dialogs.
bparent
Posts: 7
Joined: Mon Mar 21, 2005 3:15 pm

Post by bparent »

Of course, my bad, I meant to say don't use SYSTEM_PROCESSES just ALL_SESSIONS.
Post Reply