当前位置:编程学习 > VC++ >>

VC++信息安全编程(6)实现杀毒程序,杀灭D3病毒范例

 

下面我们用代码亲自来实践一个杀毒程序,清除程序的可读可写,并扫描程序的特征码,对病毒进行删除

 

 

 

 

 

 

 

#include "stdafx.h"

#include "ScanDisk.h"

#include "ScanDiskDlg.h"

 

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

 

UINT ThreadProc(LPVOID param){

CScanDiskDlg *ScanDisk=(CScanDiskDlg*)param;

CString part;

int i=0;

int cy=ScanDisk->m_Disk.GetLength()/2;

do{

       part=ScanDisk->m_Disk.Mid(2*i,2);

    ScanDisk->SearchFolder((char*)part.GetBuffer(0));  

       i++;

}while(i<cy&&ScanDisk->Status);

 

char s[256];

sprintf(s,"扫描的文件总数=%d",ScanDisk->TotalFileNum);

ScanDisk->m_Static.SendMessage(WM_SETTEXT,0,(LPARAM)(LPCTSTR)s);

return 0;

}

/////////////////////////////////////////////////////////////////////////////

// CScanDiskDlg dialog

 

CScanDiskDlg::CScanDiskDlg(CWnd* pParent /*=NULL*/)

       : CDialog(CScanDiskDlg::IDD, pParent)

{

       //{{AFX_DATA_INIT(CScanDiskDlg)

       m_Disk = _T("");

       //}}AFX_DATA_INIT

       // Note that LoadIcon does not require a subsequent DestroyIcon in Win32

       m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

       TotalFileNum=0;  //扫描文件总数

}

 

void CScanDiskDlg::DoDataExchange(CDataExchange* pDX)

{

       CDialog::DoDataExchange(pDX);

       //{{AFX_DATA_MAP(CScanDiskDlg)

       DDX_Control(pDX, IDC_STATIC1, m_Static);

       DDX_Control(pDX, IDC_LIST1, m_List);

       DDX_Control(pDX, IDC_Bstart, m_Bstart);

       DDX_Text(pDX, IDC_Epartition, m_Disk);

       //}}AFX_DATA_MAP

}

 

BEGIN_MESSAGE_MAP(CScanDiskDlg, CDialog)

       //{{AFX_MSG_MAP(CScanDiskDlg)

       ON_WM_PAINT()

       ON_WM_QUERYDRAGICON()

       ON_BN_CLICKED(IDC_Bstart, OnBstart)

       ON_BN_CLICKED(IDC_Bstop, OnBstop)

       ON_EN_CHANGE(IDC_Epartition, OnChangeEpartition)

       ON_BN_CLICKED(IDC_Bsave, OnBsave)

       //}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

/////////////////////////////////////////////////////////////////////////////

// CScanDiskDlg message handlers

 

BOOL CScanDiskDlg::OnInitDialog()

{

       CDialog::OnInitDialog();

 

       // 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

      

DWORD disk=GetLogicalDrives();

DWORD va=1;

char s[]="A:";

for(int i=0;i<32;i++){

       if(disk&(va<<i)){

        s[0]=0x41+(char)i;

        m_Disk+=s;

}}

UpdateData(FALSE);

Status=FALSE;

      

       return TRUE;  // return TRUE  unless you set the focus to a control

}

 

// 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 CScanDiskDlg::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 CScanDiskDlg::OnQueryDragIcon()

{

       return (HCURSOR) m_hIcon;

}

 

 

void CScanDiskDlg::OnBstart()

{

if(Status==FALSE){

  m_List.ResetContent();

  TotalFileNum=0;

  Status=TRUE;

  SubThread=(CWinThread*)AfxBeginThread(&ThreadProc,this,THREAD_PRIORITY_BELOW_NORMAL,0,0);

  m_Bstart.SetWindowText("停止");

}

else{

  Status=FALSE;

  m_Bstart.SetWindowText("开始");

}    

}

 

void CScanDiskDlg::OnBstop()

{

Status=FALSE;

ExitProcess(0);&nb

补充:综合编程 , 安全编程 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,