00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __HTELF_H__
00022 #define __HTELF_H__
00023
00024 #include "elfstruc.h"
00025 #include "formats.h"
00026 #include "htendian.h"
00027 #include "htformat.h"
00028 #include "relfile.h"
00029
00030 #define DESC_ELF "elf - unix exe/link format"
00031 #define DESC_ELF_HEADER "elf/header"
00032 #define DESC_ELF_SECTION_HEADERS "elf/section headers"
00033 #define DESC_ELF_PROGRAM_HEADERS "elf/program headers"
00034 #define DESC_ELF_SYMTAB "elf/symbol table %s (%d)"
00035 #define DESC_ELF_RELOCTAB "elf/relocation table %s (%d)"
00036 #define DESC_ELF_IMAGE "elf/image"
00037
00038 #define ATOM_ELF_CLASS 0x454c4600
00039 #define ATOM_ELF_CLASS_STR "454c4600"
00040
00041 #define ATOM_ELF_DATA 0x454c4601
00042 #define ATOM_ELF_DATA_STR "454c4601"
00043
00044 #define ATOM_ELF_OS_ABI 0x454c4602
00045 #define ATOM_ELF_OS_ABI_STR "454c4602"
00046
00047 #define ATOM_ELF_TYPE 0x454c4603
00048 #define ATOM_ELF_TYPE_STR "454c4603"
00049
00050 #define ATOM_ELF_MACHINE 0x454c4604
00051 #define ATOM_ELF_MACHINE_STR "454c4604"
00052
00053 #define ATOM_ELF_SH_TYPE 0x454c4605
00054 #define ATOM_ELF_SH_TYPE_STR "454c4605"
00055
00056 #define ATOM_ELF_SH_FLAGS 0x454c4606
00057 #define ATOM_ELF_SH_FLAGS_STR "454c4606"
00058
00059 #define ATOM_ELF_PH_TYPE 0x454c4607
00060 #define ATOM_ELF_PH_TYPE_STR "454c4607"
00061
00062 #define ATOM_ELF_PH_FLAGS 0x454c4608
00063 #define ATOM_ELF_PH_FLAGS_STR "454c4608"
00064
00065 #define ATOM_ELF_ST_BIND 0x454c4609
00066 #define ATOM_ELF_ST_BIND_STR "454c4609"
00067
00068 #define ATOM_ELF_ST_TYPE 0x454c460a
00069 #define ATOM_ELF_ST_TYPE_STR "454c460a"
00070
00071 #define ATOM_ELF_R_386_TYPE 0x454c460b
00072 #define ATOM_ELF_R_386_TYPE_STR "454c460b"
00073
00074 extern format_viewer_if htelf_if;
00075
00076 class sectionAndIdx: public Object {
00077 public:
00078 uint secidx;
00079 uint symidx;
00080
00081 sectionAndIdx(uint asecidx, uint asymidx)
00082 {
00083 secidx = asecidx;
00084 symidx = asymidx;
00085 }
00086 };
00087
00088 struct elf_section_headers {
00089 uint count;
00090 union {
00091 ELF_SECTION_HEADER32 *sheaders32;
00092 ELF_SECTION_HEADER64 *sheaders64;
00093 };
00094 };
00095
00096 union elf_section_header {
00097 ELF_SECTION_HEADER32 sheaders32;
00098 ELF_SECTION_HEADER64 sheaders64;
00099 };
00100
00101 struct elf_program_headers {
00102 uint count;
00103 union {
00104 ELF_PROGRAM_HEADER32 *pheaders32;
00105 ELF_PROGRAM_HEADER64 *pheaders64;
00106 };
00107 };
00108
00109 struct ht_elf_reloc_section32 {
00110 elf32_addr relocAddr;
00111 uint relocShIdx;
00112 };
00113
00114 struct ht_elf_shared_data {
00115 FILEOFS header_ofs;
00116 ELF_HEADER ident;
00117 endianess byte_order;
00118 union {
00119 ELF_HEADER32 header32;
00120 ELF_HEADER64 header64;
00121 };
00122 elf_section_headers sheaders;
00123 ht_elf_reloc_section32 *shrelocs;
00124 char **shnames;
00125 elf_program_headers pheaders;
00126 uint symtables;
00127 uint reloctables;
00128 ht_format_viewer *v_image;
00129 int fake_undefined_shidx;
00130 uint fake_undefined_size;
00131 ht_tree *undefined2fakeaddr;
00132 };
00133
00134
00135
00136
00137 class ht_elf: public ht_format_group {
00138 protected:
00139 bool loc_enum;
00140
00141 void auto_relocate32();
00142 void fake_undefined_symbols32();
00143 uint find_reloc_section_for(UINT si);
00144 void relocate_section(ht_reloc_file *f, uint si, uint rsi, elf32_addr a);
00145 public:
00146 void init(bounds *b, ht_streamfile *file, format_viewer_if **ifs, ht_format_group *format_group, FILEOFS header_ofs);
00147 virtual void done();
00148
00149 virtual void loc_enum_start();
00150 virtual bool loc_enum_next(ht_format_loc *loc);
00151 };
00152
00153
00154
00155
00156
00157 class ht_elf32_reloc_entry: public Object {
00158 public:
00159 uint type;
00160 union {
00161 uint32 r_32;
00162 uint32 r_pc32;
00163 } relocs;
00164
00165 ht_elf32_reloc_entry(uint type, uint32 A, uint32 P, uint32 S);
00166 };
00167
00168
00169
00170
00171
00172 class ht_elf32_reloc_file: public ht_reloc_file {
00173 protected:
00174 ht_elf_shared_data *data;
00175
00176 virtual void reloc_apply(Object *reloc, byte *data);
00177 virtual bool reloc_unapply(Object *reloc, byte *data);
00178 public:
00179 void init(ht_streamfile *streamfile, bool own_streamfile, ht_elf_shared_data *data);
00180 };
00181
00182 bool isValidELFSectionIdx(ht_elf_shared_data *elf_shared, int idx);
00183
00184 bool elf_phys_and_mem_section(elf_section_header *s, UINT elfclass);
00185 bool elf_valid_section(elf_section_header *s, UINT elfclass);
00186
00187 bool elf_addr_to_section(elf_section_headers *section_headers, UINT elfclass, ELFAddress addr, int *section);
00188 bool elf_addr_to_ofs(elf_section_headers *section_headers, UINT elfclass, ELFAddress addr, dword *ofs);
00189 bool elf_addr_is_valid(elf_section_headers *section_headers, UINT elfclass, ELFAddress addr);
00190
00191 bool elf_ofs_to_addr(elf_section_headers *section_headers, UINT elfclass, dword ofs, ELFAddress *addr);
00192 bool elf_ofs_to_section(elf_section_headers *section_headers, UINT elfclass, dword ofs, dword *section);
00193
00194 #endif