偷窥桌面程序和IE浏览器的密码编辑框
2010-05-12 20:35:38 来源:WEB开发网实现细节描述
1、如何从浏览器控件窗口句柄获取IHTMLDocument(参见MSDN KB Q249232——HOWTO: 如何从从HWND获取IHTMLDocument2)
BOOL HWnd2HtmlDocument()
{
CoUninitialize();
HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
if ( hInst == NULL ) return FALSE;
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
::SendMessageTimeout( g_hTarget, nMsg,
0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes );
LPFNOBJECTFROMLRESULT pfObjectFromLresult =
(LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst,
"ObjectFromLresult");
if ( pfObjectFromLresult == NULL )
{
::FreeLibrary( hInst );
CoUninitialize();
return FALSE;
}
WCHAR strDoc[] = L"{626fc520-a41e-11cf-a731-00a0c9082637}";
//IID_IHTMLDocument2 CLSID
CLSID uuidDoc;
HRESULT hrDoc = CLSIDFromString((LPOLESTR)strDoc,
&uuidDoc //IID_IHTMLDocument2
);
if(!SUCCEEDED(hrDoc))
{
::FreeLibrary( hInst );
CoUninitialize();
return FALSE;
}
HRESULT hr = (*pfObjectFromLresult)( lRes, uuidDoc,
//IID_IHTMLDocument,
0, (void**)&g_lpHTMLDocument2);
if ( SUCCEEDED(hr) )
{
//OK, We Get Here Successfully
}
else
{
::FreeLibrary( hInst );
CoUninitialize();
return FALSE;
}
::FreeLibrary( hInst );
CoUninitialize();
return TRUE;
}
在此我需要解释 g_hTarget 是浏览器句柄,其类名是“Internet Explorer_Server”。通常,如果使用MS IE浏览器,不会出现问题,但某些应用使用 Web 浏览器的ActiveX 控件,在浏览器导航之前,“Internet Explorer_Server”窗口是不存在的。如图我们来看一个例子:
更多精彩
赞助商链接