Click here to Skip to main content
6,595,854 members and growing! (22,188 online)
Email Password   helpLost your password?
General Reading » Hardware & System » Cryptography     Advanced

HookAPI source code

By pudn.com

A system wide api source code for windows api hook developpers
VC6, VC7Win2K, WinXP, Win2003, Dev
Posted:21 Jan 2005
Updated:31 Jan 2005
Views:163,635
Bookmarked:77 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
30 votes for this article.
Popularity: 4.15 Rating: 2.81 out of 5
11 votes, 36.7%
1
1 vote, 3.3%
2
2 votes, 6.7%
3
1 vote, 3.3%
4
15 votes, 50.0%
5

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>

      }
   }
#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

About the Author

pudn.com


Member
An old C programmer in China.
Occupation: Web Developer
Location: China China

Other popular Hardware & System articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 130 (Total in Forum: 130) (Refresh)FirstPrevNext
GeneralBSoD PinsupporterRedZenBird6:37 21 Jul '08  
GeneralRe: BSoD PinmemberWizardtop22:42 30 Nov '08  
GeneralHook explorer.exe crash PinmemberMember 396937520:50 15 Jun '08  
QuestionHOOKAPI on WinCE 6.0 PinmemberStiven Wang16:56 20 Mar '08  
GeneralRe: HOOKAPI on WinCE 6.0 Pinmemberprogramsalon17:22 4 Apr '08  
GeneralHooking into an undocumented API Pinmemberrusty brooks7:35 16 Jan '08  
GeneralRe: Hooking into an undocumented API Pinmemberprogramsalon16:05 24 Feb '08  
GeneralFind window handle from TextOut functions Pinmemberrusty brooks12:32 15 Jan '08  
GeneralRe: Find window handle from TextOut functions Pinmemberprogramsalon16:06 24 Feb '08  
Generalwhen I hook same process for second time and close app window process also closed :( [modified] Pinmembertruestepper9:28 15 Jan '08  
GeneralRe: when I hook same process for second time and close app window process also closed :( Pinmemberprogramsalon16:22 24 Feb '08  
AnswerRe: when I hook same process for second time and close app window process also closed :( Pinmembertruestepper0:08 25 Feb '08  
GeneralHook socket example.. Pinmemberherlimam17:20 7 Jan '08  
GeneralRe: Hook socket example.. Pinmemberprogramsalon16:13 24 Feb '08  
GeneralHook a DLL PinmemberZorro937314:07 7 Jan '08  
QuestionHow to avoid the Anti-Virus Software? Pinmemberwangk070515:50 19 Dec '07  
GeneralRe: How to avoid the Anti-Virus Software? Pinmemberprogramsalon16:19 24 Feb '08  
GeneralIt supports Win9x/NT/XP/2003/Vista. Pinmemberalva.shi17:50 26 Nov '07  
GeneralRe: It supports Win9x/NT/XP/2003/Vista. Pinmemberprogramsalon16:48 28 Nov '07  
Generalvisual c++ 2005 Pinmemberchmouc28:39 19 Nov '07  
GeneralRe: visual c++ 2005 Pinmemberhnxthuyao18:04 19 Nov '07  
QuestionIt conflicts with Explorer.exe process sometimes Pinmemberwangk070520:37 14 Sep '07  
AnswerRe: It conflicts with Explorer.exe process sometimes Pinmemberprogramsalon8:13 16 Sep '07  
GeneralRe: It conflicts with Explorer.exe process sometimes PinmemberSloanCode13:29 14 Sep '08  
GeneralHook on Windows Vista Pinmemberalva.shi16:29 9 Sep '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 31 Jan 2005
Editor: Chris Maunder
Copyright 2005 by pudn.com
Everything else Copyright © CodeProject, 1999-2009
Web13 | Advertise on the Code Project