From 45354c22d7ed2773621c9f491d85d4b7155c1569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=85=8E=E9=A5=BC=E6=9E=9C=E5=AD=90=E5=8D=B7=E9=B2=A8?= =?UTF-8?q?=E9=B1=BC=E8=BE=A3=E6=A4=92?= Date: Thu, 3 Jul 2025 15:43:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EMAC=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=80=9A=E8=BF=87netifaces=E5=BA=93=E5=92=8C=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=8E=B7=E5=8F=96=E7=BD=91=E7=BB=9C=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8F=8A=E5=BD=93=E5=89=8DMAC=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=EF=BC=8C=E7=94=9F=E6=88=90=E9=9A=8F=E6=9C=BAMAC=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=B9=B6=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9=E3=80=82?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E7=94=A8=E6=88=B7=E5=8F=8D=E9=A6=88?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E8=BF=87=E7=A8=8B=E4=B8=AD=E6=8F=90=E4=BE=9B=E6=B8=85?= =?UTF-8?q?=E6=99=B0=E7=9A=84=E6=93=8D=E4=BD=9C=E6=8C=87=E5=BC=95=E5=92=8C?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E6=80=BB=E7=BB=93=E3=80=82=E5=90=8C=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=96=B0=E4=BA=86=E8=84=9A=E6=9C=AC=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BB=A5=E6=8F=90=E5=8D=87=E5=8F=AF=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E6=80=A7=E5=92=8C=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/cursor_id_modifier.py | 279 +++++++++++++++++++++++++- scripts/run/cursor_mac_id_modifier.sh | 55 ++++- 2 files changed, 325 insertions(+), 9 deletions(-) diff --git a/scripts/cursor_id_modifier.py b/scripts/cursor_id_modifier.py index 6f39b16..aad0bc8 100644 --- a/scripts/cursor_id_modifier.py +++ b/scripts/cursor_id_modifier.py @@ -52,6 +52,17 @@ import glob import pwd import gettext +import random + +# 尝试导入netifaces,如果不可用则使用系统命令 +# Try to import netifaces, use system commands if not available +try: + import netifaces + NETIFACES_AVAILABLE = True +except ImportError: + NETIFACES_AVAILABLE = False + log_warn = lambda x: print(f"[WARN] {x}") # 临时日志函数 + log_warn("netifaces library not found, will use system commands for network operations") # 设置语言环境 # Set language environment @@ -802,6 +813,241 @@ global.macMachineId = '$mac_machine_id'; log_info(_("Successfully modified {} JS files").format(modified_count)) return True +# 获取网络接口列表 +# Get network interface list +def get_network_interfaces(): + global _ + if NETIFACES_AVAILABLE: + try: + # 使用netifaces库 + # Use netifaces library + interfaces = netifaces.interfaces() + # 过滤掉回环接口 + # Filter out loopback interfaces + return [iface for iface in interfaces if not iface.startswith('lo')] + except Exception: + pass + + # 如果netifaces不可用或失败,使用系统命令 + # If netifaces is not available or failed, use system commands + try: + result = subprocess.run(['ip', 'link', 'show'], capture_output=True, text=True) + interfaces = [] + for line in result.stdout.split('\n'): + if ': ' in line and 'state' in line.lower(): + iface_name = line.split(': ')[1].split('@')[0] + if not iface_name.startswith('lo'): + interfaces.append(iface_name) + return interfaces + except subprocess.CalledProcessError: + # 最后的备选方案 + # Last fallback option + try: + result = subprocess.run(['ls', '/sys/class/net/'], capture_output=True, text=True) + interfaces = result.stdout.strip().split('\n') + return [iface for iface in interfaces if not iface.startswith('lo')] + except subprocess.CalledProcessError: + log_error(_("Unable to get network interface list")) + return [] + +# 生成随机MAC地址 +# Generate random MAC address +def generate_random_mac(): + global _ + # 生成随机MAC地址,确保第一个字节的最低位为0(单播地址) + # Generate random MAC address, ensure the lowest bit of first byte is 0 (unicast address) + mac = [0x00, 0x16, 0x3e, + random.randint(0x00, 0x7f), + random.randint(0x00, 0xff), + random.randint(0x00, 0xff)] + return ':'.join(map(lambda x: "%02x" % x, mac)) + +# 获取当前MAC地址 +# Get current MAC address +def get_current_mac(interface): + global _ + if NETIFACES_AVAILABLE: + try: + # 使用netifaces库 + # Use netifaces library + addrs = netifaces.ifaddresses(interface) + if netifaces.AF_LINK in addrs: + return addrs[netifaces.AF_LINK][0]['addr'] + except Exception: + pass + + # 使用系统命令获取MAC地址 + # Use system command to get MAC address + try: + result = subprocess.run(['cat', f'/sys/class/net/{interface}/address'], + capture_output=True, text=True) + if result.returncode == 0: + return result.stdout.strip() + except subprocess.CalledProcessError: + pass + + # 备选方案:使用ip命令 + # Fallback: use ip command + try: + result = subprocess.run(['ip', 'link', 'show', interface], + capture_output=True, text=True) + for line in result.stdout.split('\n'): + if 'link/ether' in line: + return line.split()[1] + except subprocess.CalledProcessError: + pass + + return None + +# 修改MAC地址 +# Modify MAC address +def modify_mac_address(): + global _ + log_info(_("Starting MAC address modification...")) + + # 获取网络接口列表 + # Get network interface list + interfaces = get_network_interfaces() + if not interfaces: + log_error(_("No network interfaces found")) + return False + + log_info(_("Found network interfaces: {}").format(', '.join(interfaces))) + + # 选择要修改的接口(通常选择第一个非回环接口) + # Select interface to modify (usually the first non-loopback interface) + target_interface = None + for iface in interfaces: + # 优先选择以太网接口 + # Prefer ethernet interfaces + if any(prefix in iface.lower() for prefix in ['eth', 'enp', 'ens', 'enx']): + target_interface = iface + break + + # 如果没有找到以太网接口,选择第一个可用接口 + # If no ethernet interface found, select first available interface + if not target_interface and interfaces: + target_interface = interfaces[0] + + if not target_interface: + log_error(_("No suitable network interface found")) + return False + + log_info(_("Selected network interface: {}").format(target_interface)) + + # 获取当前MAC地址 + # Get current MAC address + current_mac = get_current_mac(target_interface) + if current_mac: + log_info(_("Current MAC address: {}").format(current_mac)) + + # 备份当前MAC地址 + # Backup current MAC address + backup_file = os.path.join(BACKUP_DIR, f"original_mac_{target_interface}.txt") + try: + os.makedirs(BACKUP_DIR, exist_ok=True) + with open(backup_file, 'w') as f: + f.write(f"{target_interface}:{current_mac}\n") + log_info(_("Original MAC address backed up to: {}").format(backup_file)) + except OSError: + log_warn(_("Failed to backup original MAC address")) + else: + log_warn(_("Unable to get current MAC address")) + + # 生成新的MAC地址 + # Generate new MAC address + new_mac = generate_random_mac() + log_info(_("Generated new MAC address: {}").format(new_mac)) + + # 修改MAC地址 + # Modify MAC address + success = False + + # 方法1:使用ip命令 + # Method 1: Use ip command + try: + log_debug(_("Attempting to modify MAC address using ip command...")) + + # 先关闭接口 + # First bring down the interface + subprocess.run(['ip', 'link', 'set', 'dev', target_interface, 'down'], + check=True, capture_output=True) + + # 修改MAC地址 + # Modify MAC address + subprocess.run(['ip', 'link', 'set', 'dev', target_interface, 'address', new_mac], + check=True, capture_output=True) + + # 重新启用接口 + # Bring up the interface + subprocess.run(['ip', 'link', 'set', 'dev', target_interface, 'up'], + check=True, capture_output=True) + + success = True + log_info(_("Successfully modified MAC address using ip command")) + + except subprocess.CalledProcessError as e: + log_warn(_("Failed to modify MAC address using ip command: {}").format(str(e))) + + # 方法2:使用ifconfig命令(备选方案) + # Method 2: Use ifconfig command (fallback) + if not success: + try: + log_debug(_("Attempting to modify MAC address using ifconfig command...")) + + # 先关闭接口 + # First bring down the interface + subprocess.run(['ifconfig', target_interface, 'down'], + check=True, capture_output=True) + + # 修改MAC地址 + # Modify MAC address + subprocess.run(['ifconfig', target_interface, 'hw', 'ether', new_mac], + check=True, capture_output=True) + + # 重新启用接口 + # Bring up the interface + subprocess.run(['ifconfig', target_interface, 'up'], + check=True, capture_output=True) + + success = True + log_info(_("Successfully modified MAC address using ifconfig command")) + + except subprocess.CalledProcessError as e: + log_warn(_("Failed to modify MAC address using ifconfig command: {}").format(str(e))) + + # 验证MAC地址修改 + # Verify MAC address modification + if success: + time.sleep(2) # 等待网络接口稳定 + # Wait for network interface to stabilize + + new_current_mac = get_current_mac(target_interface) + if new_current_mac and new_current_mac.lower() == new_mac.lower(): + log_info(_("MAC address modification verified successfully")) + log_info(_("New MAC address: {}").format(new_current_mac)) + + # 保存新MAC地址信息 + # Save new MAC address information + new_mac_file = os.path.join(BACKUP_DIR, f"new_mac_{target_interface}.txt") + try: + with open(new_mac_file, 'w') as f: + f.write(f"{target_interface}:{new_current_mac}\n") + f.write(f"Modified at: {datetime.datetime.now()}\n") + log_info(_("New MAC address information saved to: {}").format(new_mac_file)) + except OSError: + log_warn(_("Failed to save new MAC address information")) + + return True + else: + log_error(_("MAC address modification verification failed")) + log_error(_("Expected: {}, Actual: {}").format(new_mac, new_current_mac)) + return False + else: + log_error(_("All MAC address modification methods failed")) + log_error(_("Please check if you have sufficient permissions or try running with sudo")) + return False + # 禁用自动更新 # Disable auto-update def disable_auto_update(): @@ -983,16 +1229,47 @@ def main(): # 修改JS文件 # Modify JS files log_info(_("Modifying Cursor JS files...")) - if modify_cursor_js_files(): + js_success = modify_cursor_js_files() + if js_success: log_info(_("JS files modified successfully!")) else: log_warn(_("JS file modification failed, but configuration file modification may have succeeded")) log_warn(_("If Cursor still indicates the device is disabled after restarting, please rerun this script")) + # 修改MAC地址 + # Modify MAC address + log_info(_("Modifying system MAC address...")) + mac_success = modify_mac_address() + if mac_success: + log_info(_("MAC address modified successfully!")) + else: + log_warn(_("MAC address modification failed")) + log_warn(_("This may affect the effectiveness of device identification bypass")) + # 禁用自动更新 # Disable auto-update disable_auto_update() + # 显示修改结果总结 + # Display modification result summary + print() + print(f"{GREEN}================================{NC}") + print(f"{BLUE} {_('Modification Results Summary')} {NC}") + print(f"{GREEN}================================{NC}") + + if js_success: + print(f"{GREEN}✓{NC} {_('JS files modification: SUCCESS')}") + else: + print(f"{RED}✗{NC} {_('JS files modification: FAILED')}") + + if mac_success: + print(f"{GREEN}✓{NC} {_('MAC address modification: SUCCESS')}") + else: + print(f"{RED}✗{NC} {_('MAC address modification: FAILED')}") + + print(f"{GREEN}================================{NC}") + print() + log_info(_("Please restart Cursor to apply the new configuration")) # 显示最后的提示信息 diff --git a/scripts/run/cursor_mac_id_modifier.sh b/scripts/run/cursor_mac_id_modifier.sh index df48e38..07b3015 100644 --- a/scripts/run/cursor_mac_id_modifier.sh +++ b/scripts/run/cursor_mac_id_modifier.sh @@ -1904,7 +1904,9 @@ main() { echo -e "${BLUE} 5️⃣ 等待配置文件生成完成(最多45秒)${NC}" echo -e "${BLUE} 6️⃣ 关闭Cursor进程${NC}" echo -e "${BLUE} 7️⃣ 修改新生成的机器码配置文件${NC}" - echo -e "${BLUE} 8️⃣ 显示操作完成统计信息${NC}" + echo -e "${BLUE} 8️⃣ 修改系统MAC地址${NC}" + echo -e "${BLUE} 9️⃣ 禁用自动更新${NC}" + echo -e "${BLUE} 🔟 显示操作完成统计信息${NC}" echo echo -e "${YELLOW}⚠️ [注意事项]${NC}" echo -e "${YELLOW} • 脚本执行过程中请勿手动操作Cursor${NC}" @@ -1912,6 +1914,7 @@ main() { echo -e "${YELLOW} • 执行完成后需要重新启动Cursor${NC}" echo -e "${YELLOW} • 原配置文件会自动备份到backups文件夹${NC}" echo -e "${YELLOW} • 需要Python3环境来处理JSON配置文件${NC}" + echo -e "${YELLOW} • MAC地址修改是临时的,重启后恢复${NC}" fi echo @@ -1954,6 +1957,21 @@ main() { log_error "❌ [失败] 机器码修改失败!" log_info "💡 [建议] 请尝试'重置环境+修改机器码'选项" fi + + # 🔧 修改系统MAC地址(仅修改模式也需要) + echo + log_info "🔧 [MAC地址] 开始修改系统MAC地址..." + if change_system_mac_address; then + log_info "✅ [成功] MAC地址修改完成!" + else + log_warn "⚠️ [警告] MAC地址修改失败或部分失败" + log_info "💡 [提示] 这可能影响设备识别绕过的效果" + fi + + # 🚫 禁用自动更新(仅修改模式也需要) + echo + log_info "🚫 [禁用更新] 正在禁用Cursor自动更新..." + disable_auto_update else # 完整的重置环境+修改机器码流程 log_info "🚀 [开始] 开始执行重置环境+修改机器码功能..." @@ -1980,9 +1998,22 @@ main() { # 🛠️ 修改机器码配置 modify_machine_code_config - fi + # 🔧 修改系统MAC地址 + echo + log_info "🔧 [MAC地址] 开始修改系统MAC地址..." + if change_system_mac_address; then + log_info "✅ [成功] MAC地址修改完成!" + else + log_warn "⚠️ [警告] MAC地址修改失败或部分失败" + log_info "💡 [提示] 这可能影响设备识别绕过的效果" + fi + fi + # 🚫 禁用自动更新 + echo + log_info "🚫 [禁用更新] 正在禁用Cursor自动更新..." + disable_auto_update # 🎉 显示操作完成信息 echo @@ -1997,17 +2028,25 @@ main() { log_info "🚀 [提示] 现在可以重新启动 Cursor 尝试使用了!" echo - # 🚫 以下功能已暂时屏蔽 - log_warn "⚠️ [提示] 以下功能已暂时屏蔽:" - log_info "📋 [说明] - 自动更新禁用功能" - log_info "📋 [说明] - 应用修复功能" - log_info "📋 [说明] 如需恢复这些功能,请联系开发者" + # 🎉 显示修改结果总结 + echo + echo -e "${GREEN}================================${NC}" + echo -e "${BLUE} 🎯 修改结果总结 ${NC}" + echo -e "${GREEN}================================${NC}" + echo -e "${GREEN}✅ JSON配置文件修改: 完成${NC}" + echo -e "${GREEN}✅ MAC地址修改: 完成${NC}" + echo -e "${GREEN}✅ 自动更新禁用: 完成${NC}" + echo -e "${GREEN}================================${NC}" echo # 🎉 脚本执行完成 log_info "🎉 [完成] 所有操作已完成!" echo - log_info "💡 [提示] 如果需要恢复机器码修改功能,请联系开发者" + log_info "💡 [重要提示] 完整的Cursor破解流程已执行:" + echo -e "${BLUE} ✅ 机器码配置文件修改${NC}" + echo -e "${BLUE} ✅ 系统MAC地址修改${NC}" + echo -e "${BLUE} ✅ 自动更新功能禁用${NC}" + echo log_warn "⚠️ [注意] 重启 Cursor 后生效" echo log_info "🚀 [下一步] 现在可以启动 Cursor 尝试使用了!"