void CSandboxSession::ServiceL(const RMessage2 &aMessage) { if (aMessage.Function() >= EMaxArgs) { aMessage.Complete(KErrArgument); return; } if (aMessage.Function() == EGetRecog2) { aMessage.WriteL(0, iBuf); iBuf.Close(); aMessage.Complete(KErrNone); } else if (aMessage.Function() == EGetRecog) { if (iBuf.MaxLength() == 0) { iBuf.ReAllocL(1024); // Must be > sizeof(TDataType) otherwise the reallocating logic below is flawed } TUid uid = TUid::Uid(aMessage.Int0()); TUid destructorKey; CApaDataRecognizerType* rec = static_cast<CApaDataRecognizerType*>(REComSession::CreateImplementationL(uid, destructorKey)); TInt count = rec->MimeTypesCount(); for (TInt j = 0; j < count; j++) { TDataType type = rec->SupportedDataTypeL(j); TPckg<TDataType> buf(type); if (iBuf.Length() + buf.Length() >= iBuf.MaxLength()) { iBuf.ReAllocL(iBuf.MaxLength() * 2); } iBuf.Append(buf); } aMessage.Complete(iBuf.Size()); } else if (aMessage.Function() == ECloseServer) { aMessage.Complete(KErrNone); CActiveScheduler::Stop(); } else if (aMessage.Function() == EGetVTablePtr) { TUid destructorKey; TAny* obj = NULL; obj = REComSession::CreateImplementationL(TUid::Uid(aMessage.Int0()), destructorKey); TAny* vtablePtr = *((TAny**)obj); TPckg<TAny*> res(vtablePtr); aMessage.WriteL(1, res); aMessage.Complete(KErrNone); } else { ASSERT(0); } }
TInt CXmlEngSerializerGZIP::SerializeToBufferL(RBuf8& aBuf, const TXmlEngNode aNode, const TXmlEngSerializationOptions& aOpt) { CXmlEngGZIPBufferOutputStream* gzbos = CXmlEngGZIPBufferOutputStream::NewLC(aBuf); TRAPD(err,aNode.OwnerDocument().SaveL(*gzbos,aNode,aOpt)); TInt sErr = gzbos->CheckError(); if(sErr) { User::Leave(sErr); } if(err) { User::Leave(err); } CleanupStack::PopAndDestroy(gzbos); return aBuf.Size(); }
/** Test the driver data flow path by loopback, i.e Transmit the data and receive same data back. It runs the device @ default configuration @param aLoopback Loopback mode as internal or external aTxData Transmit Data buffer aRxSize Receive data size */ void TestExDriver::TestConcurrentTxRx(TInt aLoopback, const TDesC8& aTxData, TInt aRxSize) { TInt r; TRequestStatus stat; iTest.Printf(_L("Test Concurrent Synchronous Requests - Tx/Rx\n")); // Open channel r=iLdd.Open(KUnit1); iTest(r==KErrNone); // Create a buffer that has to be filled and returned by the driver RBuf8 rxBuf; r=rxBuf.Create(aRxSize); iTest(r==KErrNone); r=iLdd.SetIntLoopback(aLoopback); iTest(r==KErrNone); TData TData(&iLdd,&aTxData,&iSem1); // Call ldd interface ReceiveData() API to get data to rxBuf RThread TransferThread; _LIT(KThreadName, "TestThread"); TInt ret = TransferThread.Create( KThreadName, // Thread name TransferTestThread, // Function to be called KDefaultStackSize, KHeapSize, KHeapSize, (TAny *)&TData ); iTest.Printf(_L("Receive Data\n")); TransferThread.Logon(stat); TransferThread.Resume(); iSem1.Signal(); r = iLdd.ReceiveData(rxBuf); // In case of zero length request if (aRxSize==0) { // Driver should return error immediately iTest(r!=KErrNone); TransferThread.Kill(KErrNone); TransferThread.Close(); // Close the RBuf rxBuf.Close(); // Close channel iLdd.Close(); return; } // Print the receive data to display. // It automatically checks the Tx and Rx data. Fails if not matched. // TInt i; iTest.Printf(_L("Received Data of size (%d):"),rxBuf.Size()); for (i=0; i<rxBuf.Size(); i++) { iTest.Printf(_L("%c"),(rxBuf.Ptr())[i]); if ((TUint8)(rxBuf.Ptr())[i] != aTxData[i]) { iTest.Printf(_L("Transmit and Receive data do not match\n")); iTest(EFalse); } } iTest.Printf(_L("\n")); User::WaitForRequest(stat); TransferThread.Close(); // Free the receive buffer rxBuf.Close(); // Close channel iLdd.Close(); }
// ========================================================================== // FUNCTION: ContentLengthL // ========================================================================== TUint CContainerStoreContentManager::ContentLengthL( TContainerId aId, TBool aIsEncrypted ) { TUint returnValue = 0; TFileName contentFilename; ContentFilename( aId, contentFilename ); // Open the content file. RFile file; TInt result = file.Open( iFs, contentFilename, KFILE_MODE_READ ); if( result == KErrNone ) { CleanupClosePushL( file ); TInt fileSize; User::LeaveIfError( file.Size( fileSize ) ); if ( !aIsEncrypted ) { returnValue = fileSize; } else { UpdateBlockSizeL( aIsEncrypted ); RBuf8 encryptedBuffer; encryptedBuffer.CreateL( iBlockSize ); CleanupClosePushL( encryptedBuffer ); RBuf8 plaintextBuffer; plaintextBuffer.CreateL( iBlockSize ); CleanupClosePushL( plaintextBuffer ); // Read the last block. TInt seekPosition = fileSize - iBlockSize; User::LeaveIfError( file.Seek( ESeekCurrent, seekPosition ) ); User::LeaveIfError( file.Read( encryptedBuffer, iBlockSize ) ); // Decrypt the last block. iEncryption.DecryptL( encryptedBuffer, plaintextBuffer ); iEncryption.RemovePaddingL( plaintextBuffer ); // The content length is the file size minus the number of pad bytes in the final block. returnValue = fileSize - iBlockSize + plaintextBuffer.Size(); CleanupStack::PopAndDestroy( &plaintextBuffer ); CleanupStack::PopAndDestroy( &encryptedBuffer ); } CleanupStack::PopAndDestroy( &file ); } // If no content file exists then treat it as content length 0. else if( result != KErrNotFound ) { User::Leave( result ); } // end if return returnValue; } // end ContentLengthL
// -------------------------------------------------------------------------------------- // Serializes TXmlEngNode to buffer // -------------------------------------------------------------------------------------- // TInt CXmlEngSerializerXOP::SerializeL( RBuf8& aBuffer, const TXmlEngNode aRoot, const TXmlEngSerializationOptions& aOptions ) { if(aBuffer.Length()) { aBuffer.Close(); } LeaveIfXopIncludeL(aRoot); iDataContainerArray.Reset(); if(aOptions.iDataSerializer) { return CXmlEngSerializer::SerializeL(aBuffer, aRoot, aOptions); } TXmlEngSerializationOptions opt = aOptions; opt.iDataSerializer = this; RBuf8 xopDocument; CleanupClosePushL(xopDocument); aRoot.OwnerDocument().SaveL(xopDocument, aRoot, opt); if( iCleanXOPInfoset ) { if(xopDocument.Size() > aBuffer.MaxSize()) { aBuffer.ReAllocL( xopDocument.Size() ); } aBuffer.Append(xopDocument); } else { // adjust buffer size TInt bufSize = KXOPDocumentStart().Size() + KMimeRoot().Size() + xopDocument.Size() + KXOPDocumentEnd().Size(); for(TInt j = 0; j < iDataContainerArray.Count(); j++) { TPtrC8 contentTypeStr; if(GetContentTypeValue(iDataContainerArray[j], contentTypeStr)) { bufSize += KMimeHeaderContentType().Size() + contentTypeStr.Size() + KNewLine().Size(); } bufSize += KMimeHeaderStart().Size() + KMimeHeaderContentIdStart().Size() + iDataContainerArray[j].Cid().Length() + KMimeHeaderContentIdEnd().Size() + KNewLine().Size() + iDataContainerArray[j].Size(); } if (bufSize > aBuffer.MaxSize()) { aBuffer.ReAllocL( bufSize ); } // write to buffer aBuffer.Append(KXOPDocumentStart()); aBuffer.Append(KMimeRoot()); aBuffer.Append(xopDocument); for(TInt i = 0; i < iDataContainerArray.Count(); i++) { aBuffer.Append(KMimeHeaderStart); TPtrC8 contentTypeStr; if(GetContentTypeValue(iDataContainerArray[i], contentTypeStr)) { aBuffer.Append(KMimeHeaderContentType); aBuffer.Append(contentTypeStr); aBuffer.Append(KNewLine); } aBuffer.Append(KMimeHeaderContentIdStart); aBuffer.Append(iDataContainerArray[i].Cid()); aBuffer.Append(KMimeHeaderContentIdEnd); aBuffer.Append(KNewLine); switch(iDataContainerArray[i].NodeType()) { case TXmlEngNode::EBinaryContainer: { if(opt.iOptions & TXmlEngSerializationOptions::KOptionDecodeBinaryContainers ) { HBufC8* decodedData = CreateDecodedBufLC(iDataContainerArray[i].AsBinaryContainer().Contents()); aBuffer.Append(decodedData->Des()); CleanupStack::PopAndDestroy(); //decodedData } else { aBuffer.Append(iDataContainerArray[i].AsBinaryContainer().Contents()); } break; } case TXmlEngNode::EChunkContainer: { TPtrC8 data = TPtrC8( ((RChunk&)iDataContainerArray[i].AsChunkContainer().Chunk()).Base() + iDataContainerArray[i].AsChunkContainer().ChunkOffset(), iDataContainerArray[i].AsChunkContainer().Size()); if(opt.iOptions & TXmlEngSerializationOptions::KOptionDecodeBinaryContainers ) { HBufC8* decodedData = CreateDecodedBufLC(data); aBuffer.Append(decodedData->Des()); CleanupStack::PopAndDestroy(); //decodedData } else { aBuffer.Append(data); } break; } case TXmlEngNode::EFileContainer: { TInt size = iDataContainerArray[i].AsFileContainer().Size(); HBufC8* data = HBufC8::NewLC(size); TPtr8 dataPtr = data->Des(); iDataContainerArray[i].AsFileContainer().File().Read(dataPtr, size); if(opt.iOptions & TXmlEngSerializationOptions::KOptionDecodeBinaryContainers ) { HBufC8* decodedData = CreateDecodedBufLC(dataPtr); aBuffer.Append(decodedData->Des()); CleanupStack::PopAndDestroy(); //decodedData } else { aBuffer.Append(dataPtr); } CleanupStack::PopAndDestroy(); //data break; } } } aBuffer.Append(KXOPDocumentEnd); } CleanupStack::PopAndDestroy(); //xopDocument return aBuffer.Size(); }
void CServerCrashDataSource::GetCodeSegmentsL( const TUint64 aTid, RCodeSegPointerList &aCodeSegList, TUint & aTotalCodeSegListDescSize ) { LOG_MSG2("->CServerCrashDataSource::GetCodeSegmentsL(aTid=%Lu)\n", aTid ); aCodeSegList.ResetAndDestroy(); aTotalCodeSegListDescSize = 0; TUint32 size = KMaxFileName; RBuf8 buffer; buffer.CreateL(KMaxFileName); CleanupClosePushL(buffer); DoGetListL( ECodeSegs, aTid, (TUint)-1, buffer, size ); LOG_MSG2( " DoGetListL( ECodeSegs ) returned buffer.Size()=0x%X\n", buffer.Size() ); TUint8* ptr = (TUint8*)buffer.Ptr(); const TUint8* ptrEnd = ptr + size; while(ptr < ptrEnd) { TCodeSegListEntry* entry = (TCodeSegListEntry*)ptr; LOG_MSG4( " entry->CodeBase=0x%X, CodeSize=0x%X, ConstDataSize=0x%X\n", entry->iCodeBase, entry->iCodeSize, entry->iConstDataSize ); LOG_MSG4( " InitDataBase=0x%X, InitDataSize=0x%X, UnintDataSize=0x%X\n", entry->iInitialisedDataBase, entry->iInitialisedDataSize, entry->iUninitialisedDataSize ); LOG_MSG3( " IsXip=0x%X, CodeSegType=0x%X\n", entry->iIsXip, entry->iCodeSegType ); TCodeSegInfo *codeSeg = new(ELeave) TCodeSegInfo; TPtr name(&(entry->iName[0]), entry->iNameLength, entry->iNameLength); codeSeg->iName = name; codeSeg->iType = entry->iCodeSegType; codeSeg->iXIP = entry->iIsXip; codeSeg->iCodeSize = entry->iCodeSize; codeSeg->iCodeRunAddr = entry->iCodeBase; if( codeSeg->iXIP ) { codeSeg->iCodeLoadAddr = codeSeg->iCodeRunAddr; } else { codeSeg->iCodeLoadAddr = 0; //TODO } codeSeg->iRoDataSize = entry->iConstDataSize; codeSeg->iRoDataRunAddr = entry->iCodeBase + entry->iCodeSize; if( codeSeg->iXIP ) { codeSeg->iRoDataLoadAddr = codeSeg->iRoDataRunAddr; } else { codeSeg->iRoDataLoadAddr = 0; //TODO } codeSeg->iDataSize = entry->iInitialisedDataSize + entry->iUninitialisedDataSize; codeSeg->iDataRunAddr = entry->iInitialisedDataBase; if( codeSeg->iXIP ) { codeSeg->iDataLoadAddr = codeSeg->iDataRunAddr; } else { codeSeg->iDataLoadAddr = 0; //TODO } TInt err = aCodeSegList.Append(codeSeg); if(err != KErrNone) { delete codeSeg; User::Leave(err); } aTotalCodeSegListDescSize += sizeof(TCodeSegInfo); ptr += Align4(entry->GetSize()); } CleanupStack::PopAndDestroy(&buffer); }
// // LtkUtils::W32CrackL // loads the autometric logging engine, dlogev.dll, into wserv // enabling Autometric to monitor events from within wserv - key/pointer events, text drawn to screen etc // EXPORT_C void LtkUtils::W32CrackL() { #ifndef FSHELL_WSERV_SUPPORT User::Leave(KErrNotSupported); #else // Check if P&S says it's already enabled, if so no need to do anything if (W32CrackIsEnabled()) return; _LIT(KWsIniFile, "z:\\system\\data\\wsini.ini"); _LIT(KCWsIniFile,"c:\\system\\data\\wsini.ini"); _LIT(KLogEv, "LOG EV\r\n"); // Open z file RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); RFile file; User::LeaveIfError(file.Open(fs, KWsIniFile, EFileRead)); CleanupClosePushL(file); TInt size; User::LeaveIfError(file.Size(size)); RBuf8 buf; buf.CreateL(size + KLogEv().Size()); CleanupClosePushL(buf); User::LeaveIfError(file.Read(buf)); TPtrC16 wptr((TUint16*)buf.Ptr(), buf.Size()/2); buf.Insert(2, TPtrC8((TUint8*)KLogEv().Ptr(), KLogEv().Size())); // +2 to get past the BOM TInt err = KErrNone; err = fs.MkDirAll(KCWsIniFile); // mkdir c:\system\data\ in case it is not exist if((err != KErrNone) && (err != KErrAlreadyExists)) { User::Leave(err); } User::LeaveIfError(file.Replace(fs, KCWsIniFile, EFileWrite)); User::LeaveIfError(file.Write(buf)); CleanupStack::PopAndDestroy(2, &file); // file, buf err = RMemoryAccess::LoadDriver(); if ((err != KErrNone) && (err != KErrAlreadyExists)) { User::Leave(err); } RMemoryAccess memAccess; User::LeaveIfError(memAccess.Open()); CleanupClosePushL(memAccess); RWsSession ws; User::LeaveIfError(ws.Connect(fs)); CleanupClosePushL(ws); #ifdef __WINS__ // On wins the binary isn't renamed _LIT(KWservMatch, "wserv*.exe*"); #else _LIT(KWservMatch, "EwSrv.exe*"); #endif TFindProcess find(KWservMatch); TFullName name; User::LeaveIfError(find.Next(name)); RProcess wservProc; User::LeaveIfError(wservProc.Open(find)); if (wservProc.ExitType() != EExitPending) { // in case wserv kicks off the preferred implementation in a new process then kills itself // (is one retry enough or should we be looping here?) wservProc.Close(); User::LeaveIfError(find.Next(name)); User::LeaveIfError(wservProc.Open(find)); } CleanupClosePushL(wservProc); name = wservProc.FileName(); name[0] = 'c'; TPtrC8 narrowName = name.Collapse(); User::LeaveIfError(memAccess.InPlaceSetProcessFileName(wservProc, narrowName)); // Now tell wserv to reload its wsini.ini and enable logging ws.LogCommand(RWsSession::ELoggingEnable); ws.Flush(); // cleanup CleanupStack::PopAndDestroy(4, &fs); #endif // FSHELL_WSERV_SUPPORT }
void CCmdBtraceout::DoRunL() { if (iStdin) { CTextBuffer* buffer = CTextBuffer::NewLC(512); Stdin().SetReadMode(RIoReadHandle::EOneOrMore); TBuf<256> buf; while (Stdin().Read(buf) == KErrNone) { buffer->AppendL(buf); } RBuf8 data; data.CreateL(buffer->Length()); data.Copy(buffer->Descriptor()); // This will collapse us back to real 8-bit data if (iTruncate) { if (iOptions.IsPresent(&iFilterUid)) { if (iArguments.IsPresent(3)) { PrintWarning(_L("Ignoring 'arg_2' (%u) and all following arguments"), iArg2); } BTraceFilteredN(iCategory, iSubcategory, iFilterUid, iArg1, data.Ptr(), data.Size()); } else { if (iArguments.IsPresent(3)) { PrintWarning(_L("Ignoring 'arg_3' (%u)"), iArg3); } BTraceN(iCategory, iSubcategory, iArg1, iArg2, data.Ptr(), data.Size()); } } else { if (iOptions.IsPresent(&iFilterUid)) { if (iArguments.IsPresent(2)) { PrintWarning(_L("Ignoring 'arg_1' (%u) and all following arguments"), iArg1); } BTraceFilteredBig(iCategory, iSubcategory, iFilterUid, data.Ptr(), data.Size()); } else { if (iArguments.IsPresent(3)) { PrintWarning(_L("Ignoring 'arg_2' (%u) and all following arguments"), iArg2); } BTraceBig(iCategory, iSubcategory, iArg1, data.Ptr(), data.Size()); } } data.Close(); CleanupStack::PopAndDestroy(buffer); } else { if (iArguments.IsPresent(4)) { if (iOptions.IsPresent(&iFilterUid)) { if (iArguments.IsPresent(3)) { PrintWarning(_L("Ignoring 'arg_3' (%u)"), iArg3); } BTraceFiltered12(iCategory, iSubcategory, iFilterUid, iArg1, iArg2); } else { BTrace12(iCategory, iSubcategory, iArg1, iArg2, iArg3); } } else if (iArguments.IsPresent(3)) { if (iOptions.IsPresent(&iFilterUid)) { BTraceFiltered12(iCategory, iSubcategory, iFilterUid, iArg1, iArg2); } else { BTrace8(iCategory, iSubcategory, iArg1, iArg2); } } else if (iArguments.IsPresent(2)) { if (iOptions.IsPresent(&iFilterUid)) { BTraceFiltered8(iCategory, iSubcategory, iFilterUid, iArg1); } else { BTrace4(iCategory, iSubcategory, iArg1); } } else { if (iOptions.IsPresent(&iFilterUid)) { BTraceFiltered4(iCategory, iSubcategory, iFilterUid); } else { BTrace0(iCategory, iSubcategory); } } } }
/** Test the driver data flow path by loopback, i.e Transmit the data and receive same data back. It runs the device @ default configuration @param aLoopback Loopback mode as internal or external aTxData Transmit Data buffer aRxSize Receive data size */ void TestExDriver::TestConcurrentTxRx(TInt aLoopback, const TDesC8& aTxData, TInt aRxSize) { TInt r; // Request status object for transmit and receive. These object will be // used to read the status of asynchronous requests after the notification // of request completion // TRequestStatus txStatus; TRequestStatus rxStatus; // Timers and their respective status objects for Tx and Rx RTimer timerTx; RTimer timerRx; TRequestStatus timeStatusTx; TRequestStatus timeStatusRx; iTest.Printf(_L("Test Concurrent Asynchronous Requests - Tx/Rx\n")); // Open channel r=iLdd.Open(KUnit1); iTest(r==KErrNone); // Create a buffer that has to be filled and returned by the driver RBuf8 rxBuf; r=rxBuf.Create(aRxSize); iTest(r==KErrNone); r=iLdd.SetIntLoopback(aLoopback); iTest(r==KErrNone); // Create the timer that is relative to the thread r = timerTx.CreateLocal(); iTest(r==KErrNone); r = timerRx.CreateLocal(); iTest(r==KErrNone); // Trigger timerRx expiry after KTimeOutTxRx. The status should be pending timerRx.After(timeStatusRx,KTimeOutTxRx); iTest(timeStatusRx==KRequestPending); // Call ldd interface ReceiveData() API to get data to rxBuf r = iLdd.ReceiveData(rxStatus, rxBuf); // In case of zero length request if (aRxSize==0) { // Driver should return error immediately iTest(r!=KErrNone); // Close the RBuf rxBuf.Close(); // Close channel iLdd.Close(); return; } else { // Asynchronous request should be pending, with request message // posted to driver successfully // iTest((r==KErrNone)&&(rxStatus.Int()==KRequestPending)); } // Trigger timerTx expiry after KTimeOutTxRx. The status should be pending timerTx.After(timeStatusTx,KTimeOutTxRx); iTest(timeStatusTx==KRequestPending); // Call ldd interface TransmitData() API test data descriptor as parameter r = iLdd.TransmitData(txStatus, aTxData); // In case of zero length request if (aTxData.Size()==0) { // Driver should return error immediately iTest(r!=KErrNone); // Close the RBuf rxBuf.Close(); // Close channel iLdd.Close(); return; } else { // Asynchronous request should be pending, with request message // posted to driver successfully // iTest(r==KErrNone); } // Wait till the request is complete on rxStatus and txStatus. User thread // is blocked with this call, till it is notified about the request // completion. // if(txStatus.Int()==KRequestPending) User::WaitForRequest(txStatus,timeStatusTx); if(rxStatus.Int()==KRequestPending) User::WaitForRequest(rxStatus,timeStatusRx); // if transmit has occured correctly, the iTimeStatus will not be KErrNone, else // no transmit complete has occured and iTimer has expired iTest (timeStatusTx!=KErrNone); iTest (timeStatusRx!=KErrNone); // Cancel the iTimer request timerTx.Cancel(); timerRx.Cancel(); // txStatus holds the request completion. TRequestStatus::Int() returns the // completion code. It will be KErrNone in case of successful completion // r = txStatus.Int(); iTest((r==KErrNone)||(r==KErrTimedOut)); r = rxStatus.Int(); iTest((r==KErrNone)||(r==KErrTimedOut)); // Close the handle to the timerTx and timerRx timerTx.Close(); timerRx.Close(); // Print the recieve data to display and verify the data received manually. TInt i; iTest.Printf(_L("Received Data of size (%d):"),rxBuf.Size()); for (i=0;i<rxBuf.Size();i++) { iTest.Printf(_L("%c"),(TUint8*)(rxBuf.Ptr())[i]); if ((rxBuf.Ptr())[i] != aTxData[i]) { iTest.Printf(_L("Transmit and Receive data do not match\n")); iTest(EFalse); } } iTest.Printf(_L("\n")); // Free the receive buffer rxBuf.Close(); // Close channel iLdd.Close(); }