fp91gx wrote:
我想問
如何判別autorun.inf
檔案內容中所寫的要執行的程式
並刪除
這段程式碼可以提供給大家作學習嗎
您好,
判斷的程式皆在 KillVirus.py 中,如 0.80 版的 KillVirus.py
| Code:  | 
  
368                     if os.path.isfile(autorun_file): 
369                         f = open(autorun_file, 'r') 
370                         for line in f: 
371                             item = line.split('=')[-1].rstrip() 
375                             full_item = x.DriveLetter + ':\' + item 
376                             if os.path.isfile(full_item): 
377                                 flist.append(full_item) 
378                         f.close() 
379  
380                     # uniq flist 
381                     flist = list(set(flist)) 
  | 
 
370行,為把 autorun.inf 中的每一行分別取出。
371行,把每一行 = (等號) 後面的字串取出。例如 open=vmhr.bat ,則 item 為 vmhr.bat
375行,則把隨身碟磁區加在 item 前,例如隨身碟是 E: ,則 full_item 為 E:\vmhr.bat
而移除的程式,寫在 KillVirus.py 中,例如 0.80 版的 KillVirus.py,
| Code:  | 
  
84                     win32api.SetFileAttributes(item, win32con.FILE_ATTRIBUTE_NORMAL) 
85                     os.remove(item) 
  | 
 
84行,把檔案的屬性 (attrib) 設為一般屬性,如此才可以刪除。
85行,則是把檔案刪除。