7 typedef unsigned short int16
;
9 long translatelong(long in
) { /* translate from little endian to
10 local representation */
14 i
= (unsigned char *)&in
;
23 int translateshort(int16 in
) {
27 i
= (unsigned char *)&in
;
33 void print_header(long length
, int rdf_version
) {
41 if (rdf_version
>= 2) {
42 fread(&reclen
,1,1,infile
);
45 case 1: /* relocation record */
46 case 6: /* segment relocation */
50 fread(&rs
,2,1,infile
);
51 printf(" %s: location (%04x:%08lx), length %d, "
52 "referred seg %04x\n", t
== 1 ? "relocation" : "seg relocation",
53 (int)s
,translatelong(o
),(int)l
,
55 if (rdf_version
>= 2 && reclen
!= 8)
56 printf(" warning: reclen != 8\n");
57 if (rdf_version
== 1) length
-= 9;
58 if (rdf_version
== 1 && t
== 6)
59 printf(" warning: seg relocation not supported in RDOFF1\n");
61 case 2: /* import record */
62 case 7: /* import far symbol */
63 fread(&rs
,2,1,infile
);
66 if (rdf_version
== 1) {
68 fread(&buf
[ll
],1,1,infile
);
73 for (;ll
< reclen
- 2; ll
++)
74 fread(&buf
[ll
],1,1,infile
);
77 printf(" %simport: segment %04x = %s\n",t
== 7 ? "far " : "",
78 translateshort(rs
),buf
);
79 if (rdf_version
== 1) length
-= ll
+ 3;
80 if (rdf_version
== 1 && t
== 7)
81 printf (" warning: far import not supported in RDOFF1\n");
83 case 3: /* export record */
88 if (rdf_version
== 1) {
90 fread(&buf
[ll
],1,1,infile
);
95 for (; ll
< reclen
- 5; ll
++)
96 fread(&buf
[ll
],1,1,infile
);
98 printf(" export: (%04x:%08lx) = %s\n",(int)s
,translatelong(o
),buf
);
99 if (rdf_version
== 1) length
-= ll
+ 6;
101 case 4: /* DLL record */
104 if (rdf_version
== 1) {
106 fread(&buf
[ll
],1,1,infile
);
111 for (; ll
< reclen
- 1; ll
++)
112 fread(&buf
[ll
],1,1,infile
);
114 printf(" dll: %s\n",buf
);
115 if (rdf_version
== 1) length
-= ll
+ 1;
117 case 5: /* BSS reservation */
118 fread(&ll
,4,1,infile
);
119 printf(" bss reservation: %08lx bytes\n",translatelong(ll
));
120 if (rdf_version
== 1) length
-= 5;
121 if (rdf_version
> 1 && reclen
!= 4)
122 printf(" warning: reclen != 4\n");
125 printf(" unrecognised record (type %d",(int)t
);
126 if (rdf_version
> 1) printf(", length %d",(int)reclen
);
128 if (rdf_version
== 1) length
--;
130 if (rdf_version
!= 1) length
-= 2 + reclen
;
134 char * knowntypes
[8] = {"NULL", "text", "data", "object comment",
135 "linked comment", "loader comment",
136 "symbolic debug", "line number debug"};
138 char * translatesegmenttype(int16 type
) {
139 if (type
< 8) return knowntypes
[type
];
140 if (type
< 0x0020) return "reserved";
141 if (type
< 0x1000) return "reserved - moscow";
142 if (type
< 0x8000) return "reserved - system dependant";
143 if (type
< 0xFFFF) return "reserved - other";
144 if (type
== 0xFFFF) return "invalid type code";
145 return "type code out of range";
148 int main(int argc
,char **argv
) {
154 int foundnullsegment
= 0;
156 long segmentcontentlength
= 0;
158 long headerlength
= 0;
159 long objectlength
= 0;
161 puts("RDOFF Dump utility v2.0 (C) Copyright 1996 Julian R Hall");
164 fputs("Usage: rdfdump [-v] <filename>\n",stderr
);
168 if (! strcmp (argv
[1], "-v") )
173 fputs("required parameter missing\n",stderr
);
179 infile
= fopen(argv
[1],"rb");
181 fprintf(stderr
,"rdfdump: Could not open %s",argv
[1]);
185 fread(id
,6,1,infile
);
186 if (strncmp(id
,"RDOFF",5)) {
187 fputs("rdfdump: File does not contain valid RDOFF header\n",stderr
);
191 printf("File %s: RDOFF version %c\n\n",argv
[1],id
[5]);
192 if (id
[5] < '1' || id
[5] > '2') {
193 fprintf(stderr
,"rdfdump: unknown RDOFF version '%c'\n",id
[5]);
196 version
= id
[5] - '0';
199 fread(&l
, 4, 1, infile
);
200 objectlength
= translatelong(l
);
201 printf("Object content size: %ld bytes\n", objectlength
);
204 fread(&l
,4,1,infile
);
205 headerlength
= translatelong(l
);
206 printf("Header (%ld bytes):\n",headerlength
);
207 print_header(headerlength
, version
);
210 fread(&l
,4,1,infile
);
211 l
= translatelong(l
);
212 printf("\nText segment length = %ld bytes\n",l
);
215 fread(id
,1,1,infile
);
217 if (offset
% 16 == 0)
218 printf("\n%08lx ", offset
);
219 printf(" %02x",(int) (unsigned char)id
[0]);
223 if (verbose
) printf("\n\n");
225 fread(&l
,4,1,infile
);
226 l
= translatelong(l
);
227 printf("Data segment length = %ld bytes\n",l
);
233 fread(id
,1,1,infile
);
234 if (offset
% 16 == 0)
235 printf("\n%08lx ", offset
);
236 printf(" %02x",(int) (unsigned char) id
[0]);
245 fread(&s
,2,1,infile
);
246 s
= translateshort(s
);
248 printf("\nNULL segment\n");
249 foundnullsegment
= 1;
252 printf("\nSegment:\n Type = %04X (%s)\n",(int)s
,
253 translatesegmenttype(s
));
256 fread(&s
,2,1,infile
);
257 printf(" Number = %04X\n",(int)translateshort(s
));
258 fread(&s
,2,1,infile
);
259 printf(" Resrvd = %04X\n",(int)translateshort(s
));
260 fread(&l
,4,1,infile
);
261 l
= translatelong(l
);
262 printf(" Length = %ld bytes\n",l
);
263 segmentcontentlength
+= l
;
267 fread(id
,1,1,infile
);
269 if (offset
% 16 == 0)
270 printf("\n%08lx ", offset
);
271 printf(" %02x",(int) (unsigned char)id
[0]);
275 if (verbose
) printf("\n");
276 } while (!feof(infile
));
277 if (! foundnullsegment
)
278 printf("\nWarning: unexpected end of file - "
279 "NULL segment not found\n");
281 printf("\nTotal number of segments: %d\n", nsegments
);
282 printf("Total segment content length: %ld bytes\n",segmentcontentlength
);
284 /* calculate what the total object content length should have been */
285 l
= segmentcontentlength
+ 10 * (nsegments
+1) + headerlength
+ 4;
286 if (l
!= objectlength
)
287 printf("Warning: actual object length (%ld) != "
288 "stored object length (%ld)\n", l
, objectlength
);