1 /* p_elf_enum.h -- 2 3 This file is part of the UPX executable compressor. 4 5 Copyright (C) 1996-2020 Markus Franz Xaver Johannes Oberhumer 6 Copyright (C) 1996-2020 Laszlo Molnar 7 All Rights Reserved. 8 9 UPX and the UCL library are free software; you can redistribute them 10 and/or modify them under the terms of the GNU General Public License as 11 published by the Free Software Foundation; either version 2 of 12 the License, or (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; see the file COPYING. 21 If not, write to the Free Software Foundation, Inc., 22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 23 24 Markus F.X.J. Oberhumer Laszlo Molnar 25 <markus@oberhumer.com> <ezerotven+github@gmail.com> 26 */ 27 28 29 /************************************************************************* 30 // Use the preprocessor to work around 31 // - that the types embedding these enums have to be PODs, and 32 // deriving from an empty base class (which is the usual C++ way 33 // of "importing" enums) does not yield a POD any more 34 // - that older compilers do not correctly perform EBCO 35 **************************************************************************/ 36 37 #ifdef WANT_EHDR_ENUM 38 #undef WANT_EHDR_ENUM 39 enum { // e_ident[] 40 EI_CLASS = 4, 41 EI_DATA = 5, /* Data encoding */ 42 EI_VERSION = 6, 43 EI_OSABI = 7, 44 EI_ABIVERSION = 8 45 }; 46 enum { // e_ident[EI_CLASS] 47 ELFCLASS32 = 1, /* 32-bit objects */ 48 ELFCLASS64 = 2 /* 64-bit objects */ 49 }; 50 enum { // e_ident[EI_DATA] 51 ELFDATA2LSB = 1, /* 2's complement, little endian */ 52 ELFDATA2MSB = 2 /* 2's complement, big endian */ 53 }; 54 enum { // e_ident[EI_OSABI] 55 ELFOSABI_NONE = 0, // == ELFOSABI_SYSV 56 ELFOSABI_NETBSD = 2, 57 ELFOSABI_LINUX = 3, 58 ELFOSABI_FREEBSD = 9, 59 ELFOSABI_OPENBSD = 12, 60 ELFOSABI_ARM = 97 61 }; 62 enum { // e_type 63 ET_NONE = 0, /* No file type */ 64 ET_REL = 1, /* Relocatable file */ 65 ET_EXEC = 2, /* Executable file */ 66 ET_DYN = 3, /* Shared object file */ 67 ET_CORE = 4 /* Core file */ 68 }; 69 enum { // e_machine 70 EM_386 = 3, 71 EM_MIPS = 8, 72 EM_MIPS_RS3_LE = 10, /* MIPS R3000 little-endian */ 73 EM_PPC = 20, 74 EM_PPC64 = 21, 75 EM_ARM = 40, 76 EM_X86_64 = 62, 77 EM_AARCH64 = 183 78 79 }; 80 enum { // e_version 81 EV_CURRENT = 1 82 }; 83 #endif 84 85 86 #ifdef WANT_PHDR_ENUM 87 #undef WANT_PHDR_ENUM 88 enum { // p_type 89 PT_LOAD = 1, /* Loadable program segment */ 90 PT_DYNAMIC = 2, /* Dynamic linking information */ 91 PT_INTERP = 3, /* Name of program interpreter */ 92 PT_NOTE = 4, /* Auxiliary information (esp. OpenBSD) */ 93 PT_PHDR = 6 /* Entry for header table itself */ 94 , PT_GNU_STACK = 0x6474e551 /* Indicates stack executability */ 95 }; 96 97 enum { // p_flags 98 PF_X = 1, /* Segment is executable */ 99 PF_W = 2, /* Segment is writable */ 100 PF_R = 4 /* Segment is readable */ 101 }; 102 #endif 103 104 105 #ifdef WANT_SHDR_ENUM 106 #undef WANT_SHDR_ENUM 107 enum { // sh_type 108 SHT_NULL = 0, /* Section header table entry unused */ 109 SHT_PROGBITS = 1, /* Program data */ 110 SHT_SYMTAB = 2, /* Symbol table */ 111 SHT_STRTAB = 3, /* String table */ 112 SHT_RELA = 4, /* Relocation entries with addends */ 113 SHT_HASH = 5, /* Symbol hash table */ 114 SHT_DYNAMIC = 6, /* Dynamic linking information */ 115 SHT_NOTE = 7, /* Notes */ 116 SHT_NOBITS = 8, /* Program space with no data (bss) */ 117 SHT_REL = 9, /* Relocation entries, no addends */ 118 SHT_SHLIB = 10, /* Reserved */ 119 SHT_DYNSYM = 11, /* Dynamic linker symbol table */ 120 /* 12, 13 hole */ 121 SHT_INIT_ARRAY = 14, /* Array of constructors */ 122 SHT_FINI_ARRAY = 15, /* Array of destructors */ 123 SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */ 124 SHT_GROUP = 17, /* Section group */ 125 SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */ 126 SHT_GNU_LIBLIST = 0x6ffffff7 /* Prelink library list */ 127 128 , SHT_LOOS = 0x60000000 /* LOcal OS; SHT_ANDROID_REL{,A} is +1, +2 */ 129 , SHT_LOPROC = 0x70000000/* Start of processor-specific */ 130 , SHT_ARM_ATTRIBUTES = (SHT_LOPROC + 3) /* ARM attributes section. */ 131 }; 132 133 enum { // sh_flags 134 SHF_WRITE = (1 << 0), /* Writable */ 135 SHF_ALLOC = (1 << 1), /* Occupies memory during execution */ 136 SHF_EXECINSTR = (1 << 2), /* Executable */ 137 SHF_MERGE = (1 << 4), /* Might be merged */ 138 SHF_STRINGS = (1 << 5), /* Contains nul-terminated strings */ 139 SHF_INFO_LINK = (1 << 6), /* 'sh_info' contains SHT index */ 140 SHF_LINK_ORDER = (1 << 7) /* Preserve order after combining */ 141 }; 142 #endif 143 144 145 #ifdef WANT_DYN_ENUM 146 #undef WANT_DYN_ENUM 147 enum { // d_tag 148 DT_NULL = 0, /* End flag */ 149 DT_NEEDED = 1, /* Name of needed library */ 150 DT_PLTRELSZ = 2, /* Size in bytes of PLT relocs */ 151 DT_PLTGOT = 3, /* Processor defined value */ 152 DT_HASH = 4, /* Hash table of symbol names */ 153 DT_STRTAB = 5, /* String table */ 154 DT_SYMTAB = 6, /* Symbol table */ 155 DT_RELA = 7, /* Relocations which do contain an addend */ 156 DT_RELASZ = 8, /* Total size of Rela relocs */ 157 DT_RELAENT = 9, /* Size of one RELA relocation */ 158 DT_STRSZ = 10, /* Size of string table */ 159 DT_SYMENT = 11, /* Size of one symbol table entry */ 160 DT_INIT = 12, /* Address of init function */ 161 DT_FINI = 13, /* Address of termination function */ 162 163 DT_REL = 17, /* Relocations which contain no addend */ 164 DT_RELSZ = 18, /* Total size of Rel relocs */ 165 DT_RELENT = 19, /* Size of one Rel relocation */ 166 DT_PLTREL = 20, /* Type of reloc in PLT */ 167 DT_TEXTREL = 22, /* Reloc might modify .text */ 168 DT_JMPREL = 23, /* Address of PLT relocs */ 169 DT_INIT_ARRAY = 25, /* Array with addresses of init fct */ 170 DT_FINI_ARRAY = 26, /* Array with addresses of fini fct */ 171 DT_INIT_ARRAYSZ= 27, /* size in bytes */ 172 DT_FINI_ARRAYSZ= 28, /* size in bytes */ 173 DT_PREINIT_ARRAY = 32, /* Array with addresses of preinit fct*/ 174 DT_PREINIT_ARRAYSZ= 33, /* size in bytes */ 175 DT_CHECKSUM = 0x6ffffdf8, /* Only for prelink? */ 176 DT_GNU_HASH = 0x6ffffef5, /* GNU-style hash table */ 177 DT_VERSYM = 0x6ffffff0, /* version[] for each symbol */ 178 DT_FLAGS_1 = 0x6ffffffb, /* DF_1_* */ 179 DT_VERDEF = 0x6ffffffc, /* version definitions[] */ 180 DT_VERNEEDED= 0x6ffffffe /* version[] needed */ 181 }; 182 enum { // DT_FLAGS_1 183 DF_1_NOW = 0x00000001, /* Set RTLD_NOW for this object. */ 184 DF_1_PIE = 0x08000000 // Position-Independent Executable (main program) 185 }; 186 #endif 187 188 189 #ifdef WANT_SYM_ENUM 190 #undef WANT_SYM_ENUM 191 enum { // st_bind (high 4 bits of st_info) 192 STB_LOCAL = 0, /* Local symbol */ 193 STB_GLOBAL = 1, /* Global symbol */ 194 STB_WEAK = 2 /* Weak symbol */ 195 }; 196 197 enum { // st_type (low 4 bits of st_info) 198 STT_NOTYPE = 0, /* Symbol type is unspecified */ 199 STT_OBJECT = 1, /* Symbol is a data object */ 200 STT_FUNC = 2, /* Symbol is a code object */ 201 STT_SECTION = 3, /* Symbol associated with a section */ 202 STT_FILE = 4, /* Symbol's name is file name */ 203 STT_COMMON = 5, /* Symbol is a common data object */ 204 STT_TLS = 6 /* Symbol is thread-local data object*/ 205 }; 206 207 enum { // st_other (visibility) 208 STV_DEFAULT = 0, /* Default symbol visibility rules */ 209 STV_INTERNAL = 1, /* Processor specific hidden class */ 210 STV_HIDDEN = 2, /* Sym unavailable in other modules */ 211 STV_PROTECTED= 3 /* Not preemptible, not exported */ 212 }; 213 214 enum { // st_shndx 215 SHN_UNDEF = 0, /* Undefined section */ 216 SHN_ABS = 0xfff1, /* Associated symbol is absolute */ 217 SHN_COMMON = 0xfff2 /* Associated symbol is common */ 218 }; 219 #endif 220 221 222 #ifdef WANT_REL_ENUM //{ 223 #undef WANT_REL_ENUM ELF32_R_TYPE(unsigned x)224 static inline unsigned ELF32_R_TYPE(unsigned x) { return 0xff & x; } ELF64_R_TYPE(upx_uint64_t x)225 static inline unsigned ELF64_R_TYPE(upx_uint64_t x) { return 0xffffffff & (unsigned)x; } 226 227 # undef R_PPC_RELATIVE 228 # undef R_PPC64_RELATIVE 229 # undef R_PPC_JMP_SLOT 230 # undef R_PPC64_JMP_SLOT 231 enum { // relocation types 232 R_386_RELATIVE = 8, 233 R_AARCH64_RELATIVE = 1027, 234 R_ARM_RELATIVE = 23, 235 R_PPC_RELATIVE = 22, 236 R_PPC64_RELATIVE = R_PPC_RELATIVE, 237 R_X86_64_RELATIVE = 8, 238 239 R_386_JMP_SLOT = 7, 240 R_AARCH64_JUMP_SLOT = 1026, 241 R_ARM_JUMP_SLOT = 22, 242 R_PPC_JMP_SLOT = 21, 243 R_PPC64_JMP_SLOT = R_PPC_JMP_SLOT, 244 R_X86_64_JUMP_SLOT = 7 245 246 , R_ARM_ABS32 = 2 247 , R_ARM_GLOB_DAT = 21 248 249 , R_AARCH64_ABS64 = 257 250 , R_AARCH64_GLOB_DAT = 1025 251 252 }; 253 #endif //} 254 255 #ifdef WANT_NHDR_ENUM 256 #undef WANT_NHDR_ENUM 257 enum { // ELF PT_NOTE types 258 #define ELF_NOTE_GNU_NAME "GNU\0" 259 NT_GNU_ABI_TAG = 1, 260 NT_GNU_HWCAP = 2, 261 NT_GNU_BUILD_ID = 3, 262 263 #define ELF_NOTE_OPENBSD_NAME "OpenBSD\0" 264 NHDR_OPENBSD_TAG = 1, 265 266 #define ELF_NOTE_NETBSD_NAME "NetBSD\0" 267 NHDR_NETBSD_TAG = 1, 268 NHDR_CHECKSUM_TAG = 2, 269 NHDR_PAX_TAG = 3 270 }; 271 272 enum { // descsz descriptor sizes 273 GNU_ABI_DESCSZ = 16, // int GNU_OS, major, minor, subminor; 274 NETBSD_DESCSZ = 4, // major_ver * (10**8) + minor 275 OPENBSD_DESCSZ = 4, // 32-bit zero 276 // CHECKSUM_DESCSZ is 2*sizeof(short) + sizeof(checksum) 277 PAX_DESCSZ = 4 // 32-bit mask 278 }; 279 280 enum { // GNU OS/version 281 GNU_OS_LINUX = 0, 282 GNU_OS_HURD = 1, 283 GNU_OS_SOLARIS = 2 284 }; 285 286 enum { // NetBSD checksum methods 287 CHECKSUM_CRC32 = 1, 288 CHECKSUM_MD5 = 2, 289 CHECKSUM_SHA1 = 3, 290 CHECKSUM_SHA256 = 4 291 }; 292 293 #define ELF_NOTE_PAX_NAME "PaX\0" 294 enum { // NetBSD PaX bit values 295 PAX_MPROTECT = (1<<0), /* force enable Mprotect */ 296 PAX_NOMPROTECT = (1<<1), /* force disable Mprotect */ 297 PAX_GUARD = (1<<2), /* force enable SEGVguard */ 298 PAX_NOGUARD = (1<<3), /* force disable SEGVguard */ 299 PAX_ASLR = (1<<4), /* force enable ASLR */ 300 PAX_NOASLR = (1<<5) /* force disable ASLR */ 301 }; 302 #endif 303 304 /* vim:set ts=4 sw=4 et: */ 305