private void readVolume() { volDesc = new GDFVolumeDescriptor(); volDesc.SectorSize = 0x800; fr.Seek(0x20 * volDesc.SectorSize, SeekOrigin.Begin); if (Encoding.ASCII.GetString(fr.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA") { type = IsoType.Xsf; volDesc.RootOffset = (uint)type; } else { file.Seek((0x20 * volDesc.SectorSize) + 0xfd90000, SeekOrigin.Begin); if (Encoding.ASCII.GetString(fr.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA") { type = IsoType.Gdf; volDesc.RootOffset = (uint)type; } else { type = IsoType.XGD3; volDesc.RootOffset = (uint)type; } } file.Seek((0x20 * volDesc.SectorSize) + volDesc.RootOffset, SeekOrigin.Begin); volDesc.Identifier = fr.ReadBytes(20); volDesc.RootDirSector = fr.ReadUInt32(); volDesc.RootDirSize = fr.ReadUInt32(); volDesc.ImageCreationTime = fr.ReadBytes(8); volDesc.VolumeSize = (ulong)(fr.BaseStream.Length - volDesc.RootOffset); volDesc.VolumeSectors = (uint)(volDesc.VolumeSize / volDesc.SectorSize); }
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(); }
// 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 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(); }
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 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 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 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 XexHeader(CBinaryReader br) { Clear(); try { br.Seek(0L, SeekOrigin.Begin); if (Encoding.ASCII.GetString(br.ReadBytes(4)) == "XEX2") { br.Seek(4L, SeekOrigin.Begin); Add(XexInfoFields.ModuleFlags, new XexModuleFlags(br.ReadUInt32())); br.Seek(8L, SeekOrigin.Begin); Add(XexInfoFields.CodeOffset, new XexCodeOffset(br.ReadUInt32())); br.Seek(0x10L, SeekOrigin.Begin); Add(XexInfoFields.CertifcateOffset, new XexCertifcateOffset(br.ReadUInt32())); br.Seek(20L, SeekOrigin.Begin); uint num = br.ReadUInt32(); for (int i = 0; i < num; i++) { uint num3 = BitConverter.ToUInt32(br.ReadBytes(4), 0); if (num3 == BitConverter.ToUInt32(XexResourceInfo.Signature, 0)) { Add(XexInfoFields.ResourceInfo, new XexResourceInfo(br.ReadUInt32())); } else if (num3 == BitConverter.ToUInt32(XexCompressionInfo.Signature, 0)) { Add(XexInfoFields.CompressionInfo, new XexCompressionInfo(br.ReadUInt32())); } else if (num3 == BitConverter.ToUInt32(XexExecutionInfo.Signature, 0)) { Add(XexInfoFields.ExecutionInfo, new XexExecutionInfo(br.ReadUInt32())); } else if (num3 == BitConverter.ToUInt32(XexBaseFileFormat.Signature, 0)) { Add(XexInfoFields.BaseFileFormat, new XexBaseFileFormat(br.ReadUInt32())); } else if (num3 == BitConverter.ToUInt32(XexBaseFileTimestamp.Signature, 0)) { Add(XexInfoFields.BaseFileTimestamp, new XexBaseFileTimestamp(br.ReadUInt32())); } else if (num3 == BitConverter.ToUInt32(XexOriginalName.Signature, 0)) { Add(XexInfoFields.OriginalName, new XexOriginalName(br.ReadUInt32())); } else if (num3 == BitConverter.ToUInt32(XexRatingsInfo.Signature, 0)) { Add(XexInfoFields.RatingsInfo, new XexRatingsInfo(br.ReadUInt32())); } else if (num3 == BitConverter.ToUInt32(XexModuleFlags.Signature, 0)) { Add(XexInfoFields.SystemFlags, new XexModuleFlags(br.ReadUInt32())); } else { br.ReadUInt32(); } } } } catch (EndOfStreamException) { Console.WriteLine("EndOfStreamException when trying to read XEX file header."); } }
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 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); } }
/// <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); }