Exemplo n.º 1
0
 protected void Parse(ByteVector data)
 {
     if (data != null)
     {
         size = Id3v2SynchData.ToUInt(data.Mid(0, 4));
     }
     else
     {
         throw new ArgumentNullException("data");
     }
 }
Exemplo n.º 2
0
        protected void Parse(ByteVector data)
        {
            if (data.Count < Size)
            {
                return;
            }

            // do some sanity checking -- even in ID3v2.3.0 and less the tag size is a
            // synch-safe integer, so all buffer must be less than 128.  If this is not
            // true then this is an invalid tag.

            // note that we're doing things a little out of order here -- the size is
            // later in the bytestream than the version

            ByteVector sizeData = data.Mid(6, 4);

            if (sizeData.Count != 4)
            {
                tagSize = 0;
                TagLibDebugger.Debug("ID3v2.Header.Parse () - The tag size as read was 0 bytes!");
                return;
            }

            foreach (byte b in sizeData)
            {
                if (b >= 128)
                {
                    tagSize = 0;
                    TagLibDebugger.Debug("ID3v2.Header.Parse () - One of the size bytes in the id3v2 header was greater than the allowed 128.");
                    return;
                }
            }

            // The first three buffer, data[0..2], are the File Identifier, "ID3". (structure 3.1 "file identifier")

            // Read the version number from the fourth and fifth buffer.
            majorVersion   = data[3];             // (structure 3.1 "major version")
            revisionNumber = data[4];             // (structure 3.1 "revision number")

            // Read the flags, the first four bits of the sixth byte.
            byte flags = data[5];

            desynchronization     = ((flags >> 7) & 1) == 1;     // (structure 3.1.a)
            extendedHeader        = ((flags >> 6) & 1) == 1;     // (structure 3.1.b)
            experimentalIndicator = ((flags >> 5) & 1) == 1;     // (structure 3.1.channelMode)
            footerPresent         = ((flags >> 4) & 1) == 1;     // (structure 3.1.d)

            // Get the size from the remaining four buffer (read above)

            tagSize = Id3v2SynchData.ToUInt(sizeData);             // (structure 3.1 "size")
        }
Exemplo n.º 3
0
        public void SetData(ByteVector data, uint version)
        {
            if (data != null)
            {
                this.version = version;

                if (version < 3)
                {
                    // ID3v2.2

                    if (data.Count < 3)
                    {
                        TagLibDebugger.Debug("You must at least specify a frame ID.");
                        return;
                    }

                    // Set the frame ID -- the first three buffer

                    frameId = data.Mid(0, 3);

                    // If the full header information was not passed in, do not continue to the
                    // steps to parse the frame size and flags.

                    if (data.Count < 6)
                    {
                        frameSize = 0;
                        return;
                    }

                    frameSize = data.Mid(3, 3).ToUInt();
                }
                else if (version == 3)
                {
                    // ID3v2.3

                    if (data.Count < 4)
                    {
                        TagLibDebugger.Debug("You must at least specify a frame ID.");
                        return;
                    }

                    // Set the frame ID -- the first four buffer

                    frameId = data.Mid(0, 4);

                    // If the full header information was not passed in, do not continue to the
                    // steps to parse the frame size and flags.

                    if (data.Count < 10)
                    {
                        frameSize = 0;
                        return;
                    }

                    // Set the size -- the frame size is the four buffer starting at byte four in
                    // the frame header (structure 4)

                    frameSize = data.Mid(4, 4).ToUInt();

                    // read the first byte of flags
                    tagAlterPreservation  = ((data[8] >> 7) & 1) == 1;        // (structure 3.3.1.a)
                    fileAlterPreservation = ((data[8] >> 6) & 1) == 1;        // (structure 3.3.1.b)
                    readOnly = ((data[8] >> 5) & 1) == 1;                     // (structure 3.3.1.channelMode)

                    // read the second byte of flags
                    compression      = ((data[9] >> 7) & 1) == 1;               // (structure 3.3.1.index)
                    encryption       = ((data[9] >> 6) & 1) == 1;               // (structure 3.3.1.j)
                    groupingIdentity = ((data[9] >> 5) & 1) == 1;               // (structure 3.3.1.k)
                }
                else
                {
                    // ID3v2.4

                    if (data.Count < 4)
                    {
                        TagLibDebugger.Debug("You must at least specify a frame ID.");
                        return;
                    }

                    // Set the frame ID -- the first four buffer

                    frameId = data.Mid(0, 4);

                    // If the full header information was not passed in, do not continue to the
                    // steps to parse the frame size and flags.

                    if (data.Count < 10)
                    {
                        frameSize = 0;
                        return;
                    }

                    // Set the size -- the frame size is the four buffer starting at byte four in
                    // the frame header (structure 4)

                    frameSize = Id3v2SynchData.ToUInt(data.Mid(4, 4));

                    // read the first byte of flags
                    tagAlterPreservation  = ((data[8] >> 6) & 1) == 1;        // (structure 4.1.1.a)
                    fileAlterPreservation = ((data[8] >> 5) & 1) == 1;        // (structure 4.1.1.b)
                    readOnly = ((data[8] >> 4) & 1) == 1;                     // (structure 4.1.1.channelMode)

                    // read the second byte of flags
                    groupingIdentity    = ((data[9] >> 6) & 1) == 1;            // (structure 4.1.2.header)
                    compression         = ((data[9] >> 3) & 1) == 1;            // (structure 4.1.2.k)
                    encryption          = ((data[9] >> 2) & 1) == 1;            // (structure 4.1.2.m)
                    desynchronization   = ((data[9] >> 1) & 1) == 1;            // (structure 4.1.2.n)
                    dataLengthIndicator = (data[9] & 1) == 1;                   // (structure 4.1.2.position)
                }
            }
            else
            {
                throw new ArgumentNullException("data");
            }
        }