public static TMD DownloadTMD(Uri nusbase, ulong titleid) { Stream download = Download(nusbase, titleid, "tmd"); TMD tmd = TMD.Create(download); download.Close(); return(tmd); }
public static TMD DownloadTMD(Uri nusbase, ulong titleid, u16 version) { Stream download = Download(nusbase, titleid, "tmd." + version.ToString()); TMD tmd = TMD.Create(download); download.Close(); return(tmd); }
public static WAD Create(Stream stream) { EndianReader reader = new EndianReader(stream, Endianness.BigEndian); WAD wad = new WAD(); wad.HeaderSize = reader.ReadUInt32(); wad.WadType = reader.ReadUInt32(); wad.CertificateChainSize = reader.ReadUInt32(); wad.Reserved = reader.ReadUInt32(); wad.TicketSize = reader.ReadUInt32(); wad.TmdSize = reader.ReadUInt32(); wad.DataSize = reader.ReadUInt32(); wad.FooterSize = reader.ReadUInt32(); reader.PadToMultiple(0x40); reader.Seek(wad.CertificateChainSize, SeekOrigin.Current); reader.PadToMultiple(0x40); wad.Ticket = Ticket.Create(stream); reader.PadToMultiple(0x40); wad.TMD = TMD.Create(stream); reader.PadToMultiple(0x40); wad.DataEncrypted = new Substream(reader.Base, reader.Position, wad.DataSize); long offset = 0; foreach (TmdContent content in wad.TMD.Contents) { byte[] iv = new byte[0x10]; BigEndianConverter.GetBytes(content.Index).CopyTo(iv, 0); wad.Data.Add(new AesStream(new Substream(wad.DataEncrypted, offset), wad.Ticket.Key, iv)); offset = (long)Util.RoundUp(offset + content.Size, 0x40); } stream.Position += wad.DataSize; reader.PadToMultiple(0x40); wad.Footer = reader.ReadBytes((int)wad.FooterSize); return(wad); }
public DlcBin(Stream stream) { Key = new u8[Util.AesKeySize]; Bk = BackupHeader.Create(stream); stream.Position = Util.RoundUp(stream.Position, 0x40); TMD = TMD.Create(stream); stream.Position = Util.RoundUp(stream.Position, 0x40); u16 index = u16.MaxValue; for (int i = 0; i < Bk.ContentIndex.Length; i++) { if (Bk.ContentIndex[i] != 0) { index = (u16)(i * 8); for (int k = 1; k < 8; k++) { if ((Bk.ContentIndex[i] & (1 << k)) != 0) { index += (u16)k; } } } } if (index != ushort.MaxValue) { Content = TMD.Contents[index]; } RawData = new Substream(stream, stream.Position, Content != null ? Util.RoundUp(Content.Size, 0x40) : (stream.Length - stream.Position)); if (Content != null) { byte[] iv = new byte[0x10]; BigEndianConverter.GetBytes(Content.Index).CopyTo(iv, 0); Data = new Substream(new AesStream(RawData, Key, iv), 0, Content.Size); } }
public Disc(Stream stream) { Stream = stream; EndianReader reader = new EndianReader(Stream, Endianness.BigEndian); Stream.Position = 0; Console = (char)Stream.ReadByte(); Gamecode = ((char)Stream.ReadByte()).ToString() + (char)Stream.ReadByte(); Region = (char)Stream.ReadByte(); Publisher = ((char)Stream.ReadByte()).ToString() + (char)Stream.ReadByte(); Number = (byte)Stream.ReadByte(); Version = (byte)Stream.ReadByte(); AudioStreaming = (byte)Stream.ReadByte(); AudioStreamingBuffer = (byte)Stream.ReadByte(); reader.Position = 0x18; if (reader.ReadUInt32() != Magic) { throw new FormatException(); } reader.ReadUInt32(); Title = Util.ReadCString(Stream); reader.Position = 0x40000; uint[][] partitiontable = new uint[4][]; for (int i = 0; i < 4; i++) { partitiontable[i] = new uint[2]; for (int j = 0; j < 2; j++) { partitiontable[i][j] = reader.ReadUInt32(); } } Partitions = new List <Partition>(); for (byte i = 0; i < 4; i++) { if (partitiontable[i][0] > 0) { reader.Position = (long)partitiontable[i][1] << 2; } for (int j = 0; j < partitiontable[i][0]; j++) { Partition partition = new Partition(); Partitions.Add(partition); partition.Table = i; partition.Offset = (long)reader.ReadUInt32() << 2; partition.Type = (PartitionType)reader.ReadUInt32(); // May or may not correspond to the enum } } reader.Position = 0x4E000; RegionSet = reader.ReadUInt32(); foreach (Partition partition in Partitions) { reader.Position = partition.Offset; partition.Ticket = Ticket.Create(Stream); reader.ReadUInt32(); // TMD Size reader.ReadUInt32(); // TMD Offset partition.CertificateChain = new byte[reader.ReadUInt32()]; long certoffset = (long)reader.ReadUInt32() << 2; long h3offset = (long)reader.ReadUInt32() << 2; partition.DataOffset = (long)reader.ReadUInt32() << 2; partition.DataSize = (long)reader.ReadUInt32() << 2;; partition.TMD = TMD.Create(Stream); reader.Position = partition.Offset + certoffset; reader.Read(partition.CertificateChain, 0, partition.CertificateChain.Length); partition.Stream = new PartitionStream(partition, Stream); // At 0x420: uint dolOffset, uint fstOffset, uint fstSize, uint fstSize partition.Stream.Position = 0x424; long fstOffset = (long)new EndianReader(partition.Stream, Endianness.BigEndian).ReadUInt32() << 2; partition.Stream.Position = fstOffset; partition.Root = new U8(partition.Stream, true); } }