source: trunk/src/pe2lx/LX.H@ 91

Last change on this file since 91 was 46, checked in by sandervl, 26 years ago

* empty log message *

File size: 7.7 KB
Line 
1/*
2 * PE2LX LX
3 *
4 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
5 *
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10#ifndef __LX_H__
11#define __LX_H__
12
13#include <win32type.h>
14#include <exe386.h>
15
16#define LXHEADER_OFFSET 0x80
17#define PAGE_SIZE 4096
18#define PAGE_SHIFT 12
19
20#define SYSTEM_CHARACTER 0
21#define SYSTEM_GUI 1
22
23#define SECTION_CODE 1
24#define SECTION_INITDATA 2
25#define SECTION_UNINITDATA 4
26#define SECTION_READONLYDATA 8
27#define SECTION_IMPORT 16
28#define SECTION_STACK 32
29#define SECTION_RESOURCE_ORG 64
30#define SECTION_RESOURCE 128
31#define SECTION_COMBINEDDATA 256
32#define MAX_SECTION 64 /*PLF Mon 98-02-09 23:47:16*/
33
34#define MAX_IMPORT 8192 //this should do for most bloated apps
35#define MAX_RESOURCE 8192
36
37typedef struct {
38 char *rawdata;
39 int rawsize;
40 int virtualsize;
41 int curoff;
42 int type;
43 int address;
44 int endaddress;
45 int nrpages;
46 int nrinvalidpages;
47 BOOL fProcessed;
48 BOOL fInvalid;
49} Section;
50
51typedef struct {
52 int size;
53 int flags;
54} DataPage;
55
56#pragma pack(1)
57
58//also defined in USER32\NAMEID.H!
59#define RESID_CONVERTEDNAMES 63*1024
60typedef struct {
61 int id;
62 char name[1];
63} NameId;
64
65typedef struct {
66 unsigned char nr_stype; /* Source type - field shared with new_rlc */
67 unsigned char nr_flags; /* Flag byte - field shared with new_rlc */
68 short r32_soff; /* Source offset */
69 unsigned short r32_objmod; /* Target object number or Module ordinal */
70 unsigned short proc; /* Procedure name offset */
71 unsigned short srcpage;
72} namefixup;
73
74typedef struct {
75 unsigned char nr_stype; /* Source type - field shared with new_rlc */
76 unsigned char nr_flags; /* Flag byte - field shared with new_rlc */
77 short r32_soff; /* Source offset */
78 unsigned short r32_objmod; /* Target object number or Module ordinal */
79 unsigned short proc; /* Procedure name offset */
80} realnamefixup;
81
82typedef struct {
83 unsigned char nr_stype; /* Source type - field shared with new_rlc */
84 unsigned char nr_flags; /* Flag byte - field shared with new_rlc */
85 short r32_soff; /* Source offset */
86 unsigned short r32_objmod; /* Target object number or Module ordinal */
87 unsigned short ord; /* Ordinal */
88 unsigned short srcpage;
89} ordfixup;
90
91typedef struct {
92 unsigned char nr_stype; /* Source type - field shared with new_rlc */
93 unsigned char nr_flags; /* Flag byte - field shared with new_rlc */
94 short r32_soff; /* Source offset */
95 unsigned short r32_objmod; /* Target object number or Module ordinal */
96 unsigned short ord; /* Ordinal */
97} realordfixup;
98
99typedef struct {
100 unsigned char nr_stype; /* Source type - field shared with new_rlc */
101 unsigned char nr_flags; /* Flag byte - field shared with new_rlc */
102 short r32_soff; /* Source offset */
103 unsigned short targetobj;
104 unsigned long targetaddr;
105 unsigned short srcobj;
106 unsigned short srcpage;
107} intfixup;
108
109typedef struct {
110 unsigned char nr_stype; /* Source type - field shared with new_rlc */
111 unsigned char nr_flags; /* Flag byte - field shared with new_rlc */
112 short r32_soff; /* Source offset */
113 unsigned short targetobj;
114 unsigned long targetaddr;
115} realintfixup;
116
117typedef struct
118{
119 unsigned char b32_cnt; /* Number of entries in this bundle */
120 unsigned char b32_type; /* Bundle type */
121 unsigned short b32_obj; /* Object number */
122
123 unsigned char e32_flags; /* Entry point flags */
124 unsigned long e32_offset; /* 16-bit/32-bit offset entry */
125} exportbundle;
126
127typedef struct
128{
129 unsigned char b32_cnt; /* Number of entries in this bundle */
130 unsigned char b32_type; /* Bundle type */
131 unsigned short b32_obj; /* Object number */
132
133 unsigned char e32_flags; /* Entry point flags */
134 unsigned short modord; /* Module ordinal number */
135 unsigned long value; /* Proc name offset or ordinal */
136} forwardbundle;
137
138#pragma pack()
139
140class LXHeader {
141public:
142 LXHeader();
143 ~LXHeader();
144
145 void SetEntryAddress(int address);
146 void SetExeType(BOOL IsEXE);
147 void SetNoFixups();
148 void SetStackSize(int size);
149 void SetResourceSize(int size);
150 void SetNrResources(int cnt);
151 void StoreSection(char *rawdata, int rawsize, int virtualsize, int address, int type);
152 void AlignSections();
153 BOOL StoreImportByName(char *modname, int idxmod, char *name, int offset);
154 BOOL StoreImportByOrd(int idxmod, int ordinal, int offset);
155 void StoreImportModules(char *modules, int nrmod);
156 void SetNoNameImports();
157 BOOL SaveNewExeFile(char *filename);
158 void SetModuleType(int type);
159 void AddOff32Fixup(int address);
160 void SetNrOff32Fixups(int nr);
161 void AddNameExport(int address, char *name, int ordinal);
162 void AddOrdExport(int address, int ordinal);
163 void SetNrExtFixups(int nr);
164 void AddForwarder(char *name, int ordinal, char *forward);
165
166 int GetAddressPage(int address);
167 void SetModuleName(char *filename);
168 //resource procedures
169 void StoreResource(int id, int type, int size, char *resourcedata);
170 void StoreWin32Resource(int id, int type, int size, char *resourcedata);
171 int ConvertNametoId(char *nameid);
172 void SaveConvertedNames();
173 void StoreResourceId(int id);
174 int GetUniqueId();
175
176 //SvL: 18-7-'98: Set version resource id
177 void SetVersionResourceId(int id) { VersionResourceId = id; };
178
179private:
180 BOOL IsSystemModule(char *mod, int size);
181 int FindName(char *table, int index);
182 char *StripPath(char *path);
183 char *StripExtension(char *fname);
184
185 void StoreAndSortImport(namefixup *newfrec);
186
187 int GetNrPages();
188 int GetNrObjects();
189 void UpCase(char *mixedcase);
190 int GetSection(int type);
191 int GetSectionByAddress(int address);
192 int GetRealSectionByAddress(int address);
193 int GetSectionLEAddress(int address);
194
195 BOOL IsEXE, fConsole;
196 ULONG EntryAddress;
197 Section PESection[MAX_SECTION];
198 Section ResSection;
199 DataPage *datapage;
200
201 char *impmodules, *impnames, *impnameoff;
202 int impmodulesize, impnamesize;
203 int fFlags;
204 int StackSize;
205 int nrsections;
206
207 namefixup *impfixuprec;
208 int nrimpfixups;
209
210 intfixup *intfixuprec;
211 int nrintfixups;
212
213 rsrc32 *os2resource;
214 int nrresources;
215 int curresource;
216 NameId *cvtname, *curcvtname;
217 int nrcvtnames;
218 int *resids;
219 int nrids;
220 int cvtnametableid;
221 int orgrestableid;
222 ULONG *orgrestable;
223 int nrorgres;
224
225 char *exports, *curexport;
226 int nrexports;
227 exportbundle *expbundle, *curexpb;
228
229 char modulename[128];
230
231 struct e32_exe LXHdr;
232
233 static int uniqueId;
234
235 int kernel32Object;
236
237 //SvL: 18-7-'98: Version resource id
238 ULONG VersionResourceId;
239
240 unsigned char *szTIBFix;
241 int TIBSize;
242 int TIBOffEntry;
243 int TIBOffCall;
244 int TIBOffName;
245 int TIBOffKerImport;
246 //SvL: 18-7-'98: Internal pe2lx version and version resource id offsets
247 int TIBOffPe2lxVer;
248 int TIBOffVerResId;
249};
250
251extern LXHeader OS2Exe;
252
253#endif
Note: See TracBrowser for help on using the repository browser.