25 lines
1.2 KiB
PowerShell
25 lines
1.2 KiB
PowerShell
[Console]::OutputEncoding = [Text.Encoding]::UTF8
|
|
$tpl = (Get-Content "C:\Users\tonycao\work\light\enet-validator\samples\announce_686.hex" -Raw).Trim() -replace '\s',''
|
|
$h0 = (Get-Content "$env:TEMP\opencode\announce_live.hex" -Raw).Trim() -replace '\s',''
|
|
Write-Host ("template len=" + $tpl.Length/2 + " live len=" + $h0.Length/2)
|
|
$diffs = New-Object 'System.Collections.Generic.List[int]'
|
|
$n = [Math]::Min($tpl.Length, $h0.Length)
|
|
for ($i = 0; $i -lt $n; $i += 2) {
|
|
if ($tpl.Substring($i,2) -ne $h0.Substring($i,2)) { $diffs.Add([int]($i/2)) }
|
|
}
|
|
Write-Host ("differing bytes: " + $diffs.Count)
|
|
# 分组连续区域
|
|
$groups = New-Object 'System.Collections.Generic.List[object]'
|
|
foreach ($d in $diffs) {
|
|
if ($groups.Count -gt 0 -and ($d - $groups[$groups.Count-1][1]) -le 6) { $groups[$groups.Count-1][1] = $d }
|
|
else { $null = $groups.Add([pscustomobject]@{S=$d; E=$d}) }
|
|
}
|
|
foreach ($g in $groups) {
|
|
$s = [Math]::Max(0, $g.S-4); $e = [Math]::Min($n/2-1, $g.E+4)
|
|
$st=''; $sl=''
|
|
for ($i=$s; $i -le $e; $i++) { $st += $tpl.Substring(2*$i,2); $sl += $h0.Substring(2*$i,2) }
|
|
Write-Host ("0x{0:x4}-0x{1:x4}:" -f $s, $e)
|
|
Write-Host (" tpl = " + $st)
|
|
Write-Host (" live= " + $sl)
|
|
}
|