secureswitools/swisistools/source/interpretsislib/installablefile.cpp
changeset 0 ba25891c3a9e
child 50 c6e8afe0ba85
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006-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 #pragma warning (disable: 4786)
       
    20 
       
    21 #include <vector>
       
    22 #include <algorithm>
       
    23 #include <stdio.h>
       
    24 #include <iostream>
       
    25 
       
    26 #include "installablefile.h"
       
    27 #include "sisfiledata.h"
       
    28 #include "sisfiledescription.h"
       
    29 #include "sisstring.h"
       
    30 #include "is_utils.h"
       
    31 #include "logger.h"
       
    32 #include "stringutils.h"
       
    33 #include "errors.h"
       
    34 
       
    35 
       
    36 // SA SIS files
       
    37 InstallableFile::InstallableFile(const CSISFileDescription& aFdes, const CSISFileData* aFdata, const std::wstring aDrivePath, int aInstallingDrive)
       
    38 : isExecutable(aFdata->IsExecutable()),
       
    39   isExe(aFdata->IsExe()),
       
    40   iSid(aFdata->GetSid()),
       
    41   isStub(false),
       
    42   iFileDescription(&aFdes),
       
    43   iFileData(aFdata),
       
    44   iTargetFile(aFdes.Target().GetString()),
       
    45   iLocalTargetFile(aFdes.Target().GetString())
       
    46 {
       
    47 	// Update the installing file with the actual target drive letter
       
    48 	ChangeTargetDrive(aDrivePath, aInstallingDrive);
       
    49 
       
    50 	// warn the user if they are using a winscw emulator binary
       
    51 	if (aFdata->IsEmulatorExecutable())
       
    52 			LWARN(iTargetFile << L" is an emulator binary!");
       
    53 }
       
    54 
       
    55 // PA SIS files		
       
    56 InstallableFile::InstallableFile(const CSISFileDescription& aFdes, const std::wstring aDrivePath,
       
    57 								 int aInstallingDrive)
       
    58 : isExecutable(false),
       
    59   isExe(false),
       
    60   iSid(0),
       
    61   iFileDescription(&aFdes),
       
    62   iFileData(0),
       
    63   isStub(true),
       
    64   iTargetFile(aFdes.Target().GetString()),
       
    65   iLocalTargetFile(aFdes.Target().GetString())
       
    66   {
       
    67 	// Update the installing file with the actual target drive letter
       
    68 	ChangeTargetDrive(aDrivePath, aInstallingDrive);
       
    69 
       
    70 		// retrieve the file attributes e.g. exe, dll, SID etc.
       
    71 	const bool fileExists = FileExists( iLocalTargetFile );
       
    72 	
       
    73 	if  ( fileExists )
       
    74 		{
       
    75 		SBinarySecurityInfo info;
       
    76 		
       
    77         const TInt err = ReadSecurityInfo( info, iLocalTargetFile );
       
    78         //
       
    79 		if (!err)
       
    80 			{
       
    81 			int fileType = GetFileType(iLocalTargetFile);
       
    82 			if(fileType & EFileExe)
       
    83 				{
       
    84 				isExe = true;
       
    85 				isExecutable = true;
       
    86 				iSid = info.iSecureId;
       
    87 				
       
    88 				if(fileType & EFileEmulatorExe)
       
    89 					LWARN(iTargetFile << L" is an emulator binary!");
       
    90 				}
       
    91 			else if (fileType & EFileDll)
       
    92 				{
       
    93 				isExecutable = true;
       
    94 				}
       
    95 			}
       
    96 		}
       
    97 
       
    98 	// files to be removed on un-installation (FN) should not
       
    99 	// be treated as stub files
       
   100 	if (aFdes.Operation() == CSISFileDescription::EOpNull)
       
   101 		isStub = false;
       
   102 	}
       
   103 
       
   104 InstallableFile::~InstallableFile()
       
   105 {
       
   106 	delete iFileData;
       
   107 }
       
   108 
       
   109 
       
   110 void InstallableFile::ChangeTargetDrive(const std::wstring aDrivePath, int aInstallingDrive)
       
   111 {
       
   112 	// get the local path
       
   113 	ConvertToLocalPath(iLocalTargetFile,aDrivePath);
       
   114 
       
   115 	// change the drive letter
       
   116 	if (StringUtils::StartsWithDrive(iTargetFile))
       
   117 	{
       
   118 		std::wstring target(iTargetFile);
       
   119 		int targetFileDrive = tolower(target[0]);
       
   120 		if (targetFileDrive != aInstallingDrive)
       
   121 		{
       
   122 			iTargetFile[0] = aInstallingDrive;
       
   123 			LINFO(L"Disregarding drive selection. Installing "
       
   124 				+ target + L" to " + iTargetFile);
       
   125 		}
       
   126 	}
       
   127 	else
       
   128 	{
       
   129 		std::wstring error = L"Invalid target file " + iTargetFile;
       
   130 		throw InterpretSisError(error, INVALID_SIS);
       
   131 	}
       
   132 }
       
   133 
       
   134 
       
   135 struct CollectSids 
       
   136 {
       
   137 	CollectSids(std::vector<TUint32>& aSids) 
       
   138 		: iSids(aSids) {}
       
   139 
       
   140 	void operator()(const InstallableFile* v)
       
   141 	{
       
   142 		if (v->IsExe())
       
   143 		{
       
   144 			iSids.push_back(v->Sid());
       
   145 		}
       
   146 	}
       
   147 
       
   148 	std::vector<TUint32>&    iSids;
       
   149 };
       
   150 
       
   151 void GetSidsFromInstallable(const InstallableFiles& aFiles, 
       
   152 			 std::vector<TUint32>& aSids)
       
   153 {
       
   154 	std::for_each(
       
   155 		aFiles.begin(), 
       
   156 		aFiles.end(),
       
   157 		CollectSids(aSids));
       
   158 }
       
   159 
       
   160 void FreeInstallableFiles(InstallableFiles& aFiles)
       
   161 {
       
   162 	for( InstallableFiles::iterator curr = aFiles.begin(); curr != aFiles.end(); ++curr )
       
   163 	{	
       
   164 		delete *curr;				
       
   165 	}
       
   166 	aFiles.clear();
       
   167 }