104 lines
3.6 KiB
Python
104 lines
3.6 KiB
Python
import json
|
|
import logging
|
|
from pathlib import Path
|
|
from account_switcher import AccountSwitcher
|
|
import os
|
|
|
|
def get_machine_info():
|
|
"""获取当前机器码相关信息"""
|
|
info = {}
|
|
|
|
# 1. 获取 package.json 中的 machineId
|
|
cursor_path = Path(os.path.expanduser("~")) / "AppData" / "Local" / "Programs" / "Cursor"
|
|
package_json = cursor_path / "resources" / "app" / "package.json"
|
|
if package_json.exists():
|
|
with open(package_json, "r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
info["machine_id"] = data.get("machineId", "未找到")
|
|
|
|
# 2. 检查注册表项是否存在
|
|
import winreg
|
|
registry_paths = [
|
|
r"Software\Classes\Directory\Background\shell\Cursor\command",
|
|
r"Software\Classes\Directory\Background\shell\Cursor",
|
|
r"Software\Cursor\Auth",
|
|
r"Software\Cursor\Updates",
|
|
r"Software\Cursor"
|
|
]
|
|
|
|
info["registry"] = {}
|
|
for path in registry_paths:
|
|
try:
|
|
winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0, winreg.KEY_READ)
|
|
info["registry"][path] = "存在"
|
|
except WindowsError:
|
|
info["registry"][path] = "不存在"
|
|
|
|
# 3. 检查文件是否存在
|
|
local_app_data = Path(os.getenv('LOCALAPPDATA'))
|
|
files_to_check = [
|
|
local_app_data / "Cursor" / "User" / "globalStorage",
|
|
local_app_data / "Cursor" / "Cache",
|
|
local_app_data / "cursor-updater",
|
|
cursor_path / "resources" / "app" / "config.json",
|
|
cursor_path / "resources" / "app" / "state.json",
|
|
cursor_path / "resources" / "app" / "settings.json"
|
|
]
|
|
|
|
info["files"] = {}
|
|
for path in files_to_check:
|
|
info["files"][str(path)] = "存在" if path.exists() else "不存在"
|
|
|
|
return info
|
|
|
|
def test_reset_machine_id():
|
|
"""测试重置机器码功能"""
|
|
# 设置日志
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
print("=== 重置前的状态 ===")
|
|
before_info = get_machine_info()
|
|
print(json.dumps(before_info, indent=2, ensure_ascii=False))
|
|
|
|
# 创建 AccountSwitcher 实例并修改 reset_machine_id 方法以跳过重启
|
|
switcher = AccountSwitcher()
|
|
|
|
# 保存原始的 restart_cursor 方法
|
|
original_restart = switcher.restart_cursor
|
|
|
|
try:
|
|
# 替换 restart_cursor 方法为空函数
|
|
switcher.restart_cursor = lambda: True
|
|
|
|
# 执行重置
|
|
print("\n=== 执行重置 ===")
|
|
result = switcher.reset_machine_id()
|
|
print(f"重置结果: {result}")
|
|
|
|
print("\n=== 重置后的状态 ===")
|
|
after_info = get_machine_info()
|
|
print(json.dumps(after_info, indent=2, ensure_ascii=False))
|
|
|
|
# 比较差异
|
|
print("\n=== 变化分析 ===")
|
|
|
|
# 检查 machineId
|
|
if before_info.get("machine_id") != after_info.get("machine_id"):
|
|
print(f"machineId 变化: {before_info.get('machine_id')} -> {after_info.get('machine_id')}")
|
|
|
|
# 检查注册表变化
|
|
for path in before_info["registry"]:
|
|
if before_info["registry"][path] != after_info["registry"][path]:
|
|
print(f"注册表 {path}: {before_info['registry'][path]} -> {after_info['registry'][path]}")
|
|
|
|
# 检查文件变化
|
|
for path in before_info["files"]:
|
|
if before_info["files"][path] != after_info["files"][path]:
|
|
print(f"文件 {path}: {before_info['files'][path]} -> {after_info['files'][path]}")
|
|
|
|
finally:
|
|
# 恢复原始的 restart_cursor 方法
|
|
switcher.restart_cursor = original_restart
|
|
|
|
if __name__ == "__main__":
|
|
test_reset_machine_id() |