00001 /* 00002 * Copyright (c) Christos Zoulas 2003. 00003 * All Rights Reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice immediately at the beginning of the file, without modification, 00010 * this list of conditions, and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00016 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00017 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00018 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 00019 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00020 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00021 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00022 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00023 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00024 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00025 * SUCH DAMAGE. 00026 */ 00027 /* 00028 * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp 00029 * 00030 * Provide elf data structures for non-elf machines, allowing file 00031 * non-elf hosts to determine if an elf binary is stripped. 00032 * Note: cobbled from the linux header file, with modifications 00033 */ 00034 #ifndef __fake_elf_h__ 00035 #define __fake_elf_h__ 00036 00037 #if HAVE_STDINT_H 00038 #include <stdint.h> 00039 #endif 00040 00041 typedef uint32_t Elf32_Addr; 00042 typedef uint32_t Elf32_Off; 00043 typedef uint16_t Elf32_Half; 00044 typedef uint32_t Elf32_Word; 00045 typedef uint8_t Elf32_Char; 00046 00047 #if SIZEOF_UINT64_T != 8 00048 #define USE_ARRAY_FOR_64BIT_TYPES 00049 typedef uint32_t Elf64_Addr[2]; 00050 typedef uint32_t Elf64_Off[2]; 00051 typedef uint32_t Elf64_Xword[2]; 00052 #else 00053 #undef USE_ARRAY_FOR_64BIT_TYPES 00054 typedef uint64_t Elf64_Addr; 00055 typedef uint64_t Elf64_Off; 00056 typedef uint64_t Elf64_Xword; 00057 #endif 00058 typedef uint16_t Elf64_Half; 00059 typedef uint32_t Elf64_Word; 00060 typedef uint8_t Elf64_Char; 00061 00062 #define EI_NIDENT 16 00063 00064 typedef struct { 00065 Elf32_Char e_ident[EI_NIDENT]; 00066 Elf32_Half e_type; 00067 Elf32_Half e_machine; 00068 Elf32_Word e_version; 00069 Elf32_Addr e_entry; /* Entry point */ 00070 Elf32_Off e_phoff; 00071 Elf32_Off e_shoff; 00072 Elf32_Word e_flags; 00073 Elf32_Half e_ehsize; 00074 Elf32_Half e_phentsize; 00075 Elf32_Half e_phnum; 00076 Elf32_Half e_shentsize; 00077 Elf32_Half e_shnum; 00078 Elf32_Half e_shstrndx; 00079 } Elf32_Ehdr; 00080 00081 typedef struct { 00082 Elf64_Char e_ident[EI_NIDENT]; 00083 Elf64_Half e_type; 00084 Elf64_Half e_machine; 00085 Elf64_Word e_version; 00086 Elf64_Addr e_entry; /* Entry point */ 00087 Elf64_Off e_phoff; 00088 Elf64_Off e_shoff; 00089 Elf64_Word e_flags; 00090 Elf64_Half e_ehsize; 00091 Elf64_Half e_phentsize; 00092 Elf64_Half e_phnum; 00093 Elf64_Half e_shentsize; 00094 Elf64_Half e_shnum; 00095 Elf64_Half e_shstrndx; 00096 } Elf64_Ehdr; 00097 00098 /* e_type */ 00099 #define ET_EXEC 2 00100 #define ET_CORE 4 00101 00102 /* sh_type */ 00103 #define SHT_SYMTAB 2 00104 #define SHT_NOTE 7 00105 #define SHT_DYNSYM 11 00106 00107 /* elf type */ 00108 #define ELFDATANONE 0 /* e_ident[EI_DATA] */ 00109 #define ELFDATA2LSB 1 00110 #define ELFDATA2MSB 2 00111 00112 /* elf class */ 00113 #define ELFCLASSNONE 0 00114 #define ELFCLASS32 1 00115 #define ELFCLASS64 2 00116 00117 /* magic number */ 00118 #define EI_MAG0 0 /* e_ident[] indexes */ 00119 #define EI_MAG1 1 00120 #define EI_MAG2 2 00121 #define EI_MAG3 3 00122 #define EI_CLASS 4 00123 #define EI_DATA 5 00124 #define EI_VERSION 6 00125 #define EI_PAD 7 00126 00127 #define ELFMAG0 0x7f /* EI_MAG */ 00128 #define ELFMAG1 'E' 00129 #define ELFMAG2 'L' 00130 #define ELFMAG3 'F' 00131 #define ELFMAG "\177ELF" 00132 00133 #define OLFMAG1 'O' 00134 #define OLFMAG "\177OLF" 00135 00136 typedef struct { 00137 Elf32_Word p_type; 00138 Elf32_Off p_offset; 00139 Elf32_Addr p_vaddr; 00140 Elf32_Addr p_paddr; 00141 Elf32_Word p_filesz; 00142 Elf32_Word p_memsz; 00143 Elf32_Word p_flags; 00144 Elf32_Word p_align; 00145 } Elf32_Phdr; 00146 00147 typedef struct { 00148 Elf64_Word p_type; 00149 Elf64_Word p_flags; 00150 Elf64_Off p_offset; 00151 Elf64_Addr p_vaddr; 00152 Elf64_Addr p_paddr; 00153 Elf64_Xword p_filesz; 00154 Elf64_Xword p_memsz; 00155 Elf64_Xword p_align; 00156 } Elf64_Phdr; 00157 00158 #define PT_NULL 0 /* p_type */ 00159 #define PT_LOAD 1 00160 #define PT_DYNAMIC 2 00161 #define PT_INTERP 3 00162 #define PT_NOTE 4 00163 #define PT_SHLIB 5 00164 #define PT_PHDR 6 00165 #define PT_NUM 7 00166 00167 typedef struct { 00168 Elf32_Word sh_name; 00169 Elf32_Word sh_type; 00170 Elf32_Word sh_flags; 00171 Elf32_Addr sh_addr; 00172 Elf32_Off sh_offset; 00173 Elf32_Word sh_size; 00174 Elf32_Word sh_link; 00175 Elf32_Word sh_info; 00176 Elf32_Word sh_addralign; 00177 Elf32_Word sh_entsize; 00178 } Elf32_Shdr; 00179 00180 typedef struct { 00181 Elf64_Word sh_name; 00182 Elf64_Word sh_type; 00183 Elf64_Off sh_flags; 00184 Elf64_Addr sh_addr; 00185 Elf64_Off sh_offset; 00186 Elf64_Off sh_size; 00187 Elf64_Word sh_link; 00188 Elf64_Word sh_info; 00189 Elf64_Off sh_addralign; 00190 Elf64_Off sh_entsize; 00191 } Elf64_Shdr; 00192 00193 /* Notes used in ET_CORE */ 00194 #define NT_PRSTATUS 1 00195 #define NT_PRFPREG 2 00196 #define NT_PRPSINFO 3 00197 #define NT_TASKSTRUCT 4 00198 00199 #define NT_NETBSD_CORE_PROCINFO 1 00200 00201 /* Note header in a PT_NOTE section */ 00202 typedef struct elf_note { 00203 Elf32_Word n_namesz; /* Name size */ 00204 Elf32_Word n_descsz; /* Content size */ 00205 Elf32_Word n_type; /* Content type */ 00206 } Elf32_Nhdr; 00207 00208 typedef struct { 00209 Elf64_Word n_namesz; 00210 Elf64_Word n_descsz; 00211 Elf64_Word n_type; 00212 } Elf64_Nhdr; 00213 00214 #define NT_PRSTATUS 1 00215 #define NT_PRFPREG 2 00216 #define NT_PRPSINFO 3 00217 #define NT_PRXREG 4 00218 #define NT_PLATFORM 5 00219 #define NT_AUXV 6 00220 00221 /* Note types used in executables */ 00222 /* NetBSD executables (name = "NetBSD") */ 00223 #define NT_NETBSD_VERSION 1 00224 #define NT_NETBSD_EMULATION 2 00225 #define NT_FREEBSD_VERSION 1 00226 #define NT_OPENBSD_VERSION 1 00227 #define NT_DRAGONFLY_VERSION 1 00228 /* GNU executables (name = "GNU") */ 00229 #define NT_GNU_VERSION 1 00230 00231 /* GNU OS tags */ 00232 #define GNU_OS_LINUX 0 00233 #define GNU_OS_HURD 1 00234 #define GNU_OS_SOLARIS 2 00235 00236 #endif