Skip to content

Commit 089f5a9

Browse files
committed
初始化版本
0 parents  commit 089f5a9

12 files changed

+257
-0
lines changed

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"cSpell.words": [
3+
"LOCALAPPDATA",
4+
"pkill",
5+
"taskkill"
6+
]
7+
}

bin/cursor_id_modifier.exe

2.78 MB
Binary file not shown.

bin/cursor_id_modifier_linux

2.66 MB
Binary file not shown.

bin/cursor_id_modifier_mac

2.67 MB
Binary file not shown.

bin/cursor_id_modifier_mac_arm64

2.64 MB
Binary file not shown.

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module go-cursor-help
2+
3+
go 1.22.0

main.go

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
package main
2+
3+
import (
4+
"crypto/rand"
5+
"crypto/sha256"
6+
"encoding/hex"
7+
"encoding/json"
8+
"fmt"
9+
"os"
10+
"path/filepath"
11+
"runtime"
12+
)
13+
14+
// StorageConfig 存储配置结构体
15+
type StorageConfig struct {
16+
TelemetryMacMachineId string `json:"telemetry.macMachineId"`
17+
TelemetryMachineId string `json:"telemetry.machineId"`
18+
TelemetryDevDeviceId string `json:"telemetry.devDeviceId"`
19+
}
20+
21+
// 生成类似原始machineId的字符串 (64位小写hex)
22+
func generateMachineId() string {
23+
// 生成一些随机数据
24+
data := make([]byte, 32)
25+
rand.Read(data)
26+
27+
// 使用SHA256生成hash
28+
hash := sha256.New()
29+
hash.Write(data)
30+
31+
// 转换为小写的hex字符串
32+
return hex.EncodeToString(hash.Sum(nil))
33+
}
34+
35+
// 生成类似原始macMachineId的字符串 (64位小写hex)
36+
func generateMacMachineId() string {
37+
return generateMachineId() // 使用相同的格式
38+
}
39+
40+
// 生成类似原始devDeviceId的字符串 (标准UUID格式)
41+
func generateDevDeviceId() string {
42+
// 生成 UUID v4
43+
uuid := make([]byte, 16)
44+
rand.Read(uuid)
45+
46+
// 设置版本 (4) 和变体位
47+
uuid[6] = (uuid[6] & 0x0f) | 0x40 // 版本 4
48+
uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 变体
49+
50+
// 格式化为标准 UUID 字符串
51+
return fmt.Sprintf("%x-%x-%x-%x-%x",
52+
uuid[0:4],
53+
uuid[4:6],
54+
uuid[6:8],
55+
uuid[8:10],
56+
uuid[10:16])
57+
}
58+
59+
// 获取配置文件路径
60+
func getConfigPath() (string, error) {
61+
var configDir string
62+
switch runtime.GOOS {
63+
case "darwin":
64+
homeDir, err := os.UserHomeDir()
65+
if err != nil {
66+
return "", err
67+
}
68+
configDir = filepath.Join(homeDir, "Library", "Application Support", "Cursor", "User", "globalStorage")
69+
case "windows":
70+
appData := os.Getenv("APPDATA")
71+
configDir = filepath.Join(appData, "Cursor", "User", "globalStorage")
72+
case "linux":
73+
homeDir, err := os.UserHomeDir()
74+
if err != nil {
75+
return "", err
76+
}
77+
configDir = filepath.Join(homeDir, ".config", "Cursor", "User", "globalStorage")
78+
default:
79+
return "", fmt.Errorf("不支持的操作系统: %s", runtime.GOOS)
80+
}
81+
return filepath.Join(configDir, "storage.json"), nil
82+
}
83+
84+
// 修改文件权限
85+
func setFilePermissions(filePath string) error {
86+
if runtime.GOOS == "windows" {
87+
// Windows 使用 ACL 权限系统,这里仅设置为只读
88+
return os.Chmod(filePath, 0444)
89+
} else {
90+
// Linux 和 macOS
91+
return os.Chmod(filePath, 0444)
92+
}
93+
}
94+
95+
// 获取Cursor可执行文件路径
96+
func getCursorExePath() (string, error) {
97+
switch runtime.GOOS {
98+
case "windows":
99+
// Windows下通常在LocalAppData目录
100+
localAppData := os.Getenv("LOCALAPPDATA")
101+
return filepath.Join(localAppData, "Programs", "Cursor", "Cursor.exe"), nil
102+
case "darwin":
103+
// macOS下通常在Applications目录
104+
return "/Applications/Cursor.app/Contents/MacOS/Cursor", nil
105+
case "linux":
106+
// Linux下可能在usr/bin目录
107+
return "/usr/bin/cursor", nil
108+
default:
109+
return "", fmt.Errorf("不支持的操作系统: %s", runtime.GOOS)
110+
}
111+
}
112+
113+
114+
115+
func main() {
116+
// 获取配置文件路径
117+
configPath, err := getConfigPath()
118+
if err != nil {
119+
fmt.Printf("获取配置文件路径失败: %v\n", err)
120+
return
121+
}
122+
123+
// 读取原始文件内容
124+
content, err := os.ReadFile(configPath)
125+
if err != nil {
126+
fmt.Printf("读取配置文件失败: %v\n", err)
127+
return
128+
}
129+
130+
// 解析 JSON
131+
var config map[string]interface{}
132+
if err := json.Unmarshal(content, &config); err != nil {
133+
fmt.Printf("解析 JSON 失败: %v\n", err)
134+
return
135+
}
136+
137+
// 修改指定字段,使用更准确的生成方法
138+
config["telemetry.macMachineId"] = generateMacMachineId()
139+
config["telemetry.machineId"] = generateMachineId()
140+
config["telemetry.devDeviceId"] = generateDevDeviceId()
141+
142+
// 转换回 JSON,保持原有的格式
143+
newContent, err := json.MarshalIndent(config, "", " ")
144+
if err != nil {
145+
fmt.Printf("生成 JSON 失败: %v\n", err)
146+
return
147+
}
148+
149+
// 先确保文件可写
150+
err = os.Chmod(configPath, 0666)
151+
if err != nil {
152+
fmt.Printf("修改文件权限失败: %v\n", err)
153+
return
154+
}
155+
156+
// 写入文件
157+
err = os.WriteFile(configPath, newContent, 0666)
158+
if err != nil {
159+
fmt.Printf("写入文件失败: %v\n", err)
160+
return
161+
}
162+
163+
// 设置文件为只读
164+
err = setFilePermissions(configPath)
165+
if err != nil {
166+
fmt.Printf("设置文件只读权限失败: %v\n", err)
167+
return
168+
}
169+
170+
171+
fmt.Println("配置文件已成功更新,请手动重启Cursor以使更改生效。")
172+
}

