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 "htneimg.h"
00025 #include "htstring.h"
00026 #include "formats.h"
00027 #include "tools.h"
00028
00029 #include "nestruct.h"
00030
00031 #include "htanaly.h"
00032 #include "ne_analy.h"
00033
00034 static ht_view *htneimage_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00035 {
00036 ht_ne_shared_data *ne_shared=(ht_ne_shared_data *)group->get_shared_data();
00037
00038 LOG("%s: NE: loading image (starting analyser)...", file->get_filename());
00039 NEAnalyser *p = new NEAnalyser();
00040 p->init(ne_shared, file);
00041
00042 bounds c=*b;
00043 ht_group *g=new ht_group();
00044 g->init(&c, VO_RESIZE, DESC_NE_IMAGE"-g");
00045 AnalyInfoline *head;
00046
00047 c.y += 2;
00048 c.h -= 2;
00049 ht_ne_aviewer *v=new ht_ne_aviewer();
00050 v->init(&c, DESC_NE_IMAGE, VC_EDIT | VC_GOTO | VC_SEARCH, file, group, p, ne_shared);
00051
00052 c.y-=2;
00053 c.h=2;
00054 head=new AnalyInfoline();
00055 head->init(&c, v, ANALY_STATUS_DEFAULT);
00056
00057 v->attachInfoline(head);
00058
00059
00060 NEAddress l=(NEAddress)-1, h=0;
00061 NE_SEGMENT *s = ne_shared->segments.segments;
00062 for (UINT i=0; i<ne_shared->segments.segment_count; i++) {
00063 NEAddress base = NE_MAKE_ADDR(i+1, 0);
00064 UINT evsize = MAX(NE_get_seg_vsize(ne_shared, i), NE_get_seg_psize(ne_shared, i));
00065 if (base < l) l = base;
00066 if ((base + evsize > h) && (evsize)) h = base + evsize - 1;
00067 s++;
00068 }
00069
00070 Address *low = p->createAddress1616(NE_ADDR_SEG(l), NE_ADDR_OFS(l));
00071 Address *high = p->createAddress1616(NE_ADDR_SEG(h), NE_ADDR_OFS(h));
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 delete high;
00077 delete low;
00078
00079 v->sendmsg(msg_complete_init, 0);
00080
00081 if (!(ne_shared->hdr.flags & NE_FLAGS_SELFLOAD)) {
00082 Address *tmpaddr = p->createAddress1616(NE_ADDR_SEG(ne_shared->hdr.csip), NE_ADDR_OFS(ne_shared->hdr.csip));
00083 v->gotoAddress(tmpaddr, NULL);
00084 delete tmpaddr;
00085 }
00086
00087 g->insert(head);
00088 g->insert(v);
00089
00090 g->setpalette(palkey_generic_window_default);
00091
00092 ne_shared->v_image=v;
00093 return g;
00094 }
00095
00096 format_viewer_if htneimage_if = {
00097 htneimage_init,
00098 0
00099 };
00100
00101
00102
00103
00104
00105 void ht_ne_aviewer::init(bounds *b, char *desc, int caps, ht_streamfile *File, ht_format_group *format_group, Analyser *Analy, ht_ne_shared_data *NE_shared)
00106 {
00107 ht_aviewer::init(b, desc, caps, File, format_group, Analy);
00108 ne_shared = NE_shared;
00109 file = File;
00110 }
00111
00112 char *ht_ne_aviewer::func(UINT i, bool execute)
00113 {
00114 switch (i) {
00115 case 3: {
00116 bool e = false;
00117 file->cntl(FCNTL_GET_RELOC, &e);
00118 if (execute) {
00119 file->cntl(FCNTL_SET_RELOC, !e);
00120 }
00121 return e ? (char*)"unrelocate" : (char*)"relocate";
00122 }
00123 }
00124 return ht_aviewer::func(i, execute);
00125 }
00126
00127 void ht_ne_aviewer::setAnalyser(Analyser *a)
00128 {
00129 ((NEAnalyser*)a)->ne_shared = ne_shared;
00130 ((NEAnalyser*)a)->file = file;
00131 analy = a;
00132 analy_sub->setAnalyser(a);
00133 }