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

59 lines
2.7 KiB
PowerShell

# Ventoy в g4d: 20 пробелов перед пунктом, длина файла сохраняется.
$ErrorActionPreference = 'Stop'
$f = 'F:\efi\Paravis\Boot\g4d\grldr'
$origSize = 325669
$spaces = 20
if (Get-Process -Name vmware-vmx -ErrorAction SilentlyContinue) { throw 'VM запущена' }
$b = [IO.File]::ReadAllBytes($f)
"--- файл до правки: {0} байт" -f $b.Length
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'))
while ($start -ge 0) {
$chunk = [Text.Encoding]::UTF8.GetString($b[$start..([Math]::Min($b.Length-1, $start+60))])
if ($chunk -match '^title\s+Ventoy \(ISO') { break }
$start = Find-Bytes $b ([Text.Encoding]::ASCII.GetBytes('title')) ($start + 5)
}
if ($start -lt 0) { throw 'Ventoy не найден' }
$nextTitle = Find-Bytes $b ([Text.Encoding]::ASCII.GetBytes("`ntitle")) $start
if ($nextTitle -lt 0) { throw 'следующий title не найден' }
$blockEnd = $nextTitle + 1
$oldLen = $blockEnd - $start
$curLineEnd = (Find-Bytes $b ([Text.Encoding]::ASCII.GetBytes("`n")) $start)
$curLine = [Text.Encoding]::UTF8.GetString($b[$start..($curLineEnd-1)])
"--- сейчас: '{0}'" -f ($curLine -replace ' ','·')
$line1 = 'title' + (' ' * $spaces) + 'Ventoy (ISO образы)'
$line2 = 'chainloader (bd)/efi/Paravis/boot/g4d/Ventoy'
$coreLen = [Text.Encoding]::UTF8.GetByteCount($line1) + 1 + [Text.Encoding]::UTF8.GetByteCount($line2) + 1
if ($coreLen -gt $oldLen) { throw ("не влезает: {0} > {1}" -f $coreLen, $oldLen) }
$newBytes = New-Object System.Collections.Generic.List[byte]
$newBytes.AddRange([Text.Encoding]::UTF8.GetBytes($line1)); $newBytes.Add(0x0A)
$newBytes.AddRange([Text.Encoding]::UTF8.GetBytes($line2))
for ($i = 0; $i -lt ($oldLen - $coreLen); $i++) { $newBytes.Add(0x20) }
$newBytes.Add(0x0A)
$out = New-Object System.Collections.Generic.List[byte]
$out.AddRange([byte[]]$b[0..($start-1)])
$out.AddRange($newBytes.ToArray())
$out.AddRange([byte[]]$b[$blockEnd..($b.Length-1)])
[IO.File]::WriteAllBytes($f, $out.ToArray())
$nb = [IO.File]::ReadAllBytes($f)
"--- файл после: {0} байт (эталон {1}) {2}" -f $nb.Length, $origSize, $(if ($nb.Length -eq $origSize) { 'OK' } else { 'РАЗМЕР ИЗМЕНИЛСЯ' })
$ns = [Text.Encoding]::UTF8.GetString($nb[$start..($start+$oldLen-1)])
($ns -split "`n") | ForEach-Object { ' |' + (($_ -replace ' ','·').Substring(0,[Math]::Min(70,$_.Length))) }