NPView.cpp
上传用户:chenhai826
上传日期:2007-04-11
资源大小:72k
文件大小:5k
- // NPView.cpp : implementation of the CNPView class
- //
- #include "stdafx.h"
- #include "NoPassword.h"
- #include "NPDoc.h"
- #include "NPView.h"
- #include "MonitorThread.h"
- #include "ReportParam.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern HANDLE g_hStopAttack;
- /////////////////////////////////////////////////////////////////////////////
- // CNPView
- IMPLEMENT_DYNCREATE(CNPView, CListView)
- BEGIN_MESSAGE_MAP(CNPView, CListView)
- //{{AFX_MSG_MAP(CNPView)
- ON_COMMAND(IDM_ATTACK, OnAttack)
- ON_COMMAND(IDM_STOP, OnStop)
- ON_UPDATE_COMMAND_UI(IDM_ATTACK, OnUpdateAttack)
- ON_UPDATE_COMMAND_UI(IDM_STOP, OnUpdateStop)
- ON_COMMAND(IDM_STOPDISPLAY, OnStopDisplay)
- ON_UPDATE_COMMAND_UI(IDM_STOPDISPLAY, OnUpdateStopDisplay)
- //}}AFX_MSG_MAP
- ON_MESSAGE(UM_THREAD_REPORT,OnThreadReport)
- ON_MESSAGE(UM_THREADNUM_UPDATE,OnThreadNumUpdate)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CNPView construction/destruction
- CNPView::CNPView()
- {
- // TODO: add construction code here
- m_pMonThread = NULL;
- m_bAttacking = false;
- m_bDisplay = true;
- }
- CNPView::~CNPView()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // CNPView drawing
- void CNPView::OnDraw(CDC* pDC)
- {
- //NoPassword does nothing here.
- }
- void CNPView::OnInitialUpdate()
- {
- CListView::OnInitialUpdate();
- CListCtrl &List = GetListCtrl();
- List.DeleteAllItems();
- while(List.DeleteColumn(0));
- List.InsertColumn(0,"事件",LVCFMT_CENTER,100);
- List.InsertColumn(1,"时刻",LVCFMT_CENTER,100);
- List.InsertColumn(2,"尝试密码",LVCFMT_LEFT,200);
- List.SetTextColor(RGB(0,150,100));
- List.EnableWindow(FALSE);
- KillAllThreads();
- m_pMonThread = new CMonitorThread(this);
- m_pMonThread->CreateThread(CREATE_SUSPENDED);
- ResetEvent(g_hStopAttack);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CNPView diagnostics
- #ifdef _DEBUG
- void CNPView::AssertValid() const
- {
- CListView::AssertValid();
- }
- void CNPView::Dump(CDumpContext& dc) const
- {
- CListView::Dump(dc);
- }
- CNPDoc* CNPView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNPDoc)));
- return (CNPDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CNPView message handlers
- BOOL CNPView::PreCreateWindow(CREATESTRUCT& cs)
- {
- cs.style |= LVS_REPORT;
- return CListView::PreCreateWindow(cs);
- }
- void CNPView::KillAllThreads()
- {
- if(m_pMonThread)
- {
- SetEvent(g_hStopAttack);
- m_pMonThread->ResumeThread();
- m_pMonThread->KillThread();
- m_pMonThread = NULL;
- }
- }
- void CNPView::OnAttack()
- {
- if(!m_bAttacking)
- {
- m_bAttacking = true;
- m_pMonThread->ResumeThread();
- }
- }
- void CNPView::OnStop()
- {
- if(m_bAttacking)
- {
- m_bAttacking = false;
- m_bDisplay = true;
- m_pMonThread->SuspendThread();
- }
- }
- void CNPView::OnUpdateAttack(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_bAttacking);
- }
- void CNPView::OnUpdateStop(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(!m_bAttacking);
- }
- LRESULT CNPView::OnThreadReport(WPARAM num,LPARAM param)
- {
- char buf[50];
- CNPDoc *pDoc = GetDocument();
- CReportParam *pParam = (CReportParam *)param;
- if(m_bDisplay)
- {
- sprintf(buf,"当前有活动线程%d个",num);
- GetParent()->SetWindowText(buf);
- }
- if(pDoc->m_nResult == -1)
- {
- if(m_bDisplay)
- AddString(pParam->nEvent,pParam->password);
- pDoc->SetModifiedFlag();
- }
- if(pParam->nEvent == REPORT_SUCCEED)
- {
- m_pMonThread->SuspendThread();
- m_bAttacking = false;
- pDoc->m_nResult = pParam->password;
- sprintf(buf,"密码已经找到: [%d]",pParam->password);
- MessageBox(buf,"恭喜,恭喜!");
- }
- if(pParam->nEvent == REPORT_CONNECT_ERROR ||
- pParam->nEvent == REPORT_BAD_OTHER)
- {
- InterlockedExchange(&(pDoc->m_nCurrent),pParam->password);
- }
- else
- {
- ((CMainFrame *)GetParent())->UpdateSpeedBarData();
- }
- delete pParam;
- return 0;
- }
- void CNPView::AddString(int nEvent,int password)
- {
- static char *Results[] =
- {
- "连接服务器失败",
- "用户名错误",
- "密码错误",
- "其他错误",
- "匹配密码成功"
- };
- char buf[100];
- CListCtrl &List = GetListCtrl();
- int lines = List.GetCountPerPage();
- while(List.GetItemCount() > max(1,lines - 1))
- List.DeleteItem(0);
- lines = List.GetItemCount();
- ASSERT(nEvent >= 0 && nEvent < 5);
- LVITEM item;
- item.mask = LVIF_TEXT;
- item.iItem = lines;
- item.iSubItem = 0;
- item.pszText = Results[nEvent];
- List.InsertItem(&item);
- strcpy(buf,CTime::GetCurrentTime().Format("%H点%M分%S秒"));
- List.SetItemText(lines,1,buf);
- sprintf(buf,"%d",password);
- List.SetItemText(lines,2,buf);
- }
- LRESULT CNPView::OnThreadNumUpdate(WPARAM num,LPARAM)
- {
- char buf[50];
- if(m_bDisplay)
- {
- sprintf(buf,"当前有活动线程%d个",num);
- GetParent()->SetWindowText(buf);
- }
- return 0;
- }
- void CNPView::OnStopDisplay()
- {
- // TODO: Add your command handler code here
- m_bDisplay = !m_bDisplay;
- }
- void CNPView::OnUpdateStopDisplay(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(!m_bDisplay);
- }