65.9K
CodeProject 正在变化。 阅读更多。
Home

APIHijack - 一个用于轻松进行 DLL 函数钩子的库。

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.79/5 (29投票s)

2000年9月16日

CPOL
viewsIcon

827229

downloadIcon

10554

这个库允许你用你自己的 DLL 中的函数替换其他 DLL 中的函数。

  • 下载源代码文件和演示项目 - 102 Kb

    引言

    基于 Matt Pietrek 为 2000 年 2 月份的 MSJ 撰写的 DelayLoadProfileDLL.CPP。这段代码旨在包含在一个通过全局 Windows 钩子(例如 CBT 钩子)插入的 DLL 中。它将替换其他 DLL(例如 DDRAW.DLL)中的函数,替换为你的 DLL 中的函数。

    函数通过将一个参数结构传递给 HookAPICalls() 函数来钩住,如下所示

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

    现在剩下的就是让你的 DLL 加载到目标进程中。

  • APIHijack - 一个用于轻松进行 DLL 函数钩子的库。 - CodeProject - 代码之家
    © . All rights reserved.