|
1 /* |
|
2 * Copyright (c) 2005-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "dumpswiregistrytool.h" |
|
20 #ifdef _MSC_VER |
|
21 #include <new> |
|
22 #include <new.h> |
|
23 #endif /* _MSC_VER */ |
|
24 |
|
25 #ifdef _MSC_VER |
|
26 // House-keeping to allow ::new to throw rather than return NULL in MSVC++ |
|
27 int throwingHandler(size_t) |
|
28 { |
|
29 throw std::bad_alloc(); |
|
30 return 0; |
|
31 } |
|
32 #endif /* _MSC_VER */ |
|
33 |
|
34 class DumpRegistryTool tool; |
|
35 |
|
36 //entry point |
|
37 int main(int argc,char *argv[]) |
|
38 { |
|
39 #ifdef _MSC_VER |
|
40 _set_new_handler (throwingHandler); // Make ::new throw rather than return NULL |
|
41 #endif /* _MSC_VER */ |
|
42 |
|
43 if(argc < 2) |
|
44 { |
|
45 Options::DisplayUsage(); |
|
46 return 0; |
|
47 } |
|
48 try |
|
49 { |
|
50 auto_ptr<Options> options(new Options(argc , argv)); |
|
51 tool.Run(*options); |
|
52 } |
|
53 |
|
54 catch (Exceptions aErr) |
|
55 { |
|
56 Options::DisplayError(aErr); |
|
57 return aErr; |
|
58 } |
|
59 |
|
60 catch (bad_alloc&) |
|
61 { |
|
62 cout << "Error Allocating Memory " << endl ; |
|
63 } |
|
64 |
|
65 return 0; |
|
66 } |
|
67 |
|
68 DumpRegistryTool::DumpRegistryTool() |
|
69 :iRegistryEntryValid(false) , |
|
70 iFile("\\0") , |
|
71 iFileMajorVersion (0) , |
|
72 iFileMinorVersion (0) , |
|
73 iPkgVendorLocalizedName (0) , |
|
74 iPkgInstallType (0) , |
|
75 iRomBasedPkg (0) , |
|
76 iPkgPreinstalledStatus (0) , |
|
77 iPkgSignedStatus (0) , |
|
78 iPkgTrust (0) , |
|
79 iNotUsed (0) , |
|
80 iTimeStampl (0) , |
|
81 iTimeStamph (0) |
|
82 { |
|
83 iInstallType[0] = "Installation" ; |
|
84 iInstallType[1] = "Augmentation" ; |
|
85 iInstallType[2] = "PartialUpgrade" ; |
|
86 iInstallType[3] = "PralledApp" ; |
|
87 iInstallType[4] = "PralledPatch" ; |
|
88 |
|
89 iPackageTrust[0] = "SisPackageUnsignedOrSelfSigned" ; |
|
90 iPackageTrust[50] = "SisPackageValidationFailed" ; |
|
91 iPackageTrust[100] = "SisPackageCertificateChainNoTrustAnchor" ; |
|
92 iPackageTrust[200] = "SisPackageCertificateChainValidatedToTrustAnchor" ; |
|
93 iPackageTrust[300] = "SisPackageChainValidatedToTrustAnchorOCSPTransientError" ; |
|
94 iPackageTrust[400] = "SisPackageChainValidatedToTrustAnchorAndOCSPValid" ; |
|
95 iPackageTrust[500] = "SisPackageBuiltIntoRom" ; |
|
96 |
|
97 iValidationStatus[0] = "Unknown" ; |
|
98 iValidationStatus[10] = "Expired" ; |
|
99 iValidationStatus[20] = "Invalid" ; |
|
100 iValidationStatus[30] = "Unsigned" ; |
|
101 iValidationStatus[40] = "Validated" ; |
|
102 iValidationStatus[50] = "ValidatedToAnchor" ; |
|
103 iValidationStatus[60] = "PackageInRom" ; |
|
104 |
|
105 iRevocationStatus[0] = "Unknown2" ; |
|
106 iRevocationStatus[10] = "OcspNotPerformed" ; |
|
107 iRevocationStatus[20] = "OcspRevoked" ; |
|
108 iRevocationStatus[30] = "OcspUnknown" ; |
|
109 iRevocationStatus[40] = "OcspTransient" ; |
|
110 iRevocationStatus[50] = "OcspGood" ; |
|
111 } |
|
112 |
|
113 /** |
|
114 Calls the ListFilesInDirectory(),which provides a vector containing all the .reg files present in the |
|
115 package directory specified,and iterates this vector one by one and calls ExtractRegistry() ,to extract the information |
|
116 from that particular .reg file. |
|
117 */ |
|
118 |
|
119 void DumpRegistryTool::Run(const Options& aOptions) |
|
120 { |
|
121 std::vector<std::string> regFiles; |
|
122 //-p option specified |
|
123 if(aOptions.IsPkgUIDSpecified()) |
|
124 { |
|
125 regFiles = OSInterface::ExtractFilesFromDirectory(aOptions.PkgUID(), "reg"); |
|
126 } |
|
127 |
|
128 //-r option specified |
|
129 if(aOptions.IsRegistryEntrySpecified()) |
|
130 { |
|
131 regFiles = OSInterface::ExtractFilesFromDirectory(aOptions.RegistryFilePath(), "reg"); |
|
132 } |
|
133 |
|
134 for(vector<string>::const_iterator regIterator = regFiles.begin(); regIterator != regFiles.end(); regIterator++) |
|
135 { |
|
136 string file = *regIterator; |
|
137 const char* fileName = file.c_str(); |
|
138 bool success = ExtractRegistry(fileName , aOptions); |
|
139 if(!success) |
|
140 { |
|
141 cout << "Package Information:" << endl << endl; |
|
142 cout << "Registry Entry :" << fileName <<" IS EMPTY " << endl; |
|
143 } |
|
144 } |
|
145 |
|
146 //if -r option is specified and the registry entry(either pkg name,pkg uid or vendor name is not specified) |
|
147 //display usage. |
|
148 if(!iRegistryEntryValid && (aOptions.IsRegistryEntrySpecified())) |
|
149 { |
|
150 cout << "Invalid Registry Entry Specified ." << endl << endl; |
|
151 } |
|
152 } |
|
153 |
|
154 /** |
|
155 Extracts the particular registry contents. |
|
156 @param registry file |
|
157 */ |
|
158 bool DumpRegistryTool::ExtractRegistry(const char* aRegFile , const Options& aOptions) |
|
159 { |
|
160 StreamReader reader(aRegFile); |
|
161 //check if file is empty |
|
162 bool isFileEmpty = reader.Initialise(); |
|
163 if(isFileEmpty) |
|
164 { |
|
165 return false; |
|
166 } |
|
167 |
|
168 RegistryPackage package; |
|
169 RegistryToken token; |
|
170 token.ExtractRegistryToken(reader,package); |
|
171 ExtractPackageInformation(reader); |
|
172 |
|
173 unsigned int uid = package.PkgUID(); |
|
174 char uidBuf[KLength]; |
|
175 itoa(uid,uidBuf,KRadix); |
|
176 |
|
177 //if -p option is specified |
|
178 if(aOptions.IsPkgUIDSpecified()) |
|
179 { |
|
180 cout << "Package Information:" << endl << endl; |
|
181 cout << "Registry File :" << aRegFile << endl << endl; |
|
182 package.DisplayPackage(); |
|
183 token.DisplayRegistryToken(); |
|
184 DisplayPackageInformation(); |
|
185 } |
|
186 |
|
187 //if -r option sis specified. |
|
188 if(aOptions.IsRegistryEntrySpecified()) |
|
189 { |
|
190 int packageUid = CompareUserAndFileSpecifiedData(aOptions.PkgUID(), uidBuf); |
|
191 int packageName = CompareUserAndFileSpecifiedData(aOptions.PkgName(), package.PackageName()); |
|
192 int vendorName = CompareUserAndFileSpecifiedData(aOptions.VendorName(), package.Vendor()); |
|
193 |
|
194 if(packageUid && packageName && vendorName) |
|
195 { |
|
196 iRegistryEntryValid = true; |
|
197 cout <<"Registry Controller Information:" << endl << endl; |
|
198 cout << "Registry Entry :" << aRegFile << endl << endl; |
|
199 package.DisplayPackage(); |
|
200 unsigned int count = token.GetControllerCount(); |
|
201 for(int i = 0 ; i < count ; i++) |
|
202 { |
|
203 token.ControllerInformation()->DisplayControllerInfo(i); |
|
204 } |
|
205 ExtractControllerInformation(reader); |
|
206 } |
|
207 } |
|
208 iFile.close(); |
|
209 return true; |
|
210 } |
|
211 |
|
212 /** |
|
213 Extracts the information about sis dependencies,sis embeds, sis file description,sis properties , |
|
214 validation status and revocation status . |
|
215 */ |
|
216 |
|
217 void DumpRegistryTool::ExtractControllerInformation(StreamReader& aReader) |
|
218 { |
|
219 //list of depenedent SISX packages |
|
220 unsigned int dependencyCount = aReader.ReadInt32(); |
|
221 cout << "Number of Dependencies : " << dependencyCount << endl << endl; |
|
222 if(dependencyCount) |
|
223 { |
|
224 cout << "Dependencies Information : " << endl << endl; |
|
225 SISDependency* dependency = new SISDependency[dependencyCount]; |
|
226 for(int j = 0; j < dependencyCount; j++) |
|
227 { |
|
228 dependency[j].ExtractDependency(aReader); |
|
229 dependency[j].DisplayDependencyInfo(); |
|
230 } |
|
231 delete [] dependency; |
|
232 } |
|
233 |
|
234 //list of embedded SISX files |
|
235 unsigned int embeddedCount = aReader.ReadInt32(); |
|
236 cout<<"Number of Embedded Packages : " << embeddedCount << endl << endl; |
|
237 if(embeddedCount) |
|
238 { |
|
239 cout << "List Of Embedded Packages:" << endl << endl; |
|
240 SISEmbeds* embed = new SISEmbeds[embeddedCount]; |
|
241 for(int i = 0; i < embeddedCount ; i++) |
|
242 { |
|
243 embed[i].ExtractEmbeds(aReader); |
|
244 embed[i].DisplayEmbeddedInfo(); |
|
245 } |
|
246 delete [] embed; |
|
247 } |
|
248 |
|
249 //properties for the SISX package,is a key, value pair associated with a SISX package. |
|
250 unsigned int sisPropertyCount = aReader.ReadInt32(); |
|
251 cout << "SISProperty Count:"<< sisPropertyCount << endl << endl; |
|
252 if(sisPropertyCount) |
|
253 { |
|
254 cout << "SIS Properties :" << endl << endl; |
|
255 SISProperty* property = new SISProperty[sisPropertyCount]; |
|
256 for(int k = 0; k < sisPropertyCount; k++) |
|
257 { |
|
258 property[k].ExtractSISProperty(aReader); |
|
259 property[k].DisplaySISProperty(); |
|
260 } |
|
261 delete [] property; |
|
262 } |
|
263 |
|
264 //information about files to be installed . |
|
265 unsigned int sisFileDescriptionCount = aReader.ReadInt32(); |
|
266 cout << "Number Of File Descriptions :" << sisFileDescriptionCount << endl << endl; |
|
267 if(sisFileDescriptionCount) |
|
268 { |
|
269 cout << "SIS File Description:" << endl << endl; |
|
270 SISFileDescription* description = new SISFileDescription[sisFileDescriptionCount]; |
|
271 for(int l = 0; l < sisFileDescriptionCount; l++) |
|
272 { |
|
273 description[l].ExtractSISFileDescription(aReader); |
|
274 description[l].DisplaySISFileDescription(l); |
|
275 } |
|
276 delete [] description; |
|
277 } |
|
278 |
|
279 unsigned int statusOfValidation = aReader.ReadInt32(); |
|
280 if(tool.iValidationStatus.find(statusOfValidation) !=tool.iValidationStatus.end()) |
|
281 { |
|
282 cout<<"Validation Status : "<< iValidationStatus[statusOfValidation] << endl; |
|
283 } |
|
284 else |
|
285 { |
|
286 cout << "Validation Status : " << "Unknown" << endl; |
|
287 } |
|
288 |
|
289 unsigned int revocationStatus = aReader.ReadInt32(); |
|
290 if(tool.iRevocationStatus.find(revocationStatus) != tool.iRevocationStatus.end()) |
|
291 { |
|
292 cout << "Revocation Status : " << iRevocationStatus[revocationStatus] << endl; |
|
293 } |
|
294 else |
|
295 { |
|
296 cout << "Revocation Status : " << "Unknown" << endl; |
|
297 } |
|
298 |
|
299 } |
|
300 |
|
301 //this function is to check whether the user specified values for registry entries matches the one specified in the .reg file. |
|
302 int DumpRegistryTool::CompareUserAndFileSpecifiedData(const string& aUserSpecified , const string& aFileSpecified) |
|
303 { |
|
304 string::const_iterator userIter = aUserSpecified.begin(); |
|
305 string::const_iterator fileIter = aFileSpecified.begin(); |
|
306 |
|
307 int userSize = aUserSpecified.length(); |
|
308 int size = aFileSpecified.length(); |
|
309 |
|
310 //stop when either string end has reached |
|
311 while((userIter != aUserSpecified.end()) && (fileIter != aFileSpecified.end())) |
|
312 { |
|
313 if(::toupper(*userIter) != ::toupper(*fileIter)) |
|
314 { |
|
315 return 0; |
|
316 } |
|
317 ++userIter; |
|
318 ++fileIter; |
|
319 } |
|
320 |
|
321 if(userSize == size) |
|
322 { |
|
323 return 1; |
|
324 } |
|
325 else |
|
326 { |
|
327 return 0; |
|
328 } |
|
329 } |
|
330 |
|
331 |
|
332 /** |
|
333 This function extracts top level information about a package namely install type,whether it is rom based,trust status of package |
|
334 */ |
|
335 void DumpRegistryTool::ExtractPackageInformation(StreamReader& aReader) |
|
336 { |
|
337 iFileMajorVersion = aReader.ReadInt16(); |
|
338 iFileMinorVersion = aReader.ReadInt16(); |
|
339 iPkgVendorLocalizedName = aReader.ReadDescriptor(); |
|
340 iPkgInstallType = aReader.ReadInt32(); |
|
341 iRomBasedPkg = aReader.ReadInt32(); //is package ROM Based |
|
342 iPkgPreinstalledStatus = aReader.ReadInt32(); //is package preinstalled |
|
343 iPkgSignedStatus = aReader.ReadInt32(); //is package signed |
|
344 iPkgTrust = aReader.ReadInt32(); //trust status of package |
|
345 iNotUsed = aReader.ReadInt32(); |
|
346 iTimeStampl = aReader.ReadInt32(); |
|
347 iTimeStamph = aReader.ReadInt32(); |
|
348 } |
|
349 |
|
350 |
|
351 void DumpRegistryTool::DisplayPackageInformation() |
|
352 { |
|
353 cout << "File Major Version :" << iFileMajorVersion << endl; |
|
354 cout << "File Minor Version :" << iFileMinorVersion << endl; |
|
355 cout << "Package Vendor Localized Name :" << iPkgVendorLocalizedName << endl; |
|
356 if(tool.iInstallType.find(iPkgInstallType) != tool.iInstallType.end()) |
|
357 { |
|
358 cout << "Package Install Type :" << tool.iInstallType[iPkgInstallType] << endl; |
|
359 } |
|
360 else |
|
361 { |
|
362 cout << "Package Install Type :" << "Unknown" << endl; |
|
363 } |
|
364 |
|
365 if(iRomBasedPkg) |
|
366 { |
|
367 cout << "Is Package in ROM :" << "Yes" << endl; |
|
368 } |
|
369 else |
|
370 { |
|
371 cout<<"Is Package in ROM :"<< "No" <<endl; |
|
372 } |
|
373 |
|
374 |
|
375 if(iPkgPreinstalledStatus) |
|
376 { |
|
377 cout << "Package Preinstalled :" << "Yes" << endl; |
|
378 } |
|
379 else |
|
380 { |
|
381 cout << "Package Preinstalled :" << "No" << endl; |
|
382 } |
|
383 |
|
384 if(iPkgSignedStatus) |
|
385 { |
|
386 cout << "Package Signed :" << "Yes" << endl; |
|
387 } |
|
388 else |
|
389 { |
|
390 cout << "Is Package Signed :" << "No" << endl; |
|
391 } |
|
392 |
|
393 if(tool.iPackageTrust.find(iPkgTrust) !=tool.iPackageTrust.end()) |
|
394 { |
|
395 cout << "Package Trust :" << tool.iPackageTrust[iPkgTrust] << endl; |
|
396 } |
|
397 else |
|
398 { |
|
399 cout << "Package Trust :" << "Unknown" << endl << endl; |
|
400 } |
|
401 } |
|
402 |
|
403 |
|
404 DumpRegistryTool::~DumpRegistryTool() |
|
405 { |
|
406 delete [] iPkgVendorLocalizedName; |
|
407 } |
|
408 |
|
409 |
|
410 |
|
411 |