![]() |
Hooking API RegCreateKeyA,RegCreateKeyW |
Post Reply
|
Page 123 7> |
| Author | ||||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17492 |
Post Options
Quote Reply
Topic: Hooking API RegCreateKeyA,RegCreateKeyWPosted: 12 May 2009 at 11:09am |
|||
|
I'd suggest you go through the referenced links to get a feel for things. The WDK includes a sample FSFD, I believe, and you will undoubtedly find some examples by searching...
|
||||
|
Daily affirmation:
net helpmsg 4006 |
||||
![]() |
||||
zu1u
Newbie
Joined: 09 May 2009 Online Status: Offline Posts: 12 |
Post Options
Quote Reply
Posted: 12 May 2009 at 10:17am |
|||
|
ok i'll try driver first. Are there sample drivers that are doing similar to my need? I'm totally new to drivers.
I'm not writing a comercial app. |
||||
![]() |
||||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17492 |
Post Options
Quote Reply
Posted: 11 May 2009 at 6:46pm |
|||
|
The actual hook id used to get the module loaded doesn't really have to do anything - the HookProc can just be a dummy function. Once the code is loaded you can detour the functions as the Detours examples show, etc. There are other techniques for API hooking as well as other ways (AppInit_DLLs, CreateRemoteThread, etc.) to get your code loaded so you can hook the API.
File System Filter Drivers Introduction to File System Filter Drivers |
||||
|
Daily affirmation:
net helpmsg 4006 |
||||
![]() |
||||
zu1u
Newbie
Joined: 09 May 2009 Online Status: Offline Posts: 12 |
Post Options
Quote Reply
Posted: 11 May 2009 at 5:52pm |
|||
exactly thats what i meant. I read that i have to load the code in the adress space of all the processes. The question i have is how can i achieve this in the easiest way? If i use SetWindowsHookEx(.....,0) it is loaded in all process!? What idHook to use though? WM_GETMESSAGE? And how am i invoking the detouring just from loading my code into the address space of some process? Or better not using detouring in that case at all?
maybe, but what i meant by preprocessing is really just that i want to forward the filepath of the file being openend to another part of the overall app. Does a filesystem filter driver suit better to this? I'll read about it but if you can give some advice that'd be great |
||||
![]() |
||||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17492 |
Post Options
Quote Reply
Posted: 11 May 2009 at 4:29pm |
|||
|
Hi zu1u,
|
||||
|
Daily affirmation:
net helpmsg 4006 |
||||
![]() |
||||
zu1u
Newbie
Joined: 09 May 2009 Online Status: Offline Posts: 12 |
Post Options
Quote Reply
Posted: 11 May 2009 at 4:17pm |
|||
|
i just managed to hook a process with detours as described here.
however i didnt get the idea of how to hook a function globally? Is that what the IPC was for? In my case i want to hook createFile from kernel32.dll, so i can do some preprocessing before any file is opened. Can someone point me into the right direction? thx |
||||
![]() |
||||
slhack
Newbie
Joined: 21 May 2008 Online Status: Offline Posts: 33 |
Post Options
Quote Reply
Posted: 08 June 2008 at 7:48am |
|||
|
Thank you very much! It's very easier now to hook apis. Thanks to all!
Now I have to try a lot of things to create my application ![]() You will hear me in a few days I think, for other problems ![]() Edited by slhack - 08 June 2008 at 7:51am |
||||
![]() |
||||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17492 |
Post Options
Quote Reply
Posted: 07 June 2008 at 7:09am |
|||
|
Hi Loins,
Thanks for sharing your Detours macros - looks like it would make using Detours easier.
|
||||
|
Daily affirmation:
net helpmsg 4006 |
||||
![]() |
||||
nanothyll
Newbie
Joined: 12 May 2008 Location: China Online Status: Offline Posts: 28 |
Post Options
Quote Reply
Posted: 06 June 2008 at 7:36pm |
|||
|
I think you are using a wrong way for the detours library.
Here is some macro which i created to help you to hook APIs with detours lib: ------------------------------ #define BEGIN_HOOKS() \ DetourTransactionBegin(); \ DetourUpdateThread(GetCurrentThread()); #define END_HOOKS() \ DetourTransactionCommit(); ////////////////////////////////////////////////////////////////////////// #define HOOK_ADD(n) DetourAttach(&(PVOID&)True_##n, Fake_##n); #define HOOK_DEL(n) DetourDetach(&(PVOID&)True_##n, Fake_##n); ////////////////////////////////////////////////////////////////////////// #define OLD_PROC(n) True_##n #define NEW_PROC(n) Fake_##n ////////////////////////////////////////////////////////////////////////// #define DECLARE_HOOK(n,t,l) extern t (WINAPI * True_##n)l; \ extern t WINAPI Fake_##n l; #define IMPLEMENT_HOOK(n,t,l) t (WINAPI * True_##n)l = n; \ t WINAPI Fake_##n l #define ID(n) FID_##n ------------------------------------------------------- How to use it: ////////////////////////////////////////////////////////////////////////// ///@function: InstallHooks ///@note: Add APIs which you wanna hooking to the list ////////////////////////////////////////////////////////////////////////// BOOL InstallHooks (void) { BEGIN_HOOKS() HOOK_ADD(CopyFileA) HOOK_ADD(ExitProcess) END_HOOKS() return TRUE; } ////////////////////////////////////////////////////////////////////////// ///@function: Uninstall Hooks ///@note: please remove the APIs which you hooked to the list ////////////////////////////////////////////////////////////////////////// void UninstallHooks (void) { BEGIN_HOOKS() HOOK_DEL(CopyFileA) HOOK_DEL(ExitProcess) END_HOOKS() } ////////////////////////////////////////////////////////////////////////// /// @function: DllMain ////////////////////////////////////////////////////////////////////////// BOOL WINAPI DllMain (HINSTANCE hInst, DWORD dwReason, PVOID lpReserved) { static HANDLE hMutex = NULL; switch (dwReason) { case DLL_PROCESS_ATTACH: { DisableThreadLibraryCalls(hInst); if ((hMutex=CreateMutex(NULL, FALSE, NULL))==NULL) return FALSE; if (InitEmit(hMutex)==FALSE || InstallHooks()==FALSE) return FALSE; } break; case DLL_PROCESS_DETACH: { UninstallHooks(); TermEmit(); if (hMutex) { ReleaseMutex(hMutex); CloseHandle (hMutex); } } break; } return TRUE; } ------------------------------- in hooks.h declare the hook function: DECLARE_HOOK (CopyFileA, BOOL, (LPCSTR lpExistingFileName,LPCSTR lpNewFileName,BOOL bFailIfExists)) in hooks.cpp implement it: IMPLEMENT_HOOK(CopyFileA, BOOL, (LPCSTR lpExistingFileName,LPCSTR lpNewFileName,BOOL bFailIfExists)) { pack p(ID(CopyFileA)); p.add_s1(lpExistingFileName); p.add_s2(lpNewFileName); EMIT(p); return OLD_PROC(CopyFileA)(lpExistingFileName, lpNewFileName, bFailIfExists); } =========== Very easy isn't it? BTW: I use detours 2.1 express :) Hope that it is useful to you. |
||||
![]() |
||||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17492 |
Post Options
Quote Reply
Posted: 06 June 2008 at 9:08am |
|||
|
By "setting up", I meant assigning the members.
Yes, since you're passing a mbcs buffer rather than a wide char buffer, you would use the *Ansi function. If you would have passed a wide char buffer, the *Uni function would have worked. Edited by molotov - 06 June 2008 at 9:09am |
||||
|
Daily affirmation:
net helpmsg 4006 |
||||
![]() |
||||
Post Reply
|
Page 123 7> |
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |