diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2019-11-20 18:07:12 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2019-11-20 18:07:12 +0100 |
commit | 0625c5c5a8a8aca6a5122244fce2751e2a29b890 (patch) | |
tree | c645fed2a234eb128c4a84c8f18342e77210aaeb /MemDriverLib | |
parent | a5e16f20141b3b5ce0bc19a6ae233e3fecb15a82 (diff) |
added DX11Manager for fetching DX11 data for client dlls
Diffstat (limited to 'MemDriverLib')
-rw-r--r-- | MemDriverLib/DX11Manager.cpp | 114 | ||||
-rw-r--r-- | MemDriverLib/MemDriverLib.vcxproj | 2 | ||||
-rw-r--r-- | MemDriverLib/MemDriverLib.vcxproj.filters | 6 |
3 files changed, 122 insertions, 0 deletions
diff --git a/MemDriverLib/DX11Manager.cpp b/MemDriverLib/DX11Manager.cpp new file mode 100644 index 0000000..ab376aa --- /dev/null +++ b/MemDriverLib/DX11Manager.cpp @@ -0,0 +1,114 @@ +#include "stdafx.h" +#include "DX11Manager.h" + +#include <Windows.h> + +#pragma comment (lib, "D3D11.lib") + +struct DDataIntern { + IDXGISwapChain * SwapChain; + ID3D11Device * Device; + ID3D11DeviceContext * DeviceContext; +}; + +static LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case(WM_DESTROY): + PostQuitMessage(0); + return 0; + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + break; + } +} + +static HRESULT InitD3D(struct DDataIntern * const data, HWND hWnd) +{ + DXGI_SWAP_CHAIN_DESC SwapChainDesc; + + ZeroMemory(&SwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)); + SwapChainDesc.BufferCount = 1; + SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + SwapChainDesc.OutputWindow = hWnd; + SwapChainDesc.SampleDesc.Count = 4; + SwapChainDesc.Windowed = true; + + return D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &SwapChainDesc, + &data->SwapChain, &data->Device, NULL, &data->DeviceContext); +} + +static void CleanD3D(struct DDataIntern * const data) +{ + data->SwapChain->Release(); + data->Device->Release(); + data->DeviceContext->Release(); +} + +bool WINAPI GetDirectxData(struct DxData * const data) +{ + HINSTANCE hInstance = (HINSTANCE)((LONG_PTR)GetWindowLongW(GetActiveWindow(), -6)); + HWND hWnd; + WNDCLASSEX wc; + struct DDataIntern data_intern; + + ZeroMemory(&data_intern, sizeof(data_intern)); + ZeroMemory(&wc, sizeof(WNDCLASSEX)); + wc.cbSize = sizeof(WNDCLASSEX); + wc.hbrBackground = (HBRUSH)COLOR_WINDOW; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hInstance = hInstance; + wc.lpfnWndProc = WinProc; + wc.lpszClassName = L"DxData"; + wc.style = CS_VREDRAW | CS_HREDRAW; + RegisterClassEx(&wc); + + RECT rect = { 0, 0, 600, 400 }; + AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false); + hWnd = CreateWindowEx(NULL, L"DxData", L"DxData", WS_OVERLAPPEDWINDOW, 300, 300, rect.right - rect.left, + rect.bottom - rect.top, NULL, NULL, hInstance, NULL); + if (!hWnd) { + return false; + } + + ShowWindow(hWnd, NULL); + data->CreateSwapChainReturn = InitD3D(&data_intern, hWnd); + + { + MSG msg; + while (GetMessage(&msg, NULL, 0, 0) && + PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + memcpy(data->buf, (*(UINT64 ***)data_intern.SwapChain)[8], sizeof data->buf); + + HMODULE d3d11_base = LoadLibrary(L"d3d11.dll"); + data->DeviceVTableOffset = *(UINT64 *)data_intern.Device; + data->DeviceContextVTableOffset = *(UINT64 *)data_intern.DeviceContext; + data->SwapChainVTableOffset = (*(UINT64 **)data_intern.SwapChain)[8] - (UINT64)d3d11_base; + + CleanD3D(&data_intern); + CloseWindow(hWnd); + DestroyWindow(hWnd); + + { + MSG msg; + while (GetMessage(&msg, NULL, 0, 0) && + PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + FreeLibrary(d3d11_base); + + return true; +}
\ No newline at end of file diff --git a/MemDriverLib/MemDriverLib.vcxproj b/MemDriverLib/MemDriverLib.vcxproj index 95042aa..39a3fdb 100644 --- a/MemDriverLib/MemDriverLib.vcxproj +++ b/MemDriverLib/MemDriverLib.vcxproj @@ -154,6 +154,7 @@ </ItemDefinitionGroup> <ItemGroup> <ClInclude Include="..\include\DLLHelper.h" /> + <ClInclude Include="..\include\DX11Manager.h" /> <ClInclude Include="..\include\KMemDriver.h" /> <ClInclude Include="..\include\KInterface.h" /> <ClInclude Include="..\include\PatternScanner.h" /> @@ -163,6 +164,7 @@ <ItemGroup> <ClCompile Include="DLLHelper.cpp" /> <ClCompile Include="dllmain.cpp" /> + <ClCompile Include="DX11Manager.cpp" /> <ClCompile Include="MemDriverLib.cpp" /> <ClCompile Include="PatternScanner.cpp" /> <ClCompile Include="stdafx.cpp"> diff --git a/MemDriverLib/MemDriverLib.vcxproj.filters b/MemDriverLib/MemDriverLib.vcxproj.filters index 94e0b8d..9718fb3 100644 --- a/MemDriverLib/MemDriverLib.vcxproj.filters +++ b/MemDriverLib/MemDriverLib.vcxproj.filters @@ -33,6 +33,9 @@ <ClInclude Include="..\include\PatternScanner.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\include\DX11Manager.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="stdafx.cpp"> @@ -50,5 +53,8 @@ <ClCompile Include="PatternScanner.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="DX11Manager.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project>
\ No newline at end of file |