00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "log.h"
00022 #include "htnewexe.h"
00023 #include "htpal.h"
00024 #include "htcoffimg.h"
00025 #include "htstring.h"
00026 #include "formats.h"
00027
00028 #include "coff_s.h"
00029
00030 #include "htanaly.h"
00031 #include "coff_analy.h"
00032
00033 static ht_view *htcoffimage_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00034 {
00035 ht_coff_shared_data *coff_shared = (ht_coff_shared_data *)group->get_shared_data();
00036
00037 LOG("%s: COFF: loading image (starting analyser)...", file->get_filename());
00038 CoffAnalyser *p = new CoffAnalyser();
00039 p->init(coff_shared, file);
00040
00041 bounds c = *b;
00042 ht_group *g = new ht_group();
00043 g->init(&c, VO_RESIZE, DESC_COFF_IMAGE"-g");
00044 AnalyInfoline *head;
00045
00046 c.y+=2;
00047 c.h-=2;
00048 ht_coff_aviewer *v=new ht_coff_aviewer();
00049 v->init(&c, DESC_COFF_IMAGE, VC_EDIT | VC_GOTO | VC_SEARCH, file, group, p, coff_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
00059 RVA l=(RVA)-1, h=0;
00060 COFF_SECTION_HEADER *s=coff_shared->sections.sections;
00061 for (UINT i=0; i<coff_shared->sections.section_count; i++) {
00062 if (s->data_address < l) l = s->data_address;
00063 if ((s->data_address + s->data_size > h) && s->data_size) {
00064 h = s->data_address + s->data_size - 1;
00065 }
00066 s++;
00067 }
00068
00069 Address *low = p->createAddress32(l);
00070 Address *high = p->createAddress32(h);
00071
00072 ht_analy_sub *analy=new ht_analy_sub();
00073 analy->init(file, v, p, low, high);
00074 v->analy_sub = analy;
00075 v->insertsub(analy);
00076
00077 delete high;
00078 delete low;
00079
00080 v->sendmsg(msg_complete_init, 0);
00081
00082
00083 switch (coff_shared->opt_magic) {
00084 case COFF_OPTMAGIC_COFF32:
00085 Address *tmpaddr = p->createAddress32(coff_shared->coff32header.entrypoint_address);
00086 v->gotoAddress(tmpaddr, NULL);
00087 delete tmpaddr;
00088 break;
00089 }
00090
00091
00092 g->insert(head);
00093 g->insert(v);
00094
00095 g->setpalette(palkey_generic_window_default);
00096
00097 coff_shared->v_image=v;
00098 return g;
00099 }
00100
00101 format_viewer_if htcoffimage_if = {
00102 htcoffimage_init,
00103 0
00104 };
00105
00106
00107
00108
00109
00110 void ht_coff_aviewer::init(bounds *b, char *desc, int caps, ht_streamfile *File, ht_format_group *format_group, Analyser *Analy, ht_coff_shared_data *Coff_shared)
00111 {
00112 ht_aviewer::init(b, desc, caps, File, format_group, Analy);
00113 coff_shared = Coff_shared;
00114 file = File;
00115 }
00116
00117 void ht_coff_aviewer::setAnalyser(Analyser *a)
00118 {
00119 ((CoffAnalyser *)a)->coff_shared = coff_shared;
00120 ((CoffAnalyser *)a)->file = file;
00121 analy = a;
00122 analy_sub->setAnalyser(a);
00123 }