32 lines
1.8 KiB
PowerShell
32 lines
1.8 KiB
PowerShell
|
|
[Console]::OutputEncoding = [Text.Encoding]::UTF8
|
||
|
|
$cap = "$env:TEMP\opencode\sym_claim2.pcap"
|
||
|
|
$ts = "C:\Program Files\Wireshark\tshark.exe"
|
||
|
|
# 提取两个不同时刻的 announce (644B payload = 652 udplen) hex
|
||
|
|
$anns = @(& $ts -r $cap -Y "udp.length==652" -T fields -e frame.time_relative -e udp.payload 2>$null | Select-Object -First 2)
|
||
|
|
Write-Host ("announce count sample: " + $anns.Count)
|
||
|
|
if ($anns.Count -ge 2) {
|
||
|
|
$t0 = ($anns[0] -split "`t")[0]; $h0 = ($anns[0] -split "`t")[1]
|
||
|
|
$t1 = ($anns[1] -split "`t")[0]; $h1 = ($anns[1] -split "`t")[1]
|
||
|
|
Write-Host ("A t=" + $t0 + " len=" + ($h0.Length/2))
|
||
|
|
Write-Host ("B t=" + $t1 + " len=" + ($h1.Length/2))
|
||
|
|
# 找差异字节
|
||
|
|
$diffs = @()
|
||
|
|
$n = [Math]::Min($h0.Length, $h1.Length)
|
||
|
|
for ($i = 0; $i -lt $n; $i += 2) {
|
||
|
|
if ($h0.Substring($i,2) -ne $h1.Substring($i,2)) { $diffs += ($i/2) }
|
||
|
|
}
|
||
|
|
Write-Host ("differing byte offsets: " + (($diffs | ForEach-Object { '0x{0:x}' -f $_ }) -join ' '))
|
||
|
|
# 打印模板与实时帧在这些区域的内容
|
||
|
|
$tpl = (Get-Content "C:\Users\tonycao\work\light\enet-validator\samples\announce_686.hex" -Raw).Trim() -replace '\s',''
|
||
|
|
Write-Host ""
|
||
|
|
foreach ($d in $diffs) {
|
||
|
|
$s = [Math]::Max(0, $d - 4); $e = [Math]::Min($h0.Length/2 - 1, $d + 7)
|
||
|
|
$seg0 = ''; $seg1 = ''; $segt = ''
|
||
|
|
for ($i = $s; $i -le $e; $i++) { $seg0 += $h0.Substring(2*$i,2); $seg1 += $h1.Substring(2*$i,2); if (2*$i+2 -le $tpl.Length) { $segt += $tpl.Substring(2*$i,2) } else { $segt += '??????' } }
|
||
|
|
Write-Host ('0x{0:x}: liveA={1} liveB={2} tpl={3}' -f $d, $seg0, $seg1, $segt)
|
||
|
|
}
|
||
|
|
# 存下完整实时 announce 供修补用
|
||
|
|
Set-Content -Encoding ascii "$env:TEMP\opencode\announce_live.hex" $h0
|
||
|
|
Write-Host "saved live announce to announce_live.hex"
|
||
|
|
}
|