public IntegrityVerificationStorage(IntegrityVerificationInfo info, IStorage hashStorage,
                                            IntegrityCheckLevel integrityCheckLevel, bool leaveOpen)
            : base(info.Data, info.BlockSize, leaveOpen)
        {
            HashStorage         = hashStorage;
            IntegrityCheckLevel = integrityCheckLevel;
            Salt = info.Salt;
            Type = info.Type;

            BlockValidities = new Validity[SectorCount];
        }
Example #2
0
        public static void PrintIvfcHash(StringBuilder sb, int colLen, int indentSize, IvfcHeader ivfcInfo,
                                         IntegrityStorageType type)
        {
            var prefix  = new string(' ', indentSize);
            var prefix2 = new string(' ', indentSize + 4);

            if (type == IntegrityStorageType.RomFs)
            {
                PrintItem(sb, colLen,
                          $"{prefix}Master Hash{ivfcInfo.LevelHeaders[0].HashValidity.GetValidityString()}:",
                          ivfcInfo.MasterHash);
            }

            PrintItem(sb, colLen, $"{prefix}Magic:", ivfcInfo.Magic);
            PrintItem(sb, colLen, $"{prefix}Version:", ivfcInfo.Version);

            if (type == IntegrityStorageType.Save)
            {
                PrintItem(sb, colLen, $"{prefix}Salt Seed:", ivfcInfo.SaltSource);
            }

            var levelCount = Math.Max(ivfcInfo.NumLevels - 1, 0);

            if (type == IntegrityStorageType.Save)
            {
                levelCount = 4;
            }

            var offsetLen = type == IntegrityStorageType.Save ? 16 : 12;

            for (var i = 0; i < levelCount; i++)
            {
                var  level      = ivfcInfo.LevelHeaders[i];
                long hashOffset = 0;

                if (i != 0)
                {
                    hashOffset = ivfcInfo.LevelHeaders[i - 1].Offset;
                }

                sb.AppendLine($"{prefix}Level {i}{level.HashValidity.GetValidityString()}:");
                PrintItem(sb, colLen, $"{prefix2}Data Offset:", $"0x{level.Offset.ToString($"x{offsetLen}")}");
                PrintItem(sb, colLen, $"{prefix2}Data Size:", $"0x{level.Size.ToString($"x{offsetLen}")}");
                PrintItem(sb, colLen, $"{prefix2}Hash Offset:", $"0x{hashOffset.ToString($"x{offsetLen}")}");
                PrintItem(sb, colLen, $"{prefix2}Hash BlockSize:", $"0x{1 << level.BlockSizePower:x8}");
            }
        }
        private static IntegrityVerificationInfo[] GetIvfcInfo(IvfcHeader ivfc, IList <IStorage> levels, IntegrityStorageType type)
        {
            var initInfo = new IntegrityVerificationInfo[ivfc.NumLevels];

            initInfo[0] = new IntegrityVerificationInfo
            {
                Data      = levels[0],
                BlockSize = 0
            };

            for (int i = 1; i < ivfc.NumLevels; i++)
            {
                initInfo[i] = new IntegrityVerificationInfo
                {
                    Data      = levels[i],
                    BlockSize = 1 << ivfc.LevelHeaders[i - 1].BlockSizePower,
                        Salt  = new HMACSHA256(Encoding.ASCII.GetBytes(SaltSources[i - 1])).ComputeHash(ivfc.SaltSource),
                        Type  = type
                };
            }

            return(initInfo);
        }
 public HierarchicalIntegrityVerificationStorage(IvfcHeader header, IList <IStorage> levels,
                                                 IntegrityStorageType type, IntegrityCheckLevel integrityCheckLevel, bool leaveOpen)
     : this(GetIvfcInfo(header, levels, type), integrityCheckLevel, leaveOpen)
 {
 }
 public HierarchicalIntegrityVerificationStorage(IvfcHeader header, IStorage masterHash, IStorage data,
                                                 IntegrityStorageType type, IntegrityCheckLevel integrityCheckLevel, bool leaveOpen)
     : this(header, ToStorageList(header, masterHash, data, leaveOpen), type, integrityCheckLevel, leaveOpen)
 {
 }
Example #6
0
        public static void PrintIvfcHashNew(StringBuilder sb, int colLen, int indentSize, NcaFsIntegrityInfoIvfc ivfcInfo, IntegrityStorageType type, Validity masterHashValidity)
        {
            string prefix  = new string(' ', indentSize);
            string prefix2 = new string(' ', indentSize + 4);

            if (type == IntegrityStorageType.RomFs)
            {
                PrintItem(sb, colLen, $"{prefix}Master Hash{masterHashValidity.GetValidityString()}:", ivfcInfo.MasterHash.ToArray());
            }

            PrintItem(sb, colLen, $"{prefix}Magic:", MagicToString(ivfcInfo.Magic));
            PrintItem(sb, colLen, $"{prefix}Version:", ivfcInfo.Version >> 16);

            if (type == IntegrityStorageType.Save)
            {
                PrintItem(sb, colLen, $"{prefix}Salt Seed:", ivfcInfo.SaltSource.ToArray());
            }

            int levelCount = Math.Max(ivfcInfo.LevelCount - 1, 0);

            if (type == IntegrityStorageType.Save)
            {
                levelCount = 4;
            }

            int offsetLen = type == IntegrityStorageType.Save ? 16 : 12;

            for (int i = 0; i < levelCount; i++)
            {
                long hashOffset = 0;

                if (i != 0)
                {
                    hashOffset = ivfcInfo.GetLevelOffset(i - 1);
                }

                sb.AppendLine($"{prefix}Level {i}:");
                PrintItem(sb, colLen, $"{prefix2}Data Offset:", $"0x{ivfcInfo.GetLevelOffset(i).ToString($"x{offsetLen}")}");
                PrintItem(sb, colLen, $"{prefix2}Data Size:", $"0x{ivfcInfo.GetLevelSize(i).ToString($"x{offsetLen}")}");
                PrintItem(sb, colLen, $"{prefix2}Hash Offset:", $"0x{hashOffset.ToString($"x{offsetLen}")}");
                PrintItem(sb, colLen, $"{prefix2}Hash BlockSize:", $"0x{1 << ivfcInfo.GetLevelBlockSize(i):x8}");
            }
        }