source: trunk/src/kernel32/winimagepeldr_new.h@ 5841

Last change on this file since 5841 was 5841, checked in by phaller, 24 years ago

.

File size: 5.3 KB
Line 
1/* $Id: winimagepeldr_new.h,v 1.2 2001-05-30 18:32:15 phaller Exp $ */
2
3/*
4 * Win32 PE loader Image base class
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#ifndef __WINIMAGEPELDR_H__
13#define __WINIMAGEPELDR_H__
14
15#include <winimagebase.h>
16
17
18// 2001-05-30 PH
19// to enable sanity checks for the new loader code,
20// enable this define.
21//#define VERIFY_LOADER
22
23
24#define SINGLE_PAGE 0 //commit single page
25#define COMPLETE_SECTION 1 //commit entire section
26#define SECTION_PAGES 2 //commit default nr of pages
27
28#define DEFAULT_NR_PAGES 16 //default nr of pages to commit during exception
29
30//SvL: To load a dll/exe for i.e. getting a single resource (GetVersionSize/Resource)
31#define FLAG_PELDR_LOADASDATAFILE 1 //also implies FLAG_PELDR_SKIPIMPORTS
32#define FLAG_PELDR_SKIPIMPORTS 2
33
34//SvL: Amount of memory the peldr dll reserves for win32 exes without fixups
35//(most of them need to be loaded at 4 MB; except MS Office apps of course)
36#define PELDR_RESERVEDMEMSIZE 32*1024*1024
37
38#define ERROR_INTERNAL 1
39
40#define SECTION_CODE 1
41#define SECTION_INITDATA 2
42#define SECTION_UNINITDATA 4
43#define SECTION_READONLYDATA 8
44#define SECTION_IMPORT 16
45#define SECTION_RESOURCE 32
46#define SECTION_RELOC 64
47#define SECTION_EXPORT 128
48#define SECTION_DEBUG 256
49#define SECTION_TLS 512
50
51#define PAGE_SIZE 4096
52
53typedef struct {
54 ULONG rawoffset;
55 ULONG rawsize;
56 ULONG virtaddr;
57 ULONG realvirtaddr; //as allocated in OS/2
58 ULONG virtualsize;
59 ULONG type;
60 ULONG pageflags;
61 ULONG flags; //psh[i].Characteristics
62} Section;
63
64
65#ifdef VERIFY_LOADER
66typedef struct {
67 ULONG virtaddr;
68 ULONG ordinal;
69 ULONG nlength;
70 char name[4];
71} NameExport;
72
73typedef struct {
74 ULONG virtaddr;
75 ULONG ordinal;
76} OrdExport;
77#endif
78
79class Win32DllBase;
80class Win32MemMap;
81class CIndexLookupLimit;
82class CHashtableLookup;
83
84
85class Win32PeLdrImage : public virtual Win32ImageBase
86{
87public:
88 Win32PeLdrImage(char *szFileName, BOOL isExe);
89virtual ~Win32PeLdrImage();
90
91 //reservedMem is address of memory reserved in peldr.dll (allocated before
92 //any dlls are loaded, so that exes without fixups can be loaded at a low
93 //address)
94 virtual BOOL init(ULONG reservedMem);
95
96 virtual BOOL insideModule(ULONG address);
97 virtual BOOL insideModuleCode(ULONG address);
98
99 virtual ULONG getApi(char *name);
100 virtual ULONG getApi(int ordinal);
101
102#ifdef VERIFY_LOADER
103 virtual ULONG new_getApi(char *name);
104 virtual ULONG new_getApi(int ordinal);
105 virtual ULONG old_getApi(char *name);
106 virtual ULONG old_getApi(int ordinal);
107#endif
108
109 virtual ULONG getImageSize();
110
111 //Returns required OS version for this image
112 virtual ULONG getVersion();
113
114 //tell loader to only process resources and ignore the rest
115 void setLoadAsDataFile() { dwFlags |= FLAG_PELDR_LOADASDATAFILE; };
116 void disableImportHandling() { dwFlags |= FLAG_PELDR_SKIPIMPORTS; };
117
118 //commits image page(s) when an access violation exception is dispatched
119 BOOL commitPage(ULONG virtAddress, BOOL fWriteAccess, int fPageCmd = SECTION_PAGES);
120
121protected:
122 void StoreImportByOrd(Win32ImageBase *WinImage, ULONG ordinal, ULONG impaddr);
123 void StoreImportByName(Win32ImageBase *WinImage, char *impname, ULONG impaddr);
124
125 void addSection(ULONG type, ULONG rawoffset, ULONG rawsize, ULONG virtaddress, ULONG virtsize, ULONG flags);
126 BOOL allocSections(ULONG reservedMem);
127 BOOL allocFixedMem(ULONG reservedMem);
128 Section *findSection(ULONG type);
129 Section *findSectionByAddr(ULONG addr);
130 Section *findSectionByOS2Addr(ULONG addr);
131 Section *findPreviousSectionByOS2Addr(ULONG addr);
132
133 BOOL setMemFlags();
134 BOOL setFixups(PIMAGE_BASE_RELOCATION prel);
135 BOOL setFixups(ULONG virtAddress, ULONG size);
136 void AddOff32Fixup(ULONG fixupaddr);
137 void AddOff16Fixup(ULONG fixupaddr, BOOL fHighFixup);
138
139 BOOL processImports(char *win32file);
140
141 BOOL processExports(char *win32file);
142 void AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal, BOOL fAbsoluteAddress=FALSE);
143 void AddOrdExport(ULONG virtaddr, ULONG ordinal, BOOL fAbsoluteAddress=FALSE);
144 BOOL AddForwarder(ULONG virtaddr, char *apiname, ULONG ordinal);
145
146Win32DllBase *loadDll(char *pszCurModule);
147
148 IMAGE_OPTIONAL_HEADER oh;
149 IMAGE_FILE_HEADER fh;
150
151 ULONG nrNameExports, nameExportSize;
152 ULONG nrOrdExports;
153
154#ifdef VERIFY_LOADER
155 NameExport *nameexports, *curnameexport;
156 OrdExport *ordexports, *curordexport;
157#endif
158
159 ULONG nrsections, imageSize, imageVirtBase, imageVirtEnd;
160 //OS/2 virtual base address
161 ULONG realBaseAddress;
162 Section *section;
163
164 //internal flags (see FLAGS_PELDR_*)
165 DWORD dwFlags;
166
167 HFILE hFile;
168
169 PIMAGE_BASE_RELOCATION pFixups;
170 DWORD dwFixupSize;
171
172 Win32MemMap *memmap;
173
174 CIndexLookupLimit *pLookupOrdinal;
175 CHashtableLookup *pLookupName;
176private:
177};
178
179#endif //__WINIMAGEPELDR_H__
180
Note: See TracBrowser for help on using the repository browser.