ساخت یک آنتی ویروس به نام Chitartin با پایتون

خب با استفاده از کد زیر کتابخانه لازم را نصب کنید :

pip install psutil

حالا کد زیر را بزنید در پایتون :

import tkinter as tk
from tkinter import ttk, messagebox, filedialog
import threading
import time
import os
import json
import shutil
import ctypes
import sys
from datetime import datetime
from pathlib import Path

# نیاز به نصب: pip install psutil
try:
    import psutil
except ImportError:
    psutil = None

# -------------------- CONFIG & CONSTANTS --------------------
APP_NAME = "Chitartin Antivirus"
DATA_DIR = Path.home() / "GapAV_Pro_Data"
QUARANTINE_DIR = DATA_DIR / "Quarantine"
HISTORY_FILE = DATA_DIR / "threat_history.json"
DOWNLOADS_DIR = Path.home() / "Downloads"

for d in [DATA_DIR, QUARANTINE_DIR]:
    d.mkdir(exist_ok=True)

# Professional Color Palette (Cybersecurity Theme)
COLOR_BG = "#0a0f1a"
COLOR_CARD = "#161e2d"
COLOR_ACCENT = "#00d4ff"  # Neon Blue
COLOR_DANGER = "#ff4d4d"  # Soft Red
COLOR_SUCCESS = "#00ff88" # Neon Green
COLOR_TEXT = "#e2e8f0"
COLOR_SECONDARY = "#94a3b8"

# -------------------- UTILS --------------------
def is_admin():
    try: return ctypes.windll.shell32.IsUserAnAdmin()
    except: return False

def run_as_admin():
    try:
        script = os.path.abspath(sys.argv[0])
        params = ' '.join([f'"{arg}"' for arg in sys.argv[1:]])
        ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, f'"{script}" {params}', None, 1)
        return True
    except: return False

# -------------------- CORE ENGINE --------------------
class SecurityEngine:
    def __init__(self):
        self.history = self.load_history()

    def load_history(self):
        if HISTORY_FILE.exists():
            try:
                with open(HISTORY_FILE, 'r') as f:
                    return json.load(f)
            except:
                return []
        return []

    def save_history(self):
        with open(HISTORY_FILE, 'w') as f:
            json.dump(self.history, f, indent=4)

    def scan_file(self, file_path):
        """Advanced Heuristic Scanning"""
        try:
            p = Path(file_path)
            if not p.exists(): return False, ""
            
            name = p.name.lower()
            ext = p.suffix.lower()
            
            # Suspicious patterns
            bad_keywords = ["crack", "patch", "keygen", "hack", "trojan", "miner", "stealer", "malware"]
            suspicious_exts = {".exe", ".bat", ".vbs", ".scr", ".cmd", ".ps1", ".js", ".msi"}

            if ext in suspicious_exts:
                if any(k in name for k in bad_keywords):
                    return True, "Malware Signature Detected"
                if p.stat().st_size < 70000:
                    return True, "Heuristic: Suspiciously Small Executable"
            
            return False, ""
        except Exception as e:
            return False, str(e)

    def quarantine(self, file_path, reason):
        try:
            src = Path(file_path)
            ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            file_name = src.name
            dest_name = f"{datetime.now().strftime('%Y%m%d_%H%M%S')}_{file_name}"
            dest_path = QUARANTINE_DIR / dest_name
            
            shutil.move(str(src), str(dest_path))
            
            # Add to history
            entry = {
                "timestamp": ts,
                "file": file_name,
                "reason": reason,
                "location": str(dest_path)
            }
            self.history.append(entry)
            self.save_history()
            return True, str(dest_path)
        except Exception as e:
            return False, str(e)

