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 "htelfshs.h"
00025 #include "httag.h"
00026 #include "formats.h"
00027 #include "snprintf.h"
00028
00029 static ht_mask_ptable elfsectionheader32[]=
00030 {
00031 {"name string index", STATICTAG_EDIT_DWORD_VE("00000000")},
00032 {"type", STATICTAG_EDIT_DWORD_VE("00000004")" ("STATICTAG_DESC_DWORD_VE("00000004", ATOM_ELF_SH_TYPE_STR)")"},
00033 {"flags", STATICTAG_EDIT_DWORD_VE("00000008")" "STATICTAG_FLAGS("00000008", ATOM_ELF_SH_FLAGS_STR)},
00034 {"address", STATICTAG_EDIT_DWORD_VE("0000000c")},
00035 {"offset", STATICTAG_EDIT_DWORD_VE("00000010")},
00036 {"size", STATICTAG_EDIT_DWORD_VE("00000014")},
00037 {"link", STATICTAG_EDIT_DWORD_VE("00000018")},
00038 {"info", STATICTAG_EDIT_DWORD_VE("0000001c")},
00039 {"alignment", STATICTAG_EDIT_DWORD_VE("00000020")},
00040 {"entsize", STATICTAG_EDIT_DWORD_VE("00000024")},
00041 {0, 0}
00042 };
00043
00044 static ht_mask_ptable elfsectionheader64[]=
00045 {
00046 {"name string index", STATICTAG_EDIT_DWORD_VE("00000000")},
00047 {"type", STATICTAG_EDIT_DWORD_VE("00000004")" ("STATICTAG_DESC_DWORD_VE("00000004", ATOM_ELF_SH_TYPE_STR)")"},
00048 {"flags", STATICTAG_EDIT_QWORD_VE("00000008")" "STATICTAG_FLAGS("00000008", ATOM_ELF_SH_FLAGS_STR)},
00049 {"address", STATICTAG_EDIT_QWORD_VE("00000010")},
00050 {"offset", STATICTAG_EDIT_QWORD_VE("00000018")},
00051 {"size", STATICTAG_EDIT_QWORD_VE("00000020")},
00052 {"link", STATICTAG_EDIT_QWORD_VE("00000028")},
00053 {"info", STATICTAG_EDIT_QWORD_VE("00000030")},
00054 {"alignment", STATICTAG_EDIT_DWORD_VE("00000038")},
00055 {"entsize", STATICTAG_EDIT_DWORD_VE("0000003c")},
00056 {0, 0}
00057 };
00058
00059 static int_hash elf_sh_type[] =
00060 {
00061 {ELF_SHT_NULL, "null"},
00062 {ELF_SHT_PROGBITS, "progbits"},
00063 {ELF_SHT_SYMTAB, "symbol table"},
00064 {ELF_SHT_STRTAB, "string table"},
00065 {ELF_SHT_RELA, "relocation table + addends"},
00066 {ELF_SHT_HASH, "symbol hash table"},
00067 {ELF_SHT_DYNAMIC, "dynamic linking information"},
00068 {ELF_SHT_NOTE, "note"},
00069 {ELF_SHT_NOBITS, "nobits"},
00070 {ELF_SHT_REL, "relocation table"},
00071 {ELF_SHT_SHLIB, "shlib"},
00072 {ELF_SHT_DYNSYM, "dynamic linking symbol table"},
00073 {ELF_SHT_INIT_ARRAY, "init array"},
00074 {ELF_SHT_FINI_ARRAY, "fini array"},
00075 {ELF_SHT_PREINIT_ARRAY, "preinit array"},
00076 {0, 0}
00077 };
00078
00079 static ht_tag_flags_s elf_sh_flags[] =
00080 {
00081 {0, "[00] writable"},
00082 {1, "[01] alloc"},
00083 {2, "[02] executable"},
00084 {3, "[03] ???"},
00085 {4, "[04] merge"},
00086 {5, "[05] strings"},
00087 {6, "[06] info link"},
00088 {7, "[07] link order"},
00089 {8, "[08] OS non-conforming"},
00090 {0, 0}
00091 };
00092
00093 static ht_view *htelfsectionheaders_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00094 {
00095 ht_elf_shared_data *elf_shared=(ht_elf_shared_data *)group->get_shared_data();
00096
00097 ht_uformat_viewer *v = NULL;
00098 bool elf_bigendian = elf_shared->ident.e_ident[ELF_EI_DATA]==ELFDATA2MSB;
00099 if (elf_shared->ident.e_ident[ELF_EI_CLASS]==ELFCLASS32) {
00100 v=new ht_uformat_viewer();
00101 v->init(b, DESC_ELF_SECTION_HEADERS, VC_EDIT, file, group);
00102
00103 register_atom(ATOM_ELF_SH_TYPE, elf_sh_type);
00104 register_atom(ATOM_ELF_SH_FLAGS, elf_sh_flags);
00105
00106 FILEOFS h=elf_shared->header32.e_shoff;
00107
00108 ht_mask_sub *m=new ht_mask_sub();
00109 m->init(file, 0);
00110
00111 char info[128];
00112 ht_snprintf(info, sizeof info, "* ELF section headers at offset %08x", h);
00113
00114 m->add_mask(info);
00115
00116 v->insertsub(m);
00117
00118 elf_shared->shnames = (char**)malloc(elf_shared->sheaders.count * sizeof *elf_shared->shnames);
00119 FILEOFS so=elf_shared->sheaders.sheaders32[elf_shared->header32.e_shstrndx].sh_offset;
00120 for (UINT i=0; i<elf_shared->sheaders.count; i++) {
00121 char *s;
00122 if (file->seek(so+elf_shared->sheaders.sheaders32[i].sh_name)
00123 || !((s = fgetstrz(file)))) s = "?";
00124 char t[1024];
00125 ht_snprintf(t, sizeof t, "section %d: %s", i, s);
00126 elf_shared->shnames[i] = s;
00127
00128 ht_mask_sub *n = new ht_mask_sub();
00129 n->init(file, i);
00130
00131 n->add_staticmask_ptable(elfsectionheader32, h+i*elf_shared->header32.e_shentsize, elf_bigendian);
00132
00133 ht_collapsable_sub *cn = new ht_collapsable_sub();
00134 cn->init(file, n, 1, t, 1);
00135
00136 v->insertsub(cn);
00137 }
00138 } else if (elf_shared->ident.e_ident[ELF_EI_CLASS]==ELFCLASS64) {
00139 v = new ht_uformat_viewer();
00140 v->init(b, DESC_ELF_SECTION_HEADERS, VC_EDIT, file, group);
00141
00142 register_atom(ATOM_ELF_SH_TYPE, elf_sh_type);
00143 register_atom(ATOM_ELF_SH_FLAGS, elf_sh_flags);
00144
00145
00146 FILEOFS h = elf_shared->header64.e_shoff.lo;
00147
00148 ht_mask_sub *m=new ht_mask_sub();
00149 m->init(file, 0);
00150
00151 char info[128];
00152 ht_snprintf(info, sizeof info, "* ELF section headers at offset %08x", h);
00153
00154 m->add_mask(info);
00155
00156 v->insertsub(m);
00157
00158 elf_shared->shnames=(char**)malloc(elf_shared->sheaders.count * sizeof *elf_shared->shnames);
00159
00160 FILEOFS so=elf_shared->sheaders.sheaders64[elf_shared->header64.e_shstrndx].sh_offset.lo;
00161 for (UINT i=0; i<elf_shared->sheaders.count; i++) {
00162 char *s;
00163 if (file->seek(so+elf_shared->sheaders.sheaders64[i].sh_name)
00164 || !((s=fgetstrz(file)))) s = "?";
00165 char t[1024];
00166 ht_snprintf(t, sizeof t, "section %d: %s", i, s);
00167 elf_shared->shnames[i]=s;
00168
00169 ht_mask_sub *n=new ht_mask_sub();
00170 n->init(file, i);
00171
00172 n->add_staticmask_ptable(elfsectionheader64, h+i*elf_shared->header64.e_shentsize, elf_bigendian);
00173
00174 ht_collapsable_sub *cn=new ht_collapsable_sub();
00175 cn->init(file, n, 1, t, 1);
00176
00177 v->insertsub(cn);
00178 }
00179 }
00180
00181 return v;
00182 }
00183
00184 format_viewer_if htelfsectionheaders_if = {
00185 htelfsectionheaders_init,
00186 0
00187 };