Example #1
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 #2
0
        public Package2Header(IStorage storage, Keyset keyset, int keyGeneration)
        {
            var reader = new BinaryReader(storage.AsStream());

            byte[] key = keyset.Package2Keys[keyGeneration];

            Signature = reader.ReadBytes(0x100);
            byte[] sigData = reader.ReadBytes(0x100);
            SignatureValidity = Crypto.Rsa2048PssVerify(sigData, Signature, keyset.Package2FixedKeyModulus);

            reader.BaseStream.Position -= 0x100;
            Counter = reader.ReadBytes(0x10);

            Stream headerStream = new CachedStorage(new Aes128CtrStorage(storage.Slice(0x100), key, Counter, true), 0x4000, 4, true).AsStream();

            headerStream.Position = 0x10;
            reader = new BinaryReader(headerStream);

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

            Magic      = reader.ReadAscii(4);
            BaseOffset = reader.ReadInt32();

            reader.BaseStream.Position += 4;
            VersionMax = reader.ReadByte();
            VersionMin = reader.ReadByte();

            reader.BaseStream.Position += 2;

            for (int i = 0; i < 4; i++)
            {
                SectionSizes[i] = reader.ReadInt32();
            }

            for (int i = 0; i < 4; i++)
            {
                SectionOffsets[i] = reader.ReadInt32();
            }

            for (int i = 0; i < 4; i++)
            {
                SectionHashes[i] = reader.ReadBytes(0x20);
            }
        }
Example #3
0
 internal void ValidateNpdmSignature(byte[] modulus)
 {
     NpdmSigValidity = Crypto.Rsa2048PssVerify(SignatureData, Signature2, modulus);
 }