# -------------------- GUI APPLICATION --------------------
class GapAVProApp:
    def __init__(self, root):
        self.root = root
        self.root.title(f"{APP_NAME} - Enterprise Edition")
        self.root.geometry("1100x750")
        self.root.configure(bg=COLOR_BG)

        self.engine = SecurityEngine()
        self.stop_event = threading.Event()
        
        # States
        self.is_protected = False
        self.is_monitoring = False
        self.is_watching = False

        self.build_ui()
        self.log("System Booted. All modules standby.")

    def build_ui(self):
        # --- Header ---
        header = tk.Frame(self.root, bg=COLOR_CARD, height=70)
        header.pack(fill="x", side="top")
        
        tk.Label(header, text=f"🛡️ {APP_NAME}", bg=COLOR_CARD, fg=COLOR_ACCENT, 
                 font=("Segoe UI", 20, "bold")).pack(side="left", padx=25, pady=15)

        self.admin_badge = tk.Label(header, text="ADMIN MODE" if is_admin() else "USER MODE", 
                                    bg=COLOR_SUCCESS if is_admin() else COLOR_DANGER,
                                    fg="black", font=("Segoe UI", 9, "bold"), padx=10)
        self.admin_badge.pack(side="right", padx=25)

        # --- Dashboard Container ---
        container = tk.Frame(self.root, bg=COLOR_BG)
        container.pack(fill="both", expand=True, padx=20, pady=15)

        # Left Panel: Controls
        left_panel = tk.Frame(container, bg=COLOR_CARD, highlightthickness=1, highlightbackground="#2d3748")
        left_panel.place(relx=0, rely=0, relwidth=0.45, relheight=0.6)

        tk.Label(left_panel, text="SECURITY CONTROL", bg=COLOR_CARD, fg=COLOR_TEXT, 
                 font=("Segoe UI", 16, "bold")).pack(pady=20)

        # Protection Toggle
        self.btn_protect = self.create_toggle_btn(left_panel, "Real-Time Protection", self.toggle_protection)
        self.btn_monitor = self.create_toggle_btn(left_panel, "System Intelligence", self.toggle_monitor)
        self.btn_watcher = self.create_toggle_btn(left_panel, "File Watcher", self.toggle_watcher)

        # Manual Scan Button
        tk.Button(left_panel, text="🔍 Manual Deep Scan", bg=COLOR_ACCENT, fg=COLOR_BG,
                 font=("Segoe UI", 11, "bold"), width=25, height=2, command=self.manual_scan).pack(pady=10)

        # Settings & Info
        tk.Button(left_panel, text="⚙️ System Settings", bg="#2d3748", fg=COLOR_TEXT,
                 font=("Segoe UI", 10), width=25, command=self.open_settings).pack(pady=5)

        # Right Panel: Intelligence & Stats
        right_panel = tk.Frame(container, bg=COLOR_CARD, highlightthickness=1, highlightbackground="#2d3748")
        right_panel.place(relx=0.5, rely=0, relwidth=0.5, relheight=0.6)

        tk.Label(right_panel, text="LIVE INTELLIGENCE", bg=COLOR_CARD, fg=COLOR_TEXT, 
                 font=("Segoe UI", 16, "bold")).pack(pady=15)

        self.cpu_stat = self.create_stat_row(right_panel, "CPU Load", "0%")
        self.ram_stat = self.create_stat_row(right_panel, "RAM Usage", "0%")
        self.proc_stat = self.create_stat_row(right_panel, "Active Processes", "0")
        self.health_stat = self.create_stat_row(right_panel, "System Health", "Optimal")

        # Bottom Panel: Logs & History
        bottom_panel = tk.Frame(container, bg=COLOR_CARD)
        bottom_panel.place(relx=0, rely=0.62, relwidth=1, relheight=0.38)

        # Tabs for Logs and History
        tab_control = ttk.Notebook(bottom_panel)
        tab_control.pack(fill="both", expand=True, padx=10, pady=10)

        self.log_box = tk.Text(tab_control, bg="#0a0f1a", fg=COLOR_SECONDARY, font=("Consolas", 10), state="disabled")
        tab_control.add(self.log_box, text=" Real-time Logs ")

        self.history_box = tk.Text(tab_control, bg="#0a0f1a", fg=COLOR_SUCCESS, font=("Consolas", 10), state="disabled")
        tab_control.add(self.history_box, text=" Threat History ")

        self.refresh_history_ui()

    def create_toggle_btn(self, parent, text, command):
        frame = tk.Frame(parent, bg=COLOR_CARD)
        frame.pack(fill="x", padx=30, pady=5)
        
        lbl = tk.Label(frame, text=text, bg=COLOR_CARD, fg=COLOR_TEXT, font=("Segoe UI", 11))
        lbl.pack(side="left")
        
        btn = tk.Button(frame, text="OFF", bg=COLOR_DANGER, fg="white", width=6, 
                        font=("Segoe UI", 9, "bold"), command=command)
        btn.pack(side="right")
        return btn

    def create_stat_row(self, parent, label, value):
        row = tk.Frame(parent, bg=COLOR_CARD)
        row.pack(fill="x", padx=40, pady=10)
        tk.Label(row, text=label, bg=COLOR_CARD, fg=COLOR_SECONDARY, font=("Segoe UI", 11)).pack(side="left")
        val_lbl = tk.Label(row, text=value, bg=COLOR_CARD, fg=COLOR_ACCENT, font=("Segoe UI", 12, "bold"))
        val_lbl.pack(side="right")
        return val_lbl

    # -------------------- LOGIC --------------------
    def log(self, msg, level="INFO"):
        ts = datetime.now().strftime("%H:%M:%S")
        color = COLOR_TEXT
        if level == "CRITICAL": color = COLOR_DANGER
        elif level == "SUCCESS": color = COLOR_SUCCESS
        
        self.log_box.config(state="normal")
        self.log_box.insert("end", f"[{ts}] [{level}] {msg}\n")
        self.log_box.see("end")
        self.log_box.config(state="disabled")

    def refresh_history_ui(self):
        self.history_box.config(state="normal")
        self.history_box.delete("1.0", tk.END)
        for item in reversed(self.engine.history):
            self.history_box.insert("end", f"{item['timestamp']} | {item['file']} | {item['reason']}\n")
        self.history_box.config(state="disabled")

    def toggle_protection(self):
        self.is_protected = not self.is_protected
        self.btn_protect.config(text="ON" if self.is_protected else "OFF", 
                                bg=COLOR_SUCCESS if self.is_protected else COLOR_DANGER)
        self.log(f"Protection {'enabled' if self.is_protected else 'disabled'}.", "SUCCESS")

    def toggle_monitor(self):
        self.is_monitoring = not self.is_monitoring
        self.btn_monitor.config(text="ON" if self.is_monitoring else "OFF", 
                                bg=COLOR_SUCCESS if self.is_monitoring else COLOR_DANGER)
        if self.is_monitoring:
            threading.Thread(target=self.system_monitor_loop, daemon=True).start()
        self.log(f"System Intelligence {'enabled' if self.is_monitoring else 'disabled'}.", "SUCCESS")

    def toggle_watcher(self):
        self.is_watching = not self.is_watching
        self.btn_watcher.config(text="ON" if self.is_watching else "OFF", 
                                bg=COLOR_SUCCESS if self.is_watching else COLOR_DANGER)
        self.log(f"File Watcher {'enabled' if self.is_watching else 'disabled'}.", "SUCCESS")

    def manual_scan(self):
        file_path = filedialog.askopenfilename(title="Select File to Scan")
        if not file_path:
            return
        
        self.log(f"Scanning file: {file_path}")
        detected, reason = self.engine.scan_file(file_path)
        if detected:
            ok, result = self.engine.quarantine(file_path, reason)
            if ok:
                self.log(f"Threat quarantined: {result}", "CRITICAL")
                messagebox.showwarning("Threat Detected", f"File quarantined:\n{result}")
                self.refresh_history_ui()
            else:
                self.log(f"Quarantine failed: {result}", "CRITICAL")
        else:
            self.log("No threat detected.", "SUCCESS")
            messagebox.showinfo("Scan Result", "No threat detected.")

    def open_settings(self):
        win = tk.Toplevel(self.root)
        win.title("Settings")
        win.geometry("420x260")
        win.configure(bg=COLOR_BG)

        tk.Label(win, text="System Settings", bg=COLOR_BG, fg=COLOR_ACCENT,
                 font=("Segoe UI", 16, "bold")).pack(pady=15)

        tk.Label(win, text=f"Quarantine Folder:\n{QUARANTINE_DIR}", bg=COLOR_BG, fg=COLOR_TEXT,
                 wraplength=380, justify="left").pack(pady=10)

        tk.Button(win, text="Open Quarantine Folder", bg=COLOR_ACCENT, fg=COLOR_BG,
                 command=lambda: os.startfile(str(QUARANTINE_DIR))).pack(pady=5)

        tk.Button(win, text="Close", bg="#2d3748", fg=COLOR_TEXT,
                 command=win.destroy).pack(pady=10)

    def system_monitor_loop(self):
        while self.is_monitoring and not self.stop_event.is_set():
            try:
                if psutil:
                    cpu = psutil.cpu_percent(interval=1)
                    ram = psutil.virtual_memory().percent
                    proc = len(psutil.pids())
                    health = "Optimal" if cpu < 60 and ram < 70 else "Warning" if cpu < 85 else "Critical"

                    self.root.after(0, lambda c=cpu, r=ram, p=proc, h=health: self.update_stats(c, r, p, h))
                time.sleep(1)
            except Exception as e:
                self.root.after(0, lambda: self.log(f"Monitor error: {e}", "CRITICAL"))
                break

    def update_stats(self, cpu, ram, proc, health):
        self.cpu_stat.config(text=f"{cpu}%")
        self.ram_stat.config(text=f"{ram}%")
        self.proc_stat.config(text=str(proc))
        self.health_stat.config(text=health)

    def on_close(self):
        self.stop_event.set()
        self.root.destroy()

# -------------------- MAIN --------------------
if __name__ == "__main__":
    root = tk.Tk()
    app = GapAVProApp(root)
    root.protocol("WM_DELETE_WINDOW", app.on_close)
    root.mainloop()

خب اینم از پروژه امروز

کانال روبیکا من : کانال روبیکا من : https://rubika.ir/artinkarimian3

اگر ایده یا پروژه ای دارید از طریق لینک زیر :
https://formafzar.com/form/zso58
پیام خود را وارد کنید راستی به تمام سوالات شما پاسخ داده میشود .

رمز داخل سایت (جهت نیاز) : artinkarimian125701