Created
August 19, 2019 18:19
-
-
Save veeenu/325d8ff254fa9651a1ce8b2c48567a1d to your computer and use it in GitHub Desktop.
DXGI vtable lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LPVOID swapchain_present_vtable_lookup() { | |
// Credits: https://www.unknowncheats.me/forum/d3d-tutorials-and-source/88369-universal-d3d11-hook.html | |
D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0; | |
ID3D11Device *pDevice = nullptr; | |
ID3D11DeviceContext *pContext = nullptr; | |
IDXGISwapChain* pSwapChain = nullptr; | |
DXGI_SWAP_CHAIN_DESC swapChainDesc; | |
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc)); | |
swapChainDesc.BufferCount = 1; | |
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | |
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; | |
swapChainDesc.OutputWindow = GetForegroundWindow(); | |
swapChainDesc.SampleDesc.Count = 1; | |
swapChainDesc.Windowed = TRUE; | |
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; | |
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; | |
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; | |
if (FAILED(D3D11CreateDeviceAndSwapChain( | |
NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, &featureLevel, 1, | |
D3D11_SDK_VERSION, &swapChainDesc, &pSwapChain, &pDevice, NULL, &pContext))) { | |
std::cout << "D3D11CreateDeviceAndSwapChain failed" << std::endl; | |
return nullptr; | |
} | |
DWORD_PTR* pSwapChainVtable; | |
pSwapChainVtable = (DWORD_PTR*)pSwapChain; | |
pSwapChainVtable = (DWORD_PTR*)pSwapChainVtable[0]; | |
LPVOID ret = reinterpret_cast<LPVOID>(pSwapChainVtable[8]); | |
pDevice->Release(); | |
pContext->Release(); | |
pSwapChain->Release(); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment