5,276,801 members and growing! (15,711 online)
Email Password   helpLost your password?
General Programming » DLLs & Assemblies » Hooks     Advanced License: The Code Project Open License (CPOL)

APIHijack - A Library for easy DLL function hooking.

By Wade Brainerd

This library allows you to replace functions in other DLLs with functions from your own DLL.
VC6, C++Windows, NT4, Win2KVS6, VS, Dev

Posted: 15 Sep 2000
Updated: 15 Sep 2000
Views: 331,753
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
44 votes for this Article.
Popularity: 7.74 Rating: 4.71 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
1 vote, 4.2%
3
5 votes, 20.8%
4
18 votes, 75.0%
5
  • Download source files and demo project - 102 Kb

    Introduction

    Based on DelayLoadProfileDLL.CPP, by Matt Pietrek for MSJ February 2000. This code is intended to be included in a DLL inserted through a global Windows Hook (CBT hook for example). It will replace functions from other DLLs (e.g. DDRAW.DLL) with functions from your DLL.

    Functions are hooked by passing a parameter structure to the HookAPICalls() function as follows:

    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)
    {
        if ( fdwReason == DLL_PROCESS_ATTACH )  // When initializing....
        {
            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 right 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.

  • License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    About the Author

    Wade Brainerd



    Location: United States United States

    Other popular DLLs & Assemblies articles:

    Article Top
    Sign Up to vote for this article
    You must Sign In to use this message board.
    FAQ FAQ Noise ToleranceSearch Search Messages 
     Layout  Per page   
     Msgs 1 to 25 of 151 (Total in Forum: 151) (Refresh)FirstPrevNext
    Subject  Author Date 
    GeneralProblem when trying to hook text functionsmemberRoey C10:25 31 Mar '08  
    GeneralIt does not work for me.memberAchilleas Margaritis0:09 28 Nov '07  
    Generalnot imported by name?!memberParallan0:27 4 Nov '07  
    GeneralHow to hook user defined DLL ?membermahesh kumar s2:46 3 Jul '07  
    Generalmonitoring dll function callsmembermahesh kumar s5:04 28 Jun '07  
    Generalthis trick doesn't work with all programs, nor?member6r15u3:10 30 Jan '07  
    GeneralAPIHijack is outmoded?memberplayer.23:51 24 Jul '06  
    GeneralCompile with Visual Studio 2003memberP Gibson2:30 7 Jul '06  
    GeneralHooking LoadLibraryAmemberRed XIII1:58 28 Jun '06  
    GeneralVB.Net and APIHijackmemberVitoto6:36 12 Jan '06  
    GeneralThe demomembertriplebit2:07 21 Nov '05  
    GeneralThe demomembertriplebit2:06 21 Nov '05  
    GeneralPurely excelent...memberNick Z.15:21 3 Nov '05  
    AnswerRe: Purely excelent...memberNguyen Duc Minh21:01 19 Nov '05  
    Questionhow to hook copy,cat,past operationsmemberAl_Shakhly23:15 1 Nov '05  
    GeneralRetreiving variablememberKrisse5:04 14 Aug '05  
    GeneralHooking dynamicly loaded DLLs functionsmemberseybold23:33 23 May '05  
    GeneralRe: Hooking dynamicly loaded DLLs functionsmemberdchris_med4:16 14 Feb '06  
    GeneralLooking like a atlternative of DsSubCls.dllmemberThatsAlok20:10 3 Dec '04  
    GeneralHooked function address is replaced by Original onememberkeenalex21:07 23 Sep '04  
    GeneralRe: Hooked function address is replaced by Original onememberGareth Haslip3:32 11 Oct '04  
    GeneralRe: Hooked function address is replaced by Original onemembersturlamolden13:58 12 Oct '06  
    GeneralCallbacks from insidememberK-ballo15:34 20 Aug '04  
    Generalcan't do it for . . .membereuacela11:36 8 Aug '04  
    GeneralRe: can't do it for . . .memberflaming_red_dingo4:38 2 Apr '05  

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

    PermaLink | Privacy | Terms of Use
    Last Updated: 15 Sep 2000
    Editor: Chris Maunder
    Copyright 2000 by Wade Brainerd
    Everything else Copyright © CodeProject, 1999-2008
    Web19 | Advertise on the Code Project