⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 redlofkillerdlg.cpp

📁 一个可以查杀Redlof病毒的小工具,界面玩具地很,但实现具一定参考价值
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// RedLofKillerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RedLofKiller.h"
#include "RedLofKillerDlg.h"
#include "ConfirmDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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()

/////////////////////////////////////////////////////////////////////////////
// CRedLofKillerDlg dialog

CRedLofKillerDlg::CRedLofKillerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRedLofKillerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRedLofKillerDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CRedLofKillerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRedLofKillerDlg)
	DDX_Control(pDX, IDC_LIST_INFECTED, m_lstInfected);
	DDX_Control(pDX, IDC_SCAN_PROGRESS, m_stScanProgress);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRedLofKillerDlg, CDialog)
	//{{AFX_MSG_MAP(CRedLofKillerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SELECT_FOLDER, OnSelectFolder)
	ON_BN_CLICKED(IDC_SCAN_START, OnScanStart)
	ON_BN_CLICKED(IDC_SCAN_STOP, OnScanStop)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_CONFIRM, OnConfirm)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRedLofKillerDlg message handlers

BOOL CRedLofKillerDlg::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

	InitApp();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CRedLofKillerDlg::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 CRedLofKillerDlg::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 calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CRedLofKillerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//***********************************************************
//函数名称:
//功能描述:
//***********************************************************
void CRedLofKillerDlg::OnSelectFolder() 
{
	BROWSEINFO browInfo;
	LPMALLOC lpMalloc;
	LPITEMIDLIST pidl;
	memset(&browInfo, 0, sizeof(BROWSEINFO));
	browInfo.hwndOwner = this->m_hWnd;
	browInfo.pszDisplayName = NULL;
	browInfo.lpszTitle = "Hello";
	browInfo.lpfn = BrowseCallBack;
	browInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
	browInfo.lParam = (LPARAM)this;
	if (SUCCEEDED(::SHGetMalloc(&lpMalloc))) {
		pidl = ::SHBrowseForFolder(&browInfo);
		if (pidl != NULL) {
			lpMalloc->Free(pidl);
		}
		lpMalloc->Release();
		//AfxMessageBox(m_strFolderScan);
		m_nExtCnt = m_strExt.GetSize();
		if ((m_strFolderScan.Right(1)).Compare("\\")) {
			m_strFolderScan.Insert( m_strFolderScan.GetLength(), "\\");
		}
		
	}
  //这里可以开始对指定文件夹下的文件进行扫描	
	
}


//函数名称:
//功能描述:
//@param
//@param
//@param
//@param
//@return 
int CALLBACK CRedLofKillerDlg::BrowseCallBack(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
	
	
	CRedLofKillerDlg* pDlg = (CRedLofKillerDlg*)lpData;
	LPTSTR lpszFolder = pDlg->m_strFolderScan.GetBuffer(MAX_PATH);
	switch (uMsg) {
	case BFFM_INITIALIZED:
		break;
	case BFFM_SELCHANGED:
		::SHGetPathFromIDList((LPITEMIDLIST)lParam, lpszFolder);
		pDlg->m_strFolderScan.ReleaseBuffer();

		break;
	}
  return 0;
}

/*
  该函数实现对指定文件夹下的文件的扫描 
*/
//@param
//@return  SCAN_OK 
//@return	 SCAN_FAILED
int CRedLofKillerDlg::ScanFolder(CString& argFolder)
{
	TCHAR drive[_MAX_DRIVE];  //存放文件名的盘符
	TCHAR dir[_MAX_DIR];      //存放文件的路径
	TCHAR fname[_MAX_FNAME];  //存放文件名称
	TCHAR ext[_MAX_EXT];      //存放文件扩展名
	WIN32_FIND_DATA findData;
	HANDLE handleFound;
	char scanFile[MAX_PATH];  
	CString strFile; //存放被找到的文件名
	int nRet = 0;  //存放操作返回的状态
	strcpy(scanFile, argFolder);
	strcat(scanFile, "*.*");
	handleFound = ::FindFirstFile(scanFile, &findData);
	//如果找到了相应文件
	if (handleFound != INVALID_HANDLE_VALUE) 
	{
		do 
		{
			//如果用户要求退出扫描的话,就终止
			if (m_bExitScan)
			{
				break;
			}
			//如果被找到的文件不是".",并且不是"..",才进行下一步的扫描操作
			if (strcmp(findData.cFileName, ".") && strcmp(findData.cFileName, ".."))
			{
				strFile.Format("%s%s", argFolder, findData.cFileName);
				DWORD dwFlag = ::GetFileAttributes((LPCTSTR)strFile);
	  		//如果被查到的文件是文件夹的话,则递归扫描
				if (::GetFileAttributes(strFile) & FILE_ATTRIBUTE_DIRECTORY)
				{
					if (strFile.Right(1).Compare("\\")) 
					{
						strFile.Insert(strFile.GetLength(), "\\");
					}
					ScanFolder(strFile);
				}
				else 
				{
					
					m_nScanTotalCount++;
					//检查被找到的文件的扩展名是否为可能被感染的类型
					::_tsplitpath(strFile, drive, dir, fname, ext);
					for (int i = 0; i < m_nExtCnt; i++) 
					{
						if (!m_strExt.GetAt(i).Compare(::strlwr(ext))) 
						{
							break;
						}
					}
					if ( i < m_nExtCnt) 
					{
						//如果被查到的文件是普通文件的话,并且是可能被感染的类型
						//在scan函数中,如果找到病毒特征字的话就进行查杀
						nRet = ScanFile(strFile);
					}
					strFile += " being scanned";
					m_stScanProgress.SetWindowText(strFile);
				}
			}
		} while(::FindNextFile(handleFound,&findData));
		::FindClose(handleFound);
	}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -