diff options
-rw-r--r-- | KMemDriver.sln | 3 | ||||
-rw-r--r-- | MemDriverLib/DX11Manager.cpp | 114 | ||||
-rw-r--r-- | MemDriverLib/MemDriverLib.vcxproj | 2 | ||||
-rw-r--r-- | MemDriverLib/MemDriverLib.vcxproj.filters | 6 | ||||
-rw-r--r-- | include/DX11Manager.h | 14 |
5 files changed, 139 insertions, 0 deletions
diff --git a/KMemDriver.sln b/KMemDriver.sln index a26c4de..87070d3 100644 --- a/KMemDriver.sln +++ b/KMemDriver.sln @@ -21,6 +21,9 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestDLL", "TestDLL\TestDLL.vcxproj", "{E27E6F2C-154E-46AF-BED4-78D50C751565}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IntegrationTest", "IntegrationTest\IntegrationTest.vcxproj", "{AD4E6887-32BA-4CC9-924C-18F0ECAFB576}" + ProjectSection(ProjectDependencies) = postProject + {B6790A97-6995-46B6-AD73-AC5BC4AC76DB} = {B6790A97-6995-46B6-AD73-AC5BC4AC76DB} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution 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 diff --git a/include/DX11Manager.h b/include/DX11Manager.h new file mode 100644 index 0000000..1c18022 --- /dev/null +++ b/include/DX11Manager.h @@ -0,0 +1,14 @@ +#pragma once + +#include <D3D11.h> + +struct DxData { + HRESULT CreateSwapChainReturn; + /* ALL Offsets are relative to the base address of d3d11.dll */ + UINT64 DeviceVTableOffset; + UINT64 DeviceContextVTableOffset; + UINT64 SwapChainVTableOffset; + BYTE buf[64]; +}; + +bool WINAPI GetDirectxData(struct DxData * const data);
\ No newline at end of file |