#!/usr/bin/env perl

use bytes;
use strict;

@ARGV == 1 || die "No filename given";

open (FILEH, "<". $ARGV[0]) || die "Failed to open file " . $ARGV[1];
binmode FILEH;

my $hdr;
my $len = read (FILEH, $hdr, 6);

defined ($len) || die "File read error ($!)";
$len == 6 || die "Failed to read all 6 bytes of the .CO header";

my ($start, $len, $exec) = unpack ('vvv', $hdr);

print "Start:  $start\n";
print "Length: $len (End == ", $start + $len, ")\n";
print "Entry:  $exec\n";

if ($len + 6 != -s $ARGV[0]) {
	print STDERR "Warning: length inconsistency\r\n";
}
if ($exec < $start || $exec >= $start + $len) {
	print STDERR "Warning: execution address is out-of-range\r\n"
}

close FILEH;

