Results 1 to 2 of 2

Threaded View

  1. #1
    LeHaxzor's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    67
    Reputation
    10
    Thanks
    1,944
    My Mood
    Amused

    Post Detour VTable Share Full Hook

    This is the hook I use to create my Chams.


    Code:
    #pragma comment (lib, "d3dx9.lib")
    #pragma comment (lib, "d3d9.lib")
    
    #include <Windows.h>
    #include <d3d9.h>
    #include <d3dx9.h>
    #include <iostream>
    #include <fstream>
    #include <detours.h>
    #include <stdio.h>
    #include <vector>
    #include "d3d9types.h"
    
    using namespace std;
    
    #define HOOK(func,addy)	o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)hk##func)
    #define D3D_RELEASE(D3D_PTR) if( D3D_PTR ){ D3D_PTR->Release(); D3D_PTR = NULL; }
    #define ES	0
    #define DIP	1
    #define RES 2
    DWORD VTable[3] = { 0 };
    
    DWORD WINAPI FindWin(LPVOID);
    DWORD D3DEndScene;
    DWORD D3DReset;
    DWORD D3DDrawIndexedPrimitive;
    DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatching(LPVOID);
    PDWORD Direct3D_VMTable = NULL;
    
    
    
    BYTE CodeFragmentES[5] = { 0, 0, 0, 0, 0 };
    BYTE CodeFragmentR[5] = { 0, 0, 0, 0, 0 };
    BYTE CodeFragmentDIP[5] = { 0, 0, 0, 0, 0 };
    
    HRESULT WINAPI Direct3DCreate9_VMTable(VOID);
    HRESULT WINAPI hkReset(LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
    typedef HRESULT(WINAPI* tEndScene)(LPDIRECT3DDEVICE9 LeHaxzor);
    typedef HRESULT(WINAPI* DrawIndexedPrimitive_)(LPDIRECT3DDEVICE9 Device, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount);
    typedef HRESULT(WINAPI* tDrawIndexedPrimitive)(LPDIRECT3DDEVICE9 LeHaxzor, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount);
    typedef HRESULT(WINAPI* tReset)(LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
    tReset oReset;
    DrawIndexedPrimitive_ oDrawIndexedPrimitive = NULL;
    tEndScene oEndScene;
    
    
    
    DWORD FindDevice(DWORD Len)
    {
    	DWORD dwObjBase = 0;
    
    	dwObjBase = (DWORD)LoadLibrary("d3d9.dll");
    	while (dwObjBase++ < dwObjBase + Len)
    	{
    		if ((*(WORD*)(dwObjBase + 0x00)) == 0x06C7
    			&& (*(WORD*)(dwObjBase + 0x06)) == 0x8689
    			&& (*(WORD*)(dwObjBase + 0x0C)) == 0x8689
    			) {
    			dwObjBase += 2; break;
    		}
    	}
    	return(dwObjBase);
    }
    
    DWORD GetDeviceAddress(int VTableIndex)
    {
    	PDWORD VTable;
    	*(DWORD*)&VTable = *(DWORD*)FindDevice(0x128000);
    	return VTable[VTableIndex];
    }
    
    HRESULT WINAPI hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 LeHaxzor, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount)
    {
    	//DIP
    	return oDrawIndexedPrimitive(LeHaxzor, PrimType, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
    }
    
    HRESULT WINAPI hkReset(LPDIRECT3DDEVICE9 LeHaxzor, D3DPRESENT_PARAMETERS* PresP)
    {
    	//Reset
    	return oReset(LeHaxzor, PresP);
    }
    
    HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 LeHaxzor)
    {
    	return oEndScene(LeHaxzor);
    }
    
    
    LRESULT CALLBACK MsgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	return DefWindowProc(hwnd, uMsg, wParam, lParam); 
    }
    void DX_Init(DWORD* table)
    {
    	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "DX", NULL };
    	RegisterClassEx(&wc);
    	HWND hWnd = CreateWindow("DX", NULL, WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL);
    	LPDIRECT3D9 pD3D = Direct3DCreate9(D3D_SDK_VERSION);
    	D3DPRESENT_PARAMETERS d3dpp;
    	ZeroMemory(&d3dpp, sizeof(d3dpp));
    	d3dpp.Windowed = TRUE;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    	LPDIRECT3DDEVICE9 pd3dDevice;
    	pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice);
    	DWORD* pVTable = (DWORD*)pd3dDevice;
    	pVTable = (DWORD*)pVTable[0];
    
    	table[ES] = pVTable[42];
    	table[DIP] = pVTable[82];
    	table[RES] = pVTable[16];
    
    	DestroyWindow(hWnd);
    }
    
    //Hook
    DWORD WINAPI MyThread(LPVOID)
    {
    	while (GetModuleHandle("d3d9.dll") == NULL) {
    		Sleep(250);
    	}
    
    	DX_Init(VTable);
    
    	HOOK(EndScene, VTable[ES]);
    	HOOK(DrawIndexedPrimitive, VTable[DIP]);
    	HOOK(Reset, VTable[RES]);
    
    	return 0;
    }
    
    BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
    {
    	if (dwReason == DLL_PROCESS_ATTACH) {
    
    		CreateThread(0, 0, MyThread, 0, 0, 0);
    	}
    
    	return TRUE;
    }

  2. The Following User Says Thank You to LeHaxzor For This Useful Post:

    WhiteHat PH (11-03-2015)

Similar Threads

  1. [SHARE] Finally Hooked PB yayz
    By whit in forum Piercing Blow Hack Coding/Source Code
    Replies: 61
    Last Post: 05-06-2011, 02:15 AM
  2. [Help] detours/hook Connect
    By Neoticer in forum Combat Arms EU Hack Coding/Source Code
    Replies: 8
    Last Post: 01-20-2011, 10:07 AM
  3. [CODE]VTable hooking
    By Hell_Demon in forum C++/C Programming
    Replies: 4
    Last Post: 10-31-2010, 01:49 PM
  4. unable to hook DrawPrimitive in vtable
    By Anddos in forum General Hacking
    Replies: 2
    Last Post: 02-08-2010, 05:19 AM
  5. [Source]Vtable Hook?
    By SoreBack in forum Combat Arms Hacks & Cheats
    Replies: 17
    Last Post: 01-29-2009, 11:46 AM