Files

26 lines
775 B
PowerShell

param(
[Parameter(Mandatory=$true)][int]$Disk,
[Parameter(Mandatory=$true)][string]$Boot,
[Parameter(Mandatory=$true)][string]$Out
)
$ErrorActionPreference = 'Stop'
$bootData = [IO.File]::ReadAllBytes($Boot)
if ($bootData.Length -lt 512) { throw "Bad boot.img: $Boot" }
$mbr = New-Object byte[] 512
$fs = [IO.File]::Open("\\.\PhysicalDrive$Disk", [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
try {
$fs.Read($mbr, 0, 512) | Out-Null
}
finally {
$fs.Close()
}
# 0..439 — наш boot-код; 440..511 — текущая таблица разделов/подпись диска
$img = New-Object byte[] 512
[Array]::Copy($bootData, 0, $img, 0, 440)
[Array]::Copy($mbr, 440, $img, 440, 72)
[IO.File]::WriteAllBytes($Out, $img)