Skip to content

Commit a63fcac

Browse files
committed
更新文档以支持Cursor v0.47.x版本,修改相关提示信息并增强脚本功能以处理设备ID生成。包括对Windows和Mac/Linux的支持更新,确保用户获得最新信息。
1 parent a61be4b commit a63fcac

File tree

5 files changed

+173
-35
lines changed

5 files changed

+173
-35
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
>
1717
> This tool currently supports:
1818
> - ✅ Cursor v0.44.11 and below
19-
> - ✅ Windows: Latest 0.45.x versions (Supported)
20-
> - ✅ Mac/Linux: Latest 0.45.x versions (Supported, feedback welcome)
19+
> - ✅ Windows: Latest 0.47.x versions (Supported)
20+
> - ✅ Mac/Linux: Latest 0.47.x versions (Supported, feedback welcome)
2121
>
2222
> Please check your Cursor version before using this tool.
2323

README_CN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
>
1717
> 本工具当前支持版本:
1818
> - ✅ Cursor v0.44.11 及以下版本
19-
> - ✅ Windows: 最新的 0.45.x 版本(已支持)
20-
> - ✅ Mac/Linux: 最新的 0.45.x 版本(已支持,欢迎测试并反馈问题)
19+
> - ✅ Windows: 最新的 0.47.x 版本(已支持)
20+
> - ✅ Mac/Linux: 最新的 0.47.x 版本(已支持,欢迎测试并反馈问题)
2121
>
2222
> 使用前请确认您的 Cursor 版本。
2323

