1 | /* $Id: winimagepeldr.h,v 1.2 1999-09-18 17:45:23 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 | //SvL: Amount of memory the peldr dll reserves for win32 exes without fixups
|
---|
18 | //(most of them need to be loaded at 4 MB; except MS Office apps of course)
|
---|
19 | #define PELDR_RESERVEDMEMSIZE 16*1024*1024
|
---|
20 |
|
---|
21 | #define ERROR_INTERNAL 1
|
---|
22 |
|
---|
23 | #define SECTION_CODE 1
|
---|
24 | #define SECTION_INITDATA 2
|
---|
25 | #define SECTION_UNINITDATA 4
|
---|
26 | #define SECTION_READONLYDATA 8
|
---|
27 | #define SECTION_IMPORT 16
|
---|
28 | #define SECTION_RESOURCE 32
|
---|
29 | #define SECTION_RELOC 64
|
---|
30 | #define SECTION_EXPORT 128
|
---|
31 | #define SECTION_DEBUG 256
|
---|
32 | #define SECTION_TLS 512
|
---|
33 |
|
---|
34 | #define PAGE_SIZE 4096
|
---|
35 |
|
---|
36 | #define MAX_SECTION 64 /*PLF Mon 98-02-09 23:47:16*/
|
---|
37 |
|
---|
38 | typedef struct {
|
---|
39 | char *rawdata;
|
---|
40 | ULONG rawsize;
|
---|
41 | ULONG virtaddr;
|
---|
42 | ULONG realvirtaddr; //as allocated in OS/2
|
---|
43 | ULONG virtualsize;
|
---|
44 | ULONG type;
|
---|
45 | } Section;
|
---|
46 |
|
---|
47 | typedef struct {
|
---|
48 | ULONG virtaddr;
|
---|
49 | ULONG ordinal;
|
---|
50 | ULONG nlength;
|
---|
51 | char name[4];
|
---|
52 | } NameExport;
|
---|
53 |
|
---|
54 | typedef struct {
|
---|
55 | ULONG virtaddr;
|
---|
56 | ULONG ordinal;
|
---|
57 | } OrdExport;
|
---|
58 |
|
---|
59 | class Win32DllBase;
|
---|
60 |
|
---|
61 | class Win32PeLdrImage : public virtual Win32ImageBase
|
---|
62 | {
|
---|
63 | public:
|
---|
64 | Win32PeLdrImage(char *szFileName);
|
---|
65 | virtual ~Win32PeLdrImage();
|
---|
66 |
|
---|
67 | //reservedMem is address of memory reserved in peldr.dll (allocated before
|
---|
68 | //any dlls are loaded, so that exes without fixups can be loaded at a low
|
---|
69 | //address)
|
---|
70 | virtual BOOL init(ULONG reservedMem);
|
---|
71 |
|
---|
72 | protected:
|
---|
73 | void StoreImportByOrd(Win32DllBase *WinDll, ULONG ordinal, ULONG impaddr);
|
---|
74 | void StoreImportByName(Win32DllBase *WinDll, char *impname, ULONG impaddr);
|
---|
75 |
|
---|
76 | void addSection(ULONG type, char *rawdata, ULONG rawsize, ULONG virtaddress, ULONG virtsize);
|
---|
77 | BOOL allocSections(ULONG reservedMem);
|
---|
78 | BOOL allocFixedMem(ULONG reservedMem);
|
---|
79 | Section *findSection(ULONG type);
|
---|
80 | Section *findSectionByAddr(ULONG addr);
|
---|
81 |
|
---|
82 | BOOL storeSections(char *win32file);
|
---|
83 | BOOL setMemFlags();
|
---|
84 | BOOL setFixups(PIMAGE_BASE_RELOCATION prel);
|
---|
85 | void AddOff32Fixup(ULONG fixupaddr);
|
---|
86 | void AddOff16Fixup(ULONG fixupaddr, BOOL fHighFixup);
|
---|
87 |
|
---|
88 | BOOL processImports(char *win32file);
|
---|
89 |
|
---|
90 | BOOL processExports(char *win32file);
|
---|
91 | void AddNameExport(ULONG virtaddr, char *apiname, ULONG ordinal);
|
---|
92 | void AddOrdExport(ULONG virtaddr, ULONG ordinal);
|
---|
93 |
|
---|
94 | Section *pResSection;
|
---|
95 |
|
---|
96 | IMAGE_OPTIONAL_HEADER oh;
|
---|
97 | IMAGE_FILE_HEADER fh;
|
---|
98 |
|
---|
99 | ULONG nrNameExports, nameExportSize;
|
---|
100 | ULONG nrOrdExports;
|
---|
101 | NameExport *nameexports, *curnameexport;
|
---|
102 | OrdExport *ordexports, *curordexport;
|
---|
103 |
|
---|
104 | ULONG nrsections, imageSize, imageVirtBase, imageVirtEnd;
|
---|
105 | //OS/2 virtual base address
|
---|
106 | ULONG realBaseAddress;
|
---|
107 | Section section[MAX_SECTION];
|
---|
108 |
|
---|
109 | private:
|
---|
110 | };
|
---|
111 |
|
---|
112 | #include <iostream.h>
|
---|
113 | #include <fstream.h>
|
---|
114 | extern ofstream fout;
|
---|
115 |
|
---|
116 | #endif //__WINIMAGEPELDR_H__
|
---|
117 |
|
---|