Microsoft Windows Vista Community Forums - Vistaheads
Recommended Download



Welcome to the Microsoft Windows Vista Community Forums - Vistaheads, YOUR Largest Resource for Windows Vista related information.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so , join our community today!

If you have any problems with the registration process or your account login, please contact us.

Driver Scanner

Asynchronous Pluggable Protocol and http traffic analyzer

microsoft.public.internetexplorer.general






Speedup My PC
Reply
  #1 (permalink)  
Old 08-06-2009
mariom
 

Posts: n/a
Asynchronous Pluggable Protocol and http traffic analyzer
Hi,

I am trying to capture and modify HTML page from Internet Explorer 8 add-on.
I found some sample code (written by Igor Tandetnik) that implements
IInternetProtocol interface on which I based my BHO. This BHO unfortunately
works only partially.

The majority of my code can be found within the implementation of
IInternetProtocol::Read method. My goal was to capture HTML, analyze it,
probably modify it and finally send it back to IE. It means I have to read
the whole HTML page in buffer and after analysis pass it back to IE.

When user navigates on some page, everything works fine. Problem occurs when
user refreshes current page with F5. Then I receive only a small chunk of
HTML. I suspect that problem lies somewhere within my "Read" method
implementation. Here's a description how it works:

a) browser calls my component
b) I receive only a chunk of total HTML which I store to my buffer and
immediately pass "empty" response back to browser to fool him that he's
receiving something (I don't know if this is the best method, but I don'
have any better idea):
*pcbRead = 0;
retResult = S_OK;
c) process is repeated multiple times as described in b) depending on the
size of HTML
d) finally I analyze whole buffer, possibly modify it and send it back to IE

Does anyone has suggestion how to do it better, or has maybe some completely
different approach which would work with F5 also?
Does anybody know how and when InternetProtocolImpl::Read method is called
by IE?

Follows my implementation of Read method:

// IInternetProtocol::Read impl
STDMETHODIMP CInternetProtocolImpl::Read(void *pv, ULONG cb, ULONG *pcbRead)
{
if (m_spInternetProtocol==NULL)
return E_UNEXPECTED;

if ( isHtmlTextMimeType() ) {
HRESULT retResult = S_OK;
HRESULT hr = S_OK;

try {
m_criticalSection.lock();

if (!m_allDataReceived) {
ULONG retCount = 0;
int cbLocal = cb;
// check allocated buffer size
if (cbLocal > m_buffer.size() - m_readPos)
m_buffer.resize(m_readPos + cbLocal, '\0');

hr = m_spInternetProtocol->Read(&m_buffer[m_readPos],
cbLocal, &retCount);

if (hr==S_FALSE)
m_allDataReceived = true;

if (retCount!=0) {
// fix offset (use actually read bytes)
m_readPos += retCount;
}
}

if ( !m_htmlContentUpdated && m_allDataReceived ) {
analyzeHtmlContent(m_buffer);
m_htmlContentUpdated = true;
}

if ( m_htmlContentUpdated && (m_buffer.size()>0) ) {
// all data are sent
if (m_sendPos >= m_readPos) {
m_allDataReceived = false;
m_htmlContentUpdated = false;
m_readPos = 0;
m_sendPos = 0;
m_buffer.clear();
*pcbRead = 0;
retResult = S_FALSE;
} else {
int nrOfBytesForSending = cb;
if ( nrOfBytesForSending > (m_readPos-m_sendPos) )
nrOfBytesForSending = (m_readPos-m_sendPos);

memset(pv, '\0', cb);
memcpy( pv, &m_buffer[m_sendPos], nrOfBytesForSending );
m_sendPos+=nrOfBytesForSending ;

*pcbRead = nrOfBytesForSending ;
retResult = S_OK;
}
} else {
*pcbRead = 0;
retResult = S_OK;
}

m_criticalSection.unlock();
} catch(...) {
m_criticalSection.unlock();
}

return retResult;
} else {
return m_spInternetProtocol->Read(pv, cb, pcbRead);
}
}

Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Asynchronous pluggable protocol navigation fails in Vista IE7 Baker.Travis@gmail.com microsoft.public.windows.vista.general 2 06-25-2008 01:09




All times are GMT +1. The time now is 00:54.




Driver Scanner - Free Scan Now

Vistaheads.com is part of the Heads Network. See also XPHeads.com , Win7Heads.com and Win8Heads.com.


Design by Vjacheslav Trushkin for phpBBStyles.com.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.0 RC 2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120