[runtime] Add locking to mono_gc_compute_gc_descriptor (). (#4084)
[mono.git] / mono / io-layer / versioninfo.h
1 /*
2  * versioninfo.h:  Version info structures found in PE file resources
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002 Ximian, Inc.
8  */
9
10 #ifndef _WAPI_VERSIONINFO_H_
11 #define _WAPI_VERSIONINFO_H_
12
13 #include <glib.h>
14
15 /*
16  * VS_VERSIONINFO:
17  *
18  * 2 bytes: Length in bytes (this block, and all child blocks. does _not_ include alignment padding between blocks)
19  * 2 bytes: Length in bytes of VS_FIXEDFILEINFO struct
20  * 2 bytes: Type (contains 1 if version resource contains text data and 0 if version resource contains binary data)
21  * Variable length unicode string (null terminated): Key (currently "VS_VERSION_INFO")
22  * Variable length padding to align VS_FIXEDFILEINFO on a 32-bit boundary
23  * VS_FIXEDFILEINFO struct
24  * Variable length padding to align Child struct on a 32-bit boundary
25  * Child struct (zero or one StringFileInfo structs, zero or one VarFileInfo structs)
26  */
27
28 /*
29  * StringFileInfo:
30  *
31  * 2 bytes: Length in bytes (includes this block, as well as all Child blocks)
32  * 2 bytes: Value length (always zero)
33  * 2 bytes: Type (contains 1 if version resource contains text data and 0 if version resource contains binary data)
34  * Variable length unicode string: Key (currently "StringFileInfo")
35  * Variable length padding to align Child struct on a 32-bit boundary
36  * Child structs ( one or more StringTable structs.  Each StringTable struct's Key member indicates the appropriate language and code page for displaying the text in that StringTable struct.)
37  */
38
39 /*
40  * StringTable:
41  *
42  * 2 bytes: Length in bytes (includes this block as well as all Child blocks, but excludes any padding between String blocks)
43  * 2 bytes: Value length (always zero)
44  * 2 bytes: Type (contains 1 if version resource contains text data and 0 if version resource contains binary data)
45  * Variable length unicode string: Key. An 8-digit hex number stored as a unicode string.  The four most significant digits represent the language identifier.  The four least significant digits represent the code page for which the data is formatted.
46  * Variable length padding to align Child struct on a 32-bit boundary
47  * Child structs (an array of one or more String structs (each aligned on a 32-bit boundary)
48  */
49
50 /*
51  * String:
52  *
53  * 2 bytes: Length in bytes (of this block)
54  * 2 bytes: Value length (the length in words of the Value member)
55  * 2 bytes: Type (contains 1 if version resource contains text data and 0 if version resource contains binary data)
56  * Variable length unicode string: Key. arbitrary string, identifies data.
57  * Variable length padding to align Value on a 32-bit boundary
58  * Value: Variable length unicode string, holding data.
59  */
60
61 /*
62  * VarFileInfo:
63  *
64  * 2 bytes: Length in bytes (includes this block, as well as all Child blocks)
65  * 2 bytes: Value length (always zero)
66  * 2 bytes: Type (contains 1 if version resource contains text data and 0 if version resource contains binary data)
67  * Variable length unicode string: Key (currently "VarFileInfo")
68  * Variable length padding to align Child struct on a 32-bit boundary
69  * Child structs (a Var struct)
70  */
71
72 /*
73  * Var:
74  *
75  * 2 bytes: Length in bytes of this block
76  * 2 bytes: Value length in bytes of the Value
77  * 2 bytes: Type (contains 1 if version resource contains text data and 0 if version resource contains binary data)
78  * Variable length unicode string: Key ("Translation")
79  * Variable length padding to align Value on a 32-bit boundary
80  * Value: an array of one or more 4 byte values that are language and code page identifier pairs, low-order word containing a language identifier, and the high-order word containing a code page number.  Either word can be zero, indicating that the file is language or code page independent.
81  */
82
83 typedef struct
84 {
85         guint32 dwSignature;            /* Should contain 0xFEEF04BD
86                                          * on le machines */
87         guint32 dwStrucVersion;
88         guint32 dwFileVersionMS;
89         guint32 dwFileVersionLS;
90         guint32 dwProductVersionMS;
91         guint32 dwProductVersionLS;
92         guint32 dwFileFlagsMask;
93         guint32 dwFileFlags;
94         guint32 dwFileOS;
95         guint32 dwFileType;
96         guint32 dwFileSubtype;
97         guint32 dwFileDateMS;
98         guint32 dwFileDateLS;
99 } WapiFixedFileInfo;
100
101 #if G_BYTE_ORDER == G_BIG_ENDIAN
102 #define VS_FFI_SIGNATURE        0xbd04effe
103 #define VS_FFI_STRUCVERSION     0x00000100
104 #else
105 #define VS_FFI_SIGNATURE        0xfeef04bd
106 #define VS_FFI_STRUCVERSION     0x00010000
107 #endif
108
109 #define VS_FFI_FILEFLAGSMASK    0x3f
110
111 typedef struct
112 {
113         gpointer lpBaseOfDll;
114         guint32 SizeOfImage;
115         gpointer EntryPoint;
116 } WapiModuleInfo;
117
118 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
119
120 #define IMAGE_DIRECTORY_ENTRY_EXPORT    0
121 #define IMAGE_DIRECTORY_ENTRY_IMPORT    1
122 #define IMAGE_DIRECTORY_ENTRY_RESOURCE  2
123 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
124 #define IMAGE_DIRECTORY_ENTRY_SECURITY  4
125 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5
126 #define IMAGE_DIRECTORY_ENTRY_DEBUG     6
127 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
128 #define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE      7
129 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8
130 #define IMAGE_DIRECTORY_ENTRY_TLS       9
131 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG       10
132 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT      11
133 #define IMAGE_DIRECTORY_ENTRY_IAT       12
134 #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT      13
135 #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR    14
136
137 #define IMAGE_SIZEOF_SHORT_NAME 8
138
139 #define IMAGE_RESOURCE_NAME_IS_STRING           0x80000000
140 #define IMAGE_RESOURCE_DATA_IS_DIRECTORY        0x80000000
141
142 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
143 #define IMAGE_DOS_SIGNATURE     0x4d5a
144 #define IMAGE_NT_SIGNATURE      0x50450000
145 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC   0xb10
146 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC   0xb20
147 #else
148 #define IMAGE_DOS_SIGNATURE     0x5a4d
149 #define IMAGE_NT_SIGNATURE      0x00004550
150 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC   0x10b
151 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC   0x20b
152 #endif
153
154 typedef struct
155 {
156         guint16 e_magic;
157         guint16 e_cblp;
158         guint16 e_cp;
159         guint16 e_crlc;
160         guint16 e_cparhdr;
161         guint16 e_minalloc;
162         guint16 e_maxalloc;
163         guint16 e_ss;
164         guint16 e_sp;
165         guint16 e_csum;
166         guint16 e_ip;
167         guint16 e_cs;
168         guint16 e_lfarlc;
169         guint16 e_ovno;
170         guint16 e_res[4];
171         guint16 e_oemid;
172         guint16 e_oeminfo;
173         guint16 e_res2[10];
174         guint32 e_lfanew;
175 } WapiImageDosHeader;
176
177 typedef struct
178 {
179         guint16 Machine;
180         guint16 NumberOfSections;
181         guint32 TimeDateStamp;
182         guint32 PointerToSymbolTable;
183         guint32 NumberOfSymbols;
184         guint16 SizeOfOptionalHeader;
185         guint16 Characteristics;
186 } WapiImageFileHeader;
187
188 typedef struct
189 {
190         guint32 VirtualAddress;
191         guint32 Size;
192 } WapiImageDataDirectory;
193
194 typedef struct
195 {
196         guint16 Magic;
197         guint8 MajorLinkerVersion;
198         guint8 MinorLinkerVersion;
199         guint32 SizeOfCode;
200         guint32 SizeOfInitializedData;
201         guint32 SizeOfUninitializedData;
202         guint32 AddressOfEntryPoint;
203         guint32 BaseOfCode;
204         guint32 BaseOfData;
205         guint32 ImageBase;
206         guint32 SectionAlignment;
207         guint32 FileAlignment;
208         guint16 MajorOperatingSystemVersion;
209         guint16 MinorOperatingSystemVersion;
210         guint16 MajorImageVersion;
211         guint16 MinorImageVersion;
212         guint16 MajorSubsystemVersion;
213         guint16 MinorSubsystemVersion;
214         guint32 Win32VersionValue;
215         guint32 SizeOfImage;
216         guint32 SizeOfHeaders;
217         guint32 CheckSum;
218         guint16 Subsystem;
219         guint16 DllCharacteristics;
220         guint32 SizeOfStackReserve;
221         guint32 SizeOfStackCommit;
222         guint32 SizeOfHeapReserve;
223         guint32 SizeOfHeapCommit;
224         guint32 LoaderFlags;
225         guint32 NumberOfRvaAndSizes;
226         WapiImageDataDirectory DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
227 } WapiImageOptionalHeader32;
228
229 typedef struct
230 {
231         guint16 Magic;
232         guint8 MajorLinkerVersion;
233         guint8 MinorLinkerVersion;
234         guint32 SizeOfCode;
235         guint32 SizeOfInitializedData;
236         guint32 SizeOfUninitializedData;
237         guint32 AddressOfEntryPoint;
238         guint32 BaseOfCode;
239         guint64 ImageBase;
240         guint32 SectionAlignment;
241         guint32 FileAlignment;
242         guint16 MajorOperatingSystemVersion;
243         guint16 MinorOperatingSystemVersion;
244         guint16 MajorImageVersion;
245         guint16 MinorImageVersion;
246         guint16 MajorSubsystemVersion;
247         guint16 MinorSubsystemVersion;
248         guint32 Win32VersionValue;
249         guint32 SizeOfImage;
250         guint32 SizeOfHeaders;
251         guint32 CheckSum;
252         guint16 Subsystem;
253         guint16 DllCharacteristics;
254         guint64 SizeOfStackReserve;
255         guint64 SizeOfStackCommit;
256         guint64 SizeOfHeapReserve;
257         guint64 SizeOfHeapCommit;
258         guint32 LoaderFlags;
259         guint32 NumberOfRvaAndSizes;
260         WapiImageDataDirectory DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
261 } WapiImageOptionalHeader64;
262
263 #if SIZEOF_VOID_P == 8
264 typedef WapiImageOptionalHeader64       WapiImageOptionalHeader;
265 #else
266 typedef WapiImageOptionalHeader32       WapiImageOptionalHeader;
267 #endif
268
269 typedef struct
270 {
271         guint32 Signature;
272         WapiImageFileHeader FileHeader;
273         WapiImageOptionalHeader32 OptionalHeader;
274 } WapiImageNTHeaders32;
275
276 typedef struct
277 {
278         guint32 Signature;
279         WapiImageFileHeader FileHeader;
280         WapiImageOptionalHeader64 OptionalHeader;
281 } WapiImageNTHeaders64;
282
283 #if SIZEOF_VOID_P == 8
284 typedef WapiImageNTHeaders64    WapiImageNTHeaders;
285 #else
286 typedef WapiImageNTHeaders32    WapiImageNTHeaders;
287 #endif
288
289 typedef struct
290 {
291         guint8 Name[IMAGE_SIZEOF_SHORT_NAME];
292         union
293         {
294                 guint32 PhysicalAddress;
295                 guint32 VirtualSize;
296         } Misc;
297         guint32 VirtualAddress;
298         guint32 SizeOfRawData;
299         guint32 PointerToRawData;
300         guint32 PointerToRelocations;
301         guint32 PointerToLinenumbers;
302         guint16 NumberOfRelocations;
303         guint16 NumberOfLinenumbers;
304         guint32 Characteristics;
305 } WapiImageSectionHeader;
306
307 #define IMAGE_FIRST_SECTION(header) ((WapiImageSectionHeader *)((gsize)(header) + G_STRUCT_OFFSET (WapiImageNTHeaders, OptionalHeader) + GUINT16_FROM_LE (((WapiImageNTHeaders *)(header))->FileHeader.SizeOfOptionalHeader)))
308
309 #define _WAPI_IMAGE_FIRST_SECTION32(header) ((WapiImageSectionHeader *)((gsize)(header) + G_STRUCT_OFFSET (WapiImageNTHeaders32, OptionalHeader) + GUINT16_FROM_LE (((WapiImageNTHeaders32 *)(header))->FileHeader.SizeOfOptionalHeader)))
310
311 #define RT_CURSOR       0x01
312 #define RT_BITMAP       0x02
313 #define RT_ICON         0x03
314 #define RT_MENU         0x04
315 #define RT_DIALOG       0x05
316 #define RT_STRING       0x06
317 #define RT_FONTDIR      0x07
318 #define RT_FONT         0x08
319 #define RT_ACCELERATOR  0x09
320 #define RT_RCDATA       0x0a
321 #define RT_MESSAGETABLE 0x0b
322 #define RT_GROUP_CURSOR 0x0c
323 #define RT_GROUP_ICON   0x0e
324 #define RT_VERSION      0x10
325 #define RT_DLGINCLUDE   0x11
326 #define RT_PLUGPLAY     0x13
327 #define RT_VXD          0x14
328 #define RT_ANICURSOR    0x15
329 #define RT_ANIICON      0x16
330 #define RT_HTML         0x17
331 #define RT_MANIFEST     0x18
332
333 typedef struct
334 {
335         guint32 Characteristics;
336         guint32 TimeDateStamp;
337         guint16 MajorVersion;
338         guint16 MinorVersion;
339         guint16 NumberOfNamedEntries;
340         guint16 NumberOfIdEntries;
341 } WapiImageResourceDirectory;
342
343 typedef struct
344 {
345         union 
346         {
347                 struct 
348                 {
349 #if G_BYTE_ORDER == G_BIG_ENDIAN
350                         guint32 NameIsString:1;
351                         guint32 NameOffset:31;
352 #else
353                         guint32 NameOffset:31;
354                         guint32 NameIsString:1;
355 #endif
356                 };
357                 guint32 Name;
358 #if G_BYTE_ORDER == G_BIG_ENDIAN
359                 struct
360                 {
361                         guint16 __wapi_big_endian_padding;
362                         guint16 Id;
363                 };
364 #else
365                 guint16 Id;
366 #endif
367         };
368         union
369         {
370                 guint32 OffsetToData;
371                 struct 
372                 {
373 #if G_BYTE_ORDER == G_BIG_ENDIAN
374                         guint32 DataIsDirectory:1;
375                         guint32 OffsetToDirectory:31;
376 #else
377                         guint32 OffsetToDirectory:31;
378                         guint32 DataIsDirectory:1;
379 #endif
380                 };
381         };
382 } WapiImageResourceDirectoryEntry;
383
384 typedef struct 
385 {
386         guint32 OffsetToData;
387         guint32 Size;
388         guint32 CodePage;
389         guint32 Reserved;
390 } WapiImageResourceDataEntry;
391
392 #define VS_FF_DEBUG             0x0001
393 #define VS_FF_PRERELEASE        0x0002
394 #define VS_FF_PATCHED           0x0004
395 #define VS_FF_PRIVATEBUILD      0x0008
396 #define VS_FF_INFOINFERRED      0x0010
397 #define VS_FF_SPECIALBUILD      0x0020
398
399 #define VOS_UNKNOWN             0x00000000
400 #define VOS_DOS                 0x00010000
401 #define VOS_OS216               0x00020000
402 #define VOS_OS232               0x00030000
403 #define VOS_NT                  0x00040000
404 #define VOS__BASE               0x00000000
405 #define VOS__WINDOWS16          0x00000001
406 #define VOS__PM16               0x00000002
407 #define VOS__PM32               0x00000003
408 #define VOS__WINDOWS32          0x00000004
409 /* Should "embrace and extend" here with some entries for linux etc */
410
411 #define VOS_DOS_WINDOWS16       0x00010001
412 #define VOS_DOS_WINDOWS32       0x00010004
413 #define VOS_OS216_PM16          0x00020002
414 #define VOS_OS232_PM32          0x00030003
415 #define VOS_NT_WINDOWS32        0x00040004
416
417 #define VFT_UNKNOWN             0x0000
418 #define VFT_APP                 0x0001
419 #define VFT_DLL                 0x0002
420 #define VFT_DRV                 0x0003
421 #define VFT_FONT                0x0004
422 #define VFT_VXD                 0x0005
423 #define VFT_STATIC_LIB          0x0007
424
425 #define VFT2_UNKNOWN            0x0000
426 #define VFT2_DRV_PRINTER        0x0001
427 #define VFT2_DRV_KEYBOARD       0x0002
428 #define VFT2_DRV_LANGUAGE       0x0003
429 #define VFT2_DRV_DISPLAY        0x0004
430 #define VFT2_DRV_MOUSE          0x0005
431 #define VFT2_DRV_NETWORK        0x0006
432 #define VFT2_DRV_SYSTEM         0x0007
433 #define VFT2_DRV_INSTALLABLE    0x0008
434 #define VFT2_DRV_SOUND          0x0009
435 #define VFT2_DRV_COMM           0x000a
436 #define VFT2_DRV_INPUTMETHOD    0x000b
437 #define VFT2_FONT_RASTER        0x0001
438 #define VFT2_FONT_VECTOR        0x0002
439 #define VFT2_FONT_TRUETYPE      0x0003
440
441 #define MAKELANGID(primary,secondary) ((guint16)((secondary << 10) | (primary)))
442
443 extern guint32 GetFileVersionInfoSize (gunichar2 *filename, guint32 *handle);
444 extern gboolean GetFileVersionInfo (gunichar2 *filename, guint32 handle,
445                                     guint32 len, gpointer data);
446 extern gboolean VerQueryValue (gconstpointer datablock,
447                                const gunichar2 *subblock, gpointer *buffer,
448                                guint32 *len);
449 extern guint32 VerLanguageName (guint32 lang, gunichar2 *lang_out,
450                                 guint32 lang_len);
451
452 #endif /* _WAPI_VERSIONINFO_H_ */