File: htle.h

package info (click to toggle)
ht 2.1.0%2Brepack1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,852 kB
  • sloc: cpp: 88,922; ansic: 12,693; sh: 4,083; lex: 226; makefile: 185; yacc: 128
file content (170 lines) | stat: -rw-r--r-- 4,670 bytes parent folder | download | duplicates (8)
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
167
168
169
170
/* 
 *	HT Editor
 *	htle.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 __HTLE_H__
#define __HTLE_H__

#include "htobj.h"
#include "formats.h"
#include "relfile.h"

#include "lestruct.h"
#include "endianess.h"

#define DESC_LE "le - win,os2 linear exe"
#define DESC_LE_HEADER "le/header"
#define DESC_LE_VXD "le/vxd descriptor"
#define DESC_LE_OBJECTS "le/objects"
#define DESC_LE_PAGEMAP "le/page map"
#define DESC_LE_ENTRYPOINTS "le/entrypoints"
#define DESC_LE_IMAGE "le/image"

#define ATOM_LE_FLAGS			0x4c450000
#define ATOM_LE_FLAGS_STR		 "4c450000"

#define ATOM_LE_MACHINE			0x4c450001
#define ATOM_LE_MACHINE_STR		 "4c450001"

#define ATOM_LE_OS				0x4c450002
#define ATOM_LE_OS_STR			 "4c450002"

#define ATOM_LE_OBJFLAGS   		0x4c450003
#define ATOM_LE_OBJFLAGS_STR		 "4c450003"

#define ATOM_LE_ENTRY_FLAGS		0x4c450004
#define ATOM_LE_ENTRY_FLAGS_STR	 "4c450004"

#define ATOM_LE_ENTRY_BUNDLE_FLAGS		0x4c450005
#define ATOM_LE_ENTRY_BUNDLE_FLAGS_STR	 "4c450005"

#define LEAddress uint32

#define LE_ADDR_INVALID	0
#define LE_BASE_ADDR	0x400000

class ht_le_page_file;

struct ht_le_shared_data {
	Endianess byteorder;
	FileOfs hdr_ofs;
	LE_HEADER hdr;
	ht_viewer *v_header;
	ht_viewer *v_objects;
	ht_viewer *v_pagemaps;
	ht_viewer *v_image;
	ht_viewer *v_le_vxd;
	ht_le_objmap objmap;
	ht_le_pagemap pagemap;
	bool is_vxd;
	FileOfs vxd_desc_linear_ofs;
	LE_VXD_DESCRIPTOR vxd_desc;
	ht_le_page_file *linear_file;
	ht_reloc_file *reloc_file;
	LEAddress best_entrypoint;
};

class ht_le: public ht_format_group {
protected:
	bool loc_enum;

			void check_vxd();
			void do_fixups();
			void read_pagemap();
			void read_objects();
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 htle_if;

/*
 *	CLASS ht_le_page_file
 */

class ht_le_page_file: public FileLayer {
protected:
	ht_le_pagemap *pagemap;
	uint32 pagemapsize;
	uint32 page_size;
	FileOfs ofs;
public:
			ht_le_page_file(File *file, bool own_file, ht_le_pagemap *pagemap, uint32 pagemapsize, uint32 page_size);
/* overwritten */
	virtual bool isdirty(FileOfs offset, FileOfs range);
	virtual uint read(void *buf, uint size);
	virtual void seek(FileOfs offset);
	virtual FileOfs tell() const;
	virtual int vcntl(uint cmd, va_list vargs);
	virtual uint write(const void *buf, uint size);
/* new */
	   bool map_ofs(uint32 lofs, FileOfs *pofs, FileOfs *maxsize);
	   bool unmap_ofs(FileOfs pofs, uint32 *lofs);
};

/*
 *	CLASS ht_le_reloc_entry
 */

class ht_le_reloc_entry: public Object {
public:
	uint ofs;	// FIXME: hack
	uint seg;
	LEAddress addr;
	uint8 address_type;
	uint8 reloc_type;

	ht_le_reloc_entry(uint ofs, uint seg, LEAddress addr, uint8 address_type, uint8 reloc_type);
};

/*
 *	CLASS ht_le_reloc_file
 */

class ht_le_reloc_file: public ht_reloc_file {
protected:
	ht_le_shared_data *data;
/* overwritten */
	virtual void	reloc_apply(Object *reloc, byte *data);
	virtual bool	reloc_unapply(Object *reloc, byte *data);
public:
			ht_le_reloc_file(File *streamfile, bool own_streamfile, ht_le_shared_data *data);
};

FileOfs LE_get_seg_ofs(ht_le_shared_data *LE_shared, uint i);
LEAddress LE_get_seg_addr(ht_le_shared_data *LE_shared, uint i);
uint LE_get_seg_psize(ht_le_shared_data *LE_shared, uint i);
uint LE_get_seg_vsize(ht_le_shared_data *LE_shared, uint i);

bool LE_addr_to_segment(ht_le_shared_data *LE_shared, LEAddress Addr, int *segment);
bool LE_addr_is_physical(ht_le_shared_data *LE_shared, LEAddress Addr);
bool LE_addr_to_ofs(ht_le_shared_data *LE_shared, LEAddress Addr, FileOfs *ofs);

bool LE_ofs_to_addr(ht_le_shared_data *LE_shared, FileOfs ofs, LEAddress *Addr);

LEAddress LE_MAKE_ADDR(ht_le_shared_data *LE_shared, uint16 seg, uint32 ofs);
uint16 LE_ADDR_SEG(ht_le_shared_data *LE_shared, LEAddress a);
uint32 LE_ADDR_OFS(ht_le_shared_data *LE_shared, LEAddress a);

#endif /* __HTLE_H__ */