-
July 26th, 2012, 03:04 AM
#1
Hooking of function isn't working
Hi,
I'm hooking the send() function (from ws2_32.dll) in a program but once I hook it and make the program use that function, the program crashes. For now I'm doing the DLL injection (DLL that contains the function I want to replace by send() ) into the program and the assembly code to hook the function using a program called Cheat Engine, so I know that's not the problem. This the function I'm replacing for send():
Code:
DLLIMPORT int hsend(SOCKET s, const char *buf, int len, int flags)
{
WSABUF DataBuf;
DWORD Bytes;
DataBuf.len = len;
DataBuf.buf = buf;
WSASend(s, &DataBuf, 1, &Bytes, flags, NULL, NULL);
return len;
}
For test reasons I'm just trying to send the packet without doing anything else. So I'm using WSASend, since send() will be hooked. Is there any problem with this function?
And one last thing... I made a program with sockets and when I tried this it worked, it sent the packet. But in any other program it crashes...
Thanks for your time
-
July 26th, 2012, 03:26 AM
#2
Re: Hooking of function isn't working
Originally Posted by Toshioo
I'm hooking the send() function (from ws2_32.dll) in a program but once I hook it and make the program use that function, the program crashes. ...
And one last thing... I made a program with sockets and when I tried this it worked, it sent the packet. But in any other program it crashes...
Please, define "crashes"
Victor Nijegorodov
-
July 26th, 2012, 04:47 AM
#3
Re: Hooking of function isn't working
Originally Posted by VictorN
Please, define "crashes"
That message from Windows appears, saying "Program x has stopped working". Like this:
-
July 26th, 2012, 04:53 AM
#4
Re: Hooking of function isn't working
And did Windows "check the solution to this problem" in your case?
And did you try to debug your code?
And did you try to find out the address where this problem occurred (for instance in Event Viewer)?
Victor Nijegorodov
-
July 26th, 2012, 11:46 AM
#5
Re: Hooking of function isn't working
Originally Posted by VictorN
And did Windows "check the solution to this problem" in your case?
And did you try to debug your code?
And did you try to find out the address where this problem occurred (for instance in Event Viewer)?
Yes Windows looked for a solution. When it found nothing, I clicked 'Debug' and the debugger I have (Delphi 7's debugger) points to ntdll.DbgBreakPoint, which has the assembly code:
It points specifically to ret.
In event viewer, the EventData shows this:
3085084194
1
APPCRASH
Não disponÃ*vel
0
cookie.exe
0.0.0.0
4ec37c80
cookie.exe
0.0.0.0
4ec37c80
c0000005
00455306
It was a 0xc0000005 exception
Last edited by Toshioo; July 26th, 2012 at 11:55 AM.
-
July 26th, 2012, 12:20 PM
#6
Re: Hooking of function isn't working
Originally Posted by Toshioo
Yes Windows looked for a solution. When it found nothing, I clicked 'Debug' and the debugger I have (Delphi 7's debugger)
Are you using Visual Studio? If so, why didn't the Visual Studio debugger get invoked? Delphi 7 isn't going to help.
Second, we have no idea of the value of the parameters you're calling hsend() with.
Code:
DLLIMPORT int hsend(SOCKET s, const char *buf, int len, int flags)
{
WSABUF DataBuf;
DWORD Bytes;
DataBuf.len = len;
DataBuf.buf = buf;
WSASend(s, &DataBuf, 1, &Bytes, flags, NULL, NULL);
return len;
}
So what does "buf" contain, and does it point to a valid address?
Regards,
Paul McKenzie
-
July 26th, 2012, 12:53 PM
#7
Re: Hooking of function isn't working
Originally Posted by Paul McKenzie
Are you using Visual Studio? If so, why didn't the Visual Studio debugger get invoked? Delphi 7 isn't going to help.
Second, we have no idea of the value of the parameters you're calling hsend() with.
Code:
DLLIMPORT int hsend(SOCKET s, const char *buf, int len, int flags)
{
WSABUF DataBuf;
DWORD Bytes;
DataBuf.len = len;
DataBuf.buf = buf;
WSASend(s, &DataBuf, 1, &Bytes, flags, NULL, NULL);
return len;
}
So what does "buf" contain, and does it point to a valid address?
Regards,
Paul McKenzie
I don't have Visual Studio installed.
Hmm I thought it was up to the application I'm hooking to pass the correct parameters. Since I'm hooking the send() function, and that code is only ran when there is a call to send(), those parameters will be in the stack?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|