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 typedef uint64_t Elf64_Addr; 00054 typedef uint64_t Elf64_Off; 00055 typedef uint64_t Elf64_Xword; 00056 #endif 00057 typedef uint16_t Elf64_Half; 00058 typedef uint32_t Elf64_Word; 00059 typedef uint8_t Elf64_Char; 00060 00061 #define EI_NIDENT 16 00062 00063 typedef struct { 00064 Elf32_Char e_ident[EI_NIDENT]; 00065 Elf32_Half e_type; 00066 Elf32_Half e_machine; 00067 Elf32_Word e_version; 00068 Elf32_Addr e_entry; /* Entry point */ 00069 Elf32_Off e_phoff; 00070 Elf32_Off e_shoff; 00071 Elf32_Word e_flags; 00072 Elf32_Half e_ehsize; 00073 Elf32_Half e_phentsize; 00074 Elf32_Half e_phnum; 00075 Elf32_Half e_shentsize; 00076 Elf32_Half e_shnum; 00077 Elf32_Half e_shstrndx; 00078 } Elf32_Ehdr; 00079 00080 typedef struct { 00081 Elf64_Char e_ident[EI_NIDENT]; 00082 Elf64_Half e_type; 00083 Elf64_Half e_machine; 00084 Elf64_Word e_version; 00085 Elf64_Addr e_entry; /* Entry point */ 00086 Elf64_Off e_phoff; 00087 Elf64_Off e_shoff; 00088 Elf64_Word e_flags; 00089 Elf64_Half e_ehsize; 00090 Elf64_Half e_phentsize; 00091 Elf64_Half e_phnum; 00092 Elf64_Half e_shentsize; 00093 Elf64_Half e_shnum; 00094 Elf64_Half e_shstrndx; 00095 } Elf64_Ehdr; 00096 00097 /* e_type */ 00098 #define ET_EXEC 2 00099 #define ET_CORE 4 00100 00101 /* sh_type */ 00102 #define SHT_SYMTAB 2 00103 #define SHT_NOTE 7 00104 #define SHT_DYNSYM 11 00105 00106 /* elf type */ 00107 #define ELFDATANONE 0 /* e_ident[EI_DATA] */ 00108 #define ELFDATA2LSB 1 00109 #define ELFDATA2MSB 2 00110 00111 /* elf class */ 00112 #define ELFCLASSNONE 0 00113 #define ELFCLASS32 1 00114 #define ELFCLASS64 2 00115 00116 /* magic number */ 00117 #define EI_MAG0 0 /* e_ident[] indexes */ 00118 #define EI_MAG1 1 00119 #define EI_MAG2 2 00120 #define EI_MAG3 3 00121 #define EI_CLASS 4 00122 #define EI_DATA 5 00123 #define EI_VERSION 6 00124 #define EI_PAD 7 00125 00126 #define ELFMAG0 0x7f /* EI_MAG */ 00127 #define ELFMAG1 'E' 00128 #define ELFMAG2 'L' 00129 #define ELFMAG3 'F' 00130 #define ELFMAG "\177ELF" 00131 00132 #define OLFMAG1 'O' 00133 #define OLFMAG "\177OLF" 00134 00135 typedef struct { 00136 Elf32_Word p_type; 00137 Elf32_Off p_offset; 00138 Elf32_Addr p_vaddr; 00139 Elf32_Addr p_paddr; 00140 Elf32_Word p_filesz; 00141 Elf32_Word p_memsz; 00142 Elf32_Word p_flags; 00143 Elf32_Word p_align; 00144 } Elf32_Phdr; 00145 00146 typedef struct { 00147 Elf64_Word p_type; 00148 Elf64_Word p_flags; 00149 Elf64_Off p_offset; 00150 Elf64_Addr p_vaddr; 00151 Elf64_Addr p_paddr; 00152 Elf64_Xword p_filesz; 00153 Elf64_Xword p_memsz; 00154 Elf64_Xword p_align; 00155 } Elf64_Phdr; 00156 00157 #define PT_NULL 0 /* p_type */ 00158 #define PT_LOAD 1 00159 #define PT_DYNAMIC 2 00160 #define PT_INTERP 3 00161 #define PT_NOTE 4 00162 #define PT_SHLIB 5 00163 #define PT_PHDR 6 00164 #define PT_NUM 7 00165 00166 typedef struct { 00167 Elf32_Word sh_name; 00168 Elf32_Word sh_type; 00169 Elf32_Word sh_flags; 00170 Elf32_Addr sh_addr; 00171 Elf32_Off sh_offset; 00172 Elf32_Word sh_size; 00173 Elf32_Word sh_link; 00174 Elf32_Word sh_info; 00175 Elf32_Word sh_addralign; 00176 Elf32_Word sh_entsize; 00177 } Elf32_Shdr; 00178 00179 typedef struct { 00180 Elf64_Word sh_name; 00181 Elf64_Word sh_type; 00182 Elf64_Off sh_flags; 00183 Elf64_Addr sh_addr; 00184 Elf64_Off sh_offset; 00185 Elf64_Off sh_size; 00186 Elf64_Word sh_link; 00187 Elf64_Word sh_info; 00188 Elf64_Off sh_addralign; 00189 Elf64_Off sh_entsize; 00190 } Elf64_Shdr; 00191 00192 /* Notes used in ET_CORE */ 00193 #define NT_PRSTATUS 1 00194 #define NT_PRFPREG 2 00195 #define NT_PRPSINFO 3 00196 #define NT_TASKSTRUCT 4 00197 00198 #define NT_NETBSD_CORE_PROCINFO 1 00199 00200 /* Note header in a PT_NOTE section */ 00201 typedef struct elf_note { 00202 Elf32_Word n_namesz; /* Name size */ 00203 Elf32_Word n_descsz; /* Content size */ 00204 Elf32_Word n_type; /* Content type */ 00205 } Elf32_Nhdr; 00206 00207 typedef struct { 00208 Elf64_Word n_namesz; 00209 Elf64_Word n_descsz; 00210 Elf64_Word n_type; 00211 } Elf64_Nhdr; 00212 00213 #define NT_PRSTATUS 1 00214 #define NT_PRFPREG 2 00215 #define NT_PRPSINFO 3 00216 #define NT_PRXREG 4 00217 #define NT_PLATFORM 5 00218 #define NT_AUXV 6 00219 00220 /* Note types used in executables */ 00221 /* NetBSD executables (name = "NetBSD") */ 00222 #define NT_NETBSD_VERSION 1 00223 #define NT_NETBSD_EMULATION 2 00224 #define NT_FREEBSD_VERSION 1 00225 #define NT_OPENBSD_VERSION 1 00226 #define NT_DRAGONFLY_VERSION 1 00227 /* GNU executables (name = "GNU") */ 00228 #define NT_GNU_VERSION 1 00229 00230 /* GNU OS tags */ 00231 #define GNU_OS_LINUX 0 00232 #define GNU_OS_HURD 1 00233 #define GNU_OS_SOLARIS 2 00234 00235 #endif