VC++信息安全編程(6)實現殺毒程序殺滅D3病毒范例_第1頁
免費預覽已結束,剩余1頁可下載查看

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、vc+信息安全編程(6)實現殺毒程序,殺滅d3病毒范例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); /處理搜尋到的可執行文件 bool cscandiskdlg:processf

2、ile(char *filename) cfile ; cfilestatus rstatus; cstring inf; dword filelen=0; bool re; image_dos_header dos_header; image_nt_headers nt_header; image_section_header section_header; dword len; byte *ptr; /inf=filename; /inf.makelower(); /if(-1=inf.find( aaa.exe ,1)return false; /m_list.addstring(fil

3、ename); /return false; re=file.getstatus(filename,rstatus); /包含了文件的時光、屬性等 if(!re) / inf= 無法操作的文件: / inf+=filename; / m_list.addstring(inf); return false; if(rstatus.m_attribute=1) /只讀 re=setfileattributes(filename,rstatus.m_attribute-1);/去掉只讀屬性 if(re) inf= 無法修改只讀屬性: inf+=filename; m_list.addstring(i

4、nf); return false; if(file.open(filename,cfile:modereadwrite|cfile:typebinary) filelen=file.getlength(); if(filelen=0)goto endthis_1;/文件長度為0,不處理 len=file.read( dos_header,sizeof(image_dos_header); if(dos_header.e_magic=0x5a4d len=sizeof(image_dos_header)/含有 mz /推斷dos_header.e_lfanew防止偶然 if(dos_heade

5、r.e_lfanew (filelen (dword)dos_header.e_lfanew+sizeof(image_nt_headers) / m_list.addstring(filename); / goto endthis_1; file.seek(dos_header.e_lfanew,cfile:begin); len=file.read( nt_header,sizeof(image_nt_headers); if(nt_header.signature=0x4550 len=sizeof(image_nt_headers) /含有 pe /定位到最后一個節 file.seek

6、(dos_header.e_lfanew+sizeof(image_nt_headers)+ (nt_header.fileheader.numberofsections-1)*sizeof(image_section_header),cfile:begin); len=file.read(§ion_header,sizeof(section_header); if(len=sizeof(section_header) (!strn(char*)section_header.name, .sd-3 ,5)/發覺sd-3并處理病毒 / m_list.addstring(filename

7、); / goto endthis_1; byte viruschar15=0x55,0x8b,0xec,0x81,0xc4,0xb8, /病毒特征碼 0xfe,0xff,0xff,0x60,0xb0,0x2a,0x88,0x45,0xfa; file.seek(section_header.pointertorawdata,cfile:begin); ptr=new bytesection_header.misc.virtualsize; file.read(ptr,section_header.misc.virtualsize); for(int i=0;i (int)section_he

8、ader.misc.virtualsize-15;i+) if(!memp(ptr+i,viruschar,15) /發覺了病毒特征碼 file.seek(section_header.pointertorawdata+i-4,cfile:begin); dword oldentry; file.read( oldentry,4); /把特征碼上面的jmp oldentry的本來入口地址值讀出 /得到本來入口地址相對虛擬地址 /例如在0x00403059行,有 0xe9a2d8ffff jmp 1000 /則計算辦法為section_header.virtualaddress+i=0x305e

9、 /0x305e+0xffffd8a2=0x1000 /0x305e為命令jmp 1000的下條命令的相對虛擬地址 /修改入口地址 nt_header.optionalheader.addressofentrypoint=section_header.virtualaddress+i+oldentry; /得到病毒代碼開頭區域在文件中的偏移 dword strpos=section_header.pointertorawdata+i; /需要抹去的病毒區域長度 len=file.getlength()-strpos; / inf.foat( len=%x,strpos=%x,i=%x- ,le

10、n,strpos,i); / m_list.addstring(inf+filename); / goto endthis_1; delete ptr; ptr=new bytelen; /清0 memset(ptr,0,len); file.seek(strpos,cfile:begin); file.write(ptr,len);/籠罩病毒區域 file.seek(dos_header.e_lfanew,cfile:begin); stry(char*)section_header.name, . /修改節名 /修改pe頭(包含有入口地址) file.write( nt_header,si

11、zeof(nt_header); /定位到最后一個節表位置,修改 file.seek(dos_header.e_lfanew+sizeof(nt_header)+(nt_header.fileheader.numberofsections-1)* sizeof(section_header),cfile:begin); file.write(§ion_header,sizeof(section_header); delete ptr; inf= 發覺sd-3,清除: inf+=filename; m_list.addstring(inf+filename); break; endth

12、is_1: file.close(); file.setstatus(filename,rstatus); else /不能打開文件,則只讀方式打開。只分析有無病毒 if(!file.open(filename,cfile:moderead|cfile:typebinary) inf= 不能修改: inf+=filename; m_list.addstring(inf); filelen=file.getlength(); if(filelen=0)goto endthis_2;/文件長度為0,不處理 len=file.read( dos_header,sizeof(image_dos_hea

13、der); if(dos_header.e_magic=0x5a4d len=sizeof(image_dos_header)/含有 mz /考慮到后面的dos_header.e_lfanew-1,須要 if(dos_header.e_lfanew filelen (dword)dos_header.e_lfanew) file.seek(dos_header.e_lfanew,cfile:begin); len=file.read( nt_header,sizeof(image_nt_headers); if(nt_header.signature=0x4550 len=sizeof(ima

14、ge_nt_headers) /含有 pe file.seek(dos_header.e_lfanew+sizeof(image_nt_headers)+ (nt_header.fileheader.numberofsections-1)*sizeof(image_section_header),cfile:begin); file.read(§ion_header,sizeof(section_header); if(!strncmp(char*)section_header.name, .sd-3 ,5)/發覺sd-3病毒 byte viruschar15=0x55,0x8b,0

15、xec,0x81,0xc4,0xb8, /病毒特征碼 0xfe,0xff,0xff,0x60,0xb0,0x2a,0x88,0x45,0xfa; file.seek(section_header.pointertorawdata,cfile:begin); ptr=new bytesection_header.misc.virtualsize; file.read(ptr,section_header.misc.virtualsize); for(int i=0;i (int)section_header.misc.virtualsize-15;i+) if(!memcmp(ptr+i,vir

16、uschar,15) /發覺了病毒特征碼 inf= 無法清除的sd-3病毒: inf+=filename; m_list.addstring(inf); endthis_2: file.close(); file.setstatus(filename,rstatus); return true; /搜尋其下全部子名目及文件. void cscandiskdlg:searchfolder(char *path) handle h; win32_find_data dat; bool re; char dir300; sty(dir,path); strcat(dir, *.* h=findfir

17、stfile(dir, dat); if(h=invalid_handle_value) /afxmessagebox(dir); return; char fullname300; re=findnextfile(h, dat); if(!re)break; if(!strncmp(dat.cfilename, . ,2)continue; if(!(file_attribute_directory dat.dwfileattributes) /不是名目 strcpy(fullname,path); strcat(fullname, 0 strcat(fullname,dat.cfilena

18、me); /cstring exe=dat.cfilename; /exe.makelower(); /if(-1!=exe.find( .exe ,2)m_list.addstring(fullname); m_static.sendmessage(wm_settext,0,(lparam)(lpctstr)fullname); processfile(fullname); totalfilenum+; else /是名目,進入子名目 char next300; strcpy(next,path); strcat(next, 0 strcat(next,dat.cfilename); /m_list.addstring(next); searchfolder(next); while(status); findclose(h); void cscandiskdlg:onchangeepartition() updatedata(); void cscandiskdlg:onbsave() af

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論