2 * rdfdump.c - dump RDOFF file header.
15 #define PROGRAM_VERSION "2.3"
19 void print_header(int32_t length
, int rdf_version
)
21 char buf
[129], t
, l
, s
, flags
;
27 fread(&t
, 1, 1, infile
);
28 if (rdf_version
>= 2) {
29 fread(&reclen
, 1, 1, infile
);
32 case RDFREC_GENERIC
: /* generic record */
33 printf(" generic record (length=%d)\n", (int)reclen
);
34 fseek(infile
, reclen
, SEEK_CUR
);
37 case RDFREC_RELOC
: /* relocation record */
38 case RDFREC_SEGRELOC
: /* segment relocation */
39 fread(&s
, 1, 1, infile
);
40 fread(&o
, 4, 1, infile
);
41 fread(&l
, 1, 1, infile
);
42 fread(&rs
, 2, 1, infile
);
43 printf(" %s: location (%04x:%08"PRIx32
"), length %d, "
44 "referred seg %04x\n",
45 t
== 1 ? "relocation" : "seg relocation", (int)s
,
46 translateint32_t(o
), (int)l
, translateint16_t(rs
));
47 if (rdf_version
>= 2 && reclen
!= 8)
48 printf(" warning: reclen != 8\n");
51 if (rdf_version
== 1 && t
== 6)
53 (" warning: seg relocation not supported in RDOFF1\n");
56 case RDFREC_IMPORT
: /* import record */
57 case RDFREC_FARIMPORT
: /* import far symbol */
58 fread(&flags
, 1, 1, infile
);
59 fread(&rs
, 2, 1, infile
);
62 if (rdf_version
== 1) {
64 fread(&buf
[ll
], 1, 1, infile
);
67 for (; ll
< reclen
- 3; ll
++)
68 fread(&buf
[ll
], 1, 1, infile
);
73 printf((flags
& SYM_IMPORT
) ? " import" : " extern");
74 if (flags
& SYM_FUNCTION
)
78 printf(": segment %04x = %s\n", translateint16_t(rs
), buf
);
81 if (rdf_version
== 1 && t
== 7)
83 (" warning: far import not supported in RDOFF1\n");
86 case RDFREC_GLOBAL
: /* export record */
87 fread(&flags
, 1, 1, infile
);
88 fread(&s
, 1, 1, infile
);
89 fread(&o
, 4, 1, infile
);
92 if (rdf_version
== 1) {
94 fread(&buf
[ll
], 1, 1, infile
);
97 for (; ll
< reclen
- 6; ll
++)
98 fread(&buf
[ll
], 1, 1, infile
);
100 printf((flags
& SYM_GLOBAL
) ? " export" : " public");
101 if (flags
& SYM_FUNCTION
)
103 if (flags
& SYM_DATA
)
105 printf(": (%04x:%08"PRIx32
") = %s\n", (int)s
, translateint32_t(o
), buf
);
106 if (rdf_version
== 1)
110 case RDFREC_DLL
: /* DLL and Module records */
113 if (rdf_version
== 1) {
115 fread(&buf
[ll
], 1, 1, infile
);
118 for (; ll
< reclen
; ll
++)
119 fread(&buf
[ll
], 1, 1, infile
);
122 printf(" dll: %s\n", buf
);
124 printf(" module: %s\n", buf
);
125 if (rdf_version
== 1)
129 case RDFREC_BSS
: /* BSS reservation */
130 fread(&ll
, 4, 1, infile
);
131 printf(" bss reservation: %08"PRIx32
" bytes\n", translateint32_t(ll
));
132 if (rdf_version
== 1)
134 if (rdf_version
> 1 && reclen
!= 4)
135 printf(" warning: reclen != 4\n");
142 fread(&seg
, 2, 1, infile
);
143 fread(&size
, 4, 1, infile
);
144 fread(&align
, 2, 1, infile
);
145 for (ll
= 0; ll
< reclen
- 8; ll
++)
146 fread(buf
+ ll
, 1, 1, infile
);
147 printf(" common: segment %04x = %s, %"PRId32
":%d\n",
148 translateint16_t(seg
), buf
, translateint32_t(size
),
149 translateint16_t(align
));
154 printf(" unrecognized record (type %d", (int)t
);
155 if (rdf_version
> 1) {
156 printf(", length %d", (int)reclen
);
157 fseek(infile
, reclen
, SEEK_CUR
);
162 if (rdf_version
!= 1)
163 length
-= 2 + reclen
;
167 int main(int argc
, char **argv
)
174 int foundnullsegment
= 0;
176 int32_t segmentcontentlength
= 0;
178 int32_t headerlength
= 0;
179 int32_t objectlength
= 0;
181 printf("RDOFF dump utility, version %s\n", PROGRAM_VERSION
);
182 printf("RDOFF2 revision %s\n", RDOFF2_REVISION
);
183 puts("Copyright (c) 1996,99 Julian R Hall\n"
184 "Improvements and fixes (c) 2002-2004 RET & COM Research.");
187 fputs("Usage: rdfdump [-v] <filename>\n", stderr
);
191 if (!strcmp(argv
[1], "-v")) {
194 fputs("required parameter missing\n", stderr
);
200 infile
= fopen(argv
[1], "rb");
202 fprintf(stderr
, "rdfdump: Could not open %s\n", argv
[1]);
206 fread(id
, 6, 1, infile
);
207 if (strncmp(id
, "RDOFF", 5)) {
208 fputs("rdfdump: File does not contain valid RDOFF header\n",
213 printf("File %s: RDOFF version %c\n\n", argv
[1], id
[5]);
214 if (id
[5] < '1' || id
[5] > '2') {
215 fprintf(stderr
, "rdfdump: unknown RDOFF version '%c'\n", id
[5]);
218 version
= id
[5] - '0';
221 fread(&l
, 4, 1, infile
);
222 objectlength
= translateint32_t(l
);
223 printf("Object content size: %"PRId32
" bytes\n", objectlength
);
226 fread(&l
, 4, 1, infile
);
227 headerlength
= translateint32_t(l
);
228 printf("Header (%"PRId32
" bytes):\n", headerlength
);
229 print_header(headerlength
, version
);
232 fread(&l
, 4, 1, infile
);
233 l
= translateint32_t(l
);
234 printf("\nText segment length = %"PRId32
" bytes\n", l
);
237 fread(id
, 1, 1, infile
);
239 if (offset
% 16 == 0)
240 printf("\n%08"PRIx32
" ", offset
);
241 printf(" %02x", (int)(uint8_t)id
[0]);
248 fread(&l
, 4, 1, infile
);
249 l
= translateint32_t(l
);
250 printf("Data segment length = %"PRId32
" bytes\n", l
);
255 fread(id
, 1, 1, infile
);
256 if (offset
% 16 == 0)
257 printf("\n%08"PRIx32
" ", offset
);
258 printf(" %02x", (int)(uint8_t)id
[0]);
265 fread(&s
, 2, 1, infile
);
266 s
= translateint16_t(s
);
268 printf("\nNULL segment\n");
269 foundnullsegment
= 1;
272 printf("\nSegment:\n Type = %04X (%s)\n", (int)s
,
273 translatesegmenttype(s
));
276 fread(&s
, 2, 1, infile
);
277 printf(" Number = %04X\n", (int)translateint16_t(s
));
278 fread(&s
, 2, 1, infile
);
279 printf(" Resrvd = %04X\n", (int)translateint16_t(s
));
280 fread(&l
, 4, 1, infile
);
281 l
= translateint32_t(l
);
282 printf(" Length = %"PRId32
" bytes\n", l
);
283 segmentcontentlength
+= l
;
287 fread(id
, 1, 1, infile
);
289 if (offset
% 16 == 0)
290 printf("\n%08"PRIx32
" ", offset
);
291 printf(" %02x", (int)(uint8_t)id
[0]);
297 } while (!feof(infile
));
298 if (!foundnullsegment
)
299 printf("\nWarning: unexpected end of file - "
300 "NULL segment not found\n");
302 printf("\nTotal number of segments: %d\n", nsegments
);
303 printf("Total segment content length: %"PRId32
" bytes\n",
304 segmentcontentlength
);
306 /* calculate what the total object content length should have been */
307 l
= segmentcontentlength
+ 10 * (nsegments
+ 1) + headerlength
+ 4;
308 if (l
!= objectlength
)
309 printf("Warning: actual object length (%"PRId32
") != "
310 "stored object length (%"PRId32
")\n", l
, objectlength
);