/// <summary> /// Determine if the VOL file is of type TOC 2.2, TOC 3.1 or GTPSP (others aren't supported). /// </summary> /// <param name="stream">Stream containing the VOL file.</param> /// <returns>FileType</returns> private FileType GetVOLType(Stream stream) { var fileType = FileType.UNKNOWN; using (var reader = new EndianBinReader(stream, EndianType.BIG_ENDIAN)) { if (reader.BaseStream.Length - reader.BaseStream.Position < 0x08) { throw new ArgumentException("Invalid VOL file."); } var magic = reader.ReadUInt64(); if (magic == TOC22_MAGIC) { fileType = FileType.TOC22_VOL; if (TOC31Offset(reader) > -1) { fileType = FileType.TOC31_VOL; } } else if (magic == TOCPSP_MAGIC) { fileType = FileType.GTPSP_VOL; } } return(fileType); }
public RT04Header(EndianBinReader reader) { reader.BaseStream.Position = 0; if ((Magic = reader.ReadUInt32(EndianType.BIG_ENDIAN)) != Constants.RT04_MAGIC) { throw new Exception("Invalid magic, doesn't match RT04."); } Padding = reader.ReadUInt64(); EntryCount = reader.ReadUInt32(); }
public bool Read(EndianBinReader reader) { if ((Magic = reader.ReadUInt32()) != Consts.kVOLUME_HEADER_MAGIC) { return(false); } Seed = reader.ReadUInt32(); if (Seed <= 0) { return(false); } Size = reader.ReadUInt32(); RealSize = reader.ReadUInt32(); PatchSequence = reader.ReadUInt64(); FileSize = reader.ReadUInt64(); var buffer = reader.ReadBytes(128); TitleID = Encoding.UTF8.GetString(buffer); return(true); }
/// <summary> /// Search for the TOC 3.1 in the VOL file and return its offset if found /// </summary> private long TOC31Offset(EndianBinReader reader) { for (int i = 0; i < Math.Min((reader.BaseStream.Length / 0x800), 10000); i++) { reader.BaseStream.Seek(i * 0x800, SeekOrigin.Begin); ulong magic = reader.ReadUInt64(); if (magic == TOC31_MAGIC_ENCRYPTED || magic - TOC31_MAGIC == 0) { return(i * 0x800); } } return(-1); }