Files
flash-build/g4d-ventoy-shift.ps1
T
2026-11-13 07:52:38 +03:00

46 lines
2.0 KiB
PowerShell

# Сдвиг пункта Ventoy в g4d: 13 ведущих пробелов вместо 5 (длина файла сохраняется).
$ErrorActionPreference = 'Stop'
$f = 'F:\efi\Paravis\Boot\g4d\grldr'
$b = [IO.File]::ReadAllBytes($f)
function Find-Bytes([byte[]]$hay, [byte[]]$needle, [int]$from = 0) {
for ($i = $from; $i -le $hay.Length - $needle.Length; $i++) {
$ok = $true
for ($j = 0; $j -lt $needle.Length; $j++) { if ($hay[$i+$j] -ne $needle[$j]) { $ok = $false; break } }
if ($ok) { return $i }
}
return -1
}
$startMarker = [Text.Encoding]::ASCII.GetBytes('title Ventoy (ISO')
$start = Find-Bytes $b $startMarker
if ($start -lt 0) { throw 'пункт Ventoy не найден' }
$bootMarker = [Text.Encoding]::ASCII.GetBytes("`nboot`n")
$bootPos = Find-Bytes $b $bootMarker $start
if ($bootPos -lt 0) { throw 'конец блока не найден' }
$blockEnd = $bootPos + $bootMarker.Length
$oldLen = $blockEnd - $start
$newText = (@(
('title' + (' ' * 13) + 'Ventoy (ISO образы)'),
'chainloader (bd)/efi/Paravis/boot/g4d/Ventoy'
) -join "`n") + "`n"
$newBytes = [Text.Encoding]::UTF8.GetBytes($newText)
"--- старый блок {0} байт, новый {1} байт" -f $oldLen, $newBytes.Length
if ($newBytes.Length -gt $oldLen) { throw 'не влезает' }
$pad = New-Object byte[] ($oldLen - $newBytes.Length)
for ($i = 0; $i -lt $pad.Length; $i++) { $pad[$i] = 0x20 }
$out = New-Object System.Collections.Generic.List[byte]
$out.AddRange([byte[]]$b[0..($start-1)])
$out.AddRange($newBytes); $out.AddRange($pad)
$out.AddRange([byte[]]$b[$blockEnd..($b.Length-1)])
if (Get-Process -Name vmware-vmx -ErrorAction SilentlyContinue) { throw 'VM запущена — правка отменена' }
[IO.File]::WriteAllBytes($f, $out.ToArray())
$nb = [IO.File]::ReadAllBytes($f)
"--- итог: {0} байт (было {1})" -f $nb.Length, $b.Length
$t = [Text.Encoding]::UTF8.GetString($nb[$start..($blockEnd-1)])
($t -split "`n") | ForEach-Object { ' |' + ($_ -replace ' ', '·') }