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# sharing sockets

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Epila
How do I cheat?
Reputation: 0

Joined: 29 Aug 2010
Posts: 4

PostPosted: Tue Mar 11, 2014 6:35 pm    Post subject: C# sharing sockets Reply with quote

I am creating a game assistant using C# and injecting the code with EasyHook.
Everything is ok, I can inject the code, run and hook API functions with no problems
Two of those hooked functions are send and recv from wsock (wsock32.dll) library. Both are perfectly hooked and working with no known problems.

So what I am trying is to send messages to the server/client.
(client<->Assistant<->server)
I can successfully send messages (and read them, both in/out) to the server using send function and passing the socket handler and the data.
(This socket handle is saved in a IntPtr class on my C# assistant)

But I can't send messages to the client using recv using the same socket handle and the data. When I call the recv function from my C# assistant nothing happens and it return -1 as result

this is what I have from now

Code:
        internal static int SendToClient(byte[] buff)
        {
            //int len = buff . Length;;
            //buff = Huffman . Compress(buff, 0, len, ref len);

            //GCHandle pinned = GCHandle . Alloc(buff, GCHandleType . Pinned);
            //IntPtr address = pinned.AddrOfPinnedObject();

            Marshal . Copy(buff, 0, m_rBuff, buff.Length);

            int r = recv(m_Socket, m_rBuff, buff.Length, m_Flags);
            return r;
        }


recv is the native wsock recv function
buff is the buffer data I want to send to the client
Huffman compress is the compression method used in the communication
r is the return value (always -1, I don't know if it is an error or not)
m_Socket, m_Flags are the socket handler and flags which I extract from the hooked send/recv
m_rBuff is the pointer to the buffer of the receive function, which seems to be the same every time. this is extracted from the hooked recv

thanks
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 190

Joined: 25 Jan 2006
Posts: 8418
Location: 127.0.0.1

PostPosted: Tue Mar 11, 2014 7:26 pm    Post subject: Reply with quote

Use send with the clients socket object. recv will attempt to read data from the socket, not send onto it.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Epila
How do I cheat?
Reputation: 0

Joined: 29 Aug 2010
Posts: 4

PostPosted: Tue Mar 11, 2014 7:43 pm    Post subject: Reply with quote

If I use send, the assistant will send the data to the server, the socket object is the same for both recv and send.
I want to send the data to the client

Code:
        internal static int SendToServer(byte [] buff)
        {
            //send the data to the server. everything is working with no problems here

            GCHandle pinned = GCHandle.Alloc(buff, GCHandleType.Pinned);
            IntPtr address = pinned.AddrOfPinnedObject();

            return send(m_Socket, address, buff.Length, m_rFlags);
        }

        internal static int SendToClient(byte[] buff)
        {
            //send the data to the client. this one is not working
            //m_Socket is the same for both in/out

            int len = buff.Length; ;
            buff = Huffman . Compress(buff, 0, len, ref len);

            //GCHandle pinned = GCHandle.Alloc(buff, GCHandleType.Pinned);
            //IntPtr address = pinned.AddrOfPinnedObject();

            Marshal.Copy(buff, 0, m_rBuff, buff.Length);

            int r = recv(m_Socket, m_rBuff, buff.Length, m_rFlags);
            return r;
        }
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 190

Joined: 25 Jan 2006
Posts: 8418
Location: 127.0.0.1

PostPosted: Wed Mar 12, 2014 2:58 pm    Post subject: Reply with quote

Calling recv from your project is not going to have the result you want.
You are just going to be reading the buffer.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Epila
How do I cheat?
Reputation: 0

Joined: 29 Aug 2010
Posts: 4

PostPosted: Wed Mar 12, 2014 4:17 pm    Post subject: Reply with quote

So, there is anyway I can send the data back to the client?
Convert the WinSock SOCKET back to C# Socket seems to not be possible and proxing the connection is not what I want
Back to top
View user's profile Send private message
Epila
How do I cheat?
Reputation: 0

Joined: 29 Aug 2010
Posts: 4

PostPosted: Sat Apr 19, 2014 3:04 pm    Post subject: Reply with quote

up
Back to top
View user's profile Send private message
shuishan
How do I cheat?
Reputation: 0

Joined: 11 May 2022
Posts: 1

PostPosted: Wed May 11, 2022 1:05 am    Post subject: hook winsock Reply with quote

I have the same problem as you, I can't send data to my client, did you solve this problem?
Back to top
View user's profile Send private message Send e-mail
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