Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

htelfphs.cc

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      htelfphs.cc
00004  *
00005  *      Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include "elfstruc.h"
00022 #include "htatom.h"
00023 #include "htelf.h"
00024 #include "htelfphs.h"
00025 #include "httag.h"
00026 #include "formats.h"
00027 #include "snprintf.h"
00028 
00029 static ht_mask_ptable elfprogramheader32[]=
00030 {
00031         {"type",                STATICTAG_EDIT_DWORD_VE("00000000")" ("STATICTAG_DESC_DWORD_VE("00000000", ATOM_ELF_PH_TYPE_STR)")"},
00032         {"offset",              STATICTAG_EDIT_DWORD_VE("00000004")},
00033         {"virtual address",     STATICTAG_EDIT_DWORD_VE("00000008")},
00034         {"physical address",    STATICTAG_EDIT_DWORD_VE("0000000c")},
00035         {"in file size",        STATICTAG_EDIT_DWORD_VE("00000010")},
00036         {"in memory size",      STATICTAG_EDIT_DWORD_VE("00000014")},
00037         {"flags",               STATICTAG_EDIT_DWORD_VE("00000018")" "STATICTAG_FLAGS("00000018", ATOM_ELF_PH_FLAGS_STR)},
00038         {"alignment",           STATICTAG_EDIT_DWORD_VE("0000001c")},
00039         {0, 0}
00040 };
00041 
00042 static ht_mask_ptable elfprogramheader64[]=
00043 {
00044         {"type",                STATICTAG_EDIT_DWORD_VE("00000000")" ("STATICTAG_DESC_DWORD_VE("00000000", ATOM_ELF_PH_TYPE_STR)")"},
00045         {"flags",               STATICTAG_EDIT_DWORD_VE("00000004")" "STATICTAG_FLAGS("00000004", ATOM_ELF_PH_FLAGS_STR)},
00046         {"offset",              STATICTAG_EDIT_QWORD_VE("00000008")},
00047         {"virtual address",     STATICTAG_EDIT_QWORD_VE("00000010")},
00048         {"physical address",    STATICTAG_EDIT_QWORD_VE("00000018")},
00049         {"in file size",        STATICTAG_EDIT_QWORD_VE("00000020")},
00050         {"in memory size",      STATICTAG_EDIT_QWORD_VE("00000028")},
00051         {"alignment",           STATICTAG_EDIT_QWORD_VE("00000030")},
00052         {0, 0}
00053 };
00054 
00055 static int_hash elf_ph_type[] =
00056 {
00057         {ELF_PT_NULL,           "null"},
00058         {ELF_PT_LOAD,           "load"},
00059         {ELF_PT_DYNAMIC,        "dynamic"},
00060         {ELF_PT_INTERP,         "interp"},
00061         {ELF_PT_NOTE,           "note"},
00062         {ELF_PT_SHLIB,          "shlib"},
00063         {ELF_PT_PHDR,           "phdr"},
00064         {0, 0}
00065 };
00066 
00067 static ht_tag_flags_s elf_ph_flags[] =
00068 {
00069         {0,  "[00] executable"},
00070         {1,  "[01] writable"},
00071         {2,  "[02] readable"},
00072         {0, 0}
00073 };
00074 
00075 static ht_view *htelfprogramheaders_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00076 {
00077         ht_elf_shared_data *elf_shared=(ht_elf_shared_data *)group->get_shared_data();
00078 
00079         bool elf_bigendian = (elf_shared->ident.e_ident[ELF_EI_DATA] == ELFDATA2MSB);
00080         ht_uformat_viewer *v = NULL;
00081         if (elf_shared->ident.e_ident[ELF_EI_CLASS]==ELFCLASS32) {
00082                 v = new ht_uformat_viewer();
00083                 v->init(b, DESC_ELF_PROGRAM_HEADERS, VC_EDIT, file, group);
00084         
00085                 register_atom(ATOM_ELF_PH_TYPE, elf_ph_type);
00086                 register_atom(ATOM_ELF_PH_FLAGS, elf_ph_flags);
00087         
00088                 FILEOFS h=elf_shared->header32.e_phoff;
00089         
00090                 ht_mask_sub *m=new ht_mask_sub();
00091                 m->init(file, 0);
00092         
00093                 char info[128];
00094                 ht_snprintf(info, sizeof info, "* ELF program headers at offset %08x", h);
00095         
00096                 m->add_mask(info);
00097 
00098                 v->insertsub(m);
00099                 for (UINT i=0; i<elf_shared->pheaders.count; i++) {
00100                 
00101                         ht_mask_sub *n=new ht_mask_sub();
00102                         n->init(file, i);
00103                 
00104                         char t[32];
00105                         char *etype=matchhash(elf_shared->pheaders.pheaders32[i].p_type, elf_ph_type);
00106                         if (!etype) etype="?";
00107                         ht_snprintf(t, sizeof t, "entry %d (%s)", i, etype);
00108                 
00109                         n->add_staticmask_ptable(elfprogramheader32, h+i*elf_shared->header32.e_phentsize, elf_bigendian);
00110                 
00111                         ht_collapsable_sub *cn=new ht_collapsable_sub();
00112                         cn->init(file, n, 1, t, 1);
00113         
00114                         v->insertsub(cn);
00115                 }
00116         } else if (elf_shared->ident.e_ident[ELF_EI_CLASS]==ELFCLASS64) {
00117                 v = new ht_uformat_viewer();
00118                 v->init(b, DESC_ELF_PROGRAM_HEADERS, VC_EDIT, file, group);
00119         
00120                 register_atom(ATOM_ELF_PH_TYPE, elf_ph_type);
00121                 register_atom(ATOM_ELF_PH_FLAGS, elf_ph_flags);
00122 
00123 /* FIXME: 64-bit */
00124                 FILEOFS h=elf_shared->header64.e_phoff.lo;
00125         
00126                 ht_mask_sub *m=new ht_mask_sub();
00127                 m->init(file, 0);
00128         
00129                 char info[128];
00130                 ht_snprintf(info, sizeof info, "* ELF program headers at offset %08x", h);
00131         
00132                 m->add_mask(info);
00133 
00134                 v->insertsub(m);
00135                 for (UINT i=0; i<elf_shared->pheaders.count; i++) {
00136                 
00137                         ht_mask_sub *n=new ht_mask_sub();
00138                         n->init(file, i);
00139                 
00140                         char t[32];
00141                         char *etype=matchhash(elf_shared->pheaders.pheaders64[i].p_type, elf_ph_type);
00142                         if (!etype) etype="?";
00143                         ht_snprintf(t, sizeof t, "entry %d (%s)", i, etype);
00144                 
00145                         n->add_staticmask_ptable(elfprogramheader64, h+i*elf_shared->header64.e_phentsize, elf_bigendian);
00146                 
00147                         ht_collapsable_sub *cn=new ht_collapsable_sub();
00148                         cn->init(file, n, 1, t, 1);
00149         
00150                         v->insertsub(cn);
00151                 }
00152         }
00153         
00154         return v;
00155 }
00156 
00157 format_viewer_if htelfprogramheaders_if = {
00158         htelfprogramheaders_init,
00159         0
00160 };

Generated on Fri May 7 21:15:33 2004 by doxygen 1.3.5