D3D EndScene Hook Tutorial Frage

07/19/2010 16:06 N1GHTLIFE#1
Hey, ich habe mir das Tutorial von purple.d1amond angeschaut, und habe als Test ( da ich noch nie ne D3D Funktion gehooked habe ) mal den Source aus dem Tut abgetippt und wollte ihn testen. Ich habe die .dll anschließend mit Winject in den Prozess von wow injected. Doch es passiert nichts, da wo eigentlich ein Rechteck sein sollte ( oben Rechts ) ist nichts :D )

Habe ich was falsch gemacht ? :

Code:
#include "stdafx.h"
#include <windows.h>
#include <cstdio>
#include <d3d9.h>
#include <d3dx9.h>

typedef HRESULT(__stdcall* EndScene_t)(LPDIRECT3DDEVICE9);
EndScene_t pEndScene;

void DrawRect(LPDIRECT3DDEVICE9 Device_t, int X, int Y, int L, int H, D3DCOLOR color){

	D3DRECT rect = {X,Y,X+L,Y+H};

}


bool hkEndScene(LPDIRECT3DDEVICE9 pDevice){

const D3DCOLOR txtPink = D3DCOLOR_ARGB(255,255, 0, 255);

DrawRect( pDevice, 10, 10, 200, 200, txtPink);

return pEndScene(pDevice);

 }


void* DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
	BYTE *jmp = (BYTE*)malloc(len+5);
	DWORD dwback;

	VirtualProtect(src, len, PAGE_READWRITE, &dwback);

	memcpy(jmp, src, len);	jmp += len;

	jmp[0] = 0xE9;
	*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;

	src[0] = 0xE9;
	*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;

	VirtualProtect(src, len, dwback, &dwback);

	return (jmp-len);
}



void InitHook()
{
HMODULE hModule = NULL;

   while(!hModule)
   {

      hModule = GetModuleHandleA("d3d9.dll");

Sleep(100);
}



unsigned dwBeginScene;
unsigned dwEndScene;
unsigned dwReset;
unsigned dwDrawIndexedPrimitive;
unsigned dwSetViewPort;
dwBeginScene = (DWORD)hModule + 0x87010;
dwEndScene = (DWORD)hModule + 0x871A0;
dwReset = (DWORD)hModule + 0x636B0;
dwDrawIndexedPrimitive = (DWORD)hModule + 0x88830;
dwSetViewPort = (DWORD)hModule + 0x82F70 ;



				
               
				pEndScene = (EndScene_t)(DetourFunc((PBYTE)dwEndScene,(PBYTE)hkEndScene, 5));


}


BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
{
	if (fdwReason == DLL_PROCESS_ATTACH)
	{
		
  CreateThread(0,0,(LPTHREAD_START_ROUTINE) InitHook,0,0,0);


	}
	return TRUE;
}
mfG
07/20/2010 12:38 Adroxxx#2
no questions forum

#moved
07/20/2010 16:29 P-a-i-n#3
wozu hast die BS, DIP, RES u.s.w drin wenn du es nicht aufrufst ? könntest eigentlich alles rauslöschen davon bis auf die endscene ;) dann haste selber mehr überblick

PHP Code:
void Rechteck (LPDIRECT3DDEVICE9 Device_tint Xint Yint Lint HD3DCOLOR color)
{
D3DRECT rect = {XYX+LY+H};
Device_t->Clear(1, &rectD3DCLEAR_TARGETcolor00); // das hast du vergessen

zur not kannste es auch so machen bei 123456 kommt deine adresse rein das funktioniert ganz sicher ;) was du davon nutzt ist deine sache was für dich einfacher ist

Code:
#pragma once
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>

typedef HRESULT (WINAPI* tEndScene)(LPDIRECT3DDEVICE9 pDevice);
tEndScene pEndScene = NULL;


D3DCOLOR txtPink = D3DCOLOR_ARGB(255,255, 0, 255);


void Funktionen();
void *DetourFunc(BYTE *src, const BYTE *dst, const int len);


void Rechteck (LPDIRECT3DDEVICE9 Device_t, int X, int Y, int L, int H, D3DCOLOR color)
{
D3DRECT rect = {X, Y, X+L, Y+H};
Device_t->Clear(1, &rect, D3DCLEAR_TARGET, color, 0, 0); 
}


HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
{  

	Rechteck (pDevice, 10, 10, 200, 200, txtPink);


    return pEndScene(pDevice); 
}
 
void Funktionen()
{
        HMODULE hModule = NULL;
        while( !hModule )
        {
                hModule = GetModuleHandleA( "d3d9.dll" );
                Sleep( 100 );							
        }
      
        pEndScene = (tEndScene )DetourFunc((PBYTE)  0x123456 ,(PBYTE)hkEndScene, 5); 
}

int WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID reserved) 
{
        switch(reason)
        {
        case DLL_PROCESS_ATTACH:

                CreateThread(0, 0, (LPTHREAD_START_ROUTINE) Funktionen, 0, 0, 0); 
				
                break;
        }
        return true;
}

void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{															
    BYTE *jmp = (BYTE*)malloc(len+5);
    DWORD dwback;
    VirtualProtect(src, len, PAGE_READWRITE, &dwback);
    memcpy(jmp, src, len); jmp += len;
        jmp[0] = 0xE9;
    *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
    src[0] = 0xE9;
    *(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
    VirtualProtect(src, len, dwback, &dwback);
    return (jmp-len);
}
07/24/2010 20:42 xlx00xlx#4
was ist endscence hook?
10/03/2011 20:04 jearca#5
Quote:
Originally Posted by P-a-i-n View Post
wozu hast die BS, DIP, RES u.s.w drin wenn du es nicht aufrufst ? könntest eigentlich alles rauslöschen davon bis auf die endscene ;) dann haste selber mehr überblick

PHP Code:
void Rechteck (LPDIRECT3DDEVICE9 Device_tint Xint Yint Lint HD3DCOLOR color)
{
D3DRECT rect = {XYX+LY+H};
Device_t->Clear(1, &rectD3DCLEAR_TARGETcolor00); // das hast du vergessen

zur not kannste es auch so machen bei 123456 kommt deine adresse rein das funktioniert ganz sicher ;) was du davon nutzt ist deine sache was für dich einfacher ist

Code:
#pragma once
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>

typedef HRESULT (WINAPI* tEndScene)(LPDIRECT3DDEVICE9 pDevice);
tEndScene pEndScene = NULL;


D3DCOLOR txtPink = D3DCOLOR_ARGB(255,255, 0, 255);


void Funktionen();
void *DetourFunc(BYTE *src, const BYTE *dst, const int len);


void Rechteck (LPDIRECT3DDEVICE9 Device_t, int X, int Y, int L, int H, D3DCOLOR color)
{
D3DRECT rect = {X, Y, X+L, Y+H};
Device_t->Clear(1, &rect, D3DCLEAR_TARGET, color, 0, 0); 
}


HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
{  

	Rechteck (pDevice, 10, 10, 200, 200, txtPink);


    return pEndScene(pDevice); 
}
 
void Funktionen()
{
        HMODULE hModule = NULL;
        while( !hModule )
        {
                hModule = GetModuleHandleA( "d3d9.dll" );
                Sleep( 100 );							
        }
      
        pEndScene = (tEndScene )DetourFunc((PBYTE)  0x123456 ,(PBYTE)hkEndScene, 5); 
}

int WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID reserved) 
{
        switch(reason)
        {
        case DLL_PROCESS_ATTACH:

                CreateThread(0, 0, (LPTHREAD_START_ROUTINE) Funktionen, 0, 0, 0); 
				
                break;
        }
        return true;
}

void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{															
    BYTE *jmp = (BYTE*)malloc(len+5);
    DWORD dwback;
    VirtualProtect(src, len, PAGE_READWRITE, &dwback);
    memcpy(jmp, src, len); jmp += len;
        jmp[0] = 0xE9;
    *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
    src[0] = 0xE9;
    *(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
    VirtualProtect(src, len, dwback, &dwback);
    return (jmp-len);
}
im compling this code with VC++ 2010, i make a .dll and im inject with NikM injector, and when in warrock log no happend nothing
10/03/2011 21:48 Jeoni#6
Of course nothing happened. P-a-i-n have posted a structure for the hook, but without the adress for the real endscene function.

@P-a-i-n:
Weisst du zufällig auch wie man die Adresse herausbekommt?