1
/* @(#)dump.c 1.11 00/12/09 joerg */
4
"@(#)dump.c 1.11 00/12/09 joerg";
7
* File dump.c - dump a file/device both in hex and in ASCII.
9
Written by Eric Youngdale (1993).
11
Copyright 1993 Yggdrasil Computing, Incorporated
13
This program is free software; you can redistribute it and/or modify
14
it under the terms of the GNU General Public License as published by
15
the Free Software Foundation; either version 2, or (at your option)
18
This program is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
GNU General Public License for more details.
23
You should have received a copy of the GNU General Public License
24
along with this program; if not, write to the Free Software
25
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
37
#include <sys/ioctl.h>
46
unsigned char buffer[256];
47
unsigned char search[64];
52
struct termios savetty;
53
struct termios newtty;
55
struct termio savetty;
59
void reset_tty __PR((void));
60
void set_tty __PR((void));
61
void onsusp __PR((int sig));
62
void crsr2 __PR((int row, int col));
63
void showblock __PR((int flag));
64
int getbyte __PR((void));
65
void usage __PR((int excode));
66
int main __PR((int argc, char *argv[]));
71
if(tcsetattr(0, TCSANOW, &savetty) == -1)
73
if(ioctl(0, TCSETAF, &savetty)==-1)
77
comerr("Cannot put tty into normal mode\n");
79
printf("Cannot put tty into normal mode\n");
89
if(tcsetattr(0, TCSANOW, &newtty) == -1)
91
if(ioctl(0, TCSETAF, &newtty)==-1)
95
comerr("Cannot put tty into raw mode\n");
97
printf("Cannot put tty into raw mode\n");
104
/* Come here when we get a suspend signal from the terminal */
111
/* ignore SIGTTOU so we don't get stopped if csh grabs the tty */
112
signal(SIGTTOU, SIG_IGN);
117
signal(SIGTTOU, SIG_DFL);
118
/* Send the TSTP signal to suspend our process group */
119
signal(SIGTSTP, SIG_DFL);
122
/* Pause for station break */
125
signal (SIGTSTP, onsusp);
136
printf("\033[%d;%dH",row,col);
145
lseek(fileno(infile), file_addr, SEEK_SET);
146
read(fileno(infile), buffer, sizeof(buffer));
150
if (sizeof(file_addr) > sizeof(long)) {
151
printf("%16.16llx ", (Llong)file_addr+(i<<4));
153
printf("%8.8lx ", (long)file_addr+(i<<4));
156
printf("%2.2x",buffer[(i<<4)+j]);
157
if(!(j & 0x3)) printf(" ");
160
k = buffer[(i << 4) + j];
161
if(k >= ' ' && k < 0x80) printf("%c",k);
167
if (sizeof(file_addr) > sizeof(long)) {
168
printf(" Zone, zone offset: %14llx %12.12llx ",
169
(Llong)file_addr>>11, (Llong)file_addr & 0x7ff);
171
printf(" Zone, zone offset: %6lx %4.4lx ",
172
(long)(file_addr>>11), (long)(file_addr & 0x7ff));
181
c1 = buffer[file_addr & (PAGE-1)];
183
if ((file_addr & (PAGE-1)) == 0) showblock(0);
191
errmsgno(EX_BAD, "Usage: %s [options] image\n",
206
save_args(argc, argv);
210
infile = fopen(argv[1],"rb");
211
if (infile == NULL) {
213
comerr("Cannot open '%s'.\n", argv[1]);
215
printf("Cannot open '%s'.\n", argv[1]);
219
for(i=0;i<30;i++) printf("\n");
220
file_addr = (off_t)0;
221
/* Now setup the keyboard for single character input. */
222
#ifdef HAVE_TERMIOS_H
223
if(tcgetattr(0, &savetty) == -1)
225
if(ioctl(0, TCGETA, &savetty) == -1)
229
comerr("Stdin must be a tty\n");
231
printf("Stdin must be a tty\n");
236
newtty.c_lflag&=~ICANON;
237
newtty.c_lflag&=~ECHO;
241
signal(SIGTSTP, onsusp);
245
if(file_addr < (off_t)0) file_addr = (off_t)0;
248
if (c == 'a') file_addr -= PAGE;
249
if (c == 'b') file_addr += PAGE;
252
printf("Enter new starting block (in hex):");
253
if (sizeof(file_addr) > sizeof(long)) {
256
file_addr = (off_t)ll;
260
file_addr = (off_t)l;
262
file_addr = file_addr << 11;
268
printf("Enter new search string:");
269
fgets((char *)search,sizeof(search),stdin);
270
while(search[strlen((char *)search)-1] == '\n') search[strlen((char *)search)-1] = 0;
278
if (c == search[0]) break;
280
for (j=1;j<strlen((char *)search);j++)
281
if(search[j] != getbyte()) break;
282
if(j==strlen((char *)search)) break;
284
file_addr &= ~(PAGE-1);