[Console]::OutputEncoding = [Text.Encoding]::UTF8 $cap = "$env:TEMP\opencode\sym_startup.pcap" $ts = "C:\Program Files\Wireshark\tshark.exe" $tpl = (Get-Content "C:\Users\tonycao\work\light\enet-validator\samples\announce_686.hex" -Raw).Trim() -replace '\s','' # 取两帧 live announce (不同时刻) $anns = @(& $ts -r $cap -Y "udp.length==652" -T fields -e frame.time_relative -e udp.payload 2>$null | Select-Object -First 2) $h0 = ($anns[0] -split "`t")[1]; $t0 = ($anns[0] -split "`t")[0] $h1 = ($anns[1] -split "`t")[1]; $t1 = ($anns[1] -split "`t")[0] Write-Host ("template len=" + $tpl.Length/2 + " live len=" + $h0.Length/2) Write-Host "" Write-Host "=== template vs liveA(t=$t0) 差异区域 ===" $n = [Math]::Min($tpl.Length, $h0.Length) $regions = @() for ($i = 0; $i -lt $n; $i += 2) { if ($tpl.Substring($i,2) -ne $h0.Substring($i,2)) { $off = $i/2 if ($regions.Count -eq 0 -or ($off - $regions[$regions.Count-1][1]) -gt 4) { [void]$regions.Add(@($off, $off)) } else { $regions[$regions.Count-1][1] = $off } } } foreach ($r in $regions) { $s = [Math]::Max(0, $r[0]-3); $e = [Math]::Min($tpl.Length/2-1, $r[1]+3) $st=''; $sl=''; $sr='' for ($i=$s; $i -le $e; $i++) { $st += $tpl.Substring(2*$i,2) $sl += $h0.Substring(2*$i,2) if ($i -le $h1.Length/2-1) { $sr += $h1.Substring(2*$i,2) } else { $sr += '??' } } Write-Host ("0x{0:x4}-0x{1:x4}: tpl={2} liveA={3} liveB={4}" -f $s, $e, $st, $sl, $sr) } # liveA vs liveB (两帧实时宣告间的差异 = 每次宣告都变的字段) Write-Host "" Write-Host "=== liveA(t=$t0) vs liveB(t=$t1) 差异 (每次宣告变化的字段) ===" $d2 = @() for ($i = 0; $i -lt $n; $i += 2) { if ($h0.Substring($i,2) -ne $h1.Substring($i,2)) { $off = $i/2 if ($d2.Count -eq 0 -or ($off - $d2[$d2.Count-1][1]) -gt 4) { [void]$d2.Add(@($off,$off)) } else { $d2[$d2.Count-1][1] = $off } } } foreach ($r in $d2) { $s = [Math]::Max(0, $r[0]-3); $e = [Math]::Min($h0.Length/2-1, $r[1]+3) $sl=''; $sr='' for ($i=$s; $i -le $e; $i++) { $sl += $h0.Substring(2*$i,2); $sr += $h1.Substring(2*$i,2) } Write-Host ("0x{0:x4}-0x{1:x4}: A={2} B={3}" -f $s, $e, $sl, $sr) } Set-Content -Encoding ascii "$env:TEMP\opencode\announce_live.hex" $h0 Write-Host "saved: announce_live.hex"