112 DumpInHex("RelocInfo", iRomHdr->iRelocInfo) << endl; |
112 DumpInHex("RelocInfo", iRomHdr->iRelocInfo) << endl; |
113 DumpInHex("OldTraceMask", iRomHdr->iOldTraceMask) << endl; |
113 DumpInHex("OldTraceMask", iRomHdr->iOldTraceMask) << endl; |
114 DumpInHex("UserDataAddress", iRomHdr->iUserDataAddress) << endl; |
114 DumpInHex("UserDataAddress", iRomHdr->iUserDataAddress) << endl; |
115 DumpInHex("TotalUserDataSize", iRomHdr->iTotalUserDataSize) << endl; |
115 DumpInHex("TotalUserDataSize", iRomHdr->iTotalUserDataSize) << endl; |
116 DumpInHex("DebugPort", iRomHdr->iDebugPort) << endl; |
116 DumpInHex("DebugPort", iRomHdr->iDebugPort) << endl; |
117 |
117 |
118 DumpInHex("Version", iRomHdr->iVersion.iMajor, false, 2); |
118 DumpInHex("Version", iRomHdr->iVersion.iMajor, false, 2); |
119 DumpInHex(".", iRomHdr->iVersion.iMinor, aContinue, 2); |
119 DumpInHex(".", iRomHdr->iVersion.iMinor, aContinue, 2); |
120 DumpInHex("(" ,iRomHdr->iVersion.iBuild, aContinue, 2); |
120 DumpInHex("(" ,iRomHdr->iVersion.iBuild, aContinue, 2); |
121 *out << ")" << endl; |
121 *out << ")" << endl; |
122 |
122 |
123 DumpInHex("CompressionType", iRomHdr->iCompressionType) << endl; |
123 DumpInHex("CompressionType", iRomHdr->iCompressionType) << endl; |
124 DumpInHex("CompressedSize", iRomHdr->iCompressedSize) << endl; |
124 DumpInHex("CompressedSize", iRomHdr->iCompressedSize) << endl; |
125 DumpInHex("UncompressedSize", iRomHdr->iUncompressedSize) << endl; |
125 DumpInHex("UncompressedSize", iRomHdr->iUncompressedSize) << endl; |
126 DumpInHex("HcrFileAddress", iRomHdr->iHcrFileAddress) << endl; |
126 DumpInHex("HcrFileAddress", iRomHdr->iHcrFileAddress) << endl; |
127 |
127 |
128 DumpInHex("DisabledCapabilities", iRomHdr->iDisabledCapabilities[0]); |
128 DumpInHex("DisabledCapabilities", iRomHdr->iDisabledCapabilities[0]); |
129 DumpInHex(" ", iRomHdr->iDisabledCapabilities[1], aContinue) << endl; |
129 DumpInHex(" ", iRomHdr->iDisabledCapabilities[1], aContinue) << endl; |
130 |
130 |
131 DumpInHex("TraceMask", iRomHdr->iTraceMask[0]); |
131 DumpInHex("TraceMask", iRomHdr->iTraceMask[0]); |
132 aPos = 1; |
132 aPos = 1; |
133 while( aPos < (TUint)KNumTraceMaskWords) |
133 while( aPos < (TUint)KNumTraceMaskWords) { |
134 { |
134 if(iRomHdr->iTraceMask[aPos]) { |
135 if(iRomHdr->iTraceMask[aPos]) |
|
136 { |
|
137 DumpInHex(" ", iRomHdr->iTraceMask[aPos++], aContinue); |
135 DumpInHex(" ", iRomHdr->iTraceMask[aPos++], aContinue); |
138 } |
136 } |
139 else |
137 else { |
140 { |
|
141 DumpInHex(" ", iRomHdr->iTraceMask[aPos++], aContinue, 1); |
138 DumpInHex(" ", iRomHdr->iTraceMask[aPos++], aContinue, 1); |
142 } |
139 } |
143 |
140 |
144 } |
141 } |
145 |
142 |
146 *out << endl << endl; |
143 *out << endl << endl; |
147 |
144 |
148 } |
145 } |
149 void RomImageHeader::DumpRomXHdr() |
146 void RomImageHeader::DumpRomXHdr() { |
150 { |
|
151 *out << "Extension ROM Image" << endl << endl; |
147 *out << "Extension ROM Image" << endl << endl; |
152 bool aContinue = true; |
148 bool aContinue = true; |
153 |
149 |
154 DumpInHex("Timestamp", (iExtRomHdr->iTime >> 32)) ; |
150 DumpInHex("Timestamp", (iExtRomHdr->iTime >> 32)) ; |
155 DumpInHex(" ", (iExtRomHdr->iTime &0xffffffff), aContinue) << endl; |
151 DumpInHex(" ", (iExtRomHdr->iTime &0xffffffff), aContinue) << endl; |
156 |
152 |
157 DumpInHex("RomBase", iExtRomHdr->iRomBase) << endl; |
153 DumpInHex("RomBase", iExtRomHdr->iRomBase) << endl; |
158 |
154 |
159 DumpInHex("RomSize", iExtRomHdr->iRomSize) << endl; |
155 DumpInHex("RomSize", iExtRomHdr->iRomSize) << endl; |
160 DumpInHex("CheckSum", iExtRomHdr->iCheckSum) << endl; |
156 DumpInHex("CheckSum", iExtRomHdr->iCheckSum) << endl; |
161 |
157 |
162 DumpInHex("Version", iExtRomHdr->iVersion.iMajor, false, 2); |
158 DumpInHex("Version", iExtRomHdr->iVersion.iMajor, false, 2); |
163 DumpInHex(".", iExtRomHdr->iVersion.iMinor, aContinue, 2); |
159 DumpInHex(".", iExtRomHdr->iVersion.iMinor, aContinue, 2); |
164 DumpInHex("(" ,iExtRomHdr->iVersion.iBuild, aContinue, 2); |
160 DumpInHex("(" ,iExtRomHdr->iVersion.iBuild, aContinue, 2); |
165 *out << ")" << endl; |
161 *out << ")" << endl; |
166 |
162 |
167 DumpInHex("CompressionType", iExtRomHdr->iCompressionType) << endl; |
163 DumpInHex("CompressionType", iExtRomHdr->iCompressionType) << endl; |
168 DumpInHex("CompressedSize", iExtRomHdr->iCompressedSize) << endl; |
164 DumpInHex("CompressedSize", iExtRomHdr->iCompressedSize) << endl; |
169 DumpInHex("UncompressedSize", iExtRomHdr->iUncompressedSize) << endl; |
165 DumpInHex("UncompressedSize", iExtRomHdr->iUncompressedSize) << endl; |
170 |
166 |
171 *out << endl << endl; |
167 *out << endl << endl; |
172 |
168 |
173 } |
169 } |
174 //Rom Image reader |
170 //Rom Image reader |
175 RomImageReader::RomImageReader(const char* aFile, EImageType aImgType) : |
171 RomImageReader::RomImageReader(const char* aFile, EImageType aImgType) : |
176 ImageReader(aFile), iImageHeader(0), |
172 ImageReader(aFile), iImageHeader(0), |
177 iRomSize(0),iHeaderBuffer(0), |
173 iRomSize(0),iHeaderBuffer(0), |
178 iRomLayoutData(0),iImgType(aImgType) |
174 iRomLayoutData(0),iImgType(aImgType) { |
179 { |
|
180 iRomImageRootDirEntry = new RomImageDirEntry(""); |
175 iRomImageRootDirEntry = new RomImageDirEntry(""); |
181 } |
176 } |
182 |
177 |
183 RomImageReader::~RomImageReader() |
178 RomImageReader::~RomImageReader() { |
184 { |
|
185 if(iFile.is_open()) |
179 if(iFile.is_open()) |
186 iFile.close(); |
180 iFile.close(); |
187 if(iHeaderBuffer) |
181 if(iHeaderBuffer) |
188 delete []iHeaderBuffer; |
182 delete []iHeaderBuffer; |
189 if(iRomLayoutData) |
183 if(iRomLayoutData) |
190 delete []iRomLayoutData; |
184 delete []iRomLayoutData; |
191 delete iRomImageRootDirEntry; |
185 delete iRomImageRootDirEntry; |
192 |
186 |
193 |
187 |
194 } |
188 } |
195 |
189 |
196 void RomImageReader::ReadImage() |
190 void RomImageReader::ReadImage() { |
197 { |
|
198 if(iFile.is_open()) return ; |
191 if(iFile.is_open()) return ; |
199 iFile.open(iImgFileName.c_str(), ios::binary | ios::in); |
192 iFile.open(iImgFileName.c_str(), ios_base::binary | ios_base::in); |
200 if( !iFile.is_open() ) { |
193 if( !iFile.is_open() ) { |
201 throw ImageReaderException(iImgFileName.c_str(), "Cannot open file "); |
194 throw ImageReaderException(iImgFileName.c_str(), "Cannot open file "); |
202 } |
195 } |
203 |
196 |
204 TUint headerSize = GetHdrSize() ; |
197 TUint headerSize = GetHdrSize() ; |
205 if(headerSize > 0){ |
198 if(headerSize > 0){ |
206 iHeaderBuffer = new char[headerSize]; |
199 iHeaderBuffer = new char[headerSize]; |
207 iFile.read(iHeaderBuffer,headerSize); |
200 iFile.read(iHeaderBuffer,headerSize); |
208 } |
201 } |
209 } |
202 } |
210 |
203 |
211 void RomImageReader::Validate() |
204 void RomImageReader::Validate() { |
212 { |
205 } |
213 } |
206 |
214 |
207 TUint32 RomImageReader::GetImageCompressionType() { |
215 TUint32 RomImageReader::GetImageCompressionType() |
|
216 { |
|
217 if(iImageHeader->iRomHdr )// iImageType == EROM_IMAGE |
208 if(iImageHeader->iRomHdr )// iImageType == EROM_IMAGE |
218 return iImageHeader->iRomHdr->iCompressionType; |
209 return iImageHeader->iRomHdr->iCompressionType; |
219 else |
210 else |
220 return iImageHeader->iExtRomHdr->iCompressionType; |
211 return iImageHeader->iExtRomHdr->iCompressionType; |
221 } |
212 } |
222 |
213 |
223 |
214 |
224 TLinAddr RomImageReader::GetRomBase() |
215 TLinAddr RomImageReader::GetRomBase() { |
225 { |
|
226 if(iImageHeader->iRomHdr )// iImageType == EROM_IMAGE |
216 if(iImageHeader->iRomHdr )// iImageType == EROM_IMAGE |
227 return iImageHeader->iRomHdr->iRomBase ; |
217 return iImageHeader->iRomHdr->iRomBase ; |
228 else |
218 else |
229 return iImageHeader->iExtRomHdr->iRomBase; |
219 return iImageHeader->iExtRomHdr->iRomBase; |
230 } |
220 } |
231 |
221 |
232 TLinAddr RomImageReader::GetRootDirList() |
222 TLinAddr RomImageReader::GetRootDirList() { |
233 { |
|
234 if(iImageHeader->iRomHdr )// iImageType == EROM_IMAGE |
223 if(iImageHeader->iRomHdr )// iImageType == EROM_IMAGE |
235 return iImageHeader->iRomHdr->iRomRootDirectoryList; |
224 return iImageHeader->iRomHdr->iRomRootDirectoryList; |
236 else |
225 else |
237 return iImageHeader->iExtRomHdr->iRomRootDirectoryList; |
226 return iImageHeader->iExtRomHdr->iRomRootDirectoryList; |
238 } |
227 } |
239 |
228 |
240 TUint RomImageReader::GetHdrSize() |
229 TUint RomImageReader::GetHdrSize() { |
241 { |
|
242 TUint headerSize = 0; |
230 TUint headerSize = 0; |
243 if(EROM_IMAGE == iImgType){ |
231 if(EROM_IMAGE == iImgType){ |
244 headerSize = sizeof(TRomLoaderHeader) + sizeof(TRomHeader); |
232 headerSize = sizeof(TRomLoaderHeader) + sizeof(TRomHeader); |
245 }else if(EROMX_IMAGE == iImgType){ |
233 }else if(EROMX_IMAGE == iImgType){ |
246 headerSize = sizeof(TExtensionRomHeader); |
234 headerSize = sizeof(TExtensionRomHeader); |
247 }else if(EBAREROM_IMAGE == iImgType){ |
235 }else if(EBAREROM_IMAGE == iImgType){ |
248 headerSize = sizeof(TRomHeader); |
236 headerSize = sizeof(TRomHeader); |
249 } |
237 } |
250 return headerSize; |
238 return headerSize; |
251 } |
239 } |
252 |
240 |
253 |
241 |
254 static const TInt KIOBytes = 0x100000; |
242 static const TInt KIOBytes = 0x100000; |
255 // reading a huge buffer at a time is very slow, reading 1MB bytes at a time is much faster |
243 // reading a huge buffer at a time is very slow, reading 1MB bytes at a time is much faster |
256 void RomImageReader::ReadData(char* aBuffer, TUint aLength) |
244 void RomImageReader::ReadData(char* aBuffer, TUint aLength) { |
257 { |
|
258 TUint readBytes = 0 ; |
245 TUint readBytes = 0 ; |
259 while(readBytes < aLength){ |
246 while(readBytes < aLength){ |
260 TUint toRead = KIOBytes; |
247 TUint toRead = KIOBytes; |
261 if(readBytes + toRead > aLength) |
248 if(readBytes + toRead > aLength) |
262 toRead = aLength - readBytes ; |
249 toRead = aLength - readBytes ; |
263 iFile.read(&aBuffer[readBytes],toRead); |
250 iFile.read(&aBuffer[readBytes],toRead); |
264 readBytes += toRead ; |
251 readBytes += toRead ; |
265 } |
252 } |
266 } |
253 } |
267 void RomImageReader::ProcessImage() |
254 void RomImageReader::ProcessImage() { |
268 { |
|
269 if(iRomLayoutData) return ; |
255 if(iRomLayoutData) return ; |
270 iImageHeader = new RomImageHeader(iHeaderBuffer, iImgType); |
256 iImageHeader = new RomImageHeader(iHeaderBuffer, iImgType); |
271 |
257 |
272 iFile.seekg(0, ios::end); |
258 iFile.seekg(0, ios_base::end); |
273 // fileSize |
259 // fileSize |
274 TUint fileSize = iFile.tellg(); |
260 TUint fileSize = iFile.tellg(); |
275 |
261 |
276 //let's skip the RomLoaderHeader |
262 //let's skip the RomLoaderHeader |
277 TUint romDataBegin = (EROM_IMAGE == iImgType) ? sizeof(TRomLoaderHeader) : 0 ; |
263 TUint romDataBegin = (EROM_IMAGE == iImgType) ? sizeof(TRomLoaderHeader) : 0 ; |
278 iFile.seekg(romDataBegin,ios::beg); |
264 iFile.seekg(romDataBegin,ios_base::beg); |
279 |
265 |
280 if(EROMX_IMAGE == iImgType){// EROMX_IMAGE, just set the iUnpagedRomBuffer |
266 if(EROMX_IMAGE == iImgType){// EROMX_IMAGE, just set the iUnpagedRomBuffer |
281 if(GetImageCompressionType() == KUidCompressionDeflate){ |
267 if(GetImageCompressionType() == KUidCompressionDeflate){ |
282 TUint32 readLen = fileSize - sizeof(TExtensionRomHeader) ; |
268 TUint32 readLen = fileSize - sizeof(TExtensionRomHeader) ; |
283 iRomSize = iImageHeader->iExtRomHdr->iUncompressedSize ; |
269 iRomSize = iImageHeader->iExtRomHdr->iUncompressedSize ; |
350 } |
336 } |
351 TUint pagedIndexCount = ( hdr->iUncompressedSize + KPageSize - 1) / KPageSize; |
337 TUint pagedIndexCount = ( hdr->iUncompressedSize + KPageSize - 1) / KPageSize; |
352 // how many bytes ? |
338 // how many bytes ? |
353 // the page index table include the unpaged part ; |
339 // the page index table include the unpaged part ; |
354 TUint firstPagedIndexTblItem = hdr->iPageableRomStart / KPageSize; |
340 TUint firstPagedIndexTblItem = hdr->iPageableRomStart / KPageSize; |
355 |
341 |
356 TUint tempBufLen = KPageSize << 8; |
342 TUint tempBufLen = KPageSize << 8; |
357 char* readBuffer = new char[tempBufLen]; |
343 char* readBuffer = new char[tempBufLen]; |
358 |
344 |
359 TUint8* src,*srcNext = NULL; |
345 TUint8* src,*srcNext = NULL; |
360 SRomPageInfo* pageInfo = reinterpret_cast<SRomPageInfo*>(&iRomLayoutData[hdr->iRomPageIndex]); |
346 SRomPageInfo* pageInfo = reinterpret_cast<SRomPageInfo*>(&iRomLayoutData[hdr->iRomPageIndex]); |
361 CBytePair bp(EFalse); |
347 CBytePair bpe; |
362 for(TUint i = firstPagedIndexTblItem ; i < pagedIndexCount ; i+= 256){ |
348 for(TUint i = firstPagedIndexTblItem ; i < pagedIndexCount ; i+= 256){ |
363 TUint endIndex = i + 255 ; |
349 TUint endIndex = i + 255 ; |
364 if(endIndex >= pagedIndexCount) |
350 if(endIndex >= pagedIndexCount) |
365 endIndex = pagedIndexCount - 1; |
351 endIndex = pagedIndexCount - 1; |
366 TUint readLen = pageInfo[endIndex].iDataStart + pageInfo[endIndex].iDataSize - pageInfo[i].iDataStart ; |
352 TUint readLen = pageInfo[endIndex].iDataStart + pageInfo[endIndex].iDataSize - pageInfo[i].iDataStart ; |
367 iFile.read(readBuffer,readLen); |
353 iFile.read(readBuffer,readLen); |
368 src = reinterpret_cast<TUint8*>(readBuffer); |
354 src = reinterpret_cast<TUint8*>(readBuffer); |
369 for(TUint j = i ; j <= endIndex ; j++){ |
355 for(TUint j = i ; j <= endIndex ; j++){ |
370 switch(pageInfo[j].iCompressionType) |
356 switch(pageInfo[j].iCompressionType) { |
371 { |
357 case SRomPageInfo::EBytePair: { |
372 case SRomPageInfo::EBytePair: |
358 TInt unpacked = bpe.Decompress(reinterpret_cast<TUint8*>(curDataPointer), KPageSize, src, pageInfo[j].iDataSize, srcNext); |
373 { |
|
374 TInt unpacked = bp.Decompress(reinterpret_cast<TUint8*>(curDataPointer), KPageSize, src, pageInfo[j].iDataSize, srcNext); |
|
375 if (unpacked < 0) { |
359 if (unpacked < 0) { |
376 delete []readBuffer; |
360 delete []readBuffer; |
377 throw ImageReaderException("Corrupted BytePair compressed ROM image", ""); |
361 throw ImageReaderException("Corrupted BytePair compressed ROM image", ""); |
378 } |
362 } |
379 curDataPointer += unpacked; |
363 curDataPointer += unpacked; |
380 break ; |
364 break ; |
381 } |
365 } |
382 case SRomPageInfo::ENoCompression: |
366 case SRomPageInfo::ENoCompression: |
383 memcpy(curDataPointer,src,pageInfo[j].iDataSize); |
367 memcpy(curDataPointer,src,pageInfo[j].iDataSize); |
384 curDataPointer += pageInfo[j].iDataSize ; |
368 curDataPointer += pageInfo[j].iDataSize ; |
385 break ; |
369 break ; |
386 default: |
370 default: |
387 delete []readBuffer; |
371 delete []readBuffer; |
388 throw ImageReaderException("Undefined compression type", ""); |
372 throw ImageReaderException("Undefined compression type", ""); |
389 break ; |
373 break ; |
390 |
374 |
391 } |
375 } |
392 src += pageInfo[j].iDataSize; |
376 src += pageInfo[j].iDataSize; |
393 } // end for(TUint j = i ; j <= endIndex ; j++) |
377 } // end for(TUint j = i ; j <= endIndex ; j++) |
394 } // end for(TUint i = firstPagedIndexTblItem ; i < pagedIndexCount ; i+= 256) |
378 } // end for(TUint i = firstPagedIndexTblItem ; i < pagedIndexCount ; i+= 256) |
395 delete []readBuffer ; |
379 delete []readBuffer ; |
396 }// else |
380 }// else |
397 |
381 |
398 } // if(hasPageableSec) |
382 } // if(hasPageableSec) |
399 |
383 |
400 } |
384 } |
401 TUint32 offset = GetRootDirList() - GetRomBase(); |
385 TUint32 offset = GetRootDirList() - GetRomBase(); |
402 TRomRootDirectoryList* rootDirList = reinterpret_cast<TRomRootDirectoryList*>(iRomLayoutData + offset ); |
386 TRomRootDirectoryList* rootDirList = reinterpret_cast<TRomRootDirectoryList*>(iRomLayoutData + offset ); |
403 TInt dirCount = rootDirList->iNumRootDirs ; |
387 TInt dirCount = rootDirList->iNumRootDirs ; |
404 string tempName ; |
388 string tempName ; |
405 for(TInt i = 0 ; i < dirCount ; i++) { |
389 for(TInt i = 0 ; i < dirCount ; i++) { |
406 offset = rootDirList->iRootDir[i].iAddressLin - GetRomBase(); |
390 offset = rootDirList->iRootDir[i].iAddressLin - GetRomBase(); |
407 TRomDir* romDir = reinterpret_cast<TRomDir*>(iRomLayoutData + offset); |
391 TRomDir* romDir = reinterpret_cast<TRomDir*>(iRomLayoutData + offset); |
408 Name(tempName,reinterpret_cast<const wchar_t *>(romDir->iEntry.iName),romDir->iEntry.iNameLength); |
392 UTF16String unistr(reinterpret_cast<const TUint16*>(romDir->iEntry.iName),romDir->iEntry.iNameLength); |
|
393 if(!unistr.ToUTF8(tempName)) //not utf16? |
|
394 tempName.assign(reinterpret_cast<const char*>(romDir->iEntry.iName),romDir->iEntry.iNameLength) ; |
409 BuildDir(romDir, iRomImageRootDirEntry); |
395 BuildDir(romDir, iRomImageRootDirEntry); |
410 } |
396 } |
411 |
397 |
412 } |
398 } |
413 |
399 |
414 |
400 |
415 void RomImageReader::BuildDir(TRomDir* aDir, RomImageFSEntry* aPaFSEntry) |
401 void RomImageReader::BuildDir(TRomDir* aDir, RomImageFSEntry* aPaFSEntry) |
416 { |
402 { |
417 |
403 |
418 TInt processBytes = 0 ; |
404 TInt processBytes = 0 ; |
419 TInt totalDirBytes = aDir->iSize - sizeof(aDir->iSize); |
405 TInt totalDirBytes = aDir->iSize - sizeof(aDir->iSize); |
420 TRomEntry* entry = &aDir->iEntry; |
406 TRomEntry* entry = &aDir->iEntry; |
421 RomImageFSEntry *fsEntry ; |
407 RomImageFSEntry *fsEntry ; |
422 string name ; |
408 string pritableName ; |
423 const char* pritableName = ""; |
409 |
424 |
410 while(processBytes < totalDirBytes){ |
425 while(processBytes < totalDirBytes){ |
411 UTF16String unistr(reinterpret_cast<const TUint16*>(entry->iName),entry->iNameLength); |
426 Name(name,reinterpret_cast<const wchar_t *>(entry->iName),entry->iNameLength); |
412 if(!unistr.ToUTF8(pritableName)) |
427 pritableName = name.c_str(); |
413 pritableName.assign(reinterpret_cast<const char*>(entry->iName),entry->iNameLength); |
428 if(entry->iAtt & 0x10) { // is a directory |
414 if(entry->iAtt & 0x10) { // is a directory |
429 fsEntry = new RomImageDirEntry(pritableName); |
415 fsEntry = new RomImageDirEntry(pritableName.c_str()); |
430 AddChild(aPaFSEntry,fsEntry,NULL); |
416 AddChild(aPaFSEntry,fsEntry,NULL); |
431 TUint offset = entry->iAddressLin - GetRomBase(); |
417 TUint offset = entry->iAddressLin - GetRomBase(); |
432 TRomDir* subFolder = reinterpret_cast<TRomDir*>(iRomLayoutData + offset); |
418 TRomDir* subFolder = reinterpret_cast<TRomDir*>(iRomLayoutData + offset); |
433 BuildDir(subFolder,fsEntry); |
419 BuildDir(subFolder,fsEntry); |
434 } |
420 } |
435 else{ |
421 else{ |
436 fsEntry = new RomImageFileEntry(pritableName); |
422 fsEntry = new RomImageFileEntry(pritableName.c_str()); |
437 AddChild(aPaFSEntry,fsEntry,entry); |
423 AddChild(aPaFSEntry,fsEntry,entry); |
438 } |
424 } |
439 // increase the processedBytes |
425 // increase the processedBytes |
440 processBytes += (entry->iNameLength << 1) + reinterpret_cast<TInt>(entry->iName) - reinterpret_cast<TInt>(entry); |
426 processBytes += (entry->iNameLength << 1) + reinterpret_cast<TInt>(entry->iName) - reinterpret_cast<TInt>(entry); |
441 |
427 |
442 //align to next 4 bytes |
428 //align to next 4 bytes |
443 processBytes = (processBytes + 3) & ( ~3 ); |
429 processBytes = (processBytes + 3) & ( ~3 ); |
444 // get next entry |
430 // get next entry |
445 entry = reinterpret_cast<TRomEntry*>( reinterpret_cast<char*>(&aDir->iEntry) + processBytes); |
431 entry = reinterpret_cast<TRomEntry*>( reinterpret_cast<char*>(&aDir->iEntry) + processBytes); |
446 } |
432 } |
447 |
433 |
448 } |
434 } |
449 |
435 |
450 void RomImageReader::AddChild(RomImageFSEntry *aParent, RomImageFSEntry *aChild, TRomEntry* aRomEntry) |
436 void RomImageReader::AddChild(RomImageFSEntry *aParent, RomImageFSEntry *aChild, TRomEntry* aRomEntry) { |
451 { |
|
452 if(!aParent->iChildren) |
437 if(!aParent->iChildren) |
453 aParent->iChildren = aChild; |
438 aParent->iChildren = aChild; |
454 else { |
439 else { |
455 RomImageFSEntry *aLast = aParent->iChildren; |
440 RomImageFSEntry *aLast = aParent->iChildren; |
456 |
441 |
732 by making a call to TraverseImage function. |
695 by making a call to TraverseImage function. |
733 |
696 |
734 @internalComponent |
697 @internalComponent |
735 @released |
698 @released |
736 */ |
699 */ |
737 void RomImageReader::ExtractImageContents() |
700 void RomImageReader::ExtractImageContents() { |
738 { |
701 if( (iDisplayOptions & EXTRACT_FILE_SET_FLAG) ) { |
739 if( (iDisplayOptions & EXTRACT_FILE_SET_FLAG) ) |
|
740 { |
|
741 //TODO: |
|
742 ImageReader::ExtractFileSet(iRomLayoutData); |
702 ImageReader::ExtractFileSet(iRomLayoutData); |
743 } |
703 } |
744 |
704 |
745 if( iDisplayOptions & EXTRACT_FILES_FLAG || iDisplayOptions & LOG_IMAGE_CONTENTS_FLAG ) |
705 if( iDisplayOptions & EXTRACT_FILES_FLAG || iDisplayOptions & LOG_IMAGE_CONTENTS_FLAG ) { |
746 { |
706 if(iRomImageRootDirEntry) { |
747 if(iRomImageRootDirEntry) |
|
748 { |
|
749 // name of the log file. |
707 // name of the log file. |
750 string logFile; |
708 string logFile; |
751 // output stream for the log file. |
709 // output stream for the log file. |
752 ofstream oFile; |
710 ofstream oFile; |
753 |
711 |
754 if( iDisplayOptions & LOG_IMAGE_CONTENTS_FLAG){ |
712 if( iDisplayOptions & LOG_IMAGE_CONTENTS_FLAG){ |
755 if( ImageReader::iZdrivePath.compare("")){ |
713 if( ImageReader::iZdrivePath.compare("")){ |
756 // create a string to hold path information. |
|
757 string filePath(ImageReader::iZdrivePath); |
|
758 string delimiter("\\"); |
|
759 // replace backslash with double backslash. |
|
760 FindAndInsertString(filePath,delimiter,delimiter); |
|
761 logFile = filePath; |
|
762 // create specified directory. |
714 // create specified directory. |
763 CreateSpecifiedDir(&filePath[0],"\\\\"); |
715 CreateSpecifiedDir(ImageReader::iZdrivePath); |
764 logFile.append("\\\\"); |
716 int len = ImageReader::iZdrivePath.length() ; |
765 logFile.append(ImageReader::iLogFileName); |
717 const char* z = ImageReader::iZdrivePath.c_str(); |
|
718 logFile = ""; |
|
719 for(int i = 0 ; i < len ; i++){ |
|
720 if(z[i] == SLASH_CHAR2) |
|
721 logFile += SLASH_CHAR1; |
|
722 else |
|
723 logFile += z[i]; |
|
724 } |
|
725 len -- ; |
|
726 if(z[len] != SLASH_CHAR1) |
|
727 logFile += SLASH_CHAR1; |
|
728 logFile += ImageReader::iLogFileName ; |
766 } |
729 } |
767 else |
730 else { |
768 { |
|
769 logFile = ImageReader::iLogFileName; |
731 logFile = ImageReader::iLogFileName; |
770 } |
732 } |
771 // open the specified file in append mode. |
733 // open the specified file in append mode. |
772 oFile.open(logFile.c_str() ,ios::out|ios::app); |
734 oFile.open(logFile.c_str() ,ios_base::out|ios_base::app); |
773 |
735 |
774 if(!oFile.is_open()){ |
736 if(!oFile.is_open()){ |
775 throw ImageReaderException((char*)ImageReader::iLogFileName.c_str(), "Failed to open the log file"); |
737 throw ImageReaderException(ImageReader::iLogFileName.c_str(), "Failed to open the log file"); |
776 } |
738 } |
777 } |
739 } |
778 TraverseImage(iRomImageRootDirEntry,oFile); |
740 TraverseImage(iRomImageRootDirEntry,oFile); |
779 if(oFile.is_open()) oFile.close(); |
741 if(oFile.is_open()) oFile.close(); |
780 } |
742 } |
816 @released |
777 @released |
817 |
778 |
818 @param aEntity - pointer to the entry in rom image. |
779 @param aEntity - pointer to the entry in rom image. |
819 @param aFile - output stream. |
780 @param aFile - output stream. |
820 */ |
781 */ |
821 void RomImageReader::CheckFileExtension(RomImageFSEntry* aEntity,ofstream& aFile) |
782 void RomImageReader::CheckFileExtension(RomImageFSEntry* aEntity,ofstream& aFile) { |
822 { |
|
823 RomImageFileEntry* romEntry = (RomImageFileEntry*)aEntity; |
783 RomImageFileEntry* romEntry = (RomImageFileEntry*)aEntity; |
824 // get the size of the entity. |
784 // get the size of the entity. |
825 TUint32 size = romEntry->iTRomEntryPtr->iSize; |
785 TUint32 size = romEntry->iTRomEntryPtr->iSize; |
826 // get the offset of the entity. |
786 // get the offset of the entity. |
827 TUint32 offset = romEntry->iTRomEntryPtr->iAddressLin - GetRomBase() ; |
787 TUint32 offset = romEntry->iTRomEntryPtr->iAddressLin - GetRomBase() ; |
828 |
788 |
829 const char* fileName = aEntity->iName.c_str(); |
789 const char* fileName = aEntity->iName.c_str(); |
830 |
790 |
831 // create a string to hold the path information. |
791 // create a string to hold the path information. |
832 string romfilePath(romEntry->iPath); |
792 string romfilePath(romEntry->iPath); |
833 string forwardSlash("/"); |
793 int len = romfilePath.length(); |
834 string slash("\\"); |
794 char* str = const_cast<char*>(romfilePath.c_str()); |
835 //replace slash with double backward slash. |
795 for(int i = 0 ; i < len ; i++){ |
836 FindAndReplaceString( romfilePath, forwardSlash, slash ); |
796 if(str[i] == SLASH_CHAR2) |
837 |
797 str[i] = SLASH_CHAR1; |
|
798 } |
|
799 if(str[len - 1] != SLASH_CHAR1) |
|
800 romfilePath += SLASH_CHAR1; |
|
801 |
838 if( iDisplayOptions & LOG_IMAGE_CONTENTS_FLAG && iDisplayOptions & EXTRACT_FILES_FLAG ) { |
802 if( iDisplayOptions & LOG_IMAGE_CONTENTS_FLAG && iDisplayOptions & EXTRACT_FILES_FLAG ) { |
839 // get the position. |
803 // get the position. |
840 size_t pos = aEntity->iName.find_last_of("."); |
804 size_t pos = aEntity->iName.find_last_of("."); |
841 |
805 |
842 const char* extName = fileName + ( pos + 1 ); |
806 const char* extName = fileName + ( pos + 1 ); |
843 if ( !stricmp(extName ,"SIS") || !stricmp(extName ,"DAT") ) { |
807 if ( !stricmp(extName ,"SIS") || !stricmp(extName ,"DAT") ) { |
844 // if the two strings are same then extract the corresponding file. |
808 // if the two strings are same then extract the corresponding file. |
845 ImageReader::ExtractFile(offset,size,fileName,&romfilePath[0],&ImageReader::iZdrivePath[0],iRomLayoutData); |
809 ImageReader::ExtractFile(offset,size,fileName,romfilePath.c_str(),ImageReader::iZdrivePath.c_str(),iRomLayoutData); |
846 } |
810 } |
847 else { |
811 else { |
848 LogRomEnrtyToFile(romfilePath.c_str(),fileName,aFile); |
812 LogRomEnrtyToFile(romfilePath.c_str(),fileName,aFile); |
849 } |
813 } |
850 } |
814 } |