/// <summary> /// Read from a stream and get partition table entry, if possible /// </summary> /// <param name="reader">BinaryReader representing the input stream</param> /// <returns>Partition table entry object, null on error</returns> public static PartitionTableEntry Read(BinaryReader reader) { PartitionTableEntry entry = new PartitionTableEntry(); try { entry.Offset = reader.ReadUInt32(); entry.Length = reader.ReadUInt32(); return(entry); } catch { return(null); } }
/// <summary> /// Read from a stream and get an NCSD header, if possible /// </summary> /// <param name="reader">BinaryReader representing the input stream</param> /// <param name="development">True if development cart, false otherwise</param> /// <returns>NCSD header object, null on error</returns> public static NCSDHeader Read(BinaryReader reader, bool development) { NCSDHeader header = new NCSDHeader(); try { header.RSA2048Signature = reader.ReadBytes(0x100); if (new string(reader.ReadChars(4)) != NCSDMagicNumber) { return(null); } header.ImageSizeInMediaUnits = reader.ReadUInt32(); header.MediaId = reader.ReadBytes(8); header.PartitionsFSType = (FilesystemType)reader.ReadUInt64(); header.PartitionsCryptType = reader.ReadBytes(8); header.PartitionsTable = new PartitionTableEntry[8]; for (int i = 0; i < 8; i++) { header.PartitionsTable[i] = PartitionTableEntry.Read(reader); } if (header.PartitionsFSType == FilesystemType.Normal || header.PartitionsFSType == FilesystemType.None) { header.ExheaderHash = reader.ReadBytes(0x20); header.AdditionalHeaderSize = reader.ReadUInt32(); header.SectorZeroOffset = reader.ReadUInt32(); header.PartitionFlags = reader.ReadBytes(8); header.PartitionIdTable = new byte[8][]; for (int i = 0; i < 8; i++) { header.PartitionIdTable[i] = reader.ReadBytes(8); } header.Reserved1 = reader.ReadBytes(0x20); header.Reserved2 = reader.ReadBytes(0xE); header.FirmUpdateByte1 = reader.ReadByte(); header.FirmUpdateByte2 = reader.ReadByte(); header.CARD2WritableAddressMediaUnits = reader.ReadBytes(4); header.CardInfoBytemask = reader.ReadBytes(4); header.Reserved3 = reader.ReadBytes(0x108); header.TitleVersion = reader.ReadUInt16(); header.CardRevision = reader.ReadUInt16(); header.Reserved4 = reader.ReadBytes(0xCEC); // Incorrectly documented as 0xCEE header.CardSeedKeyY = reader.ReadBytes(0x10); header.EncryptedCardSeed = reader.ReadBytes(0x10); header.CardSeedAESMAC = reader.ReadBytes(0x10); header.CardSeedNonce = reader.ReadBytes(0xC); header.Reserved5 = reader.ReadBytes(0xC4); header.BackupHeader = NCCHHeader.Read(reader, readSignature: false); if (development) { header.CardDeviceReserved1 = reader.ReadBytes(0x200); header.TitleKey = reader.ReadBytes(0x10); header.CardDeviceReserved2 = reader.ReadBytes(0xF0); } } else if (header.PartitionsFSType == FilesystemType.FIRM) { header.Unknown = reader.ReadBytes(0x5E); header.EncryptedMBR = reader.ReadBytes(0x42); } return(header); } catch { return(null); } }