Пример #1
0
        /// <summary>
        /// Returns a flat list of all recursed files
        /// </summary>
        public List <KeyValuePair <string, ISOFileNode> > EnumerateAllFilesRecursively()
        {
            fileNodes  = new List <KeyValuePair <string, ISOFileNode> >();
            dirsParsed = new List <ISODirectoryNode>();

            if (Root.Children == null)
            {
                return(fileNodes);
            }

            // get all folders
            var dirs = (from a in Root.Children where a.Value.GetType() == typeof(ISODirectoryNode) select a);

            // iterate through each folder
            foreach (var d in dirs)
            {
                // process all files in this directory (and recursively process files in sub folders
                ISODirectoryNode idn = d.Value as ISODirectoryNode;
                if (dirsParsed.Where(a => a == idn).Count() > 0)
                {
                    continue;
                }

                dirsParsed.Add(idn);
                ProcessDirectoryFiles(idn.Children);
            }

            return(fileNodes.Distinct().ToList());
        }
Пример #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 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;

				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;
		}
Пример #3
0
		/// <summary>
		/// Parse the children based on the data in this directory.
		/// </summary>
		/// <param name="s">The stream to parse from.</param>
		/// <param name="visited">The set of already handled 
		/// files/directories.</param>
		public void Parse(Stream s, Dictionary<long, ISONode> visited)
		{
			// Go to the beginning of the set of directories
			s.Seek(this.Offset * ISOFile.SECTOR_SIZE, SeekOrigin.Begin);

			List<ISONodeRecord> records = new List<ISONodeRecord>();

			// Read the directory entries
			while (s.Position < ((this.Offset * ISOFile.SECTOR_SIZE) + this.Length))
			{
				ISONode node;
				ISONodeRecord record;

				// Read the record
				record = new ISONodeRecord();
				record.Parse(s);


				//zero 24-jun-2013 - improved validity checks
				//theres nothing here!
				if (record.Length == 0)
				{
					break;
				}
				else
				{
					// Check if we already have this node
					if (visited.ContainsKey(record.OffsetOfData))
					{
						// Get the node
						node = visited[record.OffsetOfData];
					}
					else
					{
						// Create the node from the record
						if (record.IsFile())
						{
							node = new ISOFileNode(record);
						}
						else if (record.IsDirectory())
						{
							node = new ISODirectoryNode(record);
						}
						else
						{
							node = new ISONode(record);
						}

						// Keep track that we've now seen the node and are parsing it
						visited.Add(node.Offset, node);
					}

					// Add the node as a child
					this.Children.Add(record.Name, node);
				}
			}

			long currentPosition = s.Position;

			// Iterate over directories...
			foreach (KeyValuePair<string, ISONode> child in this.Children)
			{
				// Parse this node
				if (child.Key != ISONodeRecord.CURRENT_DIRECTORY &&
					child.Key != ISONodeRecord.PARENT_DIRECTORY &&
					child.Value is ISODirectoryNode)
				{
					((ISODirectoryNode)child.Value).Parse(s, visited);
				}
			}

			s.Seek(currentPosition, SeekOrigin.Begin);
		}
Пример #4
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 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);
        }
Пример #5
0
        /// <summary>
        /// Parse the children based on the data in this directory.
        /// </summary>
        /// <param name="s">The stream to parse from.</param>
        /// <param name="visited">The set of already handled
        /// files/directories.</param>
        public void Parse(Stream s, Dictionary <long, ISONode> visited)
        {
            // Go to the beginning of the set of directories
            s.Seek(this.Offset * ISOFile.SECTOR_SIZE, SeekOrigin.Begin);

            List <ISONodeRecord> records = new List <ISONodeRecord>();

            // Read the directory entries
            while (s.Position < ((this.Offset * ISOFile.SECTOR_SIZE) + this.Length))
            {
                ISONode       node;
                ISONodeRecord record;

                // Read the record
                record = new ISONodeRecord();
                if (ISOFile.Format == ISOFile.ISOFormat.CDInteractive)
                {
                    record.ParseCDInteractive(s);
                }
                if (ISOFile.Format == ISOFile.ISOFormat.ISO9660)
                {
                    record.ParseISO9660(s);
                }


                //zero 24-jun-2013 - improved validity checks
                //theres nothing here!
                if (record.Length == 0)
                {
                    break;
                }
                else
                {
                    // Check if we already have this node
                    if (visited.ContainsKey(record.OffsetOfData))
                    {
                        // Get the node
                        node = visited[record.OffsetOfData];
                    }
                    else
                    {
                        // Create the node from the record
                        if (record.IsFile())
                        {
                            node = new ISOFileNode(record);
                        }
                        else if (record.IsDirectory())
                        {
                            node = new ISODirectoryNode(record);
                        }
                        else
                        {
                            node = new ISONode(record);
                        }

                        // Keep track that we've now seen the node and are parsing it
                        visited.Add(node.Offset, node);
                    }

                    // Add the node as a child
                    if (!this.Children.ContainsKey(record.Name))
                    {
                        this.Children.Add(record.Name, node);
                    }
                }
            }

            long currentPosition = s.Position;

            // Iterate over directories...
            foreach (KeyValuePair <string, ISONode> child in this.Children)
            {
                // Parse this node
                if (child.Key != ISONodeRecord.CURRENT_DIRECTORY &&
                    child.Key != ISONodeRecord.PARENT_DIRECTORY &&
                    child.Value is ISODirectoryNode)
                {
                    ((ISODirectoryNode)child.Value).Parse(s, visited);
                }
            }

            s.Seek(currentPosition, SeekOrigin.Begin);
        }