10 long translatelong(long in
) { /* translate from little endian to
11 local representation */
15 i
= (unsigned char *)&in
;
24 int16
translateshort(int16 in
) {
28 i
= (unsigned char *)&in
;
34 void print_header(long length
, int rdf_version
) {
35 char buf
[129],t
,s
,l
,flags
;
39 struct tMultiBootHeader
*mb
;
43 if (rdf_version
>= 2) {
44 fread(&reclen
,1,1,infile
);
48 case 1: /* relocation record */
49 case 6: /* segment relocation */
53 fread(&rs
,2,1,infile
);
54 printf(" %s: location (%04x:%08lx), length %d, "
55 "referred seg %04x\n", t
== 1 ? "relocation" : "seg relocation",
56 (int)s
,translatelong(o
),(int)l
,
58 if (rdf_version
>= 2 && reclen
!= 8)
59 printf(" warning: reclen != 8\n");
60 if (rdf_version
== 1) length
-= 9;
61 if (rdf_version
== 1 && t
== 6)
62 printf(" warning: seg relocation not supported in RDOFF1\n");
65 case 2: /* import record */
66 case 7: /* import far symbol */
67 fread(&rs
,2,1,infile
);
70 if (rdf_version
== 1) {
72 fread(&buf
[ll
],1,1,infile
);
77 for (;ll
< reclen
- 2; ll
++)
78 fread(&buf
[ll
],1,1,infile
);
81 printf(" %simport: segment %04x = %s\n",t
== 7 ? "far " : "",
82 translateshort(rs
),buf
);
83 if (rdf_version
== 1) length
-= ll
+ 3;
84 if (rdf_version
== 1 && t
== 7)
85 printf (" warning: far import not supported in RDOFF1\n");
88 case 3: /* export record */
89 fread(&flags
,1,1,infile
);
94 if (rdf_version
== 1) {
96 fread(&buf
[ll
],1,1,infile
);
101 for (; ll
< reclen
- 6; ll
++)
102 fread(&buf
[ll
],1,1,infile
);
104 if (flags
& SYM_GLOBAL
)
108 if (flags
& SYM_FUNCTION
) printf(" proc");
109 if (flags
& SYM_DATA
) printf(" data");
110 printf(": (%04x:%08lx) = %s\n",(int)s
,translatelong(o
),buf
);
111 if (rdf_version
== 1) length
-= ll
+ 6;
114 case 4: /* DLL and Module records */
118 if (rdf_version
== 1) {
120 fread(&buf
[ll
],1,1,infile
);
125 for (; ll
< reclen
; ll
++)
126 fread(&buf
[ll
],1,1,infile
);
128 if (t
==4) printf(" dll: %s\n",buf
);
129 else printf(" module: %s\n",buf
);
130 if (rdf_version
== 1) length
-= ll
+ 1;
132 case 5: /* BSS reservation */
133 fread(&ll
,4,1,infile
);
134 printf(" bss reservation: %08lx bytes\n",translatelong(ll
));
135 if (rdf_version
== 1) length
-= 5;
136 if (rdf_version
> 1 && reclen
!= 4)
137 printf(" warning: reclen != 4\n");
140 case 9: /* MultiBoot header record */
141 fread(buf
,reclen
,1,infile
);
142 mb
= (struct tMultiBootHeader
*)buf
;
143 printf(" multiboot header: load address=0x%X, size=0x%X, entry=0x%X\n",
144 mb
->LoadAddr
, mb
->LoadEndAddr
- mb
->LoadAddr
, mb
->Entry
);
147 printf(" unrecognised record (type %d",(int)t
);
148 if (rdf_version
> 1) {
149 printf(", length %d",(int)reclen
);
150 fseek(infile
,reclen
,SEEK_CUR
);
153 if (rdf_version
== 1) length
--;
155 if (rdf_version
!= 1) length
-= 2 + reclen
;
159 char * knowntypes
[8] = {"NULL", "text", "data", "object comment",
160 "linked comment", "loader comment",
161 "symbolic debug", "line number debug"};
163 char * translatesegmenttype(int16 type
) {
164 if (type
< 8) return knowntypes
[type
];
165 if (type
< 0x0020) return "reserved";
166 if (type
< 0x1000) return "reserved - moscow";
167 if (type
< 0x8000) return "reserved - system dependant";
168 if (type
< 0xFFFF) return "reserved - other";
169 if (type
== 0xFFFF) return "invalid type code";
170 return "type code out of range";
173 int main(int argc
,char **argv
) {
179 int foundnullsegment
= 0;
181 long segmentcontentlength
= 0;
183 long headerlength
= 0;
184 long objectlength
= 0;
186 puts("RDOFF Dump utility v2.1\n(c) Copyright 1996,99,2000 Julian R Hall, Yuri M Zaporogets");
189 fputs("Usage: rdfdump [-v] <filename>\n",stderr
);
193 if (! strcmp (argv
[1], "-v") )
198 fputs("required parameter missing\n",stderr
);
204 infile
= fopen(argv
[1],"rb");
206 fprintf(stderr
,"rdfdump: Could not open %s\n",argv
[1]);
210 fread(id
,6,1,infile
);
211 if (strncmp(id
,"RDOFF",5)) {
212 fputs("rdfdump: File does not contain valid RDOFF header\n",stderr
);
216 printf("File %s: RDOFF version %c\n\n",argv
[1],id
[5]);
217 if (id
[5] < '1' || id
[5] > '2') {
218 fprintf(stderr
,"rdfdump: unknown RDOFF version '%c'\n",id
[5]);
221 version
= id
[5] - '0';
224 fread(&l
, 4, 1, infile
);
225 objectlength
= translatelong(l
);
226 printf("Object content size: %ld bytes\n", objectlength
);
229 fread(&l
,4,1,infile
);
230 headerlength
= translatelong(l
);
231 printf("Header (%ld bytes):\n",headerlength
);
232 print_header(headerlength
, version
);
235 fread(&l
,4,1,infile
);
236 l
= translatelong(l
);
237 printf("\nText segment length = %ld bytes\n",l
);
240 fread(id
,1,1,infile
);
242 if (offset
% 16 == 0)
243 printf("\n%08lx ", offset
);
244 printf(" %02x",(int) (unsigned char)id
[0]);
248 if (verbose
) printf("\n\n");
250 fread(&l
,4,1,infile
);
251 l
= translatelong(l
);
252 printf("Data segment length = %ld bytes\n",l
);
258 fread(id
,1,1,infile
);
259 if (offset
% 16 == 0)
260 printf("\n%08lx ", offset
);
261 printf(" %02x",(int) (unsigned char) id
[0]);
270 fread(&s
,2,1,infile
);
271 s
= translateshort(s
);
273 printf("\nNULL segment\n");
274 foundnullsegment
= 1;
277 printf("\nSegment:\n Type = %04X (%s)\n",(int)s
,
278 translatesegmenttype(s
));
281 fread(&s
,2,1,infile
);
282 printf(" Number = %04X\n",(int)translateshort(s
));
283 fread(&s
,2,1,infile
);
284 printf(" Resrvd = %04X\n",(int)translateshort(s
));
285 fread(&l
,4,1,infile
);
286 l
= translatelong(l
);
287 printf(" Length = %ld bytes\n",l
);
288 segmentcontentlength
+= l
;
292 fread(id
,1,1,infile
);
294 if (offset
% 16 == 0)
295 printf("\n%08lx ", offset
);
296 printf(" %02x",(int) (unsigned char)id
[0]);
300 if (verbose
) printf("\n");
301 } while (!feof(infile
));
302 if (! foundnullsegment
)
303 printf("\nWarning: unexpected end of file - "
304 "NULL segment not found\n");
306 printf("\nTotal number of segments: %d\n", nsegments
);
307 printf("Total segment content length: %ld bytes\n",segmentcontentlength
);
309 /* calculate what the total object content length should have been */
310 l
= segmentcontentlength
+ 10 * (nsegments
+1) + headerlength
+ 4;
311 if (l
!= objectlength
)
312 printf("Warning: actual object length (%ld) != "
313 "stored object length (%ld)\n", l
, objectlength
);