# Пересборка пункта Ventoy в g4d: 13 пробелов, граница — следующий "title". $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 не найден' } $nextTitle = Find-Bytes $b ([Text.Encoding]::ASCII.GetBytes("`ntitle")) $start if ($nextTitle -lt 0) { throw 'следующий title не найден' } $blockEnd = $nextTitle + 1 $oldLen = $blockEnd - $start '--- текущий блок ({0} байт):' -f $oldLen $cur = [Text.Encoding]::UTF8.GetString($b[$start..($blockEnd-1)]) ($cur -split "`n") | ForEach-Object { ' |' + ($_ -replace ' ','·') } $line1 = 'title' + (' ' * 13) + 'Ventoy (ISO образы)' $line2 = 'chainloader (bd)/efi/Paravis/boot/g4d/Ventoy' $base = $line1.Length + 1 + $line2.Length + 1 if ($base -gt $oldLen) { throw ("не влезает: база {0} > {1}" -f $base, $oldLen) } $newText = $line1 + "`n" + $line2 + (' ' * ($oldLen - $base)) + "`n" $newBytes = [Text.Encoding]::UTF8.GetBytes($newText) "--- новый блок: {0} байт (нужно {1})" -f $newBytes.Length, $oldLen 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 '--- новый блок:' $t = [Text.Encoding]::UTF8.GetString($nb[$start..($start+$oldLen-1)]) ($t -split "`n") | ForEach-Object { ' |' + ($_ -replace ' ','·') }