|
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 "dumpinstallfilestatustool.h" |
|
20 #include "osinterface.h" |
|
21 #ifdef _MSC_VER |
|
22 #include <new> |
|
23 #include <new.h> |
|
24 #endif /* _MSC_VER */ |
|
25 using namespace std; |
|
26 |
|
27 #ifdef _MSC_VER |
|
28 // House-keeping to allow ::new to throw rather than return NULL in MSVC++ |
|
29 int throwingHandler(size_t) |
|
30 { |
|
31 throw std::bad_alloc(); |
|
32 return 0; |
|
33 } |
|
34 #endif /* _MSC_VER */ |
|
35 |
|
36 |
|
37 // entry point |
|
38 int main(int argc,char *argv[]) |
|
39 { |
|
40 #ifdef _MSC_VER |
|
41 _set_new_handler (throwingHandler); // Make ::new throw rather than return NULL |
|
42 #endif /* _MSC_VER */ |
|
43 |
|
44 if(argc < 2) |
|
45 { |
|
46 Options::DisplayUsage(); |
|
47 return 0; |
|
48 } |
|
49 |
|
50 OpenSSL_add_all_algorithms (); |
|
51 OpenSSL_add_all_ciphers (); |
|
52 OpenSSL_add_all_digests (); |
|
53 |
|
54 try |
|
55 { |
|
56 auto_ptr<DumpInstallFileStatusTool> tool(new DumpInstallFileStatusTool); |
|
57 auto_ptr<Options> options(new Options(argc,argv)); |
|
58 tool->Run(*options); |
|
59 } |
|
60 |
|
61 catch (Exceptions& aErr) |
|
62 { |
|
63 Options::DisplayError (aErr); |
|
64 return aErr; |
|
65 } |
|
66 |
|
67 catch (bad_alloc&) |
|
68 { |
|
69 cout << "Error Allocating Memory " << endl ; |
|
70 } |
|
71 |
|
72 return 0; |
|
73 } |
|
74 |
|
75 // Class DumpInstallFileStatusTool |
|
76 DumpInstallFileStatusTool::DumpInstallFileStatusTool() |
|
77 :iSISData(0) , |
|
78 iChainValidity(0) |
|
79 { |
|
80 } |
|
81 |
|
82 void DumpInstallFileStatusTool::Run(const Options& aOptions) |
|
83 { |
|
84 int dumpchainvalidityData = 0 ; |
|
85 LaunchProcess launch; |
|
86 ofstream fileName; |
|
87 |
|
88 iChainValidity = new DumpChainValidityTool(); |
|
89 iChainValidity -> Run(aOptions); |
|
90 dumpchainvalidityData = iChainValidity -> GetUnifiedCaps(); |
|
91 |
|
92 std::string inputParameter = KDumpsisInputParameter; |
|
93 inputParameter.append(aOptions.SISFile()); |
|
94 string dumpsisData = launch.ExecuteProcess(inputParameter,2); |
|
95 |
|
96 fileName.open(KEciFile.c_str(),ios::out); |
|
97 fileName.write(dumpsisData.c_str(),dumpsisData.length()); |
|
98 fileName.close(); |
|
99 |
|
100 |
|
101 CloseHandle(launch.piProcessInfo.hProcess); |
|
102 CloseHandle(launch.piProcessInfo.hThread); |
|
103 |
|
104 iSISData = new SISFileData(); |
|
105 int isExe = iSISData->EciFileRead(KEciFile.c_str(),aOptions); |
|
106 //in case sis file doesn't contain any executable. |
|
107 if(!isExe) |
|
108 { |
|
109 return; |
|
110 } |
|
111 |
|
112 int mergedCaps = (aOptions.UserCapabilities())|(dumpchainvalidityData); |
|
113 const SISFileData::ExeLabelAndCapabilitiesList* exeList = iSISData->ExeNameAndCapabilityList(); |
|
114 while(exeList) |
|
115 { |
|
116 Correlate(exeList -> iExeCapability, mergedCaps, dumpchainvalidityData, exeList -> iExeLabel); |
|
117 exeList = exeList -> iNext; |
|
118 } |
|
119 remove(KEciFile.c_str()); |
|
120 } |
|
121 |
|
122 void DumpInstallFileStatusTool::Correlate(const int aExeCapabilities , int MergedCapabilities , int aUnifiedSigningCertCaps , const string& aExeLabel) |
|
123 { |
|
124 int missingCaps; |
|
125 int loc = aExeLabel.find(".exe" , 0); |
|
126 int pos = aExeLabel.find(".dll" , 0); |
|
127 //correlate only if the file is an exe or dll. |
|
128 if(loc > 0 || pos > 0 ) |
|
129 { |
|
130 cout << "Executable : " << endl << endl; |
|
131 //when exe has no capabilities. |
|
132 if(aExeCapabilities == 0) |
|
133 { |
|
134 cout << aExeLabel << endl << endl; |
|
135 cout << "FILE STATUS : Has No Capabilities ." << endl << endl; |
|
136 } |
|
137 |
|
138 |
|
139 //check whether exe capabilities are satisified by signing cert caps.In case unified caps(from chainvalidity) is 0, do not consider them. |
|
140 else if(((aExeCapabilities & aUnifiedSigningCertCaps) == aExeCapabilities) && aUnifiedSigningCertCaps ) |
|
141 { |
|
142 cout<< aExeLabel << endl << endl; |
|
143 cout<<"FILE STATUS : Capabilities are satisfied by Signing Certificates ." << endl << endl; |
|
144 } |
|
145 |
|
146 //checking whether exe caps are satisfied by signing chain |
|
147 //in conjunction with user specified capabilities(MergedCapabilities) |
|
148 else if((aExeCapabilities & MergedCapabilities) == (aExeCapabilities)) |
|
149 { |
|
150 cout << aExeLabel << endl << endl; |
|
151 cout <<"FILE STATUS : Capabilities are satisfied by Signing Certificates ." << endl; |
|
152 cout<<"\t\t in conjunction with User Capabilities" << endl << endl; |
|
153 } |
|
154 |
|
155 else |
|
156 { |
|
157 cout << aExeLabel << endl << endl; |
|
158 cout <<"FILE STATUS : Capabilities are not satisfied ." << endl << endl; |
|
159 cout <<"Missing Capabilities List :" << endl << endl; |
|
160 int result = ((MergedCapabilities) & (aExeCapabilities)); |
|
161 missingCaps = (aExeCapabilities - result); |
|
162 DisplayMissingCapabilities(missingCaps); |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 void DumpInstallFileStatusTool::DisplayMissingCapabilities(int aMissingCaps) |
|
168 { |
|
169 int missingCapabilities = 0; |
|
170 while(aMissingCaps) |
|
171 { |
|
172 if((aMissingCaps & 0x01)) |
|
173 { |
|
174 if(missingCapabilities < KNumberOfCaps) |
|
175 { |
|
176 cout << CapabilityList[missingCapabilities] << endl;; |
|
177 } |
|
178 else |
|
179 { |
|
180 cout << "Unknown" << missingCapabilities << endl; |
|
181 } |
|
182 } |
|
183 |
|
184 aMissingCaps = aMissingCaps >> 1; |
|
185 missingCapabilities++; |
|
186 } |
|
187 |
|
188 cout << endl; |
|
189 } |
|
190 |
|
191 DumpInstallFileStatusTool::~DumpInstallFileStatusTool() |
|
192 { |
|
193 delete iSISData; |
|
194 delete iChainValidity; |
|
195 } |
|
196 |
|
197 |
|
198 |
|
199 |