imgtools/imgcheck/libimgutils/src/e32reader.cpp
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 2007-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 
       
    25 #include "e32reader.h"
       
    26 #include <f32image.h>
       
    27 
       
    28 /** 
       
    29 Constructor.
       
    30 
       
    31 @internalComponent
       
    32 @released
       
    33 */
       
    34 E32Image::E32Image()
       
    35 :E32ImageFile()
       
    36 {
       
    37 }
       
    38 
       
    39 /** 
       
    40 Destructor.
       
    41 
       
    42 @internalComponent
       
    43 @released
       
    44 */
       
    45 E32Image::~E32Image()
       
    46 {
       
    47 }
       
    48 
       
    49 /** 
       
    50 Function responsible to read the import section of an e32 image and return the dependency names.
       
    51 
       
    52 @internalComponent
       
    53 @released
       
    54 
       
    55 @param aCount - Number of imports found
       
    56 
       
    57 @return - returns the two dimensional 
       
    58 */
       
    59 char** E32Image::GetImportExecutableNames(int& aCount)
       
    60 {
       
    61 	const E32ImportSection* isection = (const E32ImportSection*)(iData + iOrigHdr->iImportOffset);
       
    62 	const E32ImportBlock* impBlock = (const E32ImportBlock*)(isection + 1);
       
    63 
       
    64 	char** nameList = (char**)malloc(iOrigHdr->iDllRefTableCount * sizeof(char*));
       
    65 
       
    66 	aCount = iOrigHdr->iDllRefTableCount;
       
    67 
       
    68 	for (int d = 0; d < iOrigHdr->iDllRefTableCount; ++d)
       
    69 		{
       
    70 			char* dllname = iData + iOrigHdr->iImportOffset + impBlock->iOffsetOfDllName;
       
    71 			char* curlyStart = strchr(dllname, '{');
       
    72 			char* dotStart = strrchr(dllname, '.');
       
    73 			
       
    74 			dllname[curlyStart - dllname] = '\0';
       
    75 			strcat(dllname,dotStart);
       
    76 			
       
    77 			nameList[d] = dllname;
       
    78 			TUint impfmt = iOrigHdr->ImportFormat();
       
    79 			impBlock = impBlock->NextBlock(impfmt); //Get next import block
       
    80 		}
       
    81 	return nameList;	
       
    82 }
       
    83 
       
    84 /** 
       
    85 Constructor intializes the class pointer members.
       
    86 
       
    87 @internalComponent
       
    88 @released
       
    89 
       
    90 @param aImageName - image file name
       
    91 */
       
    92 E32Reader::E32Reader(char* aImageName)
       
    93 :ImageReader(aImageName)
       
    94 {
       
    95 	iInputStream.open(iImgFileName.c_str(), Ios::binary | Ios::in);
       
    96 	int fwdSlashOff = iImgFileName.find_last_of('/');
       
    97 	int bwdSlashOff = iImgFileName.find_last_of('\\');
       
    98 	int exeNameOff = (fwdSlashOff > bwdSlashOff) ? fwdSlashOff : bwdSlashOff;
       
    99 	iExeName = iImgFileName.substr(exeNameOff + 1);
       
   100 }
       
   101 
       
   102 /** 
       
   103 Destructor deletes the class pointer members.
       
   104 
       
   105 @internalComponent
       
   106 @released
       
   107 */
       
   108 E32Reader::~E32Reader()
       
   109 {
       
   110 	iInputStream.close();
       
   111 	DELETE(iE32Image);
       
   112 }
       
   113 
       
   114 /** 
       
   115 Function responsible to say whether it is an e32 image or not.
       
   116 
       
   117 @internalComponent
       
   118 @released
       
   119 
       
   120 @param aImage - e32 image
       
   121 */
       
   122 bool E32Reader::IsE32Image(char* aFile)
       
   123 {
       
   124 	if(E32Image::IsE32ImageFile(aFile))
       
   125 		return true;
       
   126 	return false;
       
   127 }
       
   128 
       
   129 /** 
       
   130 Funtion to read the whole e32 image file and write the contents into iData memeber
       
   131 
       
   132 @internalComponent
       
   133 @released
       
   134 */
       
   135 void E32Reader::ReadImage()
       
   136 {
       
   137 	if( !iInputStream.is_open() )
       
   138 	{
       
   139 		cerr << "Error: " << "Can not open file" << iImgFileName.c_str() << endl;
       
   140 		exit(EXIT_FAILURE);
       
   141 	}
       
   142 	iE32Image = new E32Image();
       
   143 	iInputStream.seekg(0, Ios::end);
       
   144 	TUint32 aSz = iInputStream.tellg();
       
   145 	iInputStream.seekg(0, Ios::beg);
       
   146 	iE32Image->Adjust(aSz);
       
   147 	iE32Image->iFileSize = aSz;
       
   148 }
       
   149 
       
   150 /** 
       
   151 Function responsible to read the E32 image and put the data into E32ImageFile object.
       
   152 It is achieved using the operator >> overloaded function.
       
   153 
       
   154 @internalComponent
       
   155 @released
       
   156 */
       
   157 void E32Reader::ProcessImage()
       
   158 {
       
   159 	iInputStream >> *iE32Image;
       
   160 	iExeAvailable = true;
       
   161 }
       
   162 
       
   163 /** 
       
   164 Function responsible to gather dependencies for one e32 image.
       
   165 
       
   166 @internalComponent
       
   167 @released
       
   168 
       
   169 @return iExeNamesVsDepListMap - returns all executable's dependencies
       
   170 */
       
   171 ExeNamesVsDepListMap& E32Reader::GatherDependencies()
       
   172 {
       
   173 	int count=0;
       
   174 	char** nameList = iE32Image->GetImportExecutableNames(count);
       
   175 	int i = 0;
       
   176 	for(; i < count; ++i)
       
   177 	{
       
   178 		iDependencyList.push_back(String(nameList[i]));
       
   179 	}
       
   180 	iImageVsDepList.insert(std::make_pair(iExeName, iDependencyList));
       
   181 	return iImageVsDepList;
       
   182 }
       
   183 
       
   184 /** 
       
   185 Function responsible to return the dependency list of an e32 image.
       
   186 
       
   187 @internalComponent
       
   188 @released
       
   189 
       
   190 @return iDependencyList - returns all executable's dependencies
       
   191 */
       
   192 const StringList& E32Reader::GetDependencyList()
       
   193 {
       
   194 	return iDependencyList;
       
   195 }
       
   196 
       
   197 /** 
       
   198 Function responsible prepare the ExeVsId map.
       
   199 
       
   200 @internalComponent
       
   201 @released
       
   202 */
       
   203 void E32Reader::PrepareExeVsIdMap()
       
   204 {
       
   205 	IdData* id;
       
   206 	if(iExeVsIdData.size() == 0) //Is not already prepared
       
   207 	{
       
   208 		id = new IdData;
       
   209 		id->iUid = iE32Image->iOrigHdr->iUid1;
       
   210 		id->iDbgFlag = (iE32Image->iOrigHdr->iFlags & KImageDebuggable)? true : false;
       
   211 		TUint aHeaderFmt = E32ImageHeader::HdrFmtFromFlags(iE32Image->iOrigHdr->iFlags);
       
   212 		if (aHeaderFmt >= KImageHdrFmt_V)
       
   213 		{
       
   214 			E32ImageHeaderV* v = iE32Image->iHdr;
       
   215 			id->iSid = v->iS.iSecureId;
       
   216 			id->iVid = v->iS.iVendorId;
       
   217 		}
       
   218 		id->iFileOffset = 0;
       
   219 		iExeVsIdData[iExeName] = id;
       
   220 	}
       
   221 	id = KNull;
       
   222 }
       
   223 
       
   224 /** 
       
   225 Function responsible to return the Executable versus IdData container. 
       
   226 
       
   227 @internalComponent
       
   228 @released
       
   229 
       
   230 @return - returns iExeVsIdData
       
   231 */
       
   232 const ExeVsIdDataMap& E32Reader::GetExeVsIdMap() const
       
   233 {
       
   234 	return iExeVsIdData;
       
   235 }