Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 11:51

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Direct3DCreate9 - Hook fail

Discussion on Direct3DCreate9 - Hook fail within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
xNopex's Avatar
 
elite*gold: 0
Join Date: May 2009
Posts: 827
Received Thanks: 471
Direct3DCreate9 - Hook fail

Hallo ihr mehr oder weniger begabten Leute,

Ich brauche Hilfe. Und zwar wollte ich ein bisschen mit dem D3D-Hooking rumspielen und habe mich daran gemacht die im Titel beschriebene Funktion zu entern, um mir die Adresse ihres return Wertes zu schnappen, um dann weiter zu verfahren, ihr kennt das bestimmt alle. Habe mir dazu eine schöne, schnuckelige kleine Klasse geschrieben und will das ganze bei WarRock testen. Kenn mich da nicht aus, wenn mich jemand schlägt, weil Warrock D3D8 ist, oder weiß was ich was die ENtwickler da machen, dann kann er das ja in seinem Lösungsvorschlag berücksichtigen.
So, wo liegt das eigentliche Problem? Tjoa.. Ich gelange zwar an die Adresse des Objekts, aber kurz darauf stürzt Warrock immer ab. Ohne Fehlermeldung, nichts. Zur Idee: Ich hole mir die Adresse zu Direct3DCreate9, wird ja exportiert, überschreibe die ersten 5Bytes, sodass man, wenn die Funktion aufgerufen wird, zu meiner Funktion springt, in der ich die überschriebenen Bytes der Originalfunktion wieder mit den ürsprünglichen überschreibe, sodass eig. alles wie vorher sein müsste. In der Funktion rufe ich dann die Original Funktion auf, speichere ihren return-Wert in einem Zeiger und returne dann meinen Zeiger zurück zu Warrock.
Ich finde das klingt von der Theorie sehr schön, und wenn ich von meiner Funktion NULL returne, dann spuckt mir warrock auch ne nette Fehlermeldung aus, dass das Objekt nicht erstellt werden konnte. Also alles, wie geplant. Nur scheint die Adresse, die ich returne, doch iwie nicht zu stimmen, weil Warrock, wie gesagt, einfach mal so abkackt. Auch nach längerer Fehleranalyse bin ich zu keinem Ergebniss gekommen.

Also ich hoffe ich treffe hier auf jemanden, der mir erklären kann, wo mein Denkfehler liegt. Falls den jemand sehen will, mein bisheriger Sourcecode von den wichtigen Stellen (leider weder auskommentiert, noch optimiert):

Code:
#include "d3dHook.h"

#pragma comment( lib, "d3d9.lib" )
typedef IDirect3D9* (CALLBACK* OrigDirect3DCreate9)(UINT);
D3D9HOOK* pObject = NULL;

IDirect3D9* MyD3DCreateFunc( UINT SDKVersion )
{
	IDirect3D9* pD3D9 = NULL;

	BYTE* pDirect3DCreate9 = pObject->GetDirect3DCreate9Pointer();
	BYTE* memoryBackup = pObject->GetMemoryBackup();
	HMODULE hD3D9 = pObject->GetD3D9Module();

	if( pDirect3DCreate9 == NULL || memoryBackup == NULL || hD3D9 == NULL )
		return NULL;

	pDirect3DCreate9[0] = memoryBackup[0];
	pDirect3DCreate9[1] = memoryBackup[1];
	pDirect3DCreate9[2] = memoryBackup[2];
	pDirect3DCreate9[3] = memoryBackup[3];
	pDirect3DCreate9[4] = memoryBackup[4];

	OrigDirect3DCreate9 pOrigFunc = OrigDirect3DCreate9( GetProcAddress( hD3D9, "Direct3DCreate9" ) );
	pD3D9 = pOrigFunc( SDKVersion );
	pObject->SetD3D9Object( pD3D9 );
	return pD3D9;
}


D3D9HOOK :: D3D9HOOK()
{
	this->pD3D9 = NULL;
	this->hD3D9 = NULL;
	this->pDirect3DCreate9 = NULL;
	ZeroMemory( this->memoryBackup, 5 );
}


