|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU Lesser General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Lesser General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #ifndef ELFSECTION_H_ |
|
20 #define ELFSECTION_H_ |
|
21 |
|
22 #include <libelf.h> |
|
23 |
|
24 #include "defs.h" // for String |
|
25 |
|
26 #include "filefragment.h" |
|
27 #include "inputfile.h" |
|
28 |
|
29 class ElfSectionHeader { |
|
30 public: |
|
31 ElfSectionHeader() |
|
32 {} |
|
33 |
|
34 ElfSectionHeader(Elf32_Shdr & aShdr) : |
|
35 iElf32Shdr(aShdr) |
|
36 {} |
|
37 |
|
38 Elf32_Shdr iElf32Shdr; |
|
39 }; |
|
40 |
|
41 class ElfSectionData : public FileFragmentOwner { |
|
42 public: |
|
43 ElfSectionData() |
|
44 {} |
|
45 ElfSectionData(size_t aOffset): |
|
46 FileFragmentOwner(aOffset) |
|
47 {} |
|
48 virtual ElfSectionData * Clone() = 0; |
|
49 |
|
50 // The FileFragmentOwner protocol |
|
51 virtual void GetFileFragmentData(FileFragmentData & aFileFragmentData ) = 0; |
|
52 virtual size_t Size() = 0; |
|
53 virtual void DeleteFileFragmentData() = 0; |
|
54 |
|
55 |
|
56 }; |
|
57 |
|
58 class ElfSectionRomData : public ElfSectionData { |
|
59 public: |
|
60 ElfSectionRomData(size_t aOffset, size_t aSize) : |
|
61 ElfSectionData(aOffset), |
|
62 iSize(aSize) |
|
63 {} |
|
64 |
|
65 ElfSectionRomData(const ElfSectionRomData & aData); |
|
66 |
|
67 // ElfSection protocol |
|
68 virtual ElfSectionRomData * Clone(); |
|
69 |
|
70 // The FileFragmentOwner protocol |
|
71 virtual void GetFileFragmentData(FileFragmentData & aFileFragmentData ){} |
|
72 virtual size_t Size(){ return iSize; } |
|
73 // Nothing to delete |
|
74 virtual void DeleteFileFragmentData(){}; |
|
75 // Dont add data; |
|
76 virtual void AddData(OutputFile & aOutputFile) {}; |
|
77 |
|
78 private: |
|
79 size_t iSize; |
|
80 }; |
|
81 |
|
82 class ElfSectionElfData : public ElfSectionData { |
|
83 public: |
|
84 ElfSectionElfData(FileFragmentOwner & aSource) : |
|
85 iSource(aSource) |
|
86 {} |
|
87 |
|
88 ElfSectionElfData(const ElfSectionElfData & aData); |
|
89 |
|
90 // ElfSection protocol |
|
91 virtual ElfSectionElfData * Clone(); |
|
92 |
|
93 // The FileFragmentOwner protocol |
|
94 virtual void GetFileFragmentData(FileFragmentData & aFileFragmentData ); |
|
95 virtual size_t Size(); |
|
96 virtual void DeleteFileFragmentData(); |
|
97 virtual void AddData(OutputFile & aOutputFile); |
|
98 virtual size_t GetOffset(); |
|
99 |
|
100 private: |
|
101 FileFragmentOwner & iSource; |
|
102 }; |
|
103 |
|
104 class ElfSectionFileData : public ElfSectionData { |
|
105 public: |
|
106 ElfSectionFileData(InputFile * aInputFile) : |
|
107 iInputFile(aInputFile), iData(NULL) |
|
108 {} |
|
109 ElfSectionFileData(const ElfSectionFileData & aData); |
|
110 |
|
111 // ElfSection protocol |
|
112 virtual ElfSectionFileData * Clone(); |
|
113 |
|
114 // The FileFragmentOwner protocol |
|
115 virtual void GetFileFragmentData(FileFragmentData & aFileFragmentData ); |
|
116 virtual size_t Size(); |
|
117 virtual void DeleteFileFragmentData(); |
|
118 |
|
119 private: |
|
120 InputFile * iInputFile; |
|
121 char * iData; |
|
122 }; |
|
123 |
|
124 class ElfSectionNoData : public ElfSectionData { |
|
125 public: |
|
126 ElfSectionNoData(){} |
|
127 |
|
128 ElfSectionNoData(const ElfSectionNoData & aData); |
|
129 |
|
130 // ElfSection protocol |
|
131 virtual ElfSectionNoData * Clone(); |
|
132 |
|
133 // The FileFragmentOwner protocol |
|
134 virtual void GetFileFragmentData(FileFragmentData & aFileFragmentData ); |
|
135 virtual size_t Size() { return 0; } |
|
136 // Nothing to delete |
|
137 virtual void DeleteFileFragmentData(){}; |
|
138 // Dont add data; |
|
139 virtual void AddData(OutputFile & aOutputFile) {}; |
|
140 |
|
141 |
|
142 |
|
143 private: |
|
144 InputFile * iInputFile; |
|
145 }; |
|
146 |
|
147 class ElfSection { |
|
148 public: |
|
149 ElfSection(ElfSectionData * aData) : |
|
150 iSectionName(""), iSectionData(aData), iIndex(0) |
|
151 {} |
|
152 |
|
153 ElfSection(ElfSectionData * aData, String aName, Elf32_Shdr & aShdr) : |
|
154 iSectionName(aName), iSectionHdr(aShdr), iSectionData(aData) |
|
155 {} |
|
156 |
|
157 ElfSection(const ElfSection & aData); |
|
158 |
|
159 ElfSection & operator=(const ElfSection & aSection); |
|
160 |
|
161 virtual ~ElfSection(); |
|
162 |
|
163 String & GetName() { return iSectionName ; } |
|
164 void SetNameOffset(size_t nameOffset) { iSectionHdr.iElf32Shdr.sh_name = nameOffset; } |
|
165 |
|
166 ElfSectionHeader & GetSectionHeader() { return iSectionHdr; } |
|
167 |
|
168 void SetSize(size_t aSize) { iSectionHdr.iElf32Shdr.sh_size = aSize; } |
|
169 void SetOffset(size_t aOffset) { iSectionHdr.iElf32Shdr.sh_offset = aOffset; } |
|
170 |
|
171 virtual void AddData(OutputFile & aOutputFile); |
|
172 unsigned int GetIndex() { return iIndex; }; |
|
173 void SetIndex(unsigned int aIndex) { iIndex = aIndex; }; |
|
174 |
|
175 private: |
|
176 String iSectionName; |
|
177 ElfSectionHeader iSectionHdr; |
|
178 ElfSectionData * iSectionData; |
|
179 unsigned int iIndex; |
|
180 }; |
|
181 |
|
182 #endif /*ELFSECTION_H_*/ |