Ejemplo n.º 1
0
        /// <summary>
        /// Parses the tag information from the buffer.
        /// </summary>
        /// <param name="start">The start index of the tag information.</param>
        /// <param name="buffer">The buffer containing the data.</param>
        /// <param name="size">The number of bytes to read.</param>
        /// <returns>Returns true if the data was parsed sucessfully.</returns>
        public bool Parse(int start, byte[] buffer, int size)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (size < 16 || (start + size) > buffer.Length || buffer[start + 5] != 0)
            {
                return(false);
            }

            int sum = 0;

            for (int i = 0; i < 16; i++)
            {
                if (i != 4)
                {
                    sum = sum + buffer[start + i];
                }
            }

            int m = (sum % 256);

            if (m != buffer[start + 4])
            {
                return(false);
            }

            this.Identifier = UdfHelper.Get16(start, buffer);
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads a logical volume descriptor from the buffer.
        /// </summary>
        /// <param name="buffer">The buffer to read the data from.</param>
        /// <returns>Returns true if the descriptor is valid.</returns>
        private bool ReadLogicalDescriptor(byte[] buffer)
        {
            LogicalVolume volume = new LogicalVolume();

            volume.Id.Parse(84, buffer);
            volume.BlockSize = UdfHelper.Get32(212, buffer);
            if (volume.BlockSize < VirtualSectorSize || volume.BlockSize > MaxExtents)
            {
                return(false);
            }

            volume.FileSetLocation.Parse(248, buffer);

            int numPartitionMaps = UdfHelper.Get32(268, buffer);

            if (numPartitionMaps > MaxPartitions)
            {
                return(false);
            }

            int position = 440;

            for (int index = 0; index < numPartitionMaps; index++)
            {
                if (position + 2 > SectorSize)
                {
                    return(false);
                }

                PartitionMap pm = new PartitionMap();
                pm.Type = buffer[position];
                byte length = buffer[position + 1];
                if (position + length > SectorSize)
                {
                    return(false);
                }

                if (pm.Type == 1)
                {
                    if (position + 6 > SectorSize)
                    {
                        return(false);
                    }

                    pm.PartitionNumber = UdfHelper.Get16(position + 4, buffer);
                }
                else
                {
                    return(false);
                }

                position         += length;
                pm.PartitionIndex = volume.PartitionMaps.Count;
                volume.PartitionMaps.Add(pm);
            }

            this.LogicalVolumes.Add(volume);
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads a partition descriptor from the buffer.
        /// </summary>
        /// <param name="buffer">The buffer to read the partition data from.</param>
        private void ReadPartitionDescriptor(byte[] buffer)
        {
            var partition = new Partition
            {
                Number   = UdfHelper.Get16(22, buffer),
                Position = UdfHelper.Get32(188, buffer),
                Length   = UdfHelper.Get32(192, buffer)
            };

            this.Partitions.Add(partition);
        }
Ejemplo n.º 4
0
        public void Parse(int start, byte[] buffer)
        {
            try {
                this.FileType = (IcbFileType)buffer[start + 11];
            } catch (InvalidCastException) {
                this.FileType = IcbFileType.Other;
            }

            int flags = UdfHelper.Get16(start + 18, buffer);

            try {
                this.DescriptorType = (IcbDescriptorType)(flags & 3);
            } catch (InvalidCastException) {
                throw new InvalidOperationException();
            }
        }