Example #1
0
        /// <summary>
        /// Parse the given stream to populate the iso information
        /// </summary>
        /// <param name="s">The stream which we are using to parse the image.
        /// Should already be located at the start of the image.</param>
        public void Parse(Stream s)
        {
            long startPosition = s.Position;

            byte[] buffer = new byte[ISOFile.SECTOR_SIZE];

            // Seek through the first volume descriptor
            s.Seek(startPosition + (SECTOR_SIZE * 16), SeekOrigin.Begin);

            // Read one of more volume descriptors
            do
            {
                ISOVolumeDescriptor desc = new ISOVolumeDescriptor();
                desc.Parse(s);
                if (desc.IsTerminator())
                {
                    break;
                }
                else
                {
                    this.VolumeDescriptors.Add(desc);
                }
            } while(true);

            // Check to make sure we only read one volume descriptor
            // Finding more could be an error with the disk.
            if (this.VolumeDescriptors.Count != 1)
            {
                Console.WriteLine("Strange ISO format...");
                return;
            }

            // Visit all the directories and get the offset of each directory/file

            // We need to keep track of the directories and files we have visited in case there are loops.
            Dictionary <long, ISONode> visitedNodes = new Dictionary <long, ISONode>();

            // Create (and visit) the root node
            this.Root = new ISODirectoryNode(this.VolumeDescriptors[0].RootDirectoryRecord);
            visitedNodes.Add(this.Root.Offset, this.Root);
            this.Root.Parse(s, visitedNodes);
        }
Example #2
0
        /// <summary>
        /// Parse the given stream to populate the iso information
        /// </summary>
        /// <param name="s">The stream which we are using to parse the image. 
        /// Should already be located at the start of the image.</param>
        public void Parse(Stream s)
        {
            long startPosition = s.Position;
            byte[] buffer = new byte[ISOFile.SECTOR_SIZE];

            // Seek through the first volume descriptor
            s.Seek(startPosition+(SECTOR_SIZE * 16), SeekOrigin.Begin);

            // Read one of more volume descriptors
            do {
                ISOVolumeDescriptor desc = new ISOVolumeDescriptor();
                desc.Parse(s);
                if (desc.IsTerminator()) {
                    break;
                }
                else {
                    this.VolumeDescriptors.Add(desc);
                }
            } while(true);

            // Check to make sure we only read one volume descriptor
            // Finding more could be an error with the disk.
            if (this.VolumeDescriptors.Count != 1) {
                Console.WriteLine("Strange ISO format...");
                return;
            }

            // Visit all the directories and get the offset of each directory/file

            // We need to keep track of the directories and files we have visited in case there are loops.
            Dictionary<long, ISONode> visitedNodes = new Dictionary<long,ISONode>();

            // Create (and visit) the root node
            this.Root = new ISODirectoryNode(this.VolumeDescriptors[0].RootDirectoryRecord);
            visitedNodes.Add(this.Root.Offset, this.Root);
            this.Root.Parse(s, visitedNodes);
        }
        /// <summary>
        /// Parse the given stream to populate the iso information
        /// </summary>
        /// <param name="s">The stream which we are using to parse the image.
        /// Should already be located at the start of the image.</param>
        public bool Parse(Stream s, int startSector = 16)
        {
            this.VolumeDescriptors = new List <ISOVolumeDescriptor>();
            Root = null;

            long startPosition = s.Position;

            byte[] buffer = new byte[ISOFile.SECTOR_SIZE];

            // Seek through the first volume descriptor
            s.Seek(startPosition + (SECTOR_SIZE * startSector), SeekOrigin.Begin);

            // Read one of more volume descriptors
            do
            {
                //zero 24-jun-2013 - improved validity checks

                ISOVolumeDescriptor desc = new ISOVolumeDescriptor();
                bool isValid             = desc.Parse(s);
                if (!isValid)
                {
                    return(false);
                }

                this.CDFSType = Format;

                if (desc.IsTerminator())
                {
                    break;
                }
                else if (desc.Type < 4)
                {
                    this.VolumeDescriptors.Add(desc);
                }
                else
                {
                    //found a volume descriptor of incorrect type.. maybe this isnt a cdfs
                    //supposedly these exist.. wait for one to show up
                    return(false);
                }
            } while (true);

            //zero 24-jun-2013 - well, my very first test iso had 2 volume descriptors.
            // Check to make sure we only read one volume descriptor
            // Finding more could be an error with the disk.
            //if (this.VolumeDescriptors.Count != 1) {
            //    Console.WriteLine("Strange ISO format...");
            //    return;
            //}


            //zero 24-jun-2013 - if theres no volume descriptors, we're gonna call this not a cdfs
            if (VolumeDescriptors.Count == 0)
            {
                return(false);
            }

            // Visit all the directories and get the offset of each directory/file

            // We need to keep track of the directories and files we have visited in case there are loops.
            Dictionary <long, ISONode> visitedNodes = new Dictionary <long, ISONode>();

            // Create (and visit) the root node
            this.Root = new ISODirectoryNode(this.VolumeDescriptors[0].RootDirectoryRecord);

            visitedNodes.Add(this.Root.Offset, this.Root);
            this.Root.Parse(s, visitedNodes);

            return(true);
        }