# Инлайн команд Ventoy в меню g4d (вместо chainloader на g4d\Ventoy). $ErrorActionPreference = 'Stop' $targets = @('F:\grldr', 'F:\efi\Paravis\Boot\g4d\grldr') 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 } if (Get-Process -Name vmware-vmx -ErrorAction SilentlyContinue) { throw 'VM запущена — отмена' } $line1 = 'title' + (' ' * 13) + 'Ventoy (ISO образы)' $line2 = 'find --set-root /ventoy/core.img' $line3 = 'kernel /ventoy/core.img' $line4 = 'boot' foreach ($f in $targets) { $b = [IO.File]::ReadAllBytes($f) $startNeedle = [Text.Encoding]::UTF8.GetBytes('title' + (' ' * 13) + 'Ventoy (ISO') $start = Find-Bytes $b $startNeedle if ($start -lt 0) { " $f : пункт Ventoy не найден"; continue } $nextTitle = Find-Bytes $b ([Text.Encoding]::ASCII.GetBytes("`ntitle")) $start if ($nextTitle -lt 0) { throw "$f : следующий title не найден" } $blockEnd = $nextTitle + 1 $oldLen = $blockEnd - $start $core = [Text.Encoding]::UTF8.GetBytes($line1 + "`n" + $line2 + "`n" + $line3 + "`n" + $line4 + "`n") if ($core.Length -gt $oldLen) { throw ("$f : не влезает {0} > {1}" -f $core.Length, $oldLen) } # добивка — в конец строки boot (перед завершающим \n), чтобы не было «строки из пробелов» $body = New-Object System.Collections.Generic.List[byte] $body.AddRange([byte[]]$core[0..($core.Length-2)]) for ($i = 0; $i -lt ($oldLen - $core.Length); $i++) { $body.Add(0x20) } $body.Add(0x0A) $out = New-Object System.Collections.Generic.List[byte] $out.AddRange([byte[]]$b[0..($start-1)]) $out.AddRange($body.ToArray()) $out.AddRange([byte[]]$b[$blockEnd..($b.Length-1)]) [IO.File]::WriteAllBytes($f, $out.ToArray()) $nb = [IO.File]::ReadAllBytes($f) "--- $f : {0} байт (было {1})" -f $nb.Length, $b.Length $t = [Text.Encoding]::UTF8.GetString($nb[$start..($start+$oldLen-1)]) ($t -split "`n") | ForEach-Object { ' ' + (($_ -replace ' ','·').Substring(0,[Math]::Min(60,$_.Length))) } }