APIHijack - A Library for Easy DLL Function Hooking.
Posted
by Wade Brainerd
on January 31st, 2001
Functions are hooked by passing a parameter structure to the HookAPICalls() function as follows:
// Hook structure. SDLLHook D3DHook = { "DDRAW.DLL", false, NULL, // Default hook disabled, NULL function pointer. { { "DirectDrawCreate", MyDirectDrawCreate }, { NULL, NULL } } }; BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD fdwReason, LPVOID lpReserved ) { // When initializing.... if ( fdwReason == DLL_PROCESS_ATTACH ) { hDLL = hModule; // We don't need thread notifications for what we're doing. // Thus, get rid of them, thereby eliminating some of the // overhead of this DLL DisableThreadLibraryCalls( hModule ); // Only hook the APIs if this is the Everquest process. GetModuleFileName( GetModuleHandle( NULL ), Work, sizeof(Work) ); PathStripPath( Work ); if ( stricmp( Work, "myhooktarget.exe" ) == 0 ) HookAPICalls( &D3DHook ); } return TRUE; }
Now all that remains is to get your DLL loaded into the target process. The MSDN has a few good articles on Windows hooks, which are the preferred way to get an arbitrary DLL loaded into a process:
http://msdn.microsoft.com/library/techart/msdn_hooks32.htm
Also, the article from which this code is based shows another way to do it, which involves loading the process to be hooked as a debug target:
http://msdn.microsoft.com/library/periodic/period00/hood0200.htm

Comments
Jordan shoes mentioned Gene to go for the variety, a margin of Nike
Posted by TaddyGaffic on 04/24/2013 05:03pmIn focus groups conducted at 80 community-based organizations around the country, Motivational Educational Entertainment of Philadelphia [url=http://markwarren.org.uk/goodbuy.cfm]nike free[/url] identified disturbing trends among youths ages 16 to 20. The "Just Say No" message of abstinence-only campaigns has been lost on this group of young people, who grew up during an era when the hip-hop sensibility of getting cash and clothes did not incorporate values of conscientious sexual behavior or social responsibility. Rappers who mingle [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache free[/url] with glamorous-looking half-naked women rarely mention contraception while they're listing the number of compromising sexual situations they've been in lately. There are number of good brands in the market like Adidas, Nike, Reebok, Asics, Brooks, Puma etc. Most of these brands have shoes tailored for professional and amateur tennis players. New advanced technologies have made these shoes more player-friendly. After that, I eventually like to try to get down to the 150-160 range. I not entirely sure if that a healthy number for a gal my height or not, and I haven looked into it. But, I know that when I was 180 I still didn feel that [url=http://markwarren.org.uk/goodbuy.cfm]nike free run uk[/url] fit, so I think an extra 20 or so will help with that.. Lotto sneakers selling price are generally liable along with using the form of sneakers you choose on. Your Lotto sneakers established fact because of their style along with good quality plus the create. That they create sneakers coming from all varieties much like the loafers,Puma II Shoes, new sandals, sneakers along with task tennis shoes or anything else
Replyproblem in hooking ntshrui.dll apis
Posted by sameen_f on 07/01/2009 06:35amhi, i have tried this code it is working fine but when i tired to hook other apis then it showed no output...i need help in how to hook apis from ntshrui.dll....or is there any need for any kind of driver with the given source code...
ReplyAPIHijack for IDirect3D8::CreateDevice ????
Posted by boonchait on 12/04/2004 03:08pmHow can i set APIHijack for IDirect3D8::CreateDevice.
Replycan't highjack TextOut well from gdi32.dll
Posted by Legacy on 02/12/2004 12:00amOriginally posted by: Benjamin Gao
when i highjack TextOut function in notepad.exe or wordpad.exe,nothing happened.
Replynot TextOut you wnat to TextOutA and TextOutW
how can I hook Com ports in Win2000,WinXP?
Posted by Legacy on 02/04/2004 12:00amOriginally posted by: Gokay Gursoy
Dear Sir/Madam
ReplyHow can I hook com ports (Com1/Com2) in Win2000/WinXP?
I want to see data incoming and data outgoing from my com1
and com2.I would be very pleased if you send me some delphi
source about this.
Best Regards
Gokay Gursoy
How do i Hook WM_CHAR in WinXP?
Posted by Legacy on 01/30/2004 12:00amOriginally posted by: uqtur
Hello !
I write a hook with VC 6.0 in Win2K and it worked .
but in Win XP It dosn't worked functionally.
my purpose is display some UNICODE characters in
correctly with this HOOK.can any one help me?
thank you .
////
static LRESULT WINAPI MyApp ( int nCode, WPARAM wParam, LPARAM lParam)
{
...
pwszKLID=malloc(10);
msg=(LPMSG)lParam;
//
switch (msg->message)
{
case WM_KEYDOWN:
My6=msg->wParam;
GetKeyboardState(st);
break;
case WM_CHAR:
{
if ((msg->wParam)==63) //can't display correctly ,replace with '?'
{
switch (My6)
{
case 71://g
SendMessage(msg->hwnd,WM_CHAR,234,0);
PostMessage(msg->hwnd,WM_KEYDOWN,8,0);
break;
case 73://i
SendMessage(msg->hwnd,WM_CHAR,188,0);
PostMessage(msg->hwnd,WM_KEYDOWN,8,0);
break;
....
}
}
break;
}
}
//
lResult = CallNextHookEx(g_hhook, nCode, wParam, lParam);
return(lResult);
}
////
ReplyError when compile
Posted by Legacy on 01/28/2004 12:00amOriginally posted by: BigWizard
Deleting intermediate files and output files for project 'TestDLL - Win32 Debug'.
--------------------Configuration: TestDLL - Win32 Debug--------------------
Compiling...
apihijack.cpp
c:\temp\3\apihijack.cpp(158) : error C2440: '=' : cannot convert from 'unsigned long' to 'void *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\temp\3\apihijack.cpp(196) : error C2440: '=' : cannot convert from 'unsigned long *' to 'unsigned long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\temp\3\apihijack.cpp(203) : error C2446: '>' : no conversion from 'unsigned long *' to 'unsigned long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\temp\3\apihijack.cpp(203) : error C2040: '>' : 'unsigned long' differs in levels of indirection from 'unsigned long *'
c:\temp\3\apihijack.cpp(204) : error C2440: '=' : cannot convert from 'unsigned long *' to 'unsigned long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
dllmain.cpp
Error executing cl.exe.
TestDLL.dll - 5 error(s), 0 warning(s)
ReplyHow do i hook a API that exported with ordinal rather than Name,certenly,I know it's protype!
Posted by Legacy on 01/23/2004 12:00amOriginally posted by: Hellow
ReplyHow to hook DLL outside windows \ system32
Posted by Legacy on 08/30/2003 12:00amOriginally posted by: Martijn
ReplyHow to do dynamic LoadLibrary dlls (works for games)
Posted by Legacy on 06/11/2003 12:00amOriginally posted by: twinsen
ReplyLoading, Please Wait ...