CSDN博客

img TaShin

获取网页中的密码和文本输入框的内容

发表于2003/9/23 23:40:00  1365人阅读

分类: 应用开发

介绍
网页中的密码输入框和一般不同,他没有句柄之类的,但是可以通过IE的IHTMLInputTextElement接口获取!

本文是教你如何得到网页中输入框的内容。如何你想获取网页中的密码,则只要把if (lstrcmpi(strtype, _T("TEXT")) == 0) 改成if

(lstrcmpi(strtype, _T("PASSWORD")) == 0) 就可以了,如果你要是再加个实时监视的话,就成了密码窃取程序了咯!
  
  主要思路:获取IE的IHTMLInputTextElement接口,这样就可以获取网页中的输入框(包括文本和密码输入框)的内容了。
  
  警告:本代码只用作学习和编程测试的使用,严禁用于商业或者非法用途,否则一切后果与本人无关!

  如果要转载,请与作者联系!
  Copyright (C) 2002.  All Rights Reserved.
        



     VARIANT id, index;
     CComPtr<IDispatch> spDispatch;
     CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
     CComQIPtr<IHTMLElement, &IID_IHTMLElement> pElement;
     CComPtr<IHTMLElementCollection> pElementCol;
     CComPtr<IHTMLFormElement> pFormElement;
     CComPtr<IHTMLInputTextElement> pInputElement;

//首先获取IWebBrowser2接口
CoInitialize(NULL);    //必须要这句初始化
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (m_spSHWinds == NULL)
{
    if (m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) != S_OK)
    {
         MessageBox("Failed");
         CoUninitialize();
              
    }
}

if (m_spSHWinds)
         {
              int n = m_spSHWinds->GetCount();
              for (int i = 0; i < n; i++)
              {
               _variant_t v = (long)i;
               IDispatchPtr spDisp = m_spSHWinds->Item(v);

               SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);   //生成一个IE窗口的智能指针
                     if (spBrowser)
                 {
//获取IHTMLDocument2接口
if (SUCCEEDED(spBrowser->get_Document( &spDispatch)))
               pDoc2 = spDispatch;
                if(pDoc2!=NULL)
                {
    //    AfxMessageBox("已经获取IHTMLDocument2");
    if (SUCCEEDED(pDoc2->get_forms(&pElementCol)))
    {
    //    AfxMessageBox("已经获取IHTMLElementCollection");
                long p=0;
        if(SUCCEEDED(pElementCol->get_length(&p)));
                 if(p!=0)
         {  

        for(long i=0;i<=(p-1);i++)
        {

                      V_VT(&id) = VT_I4;
                      V_I4(&id) = i;
                      V_VT(&index) = VT_I4;
                      V_I4(&index) = 0;

        if(SUCCEEDED(pElementCol->item(id,index, &spDispatch)))
                                          

if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLFormElement,(void**)&pFormElement)))
    {
    // AfxMessageBox("已经获取IHTMLFormElement");
    long q=0;
     if(SUCCEEDED(pFormElement->get_length(&q)));
    for(long j=0;j<=(q-1);j++)
    {
                V_VT(&id) = VT_I4;
                            V_I4(&id) = j;
                            V_VT(&index) = VT_I4;
                            V_I4(&index) = 0;
                           if(SUCCEEDED(pFormElement->item(id,index, &spDispatch)))

                          

if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLInputTextElement,(void**)&pInputElement)))
         {
            //AfxMessageBox("已经获取IHTMLInputTextElement");
                           CComBSTR value;
               CComBSTR type;
               pInputElement->get_type(&type);//获取输入框类型(密码框还是文本框)
                          
                           CString strtype(type);
                           strtype.MakeUpper();
            if (lstrcmpi(strtype, _T("TEXT")) == 0)
            {
            pInputElement->get_value(&value);//获取文本框的值
            CString strvalue(value);
            AfxMessageBox(strvalue);
                           }
                         }
                    }
                }
            }
         }
                
}

   注意:具体细节请看原始代码!最好不要向作者要技术支持!谢谢阅

读!  TanXin79@163.net,文章的源代码:

http://www.vchelp.net/ASP/ibr_upload/791.rar

0 0

相关博文

我的热门文章

img
取 消
img