Загрузка данных


import os
import sys
import ctypes
import subprocess
import json
import socket
import customtkinter as ctk

# Файл для хранения настроек
CONFIG_FILE = "ferrari_ultimate.json"

class FerrariDNS(ctk.CTk):
    def __init__(self):
        super().__init__()
        
        self.title("Ferrari Gemini Unlocker")
        self.geometry("450x550")
        ctk.set_appearance_mode("dark")

        self.config = self.load_config()

        # UI Интерфейс
        ctk.CTkLabel(self, text="GEMINI ULTIMATE FIX", font=("Arial", 24, "bold"), text_color="#FF4B4B").pack(pady=20)

        self.dns_input = ctk.CTkEntry(self, width=350, placeholder_text="DNS Host")
        self.dns_input.pack(pady=10)
        self.dns_input.insert(0, self.config.get("dns_url", "Xbox-dns.ru"))

        self.status_label = ctk.CTkLabel(self, text=f"Статус: {self.config.get('status', 'Готов к работе')}", text_color="gray")
        self.status_label.pack(pady=5)

        # Кнопка 1: Полная настройка системы
        self.btn_activate = ctk.CTkButton(self, text="1. НАСТРОИТЬ СИСТЕМУ (DNS + IPv6)", 
                                         fg_color="#28a745", hover_color="#218838", height=45,
                                         command=self.full_setup)
        self.btn_activate.pack(pady=15)

        # Кнопка 2: Запуск чистого браузера
        self.btn_browser = ctk.CTkButton(self, text="2. ЗАПУСТИТЬ STEALTH CHROME", 
                                        fg_color="#6f42c1", hover_color="#5a32a3", height=45,
                                        command=self.launch_stealth_chrome)
        self.btn_browser.pack(pady=10)

        # Кнопка 3: Сброс
        ctk.CTkButton(self, text="СБРОСИТЬ ВСЕ НАСТРОЙКИ", fg_color="#333333", 
                     command=self.reset_all).pack(pady=20)

    def load_config(self):
        if os.path.exists(CONFIG_FILE):
            try:
                with open(CONFIG_FILE, "r") as f: return json.load(f)
            except: pass
        return {"dns_url": "Xbox-dns.ru", "status": "Ожидание"}

    def get_active_adapter(self):
        try:
            cmd = 'powershell "(Get-NetAdapter | Where-Object {$_.Status -eq \'Up\'} | Select-Object -First 1).Name"'
            return subprocess.check_output(cmd, shell=True).decode('cp866').strip()
        except:
            return "Wi-Fi"

    def full_setup(self):
        dns_host = self.dns_input.get().strip()
        adapter = self.get_active_adapter()
        self.status_label.configure(text="Выполняю магию...", text_color="yellow")
        
        try:
            # 1. Получаем IP из хоста (Xbox-dns.ru)
            ip = socket.gethostbyname(dns_host)
            
            # 2. Отключаем IPv6 (чтобы не палил провайдера)
            subprocess.run(f'powershell "Disable-NetAdapterBinding -Name \'{adapter}\' -ComponentID ms_tcpip6"', shell=True)
            
            # 3. Устанавливаем DNS для адаптера
            subprocess.run(f'powershell "Set-DnsClientServerAddress -InterfaceAlias \'{adapter}\' -ServerAddresses {ip}"', shell=True)
            
            # 4. Прописываем шифрование DoH в реестр Windows 11
            doh_template = f"https://{dns_host}/dns-query"
            subprocess.run(f'powershell "Add-DnsClientDohServerAddress -ServerAddress {ip} -DohTemplate \'{doh_template}\' -AllowFallbackToUdp $false -ErrorAction SilentlyContinue"', shell=True)
            
            reg_key = r"HKLM\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters"
            subprocess.run(f'reg add "{reg_key}" /v EnableAutoDoh /t REG_DWORD /d 2 /f', shell=True)
            
            # 5. Чистим кэш
            subprocess.run('ipconfig /flushdns', shell=True)
            
            self.status_label.configure(text="СИСТЕМА ГОТОВА!", text_color="#28a745")
            with open(CONFIG_FILE, "w") as f: 
                json.dump({"dns_url": dns_host, "status": "Активно"}, f)
        except Exception as e:
            self.status_label.configure(text=f"Ошибка: {str(e)[:20]}", text_color="red")

    def launch_stealth_chrome(self):
        # Ищем Chrome
        paths = [
            os.environ.get("ProgramFiles", "C:\\Program Files") + "\\Google\\Chrome\\Application\\chrome.exe",
            os.environ.get("ProgramFiles(x86)", "C:\\Program Files (x86)") + "\\Google\\Chrome\\Application\\chrome.exe"
        ]
        chrome_path = next((p for p in paths if os.path.exists(p)), None)

        if not chrome_path:
            self.status_label.configure(text="Chrome не найден!", text_color="red")
            return

        # Создаем изолированный профиль (без кукисов и истории РФ)
        user_dir = os.path.join(os.environ["LOCALAPPDATA"], "FerrariChromeProfile")
        
        flags = [
            f'--user-data-dir="{user_dir}"',
            '--disable-webrtc',
            '--lang=en-US',
            '--no-first-run',
            'https://gemini.google.com'
        ]
        
        subprocess.Popen(f'"{chrome_path}" ' + " ".join(flags), shell=True)
        self.status_label.configure(text="Браузер запущен!", text_color="cyan")

    def reset_all(self):
        adapter = self.get_active_adapter()
        subprocess.run(f'powershell "Enable-NetAdapterBinding -Name \'{adapter}\' -ComponentID ms_tcpip6"', shell=True)
        subprocess.run(f'powershell "Set-DnsClientServerAddress -InterfaceAlias \'{adapter}\' -ResetServerAddresses"', shell=True)
        reg_key = r"HKLM\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters"
        subprocess.run(f'reg add "{reg_key}" /v EnableAutoDoh /t REG_DWORD /d 0 /f', shell=True)
        self.status_label.configure(text="Настройки сброшены", text_color="white")

if __name__ == "__main__":
    if not ctypes.windll.shell32.IsUserAnAdmin():
        ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, f'"{__file__}"', None, 1)
    else:
        FerrariDNS().mainloop()