コード例 #1
0
ファイル: TMD.cs プロジェクト: zurgeg/riivolution
        public static TMD Create(Stream stream)
        {
            u16 numcontents;

            TMD tmd = new TMD(Signature.Create(stream));

            EndianReader reader = new EndianReader(stream, Endianness.BigEndian);

            tmd.Version          = reader.ReadByte();
            tmd.CaCrlVersion     = reader.ReadByte();
            tmd.SignerCrlVersion = reader.ReadByte();
            tmd.Padding          = reader.ReadByte();
            tmd.SystemVersion    = reader.ReadUInt64();
            tmd.TitleID          = reader.ReadUInt64();
            tmd.TitleType        = reader.ReadUInt32();
            tmd.GroupID          = reader.ReadUInt16();
            reader.ReadBytes(tmd.Padding2);
            tmd.AccessRights = reader.ReadUInt32();
            tmd.TitleVersion = reader.ReadUInt16();
            numcontents      = reader.ReadUInt16();
            tmd.BootIndex    = reader.ReadUInt16();
            tmd.Padding3     = reader.ReadUInt16();

            for (int i = 0; i < numcontents; i++)
            {
                tmd.Contents.Add(TmdContent.Create(stream));
            }

            return(tmd);
        }
コード例 #2
0
ファイル: NUS.cs プロジェクト: zurgeg/riivolution
        public static TMD DownloadTMD(Uri nusbase, ulong titleid)
        {
            Stream download = Download(nusbase, titleid, "tmd");

            TMD tmd = TMD.Create(download);

            download.Close();

            return(tmd);
        }
コード例 #3
0
ファイル: NUS.cs プロジェクト: zurgeg/riivolution
        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);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 public DlcBin()
 {
     Bk  = new BackupHeader();
     TMD = new TMD();
     Key = new u8[Util.AesKeySize];
 }
コード例 #6
0
        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);
            }
        }