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

45 lines
2.1 KiB
PowerShell

# Пересборка пункта Ventoy в g4d: без ведущих пробелов, добивка в конце строки chainloader.
$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
}
$start = Find-Bytes $b ([Text.Encoding]::ASCII.GetBytes('title Ventoy (ISO'))
if ($start -lt 0) { throw 'пункт Ventoy не найден' }
$bootPos = Find-Bytes $b ([Text.Encoding]::ASCII.GetBytes("`nboot`n")) $start
if ($bootPos -lt 0) { throw 'конец блока не найден' }
$blockEnd = $bootPos + 6
$oldLen = $blockEnd - $start
$line1 = 'title' + (' ' * 13) + 'Ventoy (ISO образы)'
$line2 = 'chainloader (bd)/efi/Paravis/boot/g4d/Ventoy'
$base = ($line1 + "`n" + $line2).Length + 1 # + завершающий \n
"--- старый блок {0} байт, база {1} байт, добивка {2}" -f $oldLen, $base, ($oldLen - $base)
if ($base -gt $oldLen) { throw 'не влезает' }
$newText = $line1 + "`n" + $line2 + (' ' * ($oldLen - $base)) + "`n"
$newBytes = [Text.Encoding]::UTF8.GetBytes($newText)
"--- итоговая длина блока: {0}" -f $newBytes.Length
if (Get-Process -Name vmware-vmx -ErrorAction SilentlyContinue) { throw 'VM запущена — отмена' }
$out = New-Object System.Collections.Generic.List[byte]
$out.AddRange([byte[]]$b[0..($start-1)])
$out.AddRange($newBytes)
$out.AddRange([byte[]]$b[$blockEnd..($b.Length-1)])
[IO.File]::WriteAllBytes($f, $out.ToArray())
$nb = [IO.File]::ReadAllBytes($f)
"--- файл: {0} байт (было {1})" -f $nb.Length, $b.Length
$txt = [Text.Encoding]::UTF8.GetString($nb[$start..($start+80)])
'--- начало блока:'
$txt -split "`n" | Select-Object -First 3 | ForEach-Object { ' |' + (($_ -replace ' ','·').Substring(0,[Math]::Min(80,$_.Length))) }