Re: Hooks into PR_Write and PR_Read

[email protected] Sun, 30 Sep 2012 16:56:47 -0700 (PDT)
Newsgroups gmane.comp.mozilla.devel.nspr
Message-ID <[email protected]>
Hi Gregory,

This post looks fairly old, but I try to ask for a hand anyway maybe someone will reply.

I am trying hooking PR_Write and PR_Read too, however my hooks don't work that good with Mozilla's PR_Write and PR_Read.

I am using the code shown at the first section of this link:
http://www.codeproject.com/Articles/30140/API-Hooking-with-MS-Detours

The first example does not use detour. It just shows how to hook a MessageBox.

Can I reuse this code for PR_Write and PR_Read ?

How do I define PR_Write? Is the following the right method?

typedef int (WINAPI *pPr_Write)(HWND, const void *, int);
int WINAPI MyPR_Write(HWND, const void *, int);


Thanks in advance,

- dome







On Monday, December 7, 2009 2:16:32 AM UTC+11, [email protected] wrote:
> Hello, 
> 
> I'm developing an application that will hook into Mozilla Firefox PR_Read and PR_Write, which will be able to tamper requests and responses. Hooking works fine, but I'm having troubles. 
> 
> The hook for PR_Write works in a way that will collect all the output for an request, tamper it and do the real send, using another call to original PR_Write. My problem is that I need to write and read all the data before I return it to Firefox. I know that the sockets are in non-blocking mode, so if I get -1 as return code and last error would block, then I just pause a bit and retry sending or reading, so I return to Firefox only when all the request was sent or all the response was read. 
> 
> Is this the right approach? Because on some websites, I keep getting -1 and would block forever, and I get stuck in my sending or receiving loop. 
> 
> Any help would be greatly appreciated, 
> Thanks.