imgtools/imgcheck/libimgutils/src/imagereader.cpp
changeset 2 39c28ec933dd
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     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 "imagereader.h"
       
    26 #include "romreader.h"
       
    27 #include "rofsreader.h"
       
    28 
       
    29 #include <time.h>
       
    30 
       
    31 /** 
       
    32 Constructor intializes the input stream.
       
    33 
       
    34 @internalComponent
       
    35 @released
       
    36 
       
    37 @param aFile - image file name
       
    38 */
       
    39 ImageReader::ImageReader(const char* aFile)
       
    40 :iImgFileName(String(aFile)), iImageSize(0), iExeAvailable(false)
       
    41 {
       
    42 }
       
    43 
       
    44 /** 
       
    45 Destructor closes the input stream
       
    46 
       
    47 @internalComponent
       
    48 @released
       
    49 */
       
    50 ImageReader::~ImageReader()
       
    51 {
       
    52     ExeVsIdDataMap::iterator exeBegin = iExeVsIdData.begin();
       
    53     ExeVsIdDataMap::iterator exeEnd = iExeVsIdData.end();
       
    54     while(exeBegin != exeEnd)
       
    55     {
       
    56         DELETE(exeBegin->second);
       
    57         ++exeBegin;
       
    58     }
       
    59 	iHiddenExeList.clear();
       
    60 	iExecutableList.clear();
       
    61 	iImageVsDepList.clear();
       
    62 }
       
    63 
       
    64 /** 
       
    65 Function responsible to identify the image type
       
    66 
       
    67 @internalComponent
       
    68 @released
       
    69 
       
    70 @param aImageName - image filename
       
    71 */
       
    72 EImageType ImageReader::ReadImageType(const String aImageName)
       
    73 {
       
    74 	char* imageName = (char*)aImageName.c_str();
       
    75 	Ifstream aIfs(imageName, Ios::in | Ios::binary);
       
    76 	if(!aIfs)
       
    77 	{
       
    78 		cout << "Error: " << "Cannot open file: " << imageName << endl;
       
    79 		exit(EXIT_FAILURE);
       
    80 	}
       
    81 	EImageType imgType = EUnknownImage;
       
    82 	char* aMagicW = new char[1024];
       
    83 	aIfs.read(aMagicW, 1024);
       
    84 	aIfs.close();
       
    85 	String magicWord(aMagicW, 1024);
       
    86 	if(aMagicW != NULL)
       
    87 		delete [] aMagicW;
       
    88 	aMagicW = 0;
       
    89 
       
    90 	if(RofsReader::IsRofsImage(magicWord))
       
    91 	{
       
    92 		imgType = ERofsImage;        
       
    93 	}
       
    94 	else if(RofsReader::IsRofsExtImage(magicWord))
       
    95 	{
       
    96 		imgType = ERofsExImage;
       
    97 	}
       
    98 	else if (RomReader::IsRomImage(magicWord))
       
    99 	{
       
   100 		imgType = ERomImage;
       
   101 	}
       
   102 	else if(RomReader::IsRomExtImage(magicWord))
       
   103 	{
       
   104 		imgType = ERomExImage;
       
   105 	}
       
   106 	return imgType;
       
   107 }
       
   108 
       
   109 /** 
       
   110 Dummy function.
       
   111 
       
   112 @internalComponent
       
   113 @released
       
   114 */
       
   115 void ImageReader::PrepareExecutableList()
       
   116 {
       
   117 }
       
   118 
       
   119 /** 
       
   120 Function responsible to return the executable list
       
   121 
       
   122 @internalComponent
       
   123 @released
       
   124 
       
   125 @return iExecutableList - returns all executable names present in the image
       
   126 */
       
   127 const StringList& ImageReader::GetExecutableList() const
       
   128 {
       
   129 	return iExecutableList;
       
   130 }
       
   131 
       
   132 /** 
       
   133 Function responsible to return the Hidden executables list
       
   134 
       
   135 @internalComponent
       
   136 @released
       
   137 
       
   138 @return iHiddenExeList - returns all hidden executable names present in the image
       
   139 */
       
   140 const StringList& ImageReader::GetHiddenExeList() const
       
   141 {
       
   142 	return iHiddenExeList;
       
   143 }
       
   144 
       
   145 /** 
       
   146 Function responsible to return the image name which is under process
       
   147 
       
   148 @internalComponent
       
   149 @released
       
   150 
       
   151 @return iImgFileName - the image name which is under process
       
   152 */
       
   153 String& ImageReader::ImageName()
       
   154 {
       
   155 	return iImgFileName;
       
   156 }
       
   157 
       
   158 /** 
       
   159 Function responsible to identify the executable presence.
       
   160 
       
   161 @internalComponent
       
   162 @released
       
   163 
       
   164 @return true - Executable is present
       
   165         false - Executable is not present
       
   166 */
       
   167 bool ImageReader::ExecutableAvailable()
       
   168 {
       
   169 	return iExeAvailable;
       
   170 }