📄 elfstructs.h
字号:
#define ELF_SYMTAB ".symtab" /* symbol table */#define ELF_TEXT ".text" /* code *//* Section Attribute Flags - sh_flags */#define SHF_WRITE 0x1 /* Writable */#define SHF_ALLOC 0x2 /* occupies memory */#define SHF_EXECINSTR 0x4 /* executable */#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ /* specific section attributes *//* Symbol Table Entry */typedef struct elf32_sym { Elf32_Word st_name; /* name - index into string table */ Elf32_Addr st_value; /* symbol value */ Elf32_Word st_size; /* symbol size */ unsigned char st_info; /* type and binding */ unsigned char st_other; /* 0 - no defined meaning */ Elf32_Half st_shndx; /* section header index */} Elf32_Sym;typedef struct { Elf64_Half st_name; /* Symbol name index in str table */ Elf_Byte st_info; /* type / binding attrs */ Elf_Byte st_other; /* unused */ Elf64_Quarter st_shndx; /* section index of symbol */ Elf64_Xword st_value; /* value of symbol */ Elf64_Xword st_size; /* size of symbol */} Elf64_Sym;/* Symbol table index */#define STN_UNDEF 0 /* undefined *//* Extract symbol info - st_info */#define ELF32_ST_BIND(x) ((x) >> 4)#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))#define ELF64_ST_BIND(x) ((x) >> 4)#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf)#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))/* Symbol Binding - ELF32_ST_BIND - st_info */#define STB_LOCAL 0 /* Local symbol */#define STB_GLOBAL 1 /* Global symbol */#define STB_WEAK 2 /* like global - lower precedence */#define STB_NUM 3 /* number of symbol bindings */#define STB_LOPROC 13 /* reserved range for processor */#define STB_HIPROC 15 /* specific symbol bindings *//* Symbol type - ELF32_ST_TYPE - st_info */#define STT_NOTYPE 0 /* not specified */#define STT_OBJECT 1 /* data object */#define STT_FUNC 2 /* function */#define STT_SECTION 3 /* section */#define STT_FILE 4 /* file */#define STT_NUM 5 /* number of symbol types */#define STT_LOPROC 13 /* reserved range for processor */#define STT_HIPROC 15 /* specific symbol types *//* Relocation entry with implicit addend */typedef struct { Elf32_Addr r_offset; /* offset of relocation */ Elf32_Word r_info; /* symbol table index and type */} Elf32_Rel;/* Relocation entry with explicit addend */typedef struct { Elf32_Addr r_offset; /* offset of relocation */ Elf32_Word r_info; /* symbol table index and type */ Elf32_Sword r_addend;} Elf32_Rela;/* Extract relocation info - r_info */#define ELF32_R_SYM(i) ((i) >> 8)#define ELF32_R_TYPE(i) ((unsigned char) (i))#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))typedef struct { Elf64_Xword r_offset; /* where to do it */ Elf64_Xword r_info; /* index & type of relocation */} Elf64_Rel;typedef struct { Elf64_Xword r_offset; /* where to do it */ Elf64_Xword r_info; /* index & type of relocation */ Elf64_Sxword r_addend; /* adjustment value */} Elf64_Rela;#define ELF64_R_SYM(info) ((info) >> 32)#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF)#define ELF64_R_INFO(s,t) (((s) << 32) + (u_int32_t)(t))/* Program Header */typedef struct { Elf32_Word p_type; /* segment type */ Elf32_Off p_offset; /* segment offset */ Elf32_Addr p_vaddr; /* virtual address of segment */ Elf32_Addr p_paddr; /* physical address - ignored? */ Elf32_Word p_filesz; /* number of bytes in file for seg. */ Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ Elf32_Word p_flags; /* flags */ Elf32_Word p_align; /* memory alignment */} Elf32_Phdr;typedef struct { Elf64_Half p_type; /* entry type */ Elf64_Half p_flags; /* flags */ Elf64_Off p_offset; /* offset */ Elf64_Addr p_vaddr; /* virtual address */ Elf64_Addr p_paddr; /* physical address */ Elf64_Xword p_filesz; /* file size */ Elf64_Xword p_memsz; /* memory size */ Elf64_Xword p_align; /* memory & file alignment */} Elf64_Phdr;/* Segment types - p_type */#define PT_NULL 0 /* unused */#define PT_LOAD 1 /* loadable segment */#define PT_DYNAMIC 2 /* dynamic linking section */#define PT_INTERP 3 /* the RTLD */#define PT_NOTE 4 /* auxiliary information */#define PT_SHLIB 5 /* reserved - purpose undefined */#define PT_PHDR 6 /* program header */#define PT_NUM 7 /* Number of segment types */#define PT_LOPROC 0x70000000 /* reserved range for processor */#define PT_HIPROC 0x7fffffff /* specific segment types *//* Segment flags - p_flags */#define PF_X 0x1 /* Executable */#define PF_W 0x2 /* Writable */#define PF_R 0x4 /* Readable */#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ /* specific segment flags *//* Dynamic structure */typedef struct { Elf32_Sword d_tag; /* controls meaning of d_val */ union { Elf32_Word d_val; /* Multiple meanings - see d_tag */ Elf32_Addr d_ptr; /* program virtual address */ } d_un;} Elf32_Dyn;typedef struct { Elf64_Xword d_tag; /* controls meaning of d_val */ union { Elf64_Addr d_ptr; Elf64_Xword d_val; } d_un;} Elf64_Dyn;/* Dynamic Array Tags - d_tag */#define DT_NULL 0 /* marks end of _DYNAMIC array */#define DT_NEEDED 1 /* string table offset of needed lib */#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */#define DT_PLTGOT 3 /* address PLT/GOT */#define DT_HASH 4 /* address of symbol hash table */#define DT_STRTAB 5 /* address of string table */#define DT_SYMTAB 6 /* address of symbol table */#define DT_RELA 7 /* address of relocation table */#define DT_RELASZ 8 /* size of relocation table */#define DT_RELAENT 9 /* size of relocation entry */#define DT_STRSZ 10 /* size of string table */#define DT_SYMENT 11 /* size of symbol table entry */#define DT_INIT 12 /* address of initialization func. */#define DT_FINI 13 /* address of termination function */#define DT_SONAME 14 /* string table offset of shared obj */#define DT_RPATH 15 /* string table offset of library search path */#define DT_SYMBOLIC 16 /* start sym search in shared obj. */#define DT_REL 17 /* address of rel. tbl. w addends */#define DT_RELSZ 18 /* size of DT_REL relocation table */#define DT_RELENT 19 /* size of DT_REL relocation entry */#define DT_PLTREL 20 /* PLT referenced relocation entry */#define DT_DEBUG 21 /* bugger */#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */#define DT_JMPREL 23 /* add. of PLT's relocation entries */#define DT_BIND_NOW 24 /* Bind now regardless of env setting */#define DT_NUM 25 /* Number used. */#define DT_LOPROC 0x70000000 /* reserved range for processor */#define DT_HIPROC 0x7fffffff /* specific dynamic array tags *//* Standard ELF hashing function */unsigned int elf_hash(const unsigned char *name);/* * Note Definitions */typedef struct { Elf32_Word namesz; Elf32_Word descsz; Elf32_Word type;} Elf32_Note;typedef struct { Elf64_Half namesz; Elf64_Half descsz; Elf64_Half type;} Elf64_Note;#if defined(ELFSIZE)#define CONCAT(x,y) __CONCAT(x,y)#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE))#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))#endif#if defined(ELFSIZE) && (ELFSIZE == 32)#define Elf_Ehdr Elf32_Ehdr#define Elf_Phdr Elf32_Phdr#define Elf_Shdr Elf32_Shdr#define Elf_Sym Elf32_Sym#define Elf_Rel Elf32_Rel#define Elf_RelA Elf32_Rela#define Elf_Dyn Elf32_Dyn#define Elf_Word Elf32_Word#define Elf_Sword Elf32_Sword#define Elf_Addr Elf32_Addr#define Elf_Off Elf32_Off#define Elf_Nhdr Elf32_Nhdr#define Elf_Note Elf32_Note#define ELF_R_SYM ELF32_R_SYM#define ELF_R_TYPE ELF32_R_TYPE#define ELF_R_INFO ELF32_R_INFO#define ELFCLASS ELFCLASS32#define ELF_ST_BIND ELF32_ST_BIND#define ELF_ST_TYPE ELF32_ST_TYPE#define ELF_ST_INFO ELF32_ST_INFO#define AuxInfo Aux32Info#elif defined(ELFSIZE) && (ELFSIZE == 64)#define Elf_Ehdr Elf64_Ehdr#define Elf_Phdr Elf64_Phdr#define Elf_Shdr Elf64_Shdr#define Elf_Sym Elf64_Sym#define Elf_Rel Elf64_Rel#define Elf_RelA Elf64_Rela#define Elf_Dyn Elf64_Dyn#define Elf_Word Elf64_Word#define Elf_Sword Elf64_Sword#define Elf_Addr Elf64_Addr#define Elf_Off Elf64_Off#define Elf_Nhdr Elf64_Nhdr#define Elf_Note Elf64_Note#define ELF_R_SYM ELF64_R_SYM#define ELF_R_TYPE ELF64_R_TYPE#define ELF_R_INFO ELF64_R_INFO#define ELFCLASS ELFCLASS64#define ELF_ST_BIND ELF64_ST_BIND#define ELF_ST_TYPE ELF64_ST_TYPE#define ELF_ST_INFO ELF64_ST_INFO#define AuxInfo Aux64Info#endif#endif /* __XEN_PUBLIC_ELFSTRUCTS_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -