Skip to content

Commit 9495ba7

Browse files
committed
Enhance ID generation in macOS and Windows scripts
- Added a function to generate random hexadecimal strings in the Windows ID modifier script for improved randomness. - Updated the macOS script to concatenate a hexadecimal representation of the prefix "auth0|user_" with a random ID, ensuring a consistent format for machine IDs across platforms. - Improved comments in both scripts for better clarity on the ID generation process.
1 parent d0415ff commit 9495ba7

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

scripts/run/cursor_mac_id_modifier.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ backup_config() {
128128

129129
# 生成随机 ID
130130
generate_random_id() {
131+
# 生成32字节(64个十六进制字符)的随机数
131132
openssl rand -hex 32
132133
}
133134

@@ -138,7 +139,13 @@ generate_uuid() {
138139

139140
# 生成新的配置
140141
generate_new_config() {
141-
local machine_id="auth0|user_$(generate_random_id)"
142+
# 将 auth0|user_ 转换为字节数组的十六进制
143+
local prefix_hex=$(echo -n "auth0|user_" | xxd -p)
144+
# 生成随机部分
145+
local random_part=$(generate_random_id)
146+
# 拼接前缀的十六进制和随机部分
147+
local machine_id="${prefix_hex}${random_part}"
148+
142149
local mac_machine_id=$(generate_random_id)
143150
local device_id=$(generate_uuid | tr '[:upper:]' '[:lower:]')
144151
local sqm_id="{$(generate_uuid | tr '[:lower:]' '[:upper:]')}"

scripts/run/cursor_win_id_modifier.ps1

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,26 @@ if (Test-Path $STORAGE_FILE) {
110110
# 生成新的 ID
111111
Write-Host "$GREEN[信息]$NC 正在生成新的 ID..."
112112

113+
# 生成随机字节数组并转换为十六进制字符串的函数
114+
function Get-RandomHex {
115+
param (
116+
[int]$length
117+
)
118+
$bytes = New-Object byte[] $length
119+
$rng = [System.Security.Cryptography.RNGCryptoServiceProvider]::new()
120+
$rng.GetBytes($bytes)
121+
$rng.Dispose()
122+
return -join ($bytes | ForEach-Object { '{0:x2}' -f $_ })
123+
}
124+
113125
$UUID = [System.Guid]::NewGuid().ToString()
114-
$MACHINE_ID = -join ((1..32) | ForEach-Object { '{0:x2}' -f (Get-Random -Max 256) })
115-
$MAC_MACHINE_ID = -join ((1..32) | ForEach-Object { '{0:x2}' -f (Get-Random -Max 256) })
126+
# 将 auth0|user_ 转换为字节数组的十六进制
127+
$prefixBytes = [System.Text.Encoding]::UTF8.GetBytes("auth0|user_")
128+
$prefixHex = -join ($prefixBytes | ForEach-Object { '{0:x2}' -f $_ })
129+
# 生成32字节(64个十六进制字符)的随机数作为 machineId 的随机部分
130+
$randomPart = Get-RandomHex -length 32
131+
$MACHINE_ID = "$prefixHex$randomPart"
132+
$MAC_MACHINE_ID = Get-RandomHex -length 32
116133
$SQM_ID = "{$([System.Guid]::NewGuid().ToString().ToUpper())}"
117134

118135
# 创建或更新配置文件

0 commit comments

Comments
 (0)