//load the ecom style data recognizer void CApaScanningDataRecognizer::LoadEcomRecognizerL(TDriveUnit& aDrive,TUid aUid) { //Get implementation information of the recognizer with UID aUid RImplInfoPtrArray implementationInfoArray; TCleanupItem cleanup(CleanUpEComInfoArray, &implementationInfoArray); CleanupStack::PushL(cleanup); REComSession::ListImplementationsL(KUidDataRecogInterFaceUid,implementationInfoArray); const TInt availCount = implementationInfoArray.Count(); CImplementationInformation* info=NULL; TInt ii; for (ii=0;ii<availCount;++ii) { info = implementationInfoArray[ii]; TUid uid = info->ImplementationUid(); if(uid.iUid == aUid.iUid ) { break; } } //If the implementation not found just return if(ii==availCount) { CleanupStack::PopAndDestroy(&implementationInfoArray); return; } //Get the version of implementation TInt version=info->Version(); // check we haven't loaded this one already TInt count=iRecognizerLib.Count(); TInt i; CApaRecognizerDll* lib=NULL; // the previous one in the list for (i=0; i<count; i++) { lib=iRecognizerLib[i]; if (lib->iId.iUid==aUid) {// we may have to override one if (lib->iPresent!=CApaRecognizerDll::ENotPresent) { CleanupStack::PopAndDestroy(&implementationInfoArray); return; // already found } else { if (lib->iVersion < version) { //Upgrade a plugin if a plugin with higher version than loaded plugin is installed. lib->iPresent = CApaRecognizerDll::ESuperseded; break; } else { CleanupStack::PopAndDestroy(&implementationInfoArray); lib->iPresent = CApaRecognizerDll::EIsPresent; return; } } } } //Remove the old version and let it continue to load new version if ((i<count)&&(lib->iPresent==CApaRecognizerDll::ESuperseded)) { RemoveRecognizer(lib); } // load the library HBufC* recogName=info->DisplayName().AllocL(); CleanupStack::PushL(recogName); lib=NULL; lib = new(ELeave) CApaRecognizerDll(recogName); CleanupStack::Pop(recogName); CleanupStack::PushL(lib); TRAPD(error,lib->iRec = CApaDataRecognizerType::CreateDataRecognizerL(aUid)); if(!error && lib->iRec) { lib->iPresent = CApaRecognizerDll::EIsPresent; AddDataRecognizerTypeL(lib->iRec); lib->iId.iUid = aUid; lib->iId.iDrive = aDrive; lib->iVersion=version; iExtra->iObserver->SetUpdateCounter(iExtra->iObserver->UpdateCounter() + 1); // // add lib to the library list iRecognizerLib.AppendL(lib); CleanupStack::Pop(lib); // lib } else { CleanupStack::PopAndDestroy(lib); // lib } CleanupStack::PopAndDestroy(&implementationInfoArray); }
// --------------------------------------------------------- // CNSmlDsProvisioningAdapter::StoreAttributesL // --------------------------------------------------------- void CNSmlDsProvisioningAdapter::StoreAttributesL( const TDesC& aType ) { _DBG_FILE("CNSmlDsProvisioningAdapter::StoreAttributesL(): begin"); TInt iDataProvElementCount = iProfiles[iProfiles.Count()-1]->iDataProvElement.Count()-1; // Leave if aType cannot be assigned if( ( aType.Length() > 0 ) && ( iProfiles[iProfiles.Count()-1]->iDataProvElement[iDataProvElementCount]->iRemoteDBUri ) ) { TBool dataProvIdFoundInZ = FALSE; TSmlDataProviderId firstDataProvIdFound = 0; TSmlDataProviderId uidFound = 0; TBool doSearch = ETrue; if ( aType.FindF( KXVcardMimeType ) != KErrNotFound ) { if ( IsOperatorProfile( *iProfiles[iProfiles.Count()-1] ) ) { const CNSmlDsProfileElement& profile = *iProfiles[iProfiles.Count()-1]; StoreOperatorUrlL( *profile.iHostAddress ); // Do not make a search through adapter implementations doSearch = EFalse; uidFound = OperatorAdapterUid(); if ( !uidFound ) { // If OperatorAdapterUid returns 0, do a search doSearch = ETrue; } } } // look through every implementation adapter until one found // which supports MIME type in question // The first one located in ROM is chosen. If none found in ROM then // the first adapter found is chosen. HBufC8 *type = HBufC8::NewLC(aType.Size()); TPtr8 typePtr = type->Des(); CnvUtfConverter::ConvertFromUnicodeToUtf8( typePtr, aType); // get list of dataproviderIds RImplInfoPtrArray implArray; CleanupStack::PushL( PtrArrCleanupItemRArr( CImplementationInformation, &implArray ) ); TUid ifUid = { KNSmlDSInterfaceUid }; REComSession::ListImplementationsL( ifUid, implArray ); if ( doSearch ) { TInt countProviders = implArray.Count(); for( TInt i = 0; i < countProviders; i++ ) { CImplementationInformation* implInfo = implArray[i]; RSyncMLDataProvider dataProvider; dataProvider.OpenL( iSession, implInfo->ImplementationUid().iUid ); CleanupClosePushL( dataProvider ); TInt mimeTypeCount = dataProvider.MimeTypeCount(); for( TInt j = 0; j < mimeTypeCount; j++ ) { HBufC* mimeType = dataProvider.MimeType( j ).AllocLC(); TPtrC8 convMimeType = ConvertTo8LC( *mimeType ); if( typePtr.Find( convMimeType ) == 0) { // MIME type in question was found uidFound = implInfo->ImplementationUid().iUid; if( firstDataProvIdFound == 0 ) { // save the first in case of none found from ROM firstDataProvIdFound = uidFound; } // check whether the provider is located in ROM (drive Z) if( implInfo->Drive() == EDriveZ ) { dataProvIdFoundInZ = TRUE; } } CleanupStack::PopAndDestroy(2); // mimetype, ConvertTo8LC if( uidFound ) { break; } } CleanupStack::PopAndDestroy(); // dataProvider if ( dataProvIdFoundInZ ) { break; } else { uidFound = firstDataProvIdFound; } } } REComSession::FinalClose(); CleanupStack::PopAndDestroy( 2 ); // type, implArray if( uidFound ) { iProfiles[iProfiles.Count()-1]->iDataProvElement[iDataProvElementCount]->iUid = uidFound; } } _DBG_FILE("CNSmlDsProvisioningAdapter::StoreAttributesL(): end"); }
TInt CLayoutLibrary::SetLayout(TInt aId) { TInt err = KErrNone; TBool foundLayout = EFalse; // Implementation info array RImplInfoPtrArray implInfoArray; TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: id=%d"), aId)); if( aId == iId ) { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: Same layout id=%d, don't load twice"), aId)); return KErrNone; } // Plain ignore is enough. If listing leaves, the array is just empty. TRAP_IGNORE( REComSession::ListImplementationsL( KHidLayoutPluginInterfaceUid, implInfoArray ) ); TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: %d plugins listed"),implInfoArray.Count() )); if ( 0 == implInfoArray.Count()) { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: No Drivers found"))); err = KErrNotFound; } else { for (TInt i=0; i<implInfoArray.Count() && !foundLayout; i++) { // parse implementation UID CImplementationInformation* info = implInfoArray[ i ]; TUid implUid = info->ImplementationUid(); TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: load plugin 0x%08x"),implUid )); // load driver // Trap so other drivers will be enumerated even if // this fails: CHidLayoutPluginInterface* plugin = NULL; TRAPD( err, plugin = CHidLayoutPluginInterface::NewL( implUid ); TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: plugin loaded"))); ); if( err == KErrNone) { CKeyboardLayout* layout = reinterpret_cast<CKeyboardLayout*>(plugin); if (aId == layout->LayoutId()) { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: Found layout %d!"), aId)); foundLayout = ETrue; // Swap the current layout object: CKeyboardLayout* tmpLayout = iLayout; iLayout = layout; iId = aId; iLoaded = ETrue; TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: delete old layout"))); delete tmpLayout; } else { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: wrong layout, delete plugin"))); delete plugin; } } else { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: plugin creation failed"))); } }// end of for loop }
// ----------------------------------------------------------------------------- // CContextEnginePluginTest::LoadPluginL // ----------------------------------------------------------------------------- // TInt CContextEnginePluginTest::LoadPluginL( CStifItemParser& /* aItem */ ) { _LIT( KMsg1, "Enter LoadPlugins" ); iLog->Log( KMsg1 ); RDebug::Print( KMsg1 ); iInitTarget = 2; TUid calendarContextUID = { 0x102823CB }; // calendar context plugin uid TUid locationContextUID = { 0x200071D0 }; // location context plugin uid RImplInfoPtrArray infoArray; TCleanupItem cleanupItem( MdsUtils::CleanupEComArray, &infoArray ); CleanupStack::PushL( cleanupItem ); CContextPlugin::ListImplementationsL( infoArray ); TInt count( 0 ); count = infoArray.Count(); TBool locationPluginFound( EFalse ); TBool calendarPluginFound( EFalse ); for ( TInt i=0; i < count; i++ ) { TUid uid = infoArray[i]->ImplementationUid(); // context plugin found if( uid == locationContextUID ) { iLocationPlugin = CContextPlugin::NewL( uid ); iLocationPlugin->SetMdeSession(*iMdEClient); iLocationPlugin->Init(*this); locationPluginFound = ETrue; iPlugin = iLocationPlugin; iPluginSet = ETrue; } else if( uid == calendarContextUID ) { iCalendarPlugin = CContextPlugin::NewL( uid ); iCalendarPlugin->SetMdeSession(*iMdEClient); iCalendarPlugin->Init(*this); calendarPluginFound = ETrue; } } CleanupStack::PopAndDestroy( &infoArray ); // infoArray, results in a call to CleanupEComArray if( !locationPluginFound ) { _LIT( KLocation, "Location context plugin not found" ); iLog->Log( KLocation ); RDebug::Print( KLocation ); return KErrNotFound; } if( !calendarPluginFound ) { _LIT( KCalendar, "Calendar context plugin not found" ); iLog->Log( KCalendar ); RDebug::Print( KCalendar ); return KErrNotFound; } _LIT( KMsg2, "Exit LoadPlugins" ); iLog->Log( KMsg2 ); RDebug::Print( KMsg2 ); return KErrNone; }
/** Test rogue plugin trying to override a ROM based plugin by duplicating the legitimate DLL's implementation UID (different interface UID so that ECOM not treat it as an update). @SYMTestCaseID SYSLIB-ECOM-CIT-3161 @SYMTestCaseDesc Copy a rogue plugin to C drive. This plugin duplicates the implementation UID of a built-in dll. Test if the rogue plugin will over shadow the built-in dll. @SYMTestPriority High @SYMTestActions 1. copy the rsc and dll of the rogue plugin to C: 2. Use the CreateImplementation API which does not specify the i/f UID to instantiate the built-in implementation. Test the instance works normally. 3. Repeat 2 but instantiate the pointer as the rogue plugin class. Pass NULL as the initialising param in the call to CreateImplementationL. Because the actual plugin returned by ECOM needs this initParam, KERN-EXEC 3 panic occurs. @SYMTestExpectedResults The test must not fail. @SYMDEF DEF094656 */ LOCAL_C void DEF094656_TestCaseL() { // DuplicateImplUidTestL SYSLIB-ECOM-CT-3157 is similar to this testcase. // CT-3157 tests higher driver letter > lower driver letter, // and lower i/f UID > higher i/f UID. // Note that this function is expected to panic. Hence not bother // with __UHEAP_MARK. //Check if the rogue plugin is in the registry. TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CIT-3161 ")); RImplInfoPtrArray ifArray; REComSession::ListImplementationsL(KRogueInterfaceUid, ifArray); TInt count = ifArray.Count(); TheTest.Printf(_L("Found %d implementations of I/f 0x%X"), count, KRogueInterfaceUid.iUid); TheTest(count == 1); TheTest(KRogueImplUid == ifArray[0]->ImplementationUid()); ifArray.ResetAndDestroy(); TUid dtor_key; // Initialisation parameter needed by CImplementationClassOne CExampleInterface::TExampleInterfaceInitParams initParams; initParams.integer = 0; initParams.descriptor = NULL; // First test creating the correct class. CExampleInterface* correctDll = reinterpret_cast<CExampleInterface*>( REComSession::CreateImplementationL(KRogueImplUid, dtor_key, &initParams) ); TheTest(correctDll != NULL); TUid testUid = correctDll->ImplId(); // the example plugins should return the value 10009DC3. TheTest(testUid == KRogueImplUid); REComSession::DestroyedImplementation(dtor_key); delete correctDll; // Indicate to thread creator that first stage test passed. correctTypeCastPassed = ETrue; // This create should crash because the plugin returned by // ECOM is really CImplementationClassOne which needs a properly // constructed initParam. CRoguePlugin* wrongDll = reinterpret_cast<CRoguePlugin*>( REComSession::CreateImplementationL(KRogueImplUid, dtor_key, NULL) ); // If gets here then someone has changed CImplementationClassOne::NewL // or 10009DC3 has been updated by another implementation. if (wrongDll) { REComSession::DestroyedImplementation(dtor_key); delete wrongDll; } REComSession::FinalClose(); TheTest(EFalse); }