NPView.cpp
上传用户:chenhai826
上传日期:2007-04-11
资源大小:72k
文件大小:5k
源码类别:

破解

开发平台:

Visual C++

  1. // NPView.cpp : implementation of the CNPView class
  2. //
  3. #include "stdafx.h"
  4. #include "NoPassword.h"
  5. #include "NPDoc.h"
  6. #include "NPView.h"
  7. #include "MonitorThread.h"
  8. #include "ReportParam.h"
  9. #include "MainFrm.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. extern HANDLE g_hStopAttack;
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CNPView
  18. IMPLEMENT_DYNCREATE(CNPView, CListView)
  19. BEGIN_MESSAGE_MAP(CNPView, CListView)
  20. //{{AFX_MSG_MAP(CNPView)
  21. ON_COMMAND(IDM_ATTACK, OnAttack)
  22. ON_COMMAND(IDM_STOP, OnStop)
  23. ON_UPDATE_COMMAND_UI(IDM_ATTACK, OnUpdateAttack)
  24. ON_UPDATE_COMMAND_UI(IDM_STOP, OnUpdateStop)
  25. ON_COMMAND(IDM_STOPDISPLAY, OnStopDisplay)
  26. ON_UPDATE_COMMAND_UI(IDM_STOPDISPLAY, OnUpdateStopDisplay)
  27. //}}AFX_MSG_MAP
  28. ON_MESSAGE(UM_THREAD_REPORT,OnThreadReport)
  29. ON_MESSAGE(UM_THREADNUM_UPDATE,OnThreadNumUpdate)
  30. END_MESSAGE_MAP()
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CNPView construction/destruction
  33. CNPView::CNPView()
  34. {
  35. // TODO: add construction code here
  36. m_pMonThread = NULL;
  37. m_bAttacking = false;
  38. m_bDisplay = true;
  39. }
  40. CNPView::~CNPView()
  41. {
  42. }
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CNPView drawing
  45. void CNPView::OnDraw(CDC* pDC)
  46. {
  47. //NoPassword does nothing here.
  48. }
  49. void CNPView::OnInitialUpdate()
  50. {
  51. CListView::OnInitialUpdate();
  52. CListCtrl &List = GetListCtrl();
  53. List.DeleteAllItems();
  54. while(List.DeleteColumn(0));
  55. List.InsertColumn(0,"事件",LVCFMT_CENTER,100);
  56. List.InsertColumn(1,"时刻",LVCFMT_CENTER,100);
  57. List.InsertColumn(2,"尝试密码",LVCFMT_LEFT,200);
  58. List.SetTextColor(RGB(0,150,100));
  59. List.EnableWindow(FALSE);
  60. KillAllThreads();
  61. m_pMonThread = new CMonitorThread(this);
  62. m_pMonThread->CreateThread(CREATE_SUSPENDED);
  63. ResetEvent(g_hStopAttack);
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CNPView diagnostics
  67. #ifdef _DEBUG
  68. void CNPView::AssertValid() const
  69. {
  70. CListView::AssertValid();
  71. }
  72. void CNPView::Dump(CDumpContext& dc) const
  73. {
  74. CListView::Dump(dc);
  75. }
  76. CNPDoc* CNPView::GetDocument() // non-debug version is inline
  77. {
  78. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNPDoc)));
  79. return (CNPDoc*)m_pDocument;
  80. }
  81. #endif //_DEBUG
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CNPView message handlers
  84. BOOL CNPView::PreCreateWindow(CREATESTRUCT& cs) 
  85. {
  86. cs.style |= LVS_REPORT;
  87. return CListView::PreCreateWindow(cs);
  88. }
  89. void CNPView::KillAllThreads()
  90. {
  91. if(m_pMonThread)
  92. {
  93. SetEvent(g_hStopAttack);
  94. m_pMonThread->ResumeThread();
  95. m_pMonThread->KillThread();
  96. m_pMonThread = NULL;
  97. }
  98. }
  99. void CNPView::OnAttack() 
  100. {
  101. if(!m_bAttacking)
  102. {
  103. m_bAttacking = true;
  104. m_pMonThread->ResumeThread();
  105. }
  106. }
  107. void CNPView::OnStop() 
  108. {
  109. if(m_bAttacking)
  110. {
  111. m_bAttacking = false;
  112. m_bDisplay = true;
  113. m_pMonThread->SuspendThread();
  114. }
  115. }
  116. void CNPView::OnUpdateAttack(CCmdUI* pCmdUI) 
  117. {
  118. pCmdUI->SetCheck(m_bAttacking);
  119. }
  120. void CNPView::OnUpdateStop(CCmdUI* pCmdUI) 
  121. {
  122. pCmdUI->SetCheck(!m_bAttacking);
  123. }
  124. LRESULT CNPView::OnThreadReport(WPARAM num,LPARAM param)
  125. {
  126. char buf[50];
  127. CNPDoc *pDoc = GetDocument();
  128. CReportParam *pParam = (CReportParam *)param;
  129. if(m_bDisplay)
  130. {
  131. sprintf(buf,"当前有活动线程%d个",num);
  132. GetParent()->SetWindowText(buf);
  133. }
  134. if(pDoc->m_nResult == -1)
  135. {
  136. if(m_bDisplay)
  137. AddString(pParam->nEvent,pParam->password);
  138. pDoc->SetModifiedFlag();
  139. }
  140. if(pParam->nEvent == REPORT_SUCCEED)
  141. {
  142. m_pMonThread->SuspendThread();
  143. m_bAttacking = false;
  144. pDoc->m_nResult = pParam->password;
  145. sprintf(buf,"密码已经找到:  [%d]",pParam->password);
  146. MessageBox(buf,"恭喜,恭喜!");
  147. }
  148. if(pParam->nEvent == REPORT_CONNECT_ERROR ||
  149. pParam->nEvent == REPORT_BAD_OTHER)
  150. {
  151. InterlockedExchange(&(pDoc->m_nCurrent),pParam->password);
  152. }
  153. else
  154. {
  155. ((CMainFrame *)GetParent())->UpdateSpeedBarData();
  156. }
  157. delete pParam;
  158. return 0;
  159. }
  160. void CNPView::AddString(int nEvent,int password)
  161. {
  162. static char *Results[] = 
  163. {
  164. "连接服务器失败",
  165. "用户名错误",
  166. "密码错误",
  167. "其他错误",
  168. "匹配密码成功"
  169. };
  170. char buf[100];
  171. CListCtrl &List = GetListCtrl();
  172. int lines = List.GetCountPerPage();
  173. while(List.GetItemCount() > max(1,lines - 1))
  174. List.DeleteItem(0);
  175. lines = List.GetItemCount();
  176. ASSERT(nEvent >= 0  && nEvent < 5);
  177. LVITEM item;
  178. item.mask = LVIF_TEXT;
  179. item.iItem = lines;
  180. item.iSubItem = 0;
  181. item.pszText = Results[nEvent];
  182. List.InsertItem(&item);
  183. strcpy(buf,CTime::GetCurrentTime().Format("%H点%M分%S秒"));
  184. List.SetItemText(lines,1,buf);
  185. sprintf(buf,"%d",password);
  186. List.SetItemText(lines,2,buf);
  187. }
  188. LRESULT CNPView::OnThreadNumUpdate(WPARAM num,LPARAM)
  189. {
  190. char buf[50];
  191. if(m_bDisplay)
  192. {
  193. sprintf(buf,"当前有活动线程%d个",num);
  194. GetParent()->SetWindowText(buf);
  195. }
  196. return 0;
  197. }
  198. void CNPView::OnStopDisplay() 
  199. {
  200. // TODO: Add your command handler code here
  201. m_bDisplay = !m_bDisplay;
  202. }
  203. void CNPView::OnUpdateStopDisplay(CCmdUI* pCmdUI) 
  204. {
  205. // TODO: Add your command update UI handler code here
  206. pCmdUI->SetCheck(!m_bDisplay);
  207. }