2 * Dumping of LE binaries
4 * Copyright 2004 Robert Reif
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 unsigned long o32_size
;
34 unsigned long o32_base
;
35 unsigned long o32_flags
;
36 unsigned long o32_pagemap
;
37 unsigned long o32_mapsize
;
43 unsigned short o32_pagedataoffset
;
44 unsigned char o32_pagesize
;
45 unsigned char o32_pageflags
;
50 unsigned char b32_cnt
;
51 unsigned char b32_type
;
57 unsigned short sdk_version
;
58 unsigned short device_number
;
59 unsigned char version_major
;
60 unsigned char version_minor
;
63 unsigned long init_order
;
64 unsigned long ctrl_ofs
;
65 unsigned long v86_ctrl_ofs
;
66 unsigned long pm_ctrl_ofs
;
67 unsigned long v86_ctrl_csip
;
68 unsigned long pm_ctrl_csip
;
69 unsigned long rm_ref_data
;
70 unsigned long service_table_ofs
;
71 unsigned long service_table_size
;
72 unsigned long win32_service_table_ofs
;
75 unsigned long reserved0
;
76 unsigned long reserved1
;
77 unsigned long reserved2
;
80 static inline WORD
get_word( const BYTE
*ptr
)
82 return ptr
[0] | (ptr
[1] << 8);
85 static void dump_le_header( const IMAGE_VXD_HEADER
*le
)
87 printf( "File header:\n" );
88 printf( " Magic: %04x (%c%c)\n",
89 le
->e32_magic
, LOBYTE(le
->e32_magic
), HIBYTE(le
->e32_magic
));
90 printf( " Byte order: %s\n",
91 le
->e32_border
== 0 ? "little-indian" : "big-endian");
92 printf( " Word order: %s\n",
93 le
->e32_worder
== 0 ? "little-indian" : "big-endian");
94 printf( " Executable format level: %d\n",
96 printf( " CPU type: %s\n",
97 le
->e32_cpu
== 0x01 ? "Intel 80286" :
98 le
->e32_cpu
== 0x02 ? "Intel 80386" :
99 le
->e32_cpu
== 0x03 ? "Intel 80486" :
100 le
->e32_cpu
== 0x04 ? "Intel 80586" :
101 le
->e32_cpu
== 0x20 ? "Intel i860 (N10)" :
102 le
->e32_cpu
== 0x21 ? "Intel i860 (N11)" :
103 le
->e32_cpu
== 0x40 ? "MIPS Mark I" :
104 le
->e32_cpu
== 0x41 ? "MIPS Mark II" :
105 le
->e32_cpu
== 0x42 ? "MIPS Mark III" :
107 printf( " Target operating system: %s\n",
108 le
->e32_os
== 0x01 ? "OS/2" :
109 le
->e32_os
== 0x02 ? "Windows" :
110 le
->e32_os
== 0x03 ? "DOS 4.x" :
111 le
->e32_os
== 0x04 ? "Windows 386" :
113 printf( " Module version: %d\n",
115 printf( " Module type flags: %08x\n",
117 if (le
->e32_mflags
& 0x8000)
119 if (le
->e32_mflags
& 0x0004)
120 printf( " Global initialization\n");
122 printf( " Per-Process initialization\n");
123 if (le
->e32_mflags
& 0x0010)
124 printf( " No internal fixup\n");
125 if (le
->e32_mflags
& 0x0020)
126 printf( " No external fixup\n");
127 if ((le
->e32_mflags
& 0x0700) == 0x0100)
128 printf( " Incompatible with PM windowing\n");
129 else if ((le
->e32_mflags
& 0x0700) == 0x0200)
130 printf( " Compatible with PM windowing\n");
131 else if ((le
->e32_mflags
& 0x0700) == 0x0300)
132 printf( " Uses PM windowing API\n");
133 if (le
->e32_mflags
& 0x2000)
134 printf( " Module not loadable\n");
135 if (le
->e32_mflags
& 0x8000)
136 printf( " Module is DLL\n");
138 printf( " Number of memory pages: %d\n",
140 printf( " Initial object CS number: %08x\n",
142 printf( " Initial EIP: %08x\n",
144 printf( " Initial object SS number: %08x\n",
146 printf( " Initial ESP: %08x\n",
148 printf( " Memory page size: %d\n",
150 printf( " Bytes on last page: %d\n",
151 le
->e32_lastpagesize
);
152 printf( " Fix-up section size: %d\n",
154 printf( " Fix-up section checksum: %08x\n",
156 printf( " Loader section size: %d\n",
158 printf( " Loader section checksum: %08x\n",
160 printf( " Offset of object table: %08x\n",
162 printf( " Object table entries: %d\n",
164 printf( " Object page map offset: %08x\n",
166 printf( " Object iterate data map offset: %08x\n",
168 printf( " Resource table offset: %08x\n",
170 printf( " Resource table entries: %d\n",
172 printf( " Resident names table offset: %08x\n",
174 printf( " Entry table offset: %08x\n",
176 printf( " Module directives table offset: %08x\n",
178 printf( " Module directives entries: %d\n",
180 printf( " Fix-up page table offset: %08x\n",
182 printf( " Fix-up record table offset: %08x\n",
184 printf( " Imported modules name table offset: %08x\n",
186 printf( " Imported modules count: %d\n",
188 printf( " Imported procedure name table offset: %08x\n",
190 printf( " Per-page checksum table offset: %08x\n",
192 printf( " Data pages offset from top of table: %08x\n",
194 printf( " Preload page count: %08x\n",
196 printf( " Non-resident names table offset: %08x\n",
198 printf( " Non-resident names table length: %d\n",
200 printf( " Non-resident names table checksum: %08x\n",
202 printf( " Automatic data object: %08x\n",
204 printf( " Debug information offset: %08x\n",
206 printf( " Debug information length: %d\n",
208 printf( " Preload instance pages number: %d\n",
209 le
->e32_instpreload
);
210 printf( " Demand instance pages number: %d\n",
212 printf( " Extra heap allocation: %d\n",
214 printf( " VxD resource table offset: %08x\n",
216 printf( " Size of VxD resource table: %d\n",
218 printf( " VxD identifier: %x\n",
220 printf( " VxD DDK version: %x\n",
224 static void dump_le_objects( const IMAGE_VXD_HEADER
*le
)
226 const struct o32_obj
*pobj
;
229 printf("\nObject table:\n");
230 pobj
= (const struct o32_obj
*)((const unsigned char *)le
+ le
->e32_objtab
);
231 for (i
= 0; i
< le
->e32_objcnt
; i
++)
234 const struct o32_map
*pmap
=0;
236 printf(" Obj. Rel.Base Codesize Flags Tableidx Tablesize Name\n");
237 printf(" %04X %08lx %08lx %08lx %08lx %08lx ", i
+ 1,
238 pobj
->o32_base
, pobj
->o32_size
, pobj
->o32_flags
,
239 pobj
->o32_pagemap
, pobj
->o32_mapsize
);
240 for (j
= 0; j
< 4; j
++)
242 if (isprint(pobj
->o32_name
[j
]))
243 printf("%c", pobj
->o32_name
[j
]);
249 if(pobj
->o32_flags
& 0x0001)
250 printf("\tReadable\n");
251 if(pobj
->o32_flags
& 0x0002)
252 printf("\tWritable\n");
253 if(pobj
->o32_flags
& 0x0004)
254 printf("\tExecutable\n");
255 if(pobj
->o32_flags
& 0x0008)
256 printf("\tResource\n");
257 if(pobj
->o32_flags
& 0x0010)
258 printf("\tDiscardable\n");
259 if(pobj
->o32_flags
& 0x0020)
260 printf("\tShared\n");
261 if(pobj
->o32_flags
& 0x0040)
262 printf("\tPreloaded\n");
263 if(pobj
->o32_flags
& 0x0080)
264 printf("\tInvalid\n");
265 if(pobj
->o32_flags
& 0x2000)
266 printf("\tUse 32\n");
268 printf(" Page tables:\n");
269 printf(" Tableidx Offset Flags\n");
270 pmap
= (const struct o32_map
*)((const unsigned char *)le
+ le
->e32_objmap
);
271 pmap
= &(pmap
[pobj
->o32_pagemap
- 1]);
272 for (j
= 0; j
< pobj
->o32_mapsize
; j
++)
274 printf(" %08lx %06x %02x\n",
275 pobj
->o32_pagemap
+ j
,
276 (pmap
->o32_pagedataoffset
<< 8) + pmap
->o32_pagesize
,
277 (int)pmap
->o32_pageflags
);
284 static void dump_le_names( const IMAGE_VXD_HEADER
*le
)
286 const unsigned char *pstr
= (const unsigned char *)le
+ le
->e32_restab
;
288 printf( "\nResident name table:\n" );
291 printf( " %4d: %*.*s\n", get_word(pstr
+ *pstr
+ 1), *pstr
, *pstr
,
293 pstr
+= *pstr
+ 1 + sizeof(WORD
);
295 if (le
->e32_cbnrestab
)
297 printf( "\nNon-resident name table:\n" );
298 pstr
= PRD(le
->e32_nrestab
, 0);
301 printf( " %4d: %*.*s\n", get_word(pstr
+ *pstr
+ 1), *pstr
, *pstr
,
303 pstr
+= *pstr
+ 1 + sizeof(WORD
);
308 static void dump_le_resources( const IMAGE_VXD_HEADER
*le
)
310 printf( "\nResources:\n" );
311 printf( " Not Implemented\n" );
314 static void dump_le_modules( const IMAGE_VXD_HEADER
*le
)
316 printf( "\nImported modulename table:\n" );
317 printf( " Not Implemented\n" );
320 static void dump_le_entries( const IMAGE_VXD_HEADER
*le
)
322 printf( "\nEntry table:\n" );
323 printf( " Not Implemented\n" );
326 static void dump_le_fixups( const IMAGE_VXD_HEADER
*le
)
328 printf( "\nFixup table:\n" );
329 printf( " Not Implemented\n" );
332 static void dump_le_VxD( const IMAGE_VXD_HEADER
*le
)
334 printf( "\nVxD descriptor:\n" );
335 printf( " Not Implemented\n" );
340 const IMAGE_DOS_HEADER
*dos
;
341 const IMAGE_VXD_HEADER
*le
;
343 dos
= PRD(0, sizeof(*dos
));
345 le
= PRD(dos
->e_lfanew
, sizeof(*le
));
347 dump_le_header( le
);
348 dump_le_objects( le
);
349 dump_le_resources( le
);
351 dump_le_entries( le
);
352 dump_le_modules( le
);
353 dump_le_fixups( le
);