imgtools/imgcheck/libimgutils/src/rofsreader.cpp
changeset 590 360bd6b35136
parent 0 044383f39525
child 633 a4eca1f021ac
equal deleted inserted replaced
588:c7c26511138f 590:360bd6b35136
    32 @released
    32 @released
    33 
    33 
    34 @param aFile - image file name
    34 @param aFile - image file name
    35 @param aImageType - image type
    35 @param aImageType - image type
    36 */
    36 */
    37 RofsReader::RofsReader(char* aFile, EImageType aImageType)
    37 RofsReader::RofsReader(const char* aFile, EImageType aImageType)
    38 :ImageReader(aFile), iImageType(aImageType)
    38 :ImageReader(aFile), iImageType(aImageType) {
    39 {
       
    40 	iImageReader = new RCoreImageReader(aFile);
    39 	iImageReader = new RCoreImageReader(aFile);
    41 	iImage = new RofsImage(iImageReader);
    40 	iImage = new RofsImage(iImageReader);
    42 	iInputStream.open(aFile, Ios::binary | Ios::in);
    41 	iInputStream.open(aFile, ios_base::binary | ios_base::in);
    43 }
    42 }
    44 
    43 
    45 /** 
    44 /** 
    46 Destructor deletes the class pointer members.
    45 Destructor deletes the class pointer members.
    47 
    46 
    48 @internalComponent
    47 @internalComponent
    49 @released
    48 @released
    50 */
    49 */
    51 RofsReader::~RofsReader()
    50 RofsReader::~RofsReader() {
    52 {
    51 	 
    53 	ExeVsE32ImageMap::iterator e32ImageBegin = iExeVsE32ImageMap.begin();
    52 	 for(ExeVsE32ImageMap::iterator it = iExeVsE32ImageMap.begin();
    54     ExeVsE32ImageMap::iterator e32ImageEnd  = iExeVsE32ImageMap.end();
    53 		it != iExeVsE32ImageMap.end(); it++) {
    55 	while(e32ImageBegin != e32ImageEnd)
    54 		if(it->second){
    56 	{
    55 			delete it->second ;
    57 		DELETE(e32ImageBegin->second);
    56 			it->second = 0 ;
    58 		++e32ImageBegin;
    57 		}
    59 	}
    58 		
    60 	iRootDirEntry->Destroy();
    59 	} 
       
    60 	 
       
    61 	iRootDirEntry = 0 ;
       
    62 	 
    61 	iExeVsOffsetMap.clear();
    63 	iExeVsOffsetMap.clear();
    62 	DELETE(iImageReader);
    64 	if(iImageReader){
       
    65 		delete iImageReader;
       
    66 		iImageReader = 0 ;
       
    67 	}
       
    68 	if(iImage){
       
    69 		delete iImage;
       
    70 		iImage = 0 ;
       
    71 	}
    63 	iInputStream.close();
    72 	iInputStream.close();
    64 	iExeVsE32ImageMap.clear();
    73 	iExeVsE32ImageMap.clear();
    65 }
    74 }
    66 
    75 
    67 /** 
    76 /** 
    68 Dummy function for compatibility
    77 Dummy function for compatibility
    69 
    78 
    70 @internalComponent
    79 @internalComponent
    71 @released
    80 @released
    72 */
    81 */
    73 void RofsReader::ReadImage()
    82 void RofsReader::ReadImage() {
    74 {
       
    75 }
    83 }
    76 
    84 
    77 /** 
    85 /** 
    78 Function responsible to 
    86 Function responsible to 
    79 1. Invoke E32Imagefile process method which will read the header part and identifies the 
    87 1. Invoke E32Imagefile process method which will read the header part and identifies the 
    81 2. Prepare executable vs E32Image map, which will be used later to read the E32Image contents.
    89 2. Prepare executable vs E32Image map, which will be used later to read the E32Image contents.
    82 
    90 
    83 @internalComponent
    91 @internalComponent
    84 @released
    92 @released
    85 */
    93 */
    86 void RofsReader::ProcessImage()
    94 void RofsReader::ProcessImage() {
    87 {
       
    88 	int retVal = iImage->ProcessImage();
    95 	int retVal = iImage->ProcessImage();
    89 	if(retVal != KErrNone)
    96 	if(retVal != KErrNone) {
    90 	{
       
    91 		exit(retVal);
    97 		exit(retVal);
    92 	}
    98 	}
    93 	iRootDirEntry = iImage->RootDirectory();
    99 	iRootDirEntry = iImage->RootDirectory();
    94 	PrepareExeVsE32ImageMap(iRootDirEntry, iImage, iImageType, iInputStream, iExeVsE32ImageMap, iExeVsOffsetMap, iHiddenExeList);
   100 	PrepareExeVsE32ImageMap(iRootDirEntry, iImage, iImageType, iInputStream, iExeVsE32ImageMap, iExeVsOffsetMap, iHiddenExeList);
    95 }
   101 }
   100 @internalComponent
   106 @internalComponent
   101 @released
   107 @released
   102 
   108 
   103 @param aName - Executable name
   109 @param aName - Executable name
   104 */
   110 */
   105 bool RofsReader::IsExecutable(String aName)
   111 bool RofsReader::IsExecutable(const string& aName) {
   106 {
       
   107 	unsigned int extOffset = aName.find_last_of('.');
   112 	unsigned int extOffset = aName.find_last_of('.');
   108 	if(extOffset != String::npos)
   113 	if(extOffset != string::npos) {
   109 	{
   114 		string ext = aName.substr(extOffset);
   110 		aName = aName.substr(extOffset);
   115 		if(ext.length() <= 4) {
   111 		if(aName.length() <= 4)
   116 			ReaderUtil::ToLower(ext);
   112 		{
   117 			if (ext.find(".exe") != string::npos || ext.find(".dll") != string::npos || 
   113 			ReaderUtil::ToLower(aName);
   118 				ext.find(".prt") != string::npos || ext.find(".nif") != string::npos || 
   114 			if (aName.find(".exe") != String::npos || aName.find(".dll") != String::npos || 
   119 				ext.find(".tsy") != string::npos || ext.find(".pdl") != string::npos || 
   115 				aName.find(".prt") != String::npos || aName.find(".nif") != String::npos || 
   120 				ext.find(".csy") != string::npos || ext.find(".agt") != string::npos || 
   116 				aName.find(".tsy") != String::npos || aName.find(".pdl") != String::npos || 
   121 				ext.find(".ani") != string::npos || ext.find(".loc") != string::npos || 
   117 				aName.find(".csy") != String::npos || aName.find(".agt") != String::npos || 
   122 				ext.find(".pdd") != string::npos || ext.find(".ldd") != string::npos ||
   118 				aName.find(".ani") != String::npos || aName.find(".loc") != String::npos || 
   123 				ext.find(".drv") != string::npos)  {
   119 				aName.find(".pdd") != String::npos || aName.find(".ldd") != String::npos ||
       
   120 				aName.find(".drv") != String::npos) 
       
   121 			{
       
   122 				return true;
   124 				return true;
   123 			}
   125 			}
   124 		}
   126 		}
   125 	}
   127 	}
   126 	return false;
   128 	return false;
   138 @param aInputStream - Input stream to read image file
   140 @param aInputStream - Input stream to read image file
   139 @param aExeVsE32ImageMap - Container to be filled
   141 @param aExeVsE32ImageMap - Container to be filled
   140 @param aExeVsOffsetMap - Container to be filled
   142 @param aExeVsOffsetMap - Container to be filled
   141 @param aHiddenExeList - Hidden executables filled here.
   143 @param aHiddenExeList - Hidden executables filled here.
   142 */
   144 */
   143 void RofsReader::PrepareExeVsE32ImageMap(TRomNode* aEntry, CCoreImage *aImage, EImageType aImageType, Ifstream& aInputStream, ExeVsE32ImageMap& aExeVsE32ImageMap, ExeVsOffsetMap& aExeVsOffsetMap, StringList& aHiddenExeList)
   145 void RofsReader::PrepareExeVsE32ImageMap(TRomNode* aEntry, CCoreImage *aImage, EImageType aImageType, ifstream& aInputStream, ExeVsE32ImageMap& aExeVsE32ImageMap, ExeVsOffsetMap& aExeVsOffsetMap, StringList& aHiddenExes) {
   144 {
   146     string name(aEntry->iName);
   145     String name((char*)aEntry->iName);
       
   146 	bool insideRofs = false;
   147 	bool insideRofs = false;
   147     E32Image* e32Image;
   148     E32Image* e32Image;
   148     if(IsExecutable(name))
   149     if(IsExecutable(name)) {
   149     {
       
   150 		iExeAvailable = true;
   150 		iExeAvailable = true;
   151 		//V9.1 images has hidden file offset as 0x0
   151 		//V9.1 images has hidden file offset as 0x0
   152 		//V9.2 to V9.6 has hidden file offset as 0xFFFFFFFFF
   152 		//V9.2 to V9.6 has hidden file offset as 0xFFFFFFFFF
   153         if(aEntry->iEntry->iFileOffset != KFileHidden && aEntry->iEntry->iFileOffset != KFileHidden_9_1)
   153         if(aEntry->iEntry->iFileOffset != KFileHidden && aEntry->iEntry->iFileOffset != KFileHidden_9_1) {
   154         {
       
   155             long fileOffset = 0;
   154             long fileOffset = 0;
   156             if(aImageType == ERofsExImage)
   155             if(aImageType == ERofsExImage) {
   157             {
   156 				if(aEntry->iEntry->iFileOffset > (long)((RofsImage*)aImage)->iAdjustment) {
   158 				if(aEntry->iEntry->iFileOffset > (long)((RofsImage*)aImage)->iAdjustment)
       
   159 				{
       
   160 	            // File exists in Rofs extension 
   157 	            // File exists in Rofs extension 
   161 		            fileOffset = aEntry->iEntry->iFileOffset - ((RofsImage*)aImage)->iAdjustment;
   158 		            fileOffset = aEntry->iEntry->iFileOffset - ((RofsImage*)aImage)->iAdjustment;
   162 				}
   159 				}
   163 				else
   160 				else {
   164 				{
       
   165 					insideRofs = true;
   161 					insideRofs = true;
   166 				}
   162 				}
   167             }
   163             }
   168             else
   164             else {
   169             {
       
   170 	            // For rofs files
   165 	            // For rofs files
   171 	            fileOffset = aEntry->iEntry->iFileOffset;
   166 	            fileOffset = aEntry->iEntry->iFileOffset;
   172             }
   167             }
   173 	            
   168 	            
   174             aInputStream.seekg(fileOffset, Ios::beg);
   169             aInputStream.seekg(fileOffset, ios_base::beg);
   175             /*
   170             /*
   176             Due to the complexities involved in sending the physical file size to E32Reader class, 
   171             Due to the complexities involved in sending the physical file size to E32Reader class, 
   177             here we avoided using it for gathering dependencies. Hence class E32ImageFile is used
   172             here we avoided using it for gathering dependencies. Hence class E32ImageFile is used
   178             directly.
   173             directly.
   179             */
   174             */
   180             e32Image = new E32Image();
   175             e32Image = new E32Image();
   181             e32Image->iFileSize = aEntry->iSize;
   176             e32Image->iFileSize = aEntry->iSize;
   182             e32Image->Adjust(aEntry->iSize); //Initialise the data pointer to the file size
   177             e32Image->Adjust(aEntry->iSize); //Initialise the data pointer to the file size
   183             aInputStream >> *e32Image; //Input the E32 file to E32ImageFile class
   178             aInputStream >> *e32Image; //Input the E32 file to E32ImageFile class
   184             aExeVsOffsetMap[ReaderUtil::ToLower(name)] = fileOffset;
   179             put_item_to_map(aExeVsOffsetMap,aEntry->iName,fileOffset);
   185 			if(!insideRofs)
   180 			if(!insideRofs) {
   186 			{
   181 				put_item_to_map_2(aExeVsE32ImageMap,aEntry->iName, e32Image);
   187 				aExeVsE32ImageMap.insert(std::make_pair(ReaderUtil::ToLower(name), e32Image));
   182 				
   188 			}
   183 			}
   189         }
   184         }
   190         else
   185         else { 
   191         {
   186             aHiddenExes.push_back(aEntry->iName);
   192             aHiddenExeList.push_back(ReaderUtil::ToLower(name));
       
   193         }
   187         }
   194     }
   188     }
   195 
   189 
   196     if(aEntry->Currentchild())
   190     if(aEntry->Currentchild()) {
   197     {
   191         PrepareExeVsE32ImageMap(aEntry->Currentchild(), aImage, aImageType, aInputStream, aExeVsE32ImageMap, aExeVsOffsetMap, aHiddenExes);
   198         PrepareExeVsE32ImageMap(aEntry->Currentchild(), aImage, aImageType, aInputStream, aExeVsE32ImageMap, aExeVsOffsetMap, aHiddenExeList);
       
   199     }
   192     }
   200     if(aEntry->Currentsibling())
   193     if(aEntry->Currentsibling()) {
   201     {
   194         PrepareExeVsE32ImageMap(aEntry->Currentsibling(), aImage, aImageType, aInputStream, aExeVsE32ImageMap, aExeVsOffsetMap, aHiddenExes);
   202         PrepareExeVsE32ImageMap(aEntry->Currentsibling(), aImage, aImageType, aInputStream, aExeVsE32ImageMap, aExeVsOffsetMap, aHiddenExeList);
       
   203     }
   195     }
   204 }
   196 }
   205 
   197 
   206 /** 
   198 /** 
   207 Function responsible to the executable lists using the container iExeVsE32ImageMap.
   199 Function responsible to the executable lists using the container iExeVsE32ImageMap.
   208 
   200 
   209 @internalComponent
   201 @internalComponent
   210 @released
   202 @released
   211 */
   203 */
   212 void RofsReader::PrepareExecutableList()
   204 void RofsReader::PrepareExecutableList() { 
   213 {
   205 	iExecutableList.clear();
   214     ExeVsE32ImageMap::iterator e32ImageBegin = iExeVsE32ImageMap.begin();
   206     for(ExeVsE32ImageMap::iterator it = iExeVsE32ImageMap.begin();
   215     ExeVsE32ImageMap::iterator e32ImageEnd  = iExeVsE32ImageMap.end();
   207 		it != iExeVsE32ImageMap.end() ; it ++) { 
   216     E32Image* entry;
   208         iExecutableList.push_back(it->first); 
   217     String name;
       
   218     while(e32ImageBegin != e32ImageEnd)
       
   219     {
       
   220         entry = e32ImageBegin->second;
       
   221         name = e32ImageBegin->first;
       
   222         iExecutableList.push_back(name);
       
   223         ++e32ImageBegin;
       
   224     }
   209     }
   225 	DeleteHiddenExecutableVsE32ImageEntry();
   210 	DeleteHiddenExecutableVsE32ImageEntry();
   226 }
   211 }
   227 
   212 
   228 /** 
   213 /** 
   230 avoid the dependency data collection for the same.
   215 avoid the dependency data collection for the same.
   231 
   216 
   232 @internalComponent
   217 @internalComponent
   233 @released
   218 @released
   234 */
   219 */
   235 void RofsReader::DeleteHiddenExecutableVsE32ImageEntry()
   220 void RofsReader::DeleteHiddenExecutableVsE32ImageEntry() { 
   236 {
   221 	for(StringList::iterator it = iHiddenExeList.begin();
   237 	StringList::iterator hExeBegin = iHiddenExeList.begin();
   222 		it != iHiddenExeList.end(); it++){ 
   238 	StringList::iterator hExeEnd = iHiddenExeList.end();
       
   239 	ExeVsE32ImageMap::iterator loc;
       
   240 
       
   241 	while(hExeBegin != hExeEnd)
       
   242 	{
       
   243 		//Remove the hidden executable entry from executables vs RomNode Map
   223 		//Remove the hidden executable entry from executables vs RomNode Map
   244 		loc = iExeVsE32ImageMap.find(*hExeBegin);
   224 		ExeVsE32ImageMap::iterator pos = iExeVsE32ImageMap.find(*it);
   245 		if(loc != iExeVsE32ImageMap.end())
   225 		if(pos != iExeVsE32ImageMap.end()) { 
   246 		{
   226 			if(pos->second)
   247 			iExeVsE32ImageMap.erase(loc);
   227 				delete pos->second ;
   248 		}
   228 			iExeVsE32ImageMap.erase(pos);
   249 		++hExeBegin;
   229 		} 
   250 	}
   230 	}
   251 }
   231 }
   252 
   232 
   253 /** 
   233 /** 
   254 Function responsible to gather dependencies for all the executables using the container iExeVsE32ImageMap.
   234 Function responsible to gather dependencies for all the executables using the container iExeVsE32ImageMap.
   256 @internalComponent
   236 @internalComponent
   257 @released
   237 @released
   258 
   238 
   259 @return iImageVsDepList - returns all executable's dependencies
   239 @return iImageVsDepList - returns all executable's dependencies
   260 */
   240 */
   261 ExeNamesVsDepListMap& RofsReader::GatherDependencies()
   241 ExeNamesVsDepListMap& RofsReader::GatherDependencies() { 
   262 {
   242 
   263 	ExeVsE32ImageMap::iterator begin = iExeVsE32ImageMap.begin();
   243 	StringList executables;
   264 	ExeVsE32ImageMap::iterator end = iExeVsE32ImageMap.end();
   244 	for(ExeVsE32ImageMap::iterator it = iExeVsE32ImageMap.begin() ; 
   265 
   245 		it != iExeVsE32ImageMap.end() ; it++) {
   266 	StringList executableList;
   246 		PrepareExeDependencyList(it->second, executables);
   267 	while(begin != end)
   247 		put_item_to_map(iImageVsDepList,it->first, executables);
   268 	{
   248 		executables.clear(); 
   269 		PrepareExeDependencyList((*begin).second, executableList);
       
   270 		iImageVsDepList.insert(std::make_pair((*begin).first, executableList));
       
   271 		executableList.clear();
       
   272 		++begin;
       
   273 	}
   249 	}
   274 	return iImageVsDepList;
   250 	return iImageVsDepList;
   275 }
   251 }
   276 
   252 
   277 /** 
   253 /** 
   280 
   256 
   281 @internalComponent
   257 @internalComponent
   282 @released
   258 @released
   283 
   259 
   284 @param - aE32Image, Using this, can get all the information about the executable
   260 @param - aE32Image, Using this, can get all the information about the executable
   285 @param - aExecutableList, Excutables placed into this list
   261 @param - aExecutables, Excutables placed into this list
   286 */
   262 */
   287 void RofsReader::PrepareExeDependencyList(E32Image* aE32Image, StringList& aExecutableList)
   263 void RofsReader::PrepareExeDependencyList(E32Image* aE32Image, StringList& aExecutables) {
   288 {
       
   289 	int count = 0;
   264 	int count = 0;
   290 	char** nameList = aE32Image->GetImportExecutableNames(count);
   265 	char** names = aE32Image->GetImportExecutableNames(count); 
   291 	int i = 0;
   266 	for(int i = 0 ; i < count; ++i) { 
   292 	String dependency;
   267 		aExecutables.push_back(names[i]);
   293 	for(; i < count; ++i)
   268 	}
   294 	{
   269 	if(names){
   295 		dependency.assign(nameList[i]);
   270 		delete [](reinterpret_cast<long*>(names));
   296 		aExecutableList.push_back(ReaderUtil::ToLower(dependency));
   271 	}
   297 	}
       
   298 	DELETE(nameList);
       
   299 }
   272 }
   300 
   273 
   301 /** 
   274 /** 
   302 Function responsible to say whether it is an ROFS image or not.
   275 Function responsible to say whether it is an ROFS image or not.
   303 
   276 
   304 @internalComponent
   277 @internalComponent
   305 @released
   278 @released
   306 
   279 
   307 @param - aWord which has the identifier string
   280 @param - aWord which has the identifier string
   308 */
   281 */
   309 bool RofsReader::IsRofsImage(String& aWord)
   282 bool RofsReader::IsRofsImage(const string& aWord) {
   310 {
   283 	return (aWord.find(KRofsImageIdentifier) == 0);//Identifier should start at the beginning
   311 	if(aWord.find(KRofsImageIdentifier) == 0) //Identifier should start at the beginning
   284  
   312 	{
       
   313 		return true;
       
   314 	}
       
   315 	return false;
       
   316 }
   285 }
   317 
   286 
   318 /** 
   287 /** 
   319 Function responsible to say whether it is an ROFS extension image or not.
   288 Function responsible to say whether it is an ROFS extension image or not.
   320 
   289 
   321 @internalComponent
   290 @internalComponent
   322 @released
   291 @released
   323 
   292 
   324 @param - aWord which has the identifier string
   293 @param - aWord which has the identifier string
   325 */
   294 */
   326 bool RofsReader::IsRofsExtImage(String& aWord)
   295 bool RofsReader::IsRofsExtImage(const string& aWord) {
   327 {
   296 	return (aWord.find(KRofsExtImageIdentifier) == 0) ;//Identifier should start at the beginning
   328 	if(aWord.find(KRofsExtImageIdentifier) == 0) //Identifier should start at the beginning
       
   329 	{
       
   330 		return true;
       
   331 	}
       
   332 	return false;
       
   333 }
   297 }
   334 
   298 
   335 /** 
   299 /** 
   336 Function responsible to traverse through the the map using the container iExeVsE32ImageMap to collect 
   300 Function responsible to traverse through the the map using the container iExeVsE32ImageMap to collect 
   337 iExeVsIdData.
   301 iExeVsIdData.
   338 
   302 
   339 @internalComponent
   303 @internalComponent
   340 @released
   304 @released
   341 */
   305 */
   342 void RofsReader::PrepareExeVsIdMap()
   306 void RofsReader::PrepareExeVsIdMap() { 
   343 {
   307     if(iExeVsIdData.size() == 0) {//Is not already prepared 
   344     ExeVsE32ImageMap::iterator begin = iExeVsE32ImageMap.begin();
   308         for(ExeVsE32ImageMap::iterator it = iExeVsE32ImageMap.begin();
   345     ExeVsE32ImageMap::iterator end = iExeVsE32ImageMap.end();
   309 			it != iExeVsE32ImageMap.end() ; it++) {
   346     String exeName;
   310             string exeName(it->first);
   347     E32Image* e32Image;
   311             E32Image* e32Image = it->second;
   348     IdData* id;
   312 			IdData* id = new IdData;
   349     if(iExeVsIdData.size() == 0) //Is not already prepared
       
   350     {
       
   351         while(begin != end)
       
   352         {
       
   353             exeName = begin->first;
       
   354             e32Image = begin->second;
       
   355 			id = new IdData;
       
   356 			id->iUid = e32Image->iOrigHdr->iUid1;
   313 			id->iUid = e32Image->iOrigHdr->iUid1;
   357 			id->iDbgFlag = (e32Image->iOrigHdr->iFlags & KImageDebuggable)? true : false;
   314 			id->iDbgFlag = (e32Image->iOrigHdr->iFlags & KImageDebuggable)? true : false;
   358             TUint aHeaderFmt = E32ImageHeader::HdrFmtFromFlags(e32Image->iOrigHdr->iFlags);
   315             TUint aHeaderFmt = E32ImageHeader::HdrFmtFromFlags(e32Image->iOrigHdr->iFlags);
   359 	        if (aHeaderFmt >= KImageHdrFmt_V)
   316 	        if (aHeaderFmt >= KImageHdrFmt_V) {
   360 	        {
       
   361                 E32ImageHeaderV* v = e32Image->iHdr;
   317                 E32ImageHeaderV* v = e32Image->iHdr;
   362                 id->iSid = v->iS.iSecureId;
   318                 id->iSid = v->iS.iSecureId;
   363                 id->iVid = v->iS.iVendorId;
   319                 id->iVid = v->iS.iVendorId;
   364 	        }
   320 	        }
   365 			id->iFileOffset = iExeVsOffsetMap[exeName];
   321 			id->iFileOffset = iExeVsOffsetMap[exeName]; 
   366 			iExeVsIdData[exeName] = id;
   322 			put_item_to_map_2(iExeVsIdData,exeName,id); 
   367             ++begin;
       
   368         }
   323         }
   369     }
   324     } 
   370 	id = KNull;
       
   371 }
   325 }
   372 
   326 
   373 /** 
   327 /** 
   374 Function responsible to return the Executable versus IdData container. 
   328 Function responsible to return the Executable versus IdData container. 
   375 
   329 
   376 @internalComponent
   330 @internalComponent
   377 @released
   331 @released
   378 
   332 
   379 @return - returns iExeVsIdData
   333 @return - returns iExeVsIdData
   380 */
   334 */
   381 const ExeVsIdDataMap& RofsReader::GetExeVsIdMap() const
   335 const ExeVsIdDataMap& RofsReader::GetExeVsIdMap() const {
   382 {
       
   383     return iExeVsIdData;
   336     return iExeVsIdData;
   384 }
   337 }