Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 20:40

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

Advertisement



C++ Detour Help

Discussion on C++ Detour Help within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Sep 2013
Posts: 3
Received Thanks: 0
C++ Detour Help

Was wondering if someone knows why my return SendTramp crashes exe
Perhaps the (int, int, size_t, int, int) from IDA is incorrect?
Attached Images
File Type: jpg help.jpg (139.2 KB, 72 views)
Clopss is offline  
Old 09/06/2013, 09:31   #2
 
tliu0c's Avatar
 
elite*gold: 0
Join Date: May 2009
Posts: 166
Received Thanks: 518
could be. Follow that function in OD and see where the crash is triggered
tliu0c is offline  
Old 09/06/2013, 10:35   #3
 
Dr. Coxxy's Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
rufst die originalfunktion 2x mit unk2 auf anstatt mit unk2, unk3.

EDIT:
english:
youre calling the origfunction with unk2, unk2 instead of unk2, unk3.
Dr. Coxxy is offline  
Old 09/07/2013, 01:45   #4
 
elite*gold: 0
Join Date: Sep 2013
Posts: 3
Received Thanks: 0
It seems that function only has the opcode for the packet, this is detour of parent function of sendto(),

Code:
int __stdcall SendTramp(char *, int, DWORD*, u_short);
DETOUR_TRAMPOLINE_EMPTY(int __stdcall SendTramp(char *, int, DWORD*, u_short));
int __stdcall SendDetour(char *buf, int len, DWORD* x, u_short hostshort) {
    Logger << TimeToString() << ": Client -> Server (Length: " << len << "  x=" << x << " host=" << hostshort << " )\n\n";
    LogPacket( buf, len );
    Logger << std::endl;
	CHAR szTemp[MAX_STRING] = {0}; 
	sprintf(szTemp, "x:%08x ", x);
	WriteChatColor(szTemp,2,0);
    return 0x10;
	//return SendTramp( buf, len, x, hostshort);
}
I'm using code off some tutorial for detouring the sendto(), but the packets are obfuscated so I switched to parent function. The Tramp once again, doesn't work. How do I go about finding the issue?
Clopss is offline  
Old 09/07/2013, 02:48   #5
 
tliu0c's Avatar
 
elite*gold: 0
Join Date: May 2009
Posts: 166
Received Thanks: 518
seems that you are trying to hook a packet function? You have to clearly describe what you are trying to do and which function is what instead of just giving a chunk of code without context...

Generally tho, when I do my hooks I never use __stdcall for the trampoline function. Because stdcall pops parameters at the end and can corrupt the stack. But then again I am not sure how you are doing your detour so maybe this is not true for you. (Are you using the microsoft detour library?)
tliu0c is offline  
Old 09/07/2013, 03:31   #6
 
elite*gold: 0
Join Date: Sep 2013
Posts: 3
Received Thanks: 0
Heres the function:

Code:
.text:00697660 ; int __stdcall SendToFunc(char *buf, int len, int, u_short hostshort)
.text:00697660 SendToFunc        proc near
.text:00697660
.text:00697660 to              = sockaddr ptr -14h
.text:00697660 var_4           = dword ptr -4
.text:00697660 buf             = dword ptr  4
.text:00697660 len             = dword ptr  8
.text:00697660 arg_8           = dword ptr  0Ch
.text:00697660 hostshort       = word ptr  10h
.text:00697660
.text:00697660                 sub     esp, 14h
.text:00697663                 mov     eax, dword_8BD320
.text:00697668                 mov     edx, dword ptr [esp+14h+hostshort]
.text:0069766C                 mov     [esp+14h+var_4], eax
.text:00697670                 mov     eax, [esp+14h+arg_8]
.text:00697674                 push    esi
.text:00697675                 mov     esi, ecx
.text:00697677                 mov     ecx, [eax]
.text:00697679                 push    edx             ; hostshort
.text:0069767A                 mov     [esp+1Ch+to.sa_family], 2
.text:00697681                 mov     dword ptr [esp+1Ch+to.sa_data+2], ecx
.text:00697685                 call    ds:htons
.text:0069768B                 mov     ecx, [esp+18h+len]
.text:0069768F                 mov     edx, [esp+18h+buf]
.text:00697693                 push    10h             ; tolen
.text:00697695                 mov     word ptr [esp+1Ch+to.sa_data], ax
.text:0069769A                 lea     eax, [esp+1Ch+to]
.text:0069769E                 push    eax             ; to
.text:0069769F                 mov     eax, [esi+4]
.text:006976A2                 push    0               ; flags
.text:006976A4                 push    ecx             ; len
.text:006976A5                 mov     ecx, [eax]
.text:006976A7                 push    edx             ; buf
.text:006976A8                 push    ecx             ; s
.text:006976A9                 call    ds:sendto
.text:006976AF                 mov     ecx, [esp+18h+var_4]
.text:006976B3                 cmp     eax, 0FFFFFFFFh
.text:006976B6                 setnz   al
.text:006976B9                 pop     esi
.text:006976BA                 call    sub_75E9C9
.text:006976BF                 add     esp, 14h
.text:006976C2                 retn    10h
.text:006976C2 SendToFunc        endp
As for detour, I use the one built into Macroquest, AddDetourF:

