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

Last change on this file since 201 was 97, checked in by phaller, 26 years ago

Add: added cvs variable $Id$ to source files.

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