Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cil-coff.h « metadata « mono - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 098057f6fc36d310729c1a893764c69357b28b9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

#ifndef __MONO_CIL_COFF_H__
#define __MONO_CIL_COFF_H__

#include <mono/metadata/metadata.h>

/*
 * 25.2.1: Method header type values
 */
#define METHOD_HEADER_FORMAT_MASK   7
#define METHOD_HEADER_TINY_FORMAT   2
#define METHOD_HEADER_TINY_FORMAT1  6
#define METHOD_HEADER_FAT_FORMAT    3

/*
 * 25.2.3.1: Flags for method headers
 */
#define METHOD_HEADER_INIT_LOCALS   0x10
#define METHOD_HEADER_MORE_SECTS    0x08

/*
 * For section data (25.3)
 */
#define METHOD_HEADER_SECTION_RESERVED    0
#define METHOD_HEADER_SECTION_EHTABLE     1
#define METHOD_HEADER_SECTION_OPTIL_TABLE 2
#define METHOD_HEADER_SECTION_FAT_FORMAT  0x40
#define METHOD_HEADER_SECTION_MORE_SECTS  0x80

/* 128 bytes */
typedef struct {
	char    msdos_sig [2];
	guint16 nlast_page;
	guint16 npages;
	char    msdos_header [54];
	guint32 pe_offset;
	char    msdos_header2 [64];
} MonoMSDOSHeader;

/* 20 bytes */
typedef struct {
	guint16  coff_machine;
	guint16  coff_sections;
	guint32  coff_time;
	guint32  coff_symptr;
	guint32  coff_symcount;
	guint16  coff_opt_header_size;
	guint16  coff_attributes;
} MonoCOFFHeader;

#define COFF_ATTRIBUTE_EXECUTABLE_IMAGE 0x0002
#define COFF_ATTRIBUTE_LIBRARY_IMAGE    0x2000

/* 28 bytes */
typedef struct {
	guint16 pe_magic;
	guchar  pe_major;
	guchar  pe_minor;
	guint32 pe_code_size;
	guint32 pe_data_size;
	guint32 pe_uninit_data_size;
	guint32 pe_rva_entry_point;
	guint32 pe_rva_code_base;
	guint32 pe_rva_data_base;
} MonoPEHeader;

/* 68 bytes */
typedef struct {
	guint32 pe_image_base;		/* must be 0x400000 */
	guint32 pe_section_align;       /* must be 8192 */
	guint32 pe_file_alignment;      /* must be 512 or 4096 */
	guint16 pe_os_major;            /* must be 4 */
	guint16 pe_os_minor;            /* must be 0 */
	guint16 pe_user_major;
	guint16 pe_user_minor;
	guint16 pe_subsys_major;
	guint16 pe_subsys_minor;
	guint32 pe_reserved_1;
	guint32 pe_image_size;
	guint32 pe_header_size;
	guint32 pe_checksum;
	guint16 pe_subsys_required;
	guint16 pe_dll_flags;
	guint32 pe_stack_reserve;
	guint32 pe_stack_commit;
	guint32 pe_heap_reserve;
	guint32 pe_heap_commit;
	guint32 pe_loader_flags;
	guint32 pe_data_dir_count;
} MonoPEHeaderNT;

typedef struct {
	guint32 rde_data_offset;
	guint32 rde_size;
	guint32 rde_codepage;
	guint32 rde_reserved;
} MonoPEResourceDataEntry;

#define MONO_PE_RESOURCE_ID_CURSOR	0x01
#define MONO_PE_RESOURCE_ID_BITMAP	0x02
#define MONO_PE_RESOURCE_ID_ICON	0x03
#define MONO_PE_RESOURCE_ID_MENU	0x04
#define MONO_PE_RESOURCE_ID_DIALOG	0x05
#define MONO_PE_RESOURCE_ID_STRING	0x06
#define MONO_PE_RESOURCE_ID_FONTDIR	0x07
#define MONO_PE_RESOURCE_ID_FONT	0x08
#define MONO_PE_RESOURCE_ID_ACCEL	0x09
#define MONO_PE_RESOURCE_ID_RCDATA	0x0a
#define MONO_PE_RESOURCE_ID_MESSAGETABLE	0x0b
#define MONO_PE_RESOURCE_ID_GROUP_CURSOR	0x0c
#define MONO_PE_RESOURCE_ID_GROUP_ICON	0x0d
#define MONO_PE_RESOURCE_ID_VERSION	0x10
#define MONO_PE_RESOURCE_ID_DLGINCLUDE	0x11
#define MONO_PE_RESOURCE_ID_PLUGPLAY	0x13
#define MONO_PE_RESOURCE_ID_VXD		0x14
#define MONO_PE_RESOURCE_ID_ANICURSOR	0x15
#define MONO_PE_RESOURCE_ID_ANIICON	0x16
#define MONO_PE_RESOURCE_ID_HTML	0x17

typedef struct {
	/* If the MSB is set, then the other 31 bits store the RVA of
	 * the unicode string containing the name.  Otherwise, the
	 * other 31 bits contain the ID of this entry.
	 */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
	guint32 name_offset:31;
	guint32 name_is_string:1;
#else
	guint32 name_is_string:1;
	guint32 name_offset:31;
#endif
	
	/* If the MSB is set, then the other 31 bits store the RVA of
	 * another subdirectory.  Otherwise, the other 31 bits store
	 * the RVA of the resource data entry leaf node.
	 */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
	guint32 dir_offset:31;
	guint32 is_dir:1;
#else
	guint32 is_dir:1;
	guint32 dir_offset:31;
#endif
} MonoPEResourceDirEntry;

typedef struct 
{
	guint32 res_characteristics;
	guint32 res_date_stamp;
	guint16 res_major;
	guint16 res_minor;
	guint16 res_named_entries;
	guint16 res_id_entries;
	/* Directory entries follow on here.  The array is
	 * res_named_entries + res_id_entries long, containing all
	 * named entries first.
	 */
} MonoPEResourceDir;

typedef struct {
	guint32 rva;
	guint32 size;
} MonoPEDirEntry;

/* 128 bytes */
typedef struct {
	MonoPEDirEntry pe_export_table;
	MonoPEDirEntry pe_import_table;
	MonoPEDirEntry pe_resource_table;
	MonoPEDirEntry pe_exception_table;
	MonoPEDirEntry pe_certificate_table;
	MonoPEDirEntry pe_reloc_table;
	MonoPEDirEntry pe_debug;
	MonoPEDirEntry pe_copyright;
	MonoPEDirEntry pe_global_ptr;
	MonoPEDirEntry pe_tls_table;
	MonoPEDirEntry pe_load_config_table;
	MonoPEDirEntry pe_bound_import;
	MonoPEDirEntry pe_iat;
	MonoPEDirEntry pe_delay_import_desc;
	MonoPEDirEntry pe_cli_header;
	MonoPEDirEntry pe_reserved;
} MonoPEDatadir;

/* 248 bytes */
typedef struct {
	char            pesig [4];
	MonoCOFFHeader  coff;
	MonoPEHeader    pe;
	MonoPEHeaderNT  nt;
	MonoPEDatadir   datadir;
} MonoDotNetHeader;

typedef struct {
	char    st_name [8];
	guint32 st_virtual_size;
	guint32 st_virtual_address;
	guint32 st_raw_data_size;
	guint32 st_raw_data_ptr;
	guint32 st_reloc_ptr;
	guint32 st_lineno_ptr;
	guint16 st_reloc_count;
	guint16 st_line_count;

#define SECT_FLAGS_HAS_CODE               0x20
#define SECT_FLAGS_HAS_INITIALIZED_DATA   0x40
#define SECT_FLAGS_HAS_UNINITIALIZED_DATA 0x80
#define SECT_FLAGS_MEM_DISCARDABLE        0x02000000
#define SECT_FLAGS_MEM_NOT_CACHED         0x04000000
#define SECT_FLAGS_MEM_NOT_PAGED          0x08000000
#define SECT_FLAGS_MEM_SHARED             0x10000000
#define SECT_FLAGS_MEM_EXECUTE            0x20000000
#define SECT_FLAGS_MEM_READ               0x40000000
#define SECT_FLAGS_MEM_WRITE              0x80000000
	guint32 st_flags;

} MonoSectionTable;

typedef struct {
	guint32        ch_size;
	guint16        ch_runtime_major;
	guint16        ch_runtime_minor;
	MonoPEDirEntry ch_metadata;

#define CLI_FLAGS_ILONLY         0x01
#define CLI_FLAGS_32BITREQUIRED  0x02
#define CLI_FLAGS_STRONGNAMESIGNED 0x8
#define CLI_FLAGS_TRACKDEBUGDATA 0x00010000
	guint32        ch_flags;

	guint32        ch_entry_point;
	MonoPEDirEntry ch_resources;
	MonoPEDirEntry ch_strong_name;
	MonoPEDirEntry ch_code_manager_table;
	MonoPEDirEntry ch_vtable_fixups;
	MonoPEDirEntry ch_export_address_table_jumps;

	/* The following are zero in the current docs */
	MonoPEDirEntry ch_eeinfo_table;
	MonoPEDirEntry ch_helper_table;
	MonoPEDirEntry ch_dynamic_info;
	MonoPEDirEntry ch_delay_load_info;
	MonoPEDirEntry ch_module_image;
	MonoPEDirEntry ch_external_fixups;
	MonoPEDirEntry ch_ridmap;
	MonoPEDirEntry ch_debug_map;
	MonoPEDirEntry ch_ip_map;
} MonoCLIHeader;

/* This is not an on-disk structure */
typedef struct {
	MonoDotNetHeader  cli_header;
	int               cli_section_count;
	MonoSectionTable  *cli_section_tables;
	void            **cli_sections;
	MonoCLIHeader     cli_cli_header;
} MonoCLIImageInfo;

guint32       mono_cli_rva_image_map (MonoCLIImageInfo *iinfo, guint32 rva);

#endif /* __MONO_CIL_COFF_H__ */