Пример #1
0
 public XdbfHeader(CBinaryReader b)
 {
     b.Seek(0L, SeekOrigin.Begin);
     MagicBytes     = b.ReadBytes(4);
     Version        = b.ReadUInt16();
     Reserved       = b.ReadUInt16();
     NumEntries     = b.ReadUInt32();
     NumEntriesCopy = b.ReadUInt32();
     UnknownA       = b.ReadUInt32();
     UnknownB       = b.ReadUInt32();
 }
Пример #2
0
        // Methods

        /// <summary>
        /// Read GZip meta data from stream
        /// </summary>
        /// <param name="stream">The stream to read</param>
        /// <param name="size">The size of the GZip file</param>
        internal void Read(Stream stream, uint size)
        {
            try
            {
                var reader = new CBinaryReader(stream);

                if (reader.ReadUInt16() != SIGNATURE)
                {
                    throw new FrameworkException("Error while parsing gzip : gzip signature not found");
                }

                _method = (GZipCompressionMethod)reader.ReadByte();
                _flags  = reader.ReadByte();
                _date   = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(reader.ReadUInt32());
                _xfl    = reader.ReadByte();
                _os     = reader.ReadByte();

                if (HasExtra)
                {
                    int extraSize = reader.ReadUInt16();
                    _extra = reader.ReadAsciiString(extraSize);
                    reader.Position++;
                }

                if (HasName)
                {
                    _name = reader.ReadAsciiString();
                }

                if (HasComment)
                {
                    _comment = reader.ReadAsciiString();
                }

                if (HasCrc)
                {
                    _crc = reader.ReadUInt16();
                }

                _dataOffset     = (uint)reader.Position;
                _dataSize       = size - _dataOffset - FOOTER_SIZE;
                reader.Position = size - FOOTER_SIZE;
                _crc32          = reader.ReadUInt32();
                _dataRealSize   = reader.ReadUInt32();
            }
            catch (FrameworkException ex)
            {
                throw ex;
            }
            catch (Exception)
            {
                throw new FrameworkException("Error while parsing gzip data : unable to read meta data");
            }
        }
Пример #3
0
 public XdbfTableEntry(CBinaryReader b)
 {
     Identifier = b.ReadUInt32();
     Offset     = b.ReadUInt32();
     Size       = b.ReadUInt32();
     Type       = b.ReadUInt16();
     Padding    = b.ReadUInt32();
 }
Пример #4
0
 public XdbfTableEntry(CBinaryReader b)
 {
     this.Identifier = b.ReadUInt32();
     this.Offset     = b.ReadUInt32();
     this.Size       = b.ReadUInt32();
     this.Type       = b.ReadUInt16();
     this.Padding    = b.ReadUInt32();
 }
Пример #5
0
        public GDFDirTable(CBinaryReader File, GDFVolumeDescriptor Vol, uint Sector, uint Size)
        {
            this.Sector = Sector;
            this.Size   = Size;
            File.Seek((long)((Sector * Vol.SectorSize) + Vol.RootOffset), SeekOrigin.Begin);
            byte[]        buffer = File.ReadBytes((int)Size);
            MemoryStream  s      = new MemoryStream(buffer);
            CBinaryReader reader = new CBinaryReader(EndianType.LittleEndian, s);

            try
            {
                while (s.Position < Size)
                {
                    GDFDirEntry item = new GDFDirEntry {
                        SubTreeL = reader.ReadUInt16(),
                        SubTreeR = reader.ReadUInt16()
                    };
                    if ((item.SubTreeL != 0xffff) && (item.SubTreeR != 0xffff))
                    {
                        item.Sector     = reader.ReadUInt32();
                        item.Size       = reader.ReadUInt32();
                        item.Attributes = (GDFDirEntryAttrib)reader.ReadByte();
                        item.NameLength = reader.ReadByte();
                        item.Name       = Encoding.ASCII.GetString(buffer, (int)s.Position, item.NameLength);
                        s.Seek((long)item.NameLength, SeekOrigin.Current);
                        long num1 = s.Position % 4L;
                        if ((s.Position % 4L) != 0L)
                        {
                            s.Seek(4L - (s.Position % 4L), SeekOrigin.Current);
                        }
                        base.Add(item);
                    }
                }
            }
            catch (EndOfStreamException)
            {
                Console.WriteLine("EndOfStreamException while trying to read directory at sector {0} ({1} bytes)", Sector.ToString(), Size.ToString());
            }
            catch (Exception exception)
            {
                Console.WriteLine("Unhandled Exception {0} for directory at sector {1} -> {2}", exception.InnerException, Sector.ToString(), exception.Message);
            }
        }
