Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 19:05

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

Advertisement



Calling Convention Problem bei Hook

Discussion on Calling Convention Problem bei Hook within the C/C++ forum part of the Coders Den category.

Closed Thread
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2014
Posts: 442
Received Thanks: 211
Post Calling Convention Problem bei Hook

Hey,
ich versuche derzeit die Argumente einer Funktion von einem Spiel zu bekommen mithilfe eines MS Detours.
Also wenn ich z.B die MessageBoxW Funktion detouren möchte, mache ich es folgendermaßen:
Code:
#include <windows.h>
#include <detours.h>

#pragma comment(lib, "detours.lib")

typedef int (WINAPI *MessageBoxType) (HWND, LPCTSTR, LPCTSTR, UINT);

MessageBoxType MessageBox_orig = nullptr;

int WINAPI MessageBoxDetour(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
{
	lpText = L"Text Parameter hooked";
	lpCaption = L"Caption Parameter hooked";

	return MessageBox_orig(hWnd, lpText, lpCaption, uType);
}

BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID lpReserved)
{
	switch(fdwReason)
	{
	case DLL_PROCESS_ATTACH:
		MessageBox_orig = (MessageBoxType)DetourFunction((PBYTE)MessageBoxW, (PBYTE)MessageBoxDetour);
		break;
	}
	return TRUE;
}
Was auch soweit funktioniert, doch jetzt möchte ich eine Funktion detouren die keinen Rückgabewert hat (void) und davon die Parameter bekommen.
Hier ein Ausschnitt aus OllyDbg von der Funktion:


Die 6 Argumente die hier im Disassembly abgebildet sind versuche ich zu bekommen:
Arg1: DWORD
Arg2: DWORD
Arg3: float
Arg4: float
Arg5: float
Arg6: bool (default arg = true)


Und IDA:


Mit einem Mid-Function Detour bekomme ich z.B die Werte die im ECX oder EAX Register stehen ohne Probleme zurück, doch mir wäre es lieber mit einem Funktionspointer, anstatt das ganze Inline-Assembler-Gefrickel

Ich vermute, dass das ein __thiscall ist, also eine Member-Funktion... doch wie würde jetzt hier der Funktionspointer aussehen?

MfG _asm
_asm is offline  
Old 05/02/2015, 18:08   #2


 
Jeoni's Avatar
 
elite*gold: 966
Join Date: Apr 2010
Posts: 1,105
Received Thanks: 681
Ja, die Funktion dort scheint in der Tat eine Memberfunktion (thiscall) zu sein.
Ich selber benutze eigentlich immer __fastcall, wenn ich solche Funktionen hooke.
Das erste Argument einer Fastcall-Funktion liegt in ECX, das Zweite in EDX, alle Weiteren, wie bei stdcall auch, auf dem Stack. Zudem räumt der Callee den Stack auf, wie bei stdcall und thiscall (sofern keine variablen Argumentlisten benutzt werden) auch.
In deinem Fall sähe die Hookfunktion also so aus:
Code:
void __fastcall MyFunction0045E200(void* thisptr, void* _edx, DWORD arg0, DWORD arg1, float arg2, float arg3, float arg4, bool arg5)
(den Funktionspointer / -typ daraus zu lesen ist ja trivial)
Das _edx muss sein, sonst würde man arg0 in EDX suchen und alle anderen Argumente einen Platz zu früh auf dem Stack.
Mit freundlichen Grüßen
Jeoni
Jeoni is offline  
Thanks
1 User
Old 05/02/2015, 18:25   #3
 
elite*gold: 0
Join Date: Dec 2014
Posts: 442
Received Thanks: 211
Danke dir Jeoni, hab nochmal die Funktion dekompiliert und mir einen typedef dafür geschrieben, jetzt funktioniert es auch (:

Falls dich das noch interessiert, in IDA:
Code:
int __thiscall sub_45E200(void *this, int a2, int a3, float a4, float a5, float a6, char a7)
#Kann geschlossen werden.

Mit freundlichen Grüßen, _asm
_asm is offline  
Thanks
1 User
Old 05/02/2015, 18:35   #4

 
snow's Avatar
 
elite*gold: 724
Join Date: Mar 2011
Posts: 10,479
Received Thanks: 3,318
Noch anzumerken wäre, dass __thiscall bei typedefs funktioniert, bei Funktionsprototypen aber wie von Jeoni korrekt geschrieben __fastcall verwendet werden muss, deshalb der Dummy-edx-Paramter.

#closed (on request)
snow is offline  
Thanks
2 Users
Closed Thread

Tags
callingconvention, hooking


Similar Threads Similar Threads
Parameter und Calling Convention finden
08/21/2014 - C/C++ - 14 Replies
Hey, habe in einem Spiel mit ollydbg eine Funktion gefunden, von der ich glaube, dass sie Text auf dem Bildschirm ausgibt: Address Hex dump Command Comments 013CDB28 F30F1085 6CFFFF MOVSS XMM0,DWORD PTR SS: ; FLOAT 42.00000 013CDB30 8D85 78FFFFFF LEA EAX, 013CDB36 F30F5805 5850CE ADDSS XMM0,DWORD PTR DS: ; FLOAT 20.00000 (y coord?) 013CDB3E D985 70FFFFFF FLD DWORD PTR SS: ; FLOAT 1760.00000 (x coord?)
[PHP problem] Calling an object's function with parameters
09/11/2013 - Web Development - 7 Replies
Hey guys, recently I got a problem with PHP on which I haven't found a solution yet. I'm calling a function out of a object, but there seems to be a problem regarding the parameters. Object (very simplyfied): class HP{ function preload_async($folders){ var_dump($folders); }
D3D Hook Problem
11/02/2011 - General Coding - 13 Replies
Hi, ich habe jetzt versucht nen D3D Hook zu schreiben, nachdem ich das Tutorial von purple diamond gelesen habe: http://www.homeofgamehacking.de/attachment.php?aid =120. Leider hab ich echt keine Ahnung was ich hier falsch mache. Bevor ich vor die DllMain Funktion extern "C" hinzugefügt habe, lies sich die Dll nicht mal injecten. Jetzt funktioniert das, allerdings wird kein Rechteck gezeichnet. Die Adresse hab ich auch wie im Tutorial mit IDA bekommen. Wäre wirklich sehr nett wenn sich das...
Wrong Calling Convention! (Run-Time Check Failure #0)
01/11/2010 - General Coding - 4 Replies
Greetings, hijax
[C++]D3D hook Problem
11/09/2009 - C/C++ - 28 Replies
#pragma once #pragma comment(lib, "d3d9.lib") #pragma comment(lib, "d3dx9.lib") #include <windows.h> #include <cstdio> #include <d3d9.h> #include <d3dx9.h> LPDIRECT3DDEVICE9 pDevice; const D3DCOLOR txtPink = D3DCOLOR_ARGB(255, 255, 0, 255); // Alpha, Rot, Grün, Blau



All times are GMT +1. The time now is 19:05.


Powered by vBulletin®
Copyright ©2000 - 2025, 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 ©2025 elitepvpers All Rights Reserved.