|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * SidChecker class is to |
|
16 * 1. extract all SID's from all executables present in ROM/ROFS sections. |
|
17 * 2. Validate them. |
|
18 * 3. Put the validated data into Reporter class Instance. |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 /** |
|
24 @file |
|
25 @internalComponent |
|
26 @released |
|
27 */ |
|
28 #include "sidchecker.h" |
|
29 |
|
30 /** |
|
31 Constructor. |
|
32 |
|
33 @internalComponent |
|
34 @released |
|
35 |
|
36 @param aCmdPtr - pointer to an processed CmdLineHandler object |
|
37 @param aImageReaderList - List of ImageReader insatance pointers |
|
38 */ |
|
39 SidChecker::SidChecker(CmdLineHandler* aCmdPtr, ImageReaderPtrList& aImageReaderList) |
|
40 :Checker(aCmdPtr, aImageReaderList) |
|
41 { |
|
42 iSidAll = (iCmdLine->ReportFlag() & KSidAll) ? true : false; |
|
43 iE32Mode = (iCmdLine->ReportFlag() & KE32Input) ? true : false; |
|
44 } |
|
45 |
|
46 /** |
|
47 Destructor |
|
48 |
|
49 @internalComponent |
|
50 @released |
|
51 */ |
|
52 SidChecker::~SidChecker() |
|
53 { |
|
54 iSidVsExeMap.clear(); |
|
55 } |
|
56 |
|
57 /** |
|
58 Function responsible to Prepare the ROM and ROFS image SID data |
|
59 |
|
60 @internalComponent |
|
61 @released |
|
62 |
|
63 @param ImgVsExeStatus - Global integrated container which contains image, exes and attribute value status. |
|
64 */ |
|
65 void SidChecker::Check(ImgVsExeStatus& aImgVsExeStatus) |
|
66 { |
|
67 ImageReaderPtrList::iterator begin = iImageReaderList.begin(); |
|
68 ImageReaderPtrList::iterator end = iImageReaderList.end(); |
|
69 |
|
70 ExeVsIdDataMap::iterator exeBegin; |
|
71 ExeVsIdDataMap::iterator exeEnd; |
|
72 ExeVsIdDataMap exeVsIdDataMap; |
|
73 ImageReader* imageReader = KNull; |
|
74 String imageName; |
|
75 while(begin != end) |
|
76 { |
|
77 imageReader = *begin; |
|
78 imageName = imageReader->ImageName(); |
|
79 ExceptionReporter(GATHERINGIDDATA, (char*)KSid.c_str(),(char*)imageName.c_str()).Log(); |
|
80 imageReader->PrepareExeVsIdMap(); |
|
81 |
|
82 exeVsIdDataMap = imageReader->GetExeVsIdMap(); |
|
83 exeBegin = exeVsIdDataMap.begin(); |
|
84 exeEnd = exeVsIdDataMap.end(); |
|
85 if((aImgVsExeStatus[imageName].size() == 0) |
|
86 || (aImgVsExeStatus[imageName][exeBegin->first].iIdData == KNull)) |
|
87 { |
|
88 while(exeBegin != exeEnd) |
|
89 { |
|
90 if(!iSidAll) |
|
91 { |
|
92 if(ReaderUtil::IsExe(&exeBegin->second->iUid)) |
|
93 { |
|
94 iSidVsExeMap.insert(std::make_pair(exeBegin->second->iSid, exeBegin->first)); |
|
95 } |
|
96 } |
|
97 else |
|
98 { |
|
99 iSidVsExeMap.insert(std::make_pair(exeBegin->second->iSid, exeBegin->first)); |
|
100 } |
|
101 aImgVsExeStatus[imageName][exeBegin->first].iIdData = exeBegin->second; |
|
102 aImgVsExeStatus[imageName][exeBegin->first].iExeName = exeBegin->first; |
|
103 ++exeBegin; |
|
104 } |
|
105 } |
|
106 ++begin; |
|
107 } |
|
108 } |
|
109 |
|
110 /** |
|
111 Function responsible to Validate and write the SID data into reporter. |
|
112 |
|
113 @internalComponent |
|
114 @released |
|
115 |
|
116 @param aExeContainer - Global integrated container which contains all the attribute, values and the status. |
|
117 */ |
|
118 void SidChecker::PrepareAndWriteData(ExeContainer* aExeContainer) |
|
119 { |
|
120 if(!iSidAll) |
|
121 { |
|
122 /**This map is used to find the uniqueness of the SID, instead of traversing through |
|
123 the iImgVsExeStatus again and again to get all Executables SID*/ |
|
124 if(ReaderUtil::IsExe(&aExeContainer->iIdData->iUid)) |
|
125 { |
|
126 FillExeAttribute(aExeContainer); |
|
127 } |
|
128 } |
|
129 else |
|
130 { |
|
131 FillExeAttribute(aExeContainer); |
|
132 } |
|
133 } |
|
134 |
|
135 /** |
|
136 Function responsible to Validate the executble SID. |
|
137 1. If the SID occurence across all the ROM/ROFS sections is one then the status is Unique. |
|
138 2. If more than one entry found and those executables Offset in ROM/ROFS section are same |
|
139 then its status is Unique(Alias). |
|
140 3. If those Offsets are differnt, then the status is Duplicate. |
|
141 |
|
142 @internalComponent |
|
143 @released |
|
144 |
|
145 @param aExeContainer - Global integrated container which contains all the attribute, values and the status. |
|
146 */ |
|
147 void SidChecker::FillExeSidStatus(ExeContainer* aExeContainer) |
|
148 { |
|
149 SidVsExeMap::iterator sidIter; |
|
150 unsigned int cnt = iSidVsExeMap.count(aExeContainer->iIdData->iSid); |
|
151 if(cnt > 1) //Is More than one SID exists? |
|
152 { |
|
153 sidIter = iSidVsExeMap.find(aExeContainer->iIdData->iSid); |
|
154 while(cnt > 0) |
|
155 { |
|
156 if( aExeContainer->iExeName != sidIter->second) |
|
157 { |
|
158 aExeContainer->iIdData->iSidStatus = KDuplicate; |
|
159 |
|
160 if(!iE32Mode) |
|
161 { |
|
162 unsigned int offset = GetExecutableOffset(sidIter->second); |
|
163 if(aExeContainer->iIdData->iFileOffset == offset) |
|
164 { |
|
165 aExeContainer->iIdData->iSidStatus = KUniqueAlias; |
|
166 break; |
|
167 } |
|
168 } |
|
169 } |
|
170 --cnt; |
|
171 ++sidIter; |
|
172 } |
|
173 } |
|
174 else |
|
175 { |
|
176 aExeContainer->iIdData->iSidStatus = KUnique; |
|
177 } |
|
178 } |
|
179 |
|
180 /** |
|
181 Function to get an executable's Offset location. |
|
182 1. Traverse through all the image entries available in the iImgVsExeStatus container. |
|
183 2. Get the executable Offset. |
|
184 |
|
185 @internalComponent |
|
186 @released |
|
187 |
|
188 @param aExeName - Executable's name. |
|
189 |
|
190 @return - returns 0 upon failure to find the Executable. |
|
191 - otherwise returns the Offset. |
|
192 */ |
|
193 const unsigned int SidChecker::GetExecutableOffset(const String& aExeName) |
|
194 { |
|
195 Reporter* reporter = Reporter::Instance(iCmdLine->ReportFlag()); |
|
196 ImgVsExeStatus& aImgVsExeStatus = reporter->GetContainerReference(); |
|
197 |
|
198 ImgVsExeStatus::iterator imgBegin = aImgVsExeStatus.begin(); |
|
199 ImgVsExeStatus::iterator imgEnd = aImgVsExeStatus.end(); |
|
200 |
|
201 ExeVsMetaData::iterator exeBegin; |
|
202 ExeVsMetaData::iterator exeEnd; |
|
203 |
|
204 while(imgBegin != imgEnd) |
|
205 { |
|
206 ExeVsMetaData& exeVsMetaData = imgBegin->second; |
|
207 exeBegin = exeVsMetaData.begin(); |
|
208 exeEnd = exeVsMetaData.end(); |
|
209 |
|
210 while(exeBegin != exeEnd) |
|
211 { |
|
212 if(aExeName == (exeBegin->second).iExeName) |
|
213 { |
|
214 return (exeBegin->second).iIdData->iFileOffset; |
|
215 } |
|
216 ++exeBegin; |
|
217 } |
|
218 ++imgBegin; |
|
219 } |
|
220 return 0; |
|
221 } |
|
222 |
|
223 /** |
|
224 Function responsible fill up the exe attribute list |
|
225 |
|
226 @internalComponent |
|
227 @released |
|
228 |
|
229 @param aExeContainer - Global integrated container which contains all the attribute, values and the status. |
|
230 */ |
|
231 void SidChecker::FillExeAttribute(ExeContainer* aExeContainer) |
|
232 { |
|
233 ExeAttribute* exeAtt = KNull; |
|
234 |
|
235 exeAtt = new ExeAttribute; |
|
236 if(!exeAtt) |
|
237 { |
|
238 throw ExceptionReporter(NOMEMORY, __FILE__, __LINE__); |
|
239 } |
|
240 |
|
241 exeAtt->iAttName = KSid; |
|
242 exeAtt->iAttValue = Common::IntToString(aExeContainer->iIdData->iSid); |
|
243 if(!iNoCheck) |
|
244 { |
|
245 FillExeSidStatus(aExeContainer); |
|
246 exeAtt->iAttStatus = aExeContainer->iIdData->iSidStatus; |
|
247 } |
|
248 else |
|
249 { |
|
250 exeAtt->iAttStatus = KNull; |
|
251 } |
|
252 if((iAllExecutables |
|
253 || (exeAtt->iAttStatus == KDuplicate)) && !exeAtt->iAttStatus.empty() |
|
254 || iNoCheck) |
|
255 { |
|
256 aExeContainer->iExeAttList.push_back(exeAtt); |
|
257 } |
|
258 } |