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
22 #include "wine/port.h"
33 #include "wine/winbase16.h"
38 unsigned long o32_size;
39 unsigned long o32_base;
40 unsigned long o32_flags;
41 unsigned long o32_pagemap;
42 unsigned long o32_mapsize;
48 unsigned short o32_pagedataoffset;
49 unsigned char o32_pagesize;
50 unsigned char o32_pageflags;
55 unsigned char b32_cnt;
56 unsigned char b32_type;
62 unsigned short sdk_version;
63 unsigned short device_number;
64 unsigned char version_major;
65 unsigned char version_minor;
68 unsigned long init_order;
69 unsigned long ctrl_ofs;
70 unsigned long v86_ctrl_ofs;
71 unsigned long pm_ctrl_ofs;
72 unsigned long v86_ctrl_csip;
73 unsigned long pm_ctrl_csip;
74 unsigned long rm_ref_data;
75 unsigned long service_table_ofs;
76 unsigned long service_table_size;
77 unsigned long win32_service_table_ofs;
80 unsigned long reserved0;
81 unsigned long reserved1;
82 unsigned long reserved2;
85 static inline WORD get_word( const BYTE *ptr )
87 return ptr[0] | (ptr[1] << 8);
90 static void dump_le_header( const IMAGE_VXD_HEADER *le )
92 printf( "File header:\n" );
93 printf( " Magic: %04x (%c%c)\n",
94 le->e32_magic, LOBYTE(le->e32_magic), HIBYTE(le->e32_magic));
95 printf( " Byte order: %s\n",
96 le->e32_border == 0 ? "little-indian" : "big-endian");
97 printf( " Word order: %s\n",
98 le->e32_worder == 0 ? "little-indian" : "big-endian");
99 printf( " Executable format level: %ld\n",
101 printf( " CPU type: %s\n",
102 le->e32_cpu == 0x01 ? "Intel 80286" :
103 le->e32_cpu == 0x02 ? "Intel 80386" :
104 le->e32_cpu == 0x03 ? "Intel 80486" :
105 le->e32_cpu == 0x04 ? "Intel 80586" :
106 le->e32_cpu == 0x20 ? "Intel i860 (N10)" :
107 le->e32_cpu == 0x21 ? "Intel i860 (N11)" :
108 le->e32_cpu == 0x40 ? "MIPS Mark I" :
109 le->e32_cpu == 0x41 ? "MIPS Mark II" :
110 le->e32_cpu == 0x42 ? "MIPS Mark III" :
112 printf( " Target operating system: %s\n",
113 le->e32_os == 0x01 ? "OS/2" :
114 le->e32_os == 0x02 ? "Windows" :
115 le->e32_os == 0x03 ? "DOS 4.x" :
116 le->e32_os == 0x04 ? "Windows 386" :
118 printf( " Module version: %ld\n",
120 printf( " Module type flags: %08lx\n",
122 if (le->e32_mflags & 0x8000)
124 if (le->e32_mflags & 0x0004)
125 printf( " Global initialization\n");
127 printf( " Per-Process initialization\n");
128 if (le->e32_mflags & 0x0010)
129 printf( " No internal fixup\n");
130 if (le->e32_mflags & 0x0020)
131 printf( " No external fixup\n");
132 if ((le->e32_mflags & 0x0700) == 0x0100)
133 printf( " Incompatible with PM windowing\n");
134 else if ((le->e32_mflags & 0x0700) == 0x0200)
135 printf( " Compatible with PM windowing\n");
136 else if ((le->e32_mflags & 0x0700) == 0x0300)
137 printf( " Uses PM windowing API\n");
138 if (le->e32_mflags & 0x2000)
139 printf( " Module not loadable\n");
140 if (le->e32_mflags & 0x8000)
141 printf( " Module is DLL\n");
143 printf( " Number of memory pages: %ld\n",
145 printf( " Initial object CS number: %08lx\n",
147 printf( " Initial EIP: %08lx\n",
149 printf( " Initial object SS number: %08lx\n",
151 printf( " Initial ESP: %08lx\n",
153 printf( " Memory page size: %ld\n",
155 printf( " Bytes on last page: %ld\n",
156 le->e32_lastpagesize);
157 printf( " Fix-up section size: %ld\n",
159 printf( " Fix-up section checksum: %08lx\n",
161 printf( " Loader section size: %ld\n",
163 printf( " Loader section checksum: %08lx\n",
165 printf( " Offset of object table: %08lx\n",
167 printf( " Object table entries: %ld\n",
169 printf( " Object page map offset: %08lx\n",
171 printf( " Object iterate data map offset: %08lx\n",
173 printf( " Resource table offset: %08lx\n",
175 printf( " Resource table entries: %ld\n",
177 printf( " Resident names table offset: %08lx\n",
179 printf( " Entry table offset: %08lx\n",
181 printf( " Module directives table offset: %08lx\n",
183 printf( " Module directives entries: %ld\n",
185 printf( " Fix-up page table offset: %08lx\n",
187 printf( " Fix-up record table offset: %08lx\n",
189 printf( " Imported modules name table offset: %08lx\n",
191 printf( " Imported modules count: %ld\n",
193 printf( " Imported procedure name table offset: %08lx\n",
195 printf( " Per-page checksum table offset: %08lx\n",
197 printf( " Data pages offset from top of table: %08lx\n",
199 printf( " Preload page count: %08lx\n",
201 printf( " Non-resident names table offset: %08lx\n",
203 printf( " Non-resident names table length: %ld\n",
205 printf( " Non-resident names table checksum: %08lx\n",
207 printf( " Automatic data object: %08lx\n",
209 printf( " Debug information offset: %08lx\n",
211 printf( " Debug information length: %ld\n",
213 printf( " Preload instance pages number: %ld\n",
214 le->e32_instpreload);
215 printf( " Demand instance pages number: %ld\n",
217 printf( " Extra heap allocation: %ld\n",
219 printf( " VxD resource table offset: %08lx\n",
221 printf( " Size of VxD resource table: %ld\n",
223 printf( " VxD identifier: %x\n",
225 printf( " VxD DDK version: %x\n",
229 static void dump_le_objects( const void *base, const IMAGE_VXD_HEADER *le )
231 const struct o32_obj *pobj;
234 printf("\nObject table:\n");
235 pobj = (const struct o32_obj *)((const unsigned char *)le + le->e32_objtab);
236 for (i = 0; i < le->e32_objcnt; i++)
239 const struct o32_map *pmap=0;
241 printf(" Obj. Rel.Base Codesize Flags Tableidx Tablesize Name\n");
242 printf(" %04X %08lx %08lx %08lx %08lx %08lx ", i + 1,
243 pobj->o32_base, pobj->o32_size, pobj->o32_flags,
244 pobj->o32_pagemap, pobj->o32_mapsize);
245 for (j = 0; j < 4; j++)
247 if (isprint(pobj->o32_name[j]))
248 printf("%c", pobj->o32_name[j]);
254 if(pobj->o32_flags & 0x0001)
255 printf("\tReadable\n");
256 if(pobj->o32_flags & 0x0002)
257 printf("\tWriteable\n");
258 if(pobj->o32_flags & 0x0004)
259 printf("\tExecutable\n");
260 if(pobj->o32_flags & 0x0008)
261 printf("\tResource\n");
262 if(pobj->o32_flags & 0x0010)
263 printf("\tDiscardable\n");
264 if(pobj->o32_flags & 0x0020)
265 printf("\tShared\n");
266 if(pobj->o32_flags & 0x0040)
267 printf("\tPreloaded\n");
268 if(pobj->o32_flags & 0x0080)
269 printf("\tInvalid\n");
270 if(pobj->o32_flags & 0x2000)
271 printf("\tUse 32\n");
273 printf(" Page tables:\n");
274 printf(" Tableidx Offset Flags\n");
275 pmap = (const struct o32_map *)((const unsigned char *)le + le->e32_objmap);
276 pmap = &(pmap[pobj->o32_pagemap - 1]);
277 for (j = 0; j < pobj->o32_mapsize; j++)
279 printf(" %08lx %06x %02x\n",
280 pobj->o32_pagemap + j,
281 (pmap->o32_pagedataoffset << 8) + pmap->o32_pagesize,
282 (int)pmap->o32_pageflags);
289 static void dump_le_names( const void *base, const IMAGE_VXD_HEADER *le )
291 const unsigned char *pstr = (const unsigned char *)le + le->e32_restab;
293 printf( "\nResident name table:\n" );
296 printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr,
298 pstr += *pstr + 1 + sizeof(WORD);
300 if (le->e32_cbnrestab)
302 printf( "\nNon-resident name table:\n" );
303 pstr = (const unsigned char *)base + le->e32_nrestab;
306 printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr,
308 pstr += *pstr + 1 + sizeof(WORD);
313 static void dump_le_resources( const void *base, const IMAGE_VXD_HEADER *le )
315 printf( "\nResources:\n" );
316 printf( " Not Implemented\n" );
319 static void dump_le_modules( const void *base, const IMAGE_VXD_HEADER *le )
321 printf( "\nImported modulename table:\n" );
322 printf( " Not Implemented\n" );
325 static void dump_le_entries( const void *base, const IMAGE_VXD_HEADER *le )
327 printf( "\nEntry table:\n" );
328 printf( " Not Implemented\n" );
331 static void dump_le_fixups( const void *base, const IMAGE_VXD_HEADER *le )
333 printf( "\nFixup table:\n" );
334 printf( " Not Implemented\n" );
337 static void dump_le_VxD( const void *base, const IMAGE_VXD_HEADER *le )
339 printf( "\nVxD descriptor:\n" );
340 printf( " Not Implemented\n" );
343 void le_dump( const void *exe, size_t exe_size )
345 const IMAGE_DOS_HEADER *dos = exe;
346 const IMAGE_VXD_HEADER *le;
348 le = (const IMAGE_VXD_HEADER*)((const char *)dos + dos->e_lfanew);
350 dump_le_header( le );
351 dump_le_objects( exe, le );
352 dump_le_resources( exe, le );
353 dump_le_names( exe, le );
354 dump_le_entries( exe, le );
355 dump_le_modules( exe, le );
356 dump_le_fixups( exe, le );
357 dump_le_VxD( exe, le );