Click here to Skip to main content
Licence CPOL
First Posted 15 Sep 2000
Views 514,222
Downloads 7,278
Bookmarked 156 times

APIHijack - A Library for easy DLL function hooking.

By | 15 Sep 2000 | Article
This library allows you to replace functions in other DLLs with functions from your own DLL.
  • 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



    United States United States

    Member



    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    QuestionNon-Debug applications can be hooked too ? PinmemberRyouku18:17 12 Jul '09  
    GeneralProblem when trying to hook text functions PinmemberRoey C9:25 31 Mar '08  
    GeneralIt does not work for me. PinmemberAchilleas Margaritis23:09 27 Nov '07  
    GeneralRe: It does not work for me. PinmemberMXT37:42 20 Jan '12  
    Generalnot imported by name?! PinmemberParallan23:27 3 Nov '07  
    QuestionHow to hook user defined DLL ? Pinmembermahesh kumar s1:46 3 Jul '07  
    Generalmonitoring dll function calls Pinmembermahesh kumar s4:04 28 Jun '07  
    Questionthis trick doesn't work with all programs, nor? Pinmember6r15u2:10 30 Jan '07  
    QuestionAPIHijack is outmoded? Pinmemberplayer.22:51 24 Jul '06  
    GeneralCompile with Visual Studio 2003 PinmemberP Gibson1:30 7 Jul '06  
    GeneralHooking LoadLibraryA PinmemberRed XIII0:58 28 Jun '06  
    GeneralVB.Net and APIHijack PinmemberVitoto5:36 12 Jan '06  
    GeneralThe demo Pinmembertriplebit1:07 21 Nov '05  
    GeneralThe demo Pinmembertriplebit1:06 21 Nov '05  
    GeneralPurely excelent... PinmemberNick Z.14:21 3 Nov '05  
    AnswerRe: Purely excelent... PinmemberNguyen Duc Minh20:01 19 Nov '05  
    Questionhow to hook copy,cat,past operations PinmemberAl_Shakhly22:15 1 Nov '05  
    GeneralRetreiving variable PinmemberKrisse4:04 14 Aug '05  
    is it possiblee to retreive a value of a variable in a process that you hijacked?
     
    1: i hijack a process
    2: find a variable by name or type
    3: return the variable onfo to the hijack dll
    4: free hijack
     
    can that be done??
     
    cheers Big Grin | :-D
    GeneralHooking dynamicly loaded DLLs functions Pinmemberseybold22:33 23 May '05  
    GeneralRe: Hooking dynamicly loaded DLLs functions Pinmemberdchris_med3:16 14 Feb '06  
    GeneralLooking like a atlternative of DsSubCls.dll PinmemberThatsAlok19:10 3 Dec '04  
    GeneralHooked function address is replaced by Original one Pinmemberkeenalex20:07 23 Sep '04  
    GeneralRe: Hooked function address is replaced by Original one PinmemberGareth Haslip2:32 11 Oct '04  
    GeneralRe: Hooked function address is replaced by Original one Pinmembersturlamolden12:58 12 Oct '06  
    GeneralCallbacks from inside PinmemberK-ballo14:34 20 Aug '04  

    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.

    Permalink | Advertise | Privacy | Mobile
    Web02 | 2.5.120529.1 | Last Updated 16 Sep 2000
    Article Copyright 2000 by Wade Brainerd
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid