Article View: borland.public.cppbuilder.nativeapi
Article #16151Re: special hook question
From: Mike Collins
Date: Wed, 28 May 2003 22:58
Date: Wed, 28 May 2003 22:58
50 lines
3922 bytes
3922 bytes
Not 100% sure if I understand you so correct me if I'm wrong: You want to determine if a SPECIFIC application can be executed, based on the existence of a secondary special file? So you're not trying to catch / filter the execution of all files executed by the user / system! There are a few ways to achieve this, however, I'm no expert and most of the following is based on research as opposed to actual hard code :-) The first system, which should work perfectly for you, is to implement a IShellExecuteHook COM interface - I'll probably be suitably corrected here, but this is basically a COM object which can be used to filter / marshal what ShellExecute (and ShellExecuteEx) can execute. When a user tries to execute an application or file, explorer.exe (the desktop for all intensive purposes) calls ShellExecute / Ex and passes along the required application / file. ShellExecute, in turn, determines how to handle the app / file and (I assume) somewhere down the line calls CreateProcess. Now it is possible to hook into ShellExecute/Ex using the IShellExecuteHook interface. For this you need to create the COM object (http://www.codeguru.com/shell/ShellLogging.html) and then register it (detailed in the article above). Now every time ShellExecute is fired (from with explorer.exe or any other application) your hook is instantiated and you can validate what goes on i.e. check the application that is being launched and check for the existence of the file. However, there are a few limitations to this method. Primarily the problem with this system is that it does NOT hook or catch CreateProcess. From the tests that I've done, it is possible to launch application from a command prompt which I can only assume is because cmd.exe uses CreateProcess to execute application / executables. Because of this, it would also be possible for a third-party to by-pass this check by creating an application that called CreateProcess on the Specific application directly. After much research, the only way that I could find to enforce a system wide hooking mechanise to marshal the execution of application both from the shell and the command, was to used a kind of DLL-injection system using SetWindowsHookEx to get my DLL into the launched application memory space and then patch the IAT import table, to re-direct all calls to ShellExecute / Ex, CreateProcess A / W, LoadLibrary and GetProcAddress. Still have a few problems with THIS method :-) Hope this help a bit, e-mail with any question but as I said, most of this is un-tested! "Dermold" <dermold@gmxx.com> wrote in message news:3ed51019@newsgroups.borland.com... > hi, > > i have to create a system which decide (if a special file exists) whether a
Technical Details
Message-ID:
<3ed53e63$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!38.144.126.75.MISMATCH!feed1.newsreader.com!newsreader.com!news-out.visi.com!petbe.visi.com!dimensional.com!pulsar.dimensional.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!uunet!sac.uu.net!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3ed51019@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,da987a5f3effc388 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-28 16:18:07 PST Reply-To: "Mike Collins" <mikec@kr8.co.uk> From: "Mike Collins" <mikec@kr8.co.uk> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ed51019@newsgroups.borland.com> Subject: Re: special hook question Date: Wed, 28 May 2003 23:58:54 +0100 Lines: 52 Organization: kr8 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 81.2.78.34 Message-ID: <3ed53e63$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1054162531 81.2.78.34 (28 May 2003 15:55:31 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!38.144.126.75.MISMATCH!feed1.newsreader.com!newsreader.com!news-out.visi.com!petbe.visi.com!dimensional.com!pulsar.dimensional.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!uunet!sac.uu.net!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail