public Xdbf(byte[] Data) { this.br = new CBinaryReader(EndianType.BigEndian, new MemoryStream(Data)); this.header = new XdbfHeader(this.br); this.entries = new XdbfTable(this.br, this.header); this.dataOffset = (uint)this.br.BaseStream.Position; }
/// <summary> /// Fetch all directory entries to build the internal index /// </summary> public void BuildIndex() { if (_indexBuilt) { return; } if (!_descriptorsRead) { throw new FrameworkException("Error : You must read the descriptors first"); } try { long rootLba = _primaryVolumeDescriptor.RootDirectoryEntry.ExtentLba; var stream = new CBinaryReader(ReadSector(rootLba, _defaultSectorMode)); var rootEntry = ReadDirectoryEntry(stream); _index = new DataTrackIndex(rootEntry); AddDirectoryToIndex(_index.Root); _indexBuilt = true; } catch (FrameworkException ex) { throw ex; } catch (Exception) { throw new FrameworkException("Error while building the index : unable to read data to build the internal index cache"); } }
// Constructors /// <summary> /// DataTrackReader /// </summary> /// <param name="stream">The stream of iso</param> /// <param name="trackNumber">The track number</param> /// <param name="system">File system used for this data track</param> /// <param name="mode">The sector mode of the track</param> /// <param name="readDescriptors">Read descriptors immediately</param> /// <param name="buildIndex">Build the index cache immediately</param> internal DataTrackReader(CBinaryReader stream, int trackNumber, DiskFileSystem system, DataTrackMode mode, bool readDescriptors = true, bool buildIndex = true) : base((FileStream)stream.BaseStream, trackNumber, system, mode) { _stream = stream; _descriptorsRead = false; _indexBuilt = false; _entriesOrder = DataTrackEntriesOrder.DEFAULT; try { if (readDescriptors) { ReadVolumeDescriptors(); } if (buildIndex) { BuildIndex(); } SeekSector(0); } catch (FrameworkException ex) { throw ex; } catch (Exception) { throw new FrameworkException("Error while reading data track : unable to read the data track"); } }
// Constructors /// <summary> /// AudioTrackReader /// </summary> /// <param name="trackNumber">The track number</param> internal AudioTrackReader(CBinaryReader stream, int trackNumber) : base((FileStream)stream.BaseStream, trackNumber) { _stream = stream; SeekSector(0); }
public Xdbf(byte[] Data) { br = new CBinaryReader(EndianType.BigEndian, new MemoryStream(Data)); header = new XdbfHeader(br); entries = new XdbfTable(br, header); dataOffset = (uint)br.BaseStream.Position; }
public XdbfTableEntry(CBinaryReader b) { Identifier = b.ReadUInt32(); Offset = b.ReadUInt32(); Size = b.ReadUInt32(); Type = b.ReadUInt16(); Padding = b.ReadUInt32(); }
public XdbfTableEntry(CBinaryReader b) { this.Identifier = b.ReadUInt32(); this.Offset = b.ReadUInt32(); this.Size = b.ReadUInt32(); this.Type = b.ReadUInt16(); this.Padding = b.ReadUInt32(); }
private void readImageData(CBinaryReader br) { br.Seek((long)this.Header.HeaderSize, SeekOrigin.Begin); int count = (int)(this.Header.FileSize - this.Header.HeaderSize); this.Image = new byte[count]; this.Image = br.ReadBytes(count); }
private void init(CBinaryReader br) { br.Seek(0L, SeekOrigin.Begin); this.Header = new XPRHeader(br); if (this.IsValid) { this.readImageData(br); } }
public void Read(CBinaryReader br, uint BaseAddress) { br.Seek((long)(this.Header.SectionNameAddress - BaseAddress), SeekOrigin.Begin); while (br.PeekChar() != 0) { this.Name = this.Name + br.ReadChar(); } br.Seek((long)this.Header.RawAddress, SeekOrigin.Begin); this.Data = br.ReadBytes((int)this.Header.RawSize); }
public void Read(CBinaryReader br, uint BaseAddress) { br.Seek(Header.SectionNameAddress - BaseAddress, SeekOrigin.Begin); while (br.PeekChar() != 0) { Name = Name + br.ReadChar(); } br.Seek(Header.RawAddress, SeekOrigin.Begin); Data = br.ReadBytes((int)Header.RawSize); }
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(); }
// 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 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(); } }
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 XexInfo(byte[] Xex) { ms = new MemoryStream(Xex); br = new CBinaryReader(EndianType.BigEndian, ms); Header = new XexHeader(br); foreach (XexInfoField field in Header.Values) { if (!field.Flags) { field.Parse(br); } } }
public GDF(FileStream File) { this.file = File; this.fr = new CBinaryReader(EndianType.LittleEndian, this.file); this.readVolume(); try { this.rootDir = new GDFDirTable(this.fr, this.volDesc, this.volDesc.RootDirSector, this.volDesc.RootDirSize); } catch (Exception exception) { this.Exceptions.Add(exception); } }
/// <summary> /// Read the disk descriptors /// </summary> public void ReadVolumeDescriptors() { if (_descriptorsRead) { return; } try { VolumeDescriptor descriptor; bool endOfList = false; bool hasPrimaryDescriptor = false; SeekSector(16); do { using (var stream = new CBinaryReader(ReadSector(_defaultSectorMode))) { descriptor = ReadVolumeDescriptor(stream); } switch (descriptor.Type) { case VolumeDescriptorType.PRIMARY: _primaryVolumeDescriptor = (PrimaryVolumeDescriptor)descriptor; hasPrimaryDescriptor = true; break; case VolumeDescriptorType.SET_TERMINATOR: endOfList = true; break; } } while (!endOfList); _descriptorsRead = true; if (!hasPrimaryDescriptor) { throw new FrameworkException("Error while reading volume descriptors : no primary descriptor found"); } } catch (FrameworkException ex) { throw ex; } catch (Exception) { throw new FrameworkException("Error while reading volume descriptors : Invalid list of descriptors"); } }
public GDF(FileStream File) { file = File; fr = new CBinaryReader(EndianType.LittleEndian, file); readVolume(); try { rootDir = new GDFDirTable(fr, volDesc, volDesc.RootDirSector, volDesc.RootDirSize); } catch (Exception exception) { Exceptions.Add(exception); } }
public XexInfo(byte[] Xex) { this.data = Xex; this.ms = new MemoryStream(this.data); this.br = new CBinaryReader(EndianType.BigEndian, this.ms); this.Header = new XexHeader(this.br); foreach (XexInfoField field in this.Header.Values) { if (!field.Flags) { field.Parse(this.br); } } }
/// <summary> /// Fetch a directory to build the internal index (recursive) /// </summary> private void AddDirectoryToIndex(DataTrackIndexEntry indexDirectoryEntry) { DirectoryEntry entry; DataTrackIndexEntry indexEntry; long lba = indexDirectoryEntry.DirectoryEntry.ExtentLba; long size = indexDirectoryEntry.DirectoryEntry.ExtentSize; int sectorsCount = (int)(size / GetSectorDataSize(_defaultSectorMode)); var stream = new CBinaryReader(ReadSectors(lba, sectorsCount, _defaultSectorMode)); // First directory entry of a directory entry is the directory itself, so let's skip it ReadDirectoryEntry(stream); // Second directory entry is the parent directory entry. // As we parse the data from root to children, it has already been handled, so let's skip it too ReadDirectoryEntry(stream); while (stream.Position < size) { short b = stream.TestByte(); if (b == 0) { // DirectoryEntry cannot be "splitted" on two sectors int dataSize = GetSectorDataSize(_defaultSectorMode); stream.Position = (((stream.Position / dataSize) + 1) * dataSize); b = stream.TestByte(); } if (b <= 0) { break; } else { entry = ReadDirectoryEntry(stream); indexEntry = new DataTrackIndexEntry(indexDirectoryEntry, entry); _index.AddToIndex(indexEntry); if (indexEntry.IsDirectory) { AddDirectoryToIndex(indexEntry); } } } stream.CloseAndDispose(); }
public XbeSectionHeader(CBinaryReader bw) { this.SectionDigest = new byte[20]; bw.Endian = EndianType.LittleEndian; this.Flags = (XbeSectionFlags)bw.ReadUInt32(); this.VirtualAddress = bw.ReadUInt32(); this.VirtualSize = bw.ReadUInt32(); this.RawAddress = bw.ReadUInt32(); this.RawSize = bw.ReadUInt32(); this.SectionNameAddress = bw.ReadUInt32(); this.SectionNameRefCount = bw.ReadUInt32(); this.HeadSharedPageRefCountAddress = bw.ReadUInt32(); this.TailSharedPageRefCountAddress = bw.ReadUInt32(); this.SectionDigest = bw.ReadBytes(20); }
public XbeCertifcate(CBinaryReader br) { this.Size = br.ReadUInt32(); this.TimeData = br.ReadBytes(4); this.titleID = br.ReadUInt32(); this.titleName = br.ReadBytes(80); this.AltTitleIDs = br.ReadBytes(0x40); this.AllowedMedia = (XbeAllowedMedia)br.ReadUInt32(); this.GameRegion = (XbeGameRegion)br.ReadUInt32(); this.GameRatings = br.ReadUInt32(); this.DiskNumber = br.ReadUInt32(); this.Version = br.ReadUInt32(); this.LanKey = br.ReadBytes(0x10); this.SignatureKey = br.ReadBytes(0x10); this.AltSignatureKeys = br.ReadBytes(0x100); }
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 XbeHeader(CBinaryReader br) { try { if (br.ReadUInt32() == 0x48454258) { DigitalSignature = br.ReadBytes(0x100); BaseAddress = br.ReadUInt32(); SizeOfHeaders = br.ReadUInt32(); SizeOfImage = br.ReadUInt32(); SizeOfImageHeader = br.ReadUInt32(); TimeDate = br.ReadBytes(4); CertificateAddress = br.ReadUInt32(); NumberOfSections = br.ReadUInt32(); SectionHeadersAddress = br.ReadUInt32(); InitialisationFlags = (XbeInitFlags)br.ReadUInt32(); EntryPoint = br.ReadUInt32(); TLSAddress = br.ReadUInt32(); PEStackCommit = br.ReadUInt32(); PEHeapReserve = br.ReadUInt32(); PEHeapCommit = br.ReadUInt32(); PEBaseAddress = br.ReadUInt32(); PESizeOfImage = br.ReadUInt32(); PEChecksum = br.ReadUInt32(); PETimeDate = br.ReadBytes(4); DebugPathnameAddress = br.ReadUInt32(); DebugFilenameAddress = br.ReadUInt32(); DebugUnicodeFilenameAddress = br.ReadUInt32(); KernelImageThunkAddress = br.ReadUInt32(); NonKernelImportDirectoryAddress = br.ReadUInt32(); NumberOfLibraryVersions = br.ReadUInt32(); LibraryVersionsAddress = br.ReadUInt32(); KernelLibraryVersionAddress = br.ReadUInt32(); XAPILibraryVersionAddress = br.ReadUInt32(); LogoBitmapAddress = br.ReadUInt32(); LogoBitmapSize = br.ReadUInt32(); IsValid = true; } } catch (Exception ex) { Console.WriteLine(ex); } }
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 XbeHeader(CBinaryReader br) { try { if (br.ReadUInt32() == 0x48454258) { this.DigitalSignature = br.ReadBytes(0x100); this.BaseAddress = br.ReadUInt32(); this.SizeOfHeaders = br.ReadUInt32(); this.SizeOfImage = br.ReadUInt32(); this.SizeOfImageHeader = br.ReadUInt32(); this.TimeDate = br.ReadBytes(4); this.CertificateAddress = br.ReadUInt32(); this.NumberOfSections = br.ReadUInt32(); this.SectionHeadersAddress = br.ReadUInt32(); this.InitialisationFlags = (XbeInitFlags)br.ReadUInt32(); this.EntryPoint = br.ReadUInt32(); this.TLSAddress = br.ReadUInt32(); this.PEStackCommit = br.ReadUInt32(); this.PEHeapReserve = br.ReadUInt32(); this.PEHeapCommit = br.ReadUInt32(); this.PEBaseAddress = br.ReadUInt32(); this.PESizeOfImage = br.ReadUInt32(); this.PEChecksum = br.ReadUInt32(); this.PETimeDate = br.ReadBytes(4); this.DebugPathnameAddress = br.ReadUInt32(); this.DebugFilenameAddress = br.ReadUInt32(); this.DebugUnicodeFilenameAddress = br.ReadUInt32(); this.KernelImageThunkAddress = br.ReadUInt32(); this.NonKernelImportDirectoryAddress = br.ReadUInt32(); this.NumberOfLibraryVersions = br.ReadUInt32(); this.LibraryVersionsAddress = br.ReadUInt32(); this.KernelLibraryVersionAddress = br.ReadUInt32(); this.XAPILibraryVersionAddress = br.ReadUInt32(); this.LogoBitmapAddress = br.ReadUInt32(); this.LogoBitmapSize = br.ReadUInt32(); this.IsValid = true; } } catch (Exception) { } }
public XbeInfo(byte[] Xbe) { br = new CBinaryReader(EndianType.LittleEndian, new MemoryStream(Xbe)); Header = new XbeHeader(br); if (Header.IsValid) { br.Seek(Header.CertificateAddress - Header.BaseAddress, SeekOrigin.Begin); Certifcate = new XbeCertifcate(br); br.Seek(Header.SectionHeadersAddress - Header.BaseAddress, SeekOrigin.Begin); for (uint i = 0; i < Header.NumberOfSections; i++) { Sections.Add(new XbeSection(br)); } foreach (XbeSection section in Sections) { section.Read(br, Header.BaseAddress); } } }
public XbeInfo(byte[] Xbe) { this.data = Xbe; this.br = new CBinaryReader(EndianType.LittleEndian, new MemoryStream(this.data)); this.Header = new XbeHeader(this.br); if (this.Header.IsValid) { this.br.Seek((long)(this.Header.CertificateAddress - this.Header.BaseAddress), SeekOrigin.Begin); this.Certifcate = new XbeCertifcate(this.br); this.br.Seek((long)(this.Header.SectionHeadersAddress - this.Header.BaseAddress), SeekOrigin.Begin); for (uint i = 0; i < this.Header.NumberOfSections; i++) { this.Sections.Add(new XbeSection(this.br)); } foreach (XbeSection section in this.Sections) { section.Read(this.br, this.Header.BaseAddress); } } }