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 


[C++ / asm] getting socket's id?!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Mar 14, 2009 6:59 am    Post subject: [C++ / asm] getting socket's id?! Reply with quote

how would i get the socket's id after i hooked send api?
after i redirected the api call to jump to my code how would i locate where is the socket's id stores?
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sat Mar 14, 2009 7:27 am    Post subject: Re: [C++ / asm] getting socket's id?! Reply with quote

1qaz wrote:
how would i get the socket's id after i hooked send api?
after i redirected the api call to jump to my code how would i locate where is the socket's id stores?


I guess toy could declare a variable. Wait until the client sends a packet. Record the first parameter into the global variable. Now you can send packets with that socket.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Mar 14, 2009 8:02 am    Post subject: Re: [C++ / asm] getting socket's id?! Reply with quote

dnsi0 wrote:
1qaz wrote:
how would i get the socket's id after i hooked send api?
after i redirected the api call to jump to my code how would i locate where is the socket's id stores?


I guess toy could declare a variable. Wait until the client sends a packet. Record the first parameter into the global variable. Now you can send packets with that socket.

and that's my question :]
how would i get the value?
i know it somewhere in the stack but what's the size of each parameter?
Back to top
View user's profile Send private message
Splizes
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Jun 2006
Posts: 1944
Location: Florida

PostPosted: Sat Mar 14, 2009 8:39 am    Post subject: Reply with quote

after you hook it, you'll have your redirected function in that function record your first parameter O.o
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Mar 14, 2009 9:22 am    Post subject: Reply with quote

The stack can only hold dwords and values smaller than dwords, then you can just use this formula:
Code:

Param = [ESP + Param Number*4]

assuming the first parameter is 0 and the second is 1.
Back to top
View user's profile Send private message MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Mar 14, 2009 9:40 am    Post subject: Reply with quote

so index starts from 0 right?
and if i'm pusing ebp register b4 that so it will be located at index 1 is that correct?
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Mar 14, 2009 9:42 am    Post subject: Reply with quote

1qaz wrote:
so index starts from 0 right?
and if i'm pusing ebp register b4 that so it will be located at index 1 is that correct?


yes.
Back to top
View user's profile Send private message MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Mar 14, 2009 9:47 am    Post subject: Reply with quote

well i guess i'm doing something wrong cuz when i load the dll i get some very long number
and i know it's not the socket id since i use a socket sniffer and it shows me something else

here's the code for you
hook function

Code:

__declspec(naked) void HookFunc (void)
{
      push ebp
      mov ebp,esp
      mov eax,[ebp+4] // after pushing ebp then socket's id will be at index 1
      push eax
      call dword ptr ds:[RecordSocketId]
      pop eax
      jmp dword ptr ds:[Address]
}

RecordSocketId is the function that suppose to save the socket's id
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Mar 14, 2009 9:49 am    Post subject: Reply with quote

Zerith wrote:
The stack can only hold dwords and values smaller than dwords, then you can just use this formula:
Code:

Param = [ESP + Param Number*4]

assuming the first parameter is 0 and the second is 1.

Why can't you just do it the C++ way? int mySend( __in SOCKET s....

then make a wrapper then call it.
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Mar 14, 2009 9:54 am    Post subject: Reply with quote

1qaz: and what's RecordSocketId? are we supposed to guess?
S3NS4: Which is equivalent to what i told him to do, what you suggested is clearer though.

Edit: oh yes, i forgot about the return address being pushed to the stack, you need to account that also.
just use S3NS4's way if it gets too tricky.


Last edited by Zerith on Sat Mar 14, 2009 9:59 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Mar 14, 2009 9:59 am    Post subject: Reply with quote

look agian i changed it a bit
Code:

SOCKET SockId;
// RecordSocketId function
void RecordSocketId (void)
{
    SetDlgItemInt(hWnd,TEXT_SOCKET_ID,(int)SockId,FALSE);
}

//Hooking
_declspec(naked) void HookFunc (void)
{
   push ebp
   mov ebp,esp
   push eax
   mov eax,[ebp+4]
   mov dword ptr ds:[SockId],eax
   call dword ptr ds:[RecordSocketId]
   pop eax
   jmp dword ptr ds:[Address]
}


hope that's more clear
edit: oh right the return address was my bad xP
thanks that's great now :>
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Mar 14, 2009 10:02 am    Post subject: Reply with quote

Look at my edited post, and you don't have to push/pop eax, it is used for the return value and will be changed later anyway.
Back to top
View user's profile Send private message MSN Messenger
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Mar 14, 2009 10:08 am    Post subject: Reply with quote

On side note, you can't always use mov eax, [ebp+4]... Some APIs use parameters that are bigger then 4 bytes... Ex-: SendInput with it's INPUT struct. http://msdn.microsoft.com/en-us/library/ms646270(VS.85).aspx

If you want to still use the asm procedure, I suggest using sizeof();
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: Sat Mar 14, 2009 10:11 am    Post subject: Reply with quote

S3NS4 wrote:
On side note, you can't always use mov eax, [ebp+4]... Some APIs use parameters that are bigger then 4 bytes... Ex-: SendInput with it's INPUT struct. http://msdn.microsoft.com/en-us/library/ms646270(VS.85).aspx

If you want to still use the asm procedure, I suggest using sizeof();


Last time i checked, SendInput takes a pointer to the INPUT struct.

Still 4 bytes Wink
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Mar 14, 2009 10:19 am    Post subject: Reply with quote

smartz993 wrote:
S3NS4 wrote:
On side note, you can't always use mov eax, [ebp+4]... Some APIs use parameters that are bigger then 4 bytes... Ex-: SendInput with it's INPUT struct. http://msdn.microsoft.com/en-us/library/ms646270(VS.85).aspx

If you want to still use the asm procedure, I suggest using sizeof();


Last time i checked, SendInput takes a pointer to the INPUT struct.

Still 4 bytes Wink


Didn't know that. But my statement is true; some APIs use parameters that are bigger than 4 bytes.
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
Goto page 1, 2  Next
Page 1 of 2

 
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