📄 qqdlg.cpp
字号:
// QQDlg.cpp : implementation file
//
#include "stdafx.h"
#include "QQ.h"
#include "QQDlg.h"
#include <atlbase.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString g_strPass;
//BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam );
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CQQDlg dialog
CQQDlg::CQQDlg(CWnd* pParent /*=NULL*/)
: CDialog(CQQDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CQQDlg)
m_strIpMask = _T("192.168.1.");
m_strLogFileName = _T("c:\\qq.txt");
m_strPassword = _T("bosssoft");
m_strQQFile = _T("C:\\Program Files\\Tencent\\QQ.exe");
m_strNowState = _T("……");
m_nIpEnd = 254;
m_nIpStart = 2;
m_bAutoChangeIP = FALSE;
m_strMask = _T("255.255.255.0");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_strNowIP = "";
m_hNextBtnID = NULL;
m_hPreBtnID = NULL;
m_hNavigateWndID = NULL;
m_hQQLoginWndID = NULL;
m_nCurIp = 0;
m_strNCName = _T("");
m_bFirst = TRUE;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CQQDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CQQDlg)
DDX_Control(pDX, IDC_COMBO_NC, m_cbNCSelect);
DDX_Control(pDX, IDC_LIST_LOG, m_lstLog);
DDX_Text(pDX, IDC_EDIT_IPMASK, m_strIpMask);
DDX_Text(pDX, IDC_EDIT_LOGFILE, m_strLogFileName);
DDX_Text(pDX, IDC_EDIT_PASSWORD, m_strPassword);
DDV_MaxChars(pDX, m_strPassword, 16);
DDX_Text(pDX, IDC_EDIT_QQ, m_strQQFile);
DDX_Text(pDX, IDC_EDIT_STATE, m_strNowState);
DDX_Text(pDX, IDC_EDIT_IPEND, m_nIpEnd);
DDV_MinMaxUInt(pDX, m_nIpEnd, 2, 254);
DDX_Text(pDX, IDC_EDIT_IPSTART, m_nIpStart);
DDV_MinMaxUInt(pDX, m_nIpStart, 2, 254);
DDX_Check(pDX, IDC_CHECK_AUTOIP, m_bAutoChangeIP);
DDX_Text(pDX, IDC_EDIT_MASK, m_strMask);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CQQDlg, CDialog)
//{{AFX_MSG_MAP(CQQDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_QQ, OnSelectQqExecute)
ON_BN_CLICKED(IDC_BUTTON_LOGFILE, OnSelectLogfile)
ON_LBN_DBLCLK(IDC_LIST_LOG, OnDblclkListLog)
ON_CBN_SELCHANGE(IDC_COMBO_NC, OnSelchangeComboNc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CQQDlg message handlers
BOOL CQQDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
ListAdapters();
return TRUE; // return TRUE unless you set the focus to a control
}
void CQQDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CQQDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CQQDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CQQDlg::OnOK()
{
// TODO: Add extra validation here
m_bFirst = TRUE;
Run();
if(m_fLogFile.m_hFile != CFile::hFileNull)//如果打开了就关闭
m_fLogFile.Close();
}
void CQQDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
}
BOOL CQQDlg::InitUserInput()//检查用户输入,
{
UpdateData();
if(m_strPassword.GetLength()<6 || m_strPassword.GetLength()>16)
{
AfxMessageBox("请正确输入注册时自动填写的密码6-16位ASCII字符!");
return FALSE;
}
g_strPass = m_strPassword;
CFileStatus rStatus;
if(!CFile::GetStatus(m_strQQFile, rStatus))
{
AfxMessageBox("QQ执行文件没找到,请正确输入文件!");
return FALSE;
}
if(m_bFirst)
{
if(m_fLogFile.m_hFile != CFile::hFileNull)//如果打开了就关闭
m_fLogFile.Close();
CFileException e;
if( !m_fLogFile.Open( m_strLogFileName, CFile::shareDenyWrite | CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate, &e ) )
{
CString str;
str.Format("LOG文件:%s 打不开!", m_strLogFileName);
AfxMessageBox(str);
return FALSE;
}
CString str;
CTime t = CTime::GetCurrentTime();
time_t gmt = t.GetTime();
str.Format("\r\n开始执行,现在时刻:%s\r\n",asctime(gmtime(&gmt)));
AddLog(str);
}
if(m_bAutoChangeIP)
{
if(m_strNCName.GetLength()<1)
{
AfxMessageBox("请正确输入网卡名,我的电脑右键属性看有效网卡名称!");
return FALSE;
}
if(m_nIpStart > m_nIpEnd)
{
UINT nTmp = m_nIpEnd;
m_nIpEnd = m_nIpStart;
m_nIpStart = nTmp;//置换一下
}
if(m_bFirst)
m_nCurIp = m_nIpStart;
}
m_bFirst = FALSE;
return TRUE;
}
void CQQDlg::Run()
{
if(!InitUserInput())
return;
if(!RunQQ())
return;
Delay(10);
JumpLoginWindow();
Delay();
if(!GetWndIDs())
return;
if(!SelectRegType())
return;
Delay();
SendClickMessage(m_hNextBtnID);
Delay();
if(!AutoInputUserData())
return;
PostClickMessage(m_hNextBtnID);
Delay();
ClickOKMessageBox();
Delay();
ClickOKMessageBox();
for(int i=0; i<7; i++)
SendClickMessage(m_hNextBtnID);
int nRe = LoopSubmit();
if(nRe == 1 || nRe == -1)//成功或者IP不允许
{
if(nRe == 1)
AddLog("注册成功,恭喜恭喜。");
else if(nRe == -1)
AddLog("错误:这个IP今天已经注册超标,换IP吧! :)");
//关闭QQ
TerminateProcess(m_piQQ.hProcess, 0);
CloseHandle( m_piQQ.hProcess );
CloseHandle( m_piQQ.hThread );
//重新刷新网卡
if(m_bAutoChangeIP)
{
while(1)
{
if(m_nCurIp<m_nIpEnd)
{
m_nCurIp = m_nCurIp + 1;
int nRes = ChangeStaticIP(m_nCurIp);
if(nRes == 0)//失常不成功
{
return;
}
else if(nRes == 1)//成功
{
// Delay(10);
Run();//继续运行
break;
}
else if(nRes == -1)// 冲突继续
{
continue;
}
}
else
break;
}
}
}
}
BOOL CQQDlg::RunQQ()
{
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &m_piQQ, sizeof(m_piQQ) );
char *pRun = m_strQQFile.GetBuffer(100);
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
pRun, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&m_piQQ // Pointer to PROCESS_INFORMATION structure.
))
{
AfxMessageBox("QQ执行出错!");
m_strQQFile.ReleaseBuffer();
return FALSE;
}
m_strQQFile.ReleaseBuffer();
return TRUE;
}
BOOL CQQDlg::IsFirstRun()
{
while(1)
{
m_hQQLoginWndID = ::FindWindowEx(NULL, NULL, "#32770", "");
CWnd wnd;
wnd.FromHandle(m_hQQLoginWndID);
CString str;
wnd.GetWindowText(str);
AfxMessageBox(str);
if(!m_hQQLoginWndID)
{
AfxMessageBox("QQ登录窗口没找到");
return FALSE;
}
}
AfxMessageBox("找到了");
::SendMessage(m_hQQLoginWndID, WM_CLOSE, NULL, NULL);
return FALSE;
}
BOOL CQQDlg::GetWndIDs()
{
for(int i=0; i<5; i++)//为了保稳期间
{
m_hNavigateWndID = ::FindWindowEx(NULL, NULL, "#32770", " ");
if(m_hNavigateWndID == NULL)
{
Delay(10);//延迟1秒钟
JumpLoginWindow();//在此发送跳过登录框消息
continue;
}
else
break;
}
if(m_hNavigateWndID == NULL)
{
AfxMessageBox("没有找到相关注册窗口0");
return FALSE;
}
m_hNextBtnID = ::FindWindowEx(m_hNavigateWndID, NULL, "Button", "下一步(&N) >");
m_hPreBtnID = ::FindWindowEx(m_hNavigateWndID, NULL, "Button", "< 上一步(&B)");
return TRUE;
}
//选择注册类型
BOOL CQQDlg::SelectRegType()
{
//找到第一页
Delay();
HWND hWnd = ::FindWindowEx(m_hNavigateWndID, NULL, "#32770", " ");
if(!hWnd)
{
AfxMessageBox("没有找到相关注册窗口1");
return FALSE;
}
hWnd = ::FindWindowEx(hWnd, NULL, "Button", "通过QQ注册向导申请");
if(!hWnd)
{
AfxMessageBox("没有找到相关注册窗口2");
return FALSE;
}
SendClickMessage(hWnd);
return TRUE;
}
BOOL CQQDlg::ReadStaticIP()
{
return TRUE;
}
//改变网卡IP
//返回 1 表示成功
// 0 表示失败
// -1 表示有IP冲突
int CQQDlg::ChangeStaticIP(UINT nNum)
{
if(nNum <1 || nNum>254)
{
AddLog("错误:IP地址范围应该在.1 ~ .254");
return 0;
}
CString strCmd;
strCmd.Format("netsh interface ip set address \"%s\" static %s.%d %s", m_strNCName, m_strIpMask, nNum, m_strMask);
LPTSTR pszCmd = (LPTSTR)(LPCTSTR)strCmd;
// CString strLog = "发送指令更改IP地址:";
// strLog += pszCmd;
AddLog(strCmd);
SECURITY_ATTRIBUTES sa;
HANDLE hRead,hWrite;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
if (!CreatePipe(&hRead,&hWrite,&sa,0)) {
AfxMessageBox("Error On CreatePipe()");
return 0;
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdError = hWrite;
si.hStdOutput = hWrite;
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
if (!CreateProcess(NULL,pszCmd,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
{
AddLog("CreateProcess()创建进程失败");
return 0;
}
CloseHandle(hWrite);
char buffer[1024] = {0};
CString strBuf = "";//返回的内容
BOOL bBadIPFlag = FALSE;//IP冲突标志
while (1) {
memset(buffer, 0, sizeof(buffer));
DWORD BytesRead;
DWORD TotalBytes;
DWORD BytesLeft;
if(!PeekNamedPipe(hRead,buffer,sizeof(buffer),&BytesRead,&TotalBytes,&BytesLeft))
break;
if(BytesRead)
{
if(!ReadFile(hRead,buffer,sizeof(buffer)-1,&BytesRead,NULL))
break;
buffer[BytesRead]='\0';
strBuf += buffer;
}
else
{
//find IP冲突的对话框
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -