#!/usr/bin/perl

open(SIG, $ARGV[0]) || die "open $ARGV[0]: $!";

$n = sysread(SIG, $buf, 1000);  # read in file with name argv[0], and referred to here as SIG

if($n > 510){
  print STDERR "boot block too large: $n bytes (max 510)\n";
  exit 1;
}

print STDERR "boot block is $n bytes (max 510)\n";

$buf .= "\0" x (510-$n); # fill it up to 510 bytes with 0 bytes, using concatenation and string multiply
$buf .= "\x55\xAA";      # last two bytes are 0x55AA

open(SIG, ">$ARGV[0]") || die "open >$ARGV[0]: $!";  # write the buffer back to the file
print SIG $buf;
close SIG;
