Example #1
0
 public CnmtContentMetaEntry(BinaryReader reader)
 {
     TitleId = reader.ReadUInt64();
     Version = new TitleVersion(reader.ReadUInt32(), true);
     Type    = (CnmtContentType)reader.ReadByte();
     reader.BaseStream.Position += 3;
 }
Example #2
0
 public CnmtDeltaSetInfo(BinaryReader reader)
 {
     TitleIdOld        = reader.ReadUInt64();
     TitleIdNew        = reader.ReadUInt64();
     VersionOld        = new TitleVersion(reader.ReadUInt32());
     VersionNew        = new TitleVersion(reader.ReadUInt32());
     FragmentSetCount  = reader.ReadInt64();
     DeltaContentCount = reader.ReadInt64();
 }
Example #3
0
 public CnmtPrevDelta(BinaryReader reader)
 {
     TitleIdOld           = reader.ReadUInt64();
     TitleIdNew           = reader.ReadUInt64();
     VersionOld           = new TitleVersion(reader.ReadUInt32());
     VersionNew           = new TitleVersion(reader.ReadUInt32());
     Size                 = reader.ReadInt64();
     CnmtPrevDeltaField20 = reader.ReadInt64();
 }
Example #4
0
 public CnmtDeltaInfo(BinaryReader reader)
 {
     TitleIdOld = reader.ReadUInt64();
     TitleIdNew = reader.ReadUInt64();
     VersionOld = new TitleVersion(reader.ReadUInt32());
     VersionNew = new TitleVersion(reader.ReadUInt32());
     Field18    = reader.ReadInt64();
     Field20    = reader.ReadInt64();
 }
Example #5
0
        public Cnmt(Stream file)
        {
            using (var reader = new BinaryReader(file))
            {
                TitleId = reader.ReadUInt64();
                uint version = reader.ReadUInt32();
                Type              = (TitleType)reader.ReadByte();
                TitleVersion      = new TitleVersion(version, Type < TitleType.Application);
                FieldD            = reader.ReadByte();
                TableOffset       = reader.ReadUInt16();
                ContentEntryCount = reader.ReadUInt16();
                MetaEntryCount    = reader.ReadUInt16();
                file.Position    += 12;

                switch (Type)
                {
                case TitleType.Application:
                    ApplicationTitleId   = TitleId;
                    PatchTitleId         = reader.ReadUInt64();
                    MinimumSystemVersion = new TitleVersion(reader.ReadUInt32(), true);
                    break;

                case TitleType.Patch:
                    ApplicationTitleId   = reader.ReadUInt64();
                    MinimumSystemVersion = new TitleVersion(reader.ReadUInt32(), true);
                    break;

                case TitleType.AddOnContent:
                    ApplicationTitleId        = reader.ReadUInt64();
                    MinimumApplicationVersion = new TitleVersion(reader.ReadUInt32());
                    break;
                }

                file.Position = 0x20 + TableOffset;

                ContentEntries = new CnmtContentEntry[ContentEntryCount];
                MetaEntries    = new CnmtContentMetaEntry[MetaEntryCount];

                for (int i = 0; i < ContentEntryCount; i++)
                {
                    ContentEntries[i] = new CnmtContentEntry(reader);
                }

                for (int i = 0; i < MetaEntryCount; i++)
                {
                    MetaEntries[i] = new CnmtContentMetaEntry(reader);
                }

                if (Type == TitleType.Patch)
                {
                    ExtendedData = new CnmtExtended(reader);
                }

                Hash = reader.ReadBytes(0x20);
            }
        }
Example #6
0
 public CnmtPrevMetaEntry(BinaryReader reader)
 {
     TitleId = reader.ReadUInt64();
     Version = new TitleVersion(reader.ReadUInt32());
     Type    = (TitleType)reader.ReadByte();
     reader.BaseStream.Position += 3;
     Hash                     = reader.ReadBytes(0x20);
     ContentCount             = reader.ReadInt16();
     CnmtPrevMetaEntryField32 = reader.ReadInt16();
     CnmtPrevMetaEntryField34 = reader.ReadInt32();
 }
