// 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"); } }
public override void Parse(CBinaryReader br) { br.Seek((long)base.Address, SeekOrigin.Begin); br.Endian = EndianType.BigEndian; this.MediaID = br.ReadBytes(4); this.Version = br.ReadUInt32(); this.BaseVersion = br.ReadUInt32(); this.TitleID = br.ReadBytes(4); this.Platform = br.ReadByte(); this.ExecutableType = br.ReadByte(); this.DiscNumber = br.ReadByte(); this.DiscCount = br.ReadByte(); }
public override void Parse(CBinaryReader br) { br.Seek(Address, SeekOrigin.Begin); br.Endian = EndianType.BigEndian; MediaID = br.ReadBytes(4); Version = br.ReadUInt32(); BaseVersion = br.ReadUInt32(); TitleID = br.ReadBytes(4); Platform = br.ReadByte(); ExecutableType = br.ReadByte(); DiscNumber = br.ReadByte(); DiscCount = br.ReadByte(); }
public XPRHeader(CBinaryReader br) { br.Endian = EndianType.LittleEndian; MagicBytes = br.ReadUInt32(); if (MagicBytes == 0x30525058) { FileSize = br.ReadUInt32(); HeaderSize = br.ReadUInt32(); TextureCommon = br.ReadUInt32(); TextureData = br.ReadUInt32(); TextureLock = br.ReadUInt32(); TextureMisc1 = br.ReadByte(); TextureFormat = br.ReadByte(); TextureRes1 = br.ReadByte(); TextureRes2 = br.ReadByte(); IsValid = true; } }
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); } }
public XdbfTable(CBinaryReader b, XdbfHeader header) { b.Seek(30L, SeekOrigin.Begin); for (int i = 0; i < header.NumEntries; i++) { base.Add(new XdbfTableEntry(b)); } while (b.PeekChar() == 0) { b.ReadByte(); } }
/// <summary> /// Read a volume descriptor according to its type /// </summary> /// <param name="stream">The stream to read</param> private VolumeDescriptor ReadVolumeDescriptor(CBinaryReader stream) { try { byte descriptorType = stream.ReadByte(); string id = stream.ReadAsciiString(5); if (id != VolumeDescriptor.VOLUME_ID) { throw new FrameworkException("Error while reading volume descriptors : ISO9660 Volume descriptor was expected"); } switch (descriptorType) { case (byte)VolumeDescriptorType.PRIMARY: return(ReadPrimaryVolumeDescriptor(stream)); case (byte)VolumeDescriptorType.SET_TERMINATOR: return(new SetTerminatorVolumeDescriptor()); case (byte)VolumeDescriptorType.BOOT: case (byte)VolumeDescriptorType.PARTITION: case (byte)VolumeDescriptorType.SUPPLEMENTARY: throw new FrameworkNotSupportedException("Error while reading volume descriptors : Only primary volume descriptor is currently supported"); default: throw new FrameworkException("Error while reading volume descriptors : ISO9660 volume descriptor was expected"); } } catch (FrameworkException ex) { throw ex; } catch (Exception) { throw new FrameworkException("Error while reading VolumeDescriptor : Invalid ISO9660 volume descriptor"); } }
/// <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); }
/// <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); }
/// <summary> /// Read a sector's data, including sub header /// </summary> /// <param name="mode">Sector's mode</param> /// <param name="subHeader">Sub header container to write sub header to</param> public byte[] ReadSector(SectorMode mode, out XaSubHeader subHeader) { try { byte[] buffer; subHeader = new XaSubHeader(); int dataSize = GetSectorDataSize(mode); buffer = new byte[dataSize]; if (mode != SectorMode.RAW) { _stream.Position += (SYNC_SIZE + HEADER_SIZE); } if (mode == SectorMode.XA_FORM1 || mode == SectorMode.XA_FORM2) { subHeader.File = _stream.ReadByte(); subHeader.Channel = _stream.ReadByte(); subHeader.SubMode = _stream.ReadByte(); subHeader.DataType = _stream.ReadByte(); _stream.Position += SUBHEADER_SIZE / 2; } _stream.Read(buffer, 0, dataSize); if (mode == SectorMode.MODE1 || mode == SectorMode.XA_FORM1) { _stream.Position += EDC_SIZE; } if (mode == SectorMode.MODE1) { _stream.Position += INTERMEDIATE_SIZE; } if (mode == SectorMode.MODE1 || mode == SectorMode.XA_FORM1) { _stream.Position += ECC_SIZE; } if (mode == SectorMode.XA_FORM2) { _stream.Position += EDC_SIZE; } return(buffer); } catch (FrameworkException ex) { throw ex; } catch (EndOfStreamException) { throw new FrameworkException("Errow while reading sector : end of file occured"); } catch (Exception) { throw new FrameworkException("Errow while reading sector : unable to read sector"); } }