secureswitools/swisistools/source/rscparser/aplappinforeader.cpp
changeset 60 245df5276b97
parent 33 8110bf1194d1
child 75 2d2d25361590
equal deleted inserted replaced
53:ae54820ef82c 60:245df5276b97
    40 
    40 
    41 #define REINTERPRET_CAST(type,exp) (reinterpret_cast<type>(exp))
    41 #define REINTERPRET_CAST(type,exp) (reinterpret_cast<type>(exp))
    42 
    42 
    43 const TUint KResourceOffsetMask = 0xFFFFF000;
    43 const TUint KResourceOffsetMask = 0xFFFFF000;
    44 
    44 
       
    45 #ifdef __LINUX__
       
    46 std::string KAppBinaryPathAndExtension("/sys/bin/.exe");
       
    47 #else
    45 std::string KAppBinaryPathAndExtension("\\sys\\bin\\.exe");
    48 std::string KAppBinaryPathAndExtension("\\sys\\bin\\.exe");
       
    49 #endif
    46 
    50 
    47 const TInt KAppRegistrationInfoResourceId = 1;
    51 const TInt KAppRegistrationInfoResourceId = 1;
    48 
    52 
    49 // The 2nd UID that defines a resource file as being an application registration resource file.
    53 // The 2nd UID that defines a resource file as being an application registration resource file.
    50 const TUid KUidAppRegistrationFile = {0x101F8021};
    54 const TUid KUidAppRegistrationFile = {0x101F8021};
    52 /**
    56 /**
    53 @internalTechnology
    57 @internalTechnology
    54 */
    58 */
    55 std::string KAppResourceFileExtension(".rsc");
    59 std::string KAppResourceFileExtension(".rsc");
    56 
    60 
       
    61 #ifdef __LINUX__
       
    62 std::string KLitPathForUntrustedRegistrationResourceFiles("/private/10003a3f/import/apps/");
       
    63 #else
    57 std::string KLitPathForUntrustedRegistrationResourceFiles("\\private\\10003a3f\\import\\apps\\");
    64 std::string KLitPathForUntrustedRegistrationResourceFiles("\\private\\10003a3f\\import\\apps\\");
       
    65 #endif
    58 
    66 
    59 //
    67 //
    60 // CAppInfoReader
    68 // CAppInfoReader
    61 //
    69 //
    62 
    70 
   196 
   204 
   197 Ptr16* CAppInfoReader::IconFileName()
   205 Ptr16* CAppInfoReader::IconFileName()
   198 {
   206 {
   199 	Ptr16* iconFileName = iIconFileName;
   207 	Ptr16* iconFileName = iIconFileName;
   200 	iIconFileName = NULL; // ownership transferred to caller
   208 	iIconFileName = NULL; // ownership transferred to caller
       
   209 	ConvertToPlatformSpecificPath(iconFileName->GetPtr(), iconFileName->GetLength());
   201 	return iconFileName;
   210 	return iconFileName;
   202 }
   211 }
   203 
   212 
   204 TBool CAppInfoReader::NonMbmIconFile() const
   213 TBool CAppInfoReader::NonMbmIconFile() const
   205 {
   214 {
   440 		std::string folder;
   449 		std::string folder;
   441 		std::string file;
   450 		std::string file;
   442 		size_t found;
   451 		size_t found;
   443 		std::string iLocalPath(iDrivePath);
   452 		std::string iLocalPath(iDrivePath);
   444 
   453 
   445 	  	found=localizeFileName.find_last_of("/\\");
   454 		#ifdef __LINUX__
       
   455 	  	found=localizeFileName.find_last_of("//");
       
   456 		#else
       
   457 		found=localizeFileName.find_last_of("/\\");
       
   458 		#endif
       
   459 
   446 	  	if(found)
   460 	  	if(found)
   447 	  		folder = localizeFileName.substr(0,found);
   461 	  		folder = localizeFileName.substr(0,found);
   448 	  	else
   462 	  	else
   449 	  		folder.assign("\\");
   463 		{
       
   464 			#ifdef __LINUX__
       
   465 			folder.assign("/");	  		
       
   466 			#else
       
   467 			folder.assign("\\");
       
   468 			#endif
       
   469 		}
   450 	  	
   470 	  	
   451 	  	file = localizeFileName.substr(found+1);
   471 	  	file = localizeFileName.substr(found+1);
   452 		file.append(".");
   472 		file.append(".");
   453 		
   473 		
   454 		iLocalPath.append(folder);
   474 		iLocalPath.append(folder);
   455 				
   475 				
   456 		std::wstring iFilePath = string2wstring(iLocalPath);
   476 		std::wstring iFilePath = string2wstring(iLocalPath);
   457 		std::wstring iFileName = string2wstring(file);
   477 		std::wstring iFileName = string2wstring(file);
       
   478 
       
   479 		#ifdef __LINUX__
       
   480 		iLocalPath.append("/");
       
   481 		#else
   458 		iLocalPath.append("\\");
   482 		iLocalPath.append("\\");
   459 
   483 		#endif
       
   484 		
   460 		std::list<std::wstring> locDirs;
   485 		std::list<std::wstring> locDirs;
   461 		GetDirContents( iFilePath, locDirs );
   486 		GetDirContents( iFilePath, locDirs );
   462 
   487 
   463 	 	std::list<std::wstring>::iterator curr = locDirs.begin();
   488 	 	std::list<std::wstring>::iterator curr = locDirs.begin();
   464 		for( curr = locDirs.begin(); curr != locDirs.end(); ++curr )
   489 		for( curr = locDirs.begin(); curr != locDirs.end(); ++curr )
   466 			if (curr->find(iFileName,0) != std::wstring::npos)
   491 			if (curr->find(iFileName,0) != std::wstring::npos)
   467 			{
   492 			{
   468 			    std::string fName;
   493 			    std::string fName;
   469 				std::string sAbsolutePath;
   494 				std::string sAbsolutePath;
   470 				sAbsolutePath.assign(iLocalPath);
   495 				sAbsolutePath.assign(iLocalPath);
   471 			 	fName = Ucs2ToUtf8( *curr );
   496 			 	fName = wstring2string( *curr );
   472 
   497 
   473 			   	sAbsolutePath.append(fName);
   498 			   	sAbsolutePath.append(fName);
   474 				//cout << sAbsolutePath<<endl;
   499 				//cout << sAbsolutePath<<endl;
   475 				
   500 				
   476 				std::string Locale;
   501 				std::string Locale;
   535 	aResourceReader.ReadUint32L(); // skip over LONG reserved_long
   560 	aResourceReader.ReadUint32L(); // skip over LONG reserved_long
   536 	aResourceReader.ReadUint32L(); // skip over LLINK reserved_llink
   561 	aResourceReader.ReadUint32L(); // skip over LLINK reserved_llink
   537 
   562 
   538 	// read LTEXT app_file
   563 	// read LTEXT app_file
   539 	PtrC16* appFile = aResourceReader.ReadTPtrCL();
   564 	PtrC16* appFile = aResourceReader.ReadTPtrCL();
       
   565 
   540 	if(NULL==appFile)
   566 	if(NULL==appFile)
   541 	{
   567 	{
   542 		std::string errMsg= "Failed : Invalid Resource File Name. Application File Name is Mendatory.";
   568 		std::string errMsg= "Failed : Invalid Resource File Name. Application File Name is Mandatory.";
   543 		throw CResourceFileException(errMsg);
   569 		throw CResourceFileException(errMsg);
   544 	}
   570 	}
       
   571 
       
   572 	ConvertToPlatformSpecificPath(appFile->iPtr, appFile->iMaxLength);
   545 
   573 
   546 	TInt err=0;
   574 	TInt err=0;
   547 	// this object gets used for 2 purposes: first to check that a ParsePtrC can be created over "appFile" without it panicking, and second to construct iAppBinaryFullName
   575 	// this object gets used for 2 purposes: first to check that a ParsePtrC can be created over "appFile" without it panicking, and second to construct iAppBinaryFullName
   548 	err = FindWild(appFile); // do this before creating a TParsePtrC, since TParsePtrC's constructor panics if it fails (which would provide an easy way for malware to kill the Apparc server)
   576 	err = FindWild(appFile); // do this before creating a TParsePtrC, since TParsePtrC's constructor panics if it fails (which would provide an easy way for malware to kill the Apparc server)
   549 
   577 
   651 		return NULL;
   679 		return NULL;
   652 
   680 
   653 	filename = new Ptr16(aIconFileName->iMaxLength);
   681 	filename = new Ptr16(aIconFileName->iMaxLength);
   654 	if(NULL==filename || NULL == filename->GetPtr())
   682 	if(NULL==filename || NULL == filename->GetPtr())
   655 	{
   683 	{
       
   684 		parsePtr.SetToNull();
   656 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
   685 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
   657 		throw CResourceFileException(errMsg);
   686 		throw CResourceFileException(errMsg);
   658 	}
   687 	}
   659 	filename->UpdateLength(aIconFileName->iMaxLength);
   688 	filename->UpdateLength(aIconFileName->iMaxLength);
   660 	BufCpy(filename->GetPtr(),aIconFileName->iPtr,aIconFileName->iMaxLength);
   689 	BufCpy(filename->GetPtr(),aIconFileName->iPtr,aIconFileName->iMaxLength);
   761 	localinfo->SetNumOfAppIcons(numOfIcons);
   790 	localinfo->SetNumOfAppIcons(numOfIcons);
   762 
   791 
   763 	// read LTEXT icon_file
   792 	// read LTEXT icon_file
   764 	iIconFileName = NULL;
   793 	iIconFileName = NULL;
   765 	PtrC16* iconFile = resourceReader.ReadTPtrCL();
   794 	PtrC16* iconFile = resourceReader.ReadTPtrCL();
       
   795 
   766 	if(NULL != iconFile)
   796 	if(NULL != iconFile)
   767 	{
   797 	{
       
   798 		ConvertToPlatformSpecificPath(iconFile->iPtr, iconFile->iMaxLength);
   768 		Ptr16*	iconFileName = CreateFullIconFileNameL(iconFile);
   799 		Ptr16*	iconFileName = CreateFullIconFileNameL(iconFile);
   769 		
   800 		
   770 		if (iconFileName)
   801 		if (iconFileName)
   771 		{
   802 		{
   772 			localinfo->SetIconFileName(iconFileName);
   803 			localinfo->SetIconFileName(iconFileName);
   843 				std::string file;
   874 				std::string file;
   844 				size_t found;
   875 				size_t found;
   845 				size_t find;
   876 				size_t find;
   846 				std::string iLocalPath(iDrivePath);
   877 				std::string iLocalPath(iDrivePath);
   847 		
   878 		
       
   879 				#ifdef __LINUX__
       
   880 				found=localizeFileName.find_last_of("//");
       
   881 				#else
   848 				found=localizeFileName.find_last_of("/\\");
   882 				found=localizeFileName.find_last_of("/\\");
       
   883 				#endif
       
   884 
   849 				if(found)
   885 				if(found)
   850 					folder = localizeFileName.substr(0,found);
   886 					folder = localizeFileName.substr(0,found);
   851 				else
   887 				else
       
   888 				{
       
   889 					#ifdef __LINUX__
       
   890 					folder.assign("/");
       
   891 					#else
   852 					folder.assign("\\");
   892 					folder.assign("\\");
       
   893 					#endif					
       
   894 				}
   853 			
   895 			
   854 				file = localizeFileName.substr(found+1);
   896 				file = localizeFileName.substr(found+1);
   855 				file.append(".");
   897 				file.append(".");
   856 			
   898 			
   857 				iLocalPath.append(folder);
   899 				iLocalPath.append(folder);
   858 					
   900 					
   859 				std::wstring iFilePath = string2wstring(iLocalPath);
   901 				std::wstring iFilePath = string2wstring(iLocalPath);
   860 				std::wstring iFileName = string2wstring(file);
   902 				std::wstring iFileName = string2wstring(file);
       
   903 				#ifdef __LINUX__
       
   904 				iLocalPath.append("/");
       
   905 				#else
   861 				iLocalPath.append("\\");
   906 				iLocalPath.append("\\");
       
   907 				#endif
       
   908 
   862 		
   909 		
   863 				std::list<std::wstring> locDirs;
   910 				std::list<std::wstring> locDirs;
   864 				GetDirContents( iFilePath, locDirs );
   911 				GetDirContents( iFilePath, locDirs );
   865 			
   912 			
   866 				std::list<std::wstring>::iterator curr = locDirs.begin();
   913 				std::list<std::wstring>::iterator curr = locDirs.begin();
   870 					{
   917 					{
   871 						std::string fName;
   918 						std::string fName;
   872 						std::string sAbsolutePath;
   919 						std::string sAbsolutePath;
   873 						std::string Locale;
   920 						std::string Locale;
   874 						sAbsolutePath.assign(iLocalPath);
   921 						sAbsolutePath.assign(iLocalPath);
   875 						fName = Ucs2ToUtf8( *curr );
   922 						fName = wstring2string( *curr );
   876 
   923 
   877 						find=fName.rfind("backup");
   924 						find=fName.rfind("backup");
   878 						if(find != string::npos)
   925 						if(find != string::npos)
   879 							continue;
   926 							continue;
   880 
   927 
  1063 
  1110 
  1064 TInt CAppInfoReader::ReadNonLocalisableInfoL(RResourceReader& aResourceReader, TUint& aLocalisableResourceId)
  1111 TInt CAppInfoReader::ReadNonLocalisableInfoL(RResourceReader& aResourceReader, TUint& aLocalisableResourceId)
  1065 {
  1112 {
  1066 	// read LTEXT localisable_resource_file
  1113 	// read LTEXT localisable_resource_file
  1067 	PtrC16*	localisableResourceFileName = aResourceReader.ReadTPtrCL();
  1114 	PtrC16*	localisableResourceFileName = aResourceReader.ReadTPtrCL();
       
  1115 
  1068 	if(NULL == localisableResourceFileName)
  1116 	if(NULL == localisableResourceFileName)
  1069 	{
  1117 	{
  1070 		iLocalisableResourceFileName = NULL;
  1118 		iLocalisableResourceFileName = NULL;
  1071 	}
  1119 	}
  1072 	else
  1120 	else
  1073 	{
  1121 	{
       
  1122 		ConvertToPlatformSpecificPath(localisableResourceFileName->iPtr, localisableResourceFileName->iMaxLength);
  1074 		if (localisableResourceFileName->iMaxLength > 0 )
  1123 		if (localisableResourceFileName->iMaxLength > 0 )
  1075 		{
  1124 		{
  1076 			ParsePtrC parsePtr(localisableResourceFileName);
  1125 			ParsePtrC parsePtr(localisableResourceFileName);
  1077 
  1126 
  1078 			if(parsePtr.IsValidName())
  1127 			if(parsePtr.IsValidName())
  1079 			{
  1128 			{
  1080 				iLocalisableResourceFileName = NULL;
  1129 				iLocalisableResourceFileName = NULL;
       
  1130 				parsePtr.SetToNull();	//To Avoid double Delete in destructor.
  1081 				std::string errMsg= "Failed : Invalid localisable Resource File Name";
  1131 				std::string errMsg= "Failed : Invalid localisable Resource File Name";
  1082 				throw CResourceFileException(errMsg);
  1132 				throw CResourceFileException(errMsg);
  1083 			}
  1133 			}
  1084 			
  1134 			
  1085 			std::string registrationFileDrive;
  1135 			std::string registrationFileDrive;
  1088 			if( index != string::npos )
  1138 			if( index != string::npos )
  1089 				registrationFileDrive.assign(iRegistrationFileName, index-1, 2);
  1139 				registrationFileDrive.assign(iRegistrationFileName, index-1, 2);
  1090 
  1140 
  1091 			TInt err=0;
  1141 			TInt err=0;
  1092 			std::string sTemp = parsePtr.StrName();
  1142 			std::string sTemp = parsePtr.StrName();
       
  1143 
  1093 			err = FindWild(registrationFileDrive, KAppResourceFileExtension, sTemp);
  1144 			err = FindWild(registrationFileDrive, KAppResourceFileExtension, sTemp);
  1094 			if(err==1)
  1145 			if(err==1)
  1095 			{
  1146 			{
  1096 				std::string errMsg= "Failed : Invalid drive for Registration File";
  1147 				std::string errMsg= "Failed : Invalid drive for Registration File";
       
  1148 				parsePtr.SetToNull();	//To Avoid double Delete in destructor.
  1097 				throw CResourceFileException(errMsg);
  1149 				throw CResourceFileException(errMsg);
  1098 			}
  1150 			}
  1099 
  1151 
  1100 			iLocalisableResourceFileName = new Ptr16(parsePtr.FullName()->iMaxLength);
  1152 			iLocalisableResourceFileName = new Ptr16(parsePtr.FullName()->iMaxLength);
  1101 			if(NULL==iLocalisableResourceFileName || NULL==iLocalisableResourceFileName->GetPtr())
  1153 			if(NULL==iLocalisableResourceFileName || NULL==iLocalisableResourceFileName->GetPtr())
  1102 			{
  1154 			{
  1103 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
  1155 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1156 				parsePtr.SetToNull();	//To Avoid double Delete in destructor.
  1104 				throw CResourceFileException(errMsg);
  1157 				throw CResourceFileException(errMsg);
  1105 			}
  1158 			}
  1106 
  1159 
  1107 			iLocalisableResourceFileName->UpdateLength(parsePtr.FullName()->iMaxLength);
  1160 			iLocalisableResourceFileName->UpdateLength(parsePtr.FullName()->iMaxLength);
  1108 			BufCpy(iLocalisableResourceFileName->GetPtr(),parsePtr.FullName()->iPtr,parsePtr.FullName()->iMaxLength);
  1161 			BufCpy(iLocalisableResourceFileName->GetPtr(),parsePtr.FullName()->iPtr,parsePtr.FullName()->iMaxLength);
  1117 	iCapability.iEmbeddability = static_cast<TAppCapability::TEmbeddability>(aResourceReader.ReadInt8L());
  1170 	iCapability.iEmbeddability = static_cast<TAppCapability::TEmbeddability>(aResourceReader.ReadInt8L());
  1118 	iCapability.iSupportsNewFile = aResourceReader.ReadInt8L();
  1171 	iCapability.iSupportsNewFile = aResourceReader.ReadInt8L();
  1119 	iCapability.iLaunchInBackground = aResourceReader.ReadInt8L();
  1172 	iCapability.iLaunchInBackground = aResourceReader.ReadInt8L();
  1120 
  1173 
  1121 	PtrC16* iTemp = aResourceReader.ReadTPtrCL();
  1174 	PtrC16* iTemp = aResourceReader.ReadTPtrCL();
       
  1175 
  1122 	if(NULL==iTemp || NULL==iTemp->iPtr)
  1176 	if(NULL==iTemp || NULL==iTemp->iPtr)
  1123 		iCapability.iGroupName = NULL;
  1177 		iCapability.iGroupName = NULL;
  1124 	else 
  1178 	else 
  1125 	{
  1179 	{
  1126 		iCapability.iGroupName = new Ptr16(iTemp->iMaxLength);
  1180 		iCapability.iGroupName = new Ptr16(iTemp->iMaxLength);
  1196 		}
  1250 		}
  1197 	}
  1251 	}
  1198 	for (TInt i=0; i < fileOwnershipArraySize; i++)
  1252 	for (TInt i=0; i < fileOwnershipArraySize; i++)
  1199 	{
  1253 	{
  1200 		PtrC16* fileNamePtr_temp = aResourceReader.ReadTPtrCL();
  1254 		PtrC16* fileNamePtr_temp = aResourceReader.ReadTPtrCL();
       
  1255 
  1201 		if(NULL != fileNamePtr_temp)
  1256 		if(NULL != fileNamePtr_temp)
  1202 		{
  1257 		{
       
  1258 			ConvertToPlatformSpecificPath(fileNamePtr_temp->iPtr, fileNamePtr_temp->iMaxLength);
  1203 			Ptr16* fileNamePtr = new Ptr16(fileNamePtr_temp->iMaxLength);
  1259 			Ptr16* fileNamePtr = new Ptr16(fileNamePtr_temp->iMaxLength);
  1204 			if(NULL==fileNamePtr || NULL==fileNamePtr->GetPtr())
  1260 			if(NULL==fileNamePtr || NULL==fileNamePtr->GetPtr())
  1205 			{
  1261 			{
  1206 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
  1262 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
  1207 				throw CResourceFileException(errMsg);
  1263 				throw CResourceFileException(errMsg);
  1208 			}
  1264 			}
  1209 			fileNamePtr->UpdateLength(fileNamePtr_temp->iMaxLength);			  
  1265 			fileNamePtr->UpdateLength(fileNamePtr_temp->iMaxLength);			  
  1210 			BufCpy(fileNamePtr->GetPtr(),fileNamePtr_temp->iPtr,fileNamePtr_temp->iMaxLength);
  1266 			BufCpy(fileNamePtr->GetPtr(),fileNamePtr_temp->iPtr,fileNamePtr_temp->iMaxLength);
       
  1267 
  1211 			iOwnedFileArray->push_back(fileNamePtr);
  1268 			iOwnedFileArray->push_back(fileNamePtr);
  1212 		}
  1269 		}
  1213 		else
  1270 		else
  1214 		{
  1271 		{
  1215 			Ptr16* fileNamePtr = NULL;
  1272 			Ptr16* fileNamePtr = NULL;
  1295                 }
  1352                 }
  1296              }
  1353              }
  1297 	    }
  1354 	    }
  1298 
  1355 
  1299 		PtrC8* dataTypePtr  = aResourceReader.ReadTPtrC8L();
  1356 		PtrC8* dataTypePtr  = aResourceReader.ReadTPtrC8L();
       
  1357 
  1300 		if(NULL != dataTypePtr)
  1358 		if(NULL != dataTypePtr)
  1301 		{
  1359 		{
  1302 			TDataType* dataType = new TDataType(dataTypePtr);
  1360 			TDataType* dataType = new TDataType(dataTypePtr);
  1303 			if(NULL==dataType)
  1361 			if(NULL==dataType)
  1304 			{
  1362 			{