[2219] | 1 | /* $Id: winimagepeldr.h,v 1.10 1999-12-27 21:21:33 sandervl Exp $ */
|
---|
[953] | 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 |
|
---|
[1812] | 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 |
|
---|
[1413] | 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 |
|
---|
[953] | 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 |
|
---|
| 48 | typedef struct {
|
---|
[1812] | 49 | ULONG rawoffset;
|
---|
[953] | 50 | ULONG rawsize;
|
---|
| 51 | ULONG virtaddr;
|
---|
| 52 | ULONG realvirtaddr; //as allocated in OS/2
|
---|
| 53 | ULONG virtualsize;
|
---|
| 54 | ULONG type;
|
---|
[1812] | 55 | ULONG pageflags;
|
---|
[2219] | 56 | ULONG flags; //psh[i].Characteristics
|
---|
[953] | 57 | } Section;
|
---|
| 58 |
|
---|
| 59 | typedef struct {
|
---|
| 60 | ULONG virtaddr;
|
---|
| 61 | ULONG ordinal;
|
---|
| 62 | ULONG nlength;
|
---|
| 63 | char name[4];
|
---|
| 64 | } NameExport;
|
---|
| 65 |
|
---|
| 66 | typedef struct {
|
---|
| 67 | ULONG virtaddr;
|
---|
| 68 | ULONG ordinal;
|
---|
| 69 | } OrdExport;
|
---|
| 70 |
|
---|
| 71 | class Win32DllBase;
|
---|
[1812] | 72 | class Win32MemMap;
|
---|
[953] | 73 |
|
---|
| 74 | class Win32PeLdrImage : public virtual Win32ImageBase
|
---|
| 75 | {
|
---|
| 76 | public:
|
---|
[1833] | 77 | Win32PeLdrImage(char *szFileName, BOOL isExe, int loadtype = REAL_LOAD);
|
---|
[953] | 78 | virtual ~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 |
|
---|
[1843] | 85 | virtual ULONG getApi(char *name);
|
---|
| 86 | virtual ULONG getApi(int ordinal);
|
---|
| 87 |
|
---|
[1891] | 88 | //Returns required OS version for this image
|
---|
| 89 | virtual ULONG getVersion();
|
---|
| 90 |
|
---|
[1812] | 91 | //commits image page(s) when an access violation exception is dispatched
|
---|
| 92 | BOOL commitPage(ULONG virtAddress, BOOL fWriteAccess, int fPageCmd = SECTION_PAGES);
|
---|
| 93 |
|
---|
[953] | 94 | protected:
|
---|
[1812] | 95 | void StoreImportByOrd(Win32DllBase *WinDll, ULONG ordinal, ULONG impaddr);
|
---|
| 96 | void StoreImportByName(Win32DllBase *WinDll, char *impname, ULONG impaddr);
|
---|
[953] | 97 |
|
---|
[2219] | 98 | void addSection(ULONG type, ULONG rawoffset, ULONG rawsize, ULONG virtaddress, ULONG virtsize, ULONG flags);
|
---|
[953] | 99 | BOOL allocSections(ULONG reservedMem);
|
---|
| 100 | BOOL allocFixedMem(ULONG reservedMem);
|
---|
| 101 | Section *findSection(ULONG type);
|
---|
| 102 | Section *findSectionByAddr(ULONG addr);
|
---|
[1812] | 103 | Section *findSectionByOS2Addr(ULONG addr);
|
---|
| 104 | Section *findPreviousSectionByOS2Addr(ULONG addr);
|
---|
[953] | 105 |
|
---|
| 106 | BOOL setMemFlags();
|
---|
| 107 | BOOL setFixups(PIMAGE_BASE_RELOCATION prel);
|
---|
[1812] | 108 | BOOL setFixups(ULONG virtAddress, ULONG size);
|
---|
[953] | 109 | void AddOff32Fixup(ULONG fixupaddr);
|
---|
| 110 | void AddOff16Fixup(ULONG fixupaddr, BOOL fHighFixup);
|
---|
| 111 |
|
---|
| 112 | BOOL processImports(char *win32file);
|
---|
| 113 |
|
---|
| 114 | BOOL processExports(char *win32file);
|
---|
| 115 | void AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal);
|
---|
| 116 | void AddOrdExport(ULONG virtaddr, ULONG ordinal);
|
---|
| 117 |
|
---|
| 118 | IMAGE_OPTIONAL_HEADER oh;
|
---|
| 119 | IMAGE_FILE_HEADER fh;
|
---|
| 120 |
|
---|
| 121 | ULONG nrNameExports, nameExportSize;
|
---|
| 122 | ULONG nrOrdExports;
|
---|
| 123 | NameExport *nameexports, *curnameexport;
|
---|
| 124 | OrdExport *ordexports, *curordexport;
|
---|
| 125 |
|
---|
| 126 | ULONG nrsections, imageSize, imageVirtBase, imageVirtEnd;
|
---|
| 127 | //OS/2 virtual base address
|
---|
| 128 | ULONG realBaseAddress;
|
---|
| 129 | Section section[MAX_SECTION];
|
---|
| 130 |
|
---|
[1413] | 131 | ULONG loadType;
|
---|
| 132 |
|
---|
[1812] | 133 | HFILE hFile;
|
---|
| 134 |
|
---|
| 135 | PIMAGE_BASE_RELOCATION pFixups;
|
---|
| 136 |
|
---|
| 137 | Win32MemMap *memmap;
|
---|
[953] | 138 | private:
|
---|
| 139 | };
|
---|
| 140 |
|
---|
| 141 | #endif //__WINIMAGEPELDR_H__
|
---|
| 142 |
|
---|