Some Days ago i worked on a D3D Hook for WT since this Hooking is detected after some mins i decided to post it public.
cMain.cpp:
cMain.h:
Credits:
- Me
- MSDN
- CyberRazzer ( Base Midfunc )
cMain.cpp:
Code:
VOID WINAPI Present_Main(LPDIRECT3DDEVICE9 pDevice,CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
{
Present_CheckPtr = TRUE;
// your code
Present_Pointer(pDevice,pSourceRect,pDestRect,hDestWindowOverride,pDirtyRegion);
Present_CheckPtr = FALSE;
}
__declspec(naked)VOID WINAPI Present_Call()
{
if ( Present_Check == TRUE )
{
cTools->WriteMemory((LPVOID)Present_Hook,(LPBYTE)Present_Bytes,5);
Present_Breakpoint();
Present_Check = FALSE;
}
__asm
{
MOV EDI,DWORD PTR SS:[EBP+0x8]
TEST EDI,EDI
PUSHFD
PUSHAD
MOV EDX,[Present_CheckPtr]
CMP EDX,0x0
JG Jump
PUSH [EBP+0x18]
PUSH [EBP+0x14]
PUSH [EBP+0x10]
PUSH [EBP+0xC]
PUSH [EBP+0x8]
CALL [Present_Main]
Jump:
POPAD
POPFD
JMP [Present_Jump]
}
}
LONG WINAPI Present_Exception(EXCEPTION_POINTERS* ExceptionInfo)
{
if ( ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP && (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress == Present_Hook )
{
ExceptionInfo->ContextRecord->Eip = (DWORD)Present_Call;
return ( EXCEPTION_CONTINUE_EXECUTION );
}
return ( EXCEPTION_CONTINUE_SEARCH );
}
VOID WINAPI Present_Breakpoint()
{
AddVectoredExceptionHandler((rand()%0xFFFFFF),Present_Exception);
CONTEXT Context = {CONTEXT_DEBUG_REGISTERS};
Context.Dr0 = Present_Hook;
Context.Dr7 = 0x1;
SetThreadContext(GetCurrentThread(),&Context);
}
Code:
VOID WINAPI DirectX9Hook()
{
while(!GetModuleHandleA("d3d9.dll")) Sleep(100);
Present_Hook = ( GetADRessPtr(17) + 0x7 );
Present_Jump = ( Present_Hook + 0x5 );
*(PDWORD)(&Present_Pointer) = GetADRessPtr(17);
cTools->WriteMemory((LPVOID)Present_Bytes,(LPBYTE)Present_Hook,5);
cTools->WriteJump((DWORD)Present_Call,(DWORD)Present_Hook);
}
cMain.h:
Code:
#include <Windows.h> typedef HRESULT (WINAPI* oReset) (LPDIRECT3DDEVICE9 pDevice,D3DPRESENT_PARAMETERS* pPresentationParameters); oReset pReset; BYTE Present_Bytes[5]; BOOL Present_Check = TRUE; DWORD Present_Hook = 0x00; DWORD Present_Jump = 0x00; BOOL Present_CheckPtr = FALSE; VOID WINAPI Present_Breakpoint(); LONG WINAPI Present_Exception(EXCEPTION_POINTERS* ExceptionInfo); HRESULT (WINAPI* Present_Pointer)(LPDIRECT3DDEVICE9,CONST RECT*,CONST RECT*,HWND,CONST RGNDATA*);
Credits:
- Me
- MSDN
- CyberRazzer ( Base Midfunc )