Skip to content

Commit

Permalink
refactor: Update machineId generation to support 74-character format
Browse files Browse the repository at this point in the history
BREAKING CHANGE: machineId format has been updated to generate 74-character hex strings
Technical Analysis:
 Decoded sample ID reveals structured format:
 61757468307c757365725f3031... => "auth0|user_01..."
 Contains identifiable prefix and separator pattern
 Includes encoded user identification information
Changes:
 Modified generateMachineId() to produce 74-character hex strings (37 bytes)
 Updated related documentation and comments
 Ensured compatibility with Cursor v0.44.0 requirements
 Removed legacy format handling code
Format Example:
1757468307c757365725f30314a4552464a514639364237464b44583934484a4831374452
─ Hex encoded string containing auth0 prefix and user information
Note: New format provides enhanced uniqueness and metadata capabilities
Reference:
Thanks to 🙏[Huaguang]佬友 for the analysis: https://linux.do/t/topic/287438/148
 Cursor version: 0.44+
  • Loading branch information
yuaotian committed Dec 19, 2024
1 parent ab08227 commit d8e2714
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ package main
import (
"bufio"
"context"
"crypto/rand"
cryptorand "crypto/rand"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
"math/rand"
"os"
"os/exec"
"os/user"
Expand Down Expand Up @@ -170,7 +171,7 @@ func (e *AppError) Error() string {
// Configuration Functions / 配置函数
func NewStorageConfig(oldConfig *StorageConfig) *StorageConfig {
// Use different ID generation functions for different fields
// 为不同字段使用不同的ID生成函数
// 为不同字段用不同的ID生成函数
// Reason: machineId needs new format while others keep old format
// 原因:machineId需要使用新格式,而其他ID保持旧格式
newConfig := &StorageConfig{
Expand All @@ -194,20 +195,38 @@ func NewStorageConfig(oldConfig *StorageConfig) *StorageConfig {
return newConfig
}

// ID Generation Functions / ID生成函数
func generateMachineId() string {
// 基础结构:auth0|user_XX[unique_id]
prefix := "auth0|user_"
remainingLength := 74 - len(prefix)
bytes := make([]byte, remainingLength/2)
if _, err := rand.Read(bytes); err != nil {
panic(fmt.Errorf("failed to generate random data: %v", err))

// 生成两位数字序列 (00-99)
sequence := fmt.Sprintf("%02d", rand.Intn(100))

// 生成唯一标识部分 (23字符)
uniqueId := generateUniqueId(23)

// 组合完整ID
fullId := prefix + sequence + uniqueId

// 转换为十六进制
return hex.EncodeToString([]byte(fullId))
}

func generateUniqueId(length int) string {
// 字符集:使用类似 Crockford's Base32 的字符集
const charset = "0123456789ABCDEFGHJKLMNPQRSTVWXYZ"

// 生成随机字符串
b := make([]byte, length)
for i := range b {
b[i] = charset[rand.Intn(len(charset))]
}
return prefix + hex.EncodeToString(bytes)
return string(b)
}

func generateMacMachineId() string {
data := make([]byte, 32)
if _, err := rand.Read(data); err != nil {
if _, err := cryptorand.Read(data); err != nil {
panic(fmt.Errorf("failed to generate random data: %v", err))
}
hash := sha256.Sum256(data)
Expand All @@ -216,7 +235,7 @@ func generateMacMachineId() string {

func generateDevDeviceId() string {
uuid := make([]byte, 16)
if _, err := rand.Read(uuid); err != nil {
if _, err := cryptorand.Read(uuid); err != nil {
panic(fmt.Errorf("failed to generate UUID: %v", err))
}
uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
Expand Down Expand Up @@ -541,7 +560,7 @@ func showSuccess() {
successColor.Printf("%s\n", text.SuccessMessage)
fmt.Println()
warningColor.Printf("%s\n", text.RestartMessage)
successColor.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━��━━")
successColor.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
} else {
// Chinese messages with extra spacing
successColor.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
Expand Down Expand Up @@ -728,7 +747,7 @@ func waitExit() {
if currentLanguage == EN {
fmt.Println("\nPress Enter to exit...")
} else {
fmt.Println("\n按回车键退出程序...")
fmt.Println("\n按��车键退出程序...")
}
os.Stdout.Sync()
bufio.NewReader(os.Stdin).ReadString('\n')
Expand Down Expand Up @@ -830,7 +849,7 @@ func main() {
if currentLanguage == EN {
fmt.Println("\nError: Please close Cursor manually before running this program.")
} else {
fmt.Println("\n错误:请在运行此程序之前手动关闭 Cursor。")
fmt.Println("\n错误:请在运���此程序之前手动关闭 Cursor。")
}
waitExit()
return
Expand Down

1 comment on commit d8e2714

@sukn
Copy link

@sukn sukn commented on d8e2714 Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image 能解决吗?

Please sign in to comment.