Files
flash-build/restore-x86xor.ps1
2026-11-13 07:52:38 +03:00

42 lines
1.7 KiB
PowerShell

# Восстановление x86.xor: оригинал (KRD 18) + рабочая правка Ventoy.
$ErrorActionPreference = 'Stop'
$bak = 'C:\PF\flash-backup-2026-10-30-2\01-PARAVIS-F\efi\Boot\x86.xor'
$dst = 'F:\efi\Paravis\Boot\loaders\xb32' # не используется, просто место
$cur = 'F:\efi\Boot\x86.xor'
$keep = 'C:\PF\Ventoy\backup\x86.xor.editor-ventoy.bin'
if (Get-Process -Name vmware-vmx -ErrorAction SilentlyContinue) { throw 'VM запущена' }
# сохранить текущий (после редактора) на всякий случай
Copy-Item $cur $keep -Force
$b = [IO.File]::ReadAllBytes($bak)
$rec = 5 * 0x200 # запись Ventoy
$path = '/EFI/BOOT/grubia32.efi'
$bytes = [Text.Encoding]::Unicode.GetBytes($path)
$slot = 0x130 - 0xBA
if ($bytes.Length + 2 -gt $slot) { throw 'путь не влезает' }
for ($i = 0; $i -lt $slot; $i++) { $b[$rec + 0xBA + $i] = 0 }
[Array]::Copy($bytes, 0, $b, $rec + 0xBA, $bytes.Length)
[IO.File]::WriteAllBytes($cur, $b)
# контроль
$nb = [IO.File]::ReadAllBytes($cur)
"--- записан: {0:N0} байт" -f $nb.Length
$u = [Text.Encoding]::Unicode.GetString($nb)
'--- пути (UTF-16):'
$i = 0
while ($i -lt $u.Length - 2) {
$c = [int]$u[$i]
if ($c -ge 32 -and $c -lt 127) {
$j = $i
while ($j -lt $u.Length -and [int]$u[$j] -ge 32 -and [int]$u[$j] -lt 127) { $j++ }
if ($j - $i -ge 5) { ' 0x{0:X4}: {1}' -f ($i*2), $u.Substring($i, $j-$i) }
$i = $j
} else { $i++ }
}
'--- cmdline/initrd (ASCII):'
$s = [Text.Encoding]::ASCII.GetString($nb)
([regex]::Matches($s,'[\x20-\x7E]{12,}') | ForEach-Object { $_.Value }) | Select-Object -First 5 | ForEach-Object { ' ' + $_ }