00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "htatom.h"
00022 #include "htendian.h"
00023 #include "htnewexe.h"
00024 #include "htne.h"
00025 #include "htneobj.h"
00026 #include "httag.h"
00027 #include "htstring.h"
00028 #include "formats.h"
00029 #include "snprintf.h"
00030
00031 #include "nestruct.h"
00032
00033 #include <stdlib.h>
00034 #include <string.h>
00035
00036 static ht_mask_ptable neobj[]=
00037 {
00038 {"offset", STATICTAG_EDIT_WORD_LE("00000000")},
00039 {"size", STATICTAG_EDIT_WORD_LE("00000002")},
00040 {"flags", STATICTAG_EDIT_WORD_LE("00000004")" "STATICTAG_FLAGS("00000004", ATOM_NE_SEGFLAGS_STR)},
00041 {"minalloc", STATICTAG_EDIT_WORD_LE("00000006")},
00042 {0, 0}
00043 };
00044
00045 static ht_tag_flags_s ne_segflags[] =
00046 {
00047 {0, "[00] data"},
00048 {1, "[01] reserved"},
00049 {2, "[02] reserved"},
00050 {3, "[03] iterated"},
00051 {4, "[04] movable"},
00052 {5, "[05] sharable"},
00053 {6, "[06] preload"},
00054 {7, "[07] read only"},
00055 {8, "[08] relocations"},
00056 {9, "[09] conforming"},
00057 {10, "[10] pl0"},
00058 {11, "[11] pl1"},
00059 {12, "[12] discardable"},
00060 {13, "[13] 32bit"},
00061 {14, "[14] huge"},
00062 {15, "[15] reserved"},
00063 {0, 0}
00064 };
00065
00066 static ht_view *htnesegments_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00067 {
00068 ht_ne_shared_data *ne_shared=(ht_ne_shared_data *)group->get_shared_data();
00069
00070 dword h=ne_shared->hdr_ofs;
00071 ht_uformat_viewer *v=new ht_uformat_viewer();
00072 v->init(b, DESC_NE_SEGMENTS, VC_EDIT | VC_SEARCH, file, group);
00073 ht_mask_sub *m=new ht_mask_sub();
00074 m->init(file, 0);
00075
00076 register_atom(ATOM_NE_SEGFLAGS, ne_segflags);
00077
00078 char t[64];
00079
00080 ht_snprintf(t, sizeof t, "* NE segment table at offset %08x", h+ne_shared->hdr.segtab);
00081 m->add_mask(t);
00082 m->add_mask("note: 0 means 65536 for segment size and minalloc");
00083
00084 file->seek(h+ne_shared->hdr.segtab);
00085 for (dword i=0; i<ne_shared->hdr.cseg; i++) {
00086 NE_SEGMENT s;
00087 file->read(&s, sizeof s);
00088 create_host_struct(&s, NE_SEGMENT_struct, little_endian);
00089 ht_snprintf(t, sizeof t, "--- segment %d (%s) ---", i+1, (s.flags & NE_DATA) ? "data" : "code");
00090 m->add_mask(t);
00091 m->add_staticmask_ptable(neobj, h+ne_shared->hdr.segtab+i*8, false);
00092 }
00093 v->insertsub(m);
00094
00095 return v;
00096 }
00097
00098 format_viewer_if htnesegments_if = {
00099 htnesegments_init,
00100 0
00101 };