/// <summary> /// Read from a stream and get an NCCH header, if possible /// </summary> /// <param name="reader">BinaryReader representing the input stream</param> /// <param name="readSignature">True if the RSA signature is read, false otherwise</param> /// <returns>NCCH header object, null on error</returns> public static NCCHHeader Read(BinaryReader reader, bool readSignature) { NCCHHeader header = new NCCHHeader(); try { if (readSignature) { header.RSA2048Signature = reader.ReadBytes(0x100); } if (new string(reader.ReadChars(4)) != NCCHMagicNumber) { return(null); } header.ContentSizeInMediaUnits = reader.ReadUInt32(); header.PartitionId = reader.ReadBytes(8).Reverse().ToArray(); header.MakerCode = reader.ReadUInt16(); header.Version = reader.ReadUInt16(); header.VerificationHash = reader.ReadUInt32(); header.ProgramId = reader.ReadBytes(8); header.Reserved1 = reader.ReadBytes(0x10); header.LogoRegionHash = reader.ReadBytes(0x20); header.ProductCode = reader.ReadBytes(0x10); header.ExtendedHeaderHash = reader.ReadBytes(0x20); header.ExtendedHeaderSizeInBytes = reader.ReadUInt32(); header.Reserved2 = reader.ReadBytes(4); header.Flags = NCCHHeaderFlags.Read(reader); header.PlainRegionOffsetInMediaUnits = reader.ReadUInt32(); header.PlainRegionSizeInMediaUnits = reader.ReadUInt32(); header.LogoRegionOffsetInMediaUnits = reader.ReadUInt32(); header.LogoRegionSizeInMediaUnits = reader.ReadUInt32(); header.ExeFSOffsetInMediaUnits = reader.ReadUInt32(); header.ExeFSSizeInMediaUnits = reader.ReadUInt32(); header.ExeFSHashRegionSizeInMediaUnits = reader.ReadUInt32(); header.Reserved3 = reader.ReadBytes(4); header.RomFSOffsetInMediaUnits = reader.ReadUInt32(); header.RomFSSizeInMediaUnits = reader.ReadUInt32(); header.RomFSHashRegionSizeInMediaUnits = reader.ReadUInt32(); header.Reserved4 = reader.ReadBytes(4); header.ExeFSSuperblockHash = reader.ReadBytes(0x20); header.RomFSSuperblockHash = reader.ReadBytes(0x20); return(header); } catch { return(null); } }
/// <summary> /// Read from a stream and get an NCCH header flags, if possible /// </summary> /// <param name="reader">BinaryReader representing the input stream</param> /// <returns>NCCH header flags object, null on error</returns> public static NCCHHeaderFlags Read(BinaryReader reader) { NCCHHeaderFlags flags = new NCCHHeaderFlags(); try { flags.Reserved0 = reader.ReadByte(); flags.Reserved1 = reader.ReadByte(); flags.Reserved2 = reader.ReadByte(); flags.CryptoMethod = (CryptoMethod)reader.ReadByte(); flags.ContentPlatform = (ContentPlatform)reader.ReadByte(); flags.MediaPlatformIndex = (ContentType)reader.ReadByte(); flags.ContentUnitSize = reader.ReadByte(); flags.BitMasks = (BitMasks)reader.ReadByte(); return(flags); } catch { return(null); } }