#!/usr/bin/env perl

use strict;
use bytes;

@ARGV == 4 || die "Should be 4 arguments";

my $in_name = shift (@ARGV);
my $out_name = shift (@ARGV);

my $length = -s $in_name;
open INFILE, "<$in_name" or die "Failed to open input file";
binmode INFILE;
open OUTFILE, ">$out_name" or die "Failed to open output file";
binmode OUTFILE;

my $start = shift (@ARGV) + 0;
my $exec  = shift (@ARGV) + 0;

my $header = pack ("vvv", $start, $length, $exec);

print OUTFILE $header;

# copy the file contents
my $buffer;
while (read(INFILE, $buffer, 1024)) {
      print OUTFILE $buffer;
}
