/* * hex - a simple hex file viewer * (c) John Donoghue, 1997. *------------------------------- * Version: 1.0 * Licence: GPL - Use and modify as * per the GPL licence, */ #include #define MAX_HEX 16 void DisplayHex(unsigned char *string,int size); void DisplayChar(unsigned char *string,int size); int main(int argc,char **argv) { FILE *file; unsigned long address=0; unsigned char buffer[16]; int i; if(argc<2) { printf("HEX V1.00 (c) John Donoghue\n"); printf("Displays a hex dump of a file.\n"); printf("Usage: %s [file]\n",argv[0]); exit(0); } file=fopen(argv[1],"r+b"); if(!file) { printf("Can't open file %s.\n",argv[1]); exit(0); } i=fread(buffer,1,MAX_HEX,file); while(i!=0) { printf("%08lx ",address); DisplayHex(buffer,i); printf(" "); DisplayChar(buffer,i); address+=i; printf("\n"); i=fread(buffer,1,MAX_HEX,file); } fclose(file); return(0); } void DisplayHex(unsigned char *string,int size) { int i; for(i=0;i=0x20 && string[i]<127) printf("%c",(int)string[i]); else printf("."); } else printf(" "); } return; }