commit
089f5a9572
12 changed files with 257 additions and 0 deletions
-
7.vscode/settings.json
-
BINbin/cursor_id_modifier.exe
-
BINbin/cursor_id_modifier_linux
-
BINbin/cursor_id_modifier_mac
-
BINbin/cursor_id_modifier_mac_arm64
-
3go.mod
-
172main.go
-
28scripts/build_all.bat
-
22scripts/build_all.sh
-
6scripts/build_linux.sh
-
13scripts/build_mac.sh
-
6scripts/build_windows.bat
@ -0,0 +1,7 @@ |
|||
{ |
|||
"cSpell.words": [ |
|||
"LOCALAPPDATA", |
|||
"pkill", |
|||
"taskkill" |
|||
] |
|||
} |
@ -0,0 +1,3 @@ |
|||
module go-cursor-help |
|||
|
|||
go 1.22.0 |
@ -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以使更改生效。") |
|||
} |
@ -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 |
@ -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!" |
@ -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" |
@ -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" |
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue