Like the *DUMP format? Wish you had it on Linux?

discuss PC<>Acorn file transfer issues & the use of FDC, XFER, Omniflop/disk etc.
User avatar
sweh
Posts: 1847
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Like the *DUMP format? Wish you had it on Linux?

Postby sweh » Wed Aug 24, 2016 11:54 pm

I call this program `hdump`

Code: Select all

#!/bin/sh

if [ -t ]
then
  cols=$(tput cols)
fi
cols=${cols:-80}

if [ $cols -ge 80 ]
then
  x=16
  a=8
else
  x=8
  a=4
fi

case $1 in
  -16) x=16 ; a=8 ; shift ;;
   -8) x=8 ; shift ;;
esac

exec hexdump -v -e '"%0'$a'_ax  "' -e $x'/1 "%02X ""  "" "' -e $x'/1 "%_p""\n"' "$@"


Maybe it's too much Beebing as a kid, but I find this format still the easiest to look at binary files!
Rgds
Stephen

User avatar
jgharston
Posts: 2756
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: Like the *DUMP format? Wish you had it on Linux?

Postby jgharston » Thu Aug 25, 2016 12:10 am

sweh wrote:Maybe it's too much Beebing as a kid, but I find this format still the easiest to look at binary files!

Me too, which is why one of the first C/Unix programs I wrote was fdump:

Code: Select all

/* fdump.c - file dump program, Copyright (C)1992 J.G.Harston *
 * cut-down version of full fdump program                     *
 * - no columns option                                        *
 * - offset option, 2-Sep-92                                  *
 * - no decimal offset option                                 *
 */

#include <stdio.h>

main(argc,argv)
int argc;
char *argv[];

{
FILE *f1;
int addr=0;
int c;
int eof=0;
char buffer[20];
int p=0;
int cols=16;

if (argc < 2 || argc > 3) {
  printf("Usage: %s file (start)\n",argv[0]);
  exit(1);
  }
if ((f1=fopen(argv[1],"r")) == NULL) {
  perror(argv[0]);
  exit(1);
  }
if (argc == 3) {
  sscanf(argv[2],"%X",&addr);
  }
fseek(f1,addr,0);

while (!eof) {
  printf("%06X ",addr);
  for (p=0; p<cols; p++) {
    if (!eof) {
      c=getc(f1);
      if (c == EOF) {
        eof=1;
        }
      else {
        buffer[p]=c;
        printf("%02X ",c);
        }
      }
    if (eof) {
      buffer[p]=32;
      printf("** ");
      }
    }
  for (p=0; p<cols; p++) {
    c=(buffer[p] & 127);
    if (c < ' ' || c == 127) c='.';
    putchar(c);
    }
  addr=addr+cols;
  printf("\n");
  }
fclose(f1);
exit(0);
}

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

Coeus
Posts: 464
Joined: Mon Jul 25, 2016 11:05 am

Re: Like the *DUMP format? Wish you had it on Linux?

Postby Coeus » Tue Sep 13, 2016 12:25 am

I like ghex for this. It uses the familiar *DUMP format, i.e. hex on the left ASCII on the right. It defaults to 16 bytes/line instead of 8 but you can have any number you like by resizing the window.

cmjones01
Posts: 135
Joined: Fri Sep 06, 2013 2:12 pm
Location: Warsaw, Poland and Cambridge, UK

Re: Like the *DUMP format? Wish you had it on Linux?

Postby cmjones01 » Tue Sep 13, 2016 7:23 am

Hear hear! I too have written *DUMP-like utilities for Linux. My favourite is one I call 'hdump2' which will display hex and ASCII from two files at the same time, with timestamps. It's really handy for analysing both directions of serial communication channels at the same time, like:

hdump2 /dev/ttyUSB0 /dev/ttyUSB1

Will display data from both devices in such a way that you can see which data came from which device, in what order, and when. And it's all inspired by *DUMP.


https://martin-jones.com/2013/07/05/emb ... the-cheap/

Chris

User avatar
BigEd
Posts: 1490
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Like the *DUMP format? Wish you had it on Linux?

Postby BigEd » Tue Sep 13, 2016 8:19 am

xxd is pretty handy - I used to use od but it's not as friendly.

Code: Select all

$ man csh | tail | xxd| head
0000000: 2020 2020 2020 2042 7279 616e 2044 756e         Bryan Dun
0000010: 6c61 702c 2043 6c61 7974 6f6e 2045 6c77  lap, Clayton Elw
0000020: 656c 6c2c 204b 6172 6c20 4b6c 6569 6e70  ell, Karl Kleinp
0000030: 6173 7465 2c20 426f 6220 4d61 6e73 6f6e  aste, Bob Manson

It has lots of options, including 'plain' and 'reverse' mode, which together mean you can patch a binary with sed or awk.


Return to “software & utilities for the pc, mac or unix”

Who is online

Users browsing this forum: No registered users and 3 guests