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

Last change on this file since 4562 was 4474, checked in by sandervl, 25 years ago

pe loader fixes, add system32\drivers dir during installation, add build date + time during kernel32 load

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