PageRenderTime 33ms CodeModel.GetById 16ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/cores/DllLoader/coff.h

http://github.com/xbmc/xbmc
C Header | 491 lines | 323 code | 67 blank | 101 comment | 0 complexity | 9873270c42f40330d5417c77d749e81d MD5 | raw file
  1/*
  2 *  Copyright (C) 2005-2018 Team Kodi
  3 *  This file is part of Kodi - https://kodi.tv
  4 *
  5 *  SPDX-License-Identifier: GPL-2.0-or-later
  6 *  See LICENSES/README.md for more information.
  7 */
  8
  9#pragma once
 10
 11//#pragma message("including coff.h")
 12//
 13//      COFF -- Common Object File Format
 14//          Used commonly by Un*x and is imbedded in Windows PE
 15//          file format.
 16//
 17
 18// These structures must be packed
 19#pragma pack(1)
 20
 21
 22/*
 23 *  Some general purpose MACROs
 24 */
 25
 26#define VERSION_MAJOR(x)    ((unsigned int)((x)& 0xff))
 27#define VERSION_MINOR(x)    ((unsigned int)(((x)>8) &0xff))
 28
 29#define BIGVERSION_MAJOR(x)    ((unsigned int)((x)& 0xffff))
 30#define BIGVERSION_MINOR(x)    ((unsigned int)(((x)>16) &0xffff))
 31
 32/*
 33 *      COFF File Header (Object & Image)
 34 *          Spec section 3.3
 35 */
 36
 37typedef struct
 38{
 39  unsigned short MachineType;            /* magic type               */
 40  unsigned short NumberOfSections;       /* number of sections       */
 41  unsigned long TimeDateStamp;          /* time & date stamp        */
 42  unsigned long PointerToSymbolTable;   /* file pointer to symtab   */
 43  unsigned long NumberOfSymbols;        /* number of symtab entries */
 44  unsigned short SizeOfOptionHeader;     /* sizeof(optional hdr)     */
 45  unsigned short Characteristics;        /* flags                    */
 46}
 47COFF_FileHeader_t;
 48
 49/*
 50 *      Machine Types
 51 *          Spec section 3.3.1
 52 *              (only i386 relevant for us)
 53 */
 54
 55#if 1
 56
 57#ifndef IMAGE_FILE_MACHINE_I386
 58#define IMAGE_FILE_MACHINE_I386     0x14c
 59#endif
 60
 61
 62
 63#define IMAGE_FILE_RELOCS_STRIPPED                  0x0001
 64#define IMAGE_FILE_EXECUTABLE_IMAGE                 0x0002
 65#define IMAGE_FILE_LINE_NUMS_STRIPPED               0x0004
 66#define IMAGE_FILE_LOCAL_SYMS_STRIPPED              0x0008
 67#define IMAGE_FILE_AGGRESSIVE_WS_TRIM               0x0010
 68#define IMAGE_FILE_LARGE_ADDRESS_AWARE              0x0020
 69#define IMAGE_FILE_16BIT_MACHINE                    0x0040
 70#define IMAGE_FILE_BYTES_REVERSED_LO                0x0080
 71#define IMAGE_FILE_32BIT_MACHINE                    0x0100
 72#define IMAGE_FILE_DEBUG_STRIPPED                   0x0200
 73#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP          0x0400
 74#define IMAGE_FILE_SYSTEM                           0x1000
 75#define IMAGE_FILE_DLL                              0x2000
 76#define IMAGE_FILE_UP_SYSTEM_ONLY                   0x4000
 77#define IMAGE_FILE_BYTES_REVERSED_HI                0x8000
 78
 79#endif
 80
 81
 82
 83#define OPTMAGIC_PE32   0x010b
 84#define OPTMAGIC_PE32P  0x020b
 85
 86#define OPTHDR_SIZE     28
 87#define OPTHDR_SIZEP    24
 88#define WINHDR_SIZE     68
 89#define WINHDR_SIZEP    88
 90
 91/*
 92 *      Optional Header Standard Fields (Image Only)
 93 *          Spec section 3.4.1
 94 */
 95
 96typedef struct
 97{
 98  unsigned short Magic;
 99  unsigned short LinkVersion;
100  unsigned long CodeSize;
101  unsigned long DataSize;
102  unsigned long BssSize;
103  unsigned long Entry;
104  unsigned long CodeBase;
105  unsigned long DataBase;
106}
107OptionHeader_t;
108
109typedef struct
110{
111  unsigned short Magic;
112  unsigned short LinkVersion;
113  unsigned long CodeSize;
114  unsigned long DataSize;
115  unsigned long BssSize;
116  unsigned long Entry;
117  unsigned long CodeBase;
118}
119OptionHeaderPlus_t;
120
121/*
122 *      Optional Header Windows NT-Specific Fields (Image Only)
123 *          Spec section 3.4.2
124 */
125
126typedef struct
127{
128  unsigned long ImageBase;
129  unsigned long SectionAlignment;
130  unsigned long FileAlignment;
131  unsigned long OSVer;
132  unsigned long ImgVer;
133  unsigned long SubSysVer;
134  unsigned long Reserved;
135  unsigned long SizeOfImage;
136  unsigned long SizeOfHeaders;
137  unsigned long CheckSum;
138  unsigned short Subsystem;
139  unsigned short DLLFlags;
140  unsigned long SizeOfStackReserve;
141  unsigned long SizeOfStackCommit;
142  unsigned long SizeOfHeapReserve;
143  unsigned long SizeOfHeapCommit;
144  unsigned long LoaderFlags;
145  unsigned long NumDirectories;
146}
147WindowsHeader_t;
148
149typedef struct
150{
151  unsigned long long ImageBase;
152  unsigned long SectionAlignment;
153  unsigned long FileAlignment;
154  unsigned long OSVer;
155  unsigned long ImgVer;
156  unsigned long SubSysVer;
157  unsigned long Reserved;
158  unsigned long SizeOfImage;
159  unsigned long SizeOfHeaders;
160  unsigned long CheckSum;
161  unsigned short Subsystem;
162  unsigned short DLLFlags;
163  unsigned long long SizeOfStackReserve;
164  unsigned long long SizeOfStackCommit;
165  unsigned long long SizeOfHeapReserve;
166  unsigned long long SizeOfHeapCommit;
167  unsigned long LoaderFlags;
168  unsigned long NumDirectories;
169}
170WindowsHeaderPlus_t;
171
172/*
173#define IMAGE_SUBSYSTEM_UNKNOWN                     0
174#define IMAGE_SUBSYSTEM_NATIVE                      1
175#define IMAGE_SUBSYSTEM_WINDOWS_GUI                 2
176#define IMAGE_SUBSYSTEM_WINDOWS_CUI                 3
177#define IMAGE_SUBSYSTEM_POSIX_CUI                   7
178#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI              9
179#define IMAGE_SUBSYSTEM_EFI_APPLICATION             10
180#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER     11
181#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER          12
182
183#define IMAGE_DLLCHARACTERISTICS_NO_BIND            0x0800
184#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER         0x2000
185#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE  0X8000
186*/
187
188/*
189 *      Optional Header Data Directories (Image Only)
190 *          Spec section 3.4.3
191 */
192
193typedef struct
194{
195  unsigned long RVA;
196  unsigned long Size;
197}
198Image_Data_Directory_t;
199
200enum Directory_Items {
201  EXPORT_TABLE = 0,
202  IMPORT_TABLE,
203  RESOURCE_TABLE,
204  EXCEPTION_TABLE,
205  CERTIFICATE_TABLE,
206  BASE_RELOCATION_TABLE,
207  DEBUG_,
208  ARCHITECTURE,
209  GLOBAL_PTR,
210  TLS_TABLE,
211  LOAD_CONFIG_TABLE,
212  BOUND_IMPORT,
213  IAT,
214  DELAY_IMPORT_DESCRIPTOR,
215  COM_RUNTIME_HEADER,
216  RESERVED
217};
218
219/*
220 *      Section Table (Section Headers)
221 *          Spec section 4.
222 */
223
224
225typedef struct
226{
227  unsigned char Name[8];
228  unsigned long VirtualSize;
229  unsigned long VirtualAddress;
230  unsigned long SizeOfRawData;
231  unsigned long PtrToRawData;
232  unsigned long PtrToRelocations;
233  unsigned long PtrToLineNums;
234  unsigned short NumRelocations;
235  unsigned short NumLineNumbers;
236  unsigned long Characteristics;
237}
238SectionHeader_t;
239
240/*
241 *      Section Flags (Characteristics)
242 *          Spec section 4.1
243 */
244
245#define IMAGE_SCN_CNT_CODE          0x00000020
246#define IMAGE_SCN_CNT_DATA          0x00000040
247#define IMAGE_SCN_CNT_BSS           0x00000080
248#define IMAGE_SCN_LNK_INFO          0x00000200
249#define IMAGE_SCN_LNK_REMOVE        0x00000800
250#define IMAGE_SCN_LNK_COMDAT        0x00001000
251#define IMAGE_SCN_ALIGN_1BYTES      0x00100000
252#define IMAGE_SCN_ALIGN_2BYTES      0x00200000
253#define IMAGE_SCN_ALIGN_4BYTES      0x00300000
254#define IMAGE_SCN_ALIGN_8BYTES      0x00400000
255#define IMAGE_SCN_ALIGN_16BYTES     0x00500000
256#define IMAGE_SCN_ALIGN_32BYTES     0x00600000
257#define IMAGE_SCN_ALIGN_64BYTES     0x00700000
258#define IMAGE_SCN_ALIGN_128BYTES    0x00800000
259#define IMAGE_SCN_ALIGN_256BYTES    0x00900000
260#define IMAGE_SCN_ALIGN_512BYTES    0x00A00000
261#define IMAGE_SCN_ALIGN_1024BYTES   0x00B00000
262#define IMAGE_SCN_ALIGN_2048BYTES   0x00C00000
263#define IMAGE_SCN_ALIGN_4096BYTES   0x00D00000
264#define IMAGE_SCN_ALIGN_8192BYTES   0x00E00000
265#define IMAGE_SCN_ALIGN_MASK        0x00F00000
266#define IMAGE_SCN_LNK_NRELOC_OVFL   0x01000000
267#define IMAGE_SCN_MEM_DISCARDABLE   0x02000000
268#define IMAGE_SCN_MEM_NOT_CACHED    0x04000000
269#define IMAGE_SCN_MEM_NOT_PAGED     0x08000000
270#define IMAGE_SCN_MEM_SHARED        0x10000000
271#define IMAGE_SCN_MEM_EXECUTE       0x20000000
272#define IMAGE_SCN_MEM_READ          0x40000000
273#define IMAGE_SCN_MEM_WRITE         0x80000000
274
275/*
276 *      COFF Relocations (Object Only)
277 *          Spec section 5.2
278 */
279
280typedef struct
281{
282  unsigned long VirtualAddress;
283  unsigned long SymTableIndex;
284  unsigned short Type;
285}
286ObjReloc_t;
287
288/*
289 *      COFF Relocation Type Indicators
290 *          Spec section 5.2.1
291 */
292
293#define IMAGE_REL_I386_ABSOLUTE     0x0000
294#define IMAGE_REL_I386_DIR16        0x0001
295#define IMAGE_REL_I386_REL16        0x0002
296#define IMAGE_REL_I386_DIR32        0x0006
297#define IMAGE_REL_I386_DIR32NB      0x0007
298#define IMAGE_REL_I386_SEG12        0x0009
299#define IMAGE_REL_I386_SECTION      0x000A
300#define IMAGE_REL_I386_SECREL       0x000B
301#define IMAGE_REL_I386_REL32        0x0014
302
303/*
304 *      COFF Line Numbers
305 *          Spec section 5.3
306 */
307
308typedef struct
309{
310  union {
311    unsigned long SymbolTableIndex;
312    unsigned long VirtualAddress;
313  } Type;
314  unsigned short LineNum;
315}
316LineNumbers_t;
317
318/*
319 *      COFF Symbol Table
320 *          Spec section 5.4
321 */
322
323typedef struct
324{
325  union {
326    unsigned char ShortName[8];
327    unsigned long long Offset;
328  } Name;
329  unsigned long Value;
330  unsigned short SectionNumber;
331  unsigned short Type;
332  unsigned char StorageClass;
333  unsigned char NumberOfAuxSymbols;
334}
335SymbolTable_t;
336
337#if !defined(TARGET_WINDOWS)
338
339#define IMAGE_SYM_UNDEFINED     0
340#define IMAGE_SYM_ABSOLUTE      0xFFFF
341#define IMAGE_SYM_DEBUG         0xFFFE
342
343
344#define IMAGE_SYM_TYPE_NULL         0
345#define IMAGE_SYM_TYPE_VOID         1
346#define IMAGE_SYM_TYPE_CHAR         2
347#define IMAGE_SYM_TYPE_SHORT        3
348#define IMAGE_SYM_TYPE_INT          4
349#define IMAGE_SYM_TYPE_LONG         5
350#define IMAGE_SYM_TYPE_FLOAT        6
351#define IMAGE_SYM_TYPE_DOUBLE       7
352#define IMAGE_SYM_TYPE_STRUCT       8
353#define IMAGE_SYM_TYPE_UNION        9
354#define IMAGE_SYM_TYPE_ENUM         10
355#define IMAGE_SYM_TYPE_MOE          11
356#define IMAGE_SYM_TYPE_BYTE         12
357#define IMAGE_SYM_TYPE_WORD         13
358#define IMAGE_SYM_TYPE_UINT         14
359#define IMAGE_SYM_TYPE_DWORD        15
360
361#define IMAGE_SYM_DWORD_NULL        0
362#define IMAGE_SYM_DWORD_POINTER     1
363#define IMAGE_SYM_DWORD_FUNCTION    2
364#define IMAGE_SYM_DWORD_ARRAY       3
365
366
367#define IMAGE_SYM_CLASS_END_OF_FUNCTION         0xFF
368#define IMAGE_SYM_CLASS_NULL                    0
369#define IMAGE_SYM_CLASS_AUTOMATIC               1
370#define IMAGE_SYM_CLASS_EXTERNAL                2
371#define IMAGE_SYM_CLASS_STATIC                  3
372#define IMAGE_SYM_CLASS_REGISTER                4
373#define IMAGE_SYM_CLASS_EXTERNAL_DEF            5
374#define IMAGE_SYM_CLASS_LABEL                   6
375#define IMAGE_SYM_CLASS_UNDEFINED_LABEL         7
376#define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT        8
377#define IMAGE_SYM_CLASS_ARGUMENT                9
378#define IMAGE_SYM_CLASS_STRUCT_TAG              10
379#define IMAGE_SYM_CLASS_MEMBER_OF_UNION         11
380#define IMAGE_SYM_CLASS_UNION_TAG               12
381#define IMAGE_SYM_CLASS_TYPE_DEFINITION         13
382#define IMAGE_SYM_CLASS_UNDEFINED_STATIC        14
383#define IMAGE_SYM_CLASS_ENUM_TAG                15
384#define IMAGE_SYM_CLASS_MEMBER_OF_ENUM          16
385#define IMAGE_SYM_CLASS_REGISTER_PARAM          17
386#define IMAGE_SYM_CLASS_BIT_FIELD               18
387#define IMAGE_SYM_CLASS_BLOCK                   100
388#define IMAGE_SYM_CLASS_FUNCTION                101
389#define IMAGE_SYM_CLASS_END_OF_STRUCT           102
390#define IMAGE_SYM_CLASS_FILE                    103
391#define IMAGE_SYM_CLASS_SECTION                 104
392#define IMAGE_SYM_CLASS_WEAK_EXTERNAL           105
393#endif
394
395typedef struct
396{
397  unsigned long TagIndex;
398  unsigned long TotalSize;
399  unsigned long PtrToLineNumber;
400  unsigned long PtrToNextFunc;
401  unsigned short unused;
402}
403AuxFuncDef_t;
404
405/*
406 *      Symbol Auxiliary Record: .bf and .ef
407 *          Spec section 5.5.2
408 */
409
410typedef struct
411{
412  unsigned long unused;
413  unsigned short LineNumber;
414  unsigned long unused1;
415  unsigned short unused2;
416  unsigned long PtrToNextFunc;
417  unsigned char unused3;
418}
419AuxBfEf_t;
420
421/*
422 *      Export Section (Directory)
423 *          Spec section 6.3
424 */
425
426/*
427 *      Export Directory Table
428 *          Spec section 6.3.1
429 */
430
431typedef struct
432{
433  unsigned long ExportFlags;
434  unsigned long TimeStamp;
435  unsigned short MajorVersion;
436  unsigned short MinorVersion;
437  unsigned long Name_RVA;
438  unsigned long OrdinalBase;
439  unsigned long NumAddrTable;
440  unsigned long NumNamePtrs;
441  unsigned long ExportAddressTable_RVA;
442  unsigned long NamePointerTable_RVA;
443  unsigned long OrdinalTable_RVA;
444}
445ExportDirTable_t;
446
447
448/*
449 *      Import Section (Directory)
450 *          Spec section 6.4
451 */
452
453/*
454 *      Import Directory Table
455 *          Spec Section 6.4.1
456 */
457
458typedef struct
459{
460  unsigned long ImportLookupTable_RVA;
461  unsigned long TimeStamp;
462  unsigned long ForwarderChain;
463  unsigned long Name_RVA;
464  unsigned long ImportAddressTable_RVA;
465}
466ImportDirTable_t;
467
468/*
469 *      .reloc Relocation types
470 *          spec section 6.6
471 */
472
473#if 1
474#define IMAGE_REL_BASED_ABSOLUTE        0
475#define IMAGE_REL_BASED_HIGH            1
476#define IMAGE_REL_BASED_LOW             2
477#define IMAGE_REL_BASED_HIGHLOW         3
478#define IMAGE_REL_BASED_HIGHADJ         4
479#define IMAGE_REL_BASED_MIPS_JMPADDR    5
480#define IMAGE_REL_BASED_SECTION         6
481#define IMAGE_REL_BASED_REL32           7
482#define IMAGE_REL_BASED_MIPS_JMPADDR16  9
483#define IMAGE_REL_BASED_DIR64           10
484#define IMAGE_REL_BASED_HIGH3ADJ        11
485#endif
486
487
488
489
490#pragma pack()
491