Browse Source

```

feat(cursor): 为Linux、Mac和Windows平台的ID修改脚本添加诊断功能

在cursor_linux_id_modifier.sh、cursor_mac_id_modifier.sh和
cursor_win_id_modifier.ps1脚本中增加了详细的诊断日志输出功能,
用于追踪ID修改过程中的匹配情况和错误定位。新增了diag函数来
输出诊断信息,包括模块标记查找结果、候选函数匹配过程、特
征校验结果等,便于调试和问题排查。
```
煎饼果子卷鲨鱼辣椒 2 weeks ago
parent
commit
33e611ba9a
  1. 29
      scripts/run/cursor_linux_id_modifier.sh
  2. 29
      scripts/run/cursor_mac_id_modifier.sh
  3. 43
      scripts/run/cursor_win_id_modifier.ps1

29
scripts/run/cursor_linux_id_modifier.sh

@ -1135,6 +1135,9 @@ EOF
if True: if True:
import re, sys import re, sys
def diag(msg):
print(f"[方案B][诊断] {msg}", file=sys.stderr)
path, machine_guid, machine_id = sys.argv[1], sys.argv[2], sys.argv[3] path, machine_guid, machine_id = sys.argv[1], sys.argv[2], sys.argv[3]
with open(path, "r", encoding="utf-8") as f: with open(path, "r", encoding="utf-8") as f:
@ -1145,6 +1148,7 @@ if True:
marker_index = data.find(marker) marker_index = data.find(marker)
if marker_index < 0: if marker_index < 0:
print("NOT_FOUND") print("NOT_FOUND")
diag(f"未找到模块标记: {marker}")
raise SystemExit(0) raise SystemExit(0)
window_end = min(len(data), marker_index + 200000) window_end = min(len(data), marker_index + 200000)
@ -1237,33 +1241,50 @@ if True:
hash_re = re.compile(r'createHash\\([\"\\']sha256[\"\\']\\)') hash_re = re.compile(r'createHash\\([\"\\']sha256[\"\\']\\)')
sig_re = re.compile(r'^async function (\\w+)\\((\\w+)\\)') sig_re = re.compile(r'^async function (\\w+)\\((\\w+)\\)')
for hm in hash_re.finditer(window):
hash_matches = list(hash_re.finditer(window))
diag(f"marker_index={marker_index} window_len={len(window)} sha256_createHash={len(hash_matches)}")
for idx, hm in enumerate(hash_matches, start=1):
hash_pos = hm.start() hash_pos = hm.start()
func_start = window.rfind("async function", 0, hash_pos) func_start = window.rfind("async function", 0, hash_pos)
if func_start < 0: if func_start < 0:
if idx <= 3:
diag(f"候选#{idx}: 未找到 async function 起点")
continue continue
open_brace = window.find("{", func_start) open_brace = window.find("{", func_start)
if open_brace < 0: if open_brace < 0:
if idx <= 3:
diag(f"候选#{idx}: 未找到函数起始花括号")
continue continue
end_brace = find_matching_brace(window, open_brace, max_scan=20000) end_brace = find_matching_brace(window, open_brace, max_scan=20000)
if end_brace is None: if end_brace is None:
if idx <= 3:
diag(f"候选#{idx}: 花括号配对失败(扫描上限内未闭合)")
continue continue
func_text = window[func_start:end_brace + 1] func_text = window[func_start:end_brace + 1]
if len(func_text) > 8000: if len(func_text) > 8000:
if idx <= 3:
diag(f"候选#{idx}: 函数体过长 len={len(func_text)},已跳过")
continue continue
sm = sig_re.match(func_text) sm = sig_re.match(func_text)
if not sm: if not sm:
if idx <= 3:
diag(f"候选#{idx}: 未解析到函数签名(async function name(param))")
continue continue
name, param = sm.group(1), sm.group(2) name, param = sm.group(1), sm.group(2)
# 特征校验:sha256 + hex digest + return param ? raw : hash # 特征校验:sha256 + hex digest + return param ? raw : hash
if not re.search(r'\\.digest\\([\"\\']hex[\"\\']\\)', func_text):
has_digest = re.search(r'\\.digest\\([\"\\']hex[\"\\']\\)', func_text) is not None
has_return = re.search(r'return\\s+' + re.escape(param) + r'\\?\\w+:\\w+\\}', func_text) is not None
if idx <= 3:
diag(f"候选#{idx}: {name}({param}) len={len(func_text)} digest={has_digest} return={has_return}")
if not has_digest:
continue continue
if not re.search(r'return\\s+' + re.escape(param) + r'\\?\\w+:\\w+\\}', func_text):
if not has_return:
continue continue
replacement = f'async function {name}({param}){{return {param}?"{machine_guid}":"{machine_id}";}}' replacement = f'async function {name}({param}){{return {param}?"{machine_guid}":"{machine_id}";}}'
@ -1272,9 +1293,11 @@ if True:
new_data = data[:abs_start] + replacement + data[abs_end + 1:] new_data = data[:abs_start] + replacement + data[abs_end + 1:]
with open(path, "w", encoding="utf-8") as f: with open(path, "w", encoding="utf-8") as f:
f.write(new_data) f.write(new_data)
diag(f"命中并重写: {name}({param}) len={len(func_text)}")
print("PATCHED") print("PATCHED")
break break
else: else:
diag("未找到满足特征的候选函数")
print("NOT_FOUND") print("NOT_FOUND")
PY PY
) )

29
scripts/run/cursor_mac_id_modifier.sh

@ -1862,6 +1862,9 @@ EOF
if True: if True:
import re, sys import re, sys
def diag(msg):
print(f"[方案B][诊断] {msg}", file=sys.stderr)
path, machine_guid, machine_id = sys.argv[1], sys.argv[2], sys.argv[3] path, machine_guid, machine_id = sys.argv[1], sys.argv[2], sys.argv[3]
with open(path, "r", encoding="utf-8") as f: with open(path, "r", encoding="utf-8") as f:
@ -1872,6 +1875,7 @@ if True:
marker_index = data.find(marker) marker_index = data.find(marker)
if marker_index < 0: if marker_index < 0:
print("NOT_FOUND") print("NOT_FOUND")
diag(f"未找到模块标记: {marker}")
raise SystemExit(0) raise SystemExit(0)
window_end = min(len(data), marker_index + 200000) window_end = min(len(data), marker_index + 200000)
@ -1964,33 +1968,50 @@ if True:
hash_re = re.compile(r'createHash\\([\"\\']sha256[\"\\']\\)') hash_re = re.compile(r'createHash\\([\"\\']sha256[\"\\']\\)')
sig_re = re.compile(r'^async function (\\w+)\\((\\w+)\\)') sig_re = re.compile(r'^async function (\\w+)\\((\\w+)\\)')
for hm in hash_re.finditer(window):
hash_matches = list(hash_re.finditer(window))
diag(f"marker_index={marker_index} window_len={len(window)} sha256_createHash={len(hash_matches)}")
for idx, hm in enumerate(hash_matches, start=1):
hash_pos = hm.start() hash_pos = hm.start()
func_start = window.rfind("async function", 0, hash_pos) func_start = window.rfind("async function", 0, hash_pos)
if func_start < 0: if func_start < 0:
if idx <= 3:
diag(f"候选#{idx}: 未找到 async function 起点")
continue continue
open_brace = window.find("{", func_start) open_brace = window.find("{", func_start)
if open_brace < 0: if open_brace < 0:
if idx <= 3:
diag(f"候选#{idx}: 未找到函数起始花括号")
continue continue
end_brace = find_matching_brace(window, open_brace, max_scan=20000) end_brace = find_matching_brace(window, open_brace, max_scan=20000)
if end_brace is None: if end_brace is None:
if idx <= 3:
diag(f"候选#{idx}: 花括号配对失败(扫描上限内未闭合)")
continue continue
func_text = window[func_start:end_brace + 1] func_text = window[func_start:end_brace + 1]
if len(func_text) > 8000: if len(func_text) > 8000:
if idx <= 3:
diag(f"候选#{idx}: 函数体过长 len={len(func_text)},已跳过")
continue continue
sm = sig_re.match(func_text) sm = sig_re.match(func_text)
if not sm: if not sm:
if idx <= 3:
diag(f"候选#{idx}: 未解析到函数签名(async function name(param))")
continue continue
name, param = sm.group(1), sm.group(2) name, param = sm.group(1), sm.group(2)
# 特征校验:sha256 + hex digest + return param ? raw : hash # 特征校验:sha256 + hex digest + return param ? raw : hash
if not re.search(r'\\.digest\\([\"\\']hex[\"\\']\\)', func_text):
has_digest = re.search(r'\\.digest\\([\"\\']hex[\"\\']\\)', func_text) is not None
has_return = re.search(r'return\\s+' + re.escape(param) + r'\\?\\w+:\\w+\\}', func_text) is not None
if idx <= 3:
diag(f"候选#{idx}: {name}({param}) len={len(func_text)} digest={has_digest} return={has_return}")
if not has_digest:
continue continue
if not re.search(r'return\\s+' + re.escape(param) + r'\\?\\w+:\\w+\\}', func_text):
if not has_return:
continue continue
replacement = f'async function {name}({param}){{return {param}?"{machine_guid}":"{machine_id}";}}' replacement = f'async function {name}({param}){{return {param}?"{machine_guid}":"{machine_id}";}}'
@ -1999,9 +2020,11 @@ if True:
new_data = data[:abs_start] + replacement + data[abs_end + 1:] new_data = data[:abs_start] + replacement + data[abs_end + 1:]
with open(path, "w", encoding="utf-8") as f: with open(path, "w", encoding="utf-8") as f:
f.write(new_data) f.write(new_data)
diag(f"命中并重写: {name}({param}) len={len(func_text)}")
print("PATCHED") print("PATCHED")
break break
else: else:
diag("未找到满足特征的候选函数")
print("NOT_FOUND") print("NOT_FOUND")
PY PY
) )

43
scripts/run/cursor_win_id_modifier.ps1

@ -618,37 +618,61 @@ function Modify-CursorJSFiles {
$hashRegex = [regex]::new('createHash\(["'']sha256["'']\)') $hashRegex = [regex]::new('createHash\(["'']sha256["'']\)')
$hashMatches = $hashRegex.Matches($windowText) $hashMatches = $hashRegex.Matches($windowText)
Write-Host " $BLUEℹ️ $NC [方案B诊断] id.js偏移=$markerIndex | sha256 createHash 命中=$($hashMatches.Count)"
$patched = $false $patched = $false
$diagLines = @()
$candidateNo = 0
foreach ($hm in $hashMatches) { foreach ($hm in $hashMatches) {
$candidateNo++
$hashPos = $hm.Index $hashPos = $hm.Index
$funcStart = $windowText.LastIndexOf("async function", $hashPos) $funcStart = $windowText.LastIndexOf("async function", $hashPos)
if ($funcStart -lt 0) { continue }
if ($funcStart -lt 0) {
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 未找到 async function 起点" }
continue
}
$openBrace = $windowText.IndexOf("{", $funcStart) $openBrace = $windowText.IndexOf("{", $funcStart)
if ($openBrace -lt 0) { continue }
if ($openBrace -lt 0) {
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 未找到函数起始花括号" }
continue
}
$endBrace = Find-JsMatchingBraceEnd -Text $windowText -OpenBraceIndex $openBrace -MaxScan 20000 $endBrace = Find-JsMatchingBraceEnd -Text $windowText -OpenBraceIndex $openBrace -MaxScan 20000
if ($endBrace -lt 0) { continue }
if ($endBrace -lt 0) {
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 花括号配对失败(扫描上限内未闭合)" }
continue
}
$funcText = $windowText.Substring($funcStart, $endBrace - $funcStart + 1) $funcText = $windowText.Substring($funcStart, $endBrace - $funcStart + 1)
if ($funcText.Length -gt 8000) { continue }
if ($funcText.Length -gt 8000) {
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 函数体过长 len=$($funcText.Length),已跳过" }
continue
}
$sig = [regex]::Match($funcText, '^async function (\w+)\((\w+)\)') $sig = [regex]::Match($funcText, '^async function (\w+)\((\w+)\)')
if (-not $sig.Success) { continue }
if (-not $sig.Success) {
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 未解析到函数签名(async function name(param))" }
continue
}
$fn = $sig.Groups[1].Value $fn = $sig.Groups[1].Value
$param = $sig.Groups[2].Value $param = $sig.Groups[2].Value
# 特征校验:sha256 + hex digest + return param ? raw : hash # 特征校验:sha256 + hex digest + return param ? raw : hash
if (-not ($funcText -match 'createHash\(["'']sha256["'']\)')) { continue }
if (-not ($funcText -match '\.digest\(["'']hex["'']\)')) { continue }
if (-not ($funcText -match ('return\s+' + [regex]::Escape($param) + '\?\w+:\w+\}'))) { continue }
$hasDigest = ($funcText -match '\.digest\(["'']hex["'']\)')
$hasReturn = ($funcText -match ('return\s+' + [regex]::Escape($param) + '\?\w+:\w+\}'))
if ($candidateNo -le 3) {
$diagLines += "候选#$candidateNo: $fn($param) len=$($funcText.Length) digest=$hasDigest return=$hasReturn"
}
if (-not $hasDigest) { continue }
if (-not $hasReturn) { continue }
$replacement = "async function $fn($param){return $param?'$machineGuid':'$machineId';}" $replacement = "async function $fn($param){return $param?'$machineGuid':'$machineId';}"
$absStart = $markerIndex + $funcStart $absStart = $markerIndex + $funcStart
$absEnd = $markerIndex + $endBrace $absEnd = $markerIndex + $endBrace
$content = $content.Substring(0, $absStart) + $replacement + $content.Substring($absEnd + 1) $content = $content.Substring(0, $absStart) + $replacement + $content.Substring($absEnd + 1)
Write-Host " $BLUEℹ️ $NC [方案B诊断] 命中候选#$candidateNo:$fn($param) len=$($funcText.Length)"
Write-Host " $GREEN✓$NC [方案B] 已重写 $fn($param) 机器码源函数(融合版特征匹配)" Write-Host " $GREEN✓$NC [方案B] 已重写 $fn($param) 机器码源函数(融合版特征匹配)"
$replacedB6 = $true $replacedB6 = $true
$patched = $true $patched = $true
@ -657,6 +681,9 @@ function Modify-CursorJSFiles {
if (-not $patched) { if (-not $patched) {
Write-Host " $YELLOW⚠️ $NC [方案B] 未定位到机器码源函数特征,已跳过" Write-Host " $YELLOW⚠️ $NC [方案B] 未定位到机器码源函数特征,已跳过"
foreach ($d in ($diagLines | Select-Object -First 3)) {
Write-Host " $BLUEℹ️ $NC [方案B诊断] $d"
}
} }
} catch { } catch {
Write-Host " $YELLOW⚠️ $NC [方案B] 定位失败,已跳过:$($_.Exception.Message)" Write-Host " $YELLOW⚠️ $NC [方案B] 定位失败,已跳过:$($_.Exception.Message)"

Loading…
Cancel
Save