HgTrojan的软件检测工具
源码
import os
import tkinter as tk
from tkinter import messagebox
from tkinter import ttk
import subprocess
import time
# 获取已安装软件的列表
def get_installed_software(progress=None, window=None):
installed_software = []
try:
output = subprocess.check_output(['wmic', 'product', 'get', 'name'])
output = output.decode().split('\n')[1:]
total_lines = len(output)
for index, line in enumerate(output):
line = line.strip()
if line:
installed_software.append(line)
# 更新进度条
if progress and window:
progress['value'] = (index + 1) / total_lines * 100
window.update_idletasks()
if window:
time.sleep(3) # 模拟处理时间
window.destroy()
except Exception as e:
print(f"Error retrieving installed software: {e}")
return installed_software
# 生成list.txt文件
def generate_list_file(selected_software):
with open('list.txt', 'w') as file:
for software in selected_software:
file.write(software + '\n')
messagebox.showinfo("生成完成", "list.txt文件已生成")
# 显示进度条窗口
def show_progress_window(task):
window = tk.Toplevel()
window.title("请稍候")
window.geometry("300x100")
progress = ttk.Progressbar(window, orient="horizontal", mode="determinate", length=280)
progress.pack(pady=20)
window.update_idletasks()
task(progress, window)
# 检测list.txt中的软件是否已安装
def check_software():
missing_software = []
def task(progress, window):
if os.path.exists('list.txt'):
with open('list.txt', 'r') as file:
required_software = file.read().splitlines()
installed_software = get_installed_software(progress, window)
for software in required_software:
if software not in installed_software:
missing_software.append(software)
if window:
window.update_idletasks()
if missing_software:
messagebox.showwarning("检测结果", f"缺少以下软件:\n" + "\n".join(missing_software))
else:
messagebox.showinfo("检测结果", "检测完毕,全部安装")
else:
messagebox.showwarning("错误", "list.txt文件不存在")
if window:
window.after(3000, window.destroy)
show_progress_window(task)
# 清除list.txt文件
def clear_list_file():
if os.path.exists('list.txt'):
os.remove('list.txt')
messagebox.showinfo("清除完成", "list.txt文件已删除")
else:
messagebox.showwarning("错误", "list.txt文件不存在")
# 创建主界面
def create_main_window():
root = tk.Tk()
root.title("HgTrojan的软件检测工具")
root.geometry("500x600")
if os.path.exists('list.txt'):
frame = tk.Frame(root)
frame.pack(fill=tk.BOTH, expand=True)
check_button = tk.Button(frame, text="检测", command=check_software)
check_button.grid(row=0, column=0, padx=10, pady=10, sticky='ew')
clear_button = tk.Button(frame, text="清除配置", command=clear_list_file)
clear_button.grid(row=0, column=1, padx=10, pady=10, sticky='ew')
frame.grid_columnconfigure(0, weight=1)
frame.grid_columnconfigure(1, weight=1)
else:
progress_window = tk.Toplevel(root)
progress_window.title("请稍候")
progress_window.geometry("300x100")
progress = ttk.Progressbar(progress_window, orient="horizontal", mode="determinate", length=280)
progress.pack(pady=20)
progress_window.update_idletasks()
installed_software = get_installed_software(progress, progress_window)
selected_software = []
frame = tk.Frame(root)
frame.pack(fill=tk.BOTH, expand=True)
canvas = tk.Canvas(frame)
scrollbar = tk.Scrollbar(frame, orient="vertical", command=canvas.yview)
scrollable_frame = tk.Frame(canvas)
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion=canvas.bbox("all")
)
)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
for software in installed_software:
var = tk.BooleanVar()
checkbox = tk.Checkbutton(scrollable_frame, text=software, variable=var)
checkbox.pack(anchor='w')
selected_software.append((software, var))
def on_generate():
selected = [software for software, var in selected_software if var.get()]
generate_list_file(selected)
generate_button = tk.Button(root, text="生成list.txt", command=on_generate)
generate_button.pack(pady=20, fill=tk.X)
root.mainloop()
if __name__ == "__main__":
create_main_window()
打包好的可执行文件
打赏: 支付宝
本人所有文章均为技术分享,均用于防御为目的的记录,所有操作均在实验环境下进行,请勿用于其他用途,否则后果自负。 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!