c++ - 绕行功能未被调用

标签 c++ detours

我正在使用带有 CDetour 的 visual studio 2003。
这次我不能提供 SSCE,所以这就是我所做的:

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;

CDetour CreateDevice_Det;
IDirect3D9* Direct3DCreate9_Hook( UINT SDKVersion )
{
        MessageBox( GetForegroundWindow(), "Direct9 Create Hooked", "dForce.dll", MB_OK );
        d3d = Direct3DCreate9(D3D_SDK_VERSION);
        return d3d;
}

BOOL WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID reserved)
{
    switch(reason)
    {
        case DLL_PROCESS_ATTACH:
        {
            HMODULE hd3d = GetModuleHandle( "d3d9.dll" );
            if( hd3d == 0 )
            {
                MessageBox( GetForegroundWindow(), "d3d9.dll still not loaded", "dForce.dll", MB_ICONSTOP );
                return FALSE;
            }
            DWORD lpAddr = (DWORD)GetProcAddress( hd3d, "Direct3DCreate9" );
            if( lpAddr == 0 )
            {
                MessageBox( GetForegroundWindow(), "could not find valid d3d9.dll create device address", "dForce.dll", MB_ICONSTOP );
                return FALSE;
            }
            CreateDevice_Det.Detour( (LPBYTE)lpAddr, (LPBYTE)Direct3DCreate9_Hook );
            CString strDetoured;
            strDetoured.Format( "CreateDevice Hooked! Address: %x", (LPVOID)lpAddr );
            MessageBox( GetForegroundWindow(), strDetoured, "dFoce.dll", MB_ICONINFORMATION );
        }break;
    }
    return TRUE;
}

我已经以同样的方式成功 Hook 了另一个函数,例如 LoadLibrary(来自 kernel32.dll),这个 dll 当然是在主程序上的 Direct3DCreate9 之前加载的,我也在控制台 wi32 程序上尝试过这个,但我的钩子(Hook)函数仍然没有被调用。我错过了什么吗?

已编辑

显然 CDetour 与 MS Detours 完全无关(发现它通过谷歌搜索 ms detours)。

最佳答案

我在这里没有看到 detourTransactionBegin()、DetourUpdateThread() 和 DetourTransactioncommit() 调用。 API Hooking with MS Detours有一个很好的解释。

关于c++ - 绕行功能未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17074327/

相关文章:

c++ - 为什么很多 OpenCL 示例是用 C++ 而不是用 C 编写的?

c++ - 将鼠标点击发送到 WebEngineView Qt C++

c++ - Qt软件调试技巧

c++ - 使用 Detours 3.0 Express 的简单数据包记录器

c++ - 弯路 Hook : GetVolumeInformation Random Volume Serial

c - 从 CreateProcess 获取 PROCESS_INFORMATION

c++ - 弯路捕捉质感

c++ - ReSharper C++ 代码分析不起作用

c++ - 为什么/etc/目录下没有创建文件