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# EasyHook ws2_32.dll WSARecv

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ErrorMaker
Newbie cheater
Reputation: 0

Joined: 25 Jun 2010
Posts: 21

PostPosted: Wed Sep 18, 2013 10:16 am    Post subject: C# EasyHook ws2_32.dll WSARecv Reply with quote

Hello CEF Smile

I'm trying to get all data from WSARecv function of ws2_32.dll using EasyHook (inject into firefox.exe)
I get the data but they look weird, like this:


Data of the hooked send function are ok.

This is my wsarecv hooked function:
Code:
        private static int wsarecv_Hooked(IntPtr socketHandle, ref NativeSocketMethod.WSABuffer buf, int count, IntPtr bytesTransferred, int socketFlags, IntPtr overlapped, IntPtr completionRoutine)
        {
            if (Interface != null)
            {
                int bytesCount = 0;
                try
                {
                    bytesCount = buf.len;
                    if (bytesCount > 0)
                    {
                        byte[] newBuffer = new byte[bytesCount];
                        Marshal.Copy(buf.buf, newBuffer, 0, bytesCount);
                        string s = System.Text.ASCIIEncoding.ASCII.GetString(newBuffer);
                        File.AppendAllText("C:\\hook.txt", "WSARecv: " + "\r\n" + s + "\r\n");
                    }
                }
                catch
                {
                    Interface.LogToScreen("WSARecv error");
                }
            }
            return NativeSocketMethod.WSARecv(socketHandle, ref buf, count, bytesTransferred, socketFlags, overlapped, completionRoutine);
        }


And this is the structure of WSABuffer:
Code:
        [StructLayout(LayoutKind.Sequential)]
        public struct WSABuffer
        {
            internal Int32 len;
            // Length of Buffer
            internal IntPtr buf;
            // Pointer to Buffer
        }


What am I doing wrong?

Thanks in advance
- ErrorMaker
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Wed Sep 18, 2013 5:01 pm    Post subject: Reply with quote

You are reading the buffer before you have received data into that buffer

Also, a secondary problem is that if it's an overlapped recv operation then you must hook(override) the completionroutine, else you will read the buffer before the read is done

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
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