Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 19:59

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

Advertisement



Problems while detouring send() and recv().

Discussion on Problems while detouring send() and recv(). within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Feb 2009
Posts: 172
Received Thanks: 70
Problems while detouring send() and recv().

Hi there,

i've a problem. I'm not sure if i've done some misstakes. But every time i inject my dll the game will crash while i get or send a packet. Maybe someone can help me? I'll post the source code.

Code:
#include <windows.h>
#include "detours.h"

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

DWORD RecvOffset = 0x00D95060;
DWORD SendOffset = 0x00D950B0;

int (__stdcall *Recv)(SOCKET Socket, char *Buffer, int Length, int Flags);
int XRecv(SOCKET Socket, char *Buffer, int Length, int Flags) {

	return Recv(Socket, Buffer, Length, Flags);
}

int (__stdcall *Send)(SOCKET Socket, char *Buffer, int Length, int Flags);
int XSend(SOCKET Socket, char *Buffer, int Length, int Flags) {

	return Send(Socket, Buffer, Length, Flags);
}

BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved) {
	switch(dwReason) {
		case DLL_PROCESS_ATTACH:
			Recv = (int (__stdcall *)(SOCKET, char *, int, int))DetourFunction((PBYTE)RecvOffset, (PBYTE)XRecv);
			Send = (int (__stdcall *)(SOCKET, char *, int, int))DetourFunction((PBYTE)SendOffset, (PBYTE)XSend);			

			break;
		case DLL_PROCESS_DETACH:
			DetourRemove((PBYTE)Recv, (PBYTE)XRecv);
			DetourRemove((PBYTE)Send, (PBYTE)XSend);			

			break;
	}
	return true;
}
I don't know why i'll get a crash. The game log says: "EXCEPTION_ACCESS_VIOLATION". I tried some various types of detouring. I'll ever get a crash.

Here's the assembler part of (ingame) send:
Code:
mov     eax, [esp+len]
push    ebx
push    esi
mov     esi, [esp+8+arg_0]
push    edi
imul    esi, 78h
push    0               ; flags
mov     edi, ecx
mov     ecx, [esp+10h+buf]
mov     edx, [edi+10h]
push    eax             ; len
mov     eax, [edx+esi]
push    ecx             ; buf
push    eax             ; s
call    ds:send
cmp     eax, 0FFFFFFFFh
mov     ebx, [esp+0Ch+arg_C]
mov     [ebx], eax
jnz     short loc_D95100
call    ds:WSAGetLastError
cmp     eax, 2733h
mov     [ebx], eax
jnz     short loc_D950F8
mov     ecx, [edi+10h]
lea     eax, [ecx+esi+50h]
inc     dword ptr [eax]

loc_D950F8:
pop     edi
pop     esi
xor     al, al
pop     ebx
retn    10h

loc_D95100:
pop     edi
pop     esi
mov     al, 1
pop     ebx
retn    10h
endp
I hope someone can help me.

Greetings,
hijax.
xUsername is offline  
Old 02/27/2009, 13:06   #2
 
elite*gold: 20
Join Date: Sep 2006
Posts: 1,100
Received Thanks: 184
Looks like a calling convetion problem, you're trying to detour a _stdcall to __cdecl call wich is the default calling convetion used by c++ compilers.
You need to define the calling convetion of your XRevc and XSend correctly, try this:
Code:
int _stdcall XRecv(SOCKET Socket, char *Buffer, int Length, int Flags) {

	return Recv(Socket, Buffer, Length, Flags);
}
int _stdcall XSend(SOCKET Socket, char *Buffer, int Length, int Flags) {

	return Send(Socket, Buffer, Length, Flags);
}
This should fix your problem.
Bot_interesierter is offline  
Old 02/27/2009, 13:13   #3
 
elite*gold: 0
Join Date: Feb 2009
Posts: 172
Received Thanks: 70
This hint wouldn't fix my problem. I always get a game crash.

The log file says:
The reason of a crash is: push esi

This is the 3rd line of the assembler code.
xUsername is offline  
Old 02/27/2009, 13:53   #4
 
elite*gold: 20
Join Date: Sep 2006
Posts: 1,100
Received Thanks: 184
Quote:
Originally Posted by hijax View Post
This hint wouldn't fix my problem. I always get a game crash.

