ShaDuPage.cpp
上传用户:shouhua
上传日期:2014-12-06
资源大小:5685k
文件大小:10k
- // ShaDuPage.cpp : implementation file
- //
- #include "stdafx.h"
- #include "AntiEvilTools.h"
- #include "ShaDuPage.h"
- #include "Dbt.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- MyList *Gogogo4;
- DWORD controlbuff[64];
- DWORD dw;
- char outputbuff[256];
- DWORD stringcount;
- char * strings[256];
- /////////////////////////////////////////////////////////////////////////////
- // CShaDuPage property page
- threadInfo Info;
- void thread();
- IMPLEMENT_DYNCREATE(CShaDuPage, CPropertyPage)
- CShaDuPage::CShaDuPage() : CPropertyPage(CShaDuPage::IDD)
- {
- //{{AFX_DATA_INIT(CShaDuPage)
- m_Radio = 0;
- IsMonitor=false;
- m_1 = TRUE;
- m_2 = TRUE;
- m_3 = TRUE;
- IsChaDu=false;
- m_4 = TRUE;
- m_5 = TRUE;
- m_6 = TRUE;
- m_7 = TRUE;
- m_8 = TRUE;
- m_9 = TRUE;
- //}}AFX_DATA_INIT
- }
- CShaDuPage::~CShaDuPage()
- {
- }
- void CShaDuPage::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CShaDuPage)
- DDX_Control(pDX, IDC_LIST_CHADU, m_ChaDu);
- DDX_Control(pDX, IDC_CHECK2, m_Check2);
- DDX_Control(pDX, IDC_CHECK1, m_Check1);
- DDX_Control(pDX, IDC_BUTTON_CHOOSE, m_Choose);
- DDX_Control(pDX, IDC_CHECK3, m_Check3);
- DDX_Radio(pDX, IDC_RADIO1, m_Radio);
- DDX_Check(pDX, IDC_CHECK1, m_1);
- DDX_Check(pDX, IDC_CHECK2, m_2);
- DDX_Check(pDX, IDC_CHECK3, m_3);
- DDX_Check(pDX, IDC_CHECK4, m_4);
- DDX_Check(pDX, IDC_CHECK5, m_5);
- DDX_Check(pDX, IDC_CHECK6, m_6);
- DDX_Check(pDX, IDC_CHECK7, m_7);
- DDX_Check(pDX, IDC_CHECK8, m_8);
- DDX_Check(pDX, IDC_CHECK9, m_9);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CShaDuPage, CPropertyPage)
- //{{AFX_MSG_MAP(CShaDuPage)
- ON_BN_CLICKED(IDC_BUTTON_CHOOSE, OnButtonChoose)
- ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
- ON_WM_PAINT()
- //ON_WM_DEVICECHANGE()
- ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
- ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
- ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
- ON_BN_CLICKED(IDC_BUTTON_U, OnButtonU)
- ON_BN_CLICKED(IDC_BUTTON_DEF, OnButtonDef)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CShaDuPage message handlers
- BOOL CShaDuPage::OnInitDialog()
- {
- CDialog::OnInitDialog();
- SetDlgItemText(IDC_STATIC1,"");
- m_Check3.ShowWindow(SW_HIDE);
- m_Choose.ShowWindow(SW_HIDE);
- m_pe_file = new CPEFile(GetSafeHwnd());
- m_pImage = new CImageList();
- ASSERT(m_pImage != NULL); // serious allocation failure checking
- m_ChaDu.SetImageList(m_pImage, LVSIL_SMALL);
- m_ChaDu.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- Gogogo4->InitSystemImageLists(m_ChaDu.m_hWnd);
- int ret=m_ChaDu.InsertColumn(0,"名称",LVCFMT_RIGHT,80,0);
- m_ChaDu.InsertColumn(1,"入口地址",LVCFMT_LEFT,80,1);
- m_ChaDu.InsertColumn(2,"文件大小",LVCFMT_LEFT,80,2);
- m_ChaDu.InsertColumn(3,"有无问题",LVCFMT_LEFT,80,3);
- m_ChaDu.InsertColumn(4,"文件路径",LVCFMT_LEFT,340,4);
- CreateThread(0,0,(LPTHREAD_START_ROUTINE)thread,0,0,&dw);
- DWORD * addr=(DWORD *)(1+(DWORD)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtCreateProcess"));
- ZeroMemory(outputbuff,256);
- controlbuff[0]=addr[0];
- controlbuff[1]=(DWORD)&outputbuff[0];
- return true;
- }
- void CShaDuPage::OnButtonChoose()
- {
- // TODO: Add your control notification handler code here
- }
- void CShaDuPage::OnButtonStart()
- {
- // TODO: Add your control notification handler code here
- SetDlgItemText(IDC_STATIC1,"正在查毒,请等待...");
- CString str;//=_T("C:\windows");
- m_ChaDu.DeleteAllItems();
- IsChaDu=TRUE;
- if(m_1)
- {
- str=_T("C:\windows\system32");
- ShaDu(str);
- }
- if(m_2)
- {
- str=_T("C:\windows");
- //ShaDu(str);
- }
- //SetDlgItemText(IDC_STATIC1,"扫描完成");
- }
- void CShaDuPage::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- if(!IsChaDu)
- {
- SetDlgItemText(IDC_STATIC1,"");
- }
- else
- {
- SetDlgItemText(IDC_STATIC1,"扫描完成");
- }
- // TODO: Add your message handler code here
- // Do not call CPropertyPage::OnPaint() for painting messages
- }
- void CShaDuPage::OnRadio1()
- {
- // TODO: Add your control notification handler code here
- m_Check3.ShowWindow(SW_HIDE);
- m_Choose.ShowWindow(SW_HIDE);
- m_Check1.ShowWindow(SW_SHOW);
- m_Check2.ShowWindow(SW_SHOW);
- }
- void CShaDuPage::OnRadio2()
- {
- // TODO: Add your control notification handler code here
- m_Check3.ShowWindow(SW_SHOW);
- m_Choose.ShowWindow(SW_HIDE);
- m_Check1.ShowWindow(SW_HIDE);
- m_Check2.ShowWindow(SW_HIDE);
- }
- void CShaDuPage::OnRadio3()
- {
- // TODO: Add your control notification handler code here
- m_Check3.ShowWindow(SW_HIDE);
- m_Choose.ShowWindow(SW_SHOW);
- m_Check1.ShowWindow(SW_HIDE);
- m_Check2.ShowWindow(SW_HIDE);
- }
- void CShaDuPage::ShaDu(CString dir)
- {
- Info.m_Dir=dir;
- Info.m_file=m_pe_file;
- Info.m_MyChaDu=&m_ChaDu;
- pThread=AfxBeginThread(ThreadFunc,&Info);
- }
- UINT ThreadFunc(LPVOID lpParam)
- {
- threadInfo* p=(threadInfo*)lpParam;
- CString szDir,str;
- CPEFile *m_pe_file;
- szDir=p->m_Dir;
- m_pe_file=p->m_file;
- MyList *m_ChaDu;
- m_ChaDu=p->m_MyChaDu;
- int index=0;
- if(szDir.Right(1) != "\")
- szDir += "\";
- szDir += "*.*";
- CFileFind ff;
- BOOL res = ff.FindFile(szDir);
- while(res)
- {
- res = ff.FindNextFile();
- if(ff.IsDirectory() && !ff.IsDots())
- {
- //如果是一个子目录,用递归继续往深一层找
- //CShaDuPage *a;
- //CString strPath = ff.GetFilePath();
- //a->ShaDu(strPath);
- }
- else if(!ff.IsDirectory() && !ff.IsDots())
- {
- //显示当前访问的文件
- CString strPath;
- strPath = ff.GetFilePath();
- if((strPath.Right(4)==".exe")||(strPath.Right(4)==".EXE"))
- {
- if (m_pe_file->LoadExecutable((LPSTR)(LPCTSTR)strPath))
- {
- if((float)(m_pe_file->m_nt_header->imageSize-m_pe_file->m_nt_header->entryPoint)/(float)(m_pe_file->m_nt_header->imageSize)<0.003)
- {
- m_ChaDu->InsertItem(index,ff.GetFileName());
- str.Format("%d",m_pe_file->m_nt_header->entryPoint);
- m_ChaDu->SetItemText(index,1,str);
- str.Format("%d",m_pe_file->m_nt_header->imageSize);
- m_ChaDu->SetItemText(index,2,str);
- m_ChaDu->SetItemText(index,3,"有问题");
- m_ChaDu->SetItemText(index,4,strPath);
- m_ChaDu->SetItem(index, 0, LVIF_TEXT | LVIF_IMAGE,ff.GetFileName(),
- Gogogo4->GetFileIcon(strPath), 0, 0, 0);
- index++;
- }
- }
- }
- }
- }
- ff.Close();
- return 0;
- }
- void CShaDuPage::OnButtonU()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- if(m_6)
- {
- HKEY hkey;
- BYTE a[]={0xBD,00,00,00};
- RegOpenKey(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer",&hkey);
- RegSetValueEx(hkey,"NoDriveTypeAutoRun",0,REG_BINARY,a,sizeof(a));
- }
- if(m_4)
- {
- ExaminaU();
- }
- if(m_5)
- {
- IsMonitor=TRUE;
- }
- }
- void CShaDuPage::OnButtonDef()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- if(m_7)
- {
- DeviceIoControl(hDevice,1000,controlbuff,256,controlbuff,256,&dw,0);
- }
- else
- {
- DeviceIoControl(hDevice,1001,NULL,NULL,NULL,NULL,&dw,0);
- }
- if(m_8)
- {
- DeviceIoControl(hDevice,
- 1002,
- controlbuff,
- 256,
- controlbuff,
- 256,
- &dw,
- 0);
- }
- else
- {
- DeviceIoControl(hDevice,
- 1003,
- NULL,
- NULL,
- NULL,
- NULL,
- &dw,
- 0);
- }
- if(m_9)
- {
- DeviceIoControl(hDevice,
- 1004,
- controlbuff,
- 256,
- controlbuff,
- 256,
- &dw,
- 0);
- }
- else
- {
- DeviceIoControl(hDevice,
- 1005,
- NULL,
- NULL,
- NULL,
- NULL,
- &dw,
- 0);
- }
- }
- void thread()
- {
- DWORD a,x; char msgbuff[512];
- char *pdest;
- int result;
- while(1)
- {
- memmove(&a,&outputbuff[0],4);
- if(!a){Sleep(10);continue;}
- char*name=(char*)&outputbuff[8];
- for(x=0;x<stringcount;x++)
- {
- if(!stricmp(name,strings[x])){a=1;goto skip;}
- }
- pdest = strstr(name,"##");
- if (pdest != NULL)
- {
- result = pdest-name;
- strcpy(msgbuff, "是否允许");
- strncat(msgbuff,&outputbuff[8],result);
- strcat(msgbuff,"运行");
- strcat(msgbuff,&outputbuff[result+10]);
- }
- else if((pdest=strstr(name,"$$")) != NULL)
- {
- result = pdest-name;
- strcpy(msgbuff, "是否允许");
- strncat(msgbuff,&outputbuff[8],result);
- strcat(msgbuff,"设置注册表");
- strcat(msgbuff,&outputbuff[result+10]);
- }
- else
- {
- pdest = strstr(name,"&&");
- result = pdest-name;
- strcpy(msgbuff,"是否允许");
- strncat(msgbuff,&outputbuff[8],result);
- strcat(msgbuff,"加载驱动");
- strcat(msgbuff,&outputbuff[result]+10);
- }
- if(IDYES==MessageBox(0, msgbuff,"WARNING",MB_YESNO|MB_ICONQUESTION|0x00200000L))
- {
- a=1;
- strings[stringcount]=_strdup(name);
- stringcount++;
- }
- else a=0;
- skip:memmove(&outputbuff[4],&a,4);
- a=0;
- memmove(&outputbuff[0],&a,4);
- }
- }
- void CShaDuPage::SetHandle(HANDLE handle)
- {
- hDevice=handle;
- }
- void CShaDuPage::ExaminaU()
- {
- CString str;
- for(char i='A';i<'Z';i++)
- {
- char driver[20]={i,':'};
- if((GetDriveType(driver)==DRIVE_REMOVABLE))
- {
- //str.Format("发现U盘%s",driver);
- //MessageBox(str);
- LPCSTR st=strcat(driver,"autorun.inf");
- CFileFind fFind;
- if(fFind.FindFile(st))
- {
- if(MessageBox("发现U盘自启动文件","提示", MB_OKCANCEL) == IDOK)
- {
- DeleteFile(st);
- }
- return;
- }
- }
- }
- MessageBox("没有发现U盘");
- return;
- }
- /*BOOL CShaDuPage::OnDeviceChange(UINT nEventType,DWORD dwData)
- {
- MessageBox("ok");
- if(IsMonitor)
- {
- switch(nEventType)
- {
- case DBT_DEVICEARRIVAL:
- ExaminaU();
- }
- }
- return true;
- }*/