|
|
|
@ -618,37 +618,61 @@ function Modify-CursorJSFiles { |
|
|
|
|
|
|
|
$hashRegex = [regex]::new('createHash\(["'']sha256["'']\)') |
|
|
|
$hashMatches = $hashRegex.Matches($windowText) |
|
|
|
Write-Host " $BLUEℹ️ $NC [方案B诊断] id.js偏移=$markerIndex | sha256 createHash 命中=$($hashMatches.Count)" |
|
|
|
$patched = $false |
|
|
|
$diagLines = @() |
|
|
|
$candidateNo = 0 |
|
|
|
|
|
|
|
foreach ($hm in $hashMatches) { |
|
|
|
$candidateNo++ |
|
|
|
$hashPos = $hm.Index |
|
|
|
$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) |
|
|
|
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 |
|
|
|
if ($endBrace -lt 0) { continue } |
|
|
|
if ($endBrace -lt 0) { |
|
|
|
if ($candidateNo -le 3) { $diagLines += "候选#$candidateNo: 花括号配对失败(扫描上限内未闭合)" } |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
$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+)\)') |
|
|
|
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 |
|
|
|
$param = $sig.Groups[2].Value |
|
|
|
|
|
|
|
# 特征校验: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';}" |
|
|
|
$absStart = $markerIndex + $funcStart |
|
|
|
$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 " $GREEN✓$NC [方案B] 已重写 $fn($param) 机器码源函数(融合版特征匹配)" |
|
|
|
$replacedB6 = $true |
|
|
|
$patched = $true |
|
|
|
@ -657,6 +681,9 @@ function Modify-CursorJSFiles { |
|
|
|
|
|
|
|
if (-not $patched) { |
|
|
|
Write-Host " $YELLOW⚠️ $NC [方案B] 未定位到机器码源函数特征,已跳过" |
|
|
|
foreach ($d in ($diagLines | Select-Object -First 3)) { |
|
|
|
Write-Host " $BLUEℹ️ $NC [方案B诊断] $d" |
|
|
|
} |
|
|
|
} |
|
|
|
} catch { |
|
|
|
Write-Host " $YELLOW⚠️ $NC [方案B] 定位失败,已跳过:$($_.Exception.Message)" |
|
|
|
|