Page 1 of 1

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

Posted: Wed Aug 24, 2016 11:54 pm
by sweh
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!

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

Posted: Thu Aug 25, 2016 12:10 am
by jgharston
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);
}

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

Posted: Tue Sep 13, 2016 12:25 am
by Coeus
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.

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

Posted: Tue Sep 13, 2016 7:23 am
by cmjones01
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

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

Posted: Tue Sep 13, 2016 8:19 am
by BigEd
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.