PolyHook x64Detour没有挂钩到Direct3DCreate9

时间:2018-05-26 21:25:19

标签: c++ assembly

我在使用polyhook挂钩进程时出现问题。出于某种原因,pDevice永远不会被设置。

#include "PolyHook.hpp"
#define CATCH_CONFIG_MAIN
#include "CatchUnitTest.h"
#include <d3d9.h>

/* this type is already defined in d3d9.h so i commented it out
typedef IDirect3D9* Direct3DCreate9(
    UINT SDKVersion
);*/
typedef IDirect3D9*(__stdcall* tDirect3DCreate9)(UINT SDKVersion);
tDirect3DCreate9* otDirect3DCreate9;

tDirect3DCreate9 oDirect3DCreate9;

LPDIRECT3D9 pDevice;

LPDIRECT3D9 __stdcall hkDirect3DCreate9(UINT SDKVersion)
{
    pDevice = oDirect3DCreate9(SDKVersion);
    return pDevice;
}

DWORD WINAPI inject()
{
    AllocConsole();
    freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
    std::cout << "SETUP" << std::endl;

    HMODULE d3d = GetModuleHandle("d3d9.dll");

    PLH::Detour* PLHDirect3DCreate9 = new PLH::Detour;
    std::cout << "new DETOUR" << std::endl;
    PLHDirect3DCreate9->SetupHook((BYTE*)GetProcAddress(d3d, "Direct3DCreate9"), (BYTE*)&hkDirect3DCreate9);
    std::cout << "setup HOOK" << std::endl;
    PLHDirect3DCreate9->Hook();
    oDirect3DCreate9 = PLHDirect3DCreate9->GetOriginal<tDirect3DCreate9>();
    while (!pDevice) {
        std::cout << "no pdevice" << std::endl;
    }

    std::cout << "END" << std::endl;
    std::cout << "pDevice: " << pDevice << std::endl;
    for (;;) {

    }
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD Reason, LPVOID lpReserved)
{
    if (Reason == DLL_PROCESS_ATTACH)
    {
        DisableThreadLibraryCalls(hModule);
        HANDLE hThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)inject, NULL, NULL, NULL);
        CloseHandle(hThread);
    }
    return TRUE;
}

和我的输出: enter image description here

我做的事情非常糟糕,但我不太确定是什么。任何指导都会有所帮助。我的最终游戏是获得由Direct3DCreate9设置的LPDIRECT3D9

我正在使用github上的这个库 https://github.com/stevemk14ebr/PolyHook

我在网上发现了一些关于此问题的其他帖子,但没有人提到他们的解决方案。

0 个答案:

没有答案