[Source]D3D9: Update on last topic

Posts 1–7 of 7 · Page 1 of 1
[Source]D3D9: Update on last topic
I've updated the library with a hook function, with it you can hook all the D3D library functions with these: Hook() & ReturnFromHook().

Hook returns the address of a 'trampoline' that is used to 'bounce' execution from the specified hook back to the original function.

The address returned by hook must be passed to ReturnFromHook(). ReturnFromHook fixes the stack and other complications that may arise. After that the program executes like it normally would.

Templates:

Code:
	DWORD _stdcall Hook(DWORD TargetAddress, DWORD HookAddress);
	DWORD _stdcall ReturnFromHook(DWORD GhookAddress, DWORD NumberOfArguments);
Hook():
TargetAddress = Address of the function you want to hook
HookAddress = Address of your hook

ReturnFromHook():
GhookAddress = Address returned by the Hook() function (This address must only be used when returning form the same hook as supplied in the Hook() function)
NumberOfArguments = May be ignored, this argument does nothing.

Tested and working:

Code:
#include <windows.h>
#include <iostream>
#include <string.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\d3d9.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\d3dx9.h>

#pragma comment (lib, "C:\\Program Files (x86)\\Microsoft DirectX SDK (June 2010)\\Lib\\x86\\d3dx9.lib")
#pragma comment(lib, "VtableScan.lib")

extern "C"{
	DWORD _stdcall ScanTable();
	DWORD _stdcall Hook(DWORD TargetAddress, DWORD HookAddress);
	DWORD _stdcall ReturnFromHook(DWORD GhookAddress, DWORD NumberOfArguments);
}



int MainThread();
void DisplaySomeText(LPDIRECT3DDEVICE9 pDevice);
DWORD Gmem = NULL;
LPD3DXFONT m_font;
int i = 0;

void OurHook(LPDIRECT3DDEVICE9 pDevice){

D3DXCreateFont( pDevice, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &m_font ); 

DisplaySomeText(pDevice);

    ReturnFromHook(Gmem, 1);

}

BOOL APIENTRY DllMain( HANDLE hModule, DWORD  fdwReason, LPVOID lpReserved ){

	if( fdwReason == DLL_PROCESS_ATTACH){
       CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&MainThread, NULL, NULL, NULL);
	   return TRUE;
	}

    return TRUE;
}

int MainThread(){

	while(!GetModuleHandle("d3d9.dll")){
         Sleep(1000);
	}

	DWORD* Vtable = (DWORD*) ScanTable();
    Gmem = Hook((DWORD)Vtable[42], (DWORD)&OurHook);		// hook endscene


	char buffer[10] = "";
	std::string OutString = "Vtable Location: 0x";
    sprintf(&buffer[0],"%x",Vtable);
    OutString += buffer;
   	MessageBox(NULL, OutString.c_str(), "SCHiM", MB_OK);


return 0;
}


void DisplaySomeText(LPDIRECT3DDEVICE9 pDevice){

      D3DCOLOR fontColor = D3DCOLOR_ARGB(255,0,255,0);   
     
      RECT rct;
      rct.left=2;
      rct.right=780;
      rct.top=10;
      rct.bottom=rct.top+20;
       
      
      m_font->DrawText(NULL, "Hooked!", -1, &rct, 0, fontColor );
      m_font->Release();
}

Virs:

Virscan
Jotti

post back results!
Update.rarattachment deleted · 203 downloads before removal
Quote Originally Posted by Liz View Post
@Chooka avgn has no powers here.
Chooka ? Isn't it @kibbles18 ? ;P
I love you.
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us