From download:
Brute force, force delete file source code
Http://www.bmpj.net/forum-viewthread-tid-783-fromuid-16.html
// MzfDeleteFileDlg. cpp: implementation file
//
# Include "stdafx. h"
# Include "MzfDeleteFile. h"
# Include "MzfDeleteFileDlg. h"
# Include "common. h"
# Include <winioctl. h>
# Include <winsvc. h>
# Ifdef _ DEBUG
# Define new DEBUG_NEW
# Undef THIS_FILE
Static char THIS_FILE [] = _ FILE __;
# Endif
//////////////////////////////////////// /////////////////////////////////////
// CAboutDlg dialog used for App About
Static int I = 0;
# Define SERVICE_NAME "MzfKillFile"
# Define DRIVER_NAME "MzfKillFile. sys"
Class CAboutDlg: public CDialog
{
Public:
CAboutDlg ();
// Dialog Data
// {AFX_DATA (CAboutDlg)
Enum {IDD = IDD_ABOUTBOX };
//} AFX_DATA
// ClassWizard generated virtual function overrides
// {AFX_VIRTUAL (CAboutDlg)
Protected:
Virtual void DoDataExchange (CDataExchange * pDX); // DDX/DDV support
//} AFX_VIRTUAL
// Implementation
Protected:
// {AFX_MSG (CAboutDlg)
//} AFX_MSG
DECLARE_MESSAGE_MAP ()
};
CAboutDlg: CAboutDlg (): CDialog (CAboutDlg: IDD)
{
// {AFX_DATA_INIT (CAboutDlg)
//} AFX_DATA_INIT
}
Void CAboutDlg: DoDataExchange (CDataExchange * pDX)
{
CDialog: DoDataExchange (pDX );
// {AFX_DATA_MAP (CAboutDlg)
//} AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP (CAboutDlg, CDialog)
// {AFX_MSG_MAP (CAboutDlg)
// No message handlers
//} AFX_MSG_MAP
END_MESSAGE_MAP ()
//////////////////////////////////////// /////////////////////////////////////
// CMzfDeleteFileDlg dialog
CMzfDeleteFileDlg: CMzfDeleteFileDlg (CWnd * pParent/* = NULL */)
: CDialog (CMzfDeleteFileDlg: IDD, pParent)
{
// {AFX_DATA_INIT (CMzfDeleteFileDlg)
//} AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
M_hIcon = AfxGetApp ()-> LoadIcon (IDR_MAINFRAME );
}
Void CMzfDeleteFileDlg: DoDataExchange (CDataExchange * pDX)
{
CDialog: DoDataExchange (pDX );
// {AFX_DATA_MAP (CMzfDeleteFileDlg)
DDX_Control (pDX, IDC_STATIC52POJIE, m_52pojie );
DDX_Control (pDX, IDC_STATICURL, m_Link );
DDX_Control (pDX, IDC_LISTFILE, m_list );
//} AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP (CMzfDeleteFileDlg, CDialog)
// {AFX_MSG_MAP (CMzfDeleteFileDlg)
ON_WM_SYSCOMMAND ()
ON_WM_PAINT ()
ON_WM_QUERYDRAGICON ()
ON_BN_CLICKED (IDC_SURE, OnSure)
ON_BN_CLICKED (IDC_ADD, OnAdd)
ON_BN_CLICKED (IDC_DELETE, OnDelete)
ON_WM_DROPFILES ()
ON_BN_CLICKED (IDC_ALL, OnAll)
ON_BN_CLICKED (IDC_NOTALL, OnNotall)
ON_WM_MOUSEMOVE ()
ON_WM_LBUTTONDOWN ()
ON_WM_CLOSE ()
//} AFX_MSG_MAP
END_MESSAGE_MAP ()
//////////////////////////////////////// /////////////////////////////////////
// CMzfDeleteFileDlg message handlers
BOOL CMzfDeleteFileDlg: OnInitDialog ()
{
CDialog: OnInitDialog ();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT (IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX );
ASSERT (IDM_ABOUTBOX <0xF000 );
CMenu * pSysMenu = GetSystemMenu (FALSE );
If (pSysMenu! = NULL)
{
CString strAboutMenu;
StrAboutMenu. LoadString (IDS_ABOUTBOX );
If (! StrAboutMenu. IsEmpty ())
{
PSysMenu-> AppendMenu (MF_SEPARATOR );
PSysMenu-> AppendMenu (MF_STRING, IDM_ABOUTBOX, strAboutMenu );
}
}
// Set the icon for this dialog. The framework does this automatically
// When the application's main window is not a dialog
SetIcon (m_hIcon, TRUE); // Set big icon
SetIcon (m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
If (! ReleaseRes (DRIVER_NAME, (WORD) IDR_SYS, "SYS "))
{
MessageBox ("failed to release the driver! ");
ExitProcess (0 );
}
BOOL bRet = LoadNTDriver (SERVICE_NAME, DRIVER_NAME );
If (! BRet)
{
UnloadNTDriver (SERVICE_NAME );
BRet = LoadNTDriver (SERVICE_NAME, DRIVER_NAME );
If (! BRet)
{
MessageBox ("failed to load driver, program exited! ");
ExitProcess (0 );
Return FALSE;
}
}
BRet = Startservice (SERVICE_NAME, DRIVER_NAME );
If (! BRet)
{
MessageBox ("failed to start the service and the program exited! ");
ExitProcess (0 );
Return FALSE;
}
DeleteFile (DRIVER_NAME );
M_list.SetExtendedStyle (LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
M_list.InsertColumn (0, "file name ");
M_list.InsertColumn (1, "file path ");
M_list.SetColumnWidth (0,130 );
M_list.SetColumnWidth (1,380 );
Return TRUE; // return TRUE unless you set the focus to a control
}
Void CMzfDeleteFileDlg: OnSysCommand (UINT nID, LPARAM lParam)
{
If (nID & 0xFFF0) = IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
DlgAbout. DoModal ();
}
Else
{
CDialog: OnSysCommand (nID, lParam );
}
}
// If you add a minimize button to your dialog, you will need the code below
// To draw the icon. For MFC applications using the document/view model,
// This is automatically done for you by the framework.
Void CMzfDeleteFileDlg: OnPaint ()
{
If (IsIconic ())
{
CPaintDC dc (this); // device context for painting
SendMessage (WM_ICONERASEBKGND, (WPARAM) dc. GetSafeHdc (), 0 );
// Center icon in client rectangle
Int cxIcon = GetSystemMetrics (SM_CXICON );
Int cyIcon = GetSystemMetrics (SM_CYICON );
CRect rect;
GetClientRect (& rect );
Int x = (rect. Width ()-cxIcon + 1)/2;
Int y = (rect. Height ()-cyIcon + 1)/2;
// Draw the icon
Dc. DrawIcon (x, y, m_hIcon );
}
Else
{
CDialog: OnPaint ();
}
}
// The system callthis to obtain the cursor to display while the user drags
// The minimized window.
HCURSOR CMzfDeleteFileDlg: OnQueryDragIcon ()
{
Return (HCURSOR) m_hIcon;
}
Void CMzfDeleteFileDlg: OnSure ()
{
// TODO: Add your control notification handler code here
For (int j = 0; j <m_list.GetItemCount (); j ++)
{
If (m_list.GetCheck (j ))
{
WCHAR szwChar [512];
DWORD dwRet;
CString str = m_list.GetItemText (j, 1 );
Int nChar = MultiByteToWideChar (CP_ACP, 0, str,-1, szwChar, 256 );
// MessageBoxW (NULL, szwChar, L "fuck", MB_ OK );
HANDLE hFile = CreateFile (WIN32_NAME, GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
If (hFile = INVALID_HANDLE_VALUE)
{
MessageBox ("failed to open the driver! "," Prompt :");
Return;
}
DeviceIoControl (hFile, IOCTL_DELETEFILE, szwChar, sizeof (szwChar), NULL, 0, & dwRet, NULL );
M_list.DeleteItem (j );
J --;
I --;
}
}
}
Void CMzfDeleteFileDlg: OnAdd ()
{
// TODO: Add your control notification handler code here
CString strFilter;
StrFilter = "All Files (*. *) | *. * | ";
CFileDialog fileDlg (TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFilter );
FileDlg. m_ofn.lStructSize = sizeof (OPENFILENAME );
If (IDOK = fileDlg. DoModal ())
{
CString strPath, strName ;;
StrPath = fileDlg. GetPathName ();
StrName = strPath. Right (strPath. GetLength ()-strPath. ReverseFind ('\')-1 );
M_list.InsertItem (I, strName );
M_list.SetItemText (I ++, 1, strPath );
}
}
Void CMzfDeleteFileDlg: OnDelete ()
{
// TODO: Add your control notification handler code here
For (int j = 0; j <m_list.GetItemCount (); j ++)
{
If (m_list.GetCheck (j ))
{
M_list.DeleteItem (j );
J --;
I --;
}
}
}
Void CMzfDeleteFileDlg: OnDropFiles (HDROP hDropInfo)
{
CHAR filePath [MAX_PATH] = {0 };
DragQueryFile (hDropInfo, 0, filePath, MAX_PATH-1 );
If (GetFileAttributes (filePath) = FILE_ATTRIBUTE_DIRECTORY)
{
MessageBox ("Folder deletion is not supported now! "," Prompt :");
Return;
}
CString strPath, strName ;;
StrPath = filePath;
StrName = strPath. Right (strPath. GetLength ()-strPath. ReverseFind ('\')-1 );
M_list.InsertItem (I, strName );
M_list.SetItemText (I ++, 1, strPath );
DragFinish (hDropInfo );
}
Void CMzfDeleteFileDlg: OnAll ()
{
// TODO: Add your control notification handler code here
For (int j = 0; j <m_list.GetItemCount (); j ++)
{
M_list.SetCheck (j );
}
}
Void CMzfDeleteFileDlg: OnNotall ()
{
// TODO: Add your control notification handler code here
For (int j = 0; j <m_list.GetItemCount (); j ++)
{
M_list.SetCheck (j, FALSE );
}
}
Void CMzfDeleteFileDlg: OnMouseMove (UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rcLink, rc52pojie;
M_Link.GetClientRect (& rcLink );
M_Link.ClientToScreen (& rcLink );
ScreenToClient (& rcLink );
M_52pojie.GetClientRect (& rc52pojie );
M_52pojie.ClientToScreen (& rc52pojie );
ScreenToClient (& rc52pojie );
If (point. x> rcLink. left & point. x <rcLink. right & point. y> rcLink. top & point. y <rcLink. bottom)
{
HCURSOR hCursor;
HCursor =: LoadCursor (NULL, IDC_HAND );
SetCursor (hCursor );
}
Else if (point. x> rc52pojie. left & point. x <rc52pojie. right & point. y> rc52pojie. top & point. y <rc52pojie. bottom)
{
HCURSOR hCursor;
HCursor =: LoadCursor (NULL, IDC_HAND );
SetCursor (hCursor );
}
CDialog: OnMouseMove (nFlags, point );
}
Void CMzfDeleteFileDlg: OnLButtonDown (UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rcLink, rc52pojie;
M_Link.GetClientRect (& rcLink );
M_Link.ClientToScreen (& rcLink );
ScreenToClient (& rcLink );
M_52pojie.GetClientRect (& rc52pojie );
M_52pojie.ClientToScreen (& rc52pojie );
ScreenToClient (& rc52pojie );
If (point. x> rcLink. left & point. x <rcLink. right & point. y> rcLink. top & point. y <rcLink. bottom)
{
ShellExecute (NULL, NULL, _ T ("http://hi.baidu.com/hu3167343/"), NULL, NULL, SW_NORMAL );
}
Else if (point. x> rc52pojie. left & point. x <rc52pojie. right & point. y> rc52pojie. top & point. y <rc52pojie. bottom)
{
ShellExecute (NULL, NULL, _ T ("http://www.52pojie.cn"), NULL, NULL, SW_NORMAL );
}
CDialog: OnLButtonDown (nFlags, point );
}
BOOL CMzfDeleteFileDlg: ReleaseRes (CString strFileName, WORD wResID, CString strFileType)
{
DWORD dwWrite;
HANDLE hFile = CreateFile (strFileName, GENERIC_WRITE, file_pai_write, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL );
If (hFile = INVALID_HANDLE_VALUE)
{
Return FALSE;
}
HRSRC hrsc = FindResource (NULL, MAKEINTRESOURCE (wResID), strFileType );
HGLOBAL hg = LoadResource (NULL, hrsc );
DWORD dwSize = SizeofResource (NULL, hrsc );
WriteFile (hFile, hg, dwSize, & dwWrite, NULL );
CloseHandle (hFile );
Return TRUE;
}
BOOL CMzfDeleteFileDlg: LoadNTDriver (CHAR * lpszDriverName, CHAR * lpszDriverPath)
{
CHAR szDriverImagePath [256];
BOOL bRet = TRUE;
SC _HANDLE hServiceMgr = NULL;
SC _HANDLE hServiceDDK = NULL;
GetFullPathName (lpszDriverPath, 256, szDriverImagePath, NULL );
HServiceMgr = OpenSCManager (NULL, NULL, SC _MANAGER_ALL_ACCESS );
If (hServiceMgr = NULL)
{
BRet = FALSE;
Goto BeforeLeave;
}
HServiceDDK = CreateService (hServiceMgr,
LpszDriverName,
LpszDriverName,
SERVICE_ALL_ACCESS,
SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START,
SERVICE_ERROR_IGNORE,
SzDriverImagePath,
NULL, NULL
);
DWORD dwRtn;
If (hServiceDDK = NULL)
{
DwRtn = GetLastError ();
If (dwRtn! = ERROR_IO_PENDING & dwRtn! = ERROR_SERVICE_EXISTS)
{
BRet = FALSE;
Goto BeforeLeave;
}
HServiceDDK = OpenService (hServiceMgr, lpszDriverName, SERVICE_ALL_ACCESS );
If (hServiceDDK = NULL)
{
BRet = FALSE;
Goto BeforeLeave;
}
}
BRet = TRUE;
BeforeLeave:
If (hServiceDDK)
{
CloseServiceHandle (hServiceDDK );
}
If (hServiceMgr)
{
CloseServiceHandle (hServiceMgr );
}
Return bRet;
}
BOOL CMzfDeleteFileDlg: Startservice (CHAR * lpszDriverName, CHAR * lpszDriverPath)
{
CHAR szDriverImagePath [256];
BOOL bRet = TRUE;
SC _HANDLE hServiceMgr = NULL;
SC _HANDLE hServiceDDK = NULL;
GetFullPathName (lpszDriverPath, 256, szDriverImagePath, NULL );
HServiceMgr = OpenSCManager (NULL, NULL, SC _MANAGER_ALL_ACCESS );
If (hServiceMgr = NULL)
{
BRet = FALSE;
Goto BeforeLeave;
}
HServiceDDK = OpenService (hServiceMgr, lpszDriverName, SERVICE_ALL_ACCESS );
If (hServiceDDK = NULL)
{
BRet = FALSE;
Goto BeforeLeave;
}
BRet = StartService (hServiceDDK, NULL, NULL );
If (! BRet)
{
DWORD dwRtn = GetLastError ();
If (dwRtn! = ERROR_IO_PENDING & dwRtn! = ERROR_SERVICE_ALREADY_RUNNING)
{
BRet = FALSE;
Goto BeforeLeave;
}
Else
{
If (dwRtn = ERROR_IO_PENDING)
{
MessageBox ("StartService () Faild ERROR_IO_PENDING! \ N ");
BRet = FALSE;
Goto BeforeLeave;
}
Else
{
BRet = TRUE;
Goto BeforeLeave;
}
}
}
BeforeLeave:
If (hServiceDDK)
{
CloseServiceHandle (hServiceDDK );
}
If (hServiceMgr)
{
CloseServiceHandle (hServiceMgr );
}
Return bRet;
}
BOOL CMzfDeleteFileDlg: UnloadNTDriver (CHAR * szSvrName)
{
Bool bRet = TRUE;
SC _HANDLE hServiceMgr = NULL;
SC _HANDLE hServiceDDK = NULL;
SERVICE_STATUS SvrSta;
HServiceMgr = OpenSCManager (NULL, NULL, SC _MANAGER_ALL_ACCESS );
If (hServiceMgr = NULL)
{
BRet = FALSE;
Goto BeforeLeave;
}
HServiceDDK = OpenService (hServiceMgr, szSvrName, SERVICE_ALL_ACCESS );
If (hServiceDDK = NULL)
{
BRet = FALSE;
Goto BeforeLeave;
}
If (! ControlService (hServiceDDK, SERVICE_CONTROL_STOP, & SvrSta ))
{
BRet = FALSE;
Goto BeforeLeave;
}
If (! DeleteService (hServiceDDK ))
{
BRet = FALSE;
Goto BeforeLeave;
}
BeforeLeave:
If (hServiceDDK)
{
CloseServiceHandle (hServiceDDK );
}
If (hServiceMgr)
{
CloseServiceHandle (hServiceMgr );
}
Return bRet;
}
Void CMzfDeleteFileDlg: OnClose ()
{
// TODO: Add your message handler code here and/or call default
UnloadNTDriver (SERVICE_NAME );
// DeleteFile (DRIVER_NAME );
CDialog: OnClose ();
}