Click here to Skip to main content
13,044,539 members (59,089 online)
Click here to Skip to main content
Add your own
alternative version

Stats

650.8K views
10K downloads
171 bookmarked
Posted 15 Sep 2000

APIHijack - A Library for easy DLL function hooking.

, 15 Sep 2000
Rate this:
Please Sign up or sign in to vote.
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)

    Share

    About the Author

    Wade Brainerd
    United States United States
    No Biography provided

    You may also be interested in...

    Pro

    Comments and Discussions

     
    QuestionHooking intra-dll calls Pin
    Member 117407493-Jun-15 21:38
    memberMember 117407493-Jun-15 21:38 
    QuestionNon-Debug applications can be hooked too ? Pin
    Ryouku12-Jul-09 18:17
    memberRyouku12-Jul-09 18:17 
    GeneralProblem when trying to hook text functions Pin
    Roey C31-Mar-08 9:25
    memberRoey C31-Mar-08 9:25 
    GeneralIt does not work for me. Pin
    Achilleas Margaritis27-Nov-07 23:09
    memberAchilleas Margaritis27-Nov-07 23:09 
    GeneralRe: It does not work for me. Pin
    MXT320-Jan-12 7:42
    memberMXT320-Jan-12 7:42 
    Generalnot imported by name?! Pin
    Parallan3-Nov-07 23:27
    memberParallan3-Nov-07 23:27 
    QuestionHow to hook user defined DLL ? Pin
    mahesh kumar s3-Jul-07 1:46
    membermahesh kumar s3-Jul-07 1:46 
    Generalmonitoring dll function calls Pin
    mahesh kumar s28-Jun-07 4:04
    membermahesh kumar s28-Jun-07 4:04 
    Questionthis trick doesn't work with all programs, nor? Pin
    6r15u30-Jan-07 2:10
    member6r15u30-Jan-07 2:10 
    QuestionAPIHijack is outmoded? Pin
    player.24-Jul-06 22:51
    memberplayer.24-Jul-06 22:51 
    GeneralCompile with Visual Studio 2003 Pin
    P Gibson7-Jul-06 1:30
    memberP Gibson7-Jul-06 1:30 
    GeneralHooking LoadLibraryA Pin
    Red XIII28-Jun-06 0:58
    memberRed XIII28-Jun-06 0:58 
    GeneralVB.Net and APIHijack Pin
    Vitoto12-Jan-06 5:36
    memberVitoto12-Jan-06 5:36 
    GeneralThe demo Pin
    triplebit21-Nov-05 1:07
    membertriplebit21-Nov-05 1:07 
    GeneralThe demo Pin
    triplebit21-Nov-05 1:06
    membertriplebit21-Nov-05 1:06 
    GeneralPurely excelent... Pin
    Nick Z.3-Nov-05 14:21
    memberNick Z.3-Nov-05 14:21 
    AnswerRe: Purely excelent... Pin
    Nguyen Duc Minh19-Nov-05 20:01
    memberNguyen Duc Minh19-Nov-05 20:01 
    Questionhow to hook copy,cat,past operations Pin
    Al_Shakhly1-Nov-05 22:15
    memberAl_Shakhly1-Nov-05 22:15 
    GeneralRetreiving variable Pin
    Krisse14-Aug-05 4:04
    memberKrisse14-Aug-05 4:04 
    GeneralHooking dynamicly loaded DLLs functions Pin
    seybold23-May-05 22:33
    memberseybold23-May-05 22:33 
    GeneralRe: Hooking dynamicly loaded DLLs functions Pin
    dchris_med14-Feb-06 3:16
    memberdchris_med14-Feb-06 3:16 
    GeneralLooking like a atlternative of DsSubCls.dll Pin
    ThatsAlok3-Dec-04 19:10
    memberThatsAlok3-Dec-04 19:10 
    GeneralHooked function address is replaced by Original one Pin
    keenalex23-Sep-04 20:07
    memberkeenalex23-Sep-04 20:07 
    GeneralRe: Hooked function address is replaced by Original one Pin
    Gareth Haslip11-Oct-04 2:32
    memberGareth Haslip11-Oct-04 2:32 
    GeneralRe: Hooked function address is replaced by Original one Pin
    sturlamolden12-Oct-06 12:58
    membersturlamolden12-Oct-06 12:58 

    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.

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