#!/usr/bin/perl -w
use strict;
use Fcntl qw(:DEFAULT :seek);

my $file = shift;
sysopen(F, $file, O_RDONLY) or die "$file: $!";

my $sect = 0;
my $prev = 0;
my $buffer;
while (1) {
  if (!sysseek(F, $sect * 512, SEEK_SET)) { last; }
  if (!sysread(F, $buffer, 16)) { last; }
  if (substr($buffer,0,3) =~ /^\xEB[<X]\x90/) {
    $buffer =~ s/([\x00-\x1f])/'<' . ord($1) . '>'/gse;
    $buffer =~ s/([\x7f-\xff])/'<' . ord($1) . '>'/gse;
    if ($prev) {
      printf(STDERR "- %8i, d = %i\n", $sect - 1, $sect - $prev);
    }
    printf(STDERR "  %8i: %s\n", $sect, $buffer);
    $prev = $sect;
  }
  $sect++;
}
printf(STDERR "- %8i, d = %i\n", $sect - 1, $sect - $prev);
