source: trunk/src/kernel32/winimagepeldr.h@ 5855

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

Revert to old but optimized loader

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