scripts/run/cursor_linux_id_modifier.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ main() {
452452
echo -e "${YELLOW} 一起交流更多Cursor技巧和AI知识(脚本免费、关注公众号加群有更多技巧和大佬) ${NC}"
453453
echo -e "${BLUE}================================${NC}"
454454
echo
455-
echo -e "${YELLOW}[重要提示]${NC} 本工具支持 Cursor v0.45.x"
455+
echo -e "${YELLOW}[重要提示]${NC} 本工具支持 Cursor v0.47.x"
456456
echo -e "${YELLOW}[重要提示]${NC} 本工具免费,如果对您有帮助,请关注公众号【煎饼果子卷AI】"
457457
echo
458458

scripts/run/cursor_mac_id_modifier.sh

+167-29
Original file line numberDiff line numberDiff line change
@@ -416,43 +416,159 @@ modify_cursor_app_files() {
416416
continue
417417
fi
418418

419-
log_debug "处理文件: ${file/$temp_dir\//}"
419+
log_debug "分析文件内容..."
420+
log_debug "文件大小: $(wc -c < "$file") 字节"
421+
422+
# 尝试查找文件中的关键部分
423+
log_debug "搜索关键函数..."
424+
grep -n "IOPlatformUUID" "$file" | head -3 || log_debug "未找到 IOPlatformUUID"
425+
grep -n "function.*getMachineId" "$file" | head -3 || log_debug "未找到 getMachineId 函数"
426+
grep -n "function.*getDeviceId" "$file" | head -3 || log_debug "未找到 getDeviceId 函数"
427+
grep -n "function t\\$" "$file" | head -3 || log_debug "未找到 t$ 函数"
428+
grep -n "function a\\$" "$file" | head -3 || log_debug "未找到 a$ 函数"
429+
430+
# 在出错时捕获更多信息
431+
trap 'log_error "脚本在 $LINENO 行附近失败了,命令: $BASH_COMMAND"; dump_debug_info "$file"' ERR
432+
433+
dump_debug_info() {
434+
local file="$1"
435+
log_debug "=== 调试信息 ==="
436+
log_debug "文件: $file"
437+
log_debug "文件存在: $(test -f "$file" && echo "" || echo "")"
438+
log_debug "文件大小: $(wc -c < "$file" 2>/dev/null || echo "无法读取")"
439+
log_debug "文件权限: $(ls -l "$file" 2>/dev/null || echo "无法获取")"
440+
log_debug "部分内容: $(head -5 "$file" 2>/dev/null | tr '\n' ' ' || echo "无法读取")"
441+
log_debug "================="
442+
}
420443

421444
# 创建文件备份
422445
cp "$file" "${file}.bak" || {
423446
log_error "无法创建文件备份: ${file/$temp_dir\//}"
424447
continue
425448
}
426449

427-
# 读取文件内容
428-
local content=$(cat "$file")
429-
430-
# 查找 IOPlatformUUID 的位置
431-
local uuid_pos=$(printf "%s" "$content" | grep -b -o "IOPlatformUUID" | cut -d: -f1)
432-
if [ -z "$uuid_pos" ]; then
433-
log_warn "$file 中未找到 IOPlatformUUID"
434-
continue
435-
fi
436-
437-
# 从 UUID 位置向前查找 switch
438-
local before_uuid=${content:0:$uuid_pos}
439-
local switch_pos=$(printf "%s" "$before_uuid" | grep -b -o "switch" | tail -n1 | cut -d: -f1)
440-
if [ -z "$switch_pos" ]; then
441-
log_warn "$file 中未找到 switch 关键字"
442-
continue
443-
fi
444-
445-
# 构建新的文件内容
446-
if printf "%sreturn crypto.randomUUID();\n%s" "${content:0:$switch_pos}" "${content:$switch_pos}" > "$file"; then
447-
((modified_count++))
448-
log_info "成功修改文件: ${file/$temp_dir\//}"
450+
# 使用 sed 替换而不是字符串操作
451+
if grep -q "IOPlatformUUID" "$file"; then
452+
log_debug "找到 IOPlatformUUID 关键字"
453+
454+
# 定位 IOPlatformUUID 相关函数
455+
if grep -q "function a\\$" "$file"; then
456+
# 针对 main.js 中发现的代码结构进行修改
457+
if sed -i.tmp 's/function a\$(t){switch/function a\$(t){return crypto.randomUUID(); switch/' "$file"; then
458+
log_debug "成功注入 randomUUID 调用到 a$ 函数"
459+
((modified_count++))
460+
log_info "成功修改文件: ${file/$temp_dir\//}"
461+
else
462+
log_error "修改 a$ 函数失败"
463+
cp "${file}.bak" "$file"
464+
fi
465+
elif grep -q "async function v5" "$file"; then
466+
# 替代方法 - 修改 v5 函数
467+
if sed -i.tmp 's/async function v5(t){let e=/async function v5(t){return crypto.randomUUID(); let e=/' "$file"; then
468+
log_debug "成功注入 randomUUID 调用到 v5 函数"
469+
((modified_count++))
470+
log_info "成功修改文件: ${file/$temp_dir\//}"
471+
else
472+
log_error "修改 v5 函数失败"
473+
cp "${file}.bak" "$file"
474+
fi
475+
else
476+
# 使用更通用的注入方法
477+
log_warn "未找到具体函数,尝试使用通用修改方法"
478+
inject_code="
479+
// 随机设备ID生成器注入
480+
const randomDeviceId = () => {
481+
try {
482+
return require('crypto').randomUUID();
483+
} catch (e) {
484+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
485+
const r = Math.random() * 16 | 0;
486+
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
487+
});
488+
}
489+
};
490+
"
491+
# 将代码注入到文件开头
492+
echo "$inject_code" > "${file}.new"
493+
cat "$file" >> "${file}.new"
494+
mv "${file}.new" "$file"
495+
496+
# 替换调用点
497+
sed -i.tmp 's/await v5(!1)/randomDeviceId()/g' "$file"
498+
sed -i.tmp 's/a\$(t)/randomDeviceId()/g' "$file"
499+
500+
log_debug "完成通用修改"
501+
((modified_count++))
502+
log_info "使用通用方法成功修改文件: ${file/$temp_dir\//}"
503+
fi
449504
else
450-
log_error "文件写入失败: ${file/$temp_dir\//}"
451-
mv "${file}.bak" "$file"
505+
# 未找到 IOPlatformUUID,可能是文件结构变化
506+
log_warn "未找到 IOPlatformUUID,尝试替代方法"
507+
508+
# 尝试找其他关键函数如 getMachineId 或 getDeviceId
509+
if grep -q "function t\$()" "$file" || grep -q "async function y5" "$file"; then
510+
log_debug "找到设备ID相关函数"
511+
512+
# 修改 MAC 地址获取函数
513+
if grep -q "function t\$()" "$file"; then
514+
sed -i.tmp 's/function t\$(){/function t\$(){return "00:00:00:00:00:00";/' "$file"
515+
log_debug "修改 MAC 地址获取函数成功"
516+
fi
517+
518+
# 修改设备ID获取函数
519+
if grep -q "async function y5" "$file"; then
520+
sed -i.tmp 's/async function y5(t){/async function y5(t){return crypto.randomUUID();/' "$file"
521+
log_debug "修改设备ID获取函数成功"
522+
fi
523+
524+
((modified_count++))
525+
log_info "使用替代方法成功修改文件: ${file/$temp_dir\//}"
526+
else
527+
# 最后尝试的通用方法 - 在文件顶部插入重写函数定义
528+
log_warn "未找到任何已知函数,使用最通用的方法"
529+
530+
inject_universal_code="
531+
// 全局拦截设备标识符
532+
const originalRequire = require;
533+
require = function(module) {
534+
const result = originalRequire(module);
535+
if (module === 'crypto' && result.randomUUID) {
536+
const originalRandomUUID = result.randomUUID;
537+
result.randomUUID = function() {
538+
return '${new_uuid}';
539+
};
540+
}
541+
return result;
542+
};
543+
544+
// 覆盖所有可能的系统ID获取函数
545+
global.getMachineId = function() { return '${machine_id}'; };
546+
global.getDeviceId = function() { return '${device_id}'; };
547+
global.macMachineId = '${mac_machine_id}';
548+
"
549+
# 将代码注入到文件开头
550+
local new_uuid=$(uuidgen | tr '[:upper:]' '[:lower:]')
551+
local machine_id="auth0|user_$(openssl rand -hex 16)"
552+
local device_id=$(uuidgen | tr '[:upper:]' '[:lower:]')
553+
local mac_machine_id=$(openssl rand -hex 32)
554+
555+
inject_universal_code=${inject_universal_code//\$\{new_uuid\}/$new_uuid}
556+
inject_universal_code=${inject_universal_code//\$\{machine_id\}/$machine_id}
557+
inject_universal_code=${inject_universal_code//\$\{device_id\}/$device_id}
558+
inject_universal_code=${inject_universal_code//\$\{mac_machine_id\}/$mac_machine_id}
559+
560+
echo "$inject_universal_code" > "${file}.new"
561+
cat "$file" >> "${file}.new"
562+
mv "${file}.new" "$file"
563+
564+
log_debug "完成通用覆盖"
565+
((modified_count++))
566+
log_info "使用最通用方法成功修改文件: ${file/$temp_dir\//}"
567+
fi
452568
fi
453569

454-
# 清理备份
455-
rm -f "${file}.bak"
570+
# 清理临时文件
571+
rm -f "${file}.tmp" "${file}.bak"
456572
done
457573

458574
if [ "$modified_count" -eq 0 ]; then
@@ -788,15 +904,37 @@ main() {
788904
echo -e "${YELLOW} 一起交流更多Cursor技巧和AI知识(脚本免费、关注公众号加群有更多技巧和大佬) ${NC}"
789905
echo -e "${BLUE}================================${NC}"
790906
echo
791-
echo -e "${YELLOW}[重要提示]${NC} 本工具支持 Cursor v0.45.x"
907+
echo -e "${YELLOW}[重要提示]${NC} 本工具支持 Cursor v0.47.x"
792908
echo -e "${YELLOW}[重要提示]${NC} 本工具免费,如果对您有帮助,请关注公众号【煎饼果子卷AI】"
793909
echo
794910

795911
check_permissions
796912
check_and_kill_cursor
797913
backup_config
798914
generate_new_config
799-
modify_cursor_app_files
915+
916+
# 询问用户是否要修改主程序文件
917+
echo
918+
log_warn "是否要修改 Cursor 主程序文件?"
919+
echo "0) 否 - 仅修改配置文件 (更安全但可能需要更频繁地重置)"
920+
echo "1) 是 - 同时修改主程序文件 (更持久但有小概率导致程序不稳定)"
921+
echo -n "请输入选择 [0-1] (默认 1): "
922+
read -r choice
923+
924+
# 处理用户选择
925+
case "$choice" in
926+
0)
927+
log_info "已跳过主程序文件修改"
928+
;;
929+
*)
930+
if modify_cursor_app_files; then
931+
log_info "主程序文件修改成功!"
932+
else
933+
log_warn "主程序文件修改失败,但配置文件修改可能已成功"
934+
log_warn "如果重启后 Cursor 仍然提示设备被禁用,请重新运行此脚本"
935+
fi
936+
;;
937+
esac
800938

801939
# 添加MAC地址修改选项
802940
echo

scripts/run/cursor_win_id_modifier.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function Get-CursorVersion {
8585
$cursorVersion = Get-CursorVersion
8686
Write-Host ""
8787

88-
Write-Host "$YELLOW[重要提示]$NC 最新的 0.45.x (以支持)"
88+
Write-Host "$YELLOW[重要提示]$NC 最新的 0.47.x (以支持)"
8989
Write-Host ""
9090

9191
# 检查并关闭 Cursor 进程

0 commit comments

Comments
 (0)