|
1 /* |
|
2 * Copyright (c) 2004-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 /** |
|
20 @file |
|
21 @internalComponent |
|
22 @released |
|
23 */ |
|
24 #ifdef _MSC_VER |
|
25 #pragma warning (disable: 4786) |
|
26 #endif // _MSC_VER |
|
27 |
|
28 #include "siscontroller.h" |
|
29 #include "utils.h" |
|
30 |
|
31 const unsigned short KRawSkipCount = 8; |
|
32 // count of fields signed by sign sis, all up to but excluding iDataIndex |
|
33 |
|
34 bool CSISController::iSkip = false; |
|
35 int CSISController::iLastCtlID = -2; |
|
36 |
|
37 CSISController::CSISController (const CSISController& aInitialiser) : |
|
38 CStructure <CSISFieldRoot::ESISController> (aInitialiser), |
|
39 iInfo (aInitialiser.iInfo), |
|
40 iSupportedOptions (aInitialiser.iSupportedOptions), |
|
41 iSupportedLanguages (aInitialiser.iSupportedLanguages), |
|
42 iPrerequisites (aInitialiser.iPrerequisites), |
|
43 iProperties (aInitialiser.iProperties), |
|
44 iLogo (aInitialiser.iLogo), |
|
45 iInstallBlock (aInitialiser.iInstallBlock), |
|
46 iSignatures (aInitialiser.iSignatures), |
|
47 iDataIndex (aInitialiser.iDataIndex), |
|
48 iRawBuffer (NULL), |
|
49 iRawBufferSize(0), |
|
50 iBufferSize (0) |
|
51 { |
|
52 InsertMembers (); |
|
53 if (aInitialiser.iRawBuffer) |
|
54 { |
|
55 try |
|
56 { |
|
57 iRawBuffer = new TUint8 [aInitialiser.iBufferSize]; |
|
58 memcpy (iRawBuffer, aInitialiser.iRawBuffer, aInitialiser.iBufferSize); |
|
59 iRawBufferSize = aInitialiser.iRawBufferSize; |
|
60 iBufferSize = aInitialiser.iBufferSize; |
|
61 } |
|
62 catch (...) |
|
63 { |
|
64 } |
|
65 } |
|
66 } |
|
67 |
|
68 |
|
69 void CSISController::InsertMembers () |
|
70 { |
|
71 // if you change these, change Read and Write (for SignSIS) and KRawSkipCount |
|
72 InsertMember (iInfo); |
|
73 InsertMember (iSupportedOptions); |
|
74 InsertMember (iSupportedLanguages); |
|
75 InsertMember (iPrerequisites); |
|
76 InsertMember (iProperties); |
|
77 InsertMember (iLogo); |
|
78 InsertMember (iInstallBlock); |
|
79 InsertMember (iSignatures); |
|
80 InsertMember (iDataIndex); |
|
81 } |
|
82 |
|
83 int CSISController::DeleteDirectory(std::string& aDirectory) |
|
84 { |
|
85 return RemoveDirectoryA(aDirectory.c_str()); |
|
86 } |
|
87 |
|
88 void CSISController::Read (TSISStream& aFile, const CSISFieldRoot::TFieldSize& aContainerSize, const CSISFieldRoot::TFieldType aArrayType) |
|
89 { |
|
90 delete [] iRawBuffer; |
|
91 iRawBuffer = NULL; |
|
92 iRawBufferSize = iBufferSize = 0; |
|
93 iRawBuffer = new TUint8 [aContainerSize]; |
|
94 iControllerID = ++iLastCtlID; |
|
95 try |
|
96 { |
|
97 iBufferSize = aContainerSize; |
|
98 TSISStream::pos_type pos = aFile.tell (); |
|
99 CSISHeader header; |
|
100 header.Read (aFile, aContainerSize, aArrayType); |
|
101 assert (header.DataType () == CSISFieldRoot::ESISController); |
|
102 iRawBufferSize = header.DataSize(); |
|
103 aFile.read (iRawBuffer, iRawBufferSize); |
|
104 aFile.seek (pos); |
|
105 if (iSkip) |
|
106 { |
|
107 assert (aArrayType == CSISFieldRoot::ESISUndefined); // arrays not tested |
|
108 iBufferSize = CStructure <CSISFieldRoot::ESISController>::SkipRead (aFile, header.DataSize(), aArrayType, KRawSkipCount, true); |
|
109 } |
|
110 else |
|
111 { |
|
112 iBufferSize = CStructure <CSISFieldRoot::ESISController>::SkipRead (aFile, header.DataSize(), aArrayType, KRawSkipCount, false); |
|
113 aFile.seek (pos); |
|
114 CStructure <CSISFieldRoot::ESISController>::Read (aFile, header.DataSize(), aArrayType); |
|
115 } |
|
116 } |
|
117 catch (...) |
|
118 { |
|
119 delete [] iRawBuffer; |
|
120 iRawBuffer = NULL; |
|
121 iBufferSize = 0; |
|
122 iRawBufferSize = 0; |
|
123 throw CSISException (CSISException::EFileFormat, L"error while reading sis"); |
|
124 } |
|
125 } |
|
126 |
|
127 |
|
128 void CSISController::Write (TSISStream& aFile, const bool aIsArrayElement) const |
|
129 { |
|
130 if (! iRawBuffer) |
|
131 { |
|
132 CStructure <CSISFieldRoot::ESISController>::Write (aFile, aIsArrayElement); |
|
133 } |
|
134 else |
|
135 { |
|
136 RawSkipWrite (aFile, aIsArrayElement, iRawBuffer, iBufferSize, KRawSkipCount); |
|
137 } |
|
138 } |
|
139 |
|
140 void CSISController::AddSignatureChain(CSignatureCertChainData& aSISSigCertChain) |
|
141 { |
|
142 iSignatures.Push (aSISSigCertChain); |
|
143 } |
|
144 |
|
145 void CSISController::RemoveSignature () |
|
146 { |
|
147 CSISException::ThrowIf (iSignatures.size () == 0, CSISException::ENotSigned, L"input file"); |
|
148 CSISFieldRoot::TFieldSize size = iSignatures.Last ().ByteCountWithHeader (false); |
|
149 assert (size < iBufferSize); |
|
150 iSignatures.Pop (); |
|
151 iBufferSize -= size; |
|
152 iRawBufferSize -= size; |
|
153 } |
|
154 |
|
155 void CSISController::Load (const std::wstring& aFileName) |
|
156 { |
|
157 TSISStream input; |
|
158 HANDLE file = ::MakeSISOpenFile(aFileName.c_str(),GENERIC_READ,OPEN_EXISTING); |
|
159 CSISException::ThrowIf ((INVALID_HANDLE_VALUE == file), |
|
160 CSISException::EFileProblem, std::wstring (L"cannot open ") + aFileName); |
|
161 bool success = input.import (file, NULL); |
|
162 |
|
163 TUint32 len = ::GetFileSize(file,0); |
|
164 |
|
165 ::CloseHandle(file); |
|
166 |
|
167 CSISException::ThrowIf (! success, CSISException::EFileProblem, std::wstring (L"cannot read ") + aFileName); |
|
168 |
|
169 TUint32 controllerSize; |
|
170 input.seek (0); |
|
171 input>>controllerSize; |
|
172 |
|
173 CSISException::ThrowIf ((controllerSize+4) != len, CSISException::EFileProblem, aFileName + std::wstring (L" Is not a valid SIS or SIS Controller")); |
|
174 |
|
175 input.seek (0); |
|
176 |
|
177 //default parameter CSISFieldRoot::ESISController is passed to ensure that the |
|
178 //Stub SIS Controller file reading starts from the controller length |
|
179 Read (input, len,CSISFieldRoot::ESISController); |
|
180 } |
|
181 |
|
182 |
|
183 void CSISController::AddPackageEntry(std::wostream& aStream, bool aVerbose) const |
|
184 { |
|
185 iSupportedLanguages.AddPackageEntry(aStream, aVerbose); |
|
186 iInfo.AddPackageEntry(aStream, aVerbose); |
|
187 iPrerequisites.AddPackageEntry(aStream, aVerbose); |
|
188 iSupportedOptions.AddPackageEntry(aStream, aVerbose); |
|
189 iProperties.AddPackageEntry(aStream, aVerbose); |
|
190 iLogo.AddPackageEntry(aStream, aVerbose); |
|
191 iInstallBlock.AddPackageEntry(aStream, aVerbose); |
|
192 for(int i = 0; i < iSignatures.size(); ++i) |
|
193 { |
|
194 iSignatures[i].AddPackageEntry(aStream, aVerbose); |
|
195 } |
|
196 } |
|
197 |
|
198 TUint64 CSISController::ControllerSizeForHash() const |
|
199 { |
|
200 TUint64 ctlSize = ByteCount(false); |
|
201 TUint64 size = ctlSize - iSignatures.ByteCountWithHeader(false) - iDataIndex.ByteCountWithHeader(false); |
|
202 if(CSISHeader::IsBigHeader(ctlSize)) |
|
203 { |
|
204 size += 8; |
|
205 } |
|
206 else |
|
207 { |
|
208 size += 4; |
|
209 } |
|
210 |
|
211 return size; |
|
212 } |
|
213 |