madshi.net Forum Index madshi.net
high quality low level programming
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Keep Hooking...

 
Post new topic   Reply to topic    madshi.net Forum Index -> madCodeHook
View previous topic :: View next topic  
Author Message
ohowson



Joined: 28 May 2008
Posts: 1

PostPosted: Wed May 28, 2008 10:19 am    Post subject: Keep Hooking... Reply with quote

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 smile
Back to top
View user's profile Send private message
madshi
Site Admin


Joined: 21 Mar 2004
Posts: 5908

PostPosted: Thu Jul 03, 2008 7:57 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
dcsoft



Joined: 11 Dec 2004
Posts: 353
Location: San Francisco Bay Area, CA USA

PostPosted: Sat Jul 12, 2008 6:07 pm    Post subject: Use ShellExecuteEx instead of WinExec Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    madshi.net Forum Index -> madCodeHook All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group