ole32/tests: Use proper helpers for iface calls.
[wine/multimedia.git] / tools / winedump / le.c
blobee043f2a3e4de116631a21e37902c27597171dc7
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <fcntl.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #ifdef HAVE_UNISTD_H
28 #include <unistd.h>
29 #endif
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winedump.h"
35 struct o32_obj
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;
42 char o32_name[4];
45 struct o32_map
47 unsigned short o32_pagedataoffset;
48 unsigned char o32_pagesize;
49 unsigned char o32_pageflags;
52 struct b32_bundle
54 unsigned char b32_cnt;
55 unsigned char b32_type;
58 struct vxd_descriptor
60 unsigned long next;
61 unsigned short sdk_version;
62 unsigned short device_number;
63 unsigned char version_major;
64 unsigned char version_minor;
65 unsigned short flags;
66 char name[8];
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;
77 unsigned long prev;
78 unsigned long size;
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",
99 le->e32_level);
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" :
110 "Unknown");
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" :
116 "Unknown");
117 printf( " Module version: %d\n",
118 le->e32_ver);
119 printf( " Module type flags: %08x\n",
120 le->e32_mflags);
121 if (le->e32_mflags & 0x8000)
123 if (le->e32_mflags & 0x0004)
124 printf( " Global initialization\n");
125 else
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",
143 le->e32_mpages);
144 printf( " Initial object CS number: %08x\n",
145 le->e32_startobj);
146 printf( " Initial EIP: %08x\n",
147 le->e32_eip);
148 printf( " Initial object SS number: %08x\n",
149 le->e32_stackobj);
150 printf( " Initial ESP: %08x\n",
151 le->e32_esp);
152 printf( " Memory page size: %d\n",
153 le->e32_pagesize);
154 printf( " Bytes on last page: %d\n",
155 le->e32_lastpagesize);
156 printf( " Fix-up section size: %d\n",
157 le->e32_fixupsize);
158 printf( " Fix-up section checksum: %08x\n",
159 le->e32_fixupsum);
160 printf( " Loader section size: %d\n",
161 le->e32_ldrsize);
162 printf( " Loader section checksum: %08x\n",
163 le->e32_ldrsum);
164 printf( " Offset of object table: %08x\n",
165 le->e32_objtab);
166 printf( " Object table entries: %d\n",
167 le->e32_objcnt);
168 printf( " Object page map offset: %08x\n",
169 le->e32_objmap);
170 printf( " Object iterate data map offset: %08x\n",
171 le->e32_itermap);
172 printf( " Resource table offset: %08x\n",
173 le->e32_rsrctab);
174 printf( " Resource table entries: %d\n",
175 le->e32_rsrccnt);
176 printf( " Resident names table offset: %08x\n",
177 le->e32_restab);
178 printf( " Entry table offset: %08x\n",
179 le->e32_enttab);
180 printf( " Module directives table offset: %08x\n",
181 le->e32_dirtab);
182 printf( " Module directives entries: %d\n",
183 le->e32_dircnt);
184 printf( " Fix-up page table offset: %08x\n",
185 le->e32_fpagetab);
186 printf( " Fix-up record table offset: %08x\n",
187 le->e32_frectab);
188 printf( " Imported modules name table offset: %08x\n",
189 le->e32_impmod);
190 printf( " Imported modules count: %d\n",
191 le->e32_impmodcnt);
192 printf( " Imported procedure name table offset: %08x\n",
193 le->e32_impproc);
194 printf( " Per-page checksum table offset: %08x\n",
195 le->e32_pagesum);
196 printf( " Data pages offset from top of table: %08x\n",
197 le->e32_datapage);
198 printf( " Preload page count: %08x\n",
199 le->e32_preload);
200 printf( " Non-resident names table offset: %08x\n",
201 le->e32_nrestab);
202 printf( " Non-resident names table length: %d\n",
203 le->e32_cbnrestab);
204 printf( " Non-resident names table checksum: %08x\n",
205 le->e32_nressum);
206 printf( " Automatic data object: %08x\n",
207 le->e32_autodata);
208 printf( " Debug information offset: %08x\n",
209 le->e32_debuginfo);
210 printf( " Debug information length: %d\n",
211 le->e32_debuglen);
212 printf( " Preload instance pages number: %d\n",
213 le->e32_instpreload);
214 printf( " Demand instance pages number: %d\n",
215 le->e32_instdemand);
216 printf( " Extra heap allocation: %d\n",
217 le->e32_heapsize);
218 printf( " VxD resource table offset: %08x\n",
219 le->e32_winresoff);
220 printf( " Size of VxD resource table: %d\n",
221 le->e32_winreslen);
222 printf( " VxD identifier: %x\n",
223 le->e32_devid);
224 printf( " VxD DDK version: %x\n",
225 le->e32_ddkver);
228 static void dump_le_objects( const IMAGE_VXD_HEADER *le )
230 const struct o32_obj *pobj;
231 unsigned int i;
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++)
237 unsigned int j;
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]);
248 else
249 printf(".");
251 printf("\n");
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);
282 pmap++;
284 pobj++;
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" );
293 while (*pstr)
295 printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr,
296 pstr + 1 );
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);
303 while (*pstr)
305 printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr,
306 pstr + 1 );
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" );
342 void le_dump( void )
344 const IMAGE_DOS_HEADER *dos;
345 const IMAGE_VXD_HEADER *le;
347 dos = PRD(0, sizeof(*dos));
348 if (!dos) return;
349 le = PRD(dos->e_lfanew, sizeof(*le));
351 dump_le_header( le );
352 dump_le_objects( le );
353 dump_le_resources( le );
354 dump_le_names( le );
355 dump_le_entries( le );
356 dump_le_modules( le );
357 dump_le_fixups( le );
358 dump_le_VxD( le );