Click here to Skip to main content
11,928,352 members (45,336 online)
Click here to Skip to main content
Add your own
alternative version


115 bookmarked

HookAPI source code

, 31 Jan 2005
Rate this:
Please Sign up or sign in to vote.
A system wide api source code for windows api hook developpers


HookAPI is the API SDK that sets up system wide hooks for all windows platforms. It could easily hook 32-bit windows system APIs or 32-bit user-defined DLL. It could be used easily and all you need to do is write a DLL file named mydll.dll or mydll_9x.dll. It is based on ApiSpy32 by Yariv Kaplan.

The code injects two DLLs into the destination application. The first DLL, HookAPIxx.dll, updates the API's first 5 bytes:

papi[0] =0xE8;
*(DWORD *)&papi[1] =(DWORD)ProcessCall -(DWORD)papi -CALL_BYTES_SIZE;

The nother DLL mydllxxx.dll, runs the new API instead of the old API, like this sample to hook the socket function:
int WINAPI mysocket(int af, int type, int protocol)
   WriteLog("debug mysocket, af=%d, type=%d, protocol=%d", af, type, protocol);

   return socket(af, type, protocol);

And HookAPIxx.dll hooks the CreateProcessW/CreateProcessA functions, so it can catch the creation of new processes and inject the two DLLs:

#ifdef WINNT
   if(!strcmp(pinfo->api_name, "CreateProcessW") || 
      !strcmp(pinfo->api_name, "CreateProcessA") )
      pi =(PROCESS_INFORMATION *)pdwParam[9];
          InjectLib(pi->hProcess, fname);  // hook new process<CODE>
</CODE>      }

If you want to use it, then load the first DLL HookAPIxx.dll. If it's an NT system(WinNT/XP/200x), you should call function HookAllProcess() in the DLL and call UnhookAllProcess when you exit. There are other functions in the DLL, like HookOneProcess, HookOneProcess2 to hook one application on NT system.

mydllxx.dll is loaded by HookAPIxx.dll when HookAPIxx.dll is initialized, and then makes the hook:

It includes the following parts:
  • HookAPI SDK full source codes
  • many examples source codes, such as;

  1. Hook socket functions like socket, send, recv, connect, ...

  2. Hook file functions like CreateFile, ReadFile, ...

  3. Hook registry functions like RegOpenKey, RegQueryValue, RegQueryValueEx, ...

  4. Delphi sample for Hook socket function

  5. Delphi sample for Hook file function

  6. Hook ExitWindowsEx

  7. Hook LoadLibrary and GetProcAddress

  8. Hook GDI functions like TextOut, ExtTextOut

  9. Hook Shell API function like SHBrowseForFolder, SHGetFileInfo, ...

  10. Hiden Processes sample, it can hide processes, task managers cannot find it

  11. Filter Advertisement bar sample, it can filter AD bar of IE or other network application, or filter the data from some ports of TCP/UDP

  12. Message Filter sample, it can filter some messages of the windows

  13. Execute file manager sample, it can forbide some files open, execute, and hidden some folders or files

  14. Net encrypt sample, it can encrypt all the application that wrriten with socket. With this, you will not need encrypt in your application.

  15. hook a ship game to auto drop bomb and auto elude bullet


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author
Web Developer
China China
An old C programmer in China.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Amir Mohammad Nasrollahi9-Aug-13 20:57
professionalAmir Mohammad Nasrollahi9-Aug-13 20:57 
GeneralMy vote of 5 Pin
Hosam Ershedat15-Aug-10 10:11
memberHosam Ershedat15-Aug-10 10:11 
GeneralBSoD Pin
RedZenBird21-Jul-08 6:37
memberRedZenBird21-Jul-08 6:37 
GeneralRe: BSoD Pin
Wizardtop30-Nov-08 22:42
memberWizardtop30-Nov-08 22:42 
GeneralHook explorer.exe crash Pin
Member 396937515-Jun-08 20:50
memberMember 396937515-Jun-08 20:50 
QuestionHOOKAPI on WinCE 6.0 Pin
Stiven Wang20-Mar-08 16:56
memberStiven Wang20-Mar-08 16:56 
GeneralRe: HOOKAPI on WinCE 6.0 Pin
programsalon4-Apr-08 17:22
memberprogramsalon4-Apr-08 17:22 
GeneralHooking into an undocumented API Pin
rusty brooks16-Jan-08 7:35
memberrusty brooks16-Jan-08 7:35 
GeneralRe: Hooking into an undocumented API Pin
programsalon24-Feb-08 16:05
memberprogramsalon24-Feb-08 16:05 
GeneralFind window handle from TextOut functions Pin
rusty brooks15-Jan-08 12:32
memberrusty brooks15-Jan-08 12:32 
If I hook into one of the TextOut functions, there is a HDC passed, which is the DC that is having the text written to it.

Is there a reliable way to determine what the HWND that is being written to is?

I've tried a few things, namely hooking into GetDC and GetDCEx, so that whenever a DC is obtained for an HWND I can store it and retrieve it during the TextOut functions. This doesn't really seem to work for me, either I have some mistakes, or something. I'm not able to reliably figure out the proper HWND.
GeneralRe: Find window handle from TextOut functions Pin
programsalon24-Feb-08 16:06
memberprogramsalon24-Feb-08 16:06 
Generalwhen I hook same process for second time and close app window process also closed :( [modified] Pin
truestepper15-Jan-08 9:28
membertruestepper15-Jan-08 9:28 
GeneralRe: when I hook same process for second time and close app window process also closed :( Pin
programsalon24-Feb-08 16:22
memberprogramsalon24-Feb-08 16:22 
AnswerRe: when I hook same process for second time and close app window process also closed :( Pin
truestepper25-Feb-08 0:08
membertruestepper25-Feb-08 0:08 
GeneralHook socket example.. Pin
herlimam7-Jan-08 17:20
memberherlimam7-Jan-08 17:20 
GeneralRe: Hook socket example.. Pin
programsalon24-Feb-08 16:13
memberprogramsalon24-Feb-08 16:13 
GeneralHook a DLL Pin
Zorro937317-Jan-08 4:07
memberZorro937317-Jan-08 4:07 
QuestionHow to avoid the Anti-Virus Software? Pin
wangk070519-Dec-07 15:50
memberwangk070519-Dec-07 15:50 
GeneralRe: How to avoid the Anti-Virus Software? Pin
programsalon24-Feb-08 16:19
memberprogramsalon24-Feb-08 16:19 
GeneralIt supports Win9x/NT/XP/2003/Vista. Pin
alva.shi26-Nov-07 17:50
memberalva.shi26-Nov-07 17:50 
GeneralRe: It supports Win9x/NT/XP/2003/Vista. Pin
programsalon28-Nov-07 16:48
memberprogramsalon28-Nov-07 16:48 
Generalvisual c++ 2005 Pin
chmouc219-Nov-07 8:39
memberchmouc219-Nov-07 8:39 
GeneralRe: visual c++ 2005 Pin
hnxthuyao19-Nov-07 18:04
memberhnxthuyao19-Nov-07 18:04 
QuestionIt conflicts with Explorer.exe process sometimes Pin
wangk070514-Sep-07 20:37
memberwangk070514-Sep-07 20:37 
AnswerRe: It conflicts with Explorer.exe process sometimes Pin
programsalon16-Sep-07 8:13
memberprogramsalon16-Sep-07 8:13 
GeneralRe: It conflicts with Explorer.exe process sometimes Pin
SloanCode14-Sep-08 13:29
memberSloanCode14-Sep-08 13:29 
GeneralHook on Windows Vista Pin
alva.shi9-Sep-07 16:29
memberalva.shi9-Sep-07 16:29 
GeneralRe: Hook on Windows Vista Pin
programsalon16-Sep-07 8:14
memberprogramsalon16-Sep-07 8:14 
GeneralRe: Hook on Windows Vista Pin
alva.shi22-Nov-07 20:46
memberalva.shi22-Nov-07 20:46 
Generalto download the full lastest version Pin
programsalon10-Aug-07 18:20
memberprogramsalon10-Aug-07 18:20 
GeneralApplications not opening in Windows XP SP2. Pin
AttVis16-Apr-07 1:20
memberAttVis16-Apr-07 1:20 
GeneralRe: Applications not opening in Windows XP SP2. Pin
wangk070519-Dec-07 16:03
memberwangk070519-Dec-07 16:03 
Generalcode Pin
xiyaa12-Mar-07 0:40
memberxiyaa12-Mar-07 0:40 
QuestionAmd Environment Pin
yuchul520-Jan-07 22:22
memberyuchul520-Jan-07 22:22 
Generalto download new version Pin
programsalon28-Dec-06 2:46
memberprogramsalon28-Dec-06 2:46 
QuestionRe: to download new version Pin
zantoy5-Oct-07 0:45
memberzantoy5-Oct-07 0:45 
QuestionHookAPINT crashing IE , MSDEV, Adob photoshop etc...????? Pin
Rakesh R. Yadava8-Dec-06 4:35
memberRakesh R. Yadava8-Dec-06 4:35 
GeneralHyper Threading Environment Pin
sneijder7-Dec-06 19:58
membersneijder7-Dec-06 19:58 
GeneralTextOut hook API Pin
biman ghpsh5-Dec-06 21:13
memberbiman ghpsh5-Dec-06 21:13 
Generalabout the bug Pin
programsalon30-Nov-06 18:25
memberprogramsalon30-Nov-06 18:25 
GeneralRe: about the bug Pin
wangk19831-Dec-06 0:16
memberwangk19831-Dec-06 0:16 
QuestionHow to fix the bug??? Pin
wangk198328-Nov-06 22:18
memberwangk198328-Nov-06 22:18 
QuestionFor whom wants to hook FILE OPERATION Pin
wangk198325-Nov-06 9:11
memberwangk198325-Nov-06 9:11 
QuestionRe: For whom wants to hook FILE OPERATION Pin
zantoy5-Oct-07 2:08
memberzantoy5-Oct-07 2:08 
GeneralHookOneProcess and HOOKREG don't work properly Pin
tezm11-Aug-06 1:18
membertezm11-Aug-06 1:18 
GeneralRe: HookOneProcess and HOOKREG don't work properly Pin
programsalon30-Nov-06 18:30
memberprogramsalon30-Nov-06 18:30 
GeneralHelp on hooking 1 process only Pin
jefft26-Apr-06 5:11
memberjefft26-Apr-06 5:11 
GeneralRe: Help on hooking 1 process only Pin
programsalon27-Jun-06 18:54
memberprogramsalon27-Jun-06 18:54 
GeneralZeesh Pin
sdssd7-Apr-06 12:28
membersdssd7-Apr-06 12:28 
GeneralRe: Zeesh Pin
programsalon27-Jun-06 18:57
memberprogramsalon27-Jun-06 18:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 31 Jan 2005
Article Copyright 2005 by
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid