www.gusucode.com > VC++写的QQ农场辅助源代码及分析资料源码程序 > VC++写的QQ农场辅助源代码及分析资料源码程序\code\qq农场源代码\qq农场源代码\PPJEIN.cpp
// PPJEIN.cpp : implementation file // #include "stdafx.h" #include "SKSGODweb.h" #include "PPJEIN.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //#include "k:\include\lib.h" ///////////////////////////////////////////////////////////////////////////// // CPPJEIN dialog #include <afxmt.h> //一个动态数组添加 uid //访问 uid,添加uid int nNowid=0; //当前已经爬行到,记录当前位置 CStringArray csArrayuser; //存入用户变量的 CCriticalSection ccslok; ////////////////////////////////////////////////////////////////////////// //存在这个用户返回真,不存在返回 0 CIniFile ini; ////////////////////////////////////////////////////////////////////////// // 从这个开始 //http://xiaoyou.qq.com/index.php?mod=profile&u=48a5beee9d1bd4e7895a8a109418dd739a3a22685ae9e508 #define WEB_BASE "http://xiaoyou.qq.com/index.php?mod=profile&u=" //然后加上 id就行了 ///index.php?mod=usershare&act=guestdiv&u=c265e4bd629300c5d2e2ef36c07624f4cd104779f8e4439c #define WEB_NEXT2 "http://api.xiaoyou.qq.com/index.php?mod=usershare&act=" BOOL CPPJEIN::CheckUser(CString user) { if (user.IsEmpty() || user.Find("%")>=0 || user.Find("?")>=0 || user.GetLength() > 100) { return 0; } if (user.GetLength() != 48) { return 0; } CString willadd=""; willadd.Format("%s%s",WEB_BASE,user); ////////////////////////////////////////////////////////////////////////// CString tempuser; int n = csArrayuser.GetSize(); //当前用户数 for (int i=0;i<n;i++) { tempuser = csArrayuser.GetAt(i); if (tempuser == willadd) { return 0; } } ////////////////////////////////////////////////////////////////////////// // m_info.AddString("添加:"+user); //添加这个 csArrayuser.Add(willadd); //添加这个用户 ////////////////////////////////////////////////////////////////////////// //又添加到 ini 文件中 int allnum = ini.GetInt("set","allnum",0); ini.SetString("web",allnum,user); ini.SetInt("set","allnum",allnum + 1); //数量++ return 1; } ////////////////////////////////////////////////////////////////////////// CPPJEIN::CPPJEIN(CWnd* pParent /*=NULL*/) : CDialog(CPPJEIN::IDD, pParent) { //{{AFX_DATA_INIT(CPPJEIN) m_url = _T("http://xiaoyou.qq.com/index.php?mod=profile&u=c265e4bd629300c5d53caeefb960a170f4d8ac36c7b8f574"); //}}AFX_DATA_INIT } void CPPJEIN::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPPJEIN) DDX_Control(pDX, IDC_PROGRESS1, m_du); DDX_Control(pDX, IDC_LIST2_INFO, m_info); DDX_Control(pDX, IDC_LIST1, m_list); DDX_Text(pDX, IDC_EDIT1, m_url); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPPJEIN, CDialog) //{{AFX_MSG_MAP(CPPJEIN) ON_BN_CLICKED(IDC_BUTTON1, Onpp) ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1) ON_BN_CLICKED(IDC_BUTTON2, OnStart) ON_LBN_DBLCLK(IDC_LIST2_INFO, OnDblclkList2Info) ON_LBN_SELCHANGE(IDC_LIST2_INFO, OnSelchangeList2Info) ON_WM_TIMER() ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1) ON_BN_CLICKED(IDC_BUTTON3, OnTestOpen) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPPJEIN message handlers #include <afxsock.h> //网络支持 #include <afxinet.h> #pragma comment (lib,"WININET.LIB ") void CPPJEIN::Onpp() { UpdateData(); GetUrl(m_url); ////////////////////////////////////////////////////////////////////////// } ////////////////////////////////////////////////////////////////////////// void OpenWebToNext(LPCTSTR lpweb) { CString WEB=(CString)lpweb; ////////////////////////////////////////////////////////////////////////// //取得 uid //"mod=profile&u=xxxxxxxxx" int nstat = WEB.Find("&u="); CString csUid = WEB.Right( WEB.GetLength() - nstat - strlen("&u=") ); CString csopenweb = (CString)WEB_NEXT2 + csUid; jein_outinfo("第二次打开: %s",csopenweb); char *buf=new char[3*1024]; jein_gethtml(csopenweb,buf,3*1024); delete buf; } ////////////////////////////////////////////////////////////////////////// //打开一个网站 void CPPJEIN::openweb(LPCTSTR pchar) { char szcurpath[MAX_PATH]; GetCurrentDirectory(MAX_PATH,szcurpath); strcat(szcurpath,"\\Untitled-1.htm"); /* m_web2.Navigate(szcurpath,NULL,NULL,NULL,NULL); m_web2.Navigate(pchar,NULL,NULL,NULL,NULL); m_web2.SetSilent(true); */ } ////////////////////////////////////////////////////////////////////////// BOOL CPPJEIN::GetUrl(CString m_URL) //得到边个 { UpdateData(); m_info.AddString("正在检测:"+m_URL); //当前检查地址 ini.SetString("set","m_url",m_url); //openweb(m_URL); //Sleep(100); CString szURL =m_URL; CString strtemp=""; HINTERNET hInternet, hUrl; char buffer[1024]; DWORD dwBytesRead = 0; DWORD dwBytesWritten = 0; BOOL bIsFirstPacket = true; BOOL bRet = true; int nNowcopyDate =0 ; //当前复制 hInternet = InternetOpen("Mozilla/4.0 (compatible)", INTERNET_OPEN_TYPE_PRECONFIG|INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY, NULL,INTERNET_INVALID_PORT_NUMBER,0); if (hInternet == NULL) { m_list.AddString("internetOpen is Error"); return 0 ; } hUrl = InternetOpenUrl(hInternet, szURL, NULL, 0, INTERNET_FLAG_RELOAD, 0); if (hUrl == NULL) { m_list.AddString("Open Url is error"); return 0; } do { memset(buffer, 0, sizeof(buffer)); InternetReadFile(hUrl, buffer, sizeof(buffer), &dwBytesRead); bIsFirstPacket = false; strtemp=strtemp+(CString)buffer; } while(dwBytesRead > 0); InternetCloseHandle(hUrl); InternetCloseHandle(hInternet); m_list.AddString("检测完成:"+ m_URL ); ////////////////////////////////////////////////////////////////////////// //这里在打开这个 OpenWebToNext(m_URL); ////////////////////////////////////////////////////////////////////////// CString strgj="amp;u="; //要搜索的关键 int statfind=0; while (1) { int nstart = strtemp.Find("amp;u=",statfind); //开始的 int nend = strtemp.Find("\"",nstart+1); if (nstart== -1 || nend== -1) //已经找不到了 { m_list.AddString("检测完成:"+m_URL); strtemp.Empty(); //释放掉空间吧 return 1; } else { CString addstr = strtemp.Mid(nstart+strgj.GetLength(),nend-nstart - strgj.GetLength()); if (addstr.Find("&") >0) { // continue; } else { CheckUser(addstr); // m_info.AddString("网页检测:"+addstr); // jein_outinfo("检查:%s",addstr); // m_list.AddString(addstr); Sleep(100); } statfind=nend+5; } } return 1; } //就从这个人开始吧 //http://xiaoyou.qq.com/index.php?mod=profile&u=48a5beee9d1bd4e723b63a5d6584ec8ce885bd65eec560db //爬行的线程 UINT TstatPP(LPVOID lp) { Sleep(100); CPPJEIN *jein =( CPPJEIN *)lp; static int nxian = 1; CString str; str.Format("运行线程数:%d",nxian++); jein->SetDlgItemText(IDC_STATIC_NUM_XIAN,str); CString nowurl; while (1) { int nallnum = csArrayuser.GetSize(); //当前所有数 if (nNowid == nallnum) //已经到当前了 { Sleep(10); continue; } else { ccslok.Lock(); //这里的锁定回头再加 nNowid++; //默认为 0 ini.SetInt("set","nNowid",nNowid); ccslok.Unlock(); if (csArrayuser.GetSize() <= nNowid-1) { continue; } nowurl = csArrayuser.GetAt(nNowid-1); jein->m_info.AddString("正在访问:"+nowurl); jein->GetUrl(nowurl); Sleep(100); } Sleep(100); } return 1; } void CPPJEIN::OnDblclkList1() { // TODO: Add your control notification handler code here m_list.ResetContent(); } //启动线程 void CPPJEIN::OnStart() { UpdateData(); CString myurl = m_url; // m_list.AddString("开始地址:"+myurl); //要开始的地址 ////////////////////////////////////////////////////////////////////////// GetUrl(myurl); //先进行初化 for (int i=0;i<4;i++) { AfxBeginThread(TstatPP,this); Sleep(200); } } void CPPJEIN::OnDblclkList2Info() { m_info.ResetContent(); } void CPPJEIN::OnSelchangeList2Info() { int n=m_info.GetCurSel(); CString temp; m_info.GetText(n,temp); m_url = temp; UpdateData(false); } void CPPJEIN::OnTimer(UINT nIDEvent) { ////////////////////////////////////////////////////////////////////////// CString str; str.Format("爬行列表数:%d\r\n已经爬行到:%d", csArrayuser.GetSize(),nNowid ); SetDlgItemText(IDC_STATIC_SHOWINFO,str); ////////////////////////////////////////////////////////////////////////// m_list.SendMessage(WM_VSCROLL,SB_BOTTOM); //G m_info.SendMessage(WM_VSCROLL,SB_BOTTOM); if (m_info.GetCount() >150) { m_info.ResetContent(); } if (m_list.GetCount()>150 ) { m_list.ResetContent(); } ////////////////////////////////////////////////////////////////////////// CDialog::OnTimer(nIDEvent); } BOOL CPPJEIN::OnInitDialog() { CDialog::OnInitDialog(); ini.SetFileName("zjein蜘蛛.ini"); if (ini.ReadIniFile()) { ReadIni(); } else { ini.WriteIniFile(); // } SetTimer(1,500,0); //显示当前搜索 ////////////////////////////////////////////////////////////////////////// return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CPPJEIN::OnSelchangeList1() { int n=m_list.GetCurSel(); CString temp; m_list.GetText(n,temp); m_url = temp; UpdateData(false); } ////////////////////////////////////////////////////////////////////////// // Download by http://www.NewXing.com UINT Treadini( LPVOID lp ) { CPPJEIN *jein =(CPPJEIN*)lp; jein->SetWindowText("正在导入数据....请稍等...."); CString str; int allnom = ini.GetInt("set","allnum",0); jein->m_du.SetRange(0,allnom); jein->m_du.SetStep( 1); for (int i=0;i<allnom;i++) { jein->m_du.StepIt(); //增加 str=ini.GetString("web",i,""); if (!str.IsEmpty()) { CString willadd=""; willadd.Format("%s%s",WEB_BASE,str); csArrayuser.Add(willadd); willadd.Empty(); } } jein_outinfo("读取数据:%d",allnom); jein->SetWindowText("数据导入完成"); AfxMessageBox("导入数据成功"); return 1; } ////////////////////////////////////////////////////////////////////////// //读取ini void CPPJEIN::ReadIni() { //读取到 csArrayuser 数组中 //从 0 开始添加 AfxBeginThread(Treadini,this); nNowid = ini.GetInt("set","nNowid",0); ////////////////////////////////////////////////////////////////////////// m_url = ini.GetString("web",nNowid,""); m_url = WEB_BASE+m_url; UpdateData(false); } //写入 ini 文件 void CPPJEIN::WriteIni() { } //test open void CPPJEIN::OnTestOpen() { UpdateData(); char *buffer = new char[30*1024]; DWORD dwBytesRead=0; CString strweb = m_url ; HINTERNET hOpenUrl; HINTERNET hSession = InternetOpen("TT Mozilla/4.0 (compatible)", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); if (hSession) { hOpenUrl = InternetOpenUrl( hSession,strweb, NULL, 0, INTERNET_FLAG_RELOAD, 0 ); } else { AfxMessageBox("internetOpen is error"); return ; } do { InternetReadFile(hOpenUrl, buffer, 512, &dwBytesRead); CStdioFile file; file.Open("1.htm",CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite); file.SeekToEnd(); file.Write(buffer,dwBytesRead); file.Close(); } while(dwBytesRead > 0); InternetCloseHandle( hOpenUrl ); InternetCloseHandle( hSession ); delete buffer; }