void CRFC3984Encode::PayloadizeFrameSingleNALModeL( TDes8& aBuffer, TUint32 /*aTimeStamp*/, TUint32& /*aMarkerBit*/, TInt& aNalCount ) { // This implementation assumes the NAL units for one frame are seperated // by 0x001 or 0x0001 start codes // Resetting iBufferIndex for this new frame, always do this for new frame // because this is used to find start codes within one frame iBufferIndex = 0; TInt startIndex = 0; // holds first byte-index of NALU TInt endIndex = 0; // hold byte-index of next to last byte of NALU TInt size = 0; HBufC8 * pBuffer = 0; // loop to find and packetize all NAL Units in the frame while ( ETrue ) { startIndex = TMccCodecInfo::FindAvcNaluStart( iBufferIndex, aBuffer ); if ( KErrNotFound == startIndex ) { break; } endIndex = TMccCodecInfo::FindAvcNaluEnd( iBufferIndex, aBuffer ); if ( KErrNotFound == endIndex ) { break; } if ( startIndex == endIndex ) { break; } // finding size of the NAL unit size = endIndex - startIndex; __ASSERT_ALWAYS( size > 0, User::Leave( KErrGeneral ) ); // some flaw in logic pBuffer = HBufC8::NewLC( size ); TPtr8 aPtr = pBuffer->Des(); // Now the size and start Index is known, copying the data aPtr.Copy( aBuffer.Mid( startIndex, size ) ); // Now inserting pointer iPayloadizedBuffers.InsertL( pBuffer, iNalCount ); CleanupStack::Pop( pBuffer ); pBuffer = NULL; // ownership transferred iNalCount++; } aNalCount = iNalCount; }
// --------------------------------------------------------- // CCookieTimer::ChangeToDecimal // --------------------------------------------------------- // TInt CCookieManagerServer::ChangeToDecimal( TDes8& aBuf,TUint32& aUid ) { CLOG( ( EServer, 0, _L( "-> CCookieManagerServer::ChangeToDecimal" ) ) ); TBuf8<100> tempBuf; TPtrC8 tempPtr = aBuf.Mid( KHexDel().Length()); tempBuf.Copy(tempPtr); TLex8 lex(tempBuf); TInt ret = lex.Val(aUid,EHex); CLOG( ( EServer, 0, _L( "<- CCookieManagerServer::ChangeToDecimal" ) ) ); return ret; }
////////////////////////////////////////////////////////////////////// // util ////////////////////////////////////////////////////////////////////// void ReplaceUrl(TDes8& aUrl,const TDesC8& aIsRepeatedKStr,const TDesC8& aStr){ HBufC8* tmp=HBufC8::NewL(aUrl.Length()+aStr.Length()+128); int iPos=aUrl.FindF(aIsRepeatedKStr); if(iPos>=0){ tmp->Des().Copy(aUrl.Left(iPos)); //加上前面有用的字符 tmp->Des().Append(aStr); int iStart=iPos+aIsRepeatedKStr.Length(); //要被替换的字符,加上要被替换的字符长度 int iLen2=aUrl.Length()-iStart; tmp->Des().Append(aUrl.Mid(iStart,iLen2)); //加上后面有用的字符 aUrl.Copy(tmp->Des()); } delete tmp; }
void MainWindow::GenerateKey(TDes8& aKey, TInt aLen) { aKey.Zero(); TTime currentTime; currentTime.HomeTime(); // ??000Ä꿪ʼ¼Æ?? TInt startYear = 2000; // µ±Ç°Äê·Ý TInt currentYear = currentTime.DateTime().Year(); TTime time(TDateTime(currentYear, EJanuary, 0, 0, 0, 0, 0)); TTimeIntervalSeconds s; currentTime.SecondsFrom(time, s); // µÃµ½ÃëÊý TInt i = s.Int(); aKey.AppendFormat(_L8("%X"), i); aKey.AppendFormat(_L8("%X"), currentYear - startYear); TInt len = aKey.Length(); if (len > aLen) { aKey.Mid(0, aLen); } else { for (TInt i = 0; i < aLen - len; i++) { TTime theTime; theTime.UniversalTime(); TInt64 randSeed(theTime.Int64()); TInt number(Math::Rand(randSeed) + i); number = number % 10 + 48; aKey.Append(number); } } }
inline void CPppMsChap::ChallengeResponseL(const TDesC8& aChallenge, TDes8& aPaddablePasswordHash, TDes8& aResponse) /** Computes the Challenge Response. @param aChallenge [in] A MS-CHAP Challenge (8 octets). @param aPaddablePasswordHash [in/out] The hash of the password in a paddable buffer (16 octets in a buffer with at least 21 octets maximum length). @param aResponse [out] The Challenge Response (24 octets). @note This function implements the ChallengeResponse routine specified in RFC 2433. @internalComponent */ { ASSERT(aChallenge.Length()==KPppMsChapChallengeSize); ASSERT(aPaddablePasswordHash.Length()==KPppMsChapHashSize && aPaddablePasswordHash.MaxLength() >= KPppMsChapPaddedHashSize); ASSERT(aResponse.Length() == KPppMsChapNTResponseSize); // aPaddablePasswordHash contains the hash of the password (16 octets) // zero-padded to 21 octets // RFC 2433 - ChallengeResponse(): "Set ZPasswordHash to // PasswordHash zero-padded to 21 octets", i.e. 5 octets aPaddablePasswordHash.AppendFill(0, KPppMsChapPaddedHashSize - KPppMsChapHashSize); // The first 8 octets of aResponse TPtr8 responseChunk(const_cast<TUint8*>(aResponse.Ptr()), KPppDESKeySize, KPppDESKeySize); DesEncryptL(aChallenge, aPaddablePasswordHash.Left(KPppMsChapDESKeySize), responseChunk); // The second 8 octets of aResponse responseChunk.Set(const_cast<TUint8*>(aResponse.Ptr()) + KPppDESKeySize, KPppDESKeySize, KPppDESKeySize); DesEncryptL(aChallenge, aPaddablePasswordHash.Mid(KPppMsChapDESKeySize, KPppMsChapDESKeySize), responseChunk); // The third 8 octets of aResponse responseChunk.Set(const_cast<TUint8*>(aResponse.Ptr()) + 2*KPppDESKeySize, KPppDESKeySize, KPppDESKeySize); DesEncryptL(aChallenge, aPaddablePasswordHash.Mid(2*KPppMsChapDESKeySize, KPppMsChapDESKeySize), responseChunk); // Restore the original length of the password hash aPaddablePasswordHash.SetLength(KPppMsChapHashSize); ASSERT(aResponse.Length() == KPppMsChapNTResponseSize); }
// ----------------------------------------------------------------------------- // CExprUDPMsg::TryParsingL // ----------------------------------------------------------------------------- // TInt CExprUDPMsg::TryParsingL( TDes8& aData, TInt& aLength ) { __ASSERT_ALWAYS( aData.Left( KUDPPrefix().Length() ) == KUDPPrefix, User::Panic( _L("Protocol"), 1 ) ); // UDP:0123,000e,[Some test data] TInt frameOverhead = KUDPPrefix().Length() + KHexDecimalLength + KPortSuffix().Length() + KHexDecimalLength + KLengthSuffix().Length() + KDataSuffix().Length() + KMessageSuffix().Length(); if ( aData.Length() >= frameOverhead ) { TPtrC8 portPtr( aData.Mid( KUDPPrefix().Length(), KHexDecimalLength ) ); TLex8 portLexer( portPtr ); TUint port; if ( portLexer.Val( port, EHex ) != KErrNone ) { return KErrCorrupt; } DEBUG_PRINT( DEBUG_STRING( "CExprUDPMsg::TryParsingL, port = %d" ), port ); //Check port suffix if ( aData.Mid( KUDPPrefix().Length() + KHexDecimalLength, KPortSuffix().Length() ) != KPortSuffix ) { return KErrCorrupt; } TPtrC8 lengthPtr( aData.Mid( KUDPPrefix().Length() + KHexDecimalLength + KPortSuffix().Length(), KHexDecimalLength ) ); TLex8 lengthLexer( lengthPtr ); TUint length; if ( lengthLexer.Val( length, EHex ) != KErrNone ) { return KErrCorrupt; } DEBUG_PRINT( DEBUG_STRING( "CExprUDPMsg::TryParsingL, length = %d" ), length ); //Check length suffix if ( aData.Mid( KUDPPrefix().Length() + KHexDecimalLength + KPortSuffix().Length() + KHexDecimalLength, KLengthSuffix().Length() ) != KLengthSuffix ) { return KErrCorrupt; } DEBUG_PRINT( DEBUG_STRING( "CExprUDPMsg::TryParsingL, parsing data" ), length ); if ( aData.Length() >= TInt( frameOverhead + length ) ) { TInt messagePos = KUDPPrefix().Length() + KHexDecimalLength + KPortSuffix().Length() + KHexDecimalLength + KLengthSuffix().Length(); TPtrC8 message( aData.Mid( messagePos, length ) ); if ( aData.Mid( messagePos + length, KDataSuffix().Length() ) != KDataSuffix ) { return KErrCorrupt; } DEBUG_PRINT( DEBUG_STRING( "CExprUDPMsg::TryParsingL, message OK" ) ); if ( aData.Mid( messagePos + length + KDataSuffix().Length(), KMessageSuffix().Length() ) != KMessageSuffix ) { return KErrCorrupt; } // send parsed results iObserver->FrameParsedL( port, message ); // set the length of the handled message aLength = frameOverhead + length; return KErrNone; } } return KErrNone; }
TInt CISO2022KRImplementation::ConvertFromUnicode( CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, TDes8& aForeign, const TDesC16& aUnicode, CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters) { TInt ret; TInt currPos = 3; TUint outputConversionFlags = 0; TUint inputConversionFlags = CCnvCharacterSetConverter::EInputConversionFlagAppend; TISO2022FromUniState currState = EISO2022Initialize; TUint8 shiftByte = 0; TPtr8 shiftBytePtr(NULL, 0); aForeign.SetLength(0); /* Start with escape sequence */ aForeign.Append( KLit8EscapeSequence ); ret = CCnvCharacterSetConverter::DoConvertFromUnicode( CnvCp949Table::ConversionData(), aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, outputConversionFlags, inputConversionFlags ); /* Append shift in and out bytes as needed */ while( currPos < aForeign.Length() ) { TUint8 *currChar = (TUint8 *)aForeign.Mid(currPos).Ptr(); if( *currChar > KMaxAscii ) { /* KSC character */ if( currState != EISO2022KSC ) { /* Insert shift out byte */ shiftByte = SHIFT_OUT_BYTE; currState = EISO2022KSC; } /* Clear the 8th bit */ *currChar = (*currChar & ~(0x80)); } else { /* ASCII character */ if( currState != EISO2022Ascii ) { /* Insert shift in byte */ shiftByte = SHIFT_IN_BYTE; currState = EISO2022Ascii; } } if( shiftByte ) { if( (aForeign.Length() + 1) > aForeign.MaxLength() ) { /* Make room for shift byte */ if( aForeign[ (aForeign.Length() - 1) ] > KMaxAscii ) { /* Drop a dual byte KSC character */ aForeign.SetLength( aForeign.Length() - 2 ); } else { /* Drop a single byte ASCII character */ aForeign.SetLength( aForeign.Length() - 1 ); } /* Increase unconverted amount */ ret++; /* TBD, propably should try to fix aIndicesOfUnconvertibleCharacters if possible */ } shiftBytePtr.Set( &shiftByte, 1, 1 ); aForeign.Insert( currPos, shiftBytePtr ); currPos++; shiftByte = 0; } /* Skip current character */ currPos++; } return ret; }