7 long translatelong(long in
) { /* translate from little endian to
8 local representation */
12 i
= (unsigned char *)&in
;
21 int translateshort(short in
) {
25 i
= (unsigned char *)&in
;
30 void print_header(long length
) {
31 unsigned char buf
[129],t
,s
,l
;
38 case 1: /* relocation record */
42 fread(&rs
,2,1,infile
);
43 printf(" relocation: location (%04x:%08lx), length %d, "
44 "referred seg %04x\n",(int)s
,translatelong(o
),(int)l
,
48 case 2: /* import record */
49 fread(&rs
,2,1,infile
);
52 fread(&buf
[l
],1,1,infile
);
54 printf(" import: segment %04x = %s\n",translateshort(rs
),buf
);
57 case 3: /* export record */
62 fread(&buf
[l
],1,1,infile
);
64 printf(" export: (%04x:%08lx) = %s\n",(int)s
,translatelong(o
),buf
);
67 case 4: /* DLL record */
70 fread(&buf
[l
],1,1,infile
);
72 printf(" dll: %s\n",buf
);
75 case 5: /* BSS reservation */
77 printf(" bss reservation: %08lx bytes\n",translatelong(l
));
81 printf(" unrecognised record (type %d)\n",(int)t
);
87 int main(int argc
,char **argv
) {
92 puts("RDOFF Dump utility v1.1 (C) Copyright 1996 Julian R Hall");
95 fputs("Usage: rdfdump [-v] <filename>\n",stderr
);
99 if (! strcmp (argv
[1], "-v") )
104 fputs("required parameter missing\n",stderr
);
110 infile
= fopen(argv
[1],"rb");
112 fprintf(stderr
,"rdfdump: Could not open %s",argv
[1]);
116 fread(id
,6,1,infile
);
117 if (strncmp(id
,"RDOFF",5)) {
118 fputs("rdfdump: File does not contain valid RDOFF header\n",stderr
);
122 printf("File %s: RDOFF version %c\n\n",argv
[1],id
[5]);
123 if (id
[5] < '1' || id
[5] > '1') {
124 fprintf(stderr
,"rdfdump: unknown RDOFF version '%c'\n",id
[5]);
128 fread(&l
,4,1,infile
);
129 l
= translatelong(l
);
130 printf("Header (%ld bytes):\n",l
);
133 fread(&l
,4,1,infile
);
134 l
= translatelong(l
);
135 printf("\nText segment length = %ld bytes\n",l
);
137 fread(id
,1,1,infile
);
138 if (verbose
) printf(" %02x",(int) (unsigned char)id
[0]);
140 if (verbose
) printf("\n\n");
142 fread(&l
,4,1,infile
);
143 l
= translatelong(l
);
144 printf("Data segment length = %ld bytes\n",l
);
149 fread(id
,1,1,infile
);
150 printf(" %02x",(int) (unsigned char) id
[0]);