From 4ebedae191803a23b9d6b33b12c2114102c2b25c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=85=8E=E9=A5=BC=E6=9E=9C=E5=AD=90=E5=8D=B7=E9=B2=A8?= =?UTF-8?q?=E9=B1=BC=E8=BE=A3=E6=A4=92?= Date: Wed, 14 Jan 2026 21:37:13 +0800 Subject: [PATCH] =?UTF-8?q?```=20fix(cursor-win-id-modifier):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DPowerShell=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=8F=92?= =?UTF-8?q?=E5=80=BC=E4=B8=AD=E7=9A=84=E5=8F=98=E9=87=8F=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 兼容PowerShell可展开字符串中"$var:"被当作作用域/驱动器前缀解析的问题, 改用"${var}"明确变量边界。同时修正了诊断信息中候选编号的字符串插值格式, 确保所有"$candidateNo"变量正确显示为数值而非空字符串。 ``` --- scripts/run/cursor_win_id_modifier.ps1 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/run/cursor_win_id_modifier.ps1 b/scripts/run/cursor_win_id_modifier.ps1 index 88acb75..4f5924c 100644 --- a/scripts/run/cursor_win_id_modifier.ps1 +++ b/scripts/run/cursor_win_id_modifier.ps1 @@ -621,6 +621,7 @@ function Modify-CursorJSFiles { Write-Host " $BLUEℹ️ $NC [方案B诊断] id.js偏移=$markerIndex | sha256 createHash 命中=$($hashMatches.Count)" $patched = $false $diagLines = @() + # 兼容:PowerShell 可展开字符串中 "$var:" 会被当作作用域/驱动器前缀解析,需用 "${var}" 明确变量边界 $candidateNo = 0 foreach ($hm in $hashMatches) { @@ -628,31 +629,31 @@ function Modify-CursorJSFiles { $hashPos = $hm.Index $funcStart = $windowText.LastIndexOf("async function", $hashPos) if ($funcStart -lt 0) { - if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 未找到 async function 起点" } + if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 未找到 async function 起点" } continue } $openBrace = $windowText.IndexOf("{", $funcStart) if ($openBrace -lt 0) { - if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 未找到函数起始花括号" } + if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 未找到函数起始花括号" } continue } $endBrace = Find-JsMatchingBraceEnd -Text $windowText -OpenBraceIndex $openBrace -MaxScan 20000 if ($endBrace -lt 0) { - if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 花括号配对失败(扫描上限内未闭合)" } + if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 花括号配对失败(扫描上限内未闭合)" } continue } $funcText = $windowText.Substring($funcStart, $endBrace - $funcStart + 1) if ($funcText.Length -gt 8000) { - if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 函数体过长 len=$($funcText.Length),已跳过" } + if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 函数体过长 len=$($funcText.Length),已跳过" } continue } $sig = [regex]::Match($funcText, '^async function (\w+)\((\w+)\)') if (-not $sig.Success) { - if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 未解析到函数签名(async function name(param))" } + if ($candidateNo -le 3) { $diagLines += "候选#${candidateNo}: 未解析到函数签名(async function name(param))" } continue } $fn = $sig.Groups[1].Value @@ -662,7 +663,7 @@ function Modify-CursorJSFiles { $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" + $diagLines += "候选#${candidateNo}: $fn($param) len=$($funcText.Length) digest=$hasDigest return=$hasReturn" } if (-not $hasDigest) { continue } if (-not $hasReturn) { continue } @@ -672,7 +673,7 @@ function Modify-CursorJSFiles { $absEnd = $markerIndex + $endBrace $content = $content.Substring(0, $absStart) + $replacement + $content.Substring($absEnd + 1) - Write-Host " $BLUEℹ️ $NC [方案B诊断] 命中候选#$candidateNo:$fn($param) len=$($funcText.Length)" + Write-Host " $BLUEℹ️ $NC [方案B诊断] 命中候选#${candidateNo}:$fn($param) len=$($funcText.Length)" Write-Host " $GREEN✓$NC [方案B] 已重写 $fn($param) 机器码源函数(融合版特征匹配)" $replacedB6 = $true $patched = $true