import hashlib import tkinter as tk from tkinter import filedialog, messagebox import os

class ScanWindow(tk.Tk): def init(self): super().init() self.title("毒驱")

    # 创建界面元素
    self.select_button = tk.Button(self, text="选择文件或文件夹", command=self.select_file_or_folder)
    self.select_button.pack()
    
    self.scan_button = tk.Button(self, text="开始扫描", command=self.scan_virus)
    self.scan_button.pack()
    
    self.progress_bar = tk.ttk.Progressbar(self, length=200)
    self.progress_bar.pack()
    
    self.background_label = tk.Label(self)
    self.background_label.pack()
    
    self.scan_type = "快速扫描"
    
    # 导入病毒库文件
    with open("file_to_scan/file1.db", "rb") as f:
        self.virus_library = f.read().splitlines()

def select_file_or_folder(self):
    file_path = filedialog.askopenfilename()
    if not file_path:
        return
    # 扫描选定的文件或文件夹的代码
    scan_result = self.scan_file_or_folder(file_path)
    if scan_result:
        messagebox.showinfo("扫描结果", "检测到病毒")
    else:
        messagebox.showinfo("扫描结果", "未检测到病毒")

def scan_file_or_folder(self, path):
    if not os.path.exists(path):
        return False
    # 检查文件是否是病毒
    with open(path, "rb") as file:
        file_hash = hashlib.md5(file.read()).hexdigest()
        if file_hash in self.virus_library:
            return True
    
    # 检查文件夹中的所有文件是否是病毒
    if os.path.isdir(path):
        for root, dirs, files in os.walk(path):
            for file in files:
                file_path = os.path.join(root, file)
                with open(file_path, "rb") as f:
                    file_hash = hashlib.md5(f.read()).hexdigest()
                    if file_hash in self.virus_library:
                        return True
    
    return False

def scan_virus(self):
    self.progress_bar.start()
    
    # 模拟扫描过程
    import time
    time.sleep(5)
    
    if self.scan_type == "快速扫描":
        # 检测到病毒
        self.progress_bar.stop()
        messagebox.showinfo("扫描完成", "检测到病毒")
        self.background_image = tk.PhotoImage(file="infected_background.png")
        self.background_label.config(image=self.background_image)
        self.background_label.image = self.background_image
    else:
        # 未检测到病毒
        self.progress_bar.stop()
        messagebox.showinfo("扫描完成", "未检测到病毒")

if name == "main": scan_window = ScanWindow() scan_window.mainloop(

让这串代码导入本地文件夹里面的file_to_scan文件夹里面的所有Data Base File格式的所有文件并修复代码中的错误:import hashlibimport tkinter as tkfrom tkinter import filedialog messageboximport osclass ScanWindowtkTk def __init__self su

原文地址: http://www.cveoy.top/t/topic/ivqR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录