FilePage.cpp
上传用户:shouhua
上传日期:2014-12-06
资源大小:5685k
文件大小:7k
源码类别:

杀毒

开发平台:

Visual C++

  1. // FilePage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "AntiEvilTools.h"
  5. #include "FilePage.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. MyList  *Gogogo3;
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CFilePage property page
  14. IMPLEMENT_DYNCREATE(CFilePage, CPropertyPage)
  15. CFilePage::CFilePage() : CPropertyPage(CFilePage::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CFilePage)
  18. hDevice=NULL;
  19. // NOTE: the ClassWizard will add member initialization here
  20. //}}AFX_DATA_INIT
  21. }
  22. CFilePage::~CFilePage()
  23. {
  24. }
  25. void CFilePage::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CPropertyPage::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CFilePage)
  29. DDX_Control(pDX, IDC_LIST_FILE, m_wndList);
  30. DDX_Control(pDX, IDC_TREE_FILE, m_wndTree);
  31. //}}AFX_DATA_MAP
  32. }
  33. BEGIN_MESSAGE_MAP(CFilePage, CPropertyPage)
  34. //{{AFX_MSG_MAP(CFilePage)
  35. ON_NOTIFY(NM_RCLICK, IDC_LIST_FILE, OnRclickProcessList)
  36. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_FILE, OnSelchangedTree)
  37. ON_COMMAND(ID_MENUITEM_SAFE_DELETE, OnMenuitemSafeDelete)
  38. ON_COMMAND(ID_MENUITEM_DELETE, OnMenuitemDelete)
  39. ON_COMMAND(ID_MENUITEM_NORE_DELETE, OnMenuitemNoreDelete)
  40. ON_COMMAND(ID_MENUITEM_FORCE_KILL, OnMenuitemForceKill)
  41. ON_COMMAND(ID_MENUITEM_SUPERMODE, OnMenuitemSupermode)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CFilePage message handlers
  46. BOOL CFilePage::OnInitDialog()
  47. {
  48. CDialog::OnInitDialog();
  49. m_wndTree.Initialize(&m_wndList);
  50. m_wndList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  51. Gogogo3->InitSystemImageLists(m_wndList.m_hWnd);
  52. int ret=m_wndList.InsertColumn(0,"文件名称",LVCFMT_RIGHT,140,0);
  53. m_wndList.InsertColumn(1,"文件路径",LVCFMT_LEFT,350,4);
  54. return TRUE;  // return TRUE  unless you set the focus to a control
  55. }
  56. void CFilePage::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult) 
  57. {
  58. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  59. // TV_ITEM itm= pNMTreeView->itemNew;
  60. *pResult = 0;
  61. }
  62. void CFilePage::OnRclickProcessList(NMHDR* pNMHDR, LRESULT* pResult) 
  63. {
  64. iSelected = m_wndList.GetNextItem(-1, LVNI_SELECTED);
  65. POINT point;
  66. ::GetCursorPos(&point);
  67. CMenu menu;
  68. menu.LoadMenu(IDR_MENU_FILE);
  69. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
  70. *pResult = 0;
  71. }
  72. void CFilePage::OnMenuitemSafeDelete() 
  73. {
  74. // TODO: Add your command handler code here
  75. if(iSelected < 0 || iSelected >= m_wndList.GetItemCount())
  76. return;
  77. char    name[255];
  78. m_wndList.GetItemText(iSelected, 1, name, 255);
  79.     CString   str;
  80. str.Format("确定删除%s吗?",name);
  81. if(MessageBox(str,"提示", MB_OKCANCEL) != IDOK)
  82. return;
  83. str.Format("%s",name);
  84. DeleteSafety(str);
  85. }
  86. void CFilePage::DeleteSafety(CString   name)
  87. {
  88. HANDLE hFile;        //文件句柄
  89.     DWORD dwFileSize = 0;//文字长度
  90. WORD c[256];         //缓冲区数组
  91. int page;            //文件页数
  92. hFile=CreateFile(name,
  93. GENERIC_WRITE,
  94. FILE_SHARE_READ,
  95. NULL,
  96. OPEN_EXISTING,
  97. 0,
  98. NULL);
  99. if(hFile==INVALID_HANDLE_VALUE)
  100. {
  101. return;
  102. }
  103.     dwFileSize=GetFileSize(hFile,NULL);
  104. printf("%dn",dwFileSize);
  105. if(dwFileSize%512==0)
  106. page=dwFileSize/512;
  107. else page=dwFileSize/512+1;
  108. ULONG   dw;
  109.     memset(c,0,512);   //缓冲区置0
  110. for(int i=0;i<page;i++)
  111. {
  112. WriteFile(hFile,c,sizeof(c),&dw,NULL);
  113. SetFilePointer(hFile,512*(i+1),NULL,FILE_BEGIN);
  114. }
  115. CloseHandle(hFile);
  116. hFile=CreateFile(name,
  117. GENERIC_WRITE,
  118. FILE_SHARE_READ,
  119. NULL,
  120. OPEN_EXISTING,
  121. 0,
  122. NULL);
  123. for(int b=0;b<256;b++)
  124. c[b]=257;
  125. for(int j=0;j<page;j++)
  126. {
  127. WriteFile(hFile,c,sizeof(c),&dw,NULL);
  128. SetFilePointer(hFile,512*(j+1),NULL,FILE_BEGIN);
  129. }
  130. CloseHandle(hFile);
  131. hFile=CreateFile(name,
  132. GENERIC_WRITE,
  133. FILE_SHARE_READ,
  134. NULL,
  135. OPEN_EXISTING,
  136. 0,
  137. NULL);
  138. srand(GetTickCount());
  139. for(int k=0;k<page;k++)
  140. {
  141. for(int m= 0;m <256; m++)
  142. {
  143. c[m] = rand();//缓冲区置随机
  144. }
  145. WriteFile(hFile,c,sizeof(c),&dw,NULL);
  146. SetFilePointer(hFile,512*(k+1),NULL,FILE_BEGIN);
  147. }
  148. CloseHandle(hFile);
  149. DeleteFile(name);
  150. }
  151. void CFilePage::OnMenuitemDelete() 
  152. {
  153. // TODO: Add your command handler code here
  154. if(iSelected < 0 || iSelected >= m_wndList.GetItemCount())
  155. return;
  156. char    name[255];
  157. m_wndList.GetItemText(iSelected,1, name, 255);
  158.     CString   str;
  159. str.Format("确定删除%s吗?",name);
  160. if(MessageBox(str,"提示", MB_OKCANCEL) != IDOK)
  161. return;
  162. str.Format("%s",name);
  163. DeleteFile(str);
  164. //OccupyFile(str);
  165. }
  166. void CFilePage::OnMenuitemNoreDelete() 
  167. {
  168. // TODO: Add your command handler code here
  169. if(iSelected < 0 || iSelected >= m_wndList.GetItemCount())
  170. return;
  171. char    name[255];
  172. m_wndList.GetItemText(iSelected, 1, name, 255);
  173.     CString   str;
  174. str.Format("确定删除%s吗?",name);
  175. if(MessageBox(str,"提示", MB_OKCANCEL) != IDOK)
  176. return;
  177. str.Format("%s",name);
  178. DeleteFile(str);
  179. OccupyFile(str);
  180. }
  181. void CFilePage::RaiseToDebugP()
  182. {
  183.     HANDLE hToken;
  184.     HANDLE hProcess = GetCurrentProcess();
  185.     if ( OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken) )
  186.     {
  187.         TOKEN_PRIVILEGES tkp;
  188.         if ( LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid) )
  189.         {
  190.             tkp.PrivilegeCount = 1;
  191.             tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  192.             
  193.             BOOL bREt = AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0) ;
  194.         }
  195.         CloseHandle(hToken);
  196.     }    
  197. }
  198. BOOL CFilePage::OccupyFile( LPCTSTR lpFileName )
  199. {
  200.     BOOL    bRet;
  201.     
  202.     RaiseToDebugP();
  203.     HANDLE hProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, 4);    // 4为system进程号
  204.     if ( hProcess == NULL )
  205.     {
  206.         hProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, 8);        // 2K下是 8??
  207.         
  208.         if ( hProcess == NULL )
  209.             return FALSE;
  210.     }
  211.     HANDLE hFile;
  212.     HANDLE hTargetHandle;
  213.     hFile = CreateFile( lpFileName, GENERIC_READ, 0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL);    
  214.     if ( hFile == INVALID_HANDLE_VALUE )
  215.     {
  216.         CloseHandle( hProcess );
  217.         return FALSE;
  218.     }
  219.     bRet = DuplicateHandle( GetCurrentProcess(), hFile, hProcess, &hTargetHandle, 
  220.         0, FALSE, DUPLICATE_SAME_ACCESS|DUPLICATE_CLOSE_SOURCE);
  221.     CloseHandle( hProcess );
  222.     return bRet;
  223. }
  224. void CFilePage::OnMenuitemForceKill() 
  225. {
  226. // TODO: Add your command handler code here
  227. if(iSelected < 0 || iSelected >= m_wndList.GetItemCount())
  228. return;
  229. char    name[256];
  230. m_wndList.GetItemText(iSelected, 1, name, 256);
  231.     CString   str;
  232. str.Format("确定删除%s吗?",name);
  233. if(MessageBox(str,"提示", MB_OKCANCEL) != IDOK)
  234. return;
  235. ULONG   bytesReturned;
  236. DeviceIoControl(hDevice,(DWORD)IOCTL_MT_KILLFILE,name,sizeof(name),NULL,0,&bytesReturned,NULL);
  237. //CloseHandle(hDevice);
  238. }
  239. void CFilePage::SetHandle(HANDLE handle)
  240. {
  241.     hDevice=handle;
  242. }
  243. void CFilePage::OnMenuitemSupermode() 
  244. {
  245. // TODO: Add your command handler code here
  246. if(hDevice==NULL)
  247. {
  248. MessageBox("failed");
  249. }
  250. else
  251. {
  252. CString str;
  253. str.Format("%08x",hDevice);
  254. MessageBox(str);
  255. }
  256. }