From 9f6eee77e043782cd4c2844f92c2bb70b3a7edca Mon Sep 17 00:00:00 2001 From: yeongpin Date: Thu, 6 Mar 2025 18:11:40 +0800 Subject: [PATCH] feat: Add Workbench JS Modification and Cursor Path Detection - Update `MachineIDResetter` to include workbench.desktop.main.js modification step - Enhance platform support for Linux, macOS, and Windows - Update CHANGELOG.md to version 1.6.02 --- .env | 4 +- .gitignore | 1 + CHANGELOG.md | 4 ++ reset_machine_manual.py | 105 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 27ed12e..777f7d3 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -version=1.6.01 -VERSION=1.6.01 +version=1.6.02 +VERSION=1.6.02 diff --git a/.gitignore b/.gitignore index bb7cb54..654a570 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ build.mac.command build.py build.sh ENV/ +test.py install.bat run.bat diff --git a/CHANGELOG.md b/CHANGELOG.md index dd98cf8..0ecb0cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## v1.6.02 +1. Hotfix: Small Problem | 修復一些問題 +2. Add: Test some Bypass Code | 測試一些繞過代碼 + ## v1.6.01 1. Fix: Cursor Auth | 修復Cursor Auth 2. Add: Create Account Maximum Retry | 增加創建賬號最大重試次數 diff --git a/reset_machine_manual.py b/reset_machine_manual.py index 420cae5..0b4a927 100644 --- a/reset_machine_manual.py +++ b/reset_machine_manual.py @@ -64,6 +64,43 @@ def get_cursor_paths(translator=None) -> Tuple[str, str]: os.path.join(base_path, paths_map[system]["main"]), ) +def get_workbench_cursor_path(translator=None) -> str: + """Get Cursor workbench.desktop.main.js path""" + system = platform.system() + + paths_map = { + "Darwin": { # macOS + "base": "/Applications/Cursor.app/Contents/Resources/app", + "main": "out/vs/workbench/workbench.desktop.main.js" + }, + "Windows": { + "base": os.path.join(os.getenv("LOCALAPPDATA", ""), "Programs", "Cursor", "resources", "app"), + "main": "out/vs/workbench/workbench.desktop.main.js" + }, + "Linux": { + "bases": ["/opt/Cursor/resources/app", "/usr/share/cursor/resources/app"], + "main": "out/vs/workbench/workbench.desktop.main.js" + } + } + + if system not in paths_map: + raise OSError(translator.get('reset.unsupported_os', system=system) if translator else f"不支持的操作系统: {system}") + + if system == "Linux": + for base in paths_map["Linux"]["bases"]: + main_path = os.path.join(base, paths_map["Linux"]["main"]) + if os.path.exists(main_path): + return main_path + raise OSError(translator.get('reset.linux_path_not_found') if translator else "在 Linux 系统上未找到 Cursor 安装路径") + + base_path = paths_map[system]["base"] + main_path = os.path.join(base_path, paths_map[system]["main"]) + + if not os.path.exists(main_path): + raise OSError(translator.get('reset.file_not_found', path=main_path) if translator else f"未找到 Cursor main.js 文件: {main_path}") + + return main_path + def version_check(version: str, min_version: str = "", max_version: str = "", translator=None) -> bool: """Version number check""" version_pattern = r"^\d+\.\d+\.\d+$" @@ -102,6 +139,70 @@ def check_cursor_version(translator) -> bool: print(f"{Fore.RED}{EMOJI['ERROR']} {translator.get('reset.check_version_failed', error=str(e))}{Style.RESET_ALL}") return False +def modify_workbench_js(file_path: str, translator=None) -> bool: + """ + Modify file content + """ + try: + # Save original file permissions + original_stat = os.stat(file_path) + original_mode = original_stat.st_mode + original_uid = original_stat.st_uid + original_gid = original_stat.st_gid + + # Create temporary file + with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", errors="ignore", delete=False) as tmp_file: + # Read original content + with open(file_path, "r", encoding="utf-8", errors="ignore") as main_file: + content = main_file.read() + + # Define replacement patterns + CButton_old_pattern = r'$(k,E(Ks,{title:"Upgrade to Pro",size:"small",get codicon(){return F.rocket},get onClick(){return t.pay}}),null)' + CButton_new_pattern = r'$(k,E(Ks,{title:"yeongpin GitHub",size:"small",get codicon(){return F.rocket},get onClick(){return function(){window.open("https://www.github.com/yeongpin","_blank")}}}),null)' + + CBadge_old_pattern = r'
Pro Trial' + CBadge_new_pattern = r'
Pro' + + CToast_old_pattern = r'notifications-toasts' + CToast_new_pattern = r'notifications-toasts hidden' + + # Replace content + content = content.replace(CButton_old_pattern, CButton_new_pattern) + content = content.replace(CBadge_old_pattern, CBadge_new_pattern) + content = content.replace(CToast_old_pattern, CToast_new_pattern) + + # Write to temporary file + tmp_file.write(content) + tmp_path = tmp_file.name + + # Backup original file + backup_path = file_path + ".backup" + if os.path.exists(backup_path): + os.remove(backup_path) + shutil.copy2(file_path, backup_path) + + # Move temporary file to original position + if os.path.exists(file_path): + os.remove(file_path) + shutil.move(tmp_path, file_path) + + # Restore original permissions + os.chmod(file_path, original_mode) + if os.name != "nt": # Not Windows + os.chown(file_path, original_uid, original_gid) + + print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {translator.get('reset.file_modified')}{Style.RESET_ALL}") + return True + + except Exception as e: + print(f"{Fore.RED}{EMOJI['ERROR']} {translator.get('reset.modify_file_failed', error=str(e))}{Style.RESET_ALL}") + if "tmp_path" in locals(): + try: + os.unlink(tmp_path) + except: + pass + return False + def modify_main_js(main_path: str, translator) -> bool: """Modify main.js file""" try: @@ -373,6 +474,10 @@ class MachineIDResetter: # Update system IDs self.update_system_ids(new_ids) + # Modify workbench.desktop.main.js + workbench_path = get_workbench_cursor_path(self.translator) + modify_workbench_js(workbench_path, self.translator) + # Check Cursor version and perform corresponding actions greater_than_0_45 = check_cursor_version(self.translator) if greater_than_0_45: