00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "elfstruc.h"
00022 #include "htatom.h"
00023 #include "htelf.h"
00024 #include "htelfhd.h"
00025 #include "httag.h"
00026 #include "formats.h"
00027 #include "snprintf.h"
00028
00029 static ht_mask_ptable elfheader[]=
00030 {
00031 {"ident", 0},
00032 {" magic", STATICTAG_EDIT_BYTE("00000000")" "STATICTAG_EDIT_BYTE("00000001")" "STATICTAG_EDIT_BYTE("00000002")" "STATICTAG_EDIT_BYTE("00000003")" = "STATICTAG_EDIT_CHAR("00000000") STATICTAG_EDIT_CHAR("00000001") STATICTAG_EDIT_CHAR("00000002") STATICTAG_EDIT_CHAR("00000003")},
00033 {" class", STATICTAG_EDIT_BYTE("00000004")" ("STATICTAG_DESC_BYTE("00000004", ATOM_ELF_CLASS_STR)")"},
00034 {" data", STATICTAG_EDIT_BYTE("00000005")" ("STATICTAG_DESC_BYTE("00000005", ATOM_ELF_DATA_STR)")"},
00035 {" version", STATICTAG_EDIT_BYTE("00000006")},
00036 {" OS ABI", STATICTAG_EDIT_BYTE("00000007")" ("STATICTAG_DESC_BYTE("00000007", ATOM_ELF_OS_ABI_STR)")"},
00037 {" version", STATICTAG_EDIT_BYTE("00000008")},
00038 {" reserved", STATICTAG_EDIT_BYTE("00000009")" "STATICTAG_EDIT_BYTE("0000000a")" "STATICTAG_EDIT_BYTE("0000000b")" "STATICTAG_EDIT_BYTE("0000000c")" "STATICTAG_EDIT_BYTE("0000000d")" "STATICTAG_EDIT_BYTE("0000000e")" "STATICTAG_EDIT_BYTE("0000000f")},
00039 {0, 0}
00040 };
00041
00042 static ht_mask_ptable elfheader32[]=
00043 {
00044 {"type", STATICTAG_EDIT_WORD_VE("00000010")" ("STATICTAG_DESC_WORD_VE("00000010", ATOM_ELF_TYPE_STR)")"},
00045 {"machine", STATICTAG_EDIT_WORD_VE("00000012")" ("STATICTAG_DESC_WORD_VE("00000012", ATOM_ELF_MACHINE_STR)")"},
00046 {"version", STATICTAG_EDIT_DWORD_VE("00000014")},
00047 {"entrypoint", STATICTAG_EDIT_DWORD_VE("00000018")},
00048 {"program header offset", STATICTAG_EDIT_DWORD_VE("0000001c")},
00049 {"section header offset", STATICTAG_EDIT_DWORD_VE("00000020")},
00050 {"flags", STATICTAG_EDIT_DWORD_VE("00000024")},
00051 {"elf header size", STATICTAG_EDIT_WORD_VE("00000028")},
00052 {"program header entry size", STATICTAG_EDIT_WORD_VE("0000002a")},
00053 {"program header count", STATICTAG_EDIT_WORD_VE("0000002c")},
00054 {"section header entry size", STATICTAG_EDIT_WORD_VE("0000002e")},
00055 {"section header count", STATICTAG_EDIT_WORD_VE("00000030")},
00056 {"section header strtab section index",STATICTAG_EDIT_WORD_VE("00000032")},
00057 {0, 0}
00058 };
00059
00060 static ht_mask_ptable elfheader64[]=
00061 {
00062 {"type", STATICTAG_EDIT_WORD_VE("00000010")" ("STATICTAG_DESC_WORD_VE("00000010", ATOM_ELF_TYPE_STR)")"},
00063 {"machine", STATICTAG_EDIT_WORD_VE("00000012")" ("STATICTAG_DESC_WORD_VE("00000012", ATOM_ELF_MACHINE_STR)")"},
00064 {"version", STATICTAG_EDIT_DWORD_VE("00000014")},
00065 {"entrypoint", STATICTAG_EDIT_QWORD_VE("00000018")},
00066 {"program header offset", STATICTAG_EDIT_QWORD_VE("00000020")},
00067 {"section header offset", STATICTAG_EDIT_QWORD_VE("00000028")},
00068 {"flags", STATICTAG_EDIT_DWORD_VE("00000030")},
00069 {"elf header size", STATICTAG_EDIT_WORD_VE("00000034")},
00070 {"program header entry size", STATICTAG_EDIT_WORD_VE("00000036")},
00071 {"program header count", STATICTAG_EDIT_WORD_VE("00000038")},
00072 {"section header entry size", STATICTAG_EDIT_WORD_VE("0000003a")},
00073 {"section header count", STATICTAG_EDIT_WORD_VE("0000003c")},
00074 {"section header strtab section index",STATICTAG_EDIT_WORD_VE("0000003e")},
00075 {0, 0}
00076 };
00077
00078 static int_hash elf_class[] =
00079 {
00080 {ELFCLASSNONE, "invalid class type"},
00081 {ELFCLASS32, "32-bit objects"},
00082 {ELFCLASS64, "64-bit objects"},
00083 {0, 0}
00084 };
00085
00086 static int_hash elf_data[] =
00087 {
00088 {ELFDATANONE, "invalid data encoding"},
00089 {ELFDATA2LSB, "LSB encoding"},
00090 {ELFDATA2MSB, "MSB encoding"},
00091 {0, 0}
00092 };
00093
00094 static int_hash elf_os_abi[] =
00095 {
00096 {ELFOSABI_SYSV, "System V"},
00097 {ELFOSABI_HPUX, "HP-UX"},
00098 {ELFOSABI_LINUX, "Linux"},
00099 {ELFOSABI_NETBSD, "NetBSD"},
00100 {ELFOSABI_HURD, "GNU/Hurd"},
00101 {ELFOSABI_86OPEN, "86Open common IA32 ABI"},
00102 {ELFOSABI_SOLARIS, "Solaris"},
00103 {ELFOSABI_MONTEREY, "Monterey"},
00104 {ELFOSABI_IRIX, "IRIX"},
00105 {ELFOSABI_FREEBSD, "FreeBSD"},
00106 {ELFOSABI_TRU64, "TRU64 UNIX"},
00107 {ELFOSABI_MODESTO, "Novell Modesto"},
00108 {ELFOSABI_OPENBSD, "OpenBSD"},
00109 {ELFOSABI_ARM, "ARM"},
00110 {ELFOSABI_STANDALONE, "standalone"},
00111 {0, 0}
00112 };
00113
00114 static int_hash elf_type[] =
00115 {
00116 {ELF_ET_NONE, "no file type"},
00117 {ELF_ET_REL, "relocatable file"},
00118 {ELF_ET_EXEC, "executable file"},
00119 {ELF_ET_DYN, "shared object file"},
00120 {ELF_ET_CORE, "core file"},
00121 {0, 0}
00122 };
00123
00124 static int_hash elf_machine[] =
00125 {
00126 {ELF_EM_NONE, "no machine"},
00127 {ELF_EM_M32, "AT&T WE32100"},
00128 {ELF_EM_SPARC, "SPARC"},
00129 {ELF_EM_386, "Intel 80386"},
00130 {ELF_EM_68K, "Motorola 68000"},
00131 {ELF_EM_88K, "Motorola 88000"},
00132 {ELF_EM_486, "Intel 80486"},
00133 {ELF_EM_860, "Intel 80860"},
00134 {ELF_EM_MIPS, "MIPS R3000 big-endian"},
00135 {ELF_EM_S370, "IBM System/370"},
00136 {ELF_EM_MIPS_RS4_BE, "MIPS R4000 big-endian"},
00137
00138 {ELF_EM_PARISC, "HPPA"},
00139
00140 {ELF_EM_VPP550, "Fujitsu VPP500"},
00141 {ELF_EM_SPARC32PLUS, "Sun's \"v8plus\""},
00142 {ELF_EM_960, "Intel 80960"},
00143 {ELF_EM_PPC, "PowerPC"},
00144 {ELF_EM_PPC64, "64-bit PowerPC"},
00145
00146 {ELF_EM_V800, "NEC V800 series"},
00147 {ELF_EM_FR20, "Fujitsu FR20"},
00148 {ELF_EM_RH32, "TRW RH32"},
00149 {ELF_EM_MCORE, "Motorola M*Core"},
00150 {ELF_EM_ARM, "ARM"},
00151 {ELF_EM_OLD_ALPHA, "Digital Alpha"},
00152 {ELF_EM_SH, "Hitachi SH"},
00153 {ELF_EM_SPARCV9, "SPARC v9 64-bit"},
00154 {ELF_EM_TRICORE, "Siemens Tricore embedded processor"},
00155 {ELF_EM_ARC, "Argonaut RISC Core, Argonaut Technologies Inc."},
00156 {ELF_EM_H8_300, "Hitachi H8/300"},
00157 {ELF_EM_H8_300H, "Hitachi H8/300H"},
00158 {ELF_EM_H8S, "Hitachi H8S"},
00159 {ELF_EM_H8_500, "Hitachi H8/500"},
00160 {ELF_EM_IA_64, "Intel IA-64 Processor"},
00161 {ELF_EM_MIPS_X, "Stanford MIPS-X"},
00162 {ELF_EM_COLDFIRE, "Motorola Coldfire"},
00163 {ELF_EM_68HC12, "Motorola M68HC12"},
00164 {ELF_EM_MMA, "Fujitsu Multimedia Accelerator"},
00165 {ELF_EM_PCP, "Siemens PCP"},
00166 {ELF_EM_NCPU, "Sony nCPU embedded RISC processor"},
00167 {ELF_EM_NDR1, "Denso NDR1 microprocesspr"},
00168 {ELF_EM_STARCORE, "Motorola Star*Core processor"},
00169 {ELF_EM_ME16, "Toyota ME16 processor"},
00170 {ELF_EM_ST100, "STMicroelectronics ST100 processor"},
00171 {ELF_EM_TINYJ, "Advanced Logic Corp. TinyJ embedded processor"},
00172 {ELF_EM_X86_64, "x86-64 (AMD Opteron)"},
00173
00174 {ELF_EM_FX66, "Siemens FX66 microcontroller"},
00175 {ELF_EM_ST9PLUS, "STMicroelectronics ST9+ 8/16 bit microcontroller"},
00176 {ELF_EM_ST7, "STMicroelectronics ST7 8-bit microcontroller"},
00177 {ELF_EM_68HC16, "Motorola MC68HC16 Microcontroller"},
00178 {ELF_EM_68HC11, "Motorola MC68HC11 Microcontroller"},
00179 {ELF_EM_68HC08, "Motorola MC68HC08 Microcontroller"},
00180 {ELF_EM_68HC05, "Motorola MC68HC05 Microcontroller"},
00181 {ELF_EM_SVX, "Silicon Graphics SVx"},
00182 {ELF_EM_ST19, "STMicroelectronics ST19 8-bit microcontroller"},
00183 {ELF_EM_VAX, "Digital VAX"},
00184
00185 {ELF_EM_PJ, "picoJava"},
00186 {0, 0}
00187 };
00188
00189 ht_view *htelfheader_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00190 {
00191 ht_elf_shared_data *elf_shared=(ht_elf_shared_data *)group->get_shared_data();
00192
00193 ht_uformat_viewer *v=new ht_uformat_viewer();
00194 v->init(b, DESC_ELF_HEADER, VC_EDIT, file, group);
00195 ht_mask_sub *m=new ht_mask_sub();
00196 m->init(file, 0);
00197 char info[128];
00198 ht_snprintf(info, sizeof info, "* ELF header at offset %08x", elf_shared->header_ofs);
00199 register_atom(ATOM_ELF_CLASS, elf_class);
00200 register_atom(ATOM_ELF_DATA, elf_data);
00201 register_atom(ATOM_ELF_OS_ABI, elf_os_abi);
00202 register_atom(ATOM_ELF_TYPE, elf_type);
00203 register_atom(ATOM_ELF_MACHINE, elf_machine);
00204 m->add_mask(info);
00205 m->add_staticmask_ptable(elfheader, elf_shared->header_ofs, true);
00206 bool elf_bigendian = (elf_shared->ident.e_ident[ELF_EI_DATA] == ELFDATA2MSB);
00207
00208 switch (elf_shared->ident.e_ident[ELF_EI_CLASS]) {
00209 case ELFCLASS32:
00210 m->add_staticmask_ptable(elfheader32, elf_shared->header_ofs, elf_bigendian);
00211 break;
00212 case ELFCLASS64:
00213 m->add_staticmask_ptable(elfheader64, elf_shared->header_ofs, elf_bigendian);
00214 break;
00215 }
00216
00217 v->insertsub(m);
00218 return v;
00219 }
00220
00221 format_viewer_if htelfheader_if = {
00222 htelfheader_init,
00223 0
00224 };