scripts/build_all.bat

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@echo off
2+
echo Creating bin directory...
3+
if not exist "..\bin" mkdir "..\bin"
4+
5+
echo Building for all platforms...
6+
7+
echo Building for Windows AMD64...
8+
set GOOS=windows
9+
set GOARCH=amd64
10+
go build -o ../bin/cursor_id_modifier.exe ../main.go
11+
12+
echo Building for macOS AMD64...
13+
set GOOS=darwin
14+
set GOARCH=amd64
15+
go build -o ../bin/cursor_id_modifier_mac ../main.go
16+
17+
echo Building for macOS ARM64...
18+
set GOOS=darwin
19+
set GOARCH=arm64
20+
go build -o ../bin/cursor_id_modifier_mac_arm64 ../main.go
21+
22+
echo Building for Linux AMD64...
23+
set GOOS=linux
24+
set GOARCH=amd64
25+
go build -o ../bin/cursor_id_modifier_linux ../main.go
26+
27+
echo All builds completed!
28+
pause

scripts/build_all.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# 创建bin目录(如果不存在)
4+
mkdir -p ../bin
5+
6+
# Windows
7+
echo "Building for Windows..."
8+
GOOS=windows GOARCH=amd64 go build -o ../bin/cursor_id_modifier.exe ../main.go
9+
10+
# macOS (Intel)
11+
echo "Building for macOS (Intel)..."
12+
GOOS=darwin GOARCH=amd64 go build -o ../bin/cursor_id_modifier_mac ../main.go
13+
14+
# macOS (Apple Silicon)
15+
echo "Building for macOS (ARM64)..."
16+
GOOS=darwin GOARCH=arm64 go build -o ../bin/cursor_id_modifier_mac_arm64 ../main.go
17+
18+
# Linux
19+
echo "Building for Linux..."
20+
GOOS=linux GOARCH=amd64 go build -o ../bin/cursor_id_modifier_linux ../main.go
21+
22+
echo "All builds completed!"

scripts/build_linux.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
echo "Building for Linux..."
3+
export GOOS=linux
4+
export GOARCH=amd64
5+
go build -o ../bin/cursor_id_modifier_linux ../main.go
6+
echo "Build complete: ../bin/cursor_id_modifier_linux"

0 commit comments

Comments
 (0)