FilePage.cpp
上传用户:shouhua
上传日期:2014-12-06
资源大小:5685k
文件大小:7k
- // FilePage.cpp : implementation file
- //
- #include "stdafx.h"
- #include "AntiEvilTools.h"
- #include "FilePage.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- MyList *Gogogo3;
- /////////////////////////////////////////////////////////////////////////////
- // CFilePage property page
- IMPLEMENT_DYNCREATE(CFilePage, CPropertyPage)
- CFilePage::CFilePage() : CPropertyPage(CFilePage::IDD)
- {
- //{{AFX_DATA_INIT(CFilePage)
- hDevice=NULL;
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- CFilePage::~CFilePage()
- {
- }
- void CFilePage::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFilePage)
- DDX_Control(pDX, IDC_LIST_FILE, m_wndList);
- DDX_Control(pDX, IDC_TREE_FILE, m_wndTree);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CFilePage, CPropertyPage)
- //{{AFX_MSG_MAP(CFilePage)
- ON_NOTIFY(NM_RCLICK, IDC_LIST_FILE, OnRclickProcessList)
- ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_FILE, OnSelchangedTree)
- ON_COMMAND(ID_MENUITEM_SAFE_DELETE, OnMenuitemSafeDelete)
- ON_COMMAND(ID_MENUITEM_DELETE, OnMenuitemDelete)
- ON_COMMAND(ID_MENUITEM_NORE_DELETE, OnMenuitemNoreDelete)
- ON_COMMAND(ID_MENUITEM_FORCE_KILL, OnMenuitemForceKill)
- ON_COMMAND(ID_MENUITEM_SUPERMODE, OnMenuitemSupermode)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFilePage message handlers
- BOOL CFilePage::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_wndTree.Initialize(&m_wndList);
- m_wndList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- Gogogo3->InitSystemImageLists(m_wndList.m_hWnd);
- int ret=m_wndList.InsertColumn(0,"文件名称",LVCFMT_RIGHT,140,0);
- m_wndList.InsertColumn(1,"文件路径",LVCFMT_LEFT,350,4);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CFilePage::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- // TV_ITEM itm= pNMTreeView->itemNew;
- *pResult = 0;
- }
- void CFilePage::OnRclickProcessList(NMHDR* pNMHDR, LRESULT* pResult)
- {
- iSelected = m_wndList.GetNextItem(-1, LVNI_SELECTED);
- POINT point;
- ::GetCursorPos(&point);
- CMenu menu;
- menu.LoadMenu(IDR_MENU_FILE);
- menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
- *pResult = 0;
- }
- void CFilePage::OnMenuitemSafeDelete()
- {
- // TODO: Add your command handler code here
- if(iSelected < 0 || iSelected >= m_wndList.GetItemCount())
- return;
- char name[255];
- m_wndList.GetItemText(iSelected, 1, name, 255);
- CString str;
- str.Format("确定删除%s吗?",name);
- if(MessageBox(str,"提示", MB_OKCANCEL) != IDOK)
- return;
- str.Format("%s",name);
- DeleteSafety(str);
- }
- void CFilePage::DeleteSafety(CString name)
- {
- HANDLE hFile; //文件句柄
- DWORD dwFileSize = 0;//文字长度
- WORD c[256]; //缓冲区数组
- int page; //文件页数
- hFile=CreateFile(name,
- GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- if(hFile==INVALID_HANDLE_VALUE)
- {
- return;
- }
- dwFileSize=GetFileSize(hFile,NULL);
- printf("%dn",dwFileSize);
- if(dwFileSize%512==0)
- page=dwFileSize/512;
- else page=dwFileSize/512+1;
- ULONG dw;
- memset(c,0,512); //缓冲区置0
- for(int i=0;i<page;i++)
- {
- WriteFile(hFile,c,sizeof(c),&dw,NULL);
- SetFilePointer(hFile,512*(i+1),NULL,FILE_BEGIN);
- }
- CloseHandle(hFile);
- hFile=CreateFile(name,
- GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- for(int b=0;b<256;b++)
- c[b]=257;
- for(int j=0;j<page;j++)
- {
- WriteFile(hFile,c,sizeof(c),&dw,NULL);
- SetFilePointer(hFile,512*(j+1),NULL,FILE_BEGIN);
- }
- CloseHandle(hFile);
- hFile=CreateFile(name,
- GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- srand(GetTickCount());
- for(int k=0;k<page;k++)
- {
- for(int m= 0;m <256; m++)
- {
- c[m] = rand();//缓冲区置随机
- }
- WriteFile(hFile,c,sizeof(c),&dw,NULL);
- SetFilePointer(hFile,512*(k+1),NULL,FILE_BEGIN);
- }
- CloseHandle(hFile);
- DeleteFile(name);
- }
- void CFilePage::OnMenuitemDelete()
- {
- // TODO: Add your command handler code here
- if(iSelected < 0 || iSelected >= m_wndList.GetItemCount())
- return;
- char name[255];
- m_wndList.GetItemText(iSelected,1, name, 255);
- CString str;
- str.Format("确定删除%s吗?",name);
- if(MessageBox(str,"提示", MB_OKCANCEL) != IDOK)
- return;
- str.Format("%s",name);
- DeleteFile(str);
- //OccupyFile(str);
- }
- void CFilePage::OnMenuitemNoreDelete()
- {
- // TODO: Add your command handler code here
- if(iSelected < 0 || iSelected >= m_wndList.GetItemCount())
- return;
- char name[255];
- m_wndList.GetItemText(iSelected, 1, name, 255);
- CString str;
- str.Format("确定删除%s吗?",name);
- if(MessageBox(str,"提示", MB_OKCANCEL) != IDOK)
- return;
- str.Format("%s",name);
- DeleteFile(str);
- OccupyFile(str);
- }
- void CFilePage::RaiseToDebugP()
- {
- HANDLE hToken;
- HANDLE hProcess = GetCurrentProcess();
- if ( OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken) )
- {
- TOKEN_PRIVILEGES tkp;
- if ( LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid) )
- {
- tkp.PrivilegeCount = 1;
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
-
- BOOL bREt = AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0) ;
- }
- CloseHandle(hToken);
- }
- }
- BOOL CFilePage::OccupyFile( LPCTSTR lpFileName )
- {
- BOOL bRet;
-
- RaiseToDebugP();
- HANDLE hProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, 4); // 4为system进程号
- if ( hProcess == NULL )
- {
- hProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, 8); // 2K下是 8??
-
- if ( hProcess == NULL )
- return FALSE;
- }
- HANDLE hFile;
- HANDLE hTargetHandle;
- hFile = CreateFile( lpFileName, GENERIC_READ, 0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL);
- if ( hFile == INVALID_HANDLE_VALUE )
- {
- CloseHandle( hProcess );
- return FALSE;
- }
- bRet = DuplicateHandle( GetCurrentProcess(), hFile, hProcess, &hTargetHandle,
- 0, FALSE, DUPLICATE_SAME_ACCESS|DUPLICATE_CLOSE_SOURCE);
- CloseHandle( hProcess );
- return bRet;
- }
- void CFilePage::OnMenuitemForceKill()
- {
- // TODO: Add your command handler code here
- if(iSelected < 0 || iSelected >= m_wndList.GetItemCount())
- return;
- char name[256];
- m_wndList.GetItemText(iSelected, 1, name, 256);
- CString str;
- str.Format("确定删除%s吗?",name);
- if(MessageBox(str,"提示", MB_OKCANCEL) != IDOK)
- return;
- ULONG bytesReturned;
- DeviceIoControl(hDevice,(DWORD)IOCTL_MT_KILLFILE,name,sizeof(name),NULL,0,&bytesReturned,NULL);
- //CloseHandle(hDevice);
- }
- void CFilePage::SetHandle(HANDLE handle)
- {
- hDevice=handle;
- }
- void CFilePage::OnMenuitemSupermode()
- {
- // TODO: Add your command handler code here
- if(hDevice==NULL)
- {
- MessageBox("failed");
- }
- else
- {
- CString str;
- str.Format("%08x",hDevice);
- MessageBox(str);
- }
- }