Code:
#define DetourOffset 0x697660
//#define EzDetour(offset,detour,trampoline) AddDetourf((DWORD)offset,detour,trampoline)
PLUGIN_API VOID InitializePlugin(VOID) {
    Logger.open( "C:\\Packets.txt", std::ios::out | std::ios::app | std::ios::ate );
    if ( Logger.tellp() > 0 ) Logger << "\n\n\n";
    Logger << "##\n## Logging Started (" << NowToString() << ")\n##\n\n\n";

    EzDetour(DetourOffset,SendDetour,SendTramp);
}
Thanks for help, think I should use MS detour instead?
Clopss is offline  
Old 09/07/2013, 06:29   #7
 
Dr. Coxxy's Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
its a thiscall and not a stdcall - dont trust idas reversed calling convention.
Dr. Coxxy is offline  
Old 09/09/2013, 11:31   #8
 
Tr.T!mbo's Avatar
 
elite*gold: 0
Join Date: Sep 2013
Posts: 13
Received Thanks: 0
Remember: If you have something like "retn 10h", it can only be __stdcall or __thiscall. Time ago, there was a nice Video here made by Mr.Sm!th (or so). It was german so I barely understood, but for you this should be fine.
Tr.T!mbo is offline  
Old 09/09/2013, 11:34   #9
 
Dr. Coxxy's Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
Quote:
Originally Posted by Tr.T!mbo View Post
Remember: If you have something like "retn 10h", it can only be __stdcall or __thiscall. Time ago, there was a nice Video here made by Mr.Sm!th (or so). It was german so I barely understood, but for you this should be fine.
depends heavily on the compiler used.
could be fastcall or a custom calling convention as well.
Dr. Coxxy is offline  
Reply


Similar Threads Similar Threads
AU3 Detour UDF - A simple way
05/21/2017 - AutoIt - 30 Replies
Here we go. Example is included If you have any wishes concerning functions, just post here. same with questions! Functions: OpenProcess Returns the Handle of the given Process by Id
C++ Detour & Dll
09/14/2012 - C/C++ - 7 Replies
Ich stehe gerade vor einem mir unerklärlichem Problem. Bis gerade eben dachte ich noch es liegt an meiner Unfähigkeit mit Detorus umzugehen bzw. meinen Reversing Künsten, aber jetzt ist mir aufgefallen, dass es scheinbar gar nicht direkt an den Detour-Funktionen liegt, sondern an meiner Dll. Um das ganze ein bisschen genauer zu beschreiben: Ich wollte endlich mal mit dem Thema Detours anfangen, klingt auch alles soweit logisch und ich glaube auch es verstanden zu haben. Also habe ich mir...
Detour und Rehook?! oder nur Detour?
09/16/2011 - WarRock - 4 Replies
Hallo EPVP' Ich hätte mal ne kleine Frage an die D3D Coder C++. Ich hab schon meinen eigenen Hack gecoded. Nun woltle ich D3D Funcs adden, hab auch den richtigen code. In-Game geht es jedoch NICHT!. Nun wurde mir von jemanden gesagt ich bräuchte eine Detour.
C++ WndProc Detour
07/27/2011 - C/C++ - 4 Replies
Hi, ich will das WndProc von einem fremden Programm Detouren, aber ich weiß nicht wie der Name der WndProc ist... Wie kann ich ihn herausfinden? Also das Programm hat nur ein Fenster sagen wir das Fenster heißt "Test" und ich habe das Handle dazu kann ich jetzt irgendwie den Name der WndProc herausfinden? MFG!



All times are GMT +2. The time now is 20:40.


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.