| View previous topic :: View next topic |
| Author |
Message |
ohowson
Joined: 28 May 2008 Posts: 1
|
Posted: Wed May 28, 2008 10:19 am Post subject: Keep Hooking... |
|
|
I've set up a number of hooks on the registry API calls. My program basically looks like this...
program blah blah;
uses blah blah;
var somefunc_next: function (stuff):longint; stdcall;
function somfunc_callback(stuff):longint; stdcall;
begin
dostuff;
restult:=somefunc_next(stuff);
end;
HookAPI('dll to hook','somefunc',@somefunc_callback,@somefun_next);
WinExec('program to hook to',SW_SHOWNORMAL);
UnhookAPI(@somfunc_next);
end.
So what I need to know is...
1. How do I make my application continue hooking until the exec'd program closes? As is it starts hooking, runs the program, then stops.
2. Will this continue hooking other processes (ie dll's etc) started by the exec'd program?
tia  |
|
| Back to top |
|
 |
madshi Site Admin
Joined: 21 Mar 2004 Posts: 5908
|
Posted: Thu Jul 03, 2008 7:57 pm Post subject: |
|
|
Hello,
and sorry for the extremely late reply!
About your questions: You may want to read the documentation carefully to understand the difference between process wide and system wide API hooking. Do you want to hook registry API calls inside of a specific running process, only? Or do you want to hook all currently running processes? And all newly created process, too? Or maybe one specific executable file (e.g. iexplore.exe) or something like that?
Generally in the NT family calling HookAPI only ever affects the current process. So if you want to hook another process or maybe even multiple processes, you need to put your hooking code into a little dll and then inject your dll into the wanted process(es). |
|
| Back to top |
|
 |
dcsoft
Joined: 11 Dec 2004 Posts: 353 Location: San Francisco Bay Area, CA USA
|
Posted: Sat Jul 12, 2008 6:07 pm Post subject: Use ShellExecuteEx instead of WinExec |
|
|
If you use ShellExecuteEx() to launch the app, you can do so on a separate thread. Use the SEE_MASK_NOCLOSEPROCESS flag so that the hProcess of the launched app is returned to you. Then do a
WaitForSingleObject(hProcess);
This call will return only when the launched app is terminated.
Don't forget to
CloseHandle(hProcess);
when you're done.
-- David |
|
| Back to top |
|
 |
|