e32tools/elf2e32/source/e32imagefile.cpp
changeset 607 378360dbbdba
parent 590 360bd6b35136
parent 606 30b30f9da0b7
child 675 02e65118a746
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
    31 #include "elffilesupplied.h"
    31 #include "elffilesupplied.h"
    32 #include "pl_dllsymbol.h"
    32 #include "pl_dllsymbol.h"
    33 #include "h_ver.h"
    33 #include "h_ver.h"
    34 #include "checksum.h"
    34 #include "checksum.h"
    35 #include "errorhandler.h"
    35 #include "errorhandler.h"
       
    36 #include "byte_pair.h"
    36 
    37 
    37 #include <string>
    38 #include <string>
    38 #include <vector>
    39 #include <vector>
    39 #include <cassert>
    40 #include <cassert>
    40 #include <iostream>
    41 #include <iostream>
    54 	unsigned int mask = ~inc;
    55 	unsigned int mask = ~inc;
    55 	unsigned int val = (unsigned int)v;
    56 	unsigned int val = (unsigned int)v;
    56 	unsigned int res = (val+inc) & mask;
    57 	unsigned int res = (val+inc) & mask;
    57 	return (T)res;
    58 	return (T)res;
    58 }
    59 }
    59 
       
    60 // Need a default constructor for TVersion, but don't want all the other stuff in h_utl.cpp
       
    61 /**
       
    62 Default constructor for TVersion class.
       
    63 @internalComponent
       
    64 @released
       
    65 */
       
    66 TVersion::TVersion(){}
       
    67 
       
    68 /**
       
    69 Constructor for TVersion class.
       
    70 @internalComponent
       
    71 @released
       
    72 */
       
    73 TVersion::TVersion(TInt aMajor, TInt aMinor, TInt aBuild): 
       
    74 	iMajor((TInt8)aMajor), iMinor((TInt8)aMinor), iBuild((TInt16)aBuild)
       
    75 {
       
    76 }
       
    77 
       
    78 
    60 
    79 /**
    61 /**
    80 Constructor for E32ImageChunkDesc class.
    62 Constructor for E32ImageChunkDesc class.
    81 @internalComponent
    63 @internalComponent
    82 @released
    64 @released
  1404 @param size
  1386 @param size
  1405 @param os
  1387 @param os
  1406 @internalComponent
  1388 @internalComponent
  1407 @released
  1389 @released
  1408 */
  1390 */
  1409 void CompressPages(TUint8 * bytes, TInt size, ofstream& os);
  1391 void CompressPages(TUint8 * bytes, TInt size, ostream& os, CBytePair *aBPE);
  1410 
  1392 
  1411 
  1393 
  1412 /**
  1394 /**
  1413 This function writes into the final E32 image file.
  1395 This function writes into the final E32 image file.
  1414 @param aName - E32 image file name
  1396 @param aName - E32 image file name
  1434 		{
  1416 		{
  1435 			size_t aHeaderSize = GetExtendedE32ImageHeaderSize();
  1417 			size_t aHeaderSize = GetExtendedE32ImageHeaderSize();
  1436 			os->write(iE32Image, aHeaderSize);
  1418 			os->write(iE32Image, aHeaderSize);
  1437 			
  1419 			
  1438 			// Compress and write out code part
  1420 			// Compress and write out code part
       
  1421 			CBytePair bpe;
  1439 			int srcStart = GetExtendedE32ImageHeaderSize();
  1422 			int srcStart = GetExtendedE32ImageHeaderSize();
  1440 			CompressPages( (TUint8*)iE32Image + srcStart, iHdr->iCodeSize, *os);
  1423 			CompressPages( (TUint8*)iE32Image + srcStart, iHdr->iCodeSize, *os, &bpe);
  1441 			
  1424 			
  1442 			
  1425 			
  1443 			// Compress and write out data part
  1426 			// Compress and write out data part
  1444 			srcStart += iHdr->iCodeSize;
  1427 			srcStart += iHdr->iCodeSize;
  1445 			int srcLen = GetE32ImageSize() - srcStart;
  1428 			int srcLen = GetE32ImageSize() - srcStart;
  1446 			
  1429 			
  1447 			CompressPages((TUint8*)iE32Image + srcStart, srcLen, *os);		
  1430 			CompressPages((TUint8*)iE32Image + srcStart, srcLen, *os, &bpe);		
  1448 
  1431 
  1449 		}
  1432 		}
  1450 		else if (compression == 0)
  1433 		else if (compression == 0)
  1451 		{
  1434 		{
  1452 			os->write(iE32Image, GetE32ImageSize()); // image not compressed
  1435 			os->write(iE32Image, GetE32ImageSize()); // image not compressed
  1700 	
  1683 	
  1701 	return KErrNone;
  1684 	return KErrNone;
  1702 }
  1685 }
  1703 
  1686 
  1704 
  1687 
  1705 int  DecompressPages(TUint8 * bytes, ifstream& is);
  1688 int DecompressPages(TUint8 * bytes, istream& is, CBytePair *aBPE);
  1706 
  1689 
  1707 
  1690 
  1708 /**
  1691 /**
  1709 This function creates the E32 image reading from the file
  1692 This function creates the E32 image reading from the file
  1710 @param is
  1693 @param is
  1771 		if (aImage.iData==NULL)
  1754 		if (aImage.iData==NULL)
  1772 			return is;
  1755 			return is;
  1773 		oh = aImage.iOrigHdr;
  1756 		oh = aImage.iOrigHdr;
  1774 
  1757 
  1775 		// Read and decompress code part of the image
  1758 		// Read and decompress code part of the image
  1776 
  1759 		CBytePair bpe;
  1777 		unsigned int uncompressedCodeSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz), is);
  1760 		unsigned int uncompressedCodeSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz), is, &bpe);
  1778 
  1761 
  1779 		
  1762 		
  1780 		// Read and decompress data part of the image
  1763 		// Read and decompress data part of the image
  1781 
  1764 
  1782 		unsigned int uncompressedDataSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz + uncompressedCodeSize), is);
  1765 		unsigned int uncompressedDataSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz + uncompressedCodeSize), is, &bpe);
  1783 
  1766 
  1784 		if (uncompressedCodeSize + uncompressedDataSize != uncompsize)
  1767 		if (uncompressedCodeSize + uncompressedDataSize != uncompsize)
  1785 			MessageHandler::GetInstance()->ReportMessage(WARNING, BYTEPAIRINCONSISTENTSIZEERROR);
  1768 			MessageHandler::GetInstance()->ReportMessage(WARNING, BYTEPAIRINCONSISTENTSIZEERROR);
  1786 
  1769 
  1787 		if ((TUint)orighdrsz > oh->iCodeOffset)
  1770 		if ((TUint)orighdrsz > oh->iCodeOffset)