commit 089f5a95724cf5fb13ae9777a74913de41ec42c7 Author: Xx Date: Mon Dec 9 15:00:45 2024 +0800 初始化版本 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..fce885a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "cSpell.words": [ + "LOCALAPPDATA", + "pkill", + "taskkill" + ] +} \ No newline at end of file diff --git a/bin/cursor_id_modifier.exe b/bin/cursor_id_modifier.exe new file mode 100644 index 0000000..c113c26 Binary files /dev/null and b/bin/cursor_id_modifier.exe differ diff --git a/bin/cursor_id_modifier_linux b/bin/cursor_id_modifier_linux new file mode 100644 index 0000000..30efdc9 Binary files /dev/null and b/bin/cursor_id_modifier_linux differ diff --git a/bin/cursor_id_modifier_mac b/bin/cursor_id_modifier_mac new file mode 100644 index 0000000..179137b Binary files /dev/null and b/bin/cursor_id_modifier_mac differ diff --git a/bin/cursor_id_modifier_mac_arm64 b/bin/cursor_id_modifier_mac_arm64 new file mode 100644 index 0000000..1c8a633 Binary files /dev/null and b/bin/cursor_id_modifier_mac_arm64 differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e0c2b2d --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go-cursor-help + +go 1.22.0 diff --git a/main.go b/main.go new file mode 100644 index 0000000..e5b709f --- /dev/null +++ b/main.go @@ -0,0 +1,172 @@ +package main + +import ( + "crypto/rand" + "crypto/sha256" + "encoding/hex" + "encoding/json" + "fmt" + "os" + "path/filepath" + "runtime" +) + +// StorageConfig 存储配置结构体 +type StorageConfig struct { + TelemetryMacMachineId string `json:"telemetry.macMachineId"` + TelemetryMachineId string `json:"telemetry.machineId"` + TelemetryDevDeviceId string `json:"telemetry.devDeviceId"` +} + +// 生成类似原始machineId的字符串 (64位小写hex) +func generateMachineId() string { + // 生成一些随机数据 + data := make([]byte, 32) + rand.Read(data) + + // 使用SHA256生成hash + hash := sha256.New() + hash.Write(data) + + // 转换为小写的hex字符串 + return hex.EncodeToString(hash.Sum(nil)) +} + +// 生成类似原始macMachineId的字符串 (64位小写hex) +func generateMacMachineId() string { + return generateMachineId() // 使用相同的格式 +} + +// 生成类似原始devDeviceId的字符串 (标准UUID格式) +func generateDevDeviceId() string { + // 生成 UUID v4 + uuid := make([]byte, 16) + rand.Read(uuid) + + // 设置版本 (4) 和变体位 + uuid[6] = (uuid[6] & 0x0f) | 0x40 // 版本 4 + uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 变体 + + // 格式化为标准 UUID 字符串 + return fmt.Sprintf("%x-%x-%x-%x-%x", + uuid[0:4], + uuid[4:6], + uuid[6:8], + uuid[8:10], + uuid[10:16]) +} + +// 获取配置文件路径 +func getConfigPath() (string, error) { + var configDir string + switch runtime.GOOS { + case "darwin": + homeDir, err := os.UserHomeDir() + if err != nil { + return "", err + } + configDir = filepath.Join(homeDir, "Library", "Application Support", "Cursor", "User", "globalStorage") + case "windows": + appData := os.Getenv("APPDATA") + configDir = filepath.Join(appData, "Cursor", "User", "globalStorage") + case "linux": + homeDir, err := os.UserHomeDir() + if err != nil { + return "", err + } + configDir = filepath.Join(homeDir, ".config", "Cursor", "User", "globalStorage") + default: + return "", fmt.Errorf("不支持的操作系统: %s", runtime.GOOS) + } + return filepath.Join(configDir, "storage.json"), nil +} + +// 修改文件权限 +func setFilePermissions(filePath string) error { + if runtime.GOOS == "windows" { + // Windows 使用 ACL 权限系统,这里仅设置为只读 + return os.Chmod(filePath, 0444) + } else { + // Linux 和 macOS + return os.Chmod(filePath, 0444) + } +} + +// 获取Cursor可执行文件路径 +func getCursorExePath() (string, error) { + switch runtime.GOOS { + case "windows": + // Windows下通常在LocalAppData目录 + localAppData := os.Getenv("LOCALAPPDATA") + return filepath.Join(localAppData, "Programs", "Cursor", "Cursor.exe"), nil + case "darwin": + // macOS下通常在Applications目录 + return "/Applications/Cursor.app/Contents/MacOS/Cursor", nil + case "linux": + // Linux下可能在usr/bin目录 + return "/usr/bin/cursor", nil + default: + return "", fmt.Errorf("不支持的操作系统: %s", runtime.GOOS) + } +} + + + +func main() { + // 获取配置文件路径 + configPath, err := getConfigPath() + if err != nil { + fmt.Printf("获取配置文件路径失败: %v\n", err) + return + } + + // 读取原始文件内容 + content, err := os.ReadFile(configPath) + if err != nil { + fmt.Printf("读取配置文件失败: %v\n", err) + return + } + + // 解析 JSON + var config map[string]interface{} + if err := json.Unmarshal(content, &config); err != nil { + fmt.Printf("解析 JSON 失败: %v\n", err) + return + } + + // 修改指定字段,使用更准确的生成方法 + config["telemetry.macMachineId"] = generateMacMachineId() + config["telemetry.machineId"] = generateMachineId() + config["telemetry.devDeviceId"] = generateDevDeviceId() + + // 转换回 JSON,保持原有的格式 + newContent, err := json.MarshalIndent(config, "", " ") + if err != nil { + fmt.Printf("生成 JSON 失败: %v\n", err) + return + } + + // 先确保文件可写 + err = os.Chmod(configPath, 0666) + if err != nil { + fmt.Printf("修改文件权限失败: %v\n", err) + return + } + + // 写入文件 + err = os.WriteFile(configPath, newContent, 0666) + if err != nil { + fmt.Printf("写入文件失败: %v\n", err) + return + } + + // 设置文件为只读 + err = setFilePermissions(configPath) + if err != nil { + fmt.Printf("设置文件只读权限失败: %v\n", err) + return + } + + + fmt.Println("配置文件已成功更新,请手动重启Cursor以使更改生效。") +} diff --git a/scripts/build_all.bat b/scripts/build_all.bat new file mode 100644 index 0000000..47a9186 --- /dev/null +++ b/scripts/build_all.bat @@ -0,0 +1,28 @@ +@echo off +echo Creating bin directory... +if not exist "..\bin" mkdir "..\bin" + +echo Building for all platforms... + +echo Building for Windows AMD64... +set GOOS=windows +set GOARCH=amd64 +go build -o ../bin/cursor_id_modifier.exe ../main.go + +echo Building for macOS AMD64... +set GOOS=darwin +set GOARCH=amd64 +go build -o ../bin/cursor_id_modifier_mac ../main.go + +echo Building for macOS ARM64... +set GOOS=darwin +set GOARCH=arm64 +go build -o ../bin/cursor_id_modifier_mac_arm64 ../main.go + +echo Building for Linux AMD64... +set GOOS=linux +set GOARCH=amd64 +go build -o ../bin/cursor_id_modifier_linux ../main.go + +echo All builds completed! +pause \ No newline at end of file diff --git a/scripts/build_all.sh b/scripts/build_all.sh new file mode 100644 index 0000000..cb752ae --- /dev/null +++ b/scripts/build_all.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# 创建bin目录(如果不存在) +mkdir -p ../bin + +# Windows +echo "Building for Windows..." +GOOS=windows GOARCH=amd64 go build -o ../bin/cursor_id_modifier.exe ../main.go + +# macOS (Intel) +echo "Building for macOS (Intel)..." +GOOS=darwin GOARCH=amd64 go build -o ../bin/cursor_id_modifier_mac ../main.go + +# macOS (Apple Silicon) +echo "Building for macOS (ARM64)..." +GOOS=darwin GOARCH=arm64 go build -o ../bin/cursor_id_modifier_mac_arm64 ../main.go + +# Linux +echo "Building for Linux..." +GOOS=linux GOARCH=amd64 go build -o ../bin/cursor_id_modifier_linux ../main.go + +echo "All builds completed!" \ No newline at end of file diff --git a/scripts/build_linux.sh b/scripts/build_linux.sh new file mode 100644 index 0000000..d123076 --- /dev/null +++ b/scripts/build_linux.sh @@ -0,0 +1,6 @@ +#!/bin/bash +echo "Building for Linux..." +export GOOS=linux +export GOARCH=amd64 +go build -o ../bin/cursor_id_modifier_linux ../main.go +echo "Build complete: ../bin/cursor_id_modifier_linux" \ No newline at end of file diff --git a/scripts/build_mac.sh b/scripts/build_mac.sh new file mode 100644 index 0000000..02b48ab --- /dev/null +++ b/scripts/build_mac.sh @@ -0,0 +1,13 @@ +#!/bin/bash +echo "Building for macOS..." +export GOOS=darwin +export GOARCH=amd64 +go build -o ../bin/cursor_id_modifier_mac ../main.go +echo "Build complete: ../bin/cursor_id_modifier_mac" + +# Build for Apple Silicon +echo "Building for macOS ARM64..." +export GOOS=darwin +export GOARCH=arm64 +go build -o ../bin/cursor_id_modifier_mac_arm64 ../main.go +echo "Build complete: ../bin/cursor_id_modifier_mac_arm64" \ No newline at end of file diff --git a/scripts/build_windows.bat b/scripts/build_windows.bat new file mode 100644 index 0000000..6481f33 --- /dev/null +++ b/scripts/build_windows.bat @@ -0,0 +1,6 @@ +@echo off +echo Building for Windows... +set GOOS=windows +set GOARCH=amd64 +go build -o ../bin/cursor_id_modifier.exe ../main.go +echo Build complete: ../bin/cursor_id_modifier.exe \ No newline at end of file