Example #1
0
        public static Validity VerifySection(this Nca nca, Nca patchNca, int index, IProgressReport logger = null, bool quiet = false)
        {
            NcaFsHeader sect     = nca.Header.GetFsHeader(index);
            NcaHashType hashType = sect.HashType;

            if (hashType != NcaHashType.Sha256 && hashType != NcaHashType.Ivfc)
            {
                return(Validity.Unchecked);
            }

            var stream = nca.OpenStorageWithPatch(patchNca, index, IntegrityCheckLevel.IgnoreOnInvalid)
                         as HierarchicalIntegrityVerificationStorage;

            if (stream == null)
            {
                return(Validity.Unchecked);
            }

            if (!quiet)
            {
                logger?.LogMessage($"Verifying section {index}...");
            }
            Validity validity = stream.Validate(true, logger);

            return(validity);
        }
Example #2
0
        public NcaFsHeader(BinaryReader reader)
        {
            long start = reader.BaseStream.Position;

            Version                     = reader.ReadInt16();
            FormatType                  = (NcaFormatType)reader.ReadByte();
            HashType                    = (NcaHashType)reader.ReadByte();
            EncryptionType              = (NcaEncryptionType)reader.ReadByte();
            reader.BaseStream.Position += 3;

            switch (HashType)
            {
            case NcaHashType.Sha256:
                Sha256Info = new Sha256Info(reader);
                break;

            case NcaHashType.Ivfc:
                IvfcInfo = new IvfcHeader(reader);
                break;
            }

            if (EncryptionType == NcaEncryptionType.AesCtrEx)
            {
                BktrInfo = new BktrPatchInfo();

                reader.BaseStream.Position = start + 0x100;

                BktrInfo.RelocationHeader = new BktrHeader(reader);
                BktrInfo.EncryptionHeader = new BktrHeader(reader);
            }

            if (FormatType == NcaFormatType.Pfs0)
            {
                Type = SectionType.Pfs0;
            }
            else if (FormatType == NcaFormatType.Romfs)
            {
                if (EncryptionType == NcaEncryptionType.AesCtrEx)
                {
                    Type = SectionType.Bktr;
                }
                else
                {
                    Type = SectionType.Romfs;
                }
            }

            reader.BaseStream.Position = start + 0x140;
            Ctr = reader.ReadBytes(8).Reverse().ToArray();

            reader.BaseStream.Position = start + 512;
        }
Example #3
0
        public static Validity VerifySection(this Nca nca, int index, IProgressReport logger = null, bool quiet = false)
        {
            if (nca.Sections[index] == null)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            NcaSection  sect     = nca.Sections[index];
            NcaHashType hashType = sect.Header.HashType;

            if (hashType != NcaHashType.Sha256 && hashType != NcaHashType.Ivfc)
            {
                return(Validity.Unchecked);
            }

            var stream = nca.OpenStorage(index, IntegrityCheckLevel.IgnoreOnInvalid, false)
                         as HierarchicalIntegrityVerificationStorage;

            if (stream == null)
            {
                return(Validity.Unchecked);
            }

            if (!quiet)
            {
                logger?.LogMessage($"Verifying section {index}...");
            }
            Validity validity = stream.Validate(true, logger);

            if (hashType == NcaHashType.Ivfc)
            {
                stream.SetLevelValidities(sect.Header.IvfcInfo);
            }
            else if (hashType == NcaHashType.Sha256)
            {
                sect.Header.Sha256Info.HashValidity = validity;
            }

            return(validity);
        }