/* hexdump.c Version 1.0b */ /* COPYRIGHT (C) 1994-2002 Norbert H. Doerry SYNTAX: HEXDUMP file This program provides a hex dump of the specified file Format of the line AAAA: DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD !AAAAAAAAAAAAAAAA Version 1.0 9 May 1994 Version 1.0a 17 May 1994 - Open file as a binary file instead of default Version 1.0b 22 June 2002 - Added GNU License, recompile using 32 bit compiler --------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --------------------------------------------------------------- If you discover any bugs, or have any questions concerning these programs, please send me an email (doerry@aol.com) */ #include #include #include int main(int argc, char **argv) { long int addr; /* address of the first character in the line */ int buffer[17]; /* character buffer */ int nbr; /* number of characters in the buffer */ int cnt; /* counter */ int last_line; /* = 1 if the last line, otherwise 0 */ FILE *in; /* input file stream */ /* if a file is specified on the command line, try to open the file, if unsuccessful, print error message and exit. if no file specified, use the standard input, stdin */ in = (argc > 1) ? fopen(argv[1],"rb") : stdin; if (in == (FILE *) NULL) { fprintf(stderr,"\n ***ERROR: Unable to open file %s\n",argv[1]); exit(1); } for (addr=0,last_line=0;last_line == 0;addr+=16) { /* read in the line */ for (nbr=0; nbr < 16 && last_line == 0 ; nbr++) { buffer[nbr] = fgetc(in) & 0x00FF; last_line = feof(in); } /* if last_line is set, ignore the EOF character */ if (last_line) nbr--; /* print the starting address for the line */ printf("%04X: ",addr); /* print the hex representations of the file */ for (cnt = 0; cnt < nbr ; cnt++) printf("%02X ",buffer[cnt]); for ( ; cnt < 16 ; cnt++) printf(" "); /* print the character delimiter */ printf("!"); /* print out the non-control characters */ for (cnt = 0; cnt < nbr ; cnt++) { if (isprint(buffer[cnt])) printf("%c",buffer[cnt]); else printf("."); } printf("\n"); } if (in != stdin) fclose(in); return 0; }