Code:
#include <Windows.h>
#include "Colors.h"
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#define DPD3D /*d3d9.dll*/XorStr<0xD6,9,0x090226CA>("\xB2\xE4\xBC\xE0\xF4\xBF\xB0\xB1"+0x090226CA).s
DWORD WINAPI D3D9VTable()
{
DWORD hD3D = (DWORD)LoadLibraryA(DPD3D);
DWORD adr = FindPattern(hD3D, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
return(adr + 2);
}
VOID WINAPI WriteMemory(LPVOID lpAddress,LPBYTE lpBuffer,DWORD dwLengh)
{
LPBYTE pAddress = (LPBYTE)lpAddress;
LPBYTE pBuffer = (LPBYTE)lpBuffer;
MEMORY_BASIC_INFORMATION MBI;
VirtualQuery(lpAddress,&MBI,sizeof(MBI));
VirtualProtect(MBI.BaseAddress,MBI.RegionSize,PAGE_EXECUTE_READWRITE,&MBI.Protect);
while ( dwLengh-- > 0 )
{
*pAddress++ = *pBuffer++;
}
VirtualProtect(MBI.BaseAddress,MBI.RegionSize,MBI.Protect,&MBI.Protect);
FlushInstructionCache(GetCurrentProcess(),lpAddress,dwLengh);
}
DWORD FindDevice;
VOID WINAPI WriteJump(DWORD dwFunction,DWORD dwAddress)
{
BYTE DetourBytes[5] = {0xE9,0x00,0x00,0x00,0x00};
*(DWORD*)(&DetourBytes[1]) = ( dwFunction - dwAddress ) - 0x5;
WriteMemory((LPVOID)dwAddress,(LPBYTE)DetourBytes,5);
}
BOOL WINAPI CheckWindowsVersion(DWORD dwMajorVersion,DWORD dwMinorVersion,DWORD dwProductType)
{
OSVERSIONINFOEX VersionInfo;
ZeroMemory(&VersionInfo,sizeof(OSVERSIONINFOEX));
VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
GetVersionEx((OSVERSIONINFO*)&VersionInfo);
if ( VersionInfo.dwMajorVersion == dwMajorVersion )
{
if ( VersionInfo.dwMinorVersion == dwMinorVersion )
{
if ( VersionInfo.wProductType == dwProductType )
{
return ( TRUE );
}
}
}
return ( FALSE );
}
VOID WINAPI HideModule(HMODULE hModule)
{
DWORD dwPEB_LDR_DATA = 0;
__asm
{
MOV EAX,FS:[0x30]
MOV EAX,[EAX+0xC]
MOV EAX,[EAX+0xC]
MOV DWORD PTR [EAX+0x20],0xFFFFFFFF
}
__asm
{
PUSHAD
PUSHFD
MOV EAX, FS:[30h]
MOV EAX, [EAX+0Ch]
MOV dwPEB_LDR_DATA, EAX
InLoadOrderModuleList:
MOV ESI, [EAX+0Ch]
MOV EDX, [EAX+10h]
LoopInLoadOrderModuleList:
LODSD
MOV ESI, EAX
MOV ECX, [EAX+18h]
CMP ECX, hModule
JNE SkipA
MOV EBX, [EAX]
MOV ECX, [EAX+4]
MOV [ECX], EBX
MOV [EBX+4], ECX
JMP InMemoryOrderModuleList
SkipA:
CMP EDX, ESI
JNE LoopInLoadOrderModuleList
InMemoryOrderModuleList:
MOV EAX, dwPEB_LDR_DATA
MOV ESI, [EAX+14h]
MOV EDX, [EAX+18h]
LoopInMemoryOrderModuleList:
LODSD
MOV ESI, EAX
MOV ECX, [EAX+10h]
CMP ECX, hModule
JNE SkipB
MOV EBX, [EAX]
MOV ECX, [EAX+4]
MOV [ECX], EBX
MOV [EBX+4], ECX
JMP InInitializationOrderModuleList
SkipB:
CMP EDX, ESI
JNE LoopInMemoryOrderModuleList
InInitializationOrderModuleList:
MOV EAX, dwPEB_LDR_DATA
MOV ESI, [EAX+1Ch]
MOV EDX, [EAX+20h]
LoopInInitializationOrderModuleList:
LODSD
MOV ESI, EAX
MOV ECX, [EAX+08h]
CMP ECX, hModule
JNE SkipC
MOV EBX, [EAX]
MOV ECX, [EAX+4]
MOV [ECX], EBX
MOV [EBX+4], ECX
JMP Finished
SkipC:
CMP EDX, ESI
JNE LoopInInitializationOrderModuleList
Finished:
POPFD;
POPAD;
}
}
BYTE DrawIndexedPrimitive_Bytes[5];
BOOL DrawIndexedPrimitive_Check = TRUE;
DWORD DrawIndexedPrimitive_Hook = 0x00;
DWORD DrawIndexedPrimitive_Jump = 0x00;
BOOL DrawIndexedPrimitive_CheckPtr = FALSE;
VOID WINAPI DrawIndexedPrimitive_Breakpoint();
LONG WINAPI DrawIndexedPrimitive_Exception(EXCEPTION_POINTERS* ExceptionInfo);
HRESULT (WINAPI* DrawIndexedPrimitive_Pointer)(LPDIRECT3DDEVICE9,D3DPRIMITIVETYPE,INT,UINT,UINT,UINT,UINT);
/*BYTE EndS_Bytes[5];
BOOL EndS_Check = TRUE;
DWORD EndS_Hook = 0x00;
DWORD EndS_Jump = 0x00;
BOOL EndS_CheckPtr = FALSE;
VOID WINAPI EndS_Breakpoint();
LONG WINAPI EndS_Exception(EXCEPTION_POINTERS* ExceptionInfo);
HRESULT (WINAPI* EndS_Pointer)(LPDIRECT3DDEVICE9 pDevice);
HRESULT (APIENTRY *oEndScene)(LPDIRECT3DDEVICE9 pDevice);*/
#define sWeapon 36
#define sMap 24
#define sSkyWalls 28
#define sBody 44
#define sHead 40
//
void DrawCrosshair(LPDIRECT3DDEVICE9 pDevice, int size, int strong, D3DCOLOR xcolor)
{
int iCenterX = GetSystemMetrics( 0 ) / 2;
int iCenterY = GetSystemMetrics( 1 ) / 2;
if( iCenterX < 20 && iCenterY < 20 )
{
iCenterX = ( GetSystemMetrics( 0 ) / 2 );
iCenterY = ( GetSystemMetrics( 1 ) / 2 );
}
D3DRECT rec2 = { iCenterX- size, iCenterY, iCenterX+ size, iCenterY+ strong};
D3DRECT rec3 = { iCenterX, iCenterY- size, iCenterX+ strong,iCenterY+ size};
pDevice->Clear(1, &rec2, D3DCLEAR_TARGET, xcolor, 1000, 0);
pDevice->Clear(1, &rec3, D3DCLEAR_TARGET, xcolor, 100, 0);
}
//
VOID DrawRect( INT x, INT y, INT h, INT w, DWORD Color, LPDIRECT3DDEVICE9 pDevice)
{
D3DRECT rec;
rec.x1 = x;
rec.x2 = x + w;
rec.y1 = y;
rec.y2 = y + h;
pDevice->Clear(1, &rec, D3DCLEAR_TARGET, Color, 0, 0);
}
void DrawMouse(DWORD color,LPDIRECT3DDEVICE9 pDevice)
{
POINT myCursor;
GetCursorPos(&myCursor);
DrawRect(myCursor.x,myCursor.y,11,1,color,pDevice);
DrawRect(myCursor.x+1,myCursor.y+1,9,1,color,pDevice);
DrawRect(myCursor.x+2,myCursor.y+2,7,1,color,pDevice);
DrawRect(myCursor.x+3,myCursor.y+3,7,1,color,pDevice);
DrawRect(myCursor.x+4,myCursor.y+4,8,1,color,pDevice);
DrawRect(myCursor.x+5,myCursor.y+5,3,1,color,pDevice);
DrawRect(myCursor.x+6,myCursor.y+6,2,1,color,pDevice);
DrawRect(myCursor.x+7,myCursor.y+6,1,1,color,pDevice);
DrawRect(myCursor.x+5,myCursor.y+10,4,1,color,pDevice);
DrawRect(myCursor.x+6,myCursor.y+12,2,1,color,pDevice);
}
//
LPDIRECT3DTEXTURE9 texYellow, texBlue;
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{
if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex,NULL)) )
return E_FAIL;
WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
|(WORD)(((colour32>>20)&0xF)<<8)
|(WORD)(((colour32>>12)&0xF)<<4)
|(WORD)(((colour32>>4)&0xF)<<0);
D3DLOCKED_RECT d3dlr;
(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
WORD *pDst16 = (WORD*)d3dlr.pBits;
for(int xy=0; xy < 8*8; xy++)
*pDst16++ = colour16;
(*ppD3Dtex)->UnlockRect(0);
return S_OK;
}
VOID WINAPI DrawIndexedPrimitive_Main(LPDIRECT3DDEVICE9 pDevice,D3DPRIMITIVETYPE Type,INT BaseVertexIndex,UINT MinIndex,UINT NumVertices,UINT StartIndex,UINT PrimitiveCount)
{
LPDIRECT3DVERTEXBUFFER9 Stream;
UINT Stride;
UINT Offset;
if ( pDevice->GetStreamSource(0,&Stream,&Offset,&Stride) == D3D_OK )
{
Stream->Release();
}
if(!OnceTxture){
GenerateTexture(pDevice, &texBlue,D3DCOLOR_ARGB(255,0,0,255));
GenerateTexture(pDevice, &texYellow,D3DCOLOR_ARGB(255,255,255,0));
OnceTxture = true;
}
DrawIndexedPrimitive_CheckPtr = TRUE;
if (Stride == sBody || Stride == sWeapon || Stride == sWeapon)
{
pDevice->SetRenderState(D3DRS_ZENABLE,FALSE);
pDevice->SetTexture(0, texYellow);
DrawIndexedPrimitive_Pointer(pDevice,Type,BaseVertexIndex,MinIndex,NumVertices,StartIndex,PrimitiveCount);
pDevice->SetRenderState(D3DRS_ZENABLE,TRUE);
pDevice->SetTexture(0, texBlue);
//DrawCrosshair(pDevice , 13, 1.5, cPink);
}
if( Stride == 1 )
DrawCrosshair(pDevice , 13, 1.5, cPink);
DrawIndexedPrimitive_CheckPtr = FALSE;
}
__declspec(naked)VOID WINAPI DrawIndexedPrimitive_Call()
{
if ( DrawIndexedPrimitive_Check == TRUE )
{
WriteMemory((LPVOID)DrawIndexedPrimitive_Hook,(LPBYTE)DrawIndexedPrimitive_Bytes,5);
DrawIndexedPrimitive_Breakpoint();
DrawIndexedPrimitive_Check = FALSE;
}
__asm
{
MOV EDI,DWORD PTR SS:[EBP+0x8]
XOR EBX,EBX
PUSHFD
PUSHAD
MOV EDX,[DrawIndexedPrimitive_CheckPtr]
CMP EDX,0x0
JG Jump
PUSH [EBP+0x20]
PUSH [EBP+0x1C]
PUSH [EBP+0x18]
PUSH [EBP+0x14]
PUSH [EBP+0x10]
PUSH [EBP+0xC]
PUSH [EBP+0x8]
CALL [DrawIndexedPrimitive_Main]
Jump:
POPAD
POPFD
CMP EDI,EBX
JMP [DrawIndexedPrimitive_Jump]
}
}
LONG WINAPI DrawIndexedPrimitive_Exception(EXCEPTION_POINTERS* ExceptionInfo)
{
if ( ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP && (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress == DrawIndexedPrimitive_Hook )
{
ExceptionInfo->ContextRecord->Eip = (DWORD)DrawIndexedPrimitive_Call;
return ( EXCEPTION_CONTINUE_EXECUTION );
}
return ( EXCEPTION_CONTINUE_SEARCH );
}
VOID WINAPI DrawIndexedPrimitive_Breakpoint()
{
AddVectoredExceptionHandler((rand()%0xFFFFFF),DrawIndexedPrimitive_Exception);
CONTEXT Context = {CONTEXT_DEBUG_REGISTERS};
Context.Dr0 = DrawIndexedPrimitive_Hook;
Context.Dr7 = 0x1;
SetThreadContext(GetCurrentThread(),&Context);
}
//
//
VOID WINAPI DirectX9Main()
{
PDWORD dwD3DVTable;
do
{
*(DWORD*)&dwD3DVTable = *(DWORD*)D3D9VTable();
}
while ( !dwD3DVTable );
/* This Hook Is For Windows 7 and Windows Vista */
if ( CheckWindowsVersion(6,1,VER_NT_WORKSTATION) || CheckWindowsVersion(6,0,VER_NT_WORKSTATION) )
{
DrawIndexedPrimitive_Hook = ( dwD3DVTable[82] + 0x2D );
DrawIndexedPrimitive_Jump = ( DrawIndexedPrimitive_Hook + 0x7 );
*(PDWORD)(&DrawIndexedPrimitive_Pointer) = (DWORD)dwD3DVTable[82];
WriteMemory((LPVOID)DrawIndexedPrimitive_Bytes,(LPBYTE)DrawIndexedPrimitive_Hook,5);
WriteJump((DWORD)DrawIndexedPrimitive_Call,(DWORD)DrawIndexedPrimitive_Hook);
//
}
/* You Want A Hook For Windows XP ? - Add A Midfunction For Windows XP And A Check Here */
else
{
MessageBoxA(GetActiveWindow(),"CoderName >> Your System Is Not Supported","<Error>",MB_OK);
ExitProcess(0);
}
}