多语言展示
当前在线:472今日阅读:84今日分享:32

VC++模拟登录CSDN论坛[有验证码]

VC++ 显示网页验证码、模拟CSDN网页登录。
使用工具

Visual C++ 6.0 、HttpWatch or firefox - firebug

步骤/方法
1

程序运行图:

2

数据包截图: (QQ登录时,在密码2222加密时卡壳了,我尝试过很多加密算法,最终以失败告终......)

3

验证码显示使用IStream和IPicture来显示: view plaincopy to clipboardprint? /************************************************************************/  /* 函数说明:获取应用程序当前目录  /* 参 数:无  /* 返 回 值:返回目录路径、CString类型字符串  /* By:Koma 2009.10.13 11:23  /************************************************************************/  CString C***Dlg::GetExePath()  {  char pathbuf[260];  int pathlen = ::GetModuleFileName(NULL,pathbuf,260);  // 替换掉单杠  while(TRUE)  {  if(pathbuf[pathlen--]=='\\')  break;  }  pathbuf[++pathlen]= 0x0;  CString fname = pathbuf;  return fname;  }  /************************************************************************/  /* 函数说明:获取应用程序当前目录  /* 参 数:无  /* 返 回 值:返回目录路径、CString类型字符串  /* By:Koma 2009.10.13 11:23  /************************************************************************/  CString C***Dlg::GetExePath()  {  char pathbuf[260];  int pathlen = ::GetModuleFileName(NULL,pathbuf,260);  // 替换掉单杠  while(TRUE)  {  if(pathbuf[pathlen--]=='\\')  break;  }  pathbuf[++pathlen]= 0x0;  CString fname = pathbuf;  return fname;  } view plaincopy to clipboardprint? /************************************************************************/  /* 函数说明:下载验证码图片  /* 参 数:无  /* 返 回 值:无  /* By:Koma 2009.10.13 11:50  /************************************************************************/  void C***Dlg::DownURLImage()  {  CInternetSession session;  CString strUrl;  CFile *pFile,out;  char buff[512];  CString strPath;  // 产生八位随机数数组成验证码  int nRand1 = rand()%100000+10000;  int nRand2 = rand()%200000+10000;  strUrl.Format('http://passport.csdn.net/ShowExPwd.aspx?temp=%d%d',nRand1,nRand2);  strPath = GetExePath() + '\\test.tmp';  pFile = session.OpenURL(strUrl);  out.Open(strPath, CFile::modeCreate | CFile::modeWrite);  while(pFile->Read(buff,512)){  out.Write(buff,512);  }  out.Flush();  out.Close();  }  /************************************************************************/  /* 函数说明:下载验证码图片  /* 参 数:无  /* 返 回 值:无  /* By:Koma 2009.10.13 11:50  /************************************************************************/  void C***Dlg::DownURLImage() { CInternetSession session; CString strUrl; CFile *pFile,out;  char buff[512]; CString strPath; // 产生八位随机数数组成验证码 int nRand1 = rand()%100000+10000; int nRand2 = rand()%200000+10000; strUrl.Format('http://passport.csdn.net/ShowExPwd.aspx?temp=%d%d',nRand1,nRand2); strPath = GetExePath() + '\\test.tmp'; pFile = session.OpenURL(strUrl);  out.Open(strPath, CFile::modeCreate | CFile::modeWrite);  while(pFile->Read(buff,512)){  out.Write(buff,512);  }  out.Flush(); out.Close();  } view plaincopy to clipboardprint? /************************************************************************/  /* 函数说明:显示验证码图片  /* 参 数:无  /* 返 回 值:无  /* By:Koma 2009.10.13 13:12  /************************************************************************/  void C***Dlg::ShowImage()  {  ::CoInitialize(NULL); // 初始化COM  HRESULT hr;  CFile file;  CString strPath;  CPaintDC dc(this);  strPath = GetExePath() + '\\test.tmp';  file.Open(strPath, CFile::modeRead | CFile::shareDenyNone);  DWORD dwSize = file.GetLength();  HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize );  LPVOID lpBuf = ::GlobalLock( hMem );  file.ReadHuge( lpBuf, dwSize );  file.Close();  ::GlobalUnlock( hMem );  // 由HGLOBAL得到IStream,参数TRUE 表示释放IStream的同时,释放内存  hr = ::CreateStreamOnHGlobal(hMem,TRUE,&pStream );  ASSERT(SUCCEEDED(hr));  hr = ::OleLoadPicture(pStream, dwSize, TRUE, IID_IPicture,(LPVOID *)&pPicture);  ASSERT(hr==S_OK);  long nWidth,nHeight; // 宽高 MM_HIMETRIC模式,单位是0.01毫米  pPicture->get_Width( &nWidth ); // 宽  pPicture->get_Height( &nHeight ); // 高  CSize sz(nWidth,nHeight); // 原大显示  dc.HIMETRICtoDP(&sz); // 转换MM_HIMETRIC模式单位为MM_TEXT像素单位  pPicture->Render(dc.m_hDC,10,100,sz.cx,sz.cy,0,nHeight,nWidth,-nHeight,NULL);  CRect rect(10,100,sz.cx + 10,sz.cy + 100);  // 将图片区域保存,以便后面只刷新图片区域  m_PicRect = rect;  if(pPicture) // 释放IPicture指针  pPicture->Release();  if(pStream) // 释放IStream指针,同时释放hMem  pStream->Release();  ::CoUninitialize();  }  /************************************************************************/  /* 函数说明:显示验证码图片  /* 参 数:无  /* 返 回 值:无  /* By:Koma 2009.10.13 13:12  /************************************************************************/  void C***Dlg::ShowImage() { ::CoInitialize(NULL); // 初始化COM  HRESULT hr;  CFile file; CString strPath; CPaintDC dc(this); strPath = GetExePath() + '\\test.tmp'; file.Open(strPath, CFile::modeRead | CFile::shareDenyNone); DWORD dwSize = file.GetLength();  HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize );  LPVOID lpBuf = ::GlobalLock( hMem ); file.ReadHuge( lpBuf, dwSize );  file.Close();  ::GlobalUnlock( hMem );  // 由HGLOBAL得到IStream,参数TRUE 表示释放IStream的同时,释放内存  hr = ::CreateStreamOnHGlobal(hMem,TRUE,&pStream );  ASSERT(SUCCEEDED(hr));  hr = ::OleLoadPicture(pStream, dwSize, TRUE, IID_IPicture,(LPVOID *)&pPicture);  ASSERT(hr==S_OK);  long nWidth,nHeight; // 宽高 MM_HIMETRIC模式,单位是0.01毫米  pPicture->get_Width( &nWidth ); // 宽  pPicture->get_Height( &nHeight ); // 高 CSize sz(nWidth,nHeight); // 原大显示 dc.HIMETRICtoDP(&sz); // 转换MM_HIMETRIC模式单位为MM_TEXT像素单位  pPicture->Render(dc.m_hDC,10,100,sz.cx,sz.cy,0,nHeight,nWidth,-nHeight,NULL);  CRect rect(10,100,sz.cx + 10,sz.cy + 100); // 将图片区域保存,以便后面只刷新图片区域 m_PicRect = rect; if(pPicture) // 释放IPicture指针 pPicture->Release(); if(pStream) // 释放IStream指针,同时释放hMem pStream->Release(); ::CoUninitialize(); }

转载来源网站

http://www.yunsec.net/a/school/ymbc/C/2009/1021/1133.html

推荐信息