Support xts nca. Handle more errors in switchfs

This commit is contained in:
Alex Barney 2019-06-22 17:18:28 -05:00
parent abad1ee666
commit 46d4274686
2 changed files with 47 additions and 31 deletions

View file

@ -148,7 +148,15 @@ namespace LibHac.Fs.NcaUtils
// ReSharper disable UnusedParameter.Local // ReSharper disable UnusedParameter.Local
private IStorage OpenAesXtsStorage(IStorage baseStorage, int index) private IStorage OpenAesXtsStorage(IStorage baseStorage, int index)
{ {
throw new NotImplementedException("NCA sections using XTS are not supported yet."); const int sectorSize = 0x200;
NcaFsHeader fsHeader = Header.GetFsHeader(index);
byte[] key0 = GetContentKey(NcaKeyType.AesXts0);
byte[] key1 = GetContentKey(NcaKeyType.AesXts1);
// todo: Handle xts for nca version 3
return new CachedStorage(new Aes128XtsStorage(baseStorage, key0, key1, sectorSize, true), 2, true);
} }
// ReSharper restore UnusedParameter.Local // ReSharper restore UnusedParameter.Local

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.NcaUtils; using LibHac.Fs.NcaUtils;
using LibHac.Fs.Save; using LibHac.Fs.Save;
@ -132,6 +133,8 @@ namespace LibHac
private void ReadTitles() private void ReadTitles()
{ {
foreach (SwitchFsNca nca in Ncas.Values.Where(x => x.Nca.Header.ContentType == ContentType.Meta)) foreach (SwitchFsNca nca in Ncas.Values.Where(x => x.Nca.Header.ContentType == ContentType.Meta))
{
try
{ {
var title = new Title(); var title = new Title();
@ -170,6 +173,11 @@ namespace LibHac
Titles[title.Id] = title; Titles[title.Id] = title;
} }
catch (Exception ex)
{
Console.WriteLine($"{ex.Message} File: {nca.Filename}");
}
}
} }
private void ReadControls() private void ReadControls()