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

📄 mento supplicantdlg.cpp

📁 一个非常漂亮的802.1x客户端源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void CMentoSupplicantDlg::OnCallShellIcon() 
{
	UpdateData();
	if ( m_iCallWay == 0 )
		m_HotKey.EnableWindow( false );
	else
		m_HotKey.EnableWindow( true );
}

void CMentoSupplicantDlg::OnSetShellIconState(int ICurrentState)
{
	SetShellIconState( ICurrentState );
}

void CMentoSupplicantDlg::OnSelchangeNicSelected() 
{
	int iTemp=0,iCurSel;
	NIC_Device *pTemp;

	m_bNICInitSign=false;

	pTemp = m_pNICs;
	iCurSel = m_NIC_Select.GetCurSel();
	while ( pTemp && iTemp<iCurSel )
	{
		iTemp++;
		pTemp = pTemp->m_pNext;
	}
	m_pCurrentNIC = pTemp;
	m_sNICIP = pTemp->m_sIP;
}

void CMentoSupplicantDlg::OnStartupConnect() 
{
	LPCTSTR	lpSubKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
	LONG	kResult;
	HKEY kLocalMachine;
	char sCurrentDir[1024];
	LPBYTE sBytePath=NULL;

	WriteDebugInfo("StartupConnect"," >> Step 0");
	UpdateData();
	WriteDebugInfo("StartupConnect"," >> Step 1");
	if ( m_bStartupConnect )
	{
		//写注册表键值
		memset( sCurrentDir, '\0', 1024 );
		sCurrentDir[0] = '\"';
		GetCurrentDirectory( 1024, (char*)(sCurrentDir+1) );
		strcat( sCurrentDir, "\\Mento Supplicant.exe\" -StartupConnect");
		kResult = ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, lpSubKey, NULL,
			KEY_ALL_ACCESS, &kLocalMachine);
		if(kResult != ERROR_SUCCESS)
		{
			DWORD dwTemp = GetLastError();
			m_bStartupConnect = false;
			if ( dwTemp != 0 )	//这才是真的出错,否则是没有找到键值
			{
				LPVOID lpMsgBuf;
				FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
					NULL, dwTemp, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
					(LPTSTR) &lpMsgBuf, 0, NULL );
				PrintOutput( (const char*)lpMsgBuf ," ** 打开注册表项错误", true );
			}
			return;
		}
		WriteDebugInfo("StartupConnect"," >> Step 1a");
		int iLenTemp = strlen(sCurrentDir);
		kResult = ::RegSetValueEx( kLocalMachine, sStartupConnectKeyName, NULL, REG_SZ, 
			(unsigned char*)sCurrentDir, iLenTemp+1 );
		if(kResult != ERROR_SUCCESS)
		{
			DWORD dwTemp = GetLastError();
			m_bStartupConnect = false;
			if ( dwTemp != 0 )	//这才是真的出错,否则是没有找到键值
			{
				LPVOID lpMsgBuf;
				FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
					NULL, dwTemp, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
					(LPTSTR) &lpMsgBuf, 0, NULL );
				PrintOutput( (const char*)lpMsgBuf ," ** 写入注册表项错误", true );
			}
			return;
		}
		::RegCloseKey(kLocalMachine);
		WriteDebugInfo("StartupConnect"," >> Step 1b");
	}
	else
	{
		WriteDebugInfo("StartupConnect"," >> Step 2a");
		//删除注册表键值
		char sMentoSupplicantSubKey[100];
		strcpy( sMentoSupplicantSubKey, lpSubKey );
		strcat( sMentoSupplicantSubKey, "\\");
		strcat( sMentoSupplicantSubKey, sStartupConnectKeyName );
		kResult = ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, lpSubKey, NULL,
			KEY_WRITE, &kLocalMachine);
		if(kResult != ERROR_SUCCESS)
		{
			DWORD dwTemp = GetLastError();
			m_bStartupConnect = false;
			if ( dwTemp != 0 )	//这才是真的出错,否则是没有找到键值
			{
				LPVOID lpMsgBuf;
				FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
					NULL, dwTemp, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
					(LPTSTR) &lpMsgBuf, 0, NULL );
				PrintOutput( (const char*)lpMsgBuf ," ** 打开注册表项错误", true );
			}
			return;
		}
		WriteDebugInfo("StartupConnect"," >> Step 2b");
		kResult = ::RegDeleteValue( kLocalMachine, sStartupConnectKeyName );
		if(kResult != ERROR_SUCCESS)
		{
			DWORD dwTemp = GetLastError();
			m_bStartupConnect = false;
			LPVOID lpMsgBuf;
			FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL, dwTemp, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
				(LPTSTR) &lpMsgBuf, 0, NULL );
			PrintOutput( (const char*)lpMsgBuf ," ** 删除注册表项错误", true );
		}
		::RegCloseKey(kLocalMachine);
	}
	WriteDebugInfo("StartupConnect"," >> Step 3");
}

//转换ip的函数
char *iptos(u_long in, byte BIP[4])
{
    static char output[IPTOSBUFFERS][3*4+3+1];
    static short which;
    u_char *p;
	
    p = (u_char *)&in;
    which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);
	BIP[0] = p[0] ;
	BIP[1] = p[1] ;
	BIP[2] = p[2] ;
	BIP[3] = p[3] ;
    sprintf(output[which], "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
    return output[which];
}

// 计算md5摘要的函数,计算过程在头文件md5.h里,ref RFC1321
byte * ComputeHash(byte * src,int i)
{
	MD5_CTX context;
	static unsigned char digest[16];
	MD5Init(&context);
	MD5Update(&context, src, i);
	MD5Final(digest, &context);
	return digest;
}

void CMentoSupplicantDlg::SaveSettings()
{
	// TODO: Add your message handler code here	
	CString ssMainSection = "MainSection";			//认证资料
	CString ssName = "Name";
	CString ssPassword = "Password";
	CString ssDefaultNIC = "DefaultNIC";
	CString ssCertSection = "CertSection";			//认证选项
	CString ssCertMode = "CertMode";
	CString ssEchoMode = "SelfEchoMode";
	CString ssEchoInterval = "EchoInterval";
	CString ssRunSection = "RunSection";			//运行选项
	CString ssConnectionMinimize = "ConnectionMinimize";
	CString ssAutoConnect = "AutoConnect";
	CString ssStartupConnect = "StartupConnect";
	CString ssCallSection = "CallSection";			//激活选项
	CString ssCallWay = "CallWay";
	CString ssHotKey = "HotKey";
	CString ssIntelligentSection = "Intelligente";	//智能选项
	CString ssIntelligentReconnect = "IntelligentReconnect";
	CString ssArtificalAddressSection="HidenSection"; //伪造地址
	CString ssArtificalAddress="IPAddress";
	CString ssArtificalAddressEnableSection="ArtificalAddressEnableSection";
	CString ssArtificalAddressEnable="ArtificalAddressEnable";

	DWORD dwHotKey;
	int iHotKeyLen = 4;

	WriteDebugInfo("SaveSettings"," >> Step 1");
	UpdateData();
	WriteDebugInfo("SaveSettings"," >> Step 2");
	//用户名和密码
	AfxGetApp()->WriteProfileString( ssMainSection, ssName, m_sName );
	AfxGetApp()->WriteProfileString( ssMainSection, ssPassword, m_sPassword );
	if ( m_pCurrentNIC )
		AfxGetApp()->WriteProfileString( ssMainSection, ssDefaultNIC, m_sNICIP );
	//是哪种认证模式:0:标准 1:实达
	AfxGetApp()->WriteProfileInt( ssCertSection, ssCertMode, m_iSelectedMode );
	AfxGetApp()->WriteProfileInt( ssCertSection, ssEchoMode, m_bSelfIntervalCheck );
	AfxGetApp()->WriteProfileInt( ssCertSection, ssEchoInterval, m_iSelfInterval );
	//连接自动最小化
	AfxGetApp()->WriteProfileInt( ssRunSection, ssPassword, m_bConnectMinimize );
	//认证自动连接
	AfxGetApp()->WriteProfileInt( ssRunSection, ssCertMode, m_bAutoConnectCheck );
	//开机自动连接
	//AfxGetApp()->GetProfileInt( ssRunSection, ssCertMode, m_bStartupConnect );
	//是哪种呼出方式:0:系统栏 1:热键
	//写入伪造地址
	
	AfxGetApp()->WriteProfileString( ssArtificalAddressSection, ssArtificalAddress, m_IP_set);
	AfxGetApp()->WriteProfileInt(ssArtificalAddressEnableSection,ssArtificalAddressEnable,m_bArtificalAddressEnable);

	AfxGetApp()->WriteProfileInt( ssCallSection, ssCallWay, m_iCallWay );
	AfxGetApp()->WriteProfileInt( ssIntelligentSection, ssIntelligentReconnect, m_bIntelligentReconnect );
	
	m_HotKey.GetHotKey( m_wVirtualKey, m_wKeyModifier );
	dwHotKey = (((DWORD)m_wKeyModifier)<<16) + (DWORD)m_wVirtualKey;
	AfxGetApp()->WriteProfileBinary( ssCallSection, ssHotKey, 
		(unsigned char*)&dwHotKey, iHotKeyLen);
	WriteDebugInfo("SaveSettings"," >> Step 3");
}

void CMentoSupplicantDlg::OnEchoInterval() 
{
	UpdateData();
	GetDlgItem( IDC_ECHOINTERVAL )->EnableWindow(m_bSelfIntervalCheck);
}

void CMentoSupplicantDlg::ProcessHidenArgs()
{
	unsigned short int i1,i2,i3,i4;
    CheckAndSetButtonStatus();
   if(m_bArtificalAddressEnable)
   {
	if ( m_IP_set.GetLength() > 0 )
	{
		sscanf ( m_IP_set.GetBuffer(m_IP_set.GetLength()), "%d.%d.%d.%d", &i1,&i2,&i3,&i4 );
		m_IP[0] = (byte) i1;
		m_IP[1] = (byte) i2;
		m_IP[2] = (byte) i3;
		m_IP[3] = (byte) i4;
	}
	if ( m_NetGate_set.GetLength() > 0 )
	{
		sscanf ( m_NetGate_set.GetBuffer(m_NetGate_set.GetLength()), "%d.%d.%d.%d", &i1,&i2,&i3,&i4 );
		m_NetGate[0] = (byte) i1;
		m_NetGate[1] = (byte) i2;
		m_NetGate[2] = (byte) i3;
		m_NetGate[3] = (byte) i4;
	}
	if ( m_NetMask_set.GetLength() > 0 )
	{
		sscanf ( m_NetMask_set.GetBuffer(m_NetMask_set.GetLength()), "%d.%d.%d.%d", &i1,&i2,&i3,&i4 );
		m_NetMask[0] = (byte) i1;
		m_NetMask[1] = (byte) i2;
		m_NetMask[2] = (byte) i3;
		m_NetMask[3] = (byte) i4;
	}
	if ( m_DNS1_set.GetLength() > 0 )
	{
		sscanf ( m_DNS1_set.GetBuffer(m_DNS1_set.GetLength()), "%d.%d.%d.%d", &i1,&i2,&i3,&i4 );
		m_DNS1[0] = (byte) i1;
		m_DNS1[1] = (byte) i2;
		m_DNS1[2] = (byte) i3;
		m_DNS1[3] = (byte) i4;
	}
   }
}

void CMentoSupplicantDlg::DoStartCert()
{
	if ( m_pCurrentNIC == NULL )
	{
		PrintOutput( "请确认你装有具有外网网址的网卡"," ** 没有合适的网卡",true);
		return;
	}
	SwitchSystemState( IDT_FIND_SERVER );
	if ( m_pMainCertThread == NULL )
		m_pMainCertThread = AfxBeginThread( (AFX_THREADPROC)MainCertThread, this, THREAD_PRIORITY_TIME_CRITICAL );
	else
		SendPackage();

	if ( m_pPingThread == NULL && m_bIntelligentReconnect )
		m_pPingThread = AfxBeginThread( (AFX_THREADPROC)JudgeNetState, this );
}

void CMentoSupplicantDlg::WriteDebugInfo(CString SOption, CString SContent)
{
	if ( m_DebugMode_set )
		AfxGetApp()->WriteProfileString( "DebugInfo", SOption , SContent );
}

