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

htne.h

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      htne.h
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 #ifndef __HTNE_H__
00022 #define __HTNE_H__
00023 
00024 #include "htobj.h"
00025 #include "formats.h"
00026 #include "relfile.h"
00027 
00028 #include "nestruct.h"
00029 
00030 #define DESC_NE "ne - win16,os2 new exe"
00031 #define DESC_NE_HEADER "ne/header"
00032 #define DESC_NE_SEGMENTS "ne/segments"
00033 #define DESC_NE_IMPORTS "ne/imports"
00034 #define DESC_NE_ENTRYPOINTS "ne/entrypoints"
00035 #define DESC_NE_NAMES "ne/names"
00036 #define DESC_NE_IMAGE "ne/image"
00037 
00038 #define ATOM_NE_FLAGS                   0x4e450000
00039 #define ATOM_NE_FLAGS_STR                "4e450000"
00040 
00041 #define ATOM_NE_OS                              0x4e450001
00042 #define ATOM_NE_OS_STR                   "4e450001"
00043 
00044 #define ATOM_NE_SEGFLAGS                        0x4e450002
00045 #define ATOM_NE_SEGFLAGS_STR             "4e450002"
00046 
00047 #define ATOM_NE_ENTFLAGS                        0x4e450003
00048 #define ATOM_NE_ENTFLAGS_STR             "4e450003"
00049 
00050 struct ne_segment_headers {
00051         UINT segment_count;
00052         NE_SEGMENT *segments;
00053 };
00054 
00055 class ne_import_rec: public Object {
00056 public:
00057         UINT addr;
00058         UINT module;
00059         bool byname;
00060         union {
00061                 UINT name_ofs;
00062                 UINT ord;
00063         };
00064 
00065         ne_import_rec(UINT a, UINT mod, bool b, UINT i)
00066         {
00067                 addr = a;
00068                 module = mod;
00069                 byname = b;
00070                 ord = i;
00071         }
00072 };
00073 
00074 class ht_aviewer;
00075 struct ht_ne_shared_data {
00076         dword hdr_ofs;
00077         NE_HEADER hdr;
00078         ne_segment_headers segments;
00079         UINT modnames_count;
00080         char **modnames;
00081         UINT fake_segment;
00082         ht_list *entrypoints;
00083         ht_tree *imports;
00084         ht_aviewer *v_image;
00085 };
00086 
00087 class ht_ne: public ht_format_group {
00088 protected:
00089         bool loc_enum;
00090 
00091                         bool create_fake_segment();
00092                         bool relocate(ht_reloc_file *rf);
00093                         bool relocate_single(ht_reloc_file *rf, UINT seg, FILEOFS ofs, UINT type, UINT flags, word value_seg, word value_ofs);
00094 public:
00095                         void init(bounds *b, ht_streamfile *file, format_viewer_if **ifs, ht_format_group *format_group, FILEOFS h);
00096         virtual void done();
00097 /* overwritten */
00098         virtual   void loc_enum_start();
00099         virtual   bool loc_enum_next(ht_format_loc *loc);
00100 };
00101 
00102 extern format_viewer_if htne_if;
00103 
00104 /*
00105  *      CLASS ht_ne_entrypoint
00106  */
00107 
00108 class ht_ne_entrypoint: public Object {
00109 public:
00110         UINT ordinal;
00111         UINT seg;
00112         UINT offset;
00113         UINT flags;
00114         char *name;
00115 
00116                 ht_ne_entrypoint(UINT ordinal, UINT seg, UINT offset, UINT flags);
00117         virtual ~ht_ne_entrypoint();
00118 };
00119 
00120 /*
00121  *      CLASS ht_ne_reloc_entry
00122  */
00123 
00124 class ht_ne_reloc_entry: public Object {
00125 public:
00126         UINT mode;
00127         bool add;
00128 
00129         word seg;
00130         word ofs;
00131 
00132         ht_ne_reloc_entry(UINT mode, bool add, word seg, word ofs);
00133 };
00134 
00135 /*
00136  *      CLASS ht_ne_reloc_file
00137  */
00138 
00139 class ht_ne_reloc_file: public ht_reloc_file {
00140 protected:
00141         ht_ne_shared_data *data;
00142 /* overwritten */
00143         virtual void    reloc_apply(Object *reloc, byte *data);
00144         virtual bool    reloc_unapply(Object *reloc, byte *data);
00145 public:
00146                    void init(ht_streamfile *streamfile, bool own_streamfile, ht_ne_shared_data *data);
00147 };
00148 
00149 /*
00150  *
00151  */
00152 
00153 FILEOFS NE_get_seg_ofs(ht_ne_shared_data *NE_shared, UINT i);
00154 dword NE_get_seg_addr(ht_ne_shared_data *NE_shared, UINT i);
00155 UINT NE_get_seg_psize(ht_ne_shared_data *NE_shared, UINT i);
00156 UINT NE_get_seg_vsize(ht_ne_shared_data *NE_shared, UINT i);
00157 
00158 bool NE_addr_to_segment(ht_ne_shared_data *NE_shared, dword Addr, int *segment);
00159 bool NE_addr_is_physical(ht_ne_shared_data *NE_shared, dword Addr);
00160 bool NE_addr_to_ofs(ht_ne_shared_data *NE_shared, dword Addr, FILEOFS *ofs);
00161 
00162 bool NE_ofs_to_addr(ht_ne_shared_data *NE_shared, FILEOFS ofs, dword *Addr);
00163 
00164 #define NEAddress dword
00165 #define NE_MAKE_ADDR(seg, ofs) ((seg)*0x10000+(ofs))
00166 #define NE_ADDR_SEG(a) ((a)>>16)
00167 #define NE_ADDR_OFS(a) ((a)&0xffff)
00168 
00169 #endif /* __HTNE_H__ */
00170 

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