Example #1
0
        /// <summary>
        /// Reads the volume descriptors for
        /// </summary>
        /// <param name="extentVds">The anchor volume extent information.</param>
        /// <returns>Returns true if the volume descriptors were read from the image successfully.</returns>
        private bool ReadVolumeDescriptors(UdfFileExtent extentVds)
        {
            byte[] buffer = new byte[SectorSize];

            long location = extentVds.Position;

            while (location < extentVds.Length && location < this.imageSize)
            {
                this.stream.Seek(location << SectorSizeLog, (int)SeekOrigin.Begin, IntPtr.Zero);
                if (!this.stream.ReadSafe(buffer, buffer.Length))
                {
                    return(false);
                }

                VolumeTag tag = new VolumeTag();
                tag.Parse(0, buffer, buffer.Length);

                switch ((VolumeDescriptorType)tag.Identifier)
                {
                case VolumeDescriptorType.Terminating:
                    // Found terminating descriptor.  Image is valid.
                    return(true);

                case VolumeDescriptorType.Partition:
                    if (this.Partitions.Count >= MaxPartitions)
                    {
                        return(false);
                    }

                    this.ReadPartitionDescriptor(buffer);
                    break;

                case VolumeDescriptorType.LogicalVolume:
                    if (this.LogicalVolumes.Count >= MaxLogicalVolumes || !this.ReadLogicalDescriptor(buffer))
                    {
                        return(false);
                    }

                    break;
                }

                location++;
            }

            // Did not find the terminating descriptor.  Not a valid image.
            return(false);
        }
Example #2
0
        /// <summary>
        /// Opens the file and attempts to read the contents of the ISO image.
        /// </summary>
        /// <returns>Returns true if the image was opened successfully.</returns>
        public bool Open()
        {
            try
            {
                using (var fileStream = this.ImageFile.OpenRead())
                {
                    // Initialize the stream
                    this.InitializeStream(fileStream);

                    // Must have at least one sector in the image.
                    if (this.imageSize < SectorSize)
                    {
                        return(false);
                    }

                    // Parse the anchor pointer to find the location of the volume descriptors.
                    UdfFileExtent extentVds = this.ReadAnchorVolumePointer();
                    if (extentVds == null)
                    {
                        return(false);
                    }

                    // Parse the volume and paritiotion information from the image.
                    if (!this.ReadVolumeDescriptors(extentVds))
                    {
                        return(false);
                    }

                    // Finally, read the file structure.
                    return(this.ReadFileStructure());
                }
            }
            catch (Exception ex)
            {
                if (!(ex is UnauthorizedAccessException || ex is DirectoryNotFoundException || ex is IOException))
                {
                    throw;
                }
            }

            return(false);
        }
Example #3
0
        /// <summary>
        /// Reads the Anchor Volume pointer from the image.
        /// </summary>
        /// <returns>Returns true if the pointer was found.</returns>
        private UdfFileExtent ReadAnchorVolumePointer()
        {
            UdfFileExtent result = null;

            byte[] buffer = new byte[SectorSize];
            this.stream.Seek(-buffer.Length, (int)SeekOrigin.End, IntPtr.Zero);
            if (!this.stream.ReadSafe(buffer, buffer.Length))
            {
                return(result);
            }

            VolumeTag tag = new VolumeTag();

            if (tag.Parse(0, buffer, buffer.Length) &&
                tag.Identifier == (short)VolumeDescriptorType.AnchorVolumePtr)
            {
                result = new UdfFileExtent();
                result.Parse(16, buffer);
            }

            return(result);
        }