Example #7
0
        public NcaHeader(BinaryReader reader, Keyset keyset)
        {
            Signature1 = reader.ReadBytes(0x100);
            Signature2 = reader.ReadBytes(0x100);
            Magic      = reader.ReadAscii(4);
            if (Magic != "NCA3")
            {
                throw new InvalidDataException("Not an NCA3 file");
            }

            reader.BaseStream.Position -= 4;
            SignatureData    = reader.ReadBytes(0x200);
            FixedSigValidity = Crypto.Rsa2048PssVerify(SignatureData, Signature1, keyset.NcaHdrFixedKeyModulus);

            reader.BaseStream.Position -= 0x200 - 4;
            Distribution = (DistributionType)reader.ReadByte();
            ContentType  = (ContentType)reader.ReadByte();
            CryptoType   = reader.ReadByte();
            KaekInd      = reader.ReadByte();
            NcaSize      = reader.ReadInt64();
            TitleId      = reader.ReadUInt64();
            reader.BaseStream.Position += 4;

            SdkVersion  = new TitleVersion(reader.ReadUInt32());
            CryptoType2 = reader.ReadByte();
            reader.BaseStream.Position += 0xF;

            RightsId = reader.ReadBytes(0x10);

            for (int i = 0; i < 4; i++)
            {
                SectionEntries[i] = new NcaSectionEntry(reader);
            }

            for (int i = 0; i < 4; i++)
            {
                SectionHashes[i] = reader.ReadBytes(0x20);
            }

            for (int i = 0; i < 4; i++)
            {
                EncryptedKeys[i] = reader.ReadBytes(0x10);
            }

            reader.BaseStream.Position += 0xC0;

            for (int i = 0; i < 4; i++)
            {
                FsHeaders[i] = new NcaFsHeader(reader);
            }
        }
Example #8
0
        public Cnmt(Stream file)
        {
            using (var reader = new BinaryReader(file))
            {
                TitleId = reader.ReadUInt64();
                uint version = reader.ReadUInt32();
                Type              = (ContentMetaType)reader.ReadByte();
                TitleVersion      = new TitleVersion(version, Type < ContentMetaType.Application);
                FieldD            = reader.ReadByte();
                TableOffset       = reader.ReadUInt16();
                ContentEntryCount = reader.ReadUInt16();
                MetaEntryCount    = reader.ReadUInt16();

                // Old, pre-release cnmt files don't have the "required system version" field.
                // Try to detect this by reading the padding after that field.
                // The old format usually contains hashes there.
                file.Position += 8;
                int  padding         = reader.ReadInt32();
                bool isOldCnmtFormat = padding != 0;

                switch (Type)
                {
                case ContentMetaType.Application:
                    ApplicationTitleId   = TitleId;
                    PatchTitleId         = reader.ReadUInt64();
                    MinimumSystemVersion = new TitleVersion(reader.ReadUInt32(), true);
                    break;

                case ContentMetaType.Patch:
                    ApplicationTitleId   = reader.ReadUInt64();
                    MinimumSystemVersion = new TitleVersion(reader.ReadUInt32(), true);
                    break;

                case ContentMetaType.AddOnContent:
                    ApplicationTitleId        = reader.ReadUInt64();
                    MinimumApplicationVersion = new TitleVersion(reader.ReadUInt32());
                    break;
                }

                int baseOffset = isOldCnmtFormat ? 0x18 : 0x20;
                file.Position = baseOffset + TableOffset;

                ContentEntries = new CnmtContentEntry[ContentEntryCount];
                MetaEntries    = new CnmtContentMetaEntry[MetaEntryCount];

                for (int i = 0; i < ContentEntryCount; i++)
                {
                    ContentEntries[i] = new CnmtContentEntry(reader);
                }

                for (int i = 0; i < MetaEntryCount; i++)
                {
                    MetaEntries[i] = new CnmtContentMetaEntry(reader);
                }

                if (Type == ContentMetaType.Patch)
                {
                    ExtendedData = new CnmtExtended(reader);
                }

                Hash = reader.ReadBytes(0x20);
            }
        }