1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/*
* HT Editor
* htne.h
*
* Copyright (C) 1999-2002 Stefan Weyergraf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __HTNE_H__
#define __HTNE_H__
#include "htobj.h"
#include "formats.h"
#include "relfile.h"
#include "nestruct.h"
#define DESC_NE "ne - win16,os2 new exe"
#define DESC_NE_HEADER "ne/header"
#define DESC_NE_SEGMENTS "ne/segments"
#define DESC_NE_IMPORTS "ne/imports"
#define DESC_NE_ENTRYPOINTS "ne/entrypoints"
#define DESC_NE_NAMES "ne/names"
#define DESC_NE_IMAGE "ne/image"
#define ATOM_NE_FLAGS 0x4e450000
#define ATOM_NE_FLAGS_STR "4e450000"
#define ATOM_NE_OS 0x4e450001
#define ATOM_NE_OS_STR "4e450001"
#define ATOM_NE_SEGFLAGS 0x4e450002
#define ATOM_NE_SEGFLAGS_STR "4e450002"
#define ATOM_NE_ENTFLAGS 0x4e450003
#define ATOM_NE_ENTFLAGS_STR "4e450003"
struct ne_segment_headers {
uint segment_count;
NE_SEGMENT *segments;
};
class ne_import_rec: public Object {
public:
uint addr;
uint module;
bool byname;
union {
uint name_ofs;
uint ord;
};
ne_import_rec(uint a, uint mod, bool b, uint i);
virtual int compareTo(const Object *obj) const;
};
class ht_aviewer;
struct ht_ne_shared_data {
uint32 hdr_ofs;
NE_HEADER hdr;
ne_segment_headers segments;
uint modnames_count;
char **modnames;
uint fake_segment;
Container *entrypoints;
Container *imports;
ht_aviewer *v_image;
};
class ht_ne: public ht_format_group {
protected:
bool loc_enum;
bool create_fake_segment();
bool relocate(ht_reloc_file *rf);
bool relocate_single(ht_reloc_file *rf, uint seg, FileOfs ofs, uint type, uint flags, uint16 value_seg, uint16 value_ofs);
public:
void init(Bounds *b, File *file, format_viewer_if **ifs, ht_format_group *format_group, FileOfs h);
virtual void done();
/* overwritten */
virtual void loc_enum_start();
virtual bool loc_enum_next(ht_format_loc *loc);
};
extern format_viewer_if htne_if;
/*
* CLASS ht_ne_entrypoint
*/
class ht_ne_entrypoint: public Object {
public:
uint ordinal;
uint seg;
uint offset;
uint flags;
char *name;
ht_ne_entrypoint(uint ordinal, uint seg, uint offset, uint flags);
virtual ~ht_ne_entrypoint();
};
/*
* CLASS ht_ne_reloc_entry
*/
class ht_ne_reloc_entry: public Object {
public:
uint mode;
bool add;
uint16 seg;
uint16 ofs;
ht_ne_reloc_entry(uint mode, bool add, uint16 seg, uint16 ofs);
};
/*
* CLASS ht_ne_reloc_file
*/
class ht_ne_reloc_file: public ht_reloc_file {
protected:
ht_ne_shared_data *data;
/* overwritten */
virtual void reloc_apply(Object *reloc, byte *data);
virtual bool reloc_unapply(Object *reloc, byte *data);
public:
ht_ne_reloc_file(File *streamfile, bool own_streamfile, ht_ne_shared_data *data);
};
/*
*
*/
FileOfs NE_get_seg_ofs(ht_ne_shared_data *NE_shared, uint i);
uint32 NE_get_seg_addr(ht_ne_shared_data *NE_shared, uint i);
uint NE_get_seg_psize(ht_ne_shared_data *NE_shared, uint i);
uint NE_get_seg_vsize(ht_ne_shared_data *NE_shared, uint i);
bool NE_addr_to_segment(ht_ne_shared_data *NE_shared, uint32 Addr, int *segment);
bool NE_addr_is_physical(ht_ne_shared_data *NE_shared, uint32 Addr);
bool NE_addr_to_ofs(ht_ne_shared_data *NE_shared, uint32 Addr, FileOfs *ofs);
bool NE_ofs_to_addr(ht_ne_shared_data *NE_shared, FileOfs ofs, uint32 *Addr);
#define NEAddress uint32
#define NE_MAKE_ADDR(seg, ofs) ((seg)*0x10000+(ofs))
#define NE_ADDR_SEG(a) ((a)>>16)
#define NE_ADDR_OFS(a) ((a)&0xffff)
#endif /* __HTNE_H__ */
|