关于Directx骇客而非技术支持的主题。
史前历史:我用蒸汽购买了名为Bayoneta的游戏,并在WinXPx64sp2上运行。它崩溃,并显示诸如“找不到Direct3DCreate9Ex()”之类的错误。依赖行者说只有Direct3DCreate9Ex()被遗漏了。我以为“一些黑客的好榜样!”。
在readind一堆文档和手册之后,编写了自己的d3d9.dll包装器。 Direct9游戏无法运行Bayonetta。弹出通知以将多个数据发送到Microsoft。
欢迎任何想法和提示。
代码:
dllmain:
#include "stdafx.h"
#include <iostream>
#include "d3d9ex.h"
extern d3d9_dll d3d9;
TCHAR dlldir[MAX_PATH];
TCHAR syspath[MAX_PATH];
HINSTANCE hlThis = 0;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD reason,
LPVOID lpReserved
)
{
#ifdef _DEBUG
HANDLE h;
#endif
hlThis = hModule;
if(reason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hModule);
//Get path to the original d3d9.dll
char infoBuf[MAX_PATH];
GetSystemDirectory(syspath, MAX_PATH);
wcscat_s(syspath, L"\\d3d9.dll");
//And load it...
d3d9.dll = LoadLibrary(syspath);
if (!d3d9.dll){
MessageBox(NULL, L"D3D9 Proxy DLL error", L"Cannot find original d3d9.dll in the system directory!", MB_OK | MB_ICONERROR);
return FALSE;
}
d3d9.D3DPERF_BeginEvent = GetProcAddress(d3d9.dll, "D3DPERF_BeginEvent");
d3d9.D3DPERF_EndEvent = GetProcAddress(d3d9.dll, "D3DPERF_EndEvent");
d3d9.D3DPERF_GetStatus = GetProcAddress(d3d9.dll, "D3DPERF_GetStatus");
d3d9.D3DPERF_QueryRepeatFrame = GetProcAddress(d3d9.dll, "D3DPERF_QueryRepeatFrame");
d3d9.D3DPERF_SetMarker = GetProcAddress(d3d9.dll, "D3DPERF_SetMarker");
d3d9.D3DPERF_SetOptions = GetProcAddress(d3d9.dll, "D3DPERF_SetOptions");
d3d9.D3DPERF_SetRegion = GetProcAddress(d3d9.dll, "D3DPERF_SetRegion");
d3d9.DebugSetLevel = GetProcAddress(d3d9.dll, "DebugSetLevel");
d3d9.DebugSetMute = GetProcAddress(d3d9.dll, "DebugSetMute");
d3d9.Direct3DCreate9 = GetProcAddress(d3d9.dll, "Direct3DCreate9");
d3d9.Direct3DShaderValidatorCreate9 = GetProcAddress(d3d9.dll, "Direct3DShaderValidatorCreate9");
d3d9.PSGPError = GetProcAddress(d3d9.dll, "PSGPError");
d3d9.PSGPSampleTexture = GetProcAddress(d3d9.dll, "PSGPSampleTexture");
}else if(reason == DLL_PROCESS_DETACH)
{
FreeLibrary(d3d9.dll);
}
return TRUE;
}
实施Direct3DCreate9Ex():
#include "stdafx.h"
#include <d3d9.h>
#include <iostream>
//#include <d3dx9.h>
#include "d3d9ex.h"
d3d9_dll d3d9;
typedef IDirect3D9 *(APIENTRY * tDirect3DCreate9)(UINT);
HRESULT D3D9EXDLL_API Direct3DCreate9Ex(
UINT SDKVersion, /* [in] */
IDirect3D9Ex **ppD3D /*[out]*/
)
{
freopen("output.txt","a+",stdout);
std::cout << "d3d9ex" ;
std::cout << __LINE__ << "\n";
IDirect3D9 *local = NULL;
//tDirect3DCreate9 D3D = (tDirect3DCreate9)d3d9.Direct3DCreate9;
tDirect3DCreate9 D3D = (tDirect3DCreate9)GetProcAddress(d3d9.dll, "Direct3DCreate9");
if( NULL == (local = (D3D)(D3D_SDK_VERSION)) )
return E_OUTOFMEMORY;
*ppD3D = dynamic_cast<IDirect3D9Ex*>(local);
return S_OK;
}
重定向到其他功能的调用
__declspec(naked) void Direct3DShaderValidatorCreate9(){
_asm { jmp [d3d9.Direct3DShaderValidatorCreate9] }
}
__declspec(naked) void PSGPError(){
_asm { jmp [d3d9.PSGPError] }
}
__declspec(naked) void PSGPSampleTexture(){
_asm { jmp [d3d9.PSGPSampleTexture] }
}
__declspec(naked) void D3DPERF_BeginEvent(){
_asm { jmp [d3d9.D3DPERF_BeginEvent] }
}
__declspec(naked) void _D3DPERF_EndEvent(){
_asm { jmp [d3d9.D3DPERF_EndEvent] }
}
__declspec(naked) void _D3DPERF_GetStatus(){
_asm { jmp [d3d9.D3DPERF_GetStatus] }
}
__declspec(naked) void _D3DPERF_QueryRepeatFrame(){
_asm { jmp [d3d9.D3DPERF_QueryRepeatFrame] }
}
__declspec(naked) void D3DPERF_SetMarker(){
_asm { jmp [d3d9.D3DPERF_SetMarker] }
}
__declspec(naked) void D3DPERF_SetOptions(){
_asm { jmp [d3d9.D3DPERF_SetOptions] }
}
__declspec(naked) void D3DPERF_SetRegion(){
_asm { jmp [d3d9.D3DPERF_SetRegion] }
}
__declspec(naked) void DebugSetLevel(){
_asm { jmp [d3d9.DebugSetLevel] }
}
__declspec(naked) void DebugSetMute(){
_asm { jmp [d3d9.DebugSetMute] }
}
__declspec(naked) void Direct3DCreate9(){
_asm { jmp [d3d9.Direct3DCreate9] }
}
d3d9ex.h:
#ifdef D3D9EXDLL_EXPORTS
#define D3D9EXDLL_API __stdcall
#else
#define D3D9EXDLL_API __stdcall
#endif
struct IDirect3D9Ex;
struct d3d9_dll
{
HMODULE dll;
FARPROC Direct3DShaderValidatorCreate9;
FARPROC PSGPError;
FARPROC PSGPSampleTexture;
FARPROC D3DPERF_BeginEvent;
FARPROC D3DPERF_EndEvent;
FARPROC D3DPERF_GetStatus;
FARPROC D3DPERF_QueryRepeatFrame;
FARPROC D3DPERF_SetMarker;
FARPROC D3DPERF_SetOptions;
FARPROC D3DPERF_SetRegion;
FARPROC DebugSetLevel;
FARPROC DebugSetMute;
FARPROC Direct3DCreate9;
};
HRESULT D3D9EXDLL_API Direct3DCreate9Ex(
UINT SDKVersion, /* [in] */
IDirect3D9Ex **ppD3D /*[out]*/
);
.def文件:
LIBRARY D3D9
EXPORTS
Direct3DShaderValidatorCreate9 @2
PSGPError @3
PSGPSampleTexture @4
D3DPERF_BeginEvent @5
D3DPERF_EndEvent = _D3DPERF_EndEvent @6
D3DPERF_GetStatus = _D3DPERF_GetStatus @7
D3DPERF_QueryRepeatFrame = _D3DPERF_QueryRepeatFrame @8
D3DPERF_SetMarker @9
D3DPERF_SetOptions @10
D3DPERF_SetRegion @11
DebugSetLevel @12
DebugSetMute @13
Direct3DCreate9 @14
Direct3DCreate9Ex