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

htle.h

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      htle.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 __HTLE_H__
00022 #define __HTLE_H__
00023 
00024 #include "htobj.h"
00025 #include "formats.h"
00026 #include "relfile.h"
00027 
00028 #include "lestruct.h"
00029 #include "htendian.h"
00030 
00031 #define DESC_LE "le - win,os2 linear exe"
00032 #define DESC_LE_HEADER "le/header"
00033 #define DESC_LE_VXD "le/vxd descriptor"
00034 #define DESC_LE_OBJECTS "le/objects"
00035 #define DESC_LE_PAGEMAP "le/page map"
00036 #define DESC_LE_ENTRYPOINTS "le/entrypoints"
00037 #define DESC_LE_IMAGE "le/image"
00038 
00039 #define ATOM_LE_FLAGS                   0x4c450000
00040 #define ATOM_LE_FLAGS_STR                "4c450000"
00041 
00042 #define ATOM_LE_MACHINE                 0x4c450001
00043 #define ATOM_LE_MACHINE_STR              "4c450001"
00044 
00045 #define ATOM_LE_OS                              0x4c450002
00046 #define ATOM_LE_OS_STR                   "4c450002"
00047 
00048 #define ATOM_LE_OBJFLAGS                0x4c450003
00049 #define ATOM_LE_OBJFLAGS_STR             "4c450003"
00050 
00051 #define ATOM_LE_ENTRY_FLAGS             0x4c450004
00052 #define ATOM_LE_ENTRY_FLAGS_STR  "4c450004"
00053 
00054 #define ATOM_LE_ENTRY_BUNDLE_FLAGS              0x4c450005
00055 #define ATOM_LE_ENTRY_BUNDLE_FLAGS_STR   "4c450005"
00056 
00057 #define LEAddress uint32
00058 
00059 #define LE_ADDR_INVALID 0
00060 #define LE_BASE_ADDR    0x400000
00061 
00062 class ht_le_page_file;
00063 
00064 struct ht_le_shared_data {
00065         endianess byteorder;
00066         dword hdr_ofs;
00067         LE_HEADER hdr;
00068         ht_viewer *v_header;
00069         ht_viewer *v_objects;
00070         ht_viewer *v_pagemaps;
00071         ht_viewer *v_image;
00072         ht_viewer *v_le_vxd;
00073         ht_le_objmap objmap;
00074         ht_le_pagemap pagemap;
00075         bool is_vxd;
00076         UINT vxd_desc_linear_ofs;
00077         LE_VXD_DESCRIPTOR vxd_desc;
00078         ht_le_page_file *linear_file;
00079         ht_reloc_file *reloc_file;
00080         LEAddress best_entrypoint;
00081 };
00082 
00083 class ht_le: public ht_format_group {
00084 protected:
00085         bool loc_enum;
00086 
00087                         void check_vxd();
00088                         void do_fixups();
00089                         void read_pagemap();
00090                         void read_objects();
00091 public:
00092                         void init(bounds *b, ht_streamfile *file, format_viewer_if **ifs, ht_format_group *format_group, FILEOFS h);
00093         virtual void done();
00094 /* overwritten */
00095         virtual   void loc_enum_start();
00096         virtual   bool loc_enum_next(ht_format_loc *loc);
00097 };
00098 
00099 extern format_viewer_if htle_if;
00100 
00101 /*
00102  *      CLASS ht_le_page_file
00103  */
00104 
00105 class ht_le_page_file: public ht_layer_streamfile {
00106 protected:
00107         ht_le_pagemap *pagemap;
00108         dword pagemapsize;
00109         dword page_size;
00110         FILEOFS ofs;
00111 public:
00112                    void init(ht_streamfile *file, bool own_file, ht_le_pagemap *pagemap, dword pagemapsize, dword page_size);
00113 /* overwritten */
00114         virtual bool isdirty(FILEOFS offset, UINT range);
00115         virtual UINT read(void *buf, UINT size);
00116         virtual int seek(FILEOFS offset);
00117         virtual FILEOFS tell();
00118         virtual int vcntl(UINT cmd, va_list vargs);
00119         virtual UINT write(const void *buf, UINT size);
00120 /* new */
00121                    bool map_ofs(UINT lofs, FILEOFS *pofs, UINT *maxsize);
00122                    bool unmap_ofs(FILEOFS pofs, UINT *lofs);
00123 };
00124 
00125 /*
00126  *      CLASS ht_le_reloc_entry
00127  */
00128 
00129 class ht_le_reloc_entry: public Object {
00130 public:
00131         UINT ofs;       // FIXME: hack
00132         UINT seg;
00133         LEAddress addr;
00134         uint8 address_type;
00135         uint8 reloc_type;
00136 
00137         ht_le_reloc_entry(UINT ofs, UINT seg, LEAddress addr, uint8 address_type, uint8 reloc_type);
00138 };
00139 
00140 /*
00141  *      CLASS ht_le_reloc_file
00142  */
00143 
00144 class ht_le_reloc_file: public ht_reloc_file {
00145 protected:
00146         ht_le_shared_data *data;
00147 /* overwritten */
00148         virtual void    reloc_apply(Object *reloc, byte *data);
00149         virtual bool    reloc_unapply(Object *reloc, byte *data);
00150 public:
00151                    void init(ht_streamfile *streamfile, bool own_streamfile, ht_le_shared_data *data);
00152 };
00153 
00154 FILEOFS LE_get_seg_ofs(ht_le_shared_data *LE_shared, UINT i);
00155 LEAddress LE_get_seg_addr(ht_le_shared_data *LE_shared, UINT i);
00156 UINT LE_get_seg_psize(ht_le_shared_data *LE_shared, UINT i);
00157 UINT LE_get_seg_vsize(ht_le_shared_data *LE_shared, UINT i);
00158 
00159 bool LE_addr_to_segment(ht_le_shared_data *LE_shared, LEAddress Addr, int *segment);
00160 bool LE_addr_is_physical(ht_le_shared_data *LE_shared, LEAddress Addr);
00161 bool LE_addr_to_ofs(ht_le_shared_data *LE_shared, LEAddress Addr, FILEOFS *ofs);
00162 
00163 bool LE_ofs_to_addr(ht_le_shared_data *LE_shared, FILEOFS ofs, LEAddress *Addr);
00164 
00165 LEAddress LE_MAKE_ADDR(ht_le_shared_data *LE_shared, uint16 seg, uint32 ofs);
00166 uint16 LE_ADDR_SEG(ht_le_shared_data *LE_shared, LEAddress a);
00167 uint32 LE_ADDR_OFS(ht_le_shared_data *LE_shared, LEAddress a);
00168 
00169 #endif /* __HTLE_H__ */
00170 

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