bool CMentoSupplicantDlg::InitCertParamater()
{
	CString ssMainSection = "MainSection";			//认证资料
	CString ssName = "Name";
	CString ssPassword = "Password";
	CString ssDefaultNIC = "DefaultNIC";
	CString ssCertSection = "CertSection";			//认证选项
	CString ssCertMode = "CertMode";
	CString ssEchoMode = "SelfEchoMode";
	CString ssEchoInterval = "EchoInterval";
	CString ssRunSection = "RunSection";			//运行选项
	CString ssAutoConnect = "AutoConnect";
	CString ssConnectionMinimize = "ConnectionMinimize";
	CString ssStartupConnect = "StartupConnect";
	CString ssCallSection = "CallSection";			//激活选项
	CString ssCallWay = "CallWay";
	CString ssHotKey = "HotKey";
	CString ssIntelligentSection = "Intelligente";	//智能选项
	CString ssIntelligentReconnect = "IntelligentReconnect";
	CString ssHidenSection = "HidenSection";//隐藏选项,用于指定IP等
	CString ssDebugMode_set = "DebugMode";		//调试选项
	CString ssIP_set = "IPAddress";
	CString ssNetGage_set = "NetGage";
	CString ssNetMask_set = "NetMask";
	CString ssDNS_set = "DNS";
	CString ssArtificalAddressEnableSection="ArtificalAddressEnableSection";
	CString ssArtificalAddressEnable="ArtificalAddressEnable";


	m_uKey.ulValue = 0;					//密钥值
	m_uSerialNo.ulValue = 0x1000002a;	//序列号值
	m_iState = IDT_DISCONNECT;			//初始认证状态
	CheckAndSetButtonStatus();

	CMentoSupplicantApp *pApp = (CMentoSupplicantApp*)AfxGetApp();

	LPBYTE dwHotKey = NULL;
	unsigned int iHotKeyLen = 4;

	m_pPingThread = NULL;
	m_pMainCertThread = NULL;

	WriteDebugInfo("InitCertP"," >> Step 0");

	//处理调试模式
	m_DebugMode_set = AfxGetApp()->GetProfileInt( ssMainSection, ssDebugMode_set, 0 );

	//用户名和密码
	m_sName = AfxGetApp()->GetProfileString( ssMainSection, ssName, "guest" );
	m_sPassword = AfxGetApp()->GetProfileString( ssMainSection, ssPassword, "guest" );
	m_sNICIP = AfxGetApp()->GetProfileString( ssMainSection, ssDefaultNIC, "" );
	 m_IP_set=AfxGetApp()->GetProfileString( ssHidenSection, ssIP_set,"" );
	 m_bArtificalAddressEnable=AfxGetApp()->GetProfileInt(ssArtificalAddressEnableSection,ssArtificalAddressEnable,0);
	//判断网卡
	NIC_Device *pTemp = m_pNICs;
	int iSerialNo=0;
	
	while ( pTemp != NULL )
	{
		if ( pTemp->m_sIP.Compare( m_sNICIP ) == 0 )
		{
			m_NIC_Select.SetCurSel ( iSerialNo );
			m_pCurrentNIC = pTemp;
			m_sNICIP = pTemp->m_sIP;
			break;
		}
		
		iSerialNo++;
		pTemp = pTemp->m_pNext;
	}

	//是哪种认证模式:0:标准 1:实达
	m_iSelectedMode = AfxGetApp()->GetProfileInt( ssCertSection, ssCertMode, 0 );
	m_bSelfIntervalCheck = AfxGetApp()->GetProfileInt( ssCertSection, ssEchoMode, 0 );
	GetDlgItem( IDC_ECHOINTERVAL )->EnableWindow( m_bSelfIntervalCheck );
	m_iSelfInterval = AfxGetApp()->GetProfileInt( ssCertSection, ssEchoInterval, 5000 );

	//连接自动最小化
	m_bConnectMinimize = AfxGetApp()->GetProfileInt( ssRunSection, ssPassword, 0 );

	//运行自动连接
	m_bAutoConnectCheck = AfxGetApp()->GetProfileInt( ssRunSection, ssCertMode, 0 );
	//开机自动连接
	//m_bStartupConnect = AfxGetApp()->GetProfileInt( ssRunSection, ssCertMode, 0 );

	WriteDebugInfo("InitCertP"," >> Step 1");

	LPCTSTR	lpSubKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
	LONG kResult;
	DWORD dwType=REG_SZ;
	HKEY kLocalMachine;
	kResult = ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, lpSubKey, NULL,
		KEY_ALL_ACCESS, &kLocalMachine);
	if(kResult != ERROR_SUCCESS)
	{
		DWORD dwTemp = GetLastError();
		m_bStartupConnect = false;
		if ( dwTemp != 0 )	//这才是真的出错,否则是没有找到键值
		{
			LPVOID lpMsgBuf;
			FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL, dwTemp, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
				(LPTSTR) &lpMsgBuf, 0, NULL );
			PrintOutput( (const char*)lpMsgBuf , " ** 打开注册表项错误", true );
//			return false;
		}
	}

	WriteDebugInfo("InitCertP"," >> Step 2");

	kResult = ::RegQueryValueEx( kLocalMachine, sStartupConnectKeyName, NULL, &dwType, 
		NULL, NULL);
	if(kResult != ERROR_SUCCESS)
	{
		DWORD dwTemp = GetLastError();
		m_bStartupConnect = false;
		if ( dwTemp != 0 )	//这才是真的出错,否则是没有找到键值
		{
			LPVOID lpMsgBuf;
			FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL, dwTemp, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
				(LPTSTR) &lpMsgBuf, 0, NULL );
			PrintOutput( (const char*)lpMsgBuf, " ** 查找开机自动运行信息错误", true );
			//return false;
		}
	}
	else
		m_bStartupConnect = true;
	::RegCloseKey(kLocalMachine);

	WriteDebugInfo("InitCertP"," >> Step 3");

	//是哪种呼出方式:0:系统栏 1:热键
	m_iCallWay = AfxGetApp()->GetProfileInt( ssCallSection, ssCallWay, 0 );
	AfxGetApp()->GetProfileBinary( ssCallSection, ssHotKey, &dwHotKey, &iHotKeyLen);

⌨️ 快捷键说明

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