用vc++穷举windows应用程序密码(续)
2009-04-09 20:04:13 来源:WEB开发网void EnumPasswordString(void)
{ if(!bFetched) return;
//若产生的密码尚未使用,不再产生密码,直接返回退出
bFetched=false;
CString lpszCharSet;
char lpszCurrentPassword[30]="";
CString lpszTmpCurrentPassword;
GetPrivateProfileString("设置","穷举方法","数字",lpszMethod,sizeof(lpszMethod),"Setup.ini");
//得到上一次密码产生的办法,不同的办法定义不同的密码字符集,并得到相应的密码
if(strstr(lpszMethod,"数字")!=NULL)
{lpszCharSet.Format ("%s","0123456789");
GetPrivateProfileString("数字","当前密码","0",(LPTSTR)lpszCurrentPassword,sizeof(lpszCurrentPassword),"Setup.ini");
}
if(strstr(lpszMethod,"小写字母")!=NULL)
{lpszCharSet.Format("%s","abcdefghijklmnopqrstuvwxyz" );
GetPrivateProfileString("小写字母","当前密码","a",(LPTSTR)lpszCurrentPassword,sizeof(lpszCurrentPassword),"Setup.ini");
}
if(strstr(lpszMethod,"大写字母")!=NULL)
{lpszCharSet.Format("%s","ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
GetPrivateProfileString("大写字母","当前密码","A",(LPTSTR)lpszCurrentPassword,sizeof(lpszCurrentPassword),"Setup.ini");
}
if(strstr(lpszMethod, "大小写字母组合")!=NULL)
{lpszCharSet.Format("%s","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") ;
GetPrivateProfileString("大小写字母组合","当前密码","a",(LPTSTR)lpszCurrentPassword,sizeof(lpszCurrentPassword),"Setup.ini");
}
if(strstr(lpszMethod, "数字字母组合")!=NULL)
{lpszCharSet.Format("%s","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") ;
GetPrivateProfileString("数字字母组合","当前密码","0",(LPTSTR)lpszCurrentPassword,sizeof(lpszCurrentPassword),"Setup.ini");
}
if(strstr(lpszMethod, "所有字符")!=NULL)
{ lpszCharSet.Format("%s","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+`-=,./';[]\{}|:"<>?" );
GetPrivateProfileString("所有字符","当前密码","0",(LPTSTR)lpszCurrentPassword,sizeof(lpszCurrentPassword),"Setup.ini");
}
if(strstr(lpszMethod, "数据字典")!=NULL)
{unsigned long nFilePos=GetPrivateProfileInt(lpszPath,"文件指针",0,"Setup.ini");//得到上次取密码的文件指针
CFile m_file;
m_file.Open (lpszPath,0,NULL);
if(nFilePos==m_file.GetLength())
{ m_file.Close ();
m_bEnum=false;
::EnableWindow(::GetDlgItem(m_hwnd,IDOK),TRUE);
::EnableWindow(::GetDlgItem(m_hwnd,IDCANCEL),TRUE);
::EnableWindow(::GetDlgItem(m_hwnd,IDPause),FALSE);
::SetFocus(::GetDlgItem(m_hwnd,IDOK));
return ;
//密码字典已经遍历完毕,停止线程枚举
}
m_file.Seek (nFilePos,0);
int i=0;
for(;;)
{m_file.Read(lpszPassword+i,1);//依次读取密码字符,跳过回车换行符
if ((char)lpszPassword[i]!=0x0d)
{nFilePos++;
i++;
m_file.Seek (nFilePos,0);
continue;
}
else
{ m_file.Close ();
TCHAR lpszFilePos[10];
lpszPassword[i]='';
nFilePos++;
nFilePos++;//进度信息存盘
_stprintf(lpszFilePos,"%d",nFilePos);
WritePrivateProfileString(lpszPath,"文件指针",lpszFilePos,"Setup.ini");
WritePrivateProfileString(lpszPath,"当前穷举密码",lpszPassword,"Setup.ini");
break;
}
}
return;
}
bool bSetOk=false;
lpszTmpCurrentPassword.Format("%s",lpszCurrentPassword);
int nStrLen=lpszTmpCurrentPassword.GetLength ();
int i=nStrLen;
while (i>0)
{
CString CharCode=lpszTmpCurrentPassword.Mid(i-1,1);
if (CharCode!=lpszCharSet.Right(1))
{int nIndex=lpszCharSet.Find(CharCode,0);
CharCode=lpszCharSet.Mid (nIndex+1,1);
if(i!=nStrLen)lpszTmpCurrentPassword.Format("%s%s%s",lpszTmpCurrentPassword.Left(i-1),CharCode,lpszTmpCurrentPassword.Right(nStrLen-i));
else lpszTmpCurrentPassword.Format("%s%s",lpszTmpCurrentPassword.Left(i-1),CharCode);
WritePrivateProfileString(lpszMethod,"当前密码",(LPCTSTR)lpszTmpCurrentPassword,"Setup.ini");
lpszTmpCurrentPassword.Format ("%s",lpszCurrentPassword);
lstrcpy(lpszPassword,lpszTmpCurrentPassword,lpszTmpCurrentPassword.GetLength ()+1);
bSetOk=true;
break;
}
else
{CharCode=lpszCharSet.Left(1);
if(i!=nStrLen)lpszTmpCurrentPassword.Format("%s%s%s",lpszTmpCurrentPassword.Left(i-1),CharCode,lpszTmpCurrentPassword.Right(nStrLen-i));
else lpszTmpCurrentPassword.Format("%s%s",lpszTmpCurrentPassword.Left(i-1),CharCode);
WritePrivateProfileString(lpszMethod,"当前密码",(LPCTSTR)lpszTmpCurrentPassword,"Setup.ini");
i--;
}
}
if(bSetOk)
{
return;
}
lpszTmpCurrentPassword.Insert(0,lpszCharSet.Left(1));
WritePrivateProfileString(lpszMethod,"当前密码",(LPCTSTR)lpszTmpCurrentPassword,"Setup.ini");
lpszTmpCurrentPassword.Format ("%s",lpszCurrentPassword);
lstrcpyn(lpszPassword,lpszTmpCurrentPassword,lpszTmpCurrentPassword.GetLength ()+1);
return;
}
void CGetCodeDlg::OnBrowse()
{CFileDialog m_FileOpen(TRUE,"*.txt","*.txt",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL,NULL);
TCHAR lpBuffer[MAX_PATH];
LPTSTR *lpFilePart=NULL;
GetFullPathName(lpszPath,sizeof(lpBuffer),lpBuffer,lpFilePart);
m_FileOpen.m_ofn.lpstrInitialDir =lpBuffer;
m_FileOpen.DoModal();
m_EditPath.SetWindowText(m_FileOpen.GetPathName());
}
void CGetCodeDlg::OnRadio7()
{ m_EditPath.EnableWindow(TRUE);
m_BtnBrowser.EnableWindow(TRUE);
CheckRadioButton(IDC_RADIO1,IDC_RADIO7,IDC_RADIO7);
}
void CGetCodeDlg::OnRadio1()
{ m_EditPath.EnableWindow(FALSE);
m_BtnBrowser.EnableWindow(FALSE);
CheckRadioButton(IDC_RADIO1,IDC_RADIO7,IDC_RADIO1);
}
void CGetCodeDlg::OnRadio2()
{ m_EditPath.EnableWindow(FALSE);
m_BtnBrowser.EnableWindow(FALSE);
CheckRadioButton(IDC_RADIO1,IDC_RADIO7,IDC_RADIO2);
}
void CGetCodeDlg::OnRadio3()
{ m_EditPath.EnableWindow(FALSE);
m_BtnBrowser.EnableWindow(FALSE);
CheckRadioButton(IDC_RADIO1,IDC_RADIO7,IDC_RADIO3);
}
void CGetCodeDlg::OnRadio4()
{ m_EditPath.EnableWindow(FALSE);
m_BtnBrowser.EnableWindow(FALSE);
CheckRadioButton(IDC_RADIO1,IDC_RADIO7,IDC_RADIO4);
}
void CGetCodeDlg::OnRadio5()
{ m_EditPath.EnableWindow(FALSE);
m_BtnBrowser.EnableWindow(FALSE);
CheckRadioButton(IDC_RADIO1,IDC_RADIO7,IDC_RADIO5);
}
void CGetCodeDlg::OnRadio6()
{ m_EditPath.EnableWindow(FALSE);
m_BtnBrowser.EnableWindow(FALSE);
CheckRadioButton(IDC_RADIO1,IDC_RADIO7,IDC_RADIO6);
}
更多精彩
赞助商链接