Пример #6
0
        /// <summary>
        /// Read a directory entry
        /// </summary>
        /// <param name="stream">The stream to read</param>
        private DirectoryEntry ReadDirectoryEntry(CBinaryReader stream)
        {
            DirectoryEntry entry = null;

            try
            {
                long position = stream.Position;

                entry        = new DirectoryEntry();
                entry.Length = stream.ReadByte();
                entry.ExtendedAttributeRecordlength = stream.ReadByte();

                entry.ExtentLba = stream.ReadUInt32();
                if (entry.ExtentLba != stream.ReadUInt32BE())
                {
                    throw new FrameworkException("Error while reading DirectoryEntry : ExtentLBA is not valid");
                }

                entry.ExtentSize = stream.ReadUInt32();
                if (entry.ExtentSize != stream.ReadUInt32BE())
                {
                    throw new FrameworkException("Error while reading DirectoryEntry : ExtentSize is not valid");
                }

                byte[] buffer = stream.ReadBytes(7);
                entry.Date = new DateTime(buffer[0] + 1900, buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], DateTimeKind.Utc);

                entry.Flags        = stream.ReadByte();
                entry.FileUnitSize = stream.ReadByte();
                entry.Interleave   = stream.ReadByte();

                entry.VolumeSequenceNumber = stream.ReadUInt16();
                if (entry.VolumeSequenceNumber != stream.ReadUInt16BE())
                {
                    throw new FrameworkException("Error while reading DirectoryEntry : VolumeSequenceNumber is not valid");
                }

                byte nameLength = stream.ReadByte();
                entry.Name = _regFileName.Match(stream.ReadAsciiString(nameLength, false)).Groups[1].Value;

                if (nameLength % 2 == 0)
                {
                    stream.Position += 1;
                }

                if (_isXa && (stream.Position != position + entry.Length))
                {
                    entry.XaEntry            = new XaEntry();
                    entry.XaEntry.GroupId    = stream.ReadUInt16BE();
                    entry.XaEntry.UserId     = stream.ReadUInt16BE();
                    entry.XaEntry.Attributes = stream.ReadUInt16BE();

                    entry.XaEntry.Signature = stream.ReadAsciiString(2);
                    if (entry.XaEntry.Signature != XaEntry.XA_SIGNATURE)
                    {
                        throw new FrameworkException("Error while reading DirectoryEntry : XaEntry is not valid");
                    }

                    entry.XaEntry.FileNumber = stream.ReadByte();
                    entry.XaEntry.Unused     = stream.ReadBytes(5);
                }
            }
            catch (FrameworkException ex)
            {
                throw ex;
            }
            catch (Exception)
            {
                throw new FrameworkException("Error while reading DirectoryEntry : DirectoryEntry is not valid");
            }

            return(entry);
        }
Пример #7
0
        /// <summary>
        /// Read a primary volume descriptor
        /// </summary>
        /// <param name="stream">The stream to read</param>
        private PrimaryVolumeDescriptor ReadPrimaryVolumeDescriptor(CBinaryReader stream)
        {
            PrimaryVolumeDescriptor descriptor;

            try
            {
                byte version = stream.ReadByte();

                descriptor = new PrimaryVolumeDescriptor(version);

                descriptor.Unused1  = stream.ReadByte();
                descriptor.SystemId = stream.ReadAsciiString(32);
                descriptor.VolumeId = stream.ReadAsciiString(32);
                descriptor.Unused2  = stream.ReadBytes(8);

                descriptor.VolumeSpaceSize = stream.ReadUInt32();
                if (descriptor.VolumeSpaceSize != stream.ReadUInt32BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : VolumeSpaceSize is not valid");
                }

                descriptor.Unused3 = stream.ReadBytes(32);

                descriptor.VolumeSetSize = stream.ReadUInt16();
                if (descriptor.VolumeSetSize != stream.ReadUInt16BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : VolumeSetSize is not valid");
                }

                descriptor.VolumeSequenceNumber = stream.ReadUInt16();
                if (descriptor.VolumeSequenceNumber != stream.ReadUInt16BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : VolumeSequenceNumber  is not valid");
                }

                descriptor.LogicalBlockSize = stream.ReadUInt16();
                if (descriptor.LogicalBlockSize != stream.ReadUInt16BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : LogicalBlockSize  is not valid");
                }

                descriptor.PathTableSize = stream.ReadUInt32();
                if (descriptor.PathTableSize != stream.ReadUInt32BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : PathTableSize  is not valid");
                }

                descriptor.TypeLPathTableLBA    = stream.ReadUInt32();
                descriptor.OptTypeLPathTableLBA = stream.ReadUInt32();
                descriptor.TypeMPathTableLBA    = stream.ReadUInt32BE();
                descriptor.OptTypeMPathTableLBA = stream.ReadUInt32BE();

                if (descriptor.OptTypeLPathTableLBA != 0 || descriptor.OptTypeMPathTableLBA != 0)
                {
                    _hasOptionalPathTable = true;
                }

                descriptor.RootDirectoryEntry = ReadDirectoryEntry(stream);

                // TODO : cas des fichiers
                descriptor.VolumeSetId         = stream.ReadAsciiString(128);
                descriptor.PublisherId         = stream.ReadAsciiString(128);
                descriptor.PreparerId          = stream.ReadAsciiString(128);
                descriptor.ApplicationId       = stream.ReadAsciiString(128);
                descriptor.CopyrightFileId     = stream.ReadAsciiString(38);
                descriptor.AbstractFileId      = stream.ReadAsciiString(36);
                descriptor.BibliographicFileId = stream.ReadAsciiString(37);
                //

                descriptor.CreationDate         = VolumeDescriptor.ToDateTime(stream.ReadBytes(17));
                descriptor.ModificationDate     = VolumeDescriptor.ToDateTime(stream.ReadBytes(17));
                descriptor.ExpirationDate       = VolumeDescriptor.ToDateTime(stream.ReadBytes(17));
                descriptor.EffectiveDate        = VolumeDescriptor.ToDateTime(stream.ReadBytes(17));
                descriptor.FileStructureVersion = stream.ReadByte();
                descriptor.Unused4         = stream.ReadByte();
                descriptor.ApplicationData = stream.ReadBytes(512);
                descriptor.Reserved        = stream.ReadBytes(653);

                // if the disk is CDROM/XA (and then contains an XaEntry in his DirectoryEntries),
                // "CD-XA001" can be read at offset 0x400 of the pvd (actually offset 0x8D of ApplicationData field)
                if (CBuffer.ReadAsciiString(descriptor.ApplicationData, 0x8D, 8) == VolumeDescriptor.VOLUME_XA)
                {
                    _isXa = true;
                }
            }
            catch (FrameworkException ex)
            {
                throw ex;
            }
            catch (Exception)
            {
                throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : PrimaryVolumeDescriptor is not valid");
            }

            return(descriptor);
        }