Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Hooking SendTo

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Mon Jan 12, 2009 4:27 pm    Post subject: Hooking SendTo Reply with quote

Hi,

I have a few problems. I am trying to hook the ingame SendTo function ( not ws2_32.dll) . This is the function ( IDA pro) :
Code:

 int __cdecl sub_474B1D(SOCKET s,char *buf,int len,int flags,u_long hostlong,__int16);


This is my hook:

Code:

int (__cdecl *SendTo_o)(SOCKET s, char *buf, int len, int flags, unsigned long hostlong,__int16);

int __cdecl SendTo_t(SOCKET s,char *buf,int len,int flags,unsigned long hostlong,__int16)
{
   MessageBoxA(NULL, "SendTO is called!", "info", MB_OK);
   return SendTo_o(SOCKET s, char *buf, int len, int flags, unsigned long hostlong,__int16);
}


SendTo_o = (int (__cdecl *)(SOCKET,char *,int,int,unsigned long,short))DetourFunction((PBYTE)0x00474B1D,(PBYTE)SendTo_t);



Now is my first question:
1. How can i put the bytes that get send, into a .txt file?
You can just read the buf and the bytes are in there i think, but how to log them?

2. I get a compile error: error C2275: 'SOCKET' : illegal use of this type as an expression, cant really figure out how to fix it...
All my other hooks worked.
(I hooked IsDebuggerPresent, GetModuleFileNameA, RPM, for anti anticheat.)
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Mon Jan 12, 2009 4:33 pm    Post subject: Reply with quote

sprintf the bytes into a char buffer.
Back to top
View user's profile Send private message
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Mon Jan 12, 2009 6:42 pm    Post subject: Reply with quote

Add this to the beginning of your header file:
Code:

#include <winsock2.h>


Also, even if you do manage to hook the API, it will crash because you screwed up the calling convention. winsock2.h defines ws2_32.dll APIs as WSAPI.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Jan 12, 2009 10:05 pm    Post subject: Re: Hooking SendTo Reply with quote

blackmorpheus wrote:
Hi,

I have a few problems. I am trying to hook the ingame SendTo function ( not ws2_32.dll) . This is the function ( IDA pro) :
Code:

 int __cdecl sub_474B1D(SOCKET s,char *buf,int len,int flags,u_long hostlong,__int16);


This is my hook:

Code:

int (__cdecl *SendTo_o)(SOCKET s, char *buf, int len, int flags, unsigned long hostlong,__int16);

int __cdecl SendTo_t(SOCKET s,char *buf,int len,int flags,unsigned long hostlong,__int16)
{
   MessageBoxA(NULL, "SendTO is called!", "info", MB_OK);
   return SendTo_o(SOCKET s, char *buf, int len, int flags, unsigned long hostlong,__int16);
}


SendTo_o = (int (__cdecl *)(SOCKET,char *,int,int,unsigned long,short))DetourFunction((PBYTE)0x00474B1D,(PBYTE)SendTo_t);



Now is my first question:
1. How can i put the bytes that get send, into a .txt file?
You can just read the buf and the bytes are in there i think, but how to log them?

2. I get a compile error: error C2275: 'SOCKET' : illegal use of this type as an expression, cant really figure out how to fix it...
All my other hooks worked.
(I hooked IsDebuggerPresent, GetModuleFileNameA, RPM, for anti anticheat.)


just WriteFile buf to a text file.

CreateFile(Create new if not existant)
WriteFile(buf)

_________________
Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Tue Jan 13, 2009 3:52 am    Post subject: Reply with quote

rapion124 wrote:
Add this to the beginning of your header file:
Code:

#include <winsock2.h>


Also, even if you do manage to hook the API, it will crash because you screwed up the calling convention. winsock2.h defines ws2_32.dll APIs as WSAPI.


I told you, it's not a ws2_32.dll function... It's an ingame function.

And if I add winsock2.h , it creates a shitload of errors, all redefinitions from original winsock.h.. Don't know why :O
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Tue Jan 13, 2009 6:12 am    Post subject: Reply with quote

blackmorpheus wrote:
rapion124 wrote:
Add this to the beginning of your header file:
Code:

#include <winsock2.h>


Also, even if you do manage to hook the API, it will crash because you screwed up the calling convention. winsock2.h defines ws2_32.dll APIs as WSAPI.


I told you, it's not a ws2_32.dll function... It's an ingame function.

And if I add winsock2.h , it creates a shitload of errors, all redefinitions from original winsock.h.. Don't know why :O


Is this all of the code where an instance of SOCKET is used?

Also make sure the source is .cpp not .c. apparently it doesn't work as a C file

_________________
Back to top
View user's profile Send private message
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Tue Jan 13, 2009 6:41 am    Post subject: Reply with quote

Put winsock2.h above windows.h in the list.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites