winedump: Fix some incorrect uses of Unix 'long' type.
[wine.git] / tools / winedump / le.c
blob341d9540edcb35d710b077a6e25c036f17bb7ddb
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"
23 #include <fcntl.h>
24 #include <stdarg.h>
25 #include <stdio.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winedump.h"
31 struct o32_obj
33 unsigned int o32_size;
34 unsigned int o32_base;
35 unsigned int o32_flags;
36 unsigned int o32_pagemap;
37 unsigned int o32_mapsize;
38 char o32_name[4];
41 struct o32_map
43 unsigned short o32_pagedataoffset;
44 unsigned char o32_pagesize;
45 unsigned char o32_pageflags;
48 struct b32_bundle
50 unsigned char b32_cnt;
51 unsigned char b32_type;
54 struct vxd_descriptor
56 unsigned int next;
57 unsigned short sdk_version;
58 unsigned short device_number;
59 unsigned char version_major;
60 unsigned char version_minor;
61 unsigned short flags;
62 char name[8];
63 unsigned int init_order;
64 unsigned int ctrl_ofs;
65 unsigned int v86_ctrl_ofs;
66 unsigned int pm_ctrl_ofs;
67 unsigned int v86_ctrl_csip;
68 unsigned int pm_ctrl_csip;
69 unsigned int rm_ref_data;
70 unsigned int service_table_ofs;
71 unsigned int service_table_size;
72 unsigned int win32_service_table_ofs;
73 unsigned int prev;
74 unsigned int size;
75 unsigned int reserved0;
76 unsigned int reserved1;
77 unsigned int 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",
95 le->e32_level);
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" :
106 "Unknown");
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" :
112 "Unknown");
113 printf( " Module version: %d\n",
114 le->e32_ver);
115 printf( " Module type flags: %08x\n",
116 le->e32_mflags);
117 if (le->e32_mflags & 0x8000)
119 if (le->e32_mflags & 0x0004)
120 printf( " Global initialization\n");
121 else
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",
139 le->e32_mpages);
140 printf( " Initial object CS number: %08x\n",
141 le->e32_startobj);
142 printf( " Initial EIP: %08x\n",
143 le->e32_eip);
144 printf( " Initial object SS number: %08x\n",
145 le->e32_stackobj);
146 printf( " Initial ESP: %08x\n",
147 le->e32_esp);
148 printf( " Memory page size: %d\n",
149 le->e32_pagesize);
150 printf( " Bytes on last page: %d\n",
151 le->e32_lastpagesize);
152 printf( " Fix-up section size: %d\n",
153 le->e32_fixupsize);
154 printf( " Fix-up section checksum: %08x\n",
155 le->e32_fixupsum);
156 printf( " Loader section size: %d\n",
157 le->e32_ldrsize);
158 printf( " Loader section checksum: %08x\n",
159 le->e32_ldrsum);
160 printf( " Offset of object table: %08x\n",
161 le->e32_objtab);
162 printf( " Object table entries: %d\n",
163 le->e32_objcnt);
164 printf( " Object page map offset: %08x\n",
165 le->e32_objmap);
166 printf( " Object iterate data map offset: %08x\n",
167 le->e32_itermap);
168 printf( " Resource table offset: %08x\n",
169 le->e32_rsrctab);
170 printf( " Resource table entries: %d\n",
171 le->e32_rsrccnt);
172 printf( " Resident names table offset: %08x\n",
173 le->e32_restab);
174 printf( " Entry table offset: %08x\n",
175 le->e32_enttab);
176 printf( " Module directives table offset: %08x\n",
177 le->e32_dirtab);
178 printf( " Module directives entries: %d\n",
179 le->e32_dircnt);
180 printf( " Fix-up page table offset: %08x\n",
181 le->e32_fpagetab);
182 printf( " Fix-up record table offset: %08x\n",
183 le->e32_frectab);
184 printf( " Imported modules name table offset: %08x\n",
185 le->e32_impmod);
186 printf( " Imported modules count: %d\n",
187 le->e32_impmodcnt);
188 printf( " Imported procedure name table offset: %08x\n",
189 le->e32_impproc);
190 printf( " Per-page checksum table offset: %08x\n",
191 le->e32_pagesum);
192 printf( " Data pages offset from top of table: %08x\n",
193 le->e32_datapage);
194 printf( " Preload page count: %08x\n",
195 le->e32_preload);
196 printf( " Non-resident names table offset: %08x\n",
197 le->e32_nrestab);
198 printf( " Non-resident names table length: %d\n",
199 le->e32_cbnrestab);
200 printf( " Non-resident names table checksum: %08x\n",
201 le->e32_nressum);
202 printf( " Automatic data object: %08x\n",
203 le->e32_autodata);
204 printf( " Debug information offset: %08x\n",
205 le->e32_debuginfo);
206 printf( " Debug information length: %d\n",
207 le->e32_debuglen);
208 printf( " Preload instance pages number: %d\n",
209 le->e32_instpreload);
210 printf( " Demand instance pages number: %d\n",
211 le->e32_instdemand);
212 printf( " Extra heap allocation: %d\n",
213 le->e32_heapsize);
214 printf( " VxD resource table offset: %08x\n",
215 le->e32_winresoff);
216 printf( " Size of VxD resource table: %d\n",
217 le->e32_winreslen);
218 printf( " VxD identifier: %x\n",
219 le->e32_devid);
220 printf( " VxD DDK version: %x\n",
221 le->e32_ddkver);
224 static void dump_le_objects( const IMAGE_VXD_HEADER *le )
226 const struct o32_obj *pobj;
227 unsigned int i;
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++)
233 unsigned int j;
234 const struct o32_map *pmap=0;
236 printf(" Obj. Rel.Base Codesize Flags Tableidx Tablesize Name\n");
237 printf(" %04X %08x %08x %08x %08x %08x ", 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]);
244 else
245 printf(".");
247 printf("\n");
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(" %08x %06x %02x\n",
275 pobj->o32_pagemap + j,
276 (pmap->o32_pagedataoffset << 8) + pmap->o32_pagesize,
277 (int)pmap->o32_pageflags);
278 pmap++;
280 pobj++;
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" );
289 while (*pstr)
291 printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr,
292 pstr + 1 );
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);
299 while (*pstr)
301 printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr,
302 pstr + 1 );
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" );
338 void le_dump( void )
340 const IMAGE_DOS_HEADER *dos;
341 const IMAGE_VXD_HEADER *le;
343 dos = PRD(0, sizeof(*dos));
344 if (!dos) return;
345 le = PRD(dos->e_lfanew, sizeof(*le));
347 dump_le_header( le );
348 dump_le_objects( le );
349 dump_le_resources( le );
350 dump_le_names( le );
351 dump_le_entries( le );
352 dump_le_modules( le );
353 dump_le_fixups( le );
354 dump_le_VxD( le );