?? mento supplicantdlg.cpp
字號:
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 *)∈
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 + -