-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathE32IMAGE.H
149 lines (144 loc) · 4.67 KB
/
E32IMAGE.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// E32IMAGE.H
//
// Copyright (c) 1996-2001 Symbian Ltd. All rights reserved.
//
#ifndef __E32IMAGE_H__
#define __E32IMAGE_H__
#include <fstream.h>
#include <e32std.h>
#include "pe_defs.h"
#include "pe_file.h"
// 4K alignment and 4 byte alignment macros
//#define ALIGN4K(a) ((a+0xfff)&0xfffff000)
//#define ALIGN4(a) ((a+0x3)&0xfffffffc)
//
const TInt KOrdinalBase=1;
const TUint KImageDll=0x01;
const TUint KImageNoCallEntryPoint=0x02;
const TUint KImageFixedAddressExe=0x04;
//
enum TCpu {ECpuUnknown=0, ECpuX86=0x1000, ECpuArm=0x2000, ECpuMCore=0x4000};
//
class E32ImageHeader
{
public:
TUint32 iUid1;
TUint32 iUid2;
TUint32 iUid3;
TUint32 iCheck;
TUint iSignature; // 'EPOC'
TCpu iCpu; // 0x1000 = X86, 0x2000 = ARM, 0x4000 = M*Core
TUint iCheckSumCode; // sum of all 32 bit words in .text
TUint iCheckSumData; // sum of all 32 bit works in .data
TVersion iVersion;
TInt64 iTime;
TUint iFlags; // 0 = exe, 1 = dll, +2 = no call entry points
TInt iCodeSize; // size of code, import address table, constant data and export dir
TInt iDataSize; // size of initialised data
TInt iHeapSizeMin;
TInt iHeapSizeMax;
TInt iStackSize;
TInt iBssSize;
TUint iEntryPoint; // offset into code of entry point
TUint iCodeBase; // where the code is linked for
TUint iDataBase; // where the data is linked for
TInt iDllRefTableCount; // filling this in enables E32ROM to leave space for it
TUint iExportDirOffset; // offset into the file of the export address table
TInt iExportDirCount;
TInt iTextSize; // size of just the text section, also doubles as the offset for the iat w.r.t. the code section
TUint iCodeOffset; // file offset to code section
TUint iDataOffset; // file offset to data section
TUint iImportOffset; // file offset to import section
TUint iCodeRelocOffset; // relocations for code and const
TUint iDataRelocOffset; // relocations for data
TProcessPriority iPriority; // priority of this process
};
//
class E32ImportBlock
{
public:
TInt Size();
public:
TUint32 iOffsetOfDllName; // offset of name of dll importing from
TInt iNumberOfImports; // number of imports from this dll
// TUint32 iImport[iNumberOfImports];
};
//
class E32ImportSection
{
public:
TInt iSize; // size of this section
// E32ImportBlock[iDllRefTableCount];
};
//
class E32RelocSection
{
public:
TInt iSize; // size of this relocation section
TInt iNumberOfRelocs; // number of relocations in this section
};
//
class E32ImageFile
{
public:
E32ImageFile();
~E32ImageFile();
TInt Open(const TText *const aFileName);
TBool Translate(PEFile &aPEFile);
TBool Translate(const TText * const aFileName, TUint aDataBase, TBool aAllowDllData);
void Adjust(TInt aSize);
TUint VaOfOrdinal(TUint aOrdinal);
void RelocateSection(char* aPtr, char *aRelocs, TUint aCodeDelta, TUint aDataDelta, char* aImagePtr, TLinAddr** aIATRefs);
//
TUint TextOffset();
TUint ImportAddressTableOffset();
TUint ConstOffset();
TUint DataOffset();
TUint BssOffset();
TUint CheckSumCode();
TUint CheckSumData();
TInt NumberOfImports();
TInt IsValid();
TInt IsDll();
void Dump(TText *aFileName);
void DumpHeader();
void DumpData();
void CreateExportName(char *aName);
void SetStackSize(TInt aSize);
void SetHeapSizeMin(TInt aSize);
void SetHeapSizeMax(TInt aSize);
void SetUids(TUid aUid1, TUid aUid2, TUid aUid3);
void SetCallEntryPoints(TInt aBool);
void SetFixedAddress(TInt aBool);
void SetPriority(TProcessPriority aPri);
static TInt IsE32ImageFile(char *aFileName);
private:
TInt DoCodeHeader(PEFile &aPeFile);
TInt DoDataHeader(PEFile &aPeFile, TUint aDataBase);
TInt CopyCode(char *aPtr, PEFile &aPeFile);
TInt CopyData(char *aPtr, PEFile &aPeFile);
TInt CopyImportAddrTable(char *aPtr, PEFile &aPeFile);
char *CreateImportSection(const PEFile &aPeFile, TInt &aSize);
void CreateExportSection(char *aPtr, PEFile &aPeFile);
void CreateExportDirectory(char *aPtr, PEFile &aPeFile);
void FixExportDirectory(TUint *aExportDir, PEFile &aPeFile);
void FixRelocs(PEFile &aPeFile, TUint *relocation, TUint *relocsection, TInt aNumberOfRelocs);
char *CreateCodeRelocs(TUint *reloc, TUint *relocsection, TInt nrelocs, TInt &aSize);
char *CreateDataRelocs(TUint *reloc, TUint *relocsection, TInt nrelocs, TInt &aSize);
TUint FixAddress(PEFile &aPeFile, TUint va);
TUint FixImportThunk(PEFile &aPeFile, TUint va);
public:
char *iData;
TInt iSize;
E32ImageHeader *iHeader;
char *iFileName;
char *iExportName;
private:
PIMAGE_SECTION_HEADER iPeHeader[KNumberOfSections];
char *iPeData[KNumberOfSections];
TUint iConstOffset;
TUint iCrtOffset;
};
ofstream &operator<<(ofstream &os, const E32ImageFile &aImage);
ifstream &operator>>(ifstream &is, E32ImageFile &aImage);
#endif