Исходник Direct3D9 Universal Hooking (x64)

Energy Reload
Забаненный
Статус
Оффлайн
Регистрация
20 Авг 2017
Сообщения
1,206
Реакции[?]
330
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Direct3D9 Universal Hooking - это немного измененный универсальный хук Direct3D9.
Для начало понадобится библиотека MinHook, не обычная, а та, которая во вложении.
А дальше все просто.)

Подключаем "MinHook.h"

Переменные:
C++:
namespace Module {
    std::string mod_Direct3DCreate9 = "Direct3DCreate9";
    std::string mod_d3d9 = "\\d3d9.dll";
}
Прототип функции:
C++:
typedef HRESULT(STDMETHODCALLTYPE*oReset)(IDirect3DDevice9 *, D3DPRESENT_PARAMETERS*);
oReset pReset;

typedef HRESULT(STDMETHODCALLTYPE*oEndScene)(IDirect3DDevice9 *);
oEndScene pEndScene;

typedef HRESULT(STDMETHODCALLTYPE*oPresent)(IDirect3DDevice9 *, CONST RECT*, CONST RECT*, HWND, CONST RGNDATA*);
oPresent pPresent = nullptr;

HRESULT STDMETHODCALLTYPE myEndScene(IDirect3DDevice9 * pDevice)
{

    auto hResult = pEndScene(pDevice);
    return hResult;
}

HRESULT STDMETHODCALLTYPE myPresent(IDirect3DDevice9 * pDevice, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion)
{

    auto hResult = pPresent(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
    return hResult;
}

HRESULT STDMETHODCALLTYPE myReset(IDirect3DDevice9 * pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
{
    //.....OnLostDevice();
    auto hRet =pReset(pDevice,pPresentationParameters);
    if (SUCCEEDED(hRet))
    {
    //.....OnResetDevice();
    }
    return hRet;
}
Хук Direct3D9:
C++:
bool Hook()
{
    bool bResult = FALSE;
    HRESULT hr = D3D_OK;

    IDirect3D9* d3d9 = nullptr;
    IDirect3DDevice9 *mDevice = nullptr;

    uint_t* g_methodsTable = NULL;

    char szPath[256];
    typedef IDirect3D9 *(WINAPI*D3D9CREATEPROC)(UINT);

    //Получаем папку Windows\system32
    SHGetFolderPath(NULL, CSIDL_SYSTEM, NULL, SHGFP_TYPE_CURRENT, szPath);
    //Получаем полный путь к d3d9.dll
    strcat(szPath, Module::mod_d3d9.c_str());
    //szPath = Windows\system32\d3d9.dll

    D3D9CREATEPROC Create = (D3D9CREATEPROC)GetProcAddress(GetModuleHandle(szPath), Module::mod_Direct3DCreate9.c_str());
    if (!Create)return NULL;

    if (d3d9= Create(D3D9b_SDK_VERSION))
    {
        D3DPRESENT_PARAMETERS dp;
        memset(&dp, 0, sizeof(dp));
        dp.Windowed = 1;
        dp.SwapEffect = D3DSWAPEFFECT_FLIP;
        dp.BackBufferFormat = D3DFMT_A8R8G8B8;
        dp.BackBufferCount = 1;
        dp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

        if (SUCCEEDED(hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &dp, &mDevice)))
        {
            bResult = true;
            g_methodsTable = (uint_t*)::calloc(119, sizeof(uint_t));
            ::memcpy(g_methodsTable, *(uint_t * *)mDevice, 119 * sizeof(uint_t));

            //Заводим индексы функций для установки хука
            void* pTarget_Present = (void*)g_methodsTable[IDirect3DDevice9_Index::Present];
            void* TargetReset = (void*)g_methodsTable[IDirect3DDevice9_Index::Reset];
            void* TargetEndScene = (void*)g_methodsTable[IDirect3DDevice9_Index::EndScene];

            //Сам хук
            pMinHook = std::make_unique<CMinHook>();
            pMinHook->CreateHook(TargetEndScene, myEndScene, (void**)&pEndScene);
            pMinHook->CreateHook(pTarget_Present, myPresent, (void**)&pPresent);
            pMinHook->CreateHook(TargetReset, myReset, (void**)&pReset);


            d3d9->Release();
            d3d9 = NULL;

            mDevice->Release();
            mDevice = NULL;

        }
    }
    return bResult;
}
Точка входа:
C++:
BOOL WINAPI DllMain(HMODULE hInst, DWORD dwReason, LPVOID lpReserved)
{
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Hook, 0, 0, 0);
    }
    return TRUE;
}
Индексы функций:
C++:
enum IDirect3DDevice9_Index
{
    QueryInterface,// 0
    AddRef,// 1
    Release,// 2
    TestCooperativeLevel,// 3
    GetAvailableTextureMem,// 4
    EvictManagedResources,// 5
    GetDirect3D,// 6
    _GetDeviceCaps,// 7
    GetDisplayMode,// 8
    GetCreationParameters,// 9
    SetCursorProperties,// 10
    SetCursorPosition,// 11
    _ShowCursor,// 12
    CreateAdditionalSwapChain,// 13
    GetSwapChain,// 14
    GetNumberOfSwapChains,// 15
    Reset,// 16
    Present,// 17
    GetBackBuffer,// 18
    GetRasterStatus,// 19
    SetDialogBoxMode,// 20
    SetGammaRamp,// 21
    GetGammaRamp,// 22
    CreateTexture,// 23
    CreateVolumeTexture,// 24
    CreateCubeTexture,// 25
    CreateVertexBuffer,// 26
    CreateIndexBuffer,// 27
    CreateRenderTarget,// 28
    CreateDepthStencilSurface,// 29
    UpdateSurface,// 30
    UpdateTexture,// 31
    GetRenderTargetData,// 32
    GetFrontBufferData,// 33
    StretchRect,// 34
    ColorFill,// 35
    CreateOffscreenPlainSurface,// 36
    SetRenderTarget,// 37
    GetRenderTarget,// 38
    SetDepthStencilSurface,// 39
    GetDepthStencilSurface,// 40
    BeginScene,// 41
    EndScene,// 42
    Clear,// 43
    SetTransform,// 44
    GetTransform,// 45
    MultiplyTransform,// 46
    SetViewport,// 47
    GetViewport,// 48
    SetMaterial,// 49
    GetMaterial,// 50
    SetLight,// 51
    GetLight,// 52
    LightEnable,// 53
    GetLightEnable,// 54
    SetClipPlane,// 55
    GetClipPlane,// 56
    SetRenderState,// 57
    GetRenderState,// 58
    CreateStateBlock,// 59
    BeginStateBlock,// 60
    EndStateBlock,// 61
    SetClipStatus,// 62
    GetClipStatus,// 63
    GetTexture,// 64
    SetTexture,// 65
    GetTextureStageState,// 66
    SetTextureStageState,// 67
    GetSamplerState,// 68
    SetSamplerState,// 69
    ValidateDevice,// 70
    _SetPaletteEntries,// 71
    _GetPaletteEntries,// 72
    SetCurrentTexturePalette,// 73
    GetCurrentTexturePalette,// 74
    SetScissorRect,// 75
    GetScissorRect,// 76
    SetSoftwareVertexProcessing,// 77
    GetSoftwareVertexProcessing,// 78
    SetNPatchMode,// 79
    GetNPatchMode,// 80
    DrawPrimitive,// 81
    DrawIndexedPrimitive,// 82
    DrawPrimitiveUP,// 83
    DrawIndexedPrimitiveUP,// 84
    ProcessVertices,// 85
    CreateVertexDeclaration,// 86
    SetVertexDeclaration,// 87
    GetVertexDeclaration,// 88
    SetFVF,// 89
    GetFVF,// 90
    CreateVertexShader,// 91
    SetVertexShader,// 92
    GetVertexShader,// 93
    SetVertexShaderConstantF,// 94
    GetVertexShaderConstantF,// 95
    SetVertexShaderConstantI,// 96
    GetVertexShaderConstantI,// 97
    SetVertexShaderConstantB,// 98
    GetVertexShaderConstantB,// 99
    SetStreamSource,// 100
    GetStreamSource,// 101
    SetStreamSourceFreq,// 102
    GetStreamSourceFreq,// 103
    SetIndices,// 104
    GetIndices,// 105
    CreatePixelShader,// 106
    SetPixelShader,// 107
    GetPixelShader,// 108
    SetPixelShaderConstantF,// 109
    GetPixelShaderConstantF,// 110
    SetPixelShaderConstantI,// 111
    GetPixelShaderConstantI,// 112
    SetPixelShaderConstantB,// 113
    GetPixelShaderConstantB,// 114
    DrawRectPatch,// 115
    DrawTriPatch,// 116
    DeletePatch,// 117
    CreateQuery  // 118
};
 

Вложения

Сверху Снизу