| 1 |
#ifndef PE_GENERIC_H |
| 2 |
#define PE_GENERIC_H |
| 3 |
/* |
| 4 |
Copyright (c) 2018-2023, David Anderson All rights reserved. |
| 5 |
|
| 6 |
Redistribution and use in source and binary forms, with |
| 7 |
or without modification, are permitted provided that the |
| 8 |
following conditions are met: |
| 9 |
|
| 10 |
Redistributions of source code must retain the above |
| 11 |
copyright notice, this list of conditions and the following |
| 12 |
disclaimer. |
| 13 |
|
| 14 |
Redistributions in binary form must reproduce the above |
| 15 |
copyright notice, this list of conditions and the following |
| 16 |
disclaimer in the documentation and/or other materials |
| 17 |
provided with the distribution. |
| 18 |
|
| 19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 20 |
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 21 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 22 |
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 24 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 26 |
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 27 |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 29 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 30 |
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 31 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 |
*/ |
| 33 |
#ifdef __cplusplus |
| 34 |
extern "C" { |
| 35 |
#endif /* __cplusplus */ |
| 36 |
|
| 37 |
struct dwarf_pe_generic_file_header |
| 38 |
{ |
| 39 |
Dwarf_Unsigned Machine; |
| 40 |
Dwarf_Unsigned NumberOfSections; |
| 41 |
Dwarf_Unsigned TimeDateStamp; |
| 42 |
Dwarf_Unsigned PointerToSymbolTable; |
| 43 |
Dwarf_Unsigned NumberOfSymbols; |
| 44 |
Dwarf_Unsigned SizeOfOptionalHeader; /* in object file */ |
| 45 |
Dwarf_Unsigned Characteristics; |
| 46 |
}; |
| 47 |
|
| 48 |
struct dwarf_pe_generic_data_directory |
| 49 |
{ |
| 50 |
Dwarf_Unsigned VirtualAddress; |
| 51 |
Dwarf_Unsigned Size; |
| 52 |
}; |
| 53 |
|
| 54 |
#define DWARF_PE_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16 |
| 55 |
struct dwarf_pe_generic_optional_header |
| 56 |
{ |
| 57 |
Dwarf_Unsigned Magic; |
| 58 |
unsigned char MajorLinkerVersion; |
| 59 |
unsigned char MinorLinkerVersion; |
| 60 |
Dwarf_Unsigned SizeOfCode; |
| 61 |
Dwarf_Unsigned SizeOfInitializedData; |
| 62 |
Dwarf_Unsigned SizeOfUninitializedData; |
| 63 |
Dwarf_Unsigned AddressOfEntryPoint; |
| 64 |
Dwarf_Unsigned BaseOfCode; |
| 65 |
Dwarf_Unsigned BaseOfData; |
| 66 |
Dwarf_Unsigned ImageBase; |
| 67 |
Dwarf_Unsigned SectionAlignment; |
| 68 |
Dwarf_Unsigned FileAlignment; |
| 69 |
Dwarf_Unsigned MajorOperatingSystemVersion; |
| 70 |
Dwarf_Unsigned MinorOperatingSystemVersion; |
| 71 |
Dwarf_Unsigned MajorImageVersion; |
| 72 |
Dwarf_Unsigned MinorImageVersion; |
| 73 |
Dwarf_Unsigned MajorSubsystemVersion; |
| 74 |
Dwarf_Unsigned MinorSubsystemVersion; |
| 75 |
Dwarf_Unsigned Win32VersionValue; |
| 76 |
Dwarf_Unsigned SizeOfImage; /* size in object file */ |
| 77 |
Dwarf_Unsigned SizeOfHeaders; /* size in object file */ |
| 78 |
Dwarf_Unsigned CheckSum; |
| 79 |
Dwarf_Unsigned Subsystem; |
| 80 |
Dwarf_Unsigned DllCharacteristics; |
| 81 |
Dwarf_Unsigned SizeOfStackReserve; |
| 82 |
Dwarf_Unsigned SizeOfStackCommit; |
| 83 |
Dwarf_Unsigned SizeOfHeapReserve; |
| 84 |
Dwarf_Unsigned SizeOfHeapCommit; |
| 85 |
Dwarf_Unsigned LoaderFlags; |
| 86 |
Dwarf_Unsigned NumberOfRvaAndSizes; |
| 87 |
Dwarf_Unsigned SizeOfDataDirEntry; /* size in object file */ |
| 88 |
struct dwarf_pe_generic_data_directory |
| 89 |
DataDirectory[DWARF_PE_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]; |
| 90 |
}; |
| 91 |
|
| 92 |
struct dwarf_pe_generic_image_section_header |
| 93 |
{ |
| 94 |
char *name; /* Name must be freed */ |
| 95 |
char *dwarfsectname; /* Name must be freed */ |
| 96 |
Dwarf_Unsigned SecHeaderOffset; /* offset in object file */ |
| 97 |
/* union { */ |
| 98 |
/* Dwarf_Unsigned PhysicalAddress; */ |
| 99 |
Dwarf_Unsigned VirtualSize; |
| 100 |
/* } Misc; */ |
| 101 |
Dwarf_Unsigned VirtualAddress; |
| 102 |
Dwarf_Unsigned SizeOfRawData; /* size we need */ |
| 103 |
Dwarf_Unsigned PointerToRawData; |
| 104 |
Dwarf_Unsigned PointerToRelocations; |
| 105 |
Dwarf_Unsigned PointerToLinenumbers; |
| 106 |
Dwarf_Unsigned NumberOfRelocations; |
| 107 |
Dwarf_Unsigned NumberOfLinenumbers; |
| 108 |
Dwarf_Unsigned Characteristics; |
| 109 |
Dwarf_Small * loaded_data; /* must be freed. */ |
| 110 |
Dwarf_Bool section_irrelevant_to_dwarf; |
| 111 |
}; |
| 112 |
|
| 113 |
#define DWARF_PE_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b |
| 114 |
#define DWARF_PE_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b |
| 115 |
#define DWARF_PE_IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107 |
| 116 |
|
| 117 |
/* ident[0] == 'P' means this is a PE header. |
| 118 |
ident[1] will be 1 indicating version 1. |
| 119 |
Other bytes in ident not defined, should be zero. */ |
| 120 |
typedef struct pe_filedata_s { |
| 121 |
char pe_ident[8]; |
| 122 |
const char * pe_path; /* must free.*/ |
| 123 |
int pe_fd; |
| 124 |
int pe_destruct_close_fd; /*aka: lib owns fd */ |
| 125 |
int pe_is_64bit; |
| 126 |
Dwarf_Unsigned pe_filesize; |
| 127 |
Dwarf_Unsigned pe_flags; |
| 128 |
Dwarf_Unsigned pe_machine; |
| 129 |
Dwarf_Small pe_offsetsize; /* 32 or 64 section data */ |
| 130 |
Dwarf_Small pe_pointersize; |
| 131 |
int pe_ftype; |
| 132 |
unsigned pe_endian; |
| 133 |
void (*pe_copy_word) (void *, const void *, unsigned long); |
| 134 |
Dwarf_Unsigned pe_nt_header_offset; |
| 135 |
Dwarf_Unsigned pe_optional_header_offset; |
| 136 |
Dwarf_Unsigned pe_optional_header_size; |
| 137 |
Dwarf_Unsigned pe_symbol_table_offset; |
| 138 |
Dwarf_Unsigned pe_string_table_offset; |
| 139 |
Dwarf_Unsigned pe_section_table_offset; |
| 140 |
Dwarf_Unsigned pe_signature; |
| 141 |
|
| 142 |
struct dwarf_pe_generic_file_header pe_FileHeader; |
| 143 |
|
| 144 |
struct dwarf_pe_generic_optional_header pe_OptionalHeader; |
| 145 |
|
| 146 |
Dwarf_Unsigned pe_section_count; |
| 147 |
struct dwarf_pe_generic_image_section_header *pe_sectionptr; |
| 148 |
|
| 149 |
Dwarf_Unsigned pe_string_table_size; |
| 150 |
char *pe_string_table; |
| 151 |
} dwarf_pe_object_access_internals_t; |
| 152 |
|
| 153 |
#ifdef __cplusplus |
| 154 |
} |
| 155 |
#endif /* __cplusplus */ |
| 156 |
|
| 157 |
#endif /* PE_GENERIC_H */ |