source: trunk/include/winimagepeldr.h@ 1857

Last change on this file since 1857 was 1843, checked in by sandervl, 26 years ago

MS Word fixes + changes

File size: 4.1 KB
Line 
1/* $Id: winimagepeldr.h,v 1.7 1999-11-26 00:04:33 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 REAL_LOAD 0
25#define RSRC_LOAD 1
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 16*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} Section;
57
58typedef struct {
59 ULONG virtaddr;
60 ULONG ordinal;
61 ULONG nlength;
62 char name[4];
63} NameExport;
64
65typedef struct {
66 ULONG virtaddr;
67 ULONG ordinal;
68} OrdExport;
69
70class Win32DllBase;
71class Win32MemMap;
72
73class Win32PeLdrImage : public virtual Win32ImageBase
74{
75public:
76 Win32PeLdrImage(char *szFileName, BOOL isExe, int loadtype = REAL_LOAD);
77virtual ~Win32PeLdrImage();
78
79 //reservedMem is address of memory reserved in peldr.dll (allocated before
80 //any dlls are loaded, so that exes without fixups can be loaded at a low
81 //address)
82virtual BOOL init(ULONG reservedMem);
83
84 virtual ULONG getApi(char *name);
85 virtual ULONG getApi(int ordinal);
86
87 //commits image page(s) when an access violation exception is dispatched
88 BOOL commitPage(ULONG virtAddress, BOOL fWriteAccess, int fPageCmd = SECTION_PAGES);
89
90protected:
91 void StoreImportByOrd(Win32DllBase *WinDll, ULONG ordinal, ULONG impaddr);
92 void StoreImportByName(Win32DllBase *WinDll, char *impname, ULONG impaddr);
93
94 void addSection(ULONG type, ULONG rawoffset, ULONG rawsize, ULONG virtaddress, ULONG virtsize);
95 BOOL allocSections(ULONG reservedMem);
96 BOOL allocFixedMem(ULONG reservedMem);
97 Section *findSection(ULONG type);
98 Section *findSectionByAddr(ULONG addr);
99 Section *findSectionByOS2Addr(ULONG addr);
100 Section *findPreviousSectionByOS2Addr(ULONG addr);
101
102 BOOL setMemFlags();
103 BOOL setFixups(PIMAGE_BASE_RELOCATION prel);
104 BOOL setFixups(ULONG virtAddress, ULONG size);
105 void AddOff32Fixup(ULONG fixupaddr);
106 void AddOff16Fixup(ULONG fixupaddr, BOOL fHighFixup);
107
108 BOOL processImports(char *win32file);
109
110 BOOL processExports(char *win32file);
111 void AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal);
112 void AddOrdExport(ULONG virtaddr, ULONG ordinal);
113
114 IMAGE_OPTIONAL_HEADER oh;
115 IMAGE_FILE_HEADER fh;
116
117 ULONG nrNameExports, nameExportSize;
118 ULONG nrOrdExports;
119 NameExport *nameexports, *curnameexport;
120 OrdExport *ordexports, *curordexport;
121
122 ULONG nrsections, imageSize, imageVirtBase, imageVirtEnd;
123 //OS/2 virtual base address
124 ULONG realBaseAddress;
125 Section section[MAX_SECTION];
126
127 ULONG loadType;
128
129 HFILE hFile;
130
131 PIMAGE_BASE_RELOCATION pFixups;
132
133 Win32MemMap *memmap;
134private:
135};
136
137#include <iostream.h>
138#include <fstream.h>
139extern ofstream fout;
140
141#endif //__WINIMAGEPELDR_H__
142
Note: See TracBrowser for help on using the repository browser.