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"
37 unsigned long o32_size;
38 unsigned long o32_base;
39 unsigned long o32_flags;
40 unsigned long o32_pagemap;
41 unsigned long o32_mapsize;
47 unsigned short o32_pagedataoffset;
48 unsigned char o32_pagesize;
49 unsigned char o32_pageflags;
54 unsigned char b32_cnt;
55 unsigned char b32_type;
61 unsigned short sdk_version;
62 unsigned short device_number;
63 unsigned char version_major;
64 unsigned char version_minor;
67 unsigned long init_order;
68 unsigned long ctrl_ofs;
69 unsigned long v86_ctrl_ofs;
70 unsigned long pm_ctrl_ofs;
71 unsigned long v86_ctrl_csip;
72 unsigned long pm_ctrl_csip;
73 unsigned long rm_ref_data;
74 unsigned long service_table_ofs;
75 unsigned long service_table_size;
76 unsigned long win32_service_table_ofs;
79 unsigned long reserved0;
80 unsigned long reserved1;
81 unsigned long reserved2;
84 static inline WORD get_word( const BYTE *ptr )
86 return ptr[0] | (ptr[1] << 8);
89 static void dump_le_header( const IMAGE_VXD_HEADER *le )
91 printf( "File header:\n" );
92 printf( " Magic: %04x (%c%c)\n",
93 le->e32_magic, LOBYTE(le->e32_magic), HIBYTE(le->e32_magic));
94 printf( " Byte order: %s\n",
95 le->e32_border == 0 ? "little-indian" : "big-endian");
96 printf( " Word order: %s\n",
97 le->e32_worder == 0 ? "little-indian" : "big-endian");
98 printf( " Executable format level: %d\n",
100 printf( " CPU type: %s\n",
101 le->e32_cpu == 0x01 ? "Intel 80286" :
102 le->e32_cpu == 0x02 ? "Intel 80386" :
103 le->e32_cpu == 0x03 ? "Intel 80486" :
104 le->e32_cpu == 0x04 ? "Intel 80586" :
105 le->e32_cpu == 0x20 ? "Intel i860 (N10)" :
106 le->e32_cpu == 0x21 ? "Intel i860 (N11)" :
107 le->e32_cpu == 0x40 ? "MIPS Mark I" :
108 le->e32_cpu == 0x41 ? "MIPS Mark II" :
109 le->e32_cpu == 0x42 ? "MIPS Mark III" :
111 printf( " Target operating system: %s\n",
112 le->e32_os == 0x01 ? "OS/2" :
113 le->e32_os == 0x02 ? "Windows" :
114 le->e32_os == 0x03 ? "DOS 4.x" :
115 le->e32_os == 0x04 ? "Windows 386" :
117 printf( " Module version: %d\n",
119 printf( " Module type flags: %08x\n",
121 if (le->e32_mflags & 0x8000)
123 if (le->e32_mflags & 0x0004)
124 printf( " Global initialization\n");
126 printf( " Per-Process initialization\n");
127 if (le->e32_mflags & 0x0010)
128 printf( " No internal fixup\n");
129 if (le->e32_mflags & 0x0020)
130 printf( " No external fixup\n");
131 if ((le->e32_mflags & 0x0700) == 0x0100)
132 printf( " Incompatible with PM windowing\n");
133 else if ((le->e32_mflags & 0x0700) == 0x0200)
134 printf( " Compatible with PM windowing\n");
135 else if ((le->e32_mflags & 0x0700) == 0x0300)
136 printf( " Uses PM windowing API\n");
137 if (le->e32_mflags & 0x2000)
138 printf( " Module not loadable\n");
139 if (le->e32_mflags & 0x8000)
140 printf( " Module is DLL\n");
142 printf( " Number of memory pages: %d\n",
144 printf( " Initial object CS number: %08x\n",
146 printf( " Initial EIP: %08x\n",
148 printf( " Initial object SS number: %08x\n",
150 printf( " Initial ESP: %08x\n",
152 printf( " Memory page size: %d\n",
154 printf( " Bytes on last page: %d\n",
155 le->e32_lastpagesize);
156 printf( " Fix-up section size: %d\n",
158 printf( " Fix-up section checksum: %08x\n",
160 printf( " Loader section size: %d\n",
162 printf( " Loader section checksum: %08x\n",
164 printf( " Offset of object table: %08x\n",
166 printf( " Object table entries: %d\n",
168 printf( " Object page map offset: %08x\n",
170 printf( " Object iterate data map offset: %08x\n",
172 printf( " Resource table offset: %08x\n",
174 printf( " Resource table entries: %d\n",
176 printf( " Resident names table offset: %08x\n",
178 printf( " Entry table offset: %08x\n",
180 printf( " Module directives table offset: %08x\n",
182 printf( " Module directives entries: %d\n",
184 printf( " Fix-up page table offset: %08x\n",
186 printf( " Fix-up record table offset: %08x\n",
188 printf( " Imported modules name table offset: %08x\n",
190 printf( " Imported modules count: %d\n",
192 printf( " Imported procedure name table offset: %08x\n",
194 printf( " Per-page checksum table offset: %08x\n",
196 printf( " Data pages offset from top of table: %08x\n",
198 printf( " Preload page count: %08x\n",
200 printf( " Non-resident names table offset: %08x\n",
202 printf( " Non-resident names table length: %d\n",
204 printf( " Non-resident names table checksum: %08x\n",
206 printf( " Automatic data object: %08x\n",
208 printf( " Debug information offset: %08x\n",
210 printf( " Debug information length: %d\n",
212 printf( " Preload instance pages number: %d\n",
213 le->e32_instpreload);
214 printf( " Demand instance pages number: %d\n",
216 printf( " Extra heap allocation: %d\n",
218 printf( " VxD resource table offset: %08x\n",
220 printf( " Size of VxD resource table: %d\n",
222 printf( " VxD identifier: %x\n",
224 printf( " VxD DDK version: %x\n",
228 static void dump_le_objects( const IMAGE_VXD_HEADER *le )
230 const struct o32_obj *pobj;
233 printf("\nObject table:\n");
234 pobj = (const struct o32_obj *)((const unsigned char *)le + le->e32_objtab);
235 for (i = 0; i < le->e32_objcnt; i++)
238 const struct o32_map *pmap=0;
240 printf(" Obj. Rel.Base Codesize Flags Tableidx Tablesize Name\n");
241 printf(" %04X %08lx %08lx %08lx %08lx %08lx ", i + 1,
242 pobj->o32_base, pobj->o32_size, pobj->o32_flags,
243 pobj->o32_pagemap, pobj->o32_mapsize);
244 for (j = 0; j < 4; j++)
246 if (isprint(pobj->o32_name[j]))
247 printf("%c", pobj->o32_name[j]);
253 if(pobj->o32_flags & 0x0001)
254 printf("\tReadable\n");
255 if(pobj->o32_flags & 0x0002)
256 printf("\tWritable\n");
257 if(pobj->o32_flags & 0x0004)
258 printf("\tExecutable\n");
259 if(pobj->o32_flags & 0x0008)
260 printf("\tResource\n");
261 if(pobj->o32_flags & 0x0010)
262 printf("\tDiscardable\n");
263 if(pobj->o32_flags & 0x0020)
264 printf("\tShared\n");
265 if(pobj->o32_flags & 0x0040)
266 printf("\tPreloaded\n");
267 if(pobj->o32_flags & 0x0080)
268 printf("\tInvalid\n");
269 if(pobj->o32_flags & 0x2000)
270 printf("\tUse 32\n");
272 printf(" Page tables:\n");
273 printf(" Tableidx Offset Flags\n");
274 pmap = (const struct o32_map *)((const unsigned char *)le + le->e32_objmap);
275 pmap = &(pmap[pobj->o32_pagemap - 1]);
276 for (j = 0; j < pobj->o32_mapsize; j++)
278 printf(" %08lx %06x %02x\n",
279 pobj->o32_pagemap + j,
280 (pmap->o32_pagedataoffset << 8) + pmap->o32_pagesize,
281 (int)pmap->o32_pageflags);
288 static void dump_le_names( const IMAGE_VXD_HEADER *le )
290 const unsigned char *pstr = (const unsigned char *)le + le->e32_restab;
292 printf( "\nResident name table:\n" );
295 printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr,
297 pstr += *pstr + 1 + sizeof(WORD);
299 if (le->e32_cbnrestab)
301 printf( "\nNon-resident name table:\n" );
302 pstr = PRD(le->e32_nrestab, 0);
305 printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr,
307 pstr += *pstr + 1 + sizeof(WORD);
312 static void dump_le_resources( const IMAGE_VXD_HEADER *le )
314 printf( "\nResources:\n" );
315 printf( " Not Implemented\n" );
318 static void dump_le_modules( const IMAGE_VXD_HEADER *le )
320 printf( "\nImported modulename table:\n" );
321 printf( " Not Implemented\n" );
324 static void dump_le_entries( const IMAGE_VXD_HEADER *le )
326 printf( "\nEntry table:\n" );
327 printf( " Not Implemented\n" );
330 static void dump_le_fixups( const IMAGE_VXD_HEADER *le )
332 printf( "\nFixup table:\n" );
333 printf( " Not Implemented\n" );
336 static void dump_le_VxD( const IMAGE_VXD_HEADER *le )
338 printf( "\nVxD descriptor:\n" );
339 printf( " Not Implemented\n" );
344 const IMAGE_DOS_HEADER *dos;
345 const IMAGE_VXD_HEADER *le;
347 dos = PRD(0, sizeof(*dos));
349 le = PRD(dos->e_lfanew, sizeof(*le));
351 dump_le_header( le );
352 dump_le_objects( le );
353 dump_le_resources( le );
355 dump_le_entries( le );
356 dump_le_modules( le );
357 dump_le_fixups( le );