View previous topic :: View next topic |
Author |
Message |
Epila How do I cheat? Reputation: 0
Joined: 29 Aug 2010 Posts: 4
|
Posted: Tue Mar 11, 2014 6:35 pm Post subject: C# sharing sockets |
|
|
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 |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Tue Mar 11, 2014 7:26 pm Post subject: |
|
|
Use send with the clients socket object. recv will attempt to read data from the socket, not send onto it.
_________________
- Retired. |
|
Back to top |
|
|
Epila How do I cheat? Reputation: 0
Joined: 29 Aug 2010 Posts: 4
|
Posted: Tue Mar 11, 2014 7:43 pm Post subject: |
|
|
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 |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Wed Mar 12, 2014 2:58 pm Post subject: |
|
|
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 |
|
|
Epila How do I cheat? Reputation: 0
Joined: 29 Aug 2010 Posts: 4
|
Posted: Wed Mar 12, 2014 4:17 pm Post subject: |
|
|
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 |
|
|
Epila How do I cheat? Reputation: 0
Joined: 29 Aug 2010 Posts: 4
|
Posted: Sat Apr 19, 2014 3:04 pm Post subject: |
|
|
up
|
|
Back to top |
|
|
shuishan How do I cheat? Reputation: 0
Joined: 11 May 2022 Posts: 1
|
Posted: Wed May 11, 2022 1:05 am Post subject: hook winsock |
|
|
I have the same problem as you, I can't send data to my client, did you solve this problem?
|
|
Back to top |
|
|
|