📄 elf.h
字号:
/* * Copyright (c) 1995, 1996, 2001, 2002 * Erik Theisen. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *//* * This is the ELF ABI header file * formerly known as "elf_abi.h". */#ifndef _ELF_H#define _ELF_H#if defined(__BEOS__) || \ defined(__NetBSD__) || \ defined(__FreeBSD__) || \ defined(__sun__) || \ defined(__APPLE__)#include <inttypes.h>#elif defined(__linux__) && defined(USE_HOSTCC)#include <stdint.h>#elif defined(__WIN32__)#include <unistd.h>typedef unsigned char uint8_t;typedef unsigned short uint16_t;typedef unsigned int uint32_t;#endif/* * This version doesn't work for 64-bit ABIs - Erik. *//* * These typedefs need to be handled better. */typedef uint32_t Elf32_Addr; /* Unsigned program address */typedef uint32_t Elf32_Off; /* Unsigned file offset */typedef int32_t Elf32_Sword; /* Signed large integer */typedef uint32_t Elf32_Word; /* Unsigned large integer */typedef uint16_t Elf32_Half; /* Unsigned medium integer *//* e_ident[] identification indexes */#define EI_MAG0 0 /* file ID */#define EI_MAG1 1 /* file ID */#define EI_MAG2 2 /* file ID */#define EI_MAG3 3 /* file ID */#define EI_CLASS 4 /* file class */#define EI_DATA 5 /* data encoding */#define EI_VERSION 6 /* ELF header version */#define EI_OSABI 7 /* OS/ABI specific ELF extensions */#define EI_ABIVERSION 8 /* ABI target version */#define EI_PAD 9 /* start of pad bytes */#define EI_NIDENT 16 /* Size of e_ident[] *//* e_ident[] magic number */#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */#define ELFMAG1 'E' /* e_ident[EI_MAG1] */#define ELFMAG2 'L' /* e_ident[EI_MAG2] */#define ELFMAG3 'F' /* e_ident[EI_MAG3] */#define ELFMAG "\177ELF" /* magic */#define SELFMAG 4 /* size of magic *//* e_ident[] file class */#define ELFCLASSNONE 0 /* invalid */#define ELFCLASS32 1 /* 32-bit objs */#define ELFCLASS64 2 /* 64-bit objs */#define ELFCLASSNUM 3 /* number of classes *//* e_ident[] data encoding */#define ELFDATANONE 0 /* invalid */#define ELFDATA2LSB 1 /* Little-Endian */#define ELFDATA2MSB 2 /* Big-Endian */#define ELFDATANUM 3 /* number of data encode defines *//* e_ident[] OS/ABI specific ELF extensions */#define ELFOSABI_NONE 0 /* No extension specified */#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */#define ELFOSABI_NETBSD 2 /* NetBSD */#define ELFOSABI_LINUX 3 /* Linux */#define ELFOSABI_SOLARIS 6 /* Sun Solaris */#define ELFOSABI_AIX 7 /* AIX */#define ELFOSABI_IRIX 8 /* IRIX */#define ELFOSABI_FREEBSD 9 /* FreeBSD */#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */#define ELFOSABI_MODESTO 11 /* Novell Modesto */#define ELFOSABI_OPENBSD 12 /* OpenBSD *//* 64-255 Architecture-specific value range *//* e_ident[] ABI Version */#define ELFABIVERSION 0/* e_ident */#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ (ehdr).e_ident[EI_MAG3] == ELFMAG3)/* ELF Header */typedef struct elfhdr{ unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ Elf32_Half e_type; /* object file type */ Elf32_Half e_machine; /* machine */ Elf32_Word e_version; /* object file version */ Elf32_Addr e_entry; /* virtual entry point */ Elf32_Off e_phoff; /* program header table offset */ Elf32_Off e_shoff; /* section header table offset */ Elf32_Word e_flags; /* processor-specific flags */ Elf32_Half e_ehsize; /* ELF header size */ Elf32_Half e_phentsize; /* program header entry size */ Elf32_Half e_phnum; /* number of program header entries */ Elf32_Half e_shentsize; /* section header entry size */ Elf32_Half e_shnum; /* number of section header entries */ Elf32_Half e_shstrndx; /* section header table's "section header string table" entry offset */} Elf32_Ehdr;/* e_type */#define ET_NONE 0 /* No file type */#define ET_REL 1 /* relocatable file */#define ET_EXEC 2 /* executable file */#define ET_DYN 3 /* shared object file */#define ET_CORE 4 /* core file */#define ET_NUM 5 /* number of types */#define ET_LOOS 0xfe00 /* reserved range for operating */#define ET_HIOS 0xfeff /* system specific e_type */#define ET_LOPROC 0xff00 /* reserved range for processor */#define ET_HIPROC 0xffff /* specific e_type *//* e_machine */#define EM_NONE 0 /* No Machine */#define EM_M32 1 /* AT&T WE 32100 */#define EM_SPARC 2 /* SPARC */#define EM_386 3 /* Intel 80386 */#define EM_68K 4 /* Motorola 68000 */#define EM_88K 5 /* Motorola 88000 */#if 0#define EM_486 6 /* RESERVED - was Intel 80486 */#endif#define EM_860 7 /* Intel 80860 */#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */#define EM_S370 9 /* IBM System/370 Processor */#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */#if 0#define EM_SPARC64 11 /* RESERVED - was SPARC v9 64-bit unoffical */#endif/* RESERVED 11-14 for future use */#define EM_PARISC 15 /* HPPA *//* RESERVED 16 for future use */#define EM_VPP500 17 /* Fujitsu VPP500 */#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */#define EM_960 19 /* Intel 80960 */#define EM_PPC 20 /* PowerPC */#define EM_PPC64 21 /* 64-bit PowerPC */#define EM_S390 22 /* IBM System/390 Processor *//* RESERVED 23-35 for future use */#define EM_V800 36 /* NEC V800 */#define EM_FR20 37 /* Fujitsu FR20 */#define EM_RH32 38 /* TRW RH-32 */#define EM_RCE 39 /* Motorola RCE */#define EM_ARM 40 /* Advanced Risc Machines ARM */#define EM_ALPHA 41 /* Digital Alpha */#define EM_SH 42 /* Hitachi SH */#define EM_SPARCV9 43 /* SPARC Version 9 */#define EM_TRICORE 44 /* Siemens TriCore embedded processor */#define EM_ARC 45 /* Argonaut RISC Core */#define EM_H8_300 46 /* Hitachi H8/300 */#define EM_H8_300H 47 /* Hitachi H8/300H */#define EM_H8S 48 /* Hitachi H8S */#define EM_H8_500 49 /* Hitachi H8/500 */#define EM_IA_64 50 /* Intel Merced */#define EM_MIPS_X 51 /* Stanford MIPS-X */#define EM_COLDFIRE 52 /* Motorola Coldfire */#define EM_68HC12 53 /* Motorola M68HC12 */#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/#define EM_PCP 55 /* Siemens PCP */#define EM_NCPU 56 /* Sony nCPU embeeded RISC */#define EM_NDR1 57 /* Denso NDR1 microprocessor */#define EM_STARCORE 58 /* Motorola Start*Core processor */#define EM_ME16 59 /* Toyota ME16 processor */#define EM_ST100 60 /* STMicroelectronic ST100 processor */#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/#define EM_X86_64 62 /* AMD x86-64 */#define EM_PDSP 63 /* Sony DSP Processor *//* RESERVED 64,65 for future use */#define EM_FX66 66 /* Siemens FX66 microcontroller */#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */#define EM_SVX 73 /* Silicon Graphics SVx */#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */#define EM_VAX 75 /* Digital VAX */#define EM_CHRIS 76 /* Axis Communications embedded proc. */#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */#define EM_HUANY 81 /* Harvard University mach-indep objs */#define EM_PRISM 82 /* SiTera Prism */#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */#define EM_FR30 84 /* Fujitsu FR30 */#define EM_D10V 85 /* Mitsubishi DV10V */#define EM_D30V 86 /* Mitsubishi DV30V */#define EM_V850 87 /* NEC v850 */#define EM_M32R 88 /* Mitsubishi M32R */#define EM_MN10300 89 /* Matsushita MN10200 */#define EM_MN10200 90 /* Matsushita MN10200 */#define EM_PJ 91 /* picoJava */#define EM_NUM 92 /* number of machine types *//* Version */#define EV_NONE 0 /* Invalid */#define EV_CURRENT 1 /* Current */#define EV_NUM 2 /* number of versions *//* Section Header */typedef struct { Elf32_Word sh_name; /* name - index into section header string table section */ Elf32_Word sh_type; /* type */ Elf32_Word sh_flags; /* flags */ Elf32_Addr sh_addr; /* address */ Elf32_Off sh_offset; /* file offset */ Elf32_Word sh_size; /* section size */ Elf32_Word sh_link; /* section header table index link */ Elf32_Word sh_info; /* extra information */ Elf32_Word sh_addralign; /* address alignment */ Elf32_Word sh_entsize; /* section entry size */} Elf32_Shdr;/* Special Section Indexes */#define SHN_UNDEF 0 /* undefined */#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */#define SHN_LOPROC 0xff00 /* reserved range for processor */#define SHN_HIPROC 0xff1f /* specific section indexes */#define SHN_LOOS 0xff20 /* reserved range for operating */#define SHN_HIOS 0xff3f /* specific semantics */#define SHN_ABS 0xfff1 /* absolute value */#define SHN_COMMON 0xfff2 /* common symbol */#define SHN_XINDEX 0xffff /* Index is an extra table */#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes *//* sh_type */#define SHT_NULL 0 /* inactive */#define SHT_PROGBITS 1 /* program defined information */#define SHT_SYMTAB 2 /* symbol table section */#define SHT_STRTAB 3 /* string table section */#define SHT_RELA 4 /* relocation section with addends*/#define SHT_HASH 5 /* symbol hash table section */#define SHT_DYNAMIC 6 /* dynamic section */#define SHT_NOTE 7 /* note section */#define SHT_NOBITS 8 /* no space section */#define SHT_REL 9 /* relation section without addends */#define SHT_SHLIB 10 /* reserved - purpose unknown */#define SHT_DYNSYM 11 /* dynamic symbol table section */#define SHT_INIT_ARRAY 14 /* Array of constructors */#define SHT_FINI_ARRAY 15 /* Array of destructors */#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */#define SHT_GROUP 17 /* Section group */#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */#define SHT_NUM 19 /* number of section types */#define SHT_LOOS 0x60000000 /* Start OS-specific */#define SHT_HIOS 0x6fffffff /* End OS-specific */#define SHT_LOPROC 0x70000000 /* reserved range for processor */#define SHT_HIPROC 0x7fffffff /* specific section header types */#define SHT_LOUSER 0x80000000 /* reserved range for application */#define SHT_HIUSER 0xffffffff /* specific indexes *//* Section names */#define ELF_BSS ".bss" /* uninitialized data */#define ELF_COMMENT ".comment" /* version control information */#define ELF_DATA ".data" /* initialized data */#define ELF_DATA1 ".data1" /* initialized data */#define ELF_DEBUG ".debug" /* debug */#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */#define ELF_DYNSTR ".dynstr" /* dynamic string table */#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */#define ELF_FINI ".fini" /* termination code */#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -