Rizin
unix-like reverse engineering framework and cli tools
le_specs.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2019 GustavoLCR <gugulcr@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #ifndef LE_SPECS_H
5 #define LE_SPECS_H
6 #include <rz_types.h>
7 
8 typedef enum {
15 
16 typedef enum {
17  LE_RT_POINTER = 1, /* mouse pointer shape */
18  LE_RT_BITMAP = 2, /* bitmap */
19  LE_RT_MENU = 3, /* menu template */
20  LE_RT_DIALOG = 4, /* dialog template */
21  LE_RT_STRING = 5, /* string tables */
22  LE_RT_FONTDIR = 6, /* font directory */
23  LE_RT_FONT = 7, /* font */
24  LE_RT_ACCELTABLE = 8, /* accelerator tables */
25  LE_RT_RCDATA = 9, /* binary data */
26  LE_RT_MESSAGE = 10, /* error msg tables */
27  LE_RT_DLGINCLUDE = 11, /* dialog include file name */
28  LE_RT_VKEYTBL = 12, /* key to vkey tables */
29  LE_RT_KEYTBL = 13, /* key to UGL tables */
30  LE_RT_CHARTBL = 14, /* glyph to character tables */
31  LE_RT_DISPLAYINFO = 15, /* screen display information */
32  LE_RT_FKASHORT = 16, /* function key area short form */
33  LE_RT_FKALONG = 17, /* function key area long form */
34  LE_RT_HELPTABLE = 18, /* Help table for Cary Help manager */
35  LE_RT_HELPSUBTABLE = 19, /* Help subtable for Cary Help manager */
36  LE_RT_FDDIR = 20, /* DBCS uniq/font driver directory */
37  LE_RT_FD = 21, /* DBCS uniq/font driver */
39 
40 // This bit signifies that additional information is contained in the linear EXE module
41 // and will be used in the future for parameter type checking.
42 #define ENTRY_PARAMETER_TYPING_PRESENT 0x80
43 
44 typedef struct LE_entry_bundle_header_s {
46  ut8 type; /* LE_entry_bundle_type */
47  ut16 objnum; // This is the object number for the entries in this bundle.
49 
50 #define ENTRY_EXPORTED 0x01
51 #define ENTRY_PARAM_COUNT_MASK 0xF8
52 
53 RZ_PACKED(typedef union LE_entry_bundle_entry_u {
54  RZ_PACKED(struct {
55  ut8 flags; // First bit set if exported, mask with 0xF8 to get parameters count
56  ut16 offset; // This is the offset in the object for the entry point defined at this ordinal number.
57  })
58  entry_16;
59  RZ_PACKED(struct {
60  ut8 flags; // First bit set if exported, mask with 0xF8 to get parameters count
61  ut16 offset; // This is the offset in the object for the entry point defined at this ordinal number.
62  ut16 callgate_sel; // The callgate selector for references to ring 2 entry points.
63  })
64  callgate;
65  RZ_PACKED(struct {
66  ut8 flags; // First bit set if exported, mask with 0xF8 to get parameters count
67  ut32 offset; // This is the offset in the object for the entry point defined at this ordinal number.
68  })
69  entry_32;
70  RZ_PACKED(struct {
71  ut8 flags; // First bit set if import by ordinal
72  ut16 import_ord; // This is the index into the Import Module Name Table for this forwarder.
73  ut32 offset; // If import by ordinal, is the ordinal number into the Entry Table of the target module, else is the offset into the Procedure Names Table of the target module.
74  })
75  forwarder;
76 })
77 LE_entry_bundle_entry;
78 
79 #define F_SOURCE_TYPE_MASK 0xF
80 #define F_SOURCE_ALIAS 0x10
81 #define F_SOURCE_LIST 0x20
82 
83 typedef enum {
87  POINTER32, // 16:16
90  POINTER48, // 16:32
94 
95 #define F_TARGET_TYPE_MASK 0x3
96 #define F_TARGET_ADDITIVE 0x4
97 #define F_TARGET_CHAIN 0x8
98 #define F_TARGET_OFF32 0x10 // Else 16
99 #define F_TARGET_ADD32 0x20 // Else 16
100 #define F_TARGET_ORD16 0x40 // Else 8
101 #define F_TARGET_ORD8 0x80 // Else 16
102 
103 typedef enum {
109 
110 typedef struct LE_fixup_record_header_s {
114 
115 #define O_READABLE 1
116 #define O_WRITABLE 1 << 1
117 #define O_EXECUTABLE 1 << 2
118 #define O_RESOURCE 1 << 3
119 #define O_DISCARTABLE 1 << 4
120 #define O_SHARED 1 << 5
121 #define O_PRELOAD 1 << 6
122 #define O_INVALID 1 << 7
123 #define O_ZEROED 1 << 8
124 #define O_RESIDENT 1 << 9
125 #define O_CONTIGUOUS O_RESIDENT | O_ZEROED
126 #define O_LOCKABLE 1 << 10
127 #define O_RESERVED 1 << 11
128 #define O_ALIASED 1 << 12
129 #define O_BIG_BIT 1 << 13
130 #define O_CODE 1 << 14
131 #define O_IO_PRIV 1 << 15
132 
133 typedef struct LE_object_entry_s {
137  ut32 page_tbl_idx; // This specifies the number of the first object page table entry for this object
141 
142 #define P_LEGAL 0
143 #define P_ITERATED 1
144 #define P_INVALID 2
145 #define P_ZEROED 3
146 #define P_RANGE 4
147 #define P_COMPRESSED 5
148 
149 typedef struct LE_object_page_entry_s {
150  ut32 offset; // 0 if zero-filled/invalid page (check flags)
154 
155 #define M_PP_LIB_INIT 1 << 2
156 #define M_SYS_DLL 1 << 3 // No internal fixups
157 #define M_INTERNAL_FIXUP 1 << 4
158 #define M_EXTERNAL_FIXUP 1 << 5
159 #define M_PM_WINDOWING_INCOMP 1 << 8 // Fullscreen only
160 #define M_PM_WINDOWING_COMPAT 1 << 9
161 #define M_USES_PM_WINDOWING M_PM_WINDOWING_INCOMP | M_PM_WINDOWING_COMPAT
162 #define M_NOT_LOADABLE 1 << 13
163 #define M_TYPE_MASK 0x38000
164 #define M_TYPE_EXE 0
165 #define M_TYPE_DLL 0x08000
166 #define M_TYPE_PM_DLL 0x10000
167 #define M_TYPE_PDD 0x20000 // Physical Device Driver
168 #define M_TYPE_VDD 0x28000 // Virtual Device Driver
169 #define M_MP_UNSAFE 1 << 19
170 #define M_PP_LIB_TERM 1 << 30
171 
172 typedef struct LE_image_header_s { /* New 32-bit .EXE header */
173  ut8 magic[2]; /* Magic number MAGIC */
174  ut8 border; /* The byte ordering for the .EXE */
175  ut8 worder; /* The word ordering for the .EXE */
176  ut32 level; /* The EXE format level for now = 0 */
177  ut16 cpu; /* The CPU type */
178  ut16 os; /* The OS type */
179  ut32 ver; /* Module version */
180  ut32 mflags; /* Module flags */
181  ut32 mpages; /* Module # pages */
182  ut32 startobj; /* Object # for instruction pointer */
183  ut32 eip; /* Extended instruction pointer */
184  ut32 stackobj; /* Object # for stack pointer */
185  ut32 esp; /* Extended stack pointer */
186  ut32 pagesize; /* .EXE page size */
187  ut32 pageshift; /* Page alignment shift in .EXE or Last Page Size (on LE only)*/
188  ut32 fixupsize; /* Fixup section size */
189  ut32 fixupsum; /* Fixup section checksum */
190  ut32 ldrsize; /* Loader section size */
191  ut32 ldrsum; /* Loader section checksum */
192  ut32 objtab; /* Object table offset */
193  ut32 objcnt; /* Number of objects in module */
194  ut32 objmap; /* Object page map offset */
195  ut32 itermap; /* Object iterated data map offset (File Relative) */
196  ut32 rsrctab; /* Offset of Resource Table */
197  ut32 rsrccnt; /* Number of resource entries */
198  ut32 restab; /* Offset of resident name table */
199  ut32 enttab; /* Offset of Entry Table */
200  ut32 dirtab; /* Offset of Module Directive Table */
201  ut32 dircnt; /* Number of module directives */
202  ut32 fpagetab; /* Offset of Fixup Page Table */
203  ut32 frectab; /* Offset of Fixup Record Table */
204  ut32 impmod; /* Offset of Import Module Name Table */
205  ut32 impmodcnt; /* Number of entries in Import Module Name Table */
206  ut32 impproc; /* Offset of Import Procedure Name Table */
207  ut32 pagesum; /* Offset of Per-Page Checksum Table */
208  ut32 datapage; /* Offset of Enumerated Data Pages (File Relative) */
209  ut32 preload; /* Number of preload pages */
210  ut32 nrestab; /* Offset of Non-resident Names Table (File Relative) */
211  ut32 cbnrestab; /* Size of Non-resident Name Table */
212  ut32 nressum; /* Non-resident Name Table Checksum */
213  ut32 autodata; /* Object # for automatic data object */
214  ut32 debuginfo; /* Offset of the debugging information */
215  ut32 debuglen; /* The length of the debugging info. in bytes */
216  ut32 instpreload; /* Number of instance pages in preload section of .EXE file */
217  ut32 instdemand; /* Number of instance pages in demand load section of EXE file */
218  ut32 heapsize; /* Size of heap - for 16-bit apps */
219  ut32 stacksize; /* Size of stack */
221 #endif
uint16_t ut16
uint32_t ut32
voidpf uLong offset
Definition: ioapi.h:144
LE_fixup_source_type
Definition: le_specs.h:83
@ POINTER32
Definition: le_specs.h:87
@ BYTEFIXUP
Definition: le_specs.h:84
@ SELFOFFSET32
Definition: le_specs.h:92
@ SELECTOR16
Definition: le_specs.h:86
@ UNDEFINED1
Definition: le_specs.h:85
@ POINTER48
Definition: le_specs.h:90
@ OFFSET32
Definition: le_specs.h:91
@ UNDEFINED2
Definition: le_specs.h:88
@ OFFSET16
Definition: le_specs.h:89
LE_fixup_record_type
Definition: le_specs.h:103
@ IMPORTORD
Definition: le_specs.h:105
@ INTERNALENTRY
Definition: le_specs.h:107
@ IMPORTNAME
Definition: le_specs.h:106
@ INTERNAL
Definition: le_specs.h:104
LE_entry_bundle_type
Definition: le_specs.h:8
@ CALLGATE
Definition: le_specs.h:11
@ ENTRY32
Definition: le_specs.h:12
@ FORWARDER
Definition: le_specs.h:13
@ ENTRY16
Definition: le_specs.h:10
@ UNUSED_ENTRY
Definition: le_specs.h:9
struct LE_fixup_record_header_s LE_fixup_record_header
struct LE_entry_bundle_header_s LE_entry_bundle_header
LE_resource_type
Definition: le_specs.h:16
@ LE_RT_KEYTBL
Definition: le_specs.h:29
@ LE_RT_RCDATA
Definition: le_specs.h:25
@ LE_RT_FKASHORT
Definition: le_specs.h:32
@ LE_RT_FD
Definition: le_specs.h:37
@ LE_RT_BITMAP
Definition: le_specs.h:18
@ LE_RT_VKEYTBL
Definition: le_specs.h:28
@ LE_RT_POINTER
Definition: le_specs.h:17
@ LE_RT_FKALONG
Definition: le_specs.h:33
@ LE_RT_STRING
Definition: le_specs.h:21
@ LE_RT_FDDIR
Definition: le_specs.h:36
@ LE_RT_DISPLAYINFO
Definition: le_specs.h:31
@ LE_RT_CHARTBL
Definition: le_specs.h:30
@ LE_RT_FONT
Definition: le_specs.h:23
@ LE_RT_MENU
Definition: le_specs.h:19
@ LE_RT_HELPSUBTABLE
Definition: le_specs.h:35
@ LE_RT_DIALOG
Definition: le_specs.h:20
@ LE_RT_FONTDIR
Definition: le_specs.h:22
@ LE_RT_DLGINCLUDE
Definition: le_specs.h:27
@ LE_RT_HELPTABLE
Definition: le_specs.h:34
@ LE_RT_MESSAGE
Definition: le_specs.h:26
@ LE_RT_ACCELTABLE
Definition: le_specs.h:24
struct LE_object_entry_s LE_object_entry
RZ_PACKED(typedef union LE_entry_bundle_entry_u { RZ_PACKED(struct { ut8 flags;ut16 offset;}) entry_16;RZ_PACKED(struct { ut8 flags;ut16 offset;ut16 callgate_sel;}) callgate;RZ_PACKED(struct { ut8 flags;ut32 offset;}) entry_32;RZ_PACKED(struct { ut8 flags;ut16 import_ord;ut32 offset;}) forwarder;}) LE_entry_bundle_entry
struct LE_object_page_entry_s LE_object_page_entry
struct LE_image_header_s LE_image_header
uint8_t ut8
Definition: lh5801.h:11
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
Definition: le_specs.h:44
ut16 objnum
Definition: le_specs.h:47
ut8 count
Definition: le_specs.h:45
ut8 type
Definition: le_specs.h:46
Definition: le_specs.h:133
ut32 flags
Definition: le_specs.h:136
ut32 page_tbl_entries
Definition: le_specs.h:138
ut32 reloc_base_addr
Definition: le_specs.h:135
ut32 page_tbl_idx
Definition: le_specs.h:137
ut32 reserved
Definition: le_specs.h:139
ut32 virtual_size
Definition: le_specs.h:134
Definition: le_specs.h:149
ut16 flags
Definition: le_specs.h:152
ut16 size
Definition: le_specs.h:151
ut32 offset
Definition: le_specs.h:150