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", t
== 1 ? "relocation" : "seg relocation",
43 (int) s
, translatelong(o
), (int) l
, translateshort(rs
));
44 if (rdf_version
>= 2 && reclen
!= 8)
45 printf(" warning: reclen != 8\n");
48 if (rdf_version
== 1 && t
== 6)
49 printf(" warning: seg relocation not supported in RDOFF1\n");
52 case RDFREC_IMPORT
: /* import record */
53 case RDFREC_FARIMPORT
: /* import far symbol */
54 fread(&flags
, 1, 1, infile
);
55 fread(&rs
, 2, 1, infile
);
58 if (rdf_version
== 1) {
60 fread(&buf
[ll
], 1, 1, infile
);
63 for (; ll
< reclen
- 3; ll
++)
64 fread(&buf
[ll
], 1, 1, infile
);
69 printf((flags
& SYM_IMPORT
) ? " import" : " extern");
70 if (flags
& SYM_FUNCTION
)
74 printf(": segment %04x = %s\n", translateshort(rs
), buf
);
77 if (rdf_version
== 1 && t
== 7)
78 printf(" warning: far import not supported in RDOFF1\n");
81 case RDFREC_GLOBAL
: /* export record */
82 fread(&flags
, 1, 1, infile
);
83 fread(&s
, 1, 1, infile
);
84 fread(&o
, 4, 1, infile
);
87 if (rdf_version
== 1) {
89 fread(&buf
[ll
], 1, 1, infile
);
92 for (; ll
< reclen
- 6; ll
++)
93 fread(&buf
[ll
], 1, 1, infile
);
95 printf((flags
& SYM_GLOBAL
) ? " export" : " public");
96 if (flags
& SYM_FUNCTION
)
100 printf(": (%04x:%08lx) = %s\n", (int) s
, translatelong(o
), buf
);
101 if (rdf_version
== 1)
105 case RDFREC_DLL
: /* DLL and Module records */
108 if (rdf_version
== 1) {
110 fread(&buf
[ll
], 1, 1, infile
);
113 for (; ll
< reclen
; ll
++)
114 fread(&buf
[ll
], 1, 1, infile
);
117 printf(" dll: %s\n", buf
);
119 printf(" module: %s\n", buf
);
120 if (rdf_version
== 1)
124 case RDFREC_BSS
: /* BSS reservation */
125 fread(&ll
, 4, 1, infile
);
126 printf(" bss reservation: %08lx bytes\n", translatelong(ll
));
127 if (rdf_version
== 1)
129 if (rdf_version
> 1 && reclen
!= 4)
130 printf(" warning: reclen != 4\n");
133 case RDFREC_COMMON
: {
134 unsigned short seg
, align
;
137 fread(&seg
, 2, 1, infile
);
138 fread(&size
, 4, 1, infile
);
139 fread(&align
, 2, 1, infile
);
140 for (ll
= 0; ll
< reclen
- 8; ll
++)
141 fread(buf
+ ll
, 1, 1, infile
);
142 printf(" common: segment %04x = %s, %ld:%d\n", translateshort(seg
),
143 buf
, translatelong(size
), translateshort(align
));
148 printf(" unrecognized record (type %d", (int) t
);
149 if (rdf_version
> 1) {
150 printf(", length %d", (int) reclen
);
151 fseek(infile
, reclen
, SEEK_CUR
);
156 if (rdf_version
!= 1)
157 length
-= 2 + reclen
;
161 int main(int argc
, char **argv
)
168 int foundnullsegment
= 0;
170 long segmentcontentlength
= 0;
172 long headerlength
= 0;
173 long objectlength
= 0;
175 printf("RDOFF dump utility, version %s\n", PROGRAM_VERSION
);
176 printf("RDOFF2 revision %s\n", RDOFF2_REVISION
);
177 puts("Copyright (c) 1996,99 Julian R Hall\n"
178 "Improvements and fixes (c) 2002-2004 RET & COM Research.");
181 fputs("Usage: rdfdump [-v] <filename>\n", stderr
);
185 if (!strcmp(argv
[1], "-v")) {
188 fputs("required parameter missing\n", stderr
);
194 infile
= fopen(argv
[1], "rb");
196 fprintf(stderr
, "rdfdump: Could not open %s\n", argv
[1]);
200 fread(id
, 6, 1, infile
);
201 if (strncmp(id
, "RDOFF", 5)) {
202 fputs("rdfdump: File does not contain valid RDOFF header\n", stderr
);
206 printf("File %s: RDOFF version %c\n\n", argv
[1], id
[5]);
207 if (id
[5] < '1' || id
[5] > '2') {
208 fprintf(stderr
, "rdfdump: unknown RDOFF version '%c'\n", id
[5]);
211 version
= id
[5] - '0';
214 fread(&l
, 4, 1, infile
);
215 objectlength
= translatelong(l
);
216 printf("Object content size: %ld bytes\n", objectlength
);
219 fread(&l
, 4, 1, infile
);
220 headerlength
= translatelong(l
);
221 printf("Header (%ld bytes):\n", headerlength
);
222 print_header(headerlength
, version
);
225 fread(&l
, 4, 1, infile
);
226 l
= translatelong(l
);
227 printf("\nText segment length = %ld bytes\n", l
);
230 fread(id
, 1, 1, infile
);
232 if (offset
% 16 == 0)
233 printf("\n%08lx ", offset
);
234 printf(" %02x", (int) (unsigned char) id
[0]);
241 fread(&l
, 4, 1, infile
);
242 l
= translatelong(l
);
243 printf("Data segment length = %ld bytes\n", l
);
248 fread(id
, 1, 1, infile
);
249 if (offset
% 16 == 0)
250 printf("\n%08lx ", offset
);
251 printf(" %02x", (int) (unsigned char) id
[0]);
258 fread(&s
, 2, 1, infile
);
259 s
= translateshort(s
);
261 printf("\nNULL segment\n");
262 foundnullsegment
= 1;
265 printf("\nSegment:\n Type = %04X (%s)\n", (int) s
, translatesegmenttype(s
));
268 fread(&s
, 2, 1, infile
);
269 printf(" Number = %04X\n", (int) translateshort(s
));
270 fread(&s
, 2, 1, infile
);
271 printf(" Resrvd = %04X\n", (int) translateshort(s
));
272 fread(&l
, 4, 1, infile
);
273 l
= translatelong(l
);
274 printf(" Length = %ld bytes\n", l
);
275 segmentcontentlength
+= l
;
279 fread(id
, 1, 1, infile
);
281 if (offset
% 16 == 0)
282 printf("\n%08lx ", offset
);
283 printf(" %02x", (int) (unsigned char) id
[0]);
289 } while (!feof(infile
));
290 if (!foundnullsegment
)
291 printf("\nWarning: unexpected end of file - " "NULL segment not found\n");
293 printf("\nTotal number of segments: %d\n", nsegments
);
294 printf("Total segment content length: %ld bytes\n", segmentcontentlength
);
296 /* calculate what the total object content length should have been */
297 l
= segmentcontentlength
+ 10 * (nsegments
+ 1) + headerlength
+ 4;
298 if (l
!= objectlength
)
299 printf("Warning: actual object length (%ld) != " "stored object length (%ld)\n", l
, objectlength
);