bool D3D9HOOK :: CreateHook()
{
	try
	{
		if( ! this->GetD3D9ModuleHandle() )
			throw( DWORD( ERR_INVALID_MODULE_HANDLE ) );
		
		if( ! this->GetD3D9CreatePointer() )
			throw( DWORD( ERR_INVALID_POINTER ) );

		this->TryToInstallJump();
		this->WaitForSingleObject();

	}catch( DWORD err )
	{
		switch( err )
		{
		case ERR_INVALID_MODULE_HANDLE:
			break;
		case ERR_INVALID_POINTER:
			break;
		}
		return false;
	}

	return true;
}


bool D3D9HOOK :: GetD3D9ModuleHandle()
{
	this->hD3D9 = NULL;
	for( DWORD i = 0; i < 40 && this->hD3D9 == NULL; i++ )
	{
		this->hD3D9 = GetModuleHandle( L"d3d9.dll" );
		Sleep( 250 );
	}

	if( this->hD3D9 == NULL )
		return false;

	return true;
}


bool D3D9HOOK :: GetD3D9CreatePointer()
{
	BYTE* pTemp = (BYTE*)(GetProcAddress( this->hD3D9, "Direct3DCreate9" ));
	if( pTemp == NULL )
		return false;

	this->pDirect3DCreate9 = pTemp;
	return true;
}


void D3D9HOOK :: TryToInstallJump()
{
	pObject = this;
	DWORD dwOld;
	DWORD p_dwMyFunc = DWORD(&MyD3DCreateFunc);
	VirtualProtect( pDirect3DCreate9, 5, PAGE_READWRITE, &dwOld );

	this->memoryBackup[0] = this->pDirect3DCreate9[0];
	this->memoryBackup[1] = this->pDirect3DCreate9[1];
	this->memoryBackup[2] = this->pDirect3DCreate9[2];
	this->memoryBackup[3] = this->pDirect3DCreate9[3];
	this->memoryBackup[4] = this->pDirect3DCreate9[4];

	this->pDirect3DCreate9[0] = 0xE9;
	*(DWORD*)(this->pDirect3DCreate9+1) = DWORD( p_dwMyFunc-(DWORD(this->pDirect3DCreate9))-5 );
}

void D3D9HOOK :: WaitForSingleObject()
{
	while( this->pD3D9 == NULL )
	{
		Sleep( 250 );
	}
	OutputDebugStr( L"---proxy:IDirect3D9-Object erhalten!!" );
}


HMODULE D3D9HOOK :: GetD3D9Module()
{
	return this->hD3D9;
}

BYTE* D3D9HOOK :: GetDirect3DCreate9Pointer()
{
	return this->pDirect3DCreate9;
}

BYTE* D3D9HOOK :: GetMemoryBackup()
{
	return this->memoryBackup;
}

void D3D9HOOK :: SetD3D9Object( IDirect3D9* pPara )
{
	this->pD3D9 = pPara;
}
xNopex is offline  
Old 10/30/2010, 17:49   #2
 
elite*gold: 115
Join Date: Oct 2007
Posts: 9,390
Received Thanks: 12,344
Quote:
Originally Posted by xNopex View Post
Code:
VirtualProtect( pDirect3DCreate9, 5, PAGE_READWRITE, &dwOld );
Müsste es hier nicht PAGE_EXECUTE_READWRITE heißen? Du veränderst ja was im Code. Aber wenn du sagst, dass er nicht crasht wenn du NULL returnst, sollte es eigentlich nicht daran liegen.

Quote:
Originally Posted by xNopex View Post
Code:
OrigDirect3DCreate9 pOrigFunc = OrigDirect3DCreate9( GetProcAddress( hD3D9, "Direct3DCreate9" ) );
pD3D9 = pOrigFunc( SDKVersion );
Callst du hier vielleicht mit der falschen Calling-Convention?
ms​ is offline  
Old 10/30/2010, 18:14   #3
 
xNopex's Avatar
 
elite*gold: 0
Join Date: May 2009
Posts: 827
Received Thanks: 471
Die Calling-Convention sollte stimmen. Habe den Prototyp gemäß MSDN-Eintrag definiert.
xNopex is offline  
Old 10/30/2010, 18:23   #4
 
elite*gold: 115
Join Date: Oct 2007
Posts: 9,390
Received Thanks: 12,344
Dann kann ich mir auch nicht erklären warum es nicht funktioniert, außer vielleicht das mit dem VirtualProtect.

Code:
#include <iostream>
#include <d3d9.h>

typedef IDirect3D9 *(CALLBACK *OrigDirect3DCreate9)(UINT);

using namespace std;

int main()
{
    Direct3DCreate9(D3D_SDK_VERSION); //damit die DLL überhaupt erst geladen wird
    OrigDirect3DCreate9 pOrigFunc = OrigDirect3DCreate9(GetProcAddress(GetModuleHandle("d3d9.dll"), "Direct3DCreate9"));
    cout << hex << (uint32_t)pOrigFunc << endl;
    IDirect3D9 *pD3D9 = pOrigFunc(D3D_SDK_VERSION);
    cout << hex << (uint32_t)pD3D9 << endl;
    cout << pD3D9->GetAdapterCount() << endl;
    return 0;
}
Wenn ich deinen Code in MinGW teste funktioniert alles.
ms​ is offline  
Old 10/30/2010, 18:32   #5
 
xNopex's Avatar
 
elite*gold: 0
Join Date: May 2009
Posts: 827
Received Thanks: 471
Dass es am Compiler von Microsoft liegt möchte ich iwie nicht glauben. Gerade Ausprobiert: Mit PAGE_EXECUTE_READWRITE - Rechten stürzt es ebenfalls ab. Einfach so. Keine Meldung, nichts.
xNopex is offline  
Old 10/30/2010, 18:43   #6
 
elite*gold: 115
Join Date: Oct 2007
Posts: 9,390
Received Thanks: 12,344
Dass es an Visual Studio liegt hab ich auch gar nicht behauptet, ich hab VS nur im Moment nicht installiert.

Mir ist aber gerade was anderes aufgefallen. Dein Detour (MyD3DCreateFunc) müsste ja auch die selbe Calling-Convention haben.

Code:
IDirect3D9* [B][COLOR="Red"]CALLBACK[/COLOR][/B] MyD3DCreateFunc(UINT SDKVersion)
Wenns immernoch nicht funktioniert, dann weiß ich auch nicht woran es liegt.
ms​ is offline  
Old 10/30/2010, 18:49   #7
 
xNopex's Avatar
 
elite*gold: 0
Join Date: May 2009
Posts: 827
Received Thanks: 471
v.v Es geht
Dankesehr, da wäre ich von alleine dummerweise niemals drauf gekommen.
xNopex is offline  
Reply


Similar Threads Similar Threads
FAIL | WAS FÜR EIN FAIL [ VIDEO ] | FAIL
09/22/2010 - Off Topic - 12 Replies
Schaut euch das an OMG XD YouTube - Durchfall im Pool
[WarRock Hook] Pretzel D3D Public Hook 15/9/2010
09/15/2010 - WarRock Hacks, Bots, Cheats & Exploits - 25 Replies
SCREENSHOT Da VirusTotal leider unter hoher Belastung steht, konnte ich keinen Scan von VT machen (die Wartezeit beträgt über eine Stunde, lol). Daher habe ich ein Scan von VirSCAN.org - Free Multi-Engine Online Virus Scanner v1.02, Supports 36 AntiVirus Engines! gemacht (unterstützt 36 Vireprogramme). SCAN DOWNLOAD
About this Fail Board and another Fail User
02/15/2010 - Mabinogi - 4 Replies
I sent this to Kev, the Mod of this Section, some Time ago. He said he'll think about what to do, but of course he didn't, so I'll just post it here, so the Kids can start one more brainless Flamewar about something... ... I just read some random Thread from "Trismic" and realized his Signature. It has a Link to his website http://methus.co.nr and after a Sec I recalled where I know his website from... He is promoting a fake "Mabinogi Gold Generator" on Youtube which tries to gather...



All times are GMT +2. The time now is 11:51.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.