views:

196

answers:

2

Does anyone know about system-wide API hooking with Delphi?

I downloaded madCodeHook, but it doesn't have any source, so I don't want use it; I want to program it myself.

I found an article on Code Project, but it is in C++. Please help me to write it in Delphi 2010.

A: 

you have to use hook procedures (global : entire system; or local : a single program or thread).

Basically, you'll be calling the following procedures :

  • The SetWindowsHookEx function : to install a hook (monitor system event)
  • The hook function : which is the procedure to be called by windows when the event we "hook" to happens.
  • The UnhookWindowsHookEx function : to remove your hook

Here is a simple example of a local hook monitoring keyboard entries:

//setting up the hook;
//kbHook is a variable of type HHook (unit Windows);
//kbr_Hook is the procedure that will be called once the event happens;
kbHook:=setwindowshookex(WH_KEYBOARD,@kbr_Hook,0,GetCurrentThreadID()); 

MSDN documentation: http://msdn.microsoft.com/en-us/library/ms644990%28VS.85%29.aspx

good luck

+1 because this IS correct. Some people might consider this incomplete, because Phoenix basically requested "source code", but that doesn't make this answer wrong.
Cosmin Prund
@Cosmin Prund: No, it's not correct. The question is about API hooking not hooking APIs. Hooking APIs are one of several possible ways to have your code (DLL) loaded into other processes - which is one of the required steps - but it doesn't solve the problem of API hooking (intercepting API calls).
TOndrej
@TOndrej, you're right and now I see it.
Cosmin Prund
In Mo3ez's defense, Phoenix *did* tag the question with `setwindowshookex`.
Rob Kennedy
A: 

@Phoenix, you can try uallCollection library, is written in delphi 7 (i've tested in delphi 2007 and it works ok) , and comes with an set of examples wich can download from here and full sourcecode. the only drawback is has not been updated since 07-07-2006, but personally i've tested this library even on Windows 7 and it works ok.

RRUZ
i tray uallCollection but it only obtain local api hook.i want to inject a dll into system process (Hook Api Functions across system)
Phoenix