//---------------------------------------------------------------------------
bool File_Ico::FileHeader_Begin()
{
    //Element_Size
    if (Buffer_Size<4)
        return false; //Must wait for more data

    if (CC2(Buffer) || (LittleEndian2int16u(Buffer+2)!=1 && LittleEndian2int16u(Buffer+2)!=2))
    {
        Reject("ICO");
        return false;
    }

    //All should be OK...
    return true;
}
Esempio n. 2
0
//---------------------------------------------------------------------------
// Little Endian - float 80 bits
float80 LittleEndian2float80(const char* Liste)
{
    //sign          1 bit
    //exponent     15 bit
    //integer?      1 bit
    //significand  63 bit

    //Retrieving data
    int16u Integer1=LittleEndian2int16u(Liste);
    int64u Integer2=LittleEndian2int64u(Liste+2);

    //Retrieving elements
    bool   Sign    =(Integer1&0x8000)?true:false;
    int16u Exponent= Integer1&0x7FFF;
    int64u Mantissa= Integer2&0x7FFFFFFFFFFFFFFFLL; //Only 63 bits, 1 most significant bit is explicit
    //Some computing
    if (Exponent==0 || Exponent==0x7FFF)
        return 0; //These are denormalised numbers, NANs, and other horrible things
    Exponent-=0x3FFF; //Bias
    float80 Answer=(((float80)Mantissa)/9223372036854775808.0+1.0)*std::pow((float)2, (int)Exponent); //(1+Mantissa) * 2^Exponent
    if (Sign)
        Answer=-Answer;

    return (float80)Answer;
}
Esempio n. 3
0
bool File_Zip::end_of_central_directory()
{
    if (Element_Offset+22>Element_Size) //end_of_central_directory up to relative offset of .ZIP file comment length included
        return false; //Not enough data

    //Retrieving complete local_file_header size
    int16u zip_comment_length=LittleEndian2int16u(Buffer+(size_t)Element_Offset+20);
    if (Element_Offset+22+zip_comment_length>Element_Size) //end_of_central_directory all included
        return false; //Not enough data

    //Parsing
    int32u offset;
    Element_Begin1("End of central directory");
    Skip_C4(                                                    "end of central dir signature");
    Skip_L2(                                                    "number of this disk");
    Skip_L2(                                                    "number of the disk");// with the start of the central directory
    Skip_L2(                                                    "total number of entries on this disk");// in the central directory
    Skip_L2(                                                    "total number of entries");// in the central directory
    Skip_L4(                                                    "size of the central directory");
    Get_L4 (offset,                                             "offset of start of central directory");// with respect to the starting disk number
    Skip_L2(                                                    "zip file comment length");
    Skip_XX(zip_comment_length,                                 "zip file comment");
    Element_End0();

    //Going to first central directory (once)
    if (!end_of_central_directory_IsParsed)
    {
        end_of_central_directory_IsParsed=true;
        GoTo(offset);
    }
    return true;
}
Esempio n. 4
0
//---------------------------------------------------------------------------
bool File_Rar::Header_Begin()
{
    if (Element_Offset+7>Element_Size)
        return false; //Not enough data for header size
    int16u HEAD_SIZE=LittleEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset+5);

    if (Element_Offset+HEAD_SIZE>Element_Size)
        return false; //Not enough data for header

    return true;
}
Esempio n. 5
0
//---------------------------------------------------------------------------
bool File_Umf::FileHeader_Begin()
{
    //Element_Size
    if (Buffer_Size<2)
        return false; //Must wait for more data

    int16u Length=LittleEndian2int16u(Buffer);
    if (Buffer_Size<Length)
        return false; //Must wait for more data

    //All should be OK...
    Accept("UMF");
    return true;
}
Esempio n. 6
0
//---------------------------------------------------------------------------
bool File_Dts::Synchronize()
{
    //Synchronizing
    while (Buffer_Offset+6<=Buffer_Size
      && !(BigEndian2int16u   (Buffer+Buffer_Offset+0)==0x7FFE && BigEndian2int16u   (Buffer+Buffer_Offset+2)==0x8001) //16 bits and big    endian bitstream
      && !(LittleEndian2int16u(Buffer+Buffer_Offset+0)==0x7FFE && LittleEndian2int16u(Buffer+Buffer_Offset+2)==0x8001) //16 bits and little endian bitstream
      && !(BigEndian2int16u   (Buffer+Buffer_Offset+0)==0x1FFF && BigEndian2int16u   (Buffer+Buffer_Offset+2)==0xE800 && (BigEndian2int16u   (Buffer+Buffer_Offset+4)&0xFFF0)==0x07F0) //14 bits and big    endian bitstream
      && !(LittleEndian2int16u(Buffer+Buffer_Offset+0)==0x1FFF && LittleEndian2int16u(Buffer+Buffer_Offset+2)==0xE800 && (LittleEndian2int16u(Buffer+Buffer_Offset+4)&0xFFF0)==0x07F0) //14 bits and little endian bitstream
      )
        Buffer_Offset++;
    if (Buffer_Offset+6>Buffer_Size)
    {
        //Parsing last bytes
        if (Buffer_Offset+6==Buffer_Size)
        {
            if (CC4(Buffer+Buffer_Offset)!=0x7FFE8001) //For 6 bytes instead of 4 (14 bits)
            {
                Buffer_Offset++;
                if (CC4(Buffer+Buffer_Offset)!=0x7FFE8001) //For 6 bytes instead of 4 (14 bits)
                {
                    Buffer_Offset++;
                    if (CC4(Buffer+Buffer_Offset)!=0x7FFE8001)
                    {
                        Buffer_Offset++;
                        if (CC3(Buffer+Buffer_Offset)!=0x7FFE80)
                        {
                            Buffer_Offset++;
                            if (CC2(Buffer+Buffer_Offset)!=0x7FFE)
                            {
                                Buffer_Offset++;
                                if (CC1(Buffer+Buffer_Offset)!=0x7F)
                                    Buffer_Offset++;
                            }
                        }
                    }
                }
            }
        }

        //Delay
        if (Frame_Count==0)
            Delay+=Buffer_Offset;

        return false;
    }

    //Configuring and Delay
    if (Frame_Count==0)
    {
        if (0) ;
        else if (BigEndian2int16u   (Buffer+Buffer_Offset)==0x7FFE) //16 bits and big    endian bitstream
        {
        }
        else if (LittleEndian2int16u(Buffer+Buffer_Offset)==0x7FFE) //16 bits and little endian bitstream
        {
            BigEndian=false;
        }
        else if (BigEndian2int16u   (Buffer+Buffer_Offset)==0x1FFF) //14 bits and big    endian bitstream
        {
            Word=false;
        }
        else if (LittleEndian2int16u(Buffer+Buffer_Offset)==0x1FFF) //14 bits and little endian bitstream
        {
            Word=false;
            BigEndian=false;
        }

        SyncCode=CC4(Buffer+Buffer_Offset);

        //14-bits and Little endian are not yet supported
        if (!Word || !BigEndian)
        {
            Finnished();
            return false;
        }

        //Delay
        Delay+=Buffer_Offset;
    }

    //Synched is OK
    Synched=true;
    return true;
}
Esempio n. 7
0
bool File_Zip::central_directory()
{
    if (Element_Offset+46>Element_Size) //central_directory up to relative offset of local header included
        return false; //Not enough data

    //Retrieving complete local_file_header size
    int16u file_name_length=LittleEndian2int16u(Buffer+(size_t)Element_Offset+28);
    int16u extra_field_length=LittleEndian2int16u(Buffer+(size_t)Element_Offset+30);
    int16u file_comment_length=LittleEndian2int16u(Buffer+(size_t)Element_Offset+32);
    if (Element_Offset+46+file_name_length+extra_field_length+file_comment_length>Element_Size) //central_directory_structure all included
        return false; //Not enough data

    int16u general_purpose_bit_flag;
    bool efs;
    int16u version_made_by,compression_method;

    //Parsing
    Element_Begin1("Central directory");
    Skip_C4("central file header signature");
    Get_L2 (version_made_by,"version made by");Param_Info1((version_made_by>>8)>20?"unused":Zip_made_by[version_made_by>>8]);
    Skip_L2("version needed to extract");
    Get_L2 (general_purpose_bit_flag,"general purpose bit flag");
    Skip_Flags(general_purpose_bit_flag, 0,                     "encrypted file");
    Skip_Flags(general_purpose_bit_flag, 1,                     "8K sliding dictionary");
    Skip_Flags(general_purpose_bit_flag, 2,                     "3 Shannon-Fano trees");
    Skip_Flags(general_purpose_bit_flag, 3,                     "data descriptor");
    Skip_Flags(general_purpose_bit_flag, 4,                     "Reserved for use with method 8");
    Skip_Flags(general_purpose_bit_flag, 4,                     "file is compressed patched data");
    Skip_Flags(general_purpose_bit_flag, 4,                     "Strong encryption");
    //~ Skip_Flags(general_purpose_bit_flag, 4,                     "Currently unused");
    //~ Skip_Flags(general_purpose_bit_flag, 4,                     "Currently unused");
    //~ Skip_Flags(general_purpose_bit_flag, 4,                     "Currently unused");
    //~ Skip_Flags(general_purpose_bit_flag, 4,                     "Currently unused");
    Get_Flags (general_purpose_bit_flag, 11, efs,                "Language encoding flag (EFS)");
    //~ Skip_Flags(general_purpose_bit_flag, 4,                     "Reserved by PKWARE for enhanced compression");
    //~ Skip_Flags(general_purpose_bit_flag, 4,                     "");
    //~ Skip_Flags(general_purpose_bit_flag, 4,                     "Reserved by PKWARE");
    //~ Skip_Flags(general_purpose_bit_flag, 4,                     "Reserved by PKWARE");
    Get_L2 (compression_method,"compression method");
    Param_Info1C((compression_method<20), Zip_compression_method[compression_method]);
    Param_Info1C((compression_method==97||compression_method==98), Zip_compression_method[compression_method-97+20]);
    Skip_L2("last mod file time");
    Skip_L2("last mod file date");
    Skip_L4("crc-32");
    Skip_L4("compressed size");
    Skip_L4("uncompressed size");
    Skip_L2("file name length");
    Skip_L2("extra field length");
    Skip_L2("file comment length");
    Skip_L2("disk number start");
    Skip_L2("internal file attributes");
    Skip_L4("external file attributes");
    Skip_L4("relative offset of local header");
    if(efs) {
        Skip_UTF8(file_name_length,"file name");
        Skip_UTF8(extra_field_length,"extra field");
        Skip_UTF8(file_comment_length,"file comment");
    } else {
        Skip_Local(file_name_length,"file name");
        Skip_Local(extra_field_length,"extra field");
        Skip_Local(file_comment_length,"file comment");
    }
    Element_End0();
    
    return true;
}
Esempio n. 8
0
//---------------------------------------------------------------------------
void File_Tiff::GetValueOffsetu(ifditem &IfdItem)
{
    ZtringList &Info=Infos[IfdItem.Tag]; Info.clear(); Info.Separator_Set(0, __T(" / "));
    const char* Name=Tiff_Tag_Name(IfdItem.Tag);

    if (IfdItem.Count>=10)
    {
        //Too many data, we don't currently need it and we skip it
        Skip_XX(Element_Size-(Element_Offset+4),                Name);
        Info.clear();
        return;
    }

    switch (IfdItem.Type)
    {
        case 1:                /* 8-bit unsigned integer. */
                for (int16u Pos=0; Pos<IfdItem.Count; Pos++)
                {
                    int8u Ret8;
                    #if MEDIAINFO_TRACE
                        if (LittleEndian)
                            Get_L1 (Ret8,                       Name);
                        else
                            Get_B1 (Ret8,                       Name);
                        Element_Info1(Ztring::ToZtring(Ret8));
                    #else //MEDIAINFO_TRACE
                        if (Element_Offset+1>Element_Size)
                        {
                            Trusted_IsNot();
                            break;
                        }
                        if (LittleEndian)
                            Ret8=LittleEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset);
                        else
                            Ret8=BigEndian2int8u(Buffer+Buffer_Offset+(size_t)Element_Offset);
                        Element_Offset++;
                    #endif //MEDIAINFO_TRACE
                    Info.push_back(Ztring::ToZtring(Ret8));
                }
                break;

        case 3:                /* 16-bit (2-byte) unsigned integer. */
                for (int16u Pos=0; Pos<IfdItem.Count; Pos++)
                {
                    int16u Ret16;
                    #if MEDIAINFO_TRACE
                        if (LittleEndian)
                            Get_L2 (Ret16,                      Name);
                        else
                            Get_B2 (Ret16,                      Name);
                        switch (IfdItem.Tag)
                        {
                            case Tiff_Tag::Compression : Element_Info1(Tiff_Compression(Ret16)); break;
                            case Tiff_Tag::PhotometricInterpretation : Element_Info1(Tiff_PhotometricInterpretation(Ret16)); break;
                            default : Element_Info1(Ztring::ToZtring(Ret16));
                        }
                    #else //MEDIAINFO_TRACE
                        if (Element_Offset+2>Element_Size)
                        {
                            Trusted_IsNot();
                            break;
                        }
                        if (LittleEndian)
                            Ret16=LittleEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset);
                        else
                            Ret16=BigEndian2int16u(Buffer+Buffer_Offset+(size_t)Element_Offset);
                        Element_Offset+=2;
                    #endif //MEDIAINFO_TRACE
                    Info.push_back(Ztring::ToZtring(Ret16));
                }
                break;

        case 4:                /* 32-bit (4-byte) unsigned integer */
                for (int16u Pos=0; Pos<IfdItem.Count; Pos++)
                {
                    int32u Ret32;
                    #if MEDIAINFO_TRACE
                        if (LittleEndian)
                            Get_L4 (Ret32,                      Name);
                        else
                            Get_B4 (Ret32,                      Name);
                        Element_Info1(Ztring::ToZtring(Ret32));
                    #else //MEDIAINFO_TRACE
                        if (Element_Offset+4>Element_Size)
                        {
                            Trusted_IsNot();
                            break;
                        }
                        if (LittleEndian)
                            Ret32=LittleEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
                        else
                            Ret32=BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
                        Element_Offset+=4;
                    #endif //MEDIAINFO_TRACE
                    Info.push_back(Ztring::ToZtring(Ret32));
                }
                break;

        default:            //Unknown
                {
                    if (LittleEndian)
                        Skip_L4(                                Name);
                    else
                        Skip_B4(                                Name);
                    Info.clear(); //We actually do not know the type
                }
    }
}