Click here to Skip to main content
15,899,634 members
Articles / Programming Languages / C++
Article

HookAPI source code

Rate me:
Please Sign up or sign in to vote.
3.09/5 (36 votes)
31 Jan 20052 min read 393.5K   9.6K   117   132
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


Written By
Web Developer
China China
An old C programmer in China.

Comments and Discussions

 
GeneralA bug on win9x Pin
pudn.com3-Feb-05 19:46
pudn.com3-Feb-05 19:46 
GeneralFound a Bug Pin
Asxetos3-Feb-05 3:50
Asxetos3-Feb-05 3:50 
GeneralRe: Found a Bug Pin
pudn.com3-Feb-05 19:36
pudn.com3-Feb-05 19:36 
GeneralRe: Found a Bug Pin
Asxetos3-Feb-05 22:14
Asxetos3-Feb-05 22:14 
QuestionWhy such a bad score? Pin
Luca Piccarreta31-Jan-05 21:16
Luca Piccarreta31-Jan-05 21:16 
AnswerRe: Why such a bad score? Pin
yafan1-Feb-05 19:04
yafan1-Feb-05 19:04 
GeneralRe: Why such a bad score? Pin
Luca Piccarreta1-Feb-05 21:59
Luca Piccarreta1-Feb-05 21:59 
AnswerRe: Why such a bad score? Pin
yafan1-Feb-05 19:05
yafan1-Feb-05 19:05 
That's easy. If you actually get everything to build it will cause Windows XP SP2 to blue screen, which is no small feat given that XP is fairly robust these days. I am using Visual Studio .NET 2003.

Here's what I did, in case you are interested. I might suggest that that you do not repeat my efforts since as I said earlier, it crashed my system - hard. This software should come with a large !!!WARNING!!!

I open the project:DLL\HookAPI and basically had to add in the .CPP files and .DEF file that was missing from the build, else the build basically failed. Once this was done, I did a "dumpbin.exe /exports" to make sure that I was exporting the necessary functions, namely:

HookOneProcess
UnhookOneProcess
HookOneProcess2
UnhookOneProcess2
HookAllProcess
UnhookAllProcess

I then built the EXE\HookAPI application and then the mydll.dll that performed socket interception (or tried to should I say). I launched the HookAPI function under the debugger and BAM! System crash.


Hence to say, the whole thing was summarily deleted from my system. Also, I checked the registry in case it had left some APPINIT settings. In fact, I eradicated every trace of this software.
I hate to write such a scathing review of something else's efforts. I really do. But in this case I felt justified in warning others that this stuff can crash your system, and secondly, I hate code that blue screens my system.

Since the documentation was written in chinese there is the chance that I may of misinterpreted the build sequence. But that still does not matter - it shouldn't blue screen.

Oh yes, there is one other thing: The Author says that someone else stole his software, but in fact, he basically leveraged the work of another individual, which he freely admits in the article, so how he can make that claim is beyond me. I took the effort to track down the other person's work and it was not too disimilar to the work presented in this article.


Good luck.


-yafan.













GeneralRe: Why such a bad score? Pin
pudn.com1-Feb-05 23:14
pudn.com1-Feb-05 23:14 
GeneralRe: Why such a bad score? Pin
wangk070528-Nov-06 21:15
wangk070528-Nov-06 21:15 
QuestionHow To prevent Windows Copy? Pin
Jetli Jerry31-Jan-05 19:38
Jetli Jerry31-Jan-05 19:38 
AnswerRe: How To prevent Windows Copy? Pin
John M. Drescher1-Feb-05 9:12
John M. Drescher1-Feb-05 9:12 
GeneralRe: How To prevent Windows Copy? Pin
pudn.com1-Feb-05 12:52
pudn.com1-Feb-05 12:52 
QuestionCan it be used with vb? Pin
Asxetos27-Jan-05 20:35
Asxetos27-Jan-05 20:35 
AnswerRe: Can it be used with vb? Pin
pudn.com28-Jan-05 15:17
pudn.com28-Jan-05 15:17 
GeneralRe: Can it be used with vb? Pin
Asxetos29-Jan-05 18:10
Asxetos29-Jan-05 18:10 
GeneralRe: Can it be used with vb? Pin
pudn.com31-Jan-05 13:07
pudn.com31-Jan-05 13:07 
GeneralSomething's not right. Pin
WREY21-Jan-05 16:21
WREY21-Jan-05 16:21 
Generalyou can download from http://www.programsalon.com/dl.asp?id=2420 Pin
pudn.com21-Jan-05 21:42
pudn.com21-Jan-05 21:42 
GeneralRe: you can download from http://www.programsalon.com/dl.asp?id=2420 Pin
StringCheese22-Jan-05 12:55
StringCheese22-Jan-05 12:55 
Generalhttp://www.programmersheaven.com/d/click.aspx?ID=F37002 Pin
pudn.com22-Jan-05 14:41
pudn.com22-Jan-05 14:41 
GeneralRe: http://www.programmersheaven.com/d/click.aspx?ID=F37002 Pin
StringCheese22-Jan-05 14:45
StringCheese22-Jan-05 14:45 
GeneralRe: http://www.programmersheaven.com/d/click.aspx?ID=F37002 Pin
Anonymous22-Aug-05 7:59
Anonymous22-Aug-05 7:59 
Generalor download from www.codeproject.com Pin
pudn.com22-Jan-05 14:50
pudn.com22-Jan-05 14:50 
GeneralRe: or download from www.codeproject.com Pin
StringCheese22-Jan-05 15:41
StringCheese22-Jan-05 15:41 

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.