Пример #1
0
        PathTable ReadPathTable(BasicVolumeDescriptor descriptor, Endian endian)
        {
            Assert.IsNotNull(descriptor, nameof(descriptor));
            Assert.IsTrue(endian == Endian.BigEndian || endian == Endian.LittleEndian, "Endian must be set to either little or big.");

            if (endian == Endian.BigEndian)
            {
                Reader.Position = descriptor.TypeMPathTableLocation * DefaultSectorSize;
            }
            else
            {
                Reader.Position = descriptor.TypeLPathTableLocation * DefaultSectorSize;
            }

            var buffer = Reader.ReadBytes((Int32)descriptor.PathTableSize);

            var pathtable = new PathTable(endian);

            for (var offset = 0; offset < buffer.Length;)
            {
                var namelength      = buffer[offset + 0];
                var extendedsectors = buffer[offset + 1];
                var sector          = BinaryIO.ReadUInt32FromBuffer(buffer, offset + 2, endian);
                var parentindex     = BinaryIO.ReadUInt16FromBuffer(buffer, offset + 6, endian);
                var name            = Encodings.ASCII.GetString(buffer, offset + 8, namelength).Trim(' ');

                pathtable.Items.Add(new PathTableItem(name, sector, parentindex));

                offset += MathUtil.RoundUp(8 + namelength, 2);
            }

            return(pathtable);
        }
Пример #2
0
        /// <summary>
        /// Reads a <see cref="DirectoryRecord" from a buffer./>
        /// </summary>
        /// <param name="buffer">The buffer to read from.</param>
        /// <param name="offset">The offset in the buffer to read from.</param>
        /// <returns></returns>
        DirectoryRecord ReadDirectoryRecord(Byte[] buffer, Int32 offset)
        {
            Assert.IsNotNull(buffer, nameof(buffer));

            var length = (Int32)buffer[offset];
            var record = new DirectoryRecord();

            record.ExtendedAttributeRecordLength = buffer[offset + 1];
            record.SectorNumber         = BinaryIO.ReadUInt32FromBuffer(buffer, offset + 2);
            record.DataLength           = BinaryIO.ReadUInt32FromBuffer(buffer, offset + 10);
            record.RecordingDateAndTime = ReadDirectoryRecordDateTime(buffer, offset + 18);
            record.Flags                = (DirectoryRecordFlags)buffer[offset + 25];
            record.FileUnitSize         = buffer[offset + 26];
            record.InterleaveGapSize    = buffer[offset + 27];
            record.VolumeSequenceNumber = BinaryIO.ReadUInt16FromBuffer(buffer, offset + 28);

            var textlength = buffer[offset + 32];

            record.FileIdentifier = Encodings.ASCII.GetString(buffer, offset + 33, textlength).Trim(' ');

            var num2 = ((textlength & 1) == 0) ? 1 : 0;
            var num3 = textlength + num2 + 33;
            var num4 = length - num3;

            if (num4 > 0)
            {
                record.SystemUseData = new Byte[num4];
                Array.Copy(buffer, offset + num3, record.SystemUseData, 0, num4);
            }

            return(record);
        }
        /// <summary>
        /// Reads the <see cref="VolumeDescriptor"/> at the current position of the image file.
        /// </summary>
        /// <returns>The <see cref="VolumeDescriptor"/> located at the current file position.</returns>
        VolumeDescriptor ReadVolumeDescriptor()
        {
            var buffer = Reader.ReadBytes(DefaultSectorSize);
            var type   = (VolumeDescriptorType)buffer[0];

            if (type == VolumeDescriptorType.Primary)
            {
                var descriptor = new BasicVolumeDescriptor();
                descriptor.VolumeDescriptorType    = type;
                descriptor.StandardIdentifier      = Encodings.ASCII.GetString(buffer, 1, 5);
                descriptor.VolumeDescriptorVersion = buffer[6];

                descriptor.SystemIdentifier               = Encodings.ASCII.GetString(buffer, 8, 32).Trim(' ');
                descriptor.VolumeIdentifier               = Encodings.ASCII.GetString(buffer, 40, 32).Trim(' ');
                descriptor.VolumeSpaceSize                = BinaryIO.ReadUInt32FromBuffer(buffer, 80, Endian.LittleEndian);
                descriptor.VolumeSetSize                  = BinaryIO.ReadUInt16FromBuffer(buffer, 120, Endian.LittleEndian);
                descriptor.VolumeSequenceNumber           = BinaryIO.ReadUInt16FromBuffer(buffer, 124, Endian.LittleEndian);
                descriptor.LogicalBlockSize               = BinaryIO.ReadUInt16FromBuffer(buffer, 128, Endian.LittleEndian);
                descriptor.PathTableSize                  = BinaryIO.ReadUInt32FromBuffer(buffer, 132, Endian.LittleEndian);
                descriptor.TypeLPathTableLocation         = BinaryIO.ReadUInt32FromBuffer(buffer, 140, Endian.LittleEndian);
                descriptor.OptionalTypeLPathTableLocation = BinaryIO.ReadUInt32FromBuffer(buffer, 144, Endian.LittleEndian);
                descriptor.TypeMPathTableLocation         = BinaryIO.ReadUInt32FromBuffer(buffer, 148, Endian.BigEndian);
                descriptor.OptionalTypeMPathTableLocation = BinaryIO.ReadUInt32FromBuffer(buffer, 152, Endian.BigEndian);
                descriptor.RootDirectory                  = ReadDirectoryRecord(buffer, 156);
                descriptor.VolumeSetIdentifier            = Encodings.ASCII.GetString(buffer, 190, 128).Trim(' ');
                descriptor.PublisherIdentifier            = Encodings.ASCII.GetString(buffer, 318, 128).Trim(' ');
                descriptor.DataPreparerIdentifier         = Encodings.ASCII.GetString(buffer, 446, 128).Trim(' ');
                descriptor.ApplicationIdentifier          = Encodings.ASCII.GetString(buffer, 574, 128).Trim(' ');
                descriptor.CopyrightFileIdentifier        = Encodings.ASCII.GetString(buffer, 702, 37).Trim(' ');
                descriptor.AbstractFileIdentifier         = Encodings.ASCII.GetString(buffer, 739, 37).Trim(' ');
                descriptor.BibliographicFileIdentifier    = Encodings.ASCII.GetString(buffer, 776, 37).Trim(' ');
                descriptor.CreationDateAndTime            = ReadVolumeDescriptorDateTime(buffer, 813);
                descriptor.ModificationDateAndTime        = ReadVolumeDescriptorDateTime(buffer, 830);
                descriptor.ExpirationDateAndTime          = ReadVolumeDescriptorDateTime(buffer, 847);
                descriptor.EffectiveDateAndTime           = ReadVolumeDescriptorDateTime(buffer, 864);
                descriptor.FileStructureVersion           = buffer[881];

                return(descriptor);
            }

            if (type == VolumeDescriptorType.SetTerminator)
            {
                var descriptor = new SetTerminatorVolumeDescriptor();
                descriptor.VolumeDescriptorType    = type;
                descriptor.StandardIdentifier      = Encodings.ASCII.GetString(buffer, 1, 5);
                descriptor.VolumeDescriptorVersion = buffer[6];

                return(descriptor);
            }

            throw new Exception();
        }