我正在使用带有 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/