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

htelfimg.cc

Go to the documentation of this file.
00001 /*
00002  *      HT Editor
00003  *      htelfimg.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 "log.h"
00022 #include "htelfimg.h"
00023 #include "htpal.h"
00024 #include "htstring.h"
00025 #include "formats.h"
00026 #include "tools.h"
00027 
00028 #include "elfstruc.h"
00029 #include "elf_analy.h"
00030 
00031 static ht_view *htelfimage_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00032 {
00033         ht_elf_shared_data *elf_shared=(ht_elf_shared_data *)group->get_shared_data();
00034 
00035 //      if (elf_shared->ident.e_ident[ELF_EI_CLASS]!=ELFCLASS32) return 0;
00036 
00037         LOG("%s: ELF: loading image (starting analyser)...", file->get_filename());
00038         ElfAnalyser *p = new ElfAnalyser();
00039         p->init(elf_shared, file);
00040 
00041         bounds c=*b;
00042         ht_group *g=new ht_group();
00043         g->init(&c, VO_RESIZE, DESC_ELF_IMAGE"-g");
00044         AnalyInfoline *head;
00045 
00046         c.y+=2;
00047         c.h-=2;
00048         ht_elf_aviewer *v=new ht_elf_aviewer();
00049         v->init(&c, DESC_ELF_IMAGE, VC_EDIT | VC_GOTO | VC_SEARCH, file, group, p, elf_shared);
00050 
00051         c.y-=2;
00052         c.h=2;
00053         head=new AnalyInfoline();
00054         head->init(&c, v, ANALY_STATUS_DEFAULT);
00055 
00056         v->attachInfoline(head);
00057 
00058         /* find lowest/highest address */
00059         Address *low=NULL;
00060         Address *high=NULL;
00061         switch (elf_shared->ident.e_ident[ELF_EI_CLASS]) {
00062                 case ELFCLASS32: {
00063                         ELFAddress l, h;
00064                         l.a32 = (dword)-1;
00065                         h.a32 = 0;
00066                         ELF_SECTION_HEADER32 *s = elf_shared->sheaders.sheaders32;
00067                         for (UINT i=0; i<elf_shared->sheaders.count; i++) {
00068                                 if (elf_valid_section((elf_section_header*)s, elf_shared->ident.e_ident[ELF_EI_CLASS])) {
00069                                         if (s->sh_addr < l.a32) l.a32=s->sh_addr;
00070                                         if ((s->sh_addr + s->sh_size > h.a32) && s->sh_size) h.a32=s->sh_addr + s->sh_size - 1;
00071                                 }
00072                                 s++;
00073                         }
00074                         low = p->createAddress32(l.a32);
00075                         high = p->createAddress32(h.a32);
00076                         break;
00077                 }
00078                 case ELFCLASS64: {
00079                         ELFAddress l, h;
00080                         l.a64 = to_uint64(to_sint64(-1));
00081                         h.a64 = to_uint64(0);
00082                         ELF_SECTION_HEADER64 *s = elf_shared->sheaders.sheaders64;
00083                         for (UINT i=0; i<elf_shared->sheaders.count; i++) {
00084                                 if (elf_valid_section((elf_section_header*)s, elf_shared->ident.e_ident[ELF_EI_CLASS])) {
00085                                         if (s->sh_addr < l.a64) l.a64 = s->sh_addr;
00086                                         if ((s->sh_addr + s->sh_size > h.a64)
00087                                         && s->sh_size != to_qword(0)) {
00088                                                 h.a64 = s->sh_addr + s->sh_size - to_qword(1);
00089                                         }
00090                                 }
00091                                 s++;
00092                         }
00093                         low = p->createAddress64(l.a64);
00094                         high = p->createAddress64(h.a64);
00095                         break;
00096                 }
00097         }
00098 
00099         ht_analy_sub *analy=new ht_analy_sub();
00100 
00101         if (low->compareTo(high) < 0) {
00102                 analy->init(file, v, p, low, high);
00103                 v->analy_sub = analy;
00104                 v->insertsub(analy);
00105         } else {
00106                 delete analy;
00107                 v->done();
00108                 delete v;
00109                 head->done();          
00110                 delete head;
00111                 g->done();
00112                 delete g;
00113                 delete high;
00114                 delete low;
00115                 return NULL;
00116         }
00117         
00118         delete high;
00119         delete low;
00120 
00121         v->sendmsg(msg_complete_init, 0);
00122 
00123         Address *tmpaddr = NULL;
00124         switch (elf_shared->ident.e_ident[ELF_EI_CLASS]) {
00125                 case ELFCLASS32: {
00126                         tmpaddr = p->createAddress32(elf_shared->header32.e_entry);
00127                         break;
00128                 }
00129                 case ELFCLASS64: {
00130                         tmpaddr = p->createAddress64(elf_shared->header64.e_entry);
00131                         break;
00132                 }
00133         }
00134 
00135         v->gotoAddress(tmpaddr, NULL);
00136         delete tmpaddr;
00137 
00138         g->insert(head);
00139         g->insert(v);
00140 
00141         g->setpalette(palkey_generic_window_default);
00142 
00143         elf_shared->v_image=v;
00144         return g;
00145 }
00146 
00147 format_viewer_if htelfimage_if = {
00148         htelfimage_init,
00149         0
00150 };
00151 
00152 /*
00153  *      CLASS ht_elf_aviewer
00154  */
00155 void ht_elf_aviewer::init(bounds *b, char *desc, int caps, ht_streamfile *File, ht_format_group *format_group, Analyser *Analy, ht_elf_shared_data *ELF_shared)
00156 {
00157         ht_aviewer::init(b, desc, caps, File, format_group, Analy);
00158         elf_shared = ELF_shared;
00159 }
00160 
00161 void ht_elf_aviewer::setAnalyser(Analyser *a)
00162 {
00163         ((ElfAnalyser *)a)->elf_shared = elf_shared;
00164         ((ElfAnalyser *)a)->file = file;
00165         analy = a;
00166         analy_sub->setAnalyser(a);
00167 }

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