The log file says:
The reason of a crash is: push esi

This is the 3rd line of the assembler code.
Ich sehe gerade an deiner Signatur das du Deutsch sprichst, hast du meinen Vorschlag probiert weil deiner Formulierung im Englischen nach klingt es so als hättest du es nicht getan, das push esi den crash auslöst bedeutet das der StackPointer falsch ist, was vermutlich daran liegt das du eine _stdcall function zu einer _cdecl function umleitest, übrigens brauchst du keine Adressen für revc und send hardcoden wenn du einfach die Winsock2.h includest, dann sind die Funktionen bekannt und mit ihnen die Adressen.
Natürlich muss dann der DetourFunction aufruf anders aussehen und zwar so:
Code:
Recv = (int (__stdcall *)(SOCKET, char *, int, int))DetourFunction((PBYTE)recv, (PBYTE)XRecv);
allerdings würde ich Recv anders nennen, Recv_trampoline oder so wäre ein passenderer Name.
Bot_interesierter is offline  
Old 02/27/2009, 17:06   #5
 
elite*gold: 0
Join Date: Feb 2009
Posts: 172
Received Thanks: 70
Nun ja, soweit funktioniert es.

Jedoch habe ich das Gefühl, dass ich die falsche Packete bekomme.

Denn das Packet für (Bsp.) Login ist nur ein Zeichen: *

Irgendwie nervt's mich.
xUsername is offline  
Old 02/28/2009, 15:39   #6
 
elite*gold: 20
Join Date: Sep 2006
Posts: 1,100
Received Thanks: 184
Quote:
Originally Posted by hijax View Post
Nun ja, soweit funktioniert es.

Jedoch habe ich das Gefühl, dass ich die falsche Packete bekomme.

Denn das Packet für (Bsp.) Login ist nur ein Zeichen: *

Irgendwie nervt's mich.
Wie ließt du denn die Pakete aus?
ich würde das so machen:
Code:
for(int i=0; i<Length; i++){ cout<<buffer[i];} cout<<endl;
Wenn du einfach cout<<buffer; machst dann ist es klar das du nur ein Zeichen bekommst.
Bot_interesierter is offline  
Reply


Similar Threads Similar Threads
[Help]HackShield detected send,recv hook c++
08/17/2010 - C/C++ - 6 Replies
Entschuldigung für noch einen Thread am selben Tag aber das passt glaub ich nicht wirklich in das andere deswegen eröffne ich einen neuen. Wenn ich die Winsock send recv hooke detected das Hackshield nach ca. 2 minuten einen hack kann man das Bypassen ? Und wenn ja,wie sollte ich anfangen. Würde mich freuen auf eine Antwort. Mit freundlichen Grüßen :)
[osds] problem send item & send weapon
11/12/2009 - Dekaron Private Server - 3 Replies
Hello i have 2 problems with osds control panel when i try to send weapon i have no more weapon available i cant choice i have nothing but i can send armor succesfully and my second problem is send item when i try to send item the browser say Login Error, Please login again.anyone can be fix that please? i post screenshots http://panzer.power-heberg.com/itembug.JPG http://panzer.power-heberg.com/noweapon.JPG
Send Recv
08/18/2009 - Kal Online - 0 Replies
Hey;) I start checking this code http://www.elitepvpers.com/forum/kal-hacks-bots-che ats-exploits/189618-release-kalhackzz-v0-3-v0-4-so urces.html but i cant still send a packet of move just to see my player moving.Maybe this code is obsolete i dont know if there are better send and rev codes just tell me When dll process attach happens i call my function _beginthread(f,0,NULL); void f(void* start_parameter){ Console(); //Get the console printf("DLL loaded");
[Question] Hooking send() & recv() works, but recv hiding data for co???
05/06/2009 - CO2 Programming - 2 Replies
Hey guys, I've been making a DLL to allow another program to intercept the packets of conquer using windows pipes. (Then its the job of the main program to decrypt the packets, the DLL only gives a communication channel for the main program) (winsock functions btw) - hooking send() works fine for my internet browser - hooking recv() works fine for my internet browser - hooking send() works fine for conquer online



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


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