|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Class for E32 Image implementation and dump of the elf2e32 tool |
|
15 // @internalComponent |
|
16 // @released |
|
17 // |
|
18 // |
|
19 |
|
20 #ifndef E32IMAGEFILE_H |
|
21 #define E32IMAGEFILE_H |
|
22 |
|
23 #include "pl_elfrelocation.h" |
|
24 #include "pl_elfrelocations.h" |
|
25 #include "e32imagedefs.h" |
|
26 #include "elfdefs.h" |
|
27 |
|
28 #include <fstream> |
|
29 #include <vector> |
|
30 using std::vector; |
|
31 #include <iostream> |
|
32 using std::ifstream; |
|
33 |
|
34 #include <e32std.h> |
|
35 |
|
36 enum TFileSource |
|
37 { |
|
38 EE32Image=0, |
|
39 EPeFile=1, |
|
40 EElfFile=2, |
|
41 }; |
|
42 |
|
43 class ELFExecutable; |
|
44 class ElfFileSupplied; |
|
45 |
|
46 /** |
|
47 Class E32ImageChunkDesc for different sections in the E32 image. |
|
48 @internalComponent |
|
49 @released |
|
50 */ |
|
51 class E32ImageChunkDesc |
|
52 { |
|
53 public: |
|
54 E32ImageChunkDesc(char * aData, size_t aSize, size_t aOffset, char * aDoc); |
|
55 virtual ~E32ImageChunkDesc(); |
|
56 virtual void Write(char * aPlace); |
|
57 |
|
58 public: |
|
59 char * iData; |
|
60 size_t iSize; |
|
61 size_t iOffset; |
|
62 char * iDoc; |
|
63 }; |
|
64 |
|
65 /** |
|
66 Class E32ImageChunks for a list of sections in the E32 image. |
|
67 @internalComponent |
|
68 @released |
|
69 */ |
|
70 class E32ImageChunks |
|
71 { |
|
72 public: |
|
73 |
|
74 typedef vector<E32ImageChunkDesc *> ChunkList; |
|
75 |
|
76 public: |
|
77 E32ImageChunks(); |
|
78 virtual ~E32ImageChunks(); |
|
79 |
|
80 void AddChunk(char * aData, size_t aSize, size_t aOffset, char * aDoc); |
|
81 size_t GetOffset(); |
|
82 void SetOffset(size_t aOffset); |
|
83 ChunkList & GetChunks(); |
|
84 |
|
85 public: |
|
86 ChunkList iChunks; |
|
87 |
|
88 size_t iOffset; |
|
89 |
|
90 }; |
|
91 |
|
92 class ElfFileSupplied; |
|
93 |
|
94 /** |
|
95 Class E32ImageFile for fields of an E32 image. |
|
96 @internalComponent |
|
97 @released |
|
98 */ |
|
99 class E32ImageFile |
|
100 { |
|
101 public: |
|
102 |
|
103 typedef unsigned char uint8; |
|
104 typedef unsigned short uint16; |
|
105 typedef unsigned long uint32; |
|
106 struct E32RelocPageDesc |
|
107 { |
|
108 uint32 aOffset; |
|
109 uint32 aSize; |
|
110 }; |
|
111 |
|
112 //public: |
|
113 E32ImageFile(const char * aFileName, ElfExecutable * aExecutable, ElfFileSupplied * aUseCase); |
|
114 virtual ~E32ImageFile(); |
|
115 |
|
116 void GenerateE32Image(); |
|
117 |
|
118 void ReadInputELFFile(const char * aName, size_t & aFileSize, Elf32_Ehdr * & aELFFile ); |
|
119 |
|
120 void ProcessImports(); |
|
121 const char * FindDSO(const char * aName); |
|
122 |
|
123 void ProcessRelocations(); |
|
124 void ProcessCodeRelocations(); |
|
125 void ProcessDataRelocations(); |
|
126 void CreateRelocations(ElfRelocations::RelocationList & aRelocList, char * & aRelocs, size_t & aRelocSize); |
|
127 size_t RelocationsSize(ElfRelocations::RelocationList & aRelocList); |
|
128 |
|
129 uint16 GetE32RelocType(ElfRelocation * aReloc); |
|
130 |
|
131 void ConstructImage(); |
|
132 |
|
133 virtual void InitE32ImageHeader(); |
|
134 virtual size_t GetE32ImageHeaderSize(); |
|
135 virtual size_t GetExtendedE32ImageHeaderSize(); |
|
136 virtual void SetExtendedE32ImageHeaderSize(size_t aSize); |
|
137 |
|
138 virtual void ComputeE32ImageLayout(); |
|
139 virtual size_t GetE32ImageSize(); |
|
140 virtual size_t GetExportOffset(); |
|
141 virtual void CreateExportBitMap(); |
|
142 virtual void AddExportDescription(); |
|
143 |
|
144 virtual void AllocateE32Image(); |
|
145 virtual void FinalizeE32Image(); |
|
146 virtual uint16 GetCpuIdentifier(); |
|
147 virtual uint32 EntryPointOffset(); |
|
148 |
|
149 enum EEntryPointStatus |
|
150 { |
|
151 EEntryPointOK, |
|
152 EEntryPointCorrupt, |
|
153 EEntryPointNotSupported |
|
154 }; |
|
155 |
|
156 EEntryPointStatus ValidateEntryPoint(); |
|
157 |
|
158 virtual void SetUpExceptions(); |
|
159 virtual void SetUids(); |
|
160 virtual void SetSecureId(); |
|
161 virtual void SetVendorId(); |
|
162 virtual void SetCallEntryPoints(); |
|
163 virtual void SetCapability(); |
|
164 virtual void SetPriority(bool isDllp); |
|
165 virtual void SetFixedAddress(bool isDllp); |
|
166 virtual void SetVersion(); |
|
167 virtual void SetCompressionType(); |
|
168 virtual void SetFPU(); |
|
169 virtual void SetPaged(); |
|
170 virtual void SetSymbolLookup(); |
|
171 virtual void SetDebuggable(); |
|
172 virtual void SetSmpSafe(); |
|
173 |
|
174 void UpdateHeaderCrc(); |
|
175 |
|
176 bool WriteImage(const char * aName); |
|
177 |
|
178 public: |
|
179 const char * iFileName; |
|
180 |
|
181 char * iE32Image; |
|
182 uint8 * iExportBitMap; |
|
183 ElfExecutable * iElfExecutable; |
|
184 std::vector<char*> cleanupStack; |
|
185 char* iData; |
|
186 ElfFileSupplied * iUseCase; |
|
187 E32ImageHeaderV * iHdr; |
|
188 size_t iHdrSize; |
|
189 |
|
190 E32ImageChunks iChunks; |
|
191 |
|
192 uint32 iNumDlls; |
|
193 uint32 iNumImports; |
|
194 |
|
195 uint32 * iImportSection; |
|
196 size_t iImportSectionSize; |
|
197 |
|
198 char * iCodeRelocs; |
|
199 size_t iCodeRelocsSize; |
|
200 |
|
201 char * iDataRelocs; |
|
202 size_t iDataRelocsSize; |
|
203 |
|
204 size_t iExportOffset; |
|
205 bool iLayoutDone; |
|
206 |
|
207 int iMissingExports; |
|
208 |
|
209 // This table carries the byte offsets in the import table entries corresponding |
|
210 // to the 0th ordinal entry of static dependencies. |
|
211 std::vector<int> iImportTabLocations; |
|
212 std::vector<uint32> iSymAddrTab; |
|
213 std::vector<uint32> iSymNameOffTab; |
|
214 std::string iSymbolNames; |
|
215 uint32 iSymNameOffset; |
|
216 |
|
217 public: |
|
218 E32ImageFile(); |
|
219 TInt ReadHeader(ifstream& is); |
|
220 TInt Open(const char* aFileName); |
|
221 void Adjust(TInt aSize, TBool aAllowShrink=ETrue); |
|
222 |
|
223 TUint TextOffset(); |
|
224 TUint DataOffset(); |
|
225 TUint BssOffset(); |
|
226 TUint32 Capability(); |
|
227 TUint32 Format(); |
|
228 |
|
229 void Dump(TText *aFileName,TInt aDumpFlags); |
|
230 void DumpHeader(TInt aDumpFlags); |
|
231 void DumpData(TInt aDumpFlags); |
|
232 void DumpSymbolInfo(E32EpocExpSymInfoHdr *aSymInfoHdr); |
|
233 void E32ImageExportBitMap(); |
|
234 TInt CheckExportDescription(); |
|
235 void ProcessSymbolInfo(); |
|
236 char* CreateSymbolInfo(size_t aBaseOffset); |
|
237 void SetSymInfo(E32EpocExpSymInfoHdr& aSymInfo); |
|
238 public: |
|
239 inline TUint OrigCodeOffset() const {return OffsetUnadjust(iOrigHdr->iCodeOffset);} |
|
240 inline TUint OrigDataOffset() const {return OffsetUnadjust(iOrigHdr->iDataOffset);} |
|
241 inline TUint OrigCodeRelocOffset() const {return OffsetUnadjust(iOrigHdr->iCodeRelocOffset);} |
|
242 inline TUint OrigDataRelocOffset() const {return OffsetUnadjust(iOrigHdr->iDataRelocOffset);} |
|
243 inline TUint OrigImportOffset() const {return OffsetUnadjust(iOrigHdr->iImportOffset);} |
|
244 inline TUint OrigExportDirOffset() const {return OffsetUnadjust(iOrigHdr->iExportDirOffset);} |
|
245 inline TUint OffsetUnadjust(TUint a) const {return a ? a-iOrigHdrOffsetAdj : 0;} |
|
246 inline void OffsetAdjust(TUint& a) { if (a) a+=iOrigHdrOffsetAdj; } |
|
247 |
|
248 public: |
|
249 |
|
250 TInt iSize; |
|
251 E32ImageHeader* iOrigHdr; |
|
252 TInt iError; |
|
253 TFileSource iSource; |
|
254 TUint iOrigHdrOffsetAdj; |
|
255 TInt iFileSize; |
|
256 |
|
257 }; |
|
258 |
|
259 ifstream &operator>>(ifstream &is, E32ImageFile &aImage); |
|
260 void InflateUnCompress(unsigned char* source, int sourcesize, unsigned char* dest, int destsize); |
|
261 |
|
262 |
|
263 #endif // E32IMAGEFILE_H |
|
264 |
|
265 |