4 * Very simple program to dump the contents of an OMF (OBJ) file
6 * This assumes a littleendian, unaligned-load-capable host and a
7 * C compiler which handles basic C99.
21 static const char *record_types
[256] =
65 typedef void (*dump_func
)(uint8_t, const uint8_t *, size_t);
67 static void hexdump_data(unsigned int offset
, const uint8_t *data
, size_t n
)
71 for (i
= 0; i
< n
; i
+= 16) {
72 printf(" %04x: ", i
+offset
);
73 for (j
= 0; j
< 16; j
++) {
75 printf("%02x%c", data
[i
+j
], (j
== 7) ? '-' : ' ');
80 for (j
= 0; j
< 16; j
++) {
82 putchar(isprint(data
[i
+j
]) ? data
[i
+j
] : '.');
88 static void dump_unknown(uint8_t type
, const uint8_t *data
, size_t n
)
91 hexdump_data(0, data
, n
);
94 static void dump_coment(uint8_t type
, const uint8_t *data
, size_t n
)
97 static const char *coment_class
[256] = {
98 [0x00] = "Translator",
100 [0x81] = "Library specifier",
101 [0x9c] = "MS-DOS version",
102 [0x9d] = "Memory model",
104 [0x9f] = "Library search",
105 [0xa0] = "OMF extensions",
106 [0xa1] = "New OMF extension",
107 [0xa2] = "Link pass separator",
117 [0xdd] = "Timestamp",
119 [0xe9] = "Dependency file",
120 [0xff] = "Command line"
124 dump_unknown(type
, data
, n
);
131 printf(" [NP=%d NL=%d UD=%02X] %02X %s\n",
136 coment_class
[class] ? coment_class
[class] : "???");
138 hexdump_data(2, data
+2, n
-2);
141 static const dump_func dump_type
[256] =
143 [0x88] = dump_coment
,
151 const uint8_t *p
, *data
;
158 data
= mmap(NULL
, len
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
159 if (data
== MAP_FAILED
)
168 n
= *(uint16_t *)(p
+1);
170 printf("%02x %-10s %4zd bytes",
172 record_types
[type
] ? record_types
[type
] : "???",
176 printf("\n (truncated, only %zd bytes left)\n", len
-3);
177 break; /* Truncated */
180 p
+= 3; /* Header doesn't count in the length */
181 n
--; /* Remove checksum byte */
184 for (i
= -3; i
< (int)n
; i
++)
187 printf(", checksum %02X", p
[i
]);
189 printf(" (valid)\n");
191 printf(" (actual = %02X)\n", csum
);
194 dump_type
[type
](type
, p
, n
);
196 dump_unknown(type
, p
, n
);
202 munmap((void *)data
, st
.st_size
);
206 int main(int argc
, char *argv
[])
213 for (i
= 1; i
< argc
; i
++) {
214 fd
= open(argv
[i
], O_RDONLY
);
215 if (fd
< 0 || dump_omf(fd
)) {