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

Last change on this file since 5837 was 5837, checked in by sandervl, 24 years ago

put back old lookup code; renamed new files

File size: 4.7 KB
Line 
1/* $Id: winimagepeldr_new.h,v 1.1 2001-05-30 08:23:22 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
46typedef struct {
47 ULONG rawoffset;
48 ULONG rawsize;
49 ULONG virtaddr;
50 ULONG realvirtaddr; //as allocated in OS/2
51 ULONG virtualsize;
52 ULONG type;
53 ULONG pageflags;
54 ULONG flags; //psh[i].Characteristics
55} Section;
56
57class Win32DllBase;
58class Win32MemMap;
59class CIndexLookupLimit;
60class CHashtableLookup;
61
62
63class Win32PeLdrImage : public virtual Win32ImageBase
64{
65public:
66 Win32PeLdrImage(char *szFileName, BOOL isExe);
67virtual ~Win32PeLdrImage();
68
69 //reservedMem is address of memory reserved in peldr.dll (allocated before
70 //any dlls are loaded, so that exes without fixups can be loaded at a low
71 //address)
72 virtual BOOL init(ULONG reservedMem);
73
74 virtual BOOL insideModule(ULONG address);
75 virtual BOOL insideModuleCode(ULONG address);
76
77 virtual ULONG getApi(char *name);
78 virtual ULONG getApi(int ordinal);
79
80 virtual ULONG getImageSize();
81
82 //Returns required OS version for this image
83 virtual ULONG getVersion();
84
85 //tell loader to only process resources and ignore the rest
86 void setLoadAsDataFile() { dwFlags |= FLAG_PELDR_LOADASDATAFILE; };
87 void disableImportHandling() { dwFlags |= FLAG_PELDR_SKIPIMPORTS; };
88
89 //commits image page(s) when an access violation exception is dispatched
90 BOOL commitPage(ULONG virtAddress, BOOL fWriteAccess, int fPageCmd = SECTION_PAGES);
91
92protected:
93 void StoreImportByOrd(Win32ImageBase *WinImage, ULONG ordinal, ULONG impaddr);
94 void StoreImportByName(Win32ImageBase *WinImage, char *impname, ULONG impaddr);
95
96 void addSection(ULONG type, ULONG rawoffset, ULONG rawsize, ULONG virtaddress, ULONG virtsize, ULONG flags);
97 BOOL allocSections(ULONG reservedMem);
98 BOOL allocFixedMem(ULONG reservedMem);
99 Section *findSection(ULONG type);
100 Section *findSectionByAddr(ULONG addr);
101 Section *findSectionByOS2Addr(ULONG addr);
102 Section *findPreviousSectionByOS2Addr(ULONG addr);
103
104 BOOL setMemFlags();
105 BOOL setFixups(PIMAGE_BASE_RELOCATION prel);
106 BOOL setFixups(ULONG virtAddress, ULONG size);
107 void AddOff32Fixup(ULONG fixupaddr);
108 void AddOff16Fixup(ULONG fixupaddr, BOOL fHighFixup);
109
110 BOOL processImports(char *win32file);
111
112 BOOL processExports(char *win32file);
113 void AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal, BOOL fAbsoluteAddress=FALSE);
114 void AddOrdExport(ULONG virtaddr, ULONG ordinal, BOOL fAbsoluteAddress=FALSE);
115 BOOL AddForwarder(ULONG virtaddr, char *apiname, ULONG ordinal);
116
117 Win32DllBase *loadDll(char *pszCurModule);
118
119 IMAGE_OPTIONAL_HEADER oh;
120 IMAGE_FILE_HEADER fh;
121
122 ULONG nrNameExports, nameExportSize;
123 ULONG nrOrdExports;
124
125 ULONG nrsections, imageSize, imageVirtBase, imageVirtEnd;
126 //OS/2 virtual base address
127 ULONG realBaseAddress;
128 Section *section;
129
130 //internal flags (see FLAGS_PELDR_*)
131 DWORD dwFlags;
132
133 HFILE hFile;
134
135 PIMAGE_BASE_RELOCATION pFixups;
136 DWORD dwFixupSize;
137
138 Win32MemMap *memmap;
139
140 CIndexLookupLimit *pLookupOrdinal;
141 CHashtableLookup *pLookupName;
142private:
143};
144
145#endif //__WINIMAGEPELDR_H__
146
Note: See TracBrowser for help on using the repository browser.