![]() |
Hooking API RegCreateKeyA,RegCreateKeyW |
Post Reply
|
Page 123 7> |
| Author | ||
slhack
Newbie
Joined: 21 May 2008 Online Status: Offline Posts: 33 |
Quote Reply
Topic: Hooking API RegCreateKeyA,RegCreateKeyWPosted: 27 May 2008 at 1:22pm |
|
|
Hi all!
I'm looking for hook an API in C++. i need to hook the calls named RegCreateKeyA and RegCreateKeyW and other function like the regmon's software. My goal is to hook globally these calls but I don't know how to start hooking. I know that I've to use the function named SetWindowsHookEx(); but I can't use the correct values for each parameter...And 1 more thing: do I need to create a dll to have a global hook? I'm using Visual Studio 2008 and say me if I have to change some settings on my project parameters. Is there anyone who can help me? Can you write me few lines of code,plz? Cause I surfed dozen and dozen of websites and I found a lot of differences on how to hook, but I don't know which is the best... Thanks in advance Edited by slhack - 27 May 2008 at 2:32pm |
||
![]() |
||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17287 |
Quote Reply
Posted: 27 May 2008 at 3:17pm |
|
|
Hi slhack,
Regmon doesn't hook APIs, it uses a driver to obtain its information.
This function is not used to hook functions.
You might have a look at this topic for more details / ideas:
|
||
|
Daily affirmation:
net helpmsg 4006 |
||
![]() |
||
slhack
Newbie
Joined: 21 May 2008 Online Status: Offline Posts: 33 |
Quote Reply
Posted: 28 May 2008 at 4:12am |
|
|
thanks very much! It's very useful!
But I get these errors/warnings when I compile with Visual Studio 1>c:\documents and settings\cesco\my documents\visual studio 2008\projects\bau\bau\Form1.h(19) : warning C4561: '__fastcall' incompatible with the '/clr' option: converting to '__stdcall' 1>c:\documents and settings\cesco\my documents\visual studio 2008\projects\bau\bau\Form1.h(133) : warning C4441: calling convention of '__stdcall ' ignored; '__clrcall ' used instead 1>c:\documents and settings\cesco\my documents\visual studio 2008\projects\bau\bau\form1.h(19) : warning C4793: 'N_RegCreateKeyExW' : function compiled as native : 1> The function is marked as 'naked' 1>Linking... 1>bau.obj : error LNK2028: unresolved token (0A00002D) "extern "C" long __stdcall RegCreateKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,wchar_t *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES *,struct HKEY__ * *,unsigned long *)" (?RegCreateKeyExW@@$$J236YGJPAUHKEY__@@PB_WKPA_WKKPAU_SECURITY_ATTRIBUTES@@PAPAU1@PAK@Z) referenced in function "private: long __clrcall bau::Form1::N_RegCreateKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,wchar_t *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES *,struct HKEY__ * *,unsigned long *)" (?N_RegCreateKeyExW@Form1@bau@@$$FA$AAMJPAUHKEY__@@PB_WKPA_WKKPAU_SECURITY_ATTRIBUTES@@PAPAU3@PAK@Z) 1>bau.obj : error LNK2001: unresolved external symbol _RegCreateKeyExW@36 1>bau.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall RegCreateKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,wchar_t *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES *,struct HKEY__ * *,unsigned long *)" (?RegCreateKeyExW@@$$J236YGJPAUHKEY__@@PB_WKPA_WKKPAU_SECURITY_ATTRIBUTES@@PAPAU1@PAK@Z) referenced in function "private: long __clrcall bau::Form1::N_RegCreateKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,wchar_t *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES *,struct HKEY__ * *,unsigned long *)" (?N_RegCreateKeyExW@Form1@bau@@$$FA$AAMJPAUHKEY__@@PB_WKPA_WKKPAU_SECURITY_ATTRIBUTES@@PAPAU3@PAK@Z) 1>C:\Documents and Settings\cesco\My Documents\Visual Studio 2008\Projects\bau\Debug\bau.exe : fatal error LNK1120: 3 unresolved externals (I tried to change Project properties to avoid the"/clr" option but I still get errors...without "clr" I got errors anyway )I created this Declaration:
And then this one:
Why? Can u help me? I know that I'm noob but I'm ready to learn ![]() thanks again! Edited by slhack - 28 May 2008 at 4:24am |
||
![]() |
||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17287 |
Quote Reply
Posted: 28 May 2008 at 4:35am |
|
|
Do you have Advapi32.lib specified in the linker settings?
The easiest thing would probably be for you to ZIP and upload (somewhere) a sample project that produces the problems you're encountering. You could PM me the link to the uploaded project, if you didn't wish to make it publicly known.
However, it looks like you're attempting to use the code inside of a mixed project, etc. I might suggest trying to isolate just the code you're having trouble with into its own project, and get it working there, before attempting to integrate it into a larger, more complex project.
|
||
|
Daily affirmation:
net helpmsg 4006 |
||
![]() |
||
slhack
Newbie
Joined: 21 May 2008 Online Status: Offline Posts: 33 |
Quote Reply
Posted: 28 May 2008 at 4:46am |
|
|
Here it is my little and simple project:
http://www.megafileupload.com/en/file/67044/Registry-test-rar.html If u can see it for a while I think that u can solve my little problem. Thank you very much!! |
||
![]() |
||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17287 |
Quote Reply
Posted: 28 May 2008 at 7:48pm |
|
|
What version of Detours are you using? Use of "DETOUR_TRAMPOLINE" seems to suggest an older version than the current Detours Express 2.1.
The following code in a Win32 DLL project set up to use the Detours library will produce a DLL that can be used with the WithDLL.exe sample to inject the DLL into a target process' address space, and hook the RegCreateKeyExW function. I used calc.exe. So, I invoked WithDLL.exe as follows:
DbgView verifies that InterceptRegCreateKeyExW is called a number of times.
|
||
|
Daily affirmation:
net helpmsg 4006 |
||
![]() |
||
slhack
Newbie
Joined: 21 May 2008 Online Status: Offline Posts: 33 |
Quote Reply
Posted: 29 May 2008 at 3:02am |
|
|
thank you but I have another problem: I discovered that I have to compile detours.lib(cause I haven't seen the guide before) but I can't compile it i get a lot of errors:
this one if I try to compile makefile in main directory ("C:\Program Files\Microsoft Research\Detours Express 2.1") Microsoft (R) Program Maintenance Utility Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. cd "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\src" Building for 32-bit X86. if not exist "..\include" mkdir "..\include" if not exist "..\lib" mkdir "..\lib" if not exist "..\bin" mkdir "..\bin" rc detoured.rc 'rc' is not recognized as an internal or external command, operable program or batch file. NMAKE : fatal error U1077: 'rc' : return code '0x1' Stop. NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\bin \nmake.exe"' : return code '0x2' Stop. And this one when i try to make it from "src" directory Microsoft (R) Program Maintenance Utility Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. Building for 32-bit X86. if not exist "..\include" mkdir "..\include" if not exist "..\lib" mkdir "..\lib" if not exist "..\bin" mkdir "..\bin" NMAKE : fatal error U1073: don't know how to make 'detoured.cpp' Stop. Why? and I can't find a solution on these errors!! Edited by slhack - 29 May 2008 at 3:08am |
||
![]() |
||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17287 |
Quote Reply
Posted: 29 May 2008 at 3:23am |
|
|
If you open a Visual Studio 2008 Command Prompt, change to the folder where Detours is installed (C:\Program Files\Microsoft Research\Detours Express 2.1), and type nmake, what results do you get?
Edited by molotov - 29 May 2008 at 3:23am |
||
|
Daily affirmation:
net helpmsg 4006 |
||
![]() |
||
slhack
Newbie
Joined: 21 May 2008 Online Status: Offline Posts: 33 |
Quote Reply
Posted: 29 May 2008 at 3:43am |
|
|
YEEEEESS!!It WORKS!! THANK you A LOT!!
but I still get few errors in the final stage of nmake: symtest.cpp symtest.cpp(270) : error C2664: 'BOOL (HANDLE,PSYM_ENUMMODULES_CALLBACK64,PVOID) ' : cannot convert parameter 2 from 'overloaded-function' to 'PSYM_ENUMMODULES_C ALLBACK64' None of the functions with this name in scope match the target type NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN \cl.EXE"' : return code '0x2' Stop. NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN \nmake.exe"' : return code '0x2' Stop. NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN \nmake.exe"' : return code '0x2' Stop. But I've seen that lib was compiled. But why I got these errors? In the afternoon I'll try again with my project. Thank u very much again! |
||
![]() |
||
molotov
Moderator Group
Joined: 04 October 2006 Online Status: Offline Posts: 17287 |
Quote Reply
Posted: 29 May 2008 at 4:35am |
|
Probably, this is covered here:
Edited by molotov - 29 May 2008 at 4:36am |
||
|
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 |