forked from tecknicaltom/HT-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlestruct.h
311 lines (272 loc) · 9.36 KB
/
lestruct.h
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
* HT Editor
* lestruct.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 __LESTRUCT_H_
#define __LESTRUCT_H_
#include "io/types.h"
#define LE_CPU_286 0x01
#define LE_CPU_386 0x02
#define LE_CPU_486 0x03
#define LE_CPU_586 0x04
#define LE_CPU_N10 0x20
#define LE_CPU_N11 0x21
#define LE_CPU_R2000 0x40
#define LE_CPU_R6000 0x41
#define LE_CPU_R4000 0x42
#define LE_OS_OS2 0x01
#define LE_OS_WIN 0x02
#define LE_OS_DOS4 0x03
#define LE_OS_WIN386 0x04
#define LE_MAGIC0 'L'
#define LE_MAGIC1 'E'
#define LE_SIZEOF_HEADER 196
struct LE_HEADER {
uint16 magic; // Magic number
byte border; // The byte ordering for the VXD
byte worder; // The uint16 ordering for the VXD
uint32 level; // The EXE format level for now = 0
uint16 cpu; // The CPU type
uint16 os; // The OS type
uint32 ver; // Module version
uint32 mflags; // Module flags
uint32 pagecnt; // Module # pages
uint32 startobj; // Object # for instruction pointer
uint32 eip; // Extended instruction pointer
uint32 stackobj; // Object # for stack pointer
uint32 esp; // Extended stack pointer
uint32 pagesize; // VXD page size
uint32 lastpagesize; // Last page size in VXD
uint32 fixupsize; // Fixup section size
uint32 fixupsum; // Fixup section checksum
uint32 ldrsize; // Loader section size
uint32 ldrsum; // Loader section checksum
uint32 objtab; // Object table offset
uint32 objcnt; // Number of objects in module
uint32 pagemap; // Object page map offset
uint32 itermap; // Object iterated data map offset
uint32 rsrctab; // Offset of Resource Table
uint32 rsrccnt; // Number of resource entries
uint32 restab; // Offset of resident name table
uint32 enttab; // Offset of Entry Table
uint32 dirtab; // Offset of Module Directive Table
uint32 dircnt; // Number of module directives
uint32 fpagetab; // Offset of Fixup Page Table
uint32 frectab; // Offset of Fixup Record Table
uint32 impmod; // Offset of Import Module Name Table
uint32 impmodcnt; // Number of entries in Import Module Name Table
uint32 impproc; // Offset of Import Procedure Name Table
uint32 pagesum; // Offset of Per-Page Checksum Table
uint32 datapage; // Offset of Enumerated Data Pages
uint32 preload; // Number of preload pages
uint32 nrestab; // Offset of Non-resident Names Table
uint32 cbnrestab; // Size of Non-resident Name Table
uint32 nressum; // Non-resident Name Table Checksum
uint32 autodata; // Object # for automatic data object
uint32 debuginfo; // Offset of the debugging information
uint32 debuglen; // The length of the debugging info. in bytes
uint32 instpreload; // Number of instance pages in preload section of VXD file
uint32 instdemand; // Number of instance pages in demand load section of VXD file
uint32 heapsize; // Size of heap - for 16-bit apps
byte res3[12]; // Reserved words
uint32 winresoff;
uint32 winreslen;
uint16 devid; // Device ID for VxD
uint16 ddkver; // DDK version for VxD
} PACKED;
/*
1 1 1 1 1 1
5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
þ þ þ þ þ þ þ þ þ þ þ þ þ þ þ þ
³ ³ ³ ³ ³ ³ ³ ³
³ ³ ÀÄÅÄÙ ³ ³ ÀÄÄÄÄÄ2ÄInitialization ( Only for DLL ):
³ ³ ³ ³ ³ 0: Global
³ ³ ³ ³ ³ 1: Per-Process
³ ³ ³ ³ ³
³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄ4Ä1:No internal fixup in exe image
³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄ5Ä1:No external fixup in exe image
³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ8,9,10Ä 0 - Unknown
³ ³ 1 - Incompatible with PM windowing
³ ³ 2 - Compatible with PM windowing
³ ³ 3 - Uses PM windowing API
³ ³
³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ13Ä1: Module not loadable
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ15Ä1: Module is DLL rather then program
*/
#define LE_MODULE_FLAG_INIT_PER_PROCESS (1<<2)
#define LE_MODULE_FLAG_NO_EXT_FIXUP (1<<4)
#define LE_MODULE_FLAG_NO_INT_FIXUP (1<<5)
#define LE_MODULE_FLAG_WINDOWING_MASK (7<<8)
#define LE_MODULE_FLAG_NOT_LOADABLE (1<<13)
#define LE_MODULE_FLAG_LIBRARY (1<<15)
/*
* LE Objects (aka segments, aka sections)
*/
/*
³ ³ ³ ³ ³ ÀÂÙ ³ ³ ³ ³ ³ ³ ³ ÀÄ0Ä 1: Readable
³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ1Ä 1: Writable
³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ2Ä 1: Executable
³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ3Ä 1: Resource
³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄ4Ä 1: Discardable
³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄ5Ä 1: Shared
³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄ6Ä 1: Preloaded
³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ7Ä 1: Invalid
³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ8,9ÄÄ Type: 00 - Normal
³ ³ ³ ³ ³ 01 - Zero-filled
³ ³ ³ ³ ³ 10 - Resident
³ ³ ³ ³ ³ 11 - Resident/contiguous
³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ10Ä "RESIDENT/LONG_LOCABLE"
³ ³ ³ ³
³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ12Ä "16:16_ALIAS"
³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ13Ä 1: "BIG" (USE32)
³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ14Ä 1: Conforming
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ15Ä "Object_i/o_privilege_level"
*/
#define LE_OBJECT_FLAG_READABLE (1<<0)
#define LE_OBJECT_FLAG_WRITEABLE (1<<1)
#define LE_OBJECT_FLAG_EXECUTABLE (1<<2)
#define LE_OBJECT_FLAG_RESOURCE (1<<3)
#define LE_OBJECT_FLAG_DISCARDABLE (1<<4)
#define LE_OBJECT_FLAG_SHARED (1<<5)
#define LE_OBJECT_FLAG_PRELOADED (1<<6)
#define LE_OBJECT_FLAG_INVALID (1<<7)
#define LE_OBJECT_FLAG_USE32 (1<<13)
#define LE_SIZEOF_OBJECT 24
struct LE_OBJECT {
uint32 vsize;
uint32 base_reloc_addr;
uint32 flags;
uint32 page_map_index;
uint32 page_map_count;
byte name[4];
} PACKED;
struct LE_PAGE_MAP_ENTRY {
uint16 high;
byte low;
byte flags;
} PACKED;
/*
* ENTRYPOINTS
*/
#define LE_ENTRYPOINT_BUNDLE_VALID (1<<0)
#define LE_ENTRYPOINT_BUNDLE_32BIT (1<<1)
struct LE_ENTRYPOINT_BUNDLE {
byte entry_count;
byte flags;
uint16 obj_index;
} PACKED;
#define LE_ENTRYPOINT_EXPORTED (1<<0)
#define LE_ENTRYPOINT_SHARED (1<<1)
struct LE_ENTRYPOINT16 {
byte flags;
uint16 offset;
} PACKED;
struct LE_ENTRYPOINT32 {
byte flags;
uint32 offset;
} PACKED;
/*
* FIXUPS
*/
#define LE_FIXUP_ADDR_TYPE_MASK (15<<0)
#define LE_FIXUP_ADDR_TYPE_0_8 0
#define LE_FIXUP_ADDR_TYPE_16_0 2
#define LE_FIXUP_ADDR_TYPE_16_16 3
#define LE_FIXUP_ADDR_TYPE_0_16 5
#define LE_FIXUP_ADDR_TYPE_16_32 6
#define LE_FIXUP_ADDR_TYPE_0_32 7
#define LE_FIXUP_ADDR_TYPE_REL32 8
#define LE_FIXUP_ADDR_16_16 (1<<4)
#define LE_FIXUP_ADDR_MULTIPLE (1<<5)
#define LE_FIXUP_RELOC_TYPE_MASK (3<<0)
#define LE_FIXUP_RELOC_TYPE_INTERNAL 0
#define LE_FIXUP_RELOC_TYPE_IMPORT_ORD 1
#define LE_FIXUP_RELOC_TYPE_IMPORT_NAME 2
#define LE_FIXUP_RELOC_TYPE_OSFIXUP 3 // ?
#define LE_FIXUP_RELOC_ADDITIVE (1<<2)
#define LE_FIXUP_RELOC_TARGET32 (1<<4)
#define LE_FIXUP_RELOC_ADDITIVE32 (1<<5)
#define LE_FIXUP_RELOC_ORDINAL16 (1<<6)
#define LE_FIXUP_RELOC_IORD8 (1<<7)
struct LE_FIXUP {
uint8 address_type;
uint8 reloc_type;
} PACKED;
// if address_type == 8, reloc_type = 0
struct LE_FIXUP_INTERNAL16 {
uint8 seg;
uint16 ofs;
} PACKED;
struct LE_FIXUP_INTERNAL32 {
uint8 seg;
uint32 ofs;
} PACKED;
/*
* VxD specific
*/
struct LE_VXD_DESCRIPTOR {
uint32 next;
uint16 sdk_version;
uint16 device_number;
uint8 version_major;
uint8 version_minor;
uint16 flags;
uint8 name[8]; // not (null-)terminated, fill with spaces
uint32 init_order;
uint32 ctrl_ofs;
uint32 v86_ctrl_ofs;
uint32 pm_ctrl_ofs;
uint32 v86_ctrl_csip;
uint32 pm_ctrl_csip;
uint32 rm_ref_data; // "Reference data from real mode"
uint32 service_table_ofs;
uint32 service_table_size;
uint32 win32_service_table_ofs;
uint32 prev; // normally 'verP' (Prev)
uint32 size; // size of this structure (0x50 = 80)
uint32 reserved0; // normally '1vsR' (Rsv1)
uint32 reserved1; // normally '2vsR' (Rsv2)
uint32 reserved2; // normally '3vsR' (Rsv3)
} PACKED;
/*
* internal
*/
struct ht_le_objmap {
LE_OBJECT *header;
uint *psize;
uint *vsize;
uint count;
};
struct ht_le_pagemap {
uint *offset;
uint *psize;
uint *vsize;
uint count;
};
/**/
extern byte LE_HEADER_struct[];
extern byte LE_FIXUP_struct[];
extern byte LE_ENTRYPOINT16_struct[];
extern byte LE_ENTRYPOINT32_struct[];
extern byte LE_VXD_DESCRIPTOR_struct[];
extern byte LE_FIXUP_INTERNAL_struct[];
extern byte LE_OBJECT_HEADER_struct[];
extern byte LE_PAGE_MAP_ENTRY_struct[];
extern byte LE_FIXUP_INTERNAL16_struct[];
extern byte LE_FIXUP_INTERNAL32_struct[];
#endif /* __LESTRUCT_H_ */