Beispiel #1
0
const char *FBaseCVar::ToString (UCVarValue value, ECVarType type)
{
	switch (type)
	{
	case CVAR_Bool:
		return value.Bool ? truestr : falsestr;

	case CVAR_String:
		return value.String;

	case CVAR_Int:
		mysnprintf (cstrbuf, countof(cstrbuf), "%i", value.Int);
		break;

	case CVAR_Float:
		mysnprintf (cstrbuf, countof(cstrbuf), "%g", value.Float);
		break;

	case CVAR_GUID:
		FormatGUID (cstrbuf, countof(cstrbuf), *value.pGUID);
		break;

	default:
		strcpy (cstrbuf, "<huh?>");
		break;
	}
	return cstrbuf;
}
Beispiel #2
0
// -----------------------------------------------------------------------------
// CAsf::ValidateL
//
// -----------------------------------------------------------------------------
//
void CAsf::ValidateL()
    {
    // ASF_Header_Object GUID 128 bits.
    TBuf8<32> header;

    LOGFN( "CAsf::ValidateL" );
    iFile.Read( 0, header, KObjectID );
    if ( header.Length() < KObjectID )
        {
        User::Leave( KErrOverflow );
        }
    FormatGUID( header );
    if ( header !=  KASFHeaderObject )
        {
        User::Leave( KErrArgument );
        }
    
    // read header object size.
    iFile.Read( header, KObjectSize );
    iHeaderSize = ReadUint64FromBlockL( header, 0 );
    if ( iHeaderSize <= 30 || iHeaderSize > KMaxTInt / 2 - 1 )
        {
        User::Leave( KErrOverflow );
        }

    // read header object
    // 2~31 = 2 GB, size of header would not be greater than this,
    // also, HBufC does not have a NewL with TInt64 as arguement.
    iHeaderData = HBufC8::NewL( iHeaderSize );
    TPtr8 headerPtr = iHeaderData->Des();
    iFile.Read( headerPtr, iHeaderSize - ( KObjectID + KObjectSize ) );

    iNbrOfObjects = ReadUint32FromBlockL( *iHeaderData, 0 );
    if ( iNbrOfObjects <= 0 )
        {
        User::Leave( KErrArgument );
        }

    TInt objOffset( 6 );
    if ( iHeaderData->Length() < ( objOffset + KObjectID ) )
        {
        User::Leave( KErrArgument );
        }
    //Read next object GUID
    TBuf8<32> objGUID = iHeaderData->Mid( objOffset, KObjectID );
    FormatGUID( objGUID );
    TBool loop( ETrue );

    //Loop until all needed headers are handled or top level header is finished
    while ( loop )
        {
        //Read current object size
        TUint32 objSize( ReadUint64FromBlockL( *iHeaderData, objOffset + KObjectID ) );
        if ( objSize < 24 )
            {
            User::Leave( KErrArgument );
            }
        
        if ( !iContentDescriptionObjectExists && objGUID == 
             KASFContentDescriptionObject )
            {
            iContentDescriptionObjectExists = ETrue;
            iContentDescriptionOffset = objOffset;
            ParseContentDescriptionObjectL();
            }
        else if ( !iFilePropertiesObjectExists && objGUID == 
             KASFFilePropertiesObject )
            {
            iFilePropertiesObjectExists = ETrue; // must exist
            iFilePropertiesOffset = objOffset;
            iFilePropertiesEndOffset = iFilePropertiesOffset + objSize;
            }
        else if ( !iExtendedContentDescriptionObjectExists && objGUID ==
             KASFExtendedContentDescriptionObject )
            {
            iExtendedContentDescriptionObjectExists = ETrue;
            iExtendedContentDescriptionOffset = objOffset;
            ParseExtendedContentDescriptionObjectL();
            }
        else if ( !iExtendedContentEncryptionObjectExists && objGUID ==
             KASFExtendedContentEncryptionObject )
            {
            iExtendedContentEncryptionObjectExists = ETrue;
            iExtendedContentEncryptionOffset = objOffset;
            iIsDrmProtected = ETrue;
            TInt eCEODataOffset( objOffset + KObjectID + KObjectSize + 4 );
            TInt eCEODataLength( objSize - ( KObjectID + KObjectSize + 4 ) );
            if ( iHeaderData->Length() < eCEODataOffset + eCEODataLength ||
                 eCEODataLength < 0)
                {
                User::Leave( KErrArgument );
                }
            iExtendedContentEncryptionObject = iHeaderData->Mid( eCEODataOffset,
                                                                 eCEODataLength ).AllocL();
            }
        else if ( !iContentEncryptionObjectExists && objGUID ==
             KASFContentEncryptionObject )
            {
            iContentEncryptionObjectExists = ETrue;
            iContentEncryptionOffset = objOffset;
            iIsDrmProtected = ETrue;
            ParseContentEncryptionObjectL();
            }
        else if ( !iDigitalSignatureObjectExists && objGUID ==
             KASFDigitalSignatureObject )
            {
            iDigitalSignatureObjectExists = ETrue;
            iDigitalSignatureOffset = objOffset;
            
            TInt dSODataOffset( objOffset + KObjectID + KObjectSize + 8 );
            TInt dSODataLength( objSize - ( KObjectID + KObjectSize + 8 ) );
            if ( iHeaderData->Length() < dSODataOffset + dSODataLength ||
                 dSODataLength < 0 )
                {
                User::Leave( KErrArgument );
                }
            iDigitalSignatureObject = iHeaderData->Mid( dSODataOffset,
                                                        dSODataLength ).AllocL();
            
            if ( iHeaderData->Length() < iFilePropertiesEndOffset + ( iDigitalSignatureOffset - iFilePropertiesEndOffset ) ||
                 iDigitalSignatureOffset - iFilePropertiesEndOffset < 0 ||
                 iFilePropertiesEndOffset < 0 )
                {
                iDigitalSignatureObjectExists = EFalse;
                iDigitalSignatureOffset = 0;
                delete iDigitalSignatureObject;
                iDigitalSignatureObject = NULL;
                }
            else
                {
                iSignedData = 
                    iHeaderData->Mid( iFilePropertiesEndOffset,
                                      iDigitalSignatureOffset - iFilePropertiesEndOffset ).AllocL();
                }
            }
        
        //Move object offset to the end of the current header object  
        objOffset += objSize;
        //End loop, if top level header is finished or all needed headers are handled
        if ( objOffset >= iHeaderSize - 30 ||
            ( iContentDescriptionObjectExists &&
              iFilePropertiesObjectExists &&
              iExtendedContentDescriptionObjectExists &&
              iExtendedContentEncryptionObjectExists &&
              iDigitalSignatureObjectExists ) )
            {
            loop = EFalse;
            }
        //Loop isn't finished, read next object GUID
        else
            {
            if ( iHeaderData->Length() < ( objOffset + KObjectID ) || objOffset < 0 )
                {
                User::Leave( KErrArgument );
                }
            objGUID = iHeaderData->Mid( objOffset, KObjectID );
            FormatGUID( objGUID );
            }
        }
    if ( iFilePropertiesObjectExists )
        {
        iIsValidated = ETrue;
        }
    }