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

htnenms.cc

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      htnenms.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 "htatom.h"
00022 #include "htendian.h"
00023 #include "htne.h"
00024 #include "htnenms.h"
00025 #include "httag.h"
00026 #include "formats.h"
00027 #include "snprintf.h"
00028 
00029 #include <stdlib.h>
00030 #include <string.h>
00031 
00032 static void assign_entrypoint_name(ht_ne_shared_data *ne_shared, UINT i, char *name)
00033 {
00034         if (ne_shared->entrypoints) {
00035                 ht_ne_entrypoint *e = (ht_ne_entrypoint*)ne_shared->entrypoints->get(i);
00036                 if (e) {
00037                         e->name = strdup(name);
00038                 } /*else fprintf(stderr, "entry %d not available\n", i);*/
00039         } /* else trouble :-) */
00040 }
00041 
00042 static ht_view *htnenames_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00043 {
00044         ht_ne_shared_data *ne_shared=(ht_ne_shared_data *)group->get_shared_data();
00045 
00046         dword h=ne_shared->hdr_ofs;
00047         ht_uformat_viewer *v=new ht_uformat_viewer();
00048         v->init(b, DESC_NE_NAMES, VC_EDIT | VC_SEARCH, file, group);
00049         ht_mask_sub *m=new ht_mask_sub();
00050         m->init(file, 0);
00051 
00052         char line[256]; /* secure */
00053         char *n;
00054         int i;
00055 
00056         ht_snprintf(line, sizeof line, "* NE resident names table at offset %08x", h+ne_shared->hdr.restab);
00057         m->add_mask(line);
00058 
00059         file->seek(h+ne_shared->hdr.restab);
00060         i=0;
00061         while (*(n=getstrp(file))) {
00062                 char buf[2];
00063                 file->read(buf, 2);
00064                 word ent = create_host_int(buf, 2, little_endian);
00065                 if (!i) {
00066                         ht_snprintf(line, sizeof line, "description: %s", n);
00067                 } else {
00068                         ht_snprintf(line, sizeof line, "%04x %s", ent, n);
00069                         assign_entrypoint_name(ne_shared, ent, n);
00070                 }
00071                 free(n);
00072                 m->add_mask(line);
00073                 i++;
00074         }
00075         free(n);
00076 
00077         m->add_mask("----------------------------------------------------------------");
00078         ht_snprintf(line, sizeof line, "* NE non-resident names table at offset %08x", ne_shared->hdr.nrestab);
00079         m->add_mask(line);
00080 
00081         file->seek(ne_shared->hdr.nrestab);
00082         i=0;
00083         while (*(n=getstrp(file))) {
00084                 char buf[2];
00085                 file->read(buf, 2);
00086                 word ent = create_host_int(buf, 2, little_endian);
00087                 if (!i) {
00088                         ht_snprintf(line, sizeof line, "description: %s", n);
00089                 } else {
00090                         ht_snprintf(line, sizeof line, "%04x %s", ent, n);
00091                         assign_entrypoint_name(ne_shared, ent, n);
00092                 }
00093                 free(n);
00094                 m->add_mask(line);
00095                 i++;
00096         }
00097         free(n);
00098 
00099         v->insertsub(m);
00100 
00101         return v;
00102 }
00103 
00104 format_viewer_if htnenames_if = {
00105         htnenames_init,
00106         NULL
00107 };

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