831 lines
30 KiB
Python
831 lines
30 KiB
Python
import os
|
||
import platform
|
||
import json
|
||
import sys
|
||
from colorama import Fore, Style, init, Back
|
||
from enum import Enum
|
||
from typing import Optional
|
||
import subprocess
|
||
|
||
from exit_cursor import ExitCursor
|
||
import patch_cursor_get_machine_id
|
||
from reset_machine import MachineIDResetter
|
||
from member_check import MemberChecker
|
||
|
||
os.environ["PYTHONVERBOSE"] = "0"
|
||
os.environ["PYINSTALLER_VERBOSE"] = "0"
|
||
|
||
import time
|
||
import random
|
||
from cursor_auth_manager import CursorAuthManager
|
||
import os
|
||
from logger import logging
|
||
from browser_utils import BrowserManager
|
||
from get_email_code import EmailVerificationHandler
|
||
from logo import print_logo
|
||
from config import Config
|
||
from datetime import datetime
|
||
from tqdm import tqdm
|
||
|
||
# 定义 EMOJI 字典
|
||
EMOJI = {"ERROR": "❌", "WARNING": "⚠️", "INFO": "ℹ️"}
|
||
|
||
|
||
class VerificationStatus(Enum):
|
||
"""验证状态枚举"""
|
||
|
||
PASSWORD_PAGE = "@name=password"
|
||
CAPTCHA_PAGE = "@data-index=0"
|
||
ACCOUNT_SETTINGS = "Account Settings"
|
||
|
||
|
||
class TurnstileError(Exception):
|
||
"""Turnstile 验证相关异常"""
|
||
|
||
pass
|
||
|
||
|
||
def save_screenshot(tab, stage: str, timestamp: bool = True) -> None:
|
||
"""
|
||
保存页面截图
|
||
|
||
Args:
|
||
tab: 浏览器标签页对象
|
||
stage: 截图阶段标识
|
||
timestamp: 是否添加时间戳
|
||
"""
|
||
try:
|
||
# 创建 screenshots 目录
|
||
screenshot_dir = "screenshots"
|
||
if not os.path.exists(screenshot_dir):
|
||
os.makedirs(screenshot_dir)
|
||
|
||
# 生成文件名
|
||
if timestamp:
|
||
filename = f"turnstile_{stage}_{int(time.time())}.png"
|
||
else:
|
||
filename = f"turnstile_{stage}.png"
|
||
|
||
filepath = os.path.join(screenshot_dir, filename)
|
||
|
||
# 保存截图
|
||
tab.get_screenshot(filepath)
|
||
logging.debug(f"截图已保存: {filepath}")
|
||
except Exception as e:
|
||
logging.warning(f"截图保存失败: {str(e)}")
|
||
|
||
|
||
def check_verification_success(tab) -> Optional[VerificationStatus]:
|
||
"""
|
||
检查验证是否成功,增加超时等待
|
||
"""
|
||
for status in VerificationStatus:
|
||
try:
|
||
if tab.ele(status.value, timeout=10):
|
||
logging.info(f"验证成功 - 已到达{status.name}页面")
|
||
return status
|
||
except Exception as e:
|
||
logging.debug(f"检查{status.name}状态时出错: {str(e)}")
|
||
return None
|
||
|
||
|
||
def handle_turnstile(tab, max_retries: int = 3, retry_interval: tuple = (2, 3)) -> bool:
|
||
"""
|
||
处理 Turnstile 验证
|
||
|
||
Args:
|
||
tab: 浏览器标签页对象
|
||
max_retries: 最大重试次数
|
||
retry_interval: 重试间隔时间范围(最小值, 最大值)
|
||
|
||
Returns:
|
||
bool: 验证是否成功
|
||
"""
|
||
logging.info("正在检测 Turnstile 验证...")
|
||
save_screenshot(tab, "start")
|
||
|
||
retry_count = 0
|
||
|
||
try:
|
||
while retry_count < max_retries:
|
||
retry_count += 1
|
||
logging.debug(f"第 {retry_count} 次尝试验证")
|
||
|
||
try:
|
||
# 定位验证框元素
|
||
challenge_check = (
|
||
tab.ele("@id=cf-turnstile", timeout=5)
|
||
.child()
|
||
.shadow_root.ele("tag:iframe")
|
||
.ele("tag:body")
|
||
.sr("tag:input")
|
||
)
|
||
|
||
if challenge_check:
|
||
logging.info("检测到 Turnstile 验证框,开始处理...")
|
||
# 随机延时后点击验证
|
||
time.sleep(random.uniform(2, 4))
|
||
challenge_check.click()
|
||
time.sleep(3)
|
||
|
||
# 保存验证后的截图
|
||
save_screenshot(tab, "clicked")
|
||
|
||
# 检查验证结果
|
||
if check_verification_success(tab):
|
||
logging.info("Turnstile 验证通过")
|
||
save_screenshot(tab, "success")
|
||
return True
|
||
|
||
except Exception as e:
|
||
logging.debug(f"当前尝试未成功: {str(e)}")
|
||
|
||
# 检查是否已经验证成功
|
||
if check_verification_success(tab):
|
||
return True
|
||
|
||
# 随机延时后继续下一次尝试
|
||
time.sleep(random.uniform(*retry_interval))
|
||
|
||
# 超出最大重试次数
|
||
logging.error(f"验证失败 - 已达到最大重试次数 {max_retries}")
|
||
save_screenshot(tab, "failed")
|
||
return False
|
||
|
||
except Exception as e:
|
||
error_msg = f"Turnstile 验证过程发生异常: {str(e)}"
|
||
logging.error(error_msg)
|
||
save_screenshot(tab, "error")
|
||
raise TurnstileError(error_msg)
|
||
|
||
|
||
def get_cursor_session_token(tab, max_attempts=3, retry_interval=2):
|
||
"""
|
||
获取Cursor会话token,带有重试机制
|
||
:param tab: 浏览器标签页
|
||
:param max_attempts: 最大尝试次数
|
||
:param retry_interval: 重试间隔(秒)
|
||
:return: session token 或 None
|
||
"""
|
||
logging.info("开始获取cookie")
|
||
attempts = 0
|
||
|
||
while attempts < max_attempts:
|
||
try:
|
||
cookies = tab.cookies()
|
||
for cookie in cookies:
|
||
if cookie.get("name") == "WorkosCursorSessionToken":
|
||
return cookie["value"].split("%3A%3A")[1]
|
||
|
||
attempts += 1
|
||
if attempts < max_attempts:
|
||
logging.warning(
|
||
f"第 {attempts} 次尝试未获取到CursorSessionToken,{retry_interval}秒后重试..."
|
||
)
|
||
time.sleep(retry_interval)
|
||
else:
|
||
logging.error(
|
||
f"已达到最大尝试次数({max_attempts}),获取CursorSessionToken失败"
|
||
)
|
||
|
||
except Exception as e:
|
||
logging.error(f"获取cookie失败: {str(e)}")
|
||
attempts += 1
|
||
if attempts < max_attempts:
|
||
logging.info(f"将在 {retry_interval} 秒后重试...")
|
||
time.sleep(retry_interval)
|
||
|
||
return None
|
||
|
||
|
||
def update_cursor_auth(email=None, access_token=None, refresh_token=None):
|
||
"""
|
||
更新Cursor的认证信息的便捷函数
|
||
"""
|
||
auth_manager = CursorAuthManager()
|
||
return auth_manager.update_auth(email, access_token, refresh_token)
|
||
|
||
|
||
def get_verification_code_with_retry(email_handler, max_retries=3):
|
||
"""获取验证码的重试机制"""
|
||
for attempt in range(max_retries):
|
||
try:
|
||
print_status(f"第 {attempt + 1} 次尝试获取验证码...", "info")
|
||
code = email_handler.get_verification_code()
|
||
if code:
|
||
return code
|
||
time.sleep(5) # 等待5秒后重试
|
||
except Exception as e:
|
||
print_status(f"获取验证码出错: {str(e)}", "error")
|
||
if attempt < max_retries - 1:
|
||
print_status("等待重试...", "info")
|
||
time.sleep(5)
|
||
return None
|
||
|
||
|
||
def handle_verification_code(tab, email_handler):
|
||
"""处理验证码输入流程"""
|
||
max_retries = 3
|
||
retry_count = 0
|
||
|
||
while retry_count < max_retries:
|
||
try:
|
||
if tab.ele("Account Settings", timeout=3):
|
||
print_status("注册成功 - 已进入账户设置页面", "success")
|
||
return True
|
||
|
||
if tab.ele("@data-index=0", timeout=3):
|
||
print_status("正在获取邮箱验证码...")
|
||
code = get_verification_code_with_retry(email_handler)
|
||
if not code:
|
||
print_status("获取验证码失败", "error")
|
||
return False
|
||
|
||
print_status(f"成功获取验证码: {code}", "success")
|
||
print_status("正在输入验证码...")
|
||
|
||
# 快速输入验证码
|
||
for i, digit in enumerate(code):
|
||
tab.ele(f"@data-index={i}").input(digit)
|
||
time.sleep(0.1)
|
||
|
||
print_status("验证码输入完成", "success")
|
||
time.sleep(1)
|
||
return True
|
||
|
||
retry_count += 1
|
||
time.sleep(1)
|
||
|
||
except Exception as e:
|
||
print_status(f"验证码处理过程出错: {str(e)}", "error")
|
||
retry_count += 1
|
||
if retry_count < max_retries:
|
||
time.sleep(1)
|
||
continue
|
||
return False
|
||
|
||
return False
|
||
|
||
|
||
def sign_up_account(browser, tab):
|
||
print_step_header("账号注册流程")
|
||
print_status(f"正在访问注册页面: {sign_up_url}")
|
||
tab.get(sign_up_url)
|
||
|
||
try:
|
||
if tab.ele("@name=first_name", timeout=5):
|
||
print_status("正在填写个人信息...")
|
||
|
||
# 快速填写表单
|
||
tab.ele("@name=first_name").input(first_name)
|
||
tab.ele("@name=last_name").input(last_name)
|
||
tab.ele("@name=email").input(account)
|
||
tab.ele("@type=submit").click()
|
||
print_status("个人信息已提交", "success")
|
||
|
||
except Exception as e:
|
||
print_status(f"注册页面访问失败: {str(e)}", "error")
|
||
return False
|
||
|
||
if not handle_turnstile(tab):
|
||
print_status("Turnstile 验证失败", "error")
|
||
return False
|
||
|
||
try:
|
||
if tab.ele("@name=password", timeout=5):
|
||
print_status("正在设置密码...")
|
||
tab.ele("@name=password").input(password)
|
||
tab.ele("@type=submit").click()
|
||
print_status("密码设置完成", "success")
|
||
else:
|
||
print_status("密码输入页面加载超时", "error")
|
||
return False
|
||
|
||
except Exception as e:
|
||
print_status(f"密码设置失败: {str(e)}", "error")
|
||
return False
|
||
|
||
if tab.ele("This email is not available.", timeout=2):
|
||
print_status("注册失败:邮箱已被使用", "error")
|
||
return False
|
||
|
||
if not handle_turnstile(tab):
|
||
print_status("第二次 Turnstile 验证失败", "error")
|
||
return False
|
||
|
||
if not handle_verification_code(tab, email_handler):
|
||
print_status("验证码处理失败", "error")
|
||
return False
|
||
|
||
if not handle_turnstile(tab):
|
||
print_status("最后一次 Turnstile 验证失败", "error")
|
||
return False
|
||
|
||
print_progress("系统处理中", 0.02)
|
||
|
||
print_status("正在获取账户信息...")
|
||
tab.get(settings_url)
|
||
|
||
print_step_header("注册完成")
|
||
print(f"\n{Fore.GREEN}Cursor 账号信息:{Style.RESET_ALL}")
|
||
print(f"{Fore.WHITE}├─ 邮箱: {account}")
|
||
print(f"└─ 密码: {password}{Style.RESET_ALL}")
|
||
|
||
time.sleep(2)
|
||
return True
|
||
|
||
|
||
class EmailGenerator:
|
||
def __init__(
|
||
self,
|
||
password="".join(
|
||
random.choices(
|
||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*",
|
||
k=12,
|
||
)
|
||
),
|
||
):
|
||
configInstance = Config()
|
||
configInstance.print_config()
|
||
self.domain = configInstance.get_domain()
|
||
self.default_password = password
|
||
self.default_first_name = self.generate_random_name()
|
||
self.default_last_name = self.generate_random_name()
|
||
|
||
def generate_random_name(self, length=6):
|
||
"""生成随机用户名"""
|
||
first_letter = random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||
rest_letters = "".join(
|
||
random.choices("abcdefghijklmnopqrstuvwxyz", k=length - 1)
|
||
)
|
||
return first_letter + rest_letters
|
||
|
||
def generate_email(self, length=8):
|
||
"""生成随机邮箱地址"""
|
||
random_str = "".join(random.choices("abcdefghijklmnopqrstuvwxyz", k=length))
|
||
timestamp = str(int(time.time()))[-6:] # 使用时间戳后6位
|
||
return f"{random_str}{timestamp}@{self.domain}"
|
||
|
||
def get_account_info(self):
|
||
"""获取完整的账号信息"""
|
||
return {
|
||
"email": self.generate_email(),
|
||
"password": self.default_password,
|
||
"first_name": self.default_first_name,
|
||
"last_name": self.default_last_name,
|
||
}
|
||
|
||
|
||
def get_user_agent(browser=None):
|
||
"""获取user_agent
|
||
Args:
|
||
browser: 已存在的浏览器实例,如果提供则使用该实例
|
||
"""
|
||
try:
|
||
if browser:
|
||
return browser.latest_tab.run_js("return navigator.userAgent")
|
||
else:
|
||
# 如果没有提供浏览器实例,则创建新的
|
||
browser_manager = BrowserManager()
|
||
browser = browser_manager.init_browser()
|
||
user_agent = browser.latest_tab.run_js("return navigator.userAgent")
|
||
browser_manager.quit() # 仅在新创建的实例时关闭
|
||
return user_agent
|
||
except Exception as e:
|
||
print_status(f"获取user agent失败: {str(e)}", "warning")
|
||
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||
|
||
|
||
def check_cursor_version():
|
||
"""检查cursor版本"""
|
||
pkg_path, main_path = patch_cursor_get_machine_id.get_cursor_paths()
|
||
with open(pkg_path, "r", encoding="utf-8") as f:
|
||
version = json.load(f)["version"]
|
||
return patch_cursor_get_machine_id.version_check(version, min_version="0.45.0")
|
||
|
||
|
||
def reset_machine_id(greater_than_0_45):
|
||
"""执行深度重置,包括设备ID和系统MachineGuid"""
|
||
try:
|
||
print_status("开始执行深度重置...", "info")
|
||
|
||
# 获取路径信息
|
||
storage_path = os.path.expandvars(r"%APPDATA%\Cursor\User\globalStorage\storage.json")
|
||
backup_path = os.path.expandvars(r"%APPDATA%\Cursor\User\globalStorage\backups")
|
||
|
||
# 检查并创建备份目录
|
||
if not os.path.exists(backup_path):
|
||
os.makedirs(backup_path)
|
||
|
||
# 准备 PowerShell 命令
|
||
cmd = f'''
|
||
# 设置输出编码为 UTF-8
|
||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||
$OutputEncoding = [System.Text.Encoding]::UTF8
|
||
|
||
# 配置文件路径
|
||
$STORAGE_FILE = "{storage_path}"
|
||
$BACKUP_DIR = "{backup_path}"
|
||
|
||
# 备份现有配置
|
||
if (Test-Path $STORAGE_FILE) {{
|
||
$backupName = "storage.json.backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
|
||
Copy-Item $STORAGE_FILE "$BACKUP_DIR\\$backupName"
|
||
}}
|
||
|
||
# 生成新的 ID
|
||
function New-StandardMachineId {{
|
||
$template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
|
||
$result = $template -replace '[xy]', {{
|
||
param($match)
|
||
$r = [Random]::new().Next(16)
|
||
$v = if ($match.Value -eq "x") {{ $r }} else {{ ($r -band 0x3) -bor 0x8 }}
|
||
return $v.ToString("x")
|
||
}}
|
||
return $result
|
||
}}
|
||
|
||
$MAC_MACHINE_ID = New-StandardMachineId
|
||
$UUID = [System.Guid]::NewGuid().ToString()
|
||
$prefixBytes = [System.Text.Encoding]::UTF8.GetBytes("auth0|user_")
|
||
$prefixHex = -join ($prefixBytes | ForEach-Object {{ [System.Convert]::ToString($_, 16).PadLeft(2, '0') }})
|
||
$randomPart = -join (1..32 | ForEach-Object {{ [Convert]::ToString((Get-Random -Minimum 0 -Maximum 256), 16).PadLeft(2, '0') }})
|
||
$MACHINE_ID = "$prefixHex$randomPart"
|
||
$SQM_ID = "{{$([System.Guid]::NewGuid().ToString().ToUpper())}}"
|
||
|
||
# 更新配置文件
|
||
$originalContent = Get-Content $STORAGE_FILE -Raw -Encoding UTF8
|
||
$config = $originalContent | ConvertFrom-Json
|
||
|
||
# 更新特定的值
|
||
$config.'telemetry.machineId' = $MACHINE_ID
|
||
$config.'telemetry.macMachineId' = $MAC_MACHINE_ID
|
||
$config.'telemetry.devDeviceId' = $UUID
|
||
$config.'telemetry.sqmId' = $SQM_ID
|
||
|
||
# 保存更新后的配置
|
||
$updatedJson = $config | ConvertTo-Json -Depth 10
|
||
[System.IO.File]::WriteAllText($STORAGE_FILE, $updatedJson, [System.Text.Encoding]::UTF8)
|
||
|
||
# 更新系统 MachineGuid
|
||
$newMachineGuid = [System.Guid]::NewGuid().ToString()
|
||
$registryPath = "HKLM:\\SOFTWARE\\Microsoft\\Cryptography"
|
||
|
||
# 备份原始值
|
||
$originalGuid = (Get-ItemProperty -Path $registryPath -Name "MachineGuid").MachineGuid
|
||
$backupFile = "$BACKUP_DIR\\MachineGuid.backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
|
||
$originalGuid | Out-File $backupFile -Encoding UTF8
|
||
|
||
# 更新注册表
|
||
Set-ItemProperty -Path $registryPath -Name "MachineGuid" -Value $newMachineGuid
|
||
'''
|
||
|
||
# 执行 PowerShell 命令
|
||
process = subprocess.run(
|
||
["powershell", "-NoProfile", "-NonInteractive", "-Command", cmd],
|
||
capture_output=True,
|
||
text=True,
|
||
encoding='utf-8'
|
||
)
|
||
|
||
if process.returncode == 0:
|
||
print_status("深度重置完成", "success")
|
||
if greater_than_0_45:
|
||
patch_cursor_get_machine_id.patch_cursor_get_machine_id()
|
||
else:
|
||
MachineIDResetter().reset_machine_ids()
|
||
return True
|
||
else:
|
||
print_status("深度重置失败", "error")
|
||
return False
|
||
|
||
except Exception as e:
|
||
print_status(f"深度重置出错: {str(e)}", "error")
|
||
return False
|
||
|
||
|
||
def print_menu():
|
||
"""打印美化的菜单"""
|
||
print(f"\n{Fore.CYAN}{'='*60}")
|
||
print(f"{Fore.WHITE} 系统功能选项菜单")
|
||
print(f"{Fore.CYAN}{'='*60}\n")
|
||
|
||
print(f"{Fore.YELLOW}[1]{Fore.WHITE} 仅重置机器码")
|
||
print(f" {Fore.LIGHTBLACK_EX}└─ 快速重置机器码,保持其他设置不变{Style.RESET_ALL}")
|
||
|
||
print(f"\n{Fore.YELLOW}[2]{Fore.WHITE} 一键无痕重置Fast")
|
||
print(f" {Fore.LIGHTBLACK_EX}└─ 执行完整的无痕重置使用量{Style.RESET_ALL}")
|
||
|
||
print(f"\n{Fore.YELLOW}[3]{Fore.WHITE} 深度顽固设备清理")
|
||
print(f" {Fore.LIGHTBLACK_EX}└─ 强制清理所有设备标识和系统指纹{Style.RESET_ALL}")
|
||
|
||
print(f"\n{Fore.CYAN}{'='*60}{Style.RESET_ALL}")
|
||
|
||
|
||
def print_progress(message, delay=0.03):
|
||
"""打印带进度条的提示信息"""
|
||
for i in tqdm(range(100),
|
||
desc=f"{Fore.CYAN}{message}",
|
||
bar_format="{desc}: {percentage:3.0f}%|{bar}| {n_fmt}/{total_fmt}",
|
||
ncols=70):
|
||
time.sleep(delay)
|
||
print(Style.RESET_ALL)
|
||
|
||
|
||
def get_user_input(prompt, valid_options=None):
|
||
"""获取用户输入的美化版本"""
|
||
try:
|
||
print(f"\n{Fore.YELLOW}>>>{Fore.WHITE} {prompt}{Style.RESET_ALL}", end=" ")
|
||
user_input = input().strip()
|
||
|
||
if valid_options and user_input and user_input not in valid_options:
|
||
print(f"{Fore.YELLOW}[提示] 输入无效,请重试{Style.RESET_ALL}")
|
||
return get_user_input(prompt, valid_options)
|
||
|
||
return user_input
|
||
except (KeyboardInterrupt, EOFError):
|
||
print(f"\n{Fore.YELLOW}[提示] 程序已取消{Style.RESET_ALL}")
|
||
sys.exit(0)
|
||
except Exception:
|
||
return ""
|
||
|
||
|
||
def load_last_account():
|
||
"""加载上次使用的账号"""
|
||
try:
|
||
if os.path.exists("last_account.json"):
|
||
with open("last_account.json", "r", encoding="utf-8") as f:
|
||
data = json.load(f)
|
||
return data.get("email"), data.get("last_used")
|
||
except Exception:
|
||
pass
|
||
return None, None
|
||
|
||
|
||
def save_last_account(email):
|
||
"""保存最后使用的账号"""
|
||
try:
|
||
data = {
|
||
"email": email,
|
||
"last_used": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||
}
|
||
with open("last_account.json", "w", encoding="utf-8") as f:
|
||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||
except Exception:
|
||
pass
|
||
|
||
|
||
def verify_member():
|
||
"""验证会员身份"""
|
||
checker = MemberChecker()
|
||
max_retries = 3
|
||
retry_count = 0
|
||
|
||
while retry_count < max_retries:
|
||
try:
|
||
print(f"\n{Fore.CYAN}{'='*30} 会员验证 {'='*30}{Style.RESET_ALL}")
|
||
|
||
# 加载上次使用的账号
|
||
last_email, last_used = load_last_account()
|
||
if last_email:
|
||
print(f"\n{Fore.CYAN}[提示] 上次使用账号: {last_email}")
|
||
print(f" 最后使用时间: {last_used}{Style.RESET_ALL}")
|
||
print(f"\n{Fore.YELLOW}直接按回车使用上次账号,或输入新的邮箱/订单号{Style.RESET_ALL}")
|
||
|
||
keyword = get_user_input("请输入会员邮箱或订单号:")
|
||
|
||
# 如果直接回车且有上次账号记录,使用上次的账号
|
||
if not keyword and last_email:
|
||
keyword = last_email
|
||
print(f"{Fore.CYAN}[信息] 使用上次账号: {keyword}{Style.RESET_ALL}")
|
||
elif not keyword:
|
||
if retry_count < max_retries - 1:
|
||
print(f"{Fore.YELLOW}[提示] 输入为空,请重试{Style.RESET_ALL}")
|
||
retry_count += 1
|
||
continue
|
||
else:
|
||
print(f"{Fore.YELLOW}[提示] 多次输入为空,程序退出{Style.RESET_ALL}")
|
||
sys.exit(0)
|
||
|
||
animate_loading("正在验证会员信息", 2)
|
||
result = checker.check_member(keyword)
|
||
|
||
if result['is_valid']:
|
||
# 保存成功验证的账号
|
||
save_last_account(keyword)
|
||
|
||
print(f"\n{Fore.GREEN}✓ 会员验证通过!{Style.RESET_ALL}")
|
||
print(f"\n{Fore.CYAN}会员详细信息:{Style.RESET_ALL}")
|
||
print(f"{Fore.WHITE}├─ 邮箱: {result['email']}")
|
||
print(f"├─ 订单号: {result['order_id']}")
|
||
print(f"├─ 到期时间: {result['expire_time']}")
|
||
print(f"├─ 使用限制: {result['usage_limit']}")
|
||
print(f"└─ 已使用次数: {result['used_count']}{Style.RESET_ALL}")
|
||
|
||
if result['expire_time']:
|
||
expire_time = datetime.strptime(result['expire_time'], "%Y-%m-%d %H:%M:%S")
|
||
if expire_time < datetime.now():
|
||
print(f"\n{Fore.YELLOW}[提示] 会员已过期,请续费后重试{Style.RESET_ALL}")
|
||
sys.exit(0)
|
||
return result
|
||
|
||
print(f"\n{Fore.YELLOW}[提示] 验证失败: {result['msg']}{Style.RESET_ALL}")
|
||
retry = get_user_input("是否重试? (y/n):", ['y','n'])
|
||
if retry.lower() != 'y':
|
||
print(f"\n{Fore.YELLOW}[提示] 程序已退出{Style.RESET_ALL}")
|
||
sys.exit(0)
|
||
retry_count += 1
|
||
|
||
except Exception as e:
|
||
if retry_count < max_retries - 1:
|
||
print(f"\n{Fore.YELLOW}[提示] 验证过程出现问题,正在重试...{Style.RESET_ALL}")
|
||
retry_count += 1
|
||
time.sleep(1)
|
||
continue
|
||
else:
|
||
print(f"\n{Fore.YELLOW}[提示] 验证失败次数过多,程序退出{Style.RESET_ALL}")
|
||
sys.exit(0)
|
||
|
||
print(f"\n{Fore.YELLOW}[提示] 验证次数已达上限,程序退出{Style.RESET_ALL}")
|
||
sys.exit(0)
|
||
|
||
|
||
def print_status(message, status="info"):
|
||
"""打印状态信息"""
|
||
prefix = {
|
||
"info": f"{Fore.CYAN}[信息]{Style.RESET_ALL}",
|
||
"success": f"{Fore.GREEN}[成功]{Style.RESET_ALL}",
|
||
"error": f"{Fore.RED}[错误]{Style.RESET_ALL}",
|
||
"warning": f"{Fore.YELLOW}[警告]{Style.RESET_ALL}"
|
||
}
|
||
print(f"\n{prefix.get(status, prefix['info'])} {message}")
|
||
|
||
|
||
def animate_loading(message, duration=1):
|
||
"""显示加载动画"""
|
||
chars = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
|
||
start_time = time.time()
|
||
i = 0
|
||
while time.time() - start_time < duration:
|
||
print(f"\r{Fore.CYAN}{chars[i]}{Style.RESET_ALL} {message}", end="")
|
||
time.sleep(0.1)
|
||
i = (i + 1) % len(chars)
|
||
print()
|
||
|
||
|
||
def print_step_header(step_name):
|
||
"""打印步骤标题"""
|
||
print(f"\n{Fore.CYAN}{'='*20} {step_name} {'='*20}{Style.RESET_ALL}")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
try:
|
||
init() # 初始化colorama
|
||
print_logo()
|
||
|
||
print_step_header("系统初始化")
|
||
|
||
# 会员验证
|
||
member_info = verify_member()
|
||
print_progress("初始化程序", 0.02)
|
||
|
||
print_menu()
|
||
choice = get_user_input("请选择操作选项:", ["1", "2", "3"])
|
||
|
||
if choice == "1":
|
||
print_step_header("重置机器码")
|
||
print_progress("正在重置机器码", 0.02)
|
||
|
||
# 先关闭 Cursor 进程
|
||
print_status("正在关闭 Cursor...", "info")
|
||
try:
|
||
subprocess.run(["taskkill", "/F", "/IM", "Cursor.exe"], capture_output=True)
|
||
print_status("Cursor 进程已终止", "success")
|
||
except Exception as e:
|
||
print_status(f"关闭 Cursor 进程失败: {str(e)}", "warning")
|
||
|
||
# 等待进程完全关闭
|
||
time.sleep(2)
|
||
|
||
greater_than_0_45 = check_cursor_version()
|
||
if reset_machine_id(greater_than_0_45):
|
||
print_status("机器码重置完成", "success")
|
||
print_status("请重新启动 Cursor", "info")
|
||
else:
|
||
print_status("机器码重置失败", "error")
|
||
sys.exit(0)
|
||
elif choice == "3":
|
||
print_step_header("深度顽固设备清理")
|
||
print_status("正在启动深度清理程序...", "info")
|
||
|
||
# 先关闭 Cursor
|
||
try:
|
||
subprocess.run(["taskkill", "/F", "/IM", "Cursor.exe"], capture_output=True)
|
||
print_status("Cursor 进程已终止", "success")
|
||
except Exception as e:
|
||
print_status(f"关闭 Cursor 进程失败: {str(e)}", "warning")
|
||
|
||
time.sleep(2)
|
||
|
||
# 以管理员权限运行 full_reset.py
|
||
try:
|
||
subprocess.run([
|
||
"powershell",
|
||
"-Command",
|
||
"Start-Process python -ArgumentList 'full_reset.py' -Verb RunAs -Wait"
|
||
])
|
||
print_status("深度清理完成", "success")
|
||
except Exception as e:
|
||
print_status(f"深度清理失败: {str(e)}", "error")
|
||
sys.exit(0)
|
||
|
||
print_step_header("浏览器初始化")
|
||
animate_loading("正在启动浏览器内核", 2)
|
||
|
||
# 先初始化浏览器
|
||
browser_manager = BrowserManager()
|
||
browser = browser_manager.init_browser()
|
||
|
||
animate_loading("获取系统指纹", 1)
|
||
# 使用已初始化的浏览器获取 user_agent
|
||
user_agent = get_user_agent(browser)
|
||
if "HeadlessChrome" in user_agent:
|
||
user_agent = user_agent.replace("HeadlessChrome", "Chrome")
|
||
print_status("已优化浏览器指纹", "success")
|
||
|
||
# 使用优化后的 user_agent 重新初始化浏览器
|
||
browser_manager.quit()
|
||
browser_manager = BrowserManager()
|
||
browser = browser_manager.init_browser(user_agent)
|
||
|
||
print_status("浏览器初始化完成", "success")
|
||
|
||
print_status("正在初始化邮箱验证模块...")
|
||
email_handler = EmailVerificationHandler()
|
||
|
||
print_step_header("配置信息")
|
||
login_url = "https://authenticator.cursor.sh"
|
||
sign_up_url = "https://authenticator.cursor.sh/sign-up"
|
||
settings_url = "https://www.cursor.com/settings"
|
||
mail_url = "https://tempmail.plus"
|
||
|
||
print_status("正在生成随机账号信息...")
|
||
email_generator = EmailGenerator()
|
||
account = email_generator.generate_email()
|
||
password = email_generator.default_password
|
||
first_name = email_generator.default_first_name
|
||
last_name = email_generator.default_last_name
|
||
|
||
print_status(f"生成的邮箱账号: {account}")
|
||
auto_update_cursor_auth = True
|
||
|
||
tab = browser.latest_tab
|
||
|
||
tab.run_js("try { turnstile.reset() } catch(e) { }")
|
||
|
||
if sign_up_account(browser, tab):
|
||
print_status("正在获取会话令牌...")
|
||
token = get_cursor_session_token(tab)
|
||
if token:
|
||
print_status("更新认证信息...")
|
||
update_cursor_auth(
|
||
email=account, access_token=token, refresh_token=token
|
||
)
|
||
|
||
# 先关闭浏览器以释放文件锁
|
||
if browser_manager:
|
||
browser_manager.quit()
|
||
|
||
print_status("正在关闭 Cursor...", "info")
|
||
if ExitCursor():
|
||
print_status("Cursor 已关闭", "success")
|
||
else:
|
||
print_status("Cursor 关闭失败,继续执行...", "warning")
|
||
|
||
time.sleep(2) # 等待进程完全退出
|
||
|
||
print_status("执行完整重置...")
|
||
# 以管理员权限执行完整重置
|
||
try:
|
||
subprocess.run([
|
||
"powershell",
|
||
"-Command",
|
||
"Start-Process python -ArgumentList 'full_reset.py' -Verb RunAs -Wait"
|
||
])
|
||
print_status("完整重置成功", "success")
|
||
print_status("所有操作已完成", "success")
|
||
print(f"\n{Fore.GREEN}✓ 重置完成!下次启动 Cursor 将使用新的配置。{Style.RESET_ALL}")
|
||
except Exception as e:
|
||
print_status(f"完整重置失败: {str(e)}", "error")
|
||
else:
|
||
print_status("获取会话令牌失败,注册流程未完成", "error")
|
||
|
||
except Exception as e:
|
||
print_status(f"程序执行出现错误: {str(e)}", "error")
|
||
import traceback
|
||
print_status(traceback.format_exc(), "error")
|
||
finally:
|
||
if browser_manager:
|
||
browser_manager.quit()
|
||
input(f"\n{Fore.YELLOW}按回车键退出...{Style.RESET_ALL}")
|