d3dcompiler: D3DAssemble stub.
[wine/multimedia.git] / tools / winedump / lib.c
blobde5184ae75c6b37f4eb542e6c844bf50b796e7db
1 /*
2 * Dump a COFF library (lib) file
4 * Copyright 2006 Dmitry Timoshkov
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 <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33 #ifdef HAVE_SYS_MMAN_H
34 #include <sys/mman.h>
35 #endif
36 #include <fcntl.h>
38 #define NONAMELESSUNION
39 #define NONAMELESSSTRUCT
40 #include "windef.h"
41 #include "winbase.h"
42 #include "winnt.h"
44 #include "winedump.h"
46 static void dump_import_object(const IMPORT_OBJECT_HEADER *ioh)
48 if (ioh->Version >= 1)
50 #if 0 /* FIXME: supposed to handle uuid.lib but it doesn't */
51 const ANON_OBJECT_HEADER *aoh = (const ANON_OBJECT_HEADER *)ioh;
53 printf("CLSID {%08x-%04x-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}",
54 aoh->ClassID.Data1, aoh->ClassID.Data2, aoh->ClassID.Data3,
55 aoh->ClassID.Data4[0], aoh->ClassID.Data4[1], aoh->ClassID.Data4[2], aoh->ClassID.Data4[3],
56 aoh->ClassID.Data4[4], aoh->ClassID.Data4[5], aoh->ClassID.Data4[6], aoh->ClassID.Data4[7]);
57 #endif
59 else
61 static const char * const obj_type[] = { "code", "data", "const" };
62 static const char * const name_type[] = { "ordinal", "name", "no prefix", "undecorate" };
63 const char *name;
65 printf(" Version : %X\n", ioh->Version);
66 printf(" Machine : %X (%s)\n", ioh->Machine, get_machine_str(ioh->Machine));
67 printf(" TimeDateStamp: %08X %s\n", ioh->TimeDateStamp, get_time_str(ioh->TimeDateStamp));
68 printf(" SizeOfData : %08X\n", ioh->SizeOfData);
69 name = (const char *)ioh + sizeof(*ioh);
70 printf(" DLL name : %s\n", name + strlen(name) + 1);
71 printf(" Symbol name : %s\n", name);
72 printf(" Type : %s\n", (ioh->Type < sizeof(obj_type)/sizeof(obj_type[0])) ? obj_type[ioh->Type] : "unknown");
73 printf(" Name type : %s\n", (ioh->NameType < sizeof(name_type)/sizeof(name_type[0])) ? name_type[ioh->NameType] : "unknown");
74 printf(" %-13s: %u\n", (ioh->NameType == IMPORT_OBJECT_ORDINAL) ? "Ordinal" : "Hint", ioh->u.Ordinal);
75 printf("\n");
79 static void dump_long_import(const void *base, const IMAGE_SECTION_HEADER *ish, unsigned num_sect)
81 unsigned i;
82 const DWORD *imp_data5 = NULL;
83 const WORD *imp_data6 = NULL;
85 if (globals.do_dumpheader)
86 printf("Section Table\n");
88 for (i = 0; i < num_sect; i++)
90 if (globals.do_dumpheader)
91 dump_section(&ish[i], NULL);
93 if (globals.do_dump_rawdata)
95 dump_data((const unsigned char *)base + ish[i].PointerToRawData, ish[i].SizeOfRawData, " " );
96 printf("\n");
99 if (!strcmp((const char *)ish[i].Name, ".idata$5"))
101 imp_data5 = (const DWORD *)((const char *)base + ish[i].PointerToRawData);
103 else if (!strcmp((const char *)ish[i].Name, ".idata$6"))
105 imp_data6 = (const WORD *)((const char *)base + ish[i].PointerToRawData);
107 else if (globals.do_debug && !strcmp((const char *)ish[i].Name, ".debug$S"))
109 const char *imp_debugS = (const char *)base + ish[i].PointerToRawData;
111 codeview_dump_symbols(imp_debugS, ish[i].SizeOfRawData);
112 printf("\n");
116 if (imp_data5)
118 WORD ordinal = 0;
119 const char *name = NULL;
121 if (imp_data5[0] & 0x80000000)
122 ordinal = (WORD)(imp_data5[0] & ~0x80000000);
124 if (imp_data6)
126 if (!ordinal) ordinal = imp_data6[0];
127 name = (const char *)(imp_data6 + 1);
129 else
131 /* FIXME: find out a name in the section's data */
134 if (ordinal)
136 printf(" Symbol name : %s\n", name ? name : "(ordinal import) /* FIXME */");
137 printf(" %-13s: %u\n", (imp_data5[0] & 0x80000000) ? "Ordinal" : "Hint", ordinal);
138 printf("\n");
143 enum FileSig get_kind_lib(void)
145 const char* arch = PRD(0, IMAGE_ARCHIVE_START_SIZE);
146 if (arch && !strncmp(arch, IMAGE_ARCHIVE_START, IMAGE_ARCHIVE_START_SIZE))
147 return SIG_COFFLIB;
148 return SIG_UNKNOWN;
151 void lib_dump(void)
153 long cur_file_pos;
154 const IMAGE_ARCHIVE_MEMBER_HEADER *iamh;
156 cur_file_pos = IMAGE_ARCHIVE_START_SIZE;
158 for (;;)
160 const IMPORT_OBJECT_HEADER *ioh;
161 long size;
163 if (!(iamh = PRD(cur_file_pos, sizeof(*iamh)))) break;
165 if (globals.do_dumpheader)
167 printf("Archive member name at %08lx\n", Offset(iamh));
169 printf("Name %.16s", iamh->Name);
170 if (!strncmp((const char *)iamh->Name, IMAGE_ARCHIVE_LINKER_MEMBER, sizeof(iamh->Name)))
172 printf(" - %s archive linker member\n",
173 cur_file_pos == IMAGE_ARCHIVE_START_SIZE ? "1st" : "2nd");
175 else
176 printf("\n");
177 printf("Date %.12s %s\n", iamh->Date, get_time_str(strtoul((const char *)iamh->Date, NULL, 10)));
178 printf("UserID %.6s\n", iamh->UserID);
179 printf("GroupID %.6s\n", iamh->GroupID);
180 printf("Mode %.8s\n", iamh->Mode);
181 printf("Size %.10s\n\n", iamh->Size);
184 cur_file_pos += sizeof(IMAGE_ARCHIVE_MEMBER_HEADER);
186 size = strtoul((const char *)iamh->Size, NULL, 10);
187 size = (size + 1) & ~1; /* align to an even address */
189 /* FIXME: only import library contents with the short format are
190 * recognized.
192 if (!(ioh = PRD(cur_file_pos, sizeof(*ioh)))) break;
193 if (ioh->Sig1 == IMAGE_FILE_MACHINE_UNKNOWN && ioh->Sig2 == IMPORT_OBJECT_HDR_SIG2)
195 dump_import_object(ioh);
197 else if (strncmp((const char *)iamh->Name, IMAGE_ARCHIVE_LINKER_MEMBER, sizeof(iamh->Name)))
199 long expected_size;
200 const IMAGE_FILE_HEADER *fh = (const IMAGE_FILE_HEADER *)ioh;
202 if (globals.do_dumpheader)
204 dump_file_header(fh);
205 if (fh->SizeOfOptionalHeader)
207 const IMAGE_OPTIONAL_HEADER32 *oh = (const IMAGE_OPTIONAL_HEADER32 *)((const char *)fh + sizeof(*fh));
208 dump_optional_header(oh, fh->SizeOfOptionalHeader);
211 /* Sanity check */
212 expected_size = sizeof(*fh) + fh->SizeOfOptionalHeader + fh->NumberOfSections * sizeof(IMAGE_SECTION_HEADER);
213 if (size > expected_size)
214 dump_long_import(fh, (const IMAGE_SECTION_HEADER *)((const char *)fh + sizeof(*fh) + fh->SizeOfOptionalHeader), fh->NumberOfSections);
217 cur_file_pos += size;