티스토리 뷰
Sourcecode
injme.cpp
#include "injme.h"
#include <Qt/qstring.h>
#include <Qt/qtextdocumentwriter.h>
#include <Qt/qtextdocument.h>
#include <easyhook/easyhook.h>
#include <iostream>
using namespace std;
int s_FrameNumber = 0;
HRESULT D3DX10CreateDevice_Hook (
IDXGIAdapter *pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
ID3D10Device **ppDevice
){
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 2;
swapChainDesc.BufferDesc.Width = 800;
swapChainDesc.BufferDesc.Height = 600;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
// refresh rate, sampling, output handle
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.OutputWindow = NULL;
swapChainDesc.Windowed = true;
IDXGISwapChain *swapCh;
HRESULT hResult = D3DX10CreateDeviceAndSwapChain( pAdapter, DriverType, Software, Flags, &swapChainDesc, &swapCh, ppDevice );
QString fileName;
fileName = fileName.sprintf("%1.bmp").arg(s_FrameNumber);
wchar_t* fName;
fileName.toWCharArray(fName);
CComPtr< ID3D10Texture2D > pBackBuffer;
if (FAILED(swapCh->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer))) return false;
if(FAILED(D3DX10SaveTextureToFile(pBackBuffer, D3DX10_IFF_BMP, fName ))) {
return false;
}
return hResult;
}
InjMe::InjMe()
{
HMODULE hD3d = LoadLibraryA("d3d10.dll");
TRACED_HOOK_HANDLE hHook = new HOOK_TRACE_INFO();
ULONG ACLEntries[1] = {0};
FARPROC proc = GetProcAddress(hD3d, "D3DX10CreateDevice");
LhInstallHook(proc, D3DX10CreateDevice_Hook, (PVOID)0x12345678, hHook);
LhSetInclusiveACL(ACLEntries, 1, hHook);
// Use the debugger of your choice:
LhUninstallAllHooks();
LhUninstallHook(hHook);
delete hHook;
}
injme.h
#ifndef INJME_H
#define INJME_H
#include <d3d/Include/D3D10.h>
#include <d3d/Include/D3DX10tex.h>
#include <Windows.h>
#include <atlstr.h>
#include <atlfile.h>
class InjMe {
public:
InjMe();
};
#endif // INJME_H
pro
QT -= gui core
TARGET = InjMe
TEMPLATE = lib
CONFIG += staticdll
SOURCES += injme.cpp
HEADERS += injme.h \
easyhook/easyhook.h
LIBS += easyhook\EasyHook32.lib \
d3d\Lib\x86\d3dx10.lib \
msvc2008\lib\QtCore4.lib \
msvc2008\lib\QtGui4.lib
'프로그래밍Tip' 카테고리의 다른 글
Knuth(tfind, tsearch, ...) example (0) | 2013.07.08 |
---|---|
BSTR vs. C String (0) | 2013.07.03 |
detours에 관한 좋은 설명 및 예제 (0) | 2013.06.25 |
오랫 만에 GCJ를 리뷰하며 (0) | 2013.03.11 |
GC(Garbage collector) for C/C++ (0) | 2013.03.11 |