Click here to Skip to main content
Click here to Skip to main content
Go to top

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

Introduction

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];
      if(pi->hProcess)
      {
          InjectLib(pi->hProcess, fname);  // hook new process<CODE>
</CODE>      }
   }
#endif

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:

CHookAPI::CHookAPI()
{
   LoadMyDll(); 
   Init();
   HookAllAPI();
}
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

License

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

Share

About the Author

pudn.com
Web Developer
China China
An old C programmer in China.

Comments and Discussions

 
GeneralRe: Find window handle from TextOut functions Pinmemberprogramsalon24-Feb-08 15:06 
Generalwhen I hook same process for second time and close app window process also closed :( [modified] Pinmembertruestepper15-Jan-08 8:28 
GeneralRe: when I hook same process for second time and close app window process also closed :( Pinmemberprogramsalon24-Feb-08 15:22 
AnswerRe: when I hook same process for second time and close app window process also closed :( Pinmembertruestepper24-Feb-08 23:08 
GeneralHook socket example.. Pinmemberherlimam7-Jan-08 16:20 
GeneralRe: Hook socket example.. Pinmemberprogramsalon24-Feb-08 15:13 
GeneralHook a DLL PinmemberZorro937317-Jan-08 3:07 
QuestionHow to avoid the Anti-Virus Software? Pinmemberwangk070519-Dec-07 14:50 
GeneralRe: How to avoid the Anti-Virus Software? Pinmemberprogramsalon24-Feb-08 15:19 
GeneralIt supports Win9x/NT/XP/2003/Vista. Pinmemberalva.shi26-Nov-07 16:50 
GeneralRe: It supports Win9x/NT/XP/2003/Vista. Pinmemberprogramsalon28-Nov-07 15:48 
Generalvisual c++ 2005 Pinmemberchmouc219-Nov-07 7:39 
GeneralRe: visual c++ 2005 Pinmemberhnxthuyao19-Nov-07 17:04 
QuestionIt conflicts with Explorer.exe process sometimes Pinmemberwangk070514-Sep-07 19:37 
AnswerRe: It conflicts with Explorer.exe process sometimes Pinmemberprogramsalon16-Sep-07 7:13 
GeneralRe: It conflicts with Explorer.exe process sometimes PinmemberSloanCode14-Sep-08 12:29 
GeneralHook on Windows Vista Pinmemberalva.shi9-Sep-07 15:29 
GeneralRe: Hook on Windows Vista Pinmemberprogramsalon16-Sep-07 7:14 
GeneralRe: Hook on Windows Vista Pinmemberalva.shi22-Nov-07 19:46 
Generalto download the full lastest version Pinmemberprogramsalon10-Aug-07 17:20 
GeneralApplications not opening in Windows XP SP2. PinmemberAttVis16-Apr-07 0:20 
GeneralRe: Applications not opening in Windows XP SP2. Pinmemberwangk070519-Dec-07 15:03 
Generalcode Pinmemberxiyaa11-Mar-07 23:40 
QuestionAmd Environment Pinmemberyuchul520-Jan-07 21:22 
Generalto download new version Pinmemberprogramsalon28-Dec-06 1:46 
QuestionRe: to download new version Pinmemberzantoy4-Oct-07 23:45 
QuestionHookAPINT crashing IE , MSDEV, Adob photoshop etc...????? PinmemberRakesh R. Yadava8-Dec-06 3:35 
GeneralHyper Threading Environment Pinmembersneijder7-Dec-06 18:58 
GeneralTextOut hook API Pinmemberbiman ghpsh5-Dec-06 20:13 
Generalabout the bug Pinmemberprogramsalon30-Nov-06 17:25 
GeneralRe: about the bug Pinmemberwangk198330-Nov-06 23:16 
QuestionHow to fix the bug??? Pinmemberwangk198328-Nov-06 21:18 
QuestionFor whom wants to hook FILE OPERATION Pinmemberwangk198325-Nov-06 8:11 
QuestionRe: For whom wants to hook FILE OPERATION Pinmemberzantoy5-Oct-07 1:08 
GeneralHookOneProcess and HOOKREG don't work properly Pinmembertezm11-Aug-06 0:18 
GeneralRe: HookOneProcess and HOOKREG don't work properly Pinmemberprogramsalon30-Nov-06 17:30 
GeneralHelp on hooking 1 process only Pinmemberjefft26-Apr-06 4:11 
GeneralRe: Help on hooking 1 process only Pinmemberprogramsalon27-Jun-06 17:54 
GeneralZeesh Pinmembersdssd7-Apr-06 11:28 
GeneralRe: Zeesh Pinmemberprogramsalon27-Jun-06 17:57 
GeneralFull source Code Pinmembergalaad_g_breizh21-Feb-06 4:27 
GeneralRe: Full source Code PinmemberAchernar27-Feb-06 20:37 
GeneralRe: Full source Code Pinmemberprogramsalon27-Jun-06 17:47 
GeneralRe: Full source Code Pinmemberprogramsalon27-Jun-06 18:30 
Generalusing CHookApi class Pinmembervtalau6-Feb-06 17:30 
GeneralWSARecv() is missing hook PinmemberPine19796-Dec-05 23:22 
GeneralRe: WSARecv() is missing hook Pinmembervtalau7-Feb-06 18:01 
GeneralRe: WSARecv() is missing hook Pinmemberprogramsalon27-Jun-06 18:07 
GeneralNew proccess that start after my Hook APP run is not Hooked. Pinmembertamtt31-Oct-05 4:10 
GeneralRe: New proccess that start after my Hook APP run is not Hooked. Pinmemberprogramsalon27-Jun-06 18:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.8.140916.1 | Last Updated 31 Jan 2005
Article Copyright 2005 by pudn.com
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid