2 * rdfdump.c - dump RDOFF file header.
13 #define PROGRAM_VERSION "2.3"
17 void print_header(long length
, int rdf_version
)
19 char buf
[129], t
, l
, s
, flags
;
25 fread(&t
, 1, 1, infile
);
26 if (rdf_version
>= 2) {
27 fread(&reclen
, 1, 1, infile
);
30 case RDFREC_GENERIC
: /* generic record */
31 printf(" generic record (length=%d)\n", (int)reclen
);
32 fseek(infile
, reclen
, SEEK_CUR
);
35 case RDFREC_RELOC
: /* relocation record */
36 case RDFREC_SEGRELOC
: /* segment relocation */
37 fread(&s
, 1, 1, infile
);
38 fread(&o
, 4, 1, infile
);
39 fread(&l
, 1, 1, infile
);
40 fread(&rs
, 2, 1, infile
);
41 printf(" %s: location (%04x:%08lx), length %d, "
42 "referred seg %04x\n",
43 t
== 1 ? "relocation" : "seg relocation", (int)s
,
44 translatelong(o
), (int)l
, translateshort(rs
));
45 if (rdf_version
>= 2 && reclen
!= 8)
46 printf(" warning: reclen != 8\n");
49 if (rdf_version
== 1 && t
== 6)
51 (" warning: seg relocation not supported in RDOFF1\n");
54 case RDFREC_IMPORT
: /* import record */
55 case RDFREC_FARIMPORT
: /* import far symbol */
56 fread(&flags
, 1, 1, infile
);
57 fread(&rs
, 2, 1, infile
);
60 if (rdf_version
== 1) {
62 fread(&buf
[ll
], 1, 1, infile
);
65 for (; ll
< reclen
- 3; ll
++)
66 fread(&buf
[ll
], 1, 1, infile
);
71 printf((flags
& SYM_IMPORT
) ? " import" : " extern");
72 if (flags
& SYM_FUNCTION
)
76 printf(": segment %04x = %s\n", translateshort(rs
), buf
);
79 if (rdf_version
== 1 && t
== 7)
81 (" warning: far import not supported in RDOFF1\n");
84 case RDFREC_GLOBAL
: /* export record */
85 fread(&flags
, 1, 1, infile
);
86 fread(&s
, 1, 1, infile
);
87 fread(&o
, 4, 1, infile
);
90 if (rdf_version
== 1) {
92 fread(&buf
[ll
], 1, 1, infile
);
95 for (; ll
< reclen
- 6; ll
++)
96 fread(&buf
[ll
], 1, 1, infile
);
98 printf((flags
& SYM_GLOBAL
) ? " export" : " public");
99 if (flags
& SYM_FUNCTION
)
101 if (flags
& SYM_DATA
)
103 printf(": (%04x:%08lx) = %s\n", (int)s
, translatelong(o
), buf
);
104 if (rdf_version
== 1)
108 case RDFREC_DLL
: /* DLL and Module records */
111 if (rdf_version
== 1) {
113 fread(&buf
[ll
], 1, 1, infile
);
116 for (; ll
< reclen
; ll
++)
117 fread(&buf
[ll
], 1, 1, infile
);
120 printf(" dll: %s\n", buf
);
122 printf(" module: %s\n", buf
);
123 if (rdf_version
== 1)
127 case RDFREC_BSS
: /* BSS reservation */
128 fread(&ll
, 4, 1, infile
);
129 printf(" bss reservation: %08lx bytes\n", translatelong(ll
));
130 if (rdf_version
== 1)
132 if (rdf_version
> 1 && reclen
!= 4)
133 printf(" warning: reclen != 4\n");
137 unsigned short seg
, align
;
140 fread(&seg
, 2, 1, infile
);
141 fread(&size
, 4, 1, infile
);
142 fread(&align
, 2, 1, infile
);
143 for (ll
= 0; ll
< reclen
- 8; ll
++)
144 fread(buf
+ ll
, 1, 1, infile
);
145 printf(" common: segment %04x = %s, %ld:%d\n",
146 translateshort(seg
), buf
, translatelong(size
),
147 translateshort(align
));
152 printf(" unrecognized record (type %d", (int)t
);
153 if (rdf_version
> 1) {
154 printf(", length %d", (int)reclen
);
155 fseek(infile
, reclen
, SEEK_CUR
);
160 if (rdf_version
!= 1)
161 length
-= 2 + reclen
;
165 int main(int argc
, char **argv
)
172 int foundnullsegment
= 0;
174 long segmentcontentlength
= 0;
176 long headerlength
= 0;
177 long objectlength
= 0;
179 printf("RDOFF dump utility, version %s\n", PROGRAM_VERSION
);
180 printf("RDOFF2 revision %s\n", RDOFF2_REVISION
);
181 puts("Copyright (c) 1996,99 Julian R Hall\n"
182 "Improvements and fixes (c) 2002-2004 RET & COM Research.");
185 fputs("Usage: rdfdump [-v] <filename>\n", stderr
);
189 if (!strcmp(argv
[1], "-v")) {
192 fputs("required parameter missing\n", stderr
);
198 infile
= fopen(argv
[1], "rb");
200 fprintf(stderr
, "rdfdump: Could not open %s\n", argv
[1]);
204 fread(id
, 6, 1, infile
);
205 if (strncmp(id
, "RDOFF", 5)) {
206 fputs("rdfdump: File does not contain valid RDOFF header\n",
211 printf("File %s: RDOFF version %c\n\n", argv
[1], id
[5]);
212 if (id
[5] < '1' || id
[5] > '2') {
213 fprintf(stderr
, "rdfdump: unknown RDOFF version '%c'\n", id
[5]);
216 version
= id
[5] - '0';
219 fread(&l
, 4, 1, infile
);
220 objectlength
= translatelong(l
);
221 printf("Object content size: %ld bytes\n", objectlength
);
224 fread(&l
, 4, 1, infile
);
225 headerlength
= translatelong(l
);
226 printf("Header (%ld bytes):\n", headerlength
);
227 print_header(headerlength
, version
);
230 fread(&l
, 4, 1, infile
);
231 l
= translatelong(l
);
232 printf("\nText segment length = %ld bytes\n", l
);
235 fread(id
, 1, 1, infile
);
237 if (offset
% 16 == 0)
238 printf("\n%08lx ", offset
);
239 printf(" %02x", (int)(unsigned char)id
[0]);
246 fread(&l
, 4, 1, infile
);
247 l
= translatelong(l
);
248 printf("Data segment length = %ld bytes\n", l
);
253 fread(id
, 1, 1, infile
);
254 if (offset
% 16 == 0)
255 printf("\n%08lx ", offset
);
256 printf(" %02x", (int)(unsigned char)id
[0]);
263 fread(&s
, 2, 1, infile
);
264 s
= translateshort(s
);
266 printf("\nNULL segment\n");
267 foundnullsegment
= 1;
270 printf("\nSegment:\n Type = %04X (%s)\n", (int)s
,
271 translatesegmenttype(s
));
274 fread(&s
, 2, 1, infile
);
275 printf(" Number = %04X\n", (int)translateshort(s
));
276 fread(&s
, 2, 1, infile
);
277 printf(" Resrvd = %04X\n", (int)translateshort(s
));
278 fread(&l
, 4, 1, infile
);
279 l
= translatelong(l
);
280 printf(" Length = %ld bytes\n", l
);
281 segmentcontentlength
+= l
;
285 fread(id
, 1, 1, infile
);
287 if (offset
% 16 == 0)
288 printf("\n%08lx ", offset
);
289 printf(" %02x", (int)(unsigned char)id
[0]);
295 } while (!feof(infile
));
296 if (!foundnullsegment
)
297 printf("\nWarning: unexpected end of file - "
298 "NULL segment not found\n");
300 printf("\nTotal number of segments: %d\n", nsegments
);
301 printf("Total segment content length: %ld bytes\n",
302 segmentcontentlength
);
304 /* calculate what the total object content length should have been */
305 l
= segmentcontentlength
+ 10 * (nsegments
+ 1) + headerlength
+ 4;
306 if (l
!= objectlength
)
307 printf("Warning: actual object length (%ld) != "
308 "stored object length (%ld)\n", l
, objectlength
);