mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Use savefile reader to get tickets from NAND
This commit is contained in:
parent
80cf0b43fb
commit
1dc232e704
3 changed files with 47 additions and 49 deletions
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using libhac;
|
||||
using libhac.Nand;
|
||||
using libhac.Savefile;
|
||||
|
||||
namespace NandReader
|
||||
{
|
||||
|
@ -86,19 +87,37 @@ namespace NandReader
|
|||
var tickets = new List<Ticket>();
|
||||
var system = nand.OpenSystemPartition();
|
||||
|
||||
logger?.LogMessage("Searching save 80000000000000E1");
|
||||
var saveE1 = system.OpenFile("save\\80000000000000E1", FileMode.Open, FileAccess.Read);
|
||||
tickets.AddRange(Ticket.SearchTickets(saveE1, logger));
|
||||
var saveE1File = system.OpenFile("save\\80000000000000E1", FileMode.Open, FileAccess.Read);
|
||||
tickets.AddRange(ReadTickets(saveE1File));
|
||||
|
||||
logger?.LogMessage("Searching save 80000000000000E2");
|
||||
var saveE2 = system.OpenFile("save\\80000000000000E2", FileMode.Open, FileAccess.Read);
|
||||
tickets.AddRange(Ticket.SearchTickets(saveE2, logger));
|
||||
tickets.AddRange(ReadTickets(saveE2));
|
||||
|
||||
logger?.LogMessage($"Found {tickets.Count} tickets");
|
||||
|
||||
return tickets.ToArray();
|
||||
}
|
||||
|
||||
private static List<Ticket> ReadTickets(Stream savefile)
|
||||
{
|
||||
var tickets = new List<Ticket>();
|
||||
var save = new Savefile(savefile);
|
||||
var ticketList = new BinaryReader(save.OpenFile("ticket_list.bin"));
|
||||
var ticketFile = new BinaryReader(save.OpenFile("ticket.bin"));
|
||||
|
||||
var titleId = ticketList.ReadUInt64();
|
||||
while (titleId != ulong.MaxValue)
|
||||
{
|
||||
ticketList.BaseStream.Position += 0x18;
|
||||
var start = ticketFile.BaseStream.Position;
|
||||
tickets.Add(new Ticket(ticketFile));
|
||||
ticketFile.BaseStream.Position = start + 0x400;
|
||||
titleId = ticketList.ReadUInt64();
|
||||
}
|
||||
|
||||
return tickets;
|
||||
}
|
||||
|
||||
private static Keyset OpenKeyset()
|
||||
{
|
||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
|
|
|
@ -7,6 +7,7 @@ using GalaSoft.MvvmLight;
|
|||
using GalaSoft.MvvmLight.Command;
|
||||
using libhac;
|
||||
using libhac.Nand;
|
||||
using libhac.Savefile;
|
||||
using libhac.XTSSharp;
|
||||
|
||||
namespace NandReaderGui.ViewModel
|
||||
|
@ -69,19 +70,36 @@ namespace NandReaderGui.ViewModel
|
|||
var tickets = new List<Ticket>();
|
||||
var system = nand.OpenSystemPartition();
|
||||
|
||||
logger?.LogMessage("Searching save 80000000000000E1");
|
||||
var saveE1 = system.OpenFile("save\\80000000000000E1", FileMode.Open, FileAccess.Read);
|
||||
tickets.AddRange(Ticket.SearchTickets(saveE1, logger));
|
||||
var saveE1File = system.OpenFile("save\\80000000000000E1", FileMode.Open, FileAccess.Read);
|
||||
tickets.AddRange(ReadTickets(saveE1File));
|
||||
|
||||
logger?.LogMessage("Searching save 80000000000000E2");
|
||||
var saveE2 = system.OpenFile("save\\80000000000000E2", FileMode.Open, FileAccess.Read);
|
||||
tickets.AddRange(Ticket.SearchTickets(saveE2, logger));
|
||||
tickets.AddRange(ReadTickets(saveE2));
|
||||
|
||||
logger?.LogMessage($"Found {tickets.Count} tickets");
|
||||
|
||||
return tickets.ToArray();
|
||||
}
|
||||
|
||||
private static List<Ticket> ReadTickets(Stream savefile)
|
||||
{
|
||||
var tickets = new List<Ticket>();
|
||||
var save = new Savefile(savefile);
|
||||
var ticketList = new BinaryReader(save.OpenFile("ticket_list.bin"));
|
||||
var ticketFile = new BinaryReader(save.OpenFile("ticket.bin"));
|
||||
|
||||
var titleId = ticketList.ReadUInt64();
|
||||
while (titleId != ulong.MaxValue)
|
||||
{
|
||||
ticketList.BaseStream.Position += 0x18;
|
||||
var start = ticketFile.BaseStream.Position;
|
||||
tickets.Add(new Ticket(ticketFile));
|
||||
ticketFile.BaseStream.Position = start + 0x400;
|
||||
titleId = ticketList.ReadUInt64();
|
||||
}
|
||||
|
||||
return tickets;
|
||||
}
|
||||
private static Keyset OpenKeyset()
|
||||
{
|
||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
|
|
|
@ -145,45 +145,6 @@ namespace libhac
|
|||
return stream.ToArray();
|
||||
}
|
||||
|
||||
public static Ticket[] SearchTickets(Stream file, IProgressReport logger = null)
|
||||
{
|
||||
var reader = new BinaryReader(file, Encoding.Default, true);
|
||||
file.Position += 0x140;
|
||||
var tickets = new Dictionary<string, Ticket>();
|
||||
|
||||
logger?.SetTotal(file.Length);
|
||||
|
||||
// Ticket starts occur at multiples of 0x400
|
||||
while (file.Position + 0x800 < file.Length)
|
||||
{
|
||||
var position = file.Position;
|
||||
logger?.Report(position);
|
||||
|
||||
if (reader.ReadUInt32() != 0x746f6f52) // Root
|
||||
{
|
||||
file.Position = position + 0x400;
|
||||
continue;
|
||||
}
|
||||
|
||||
file.Position -= 0x144;
|
||||
var sigType = (TicketSigType)reader.ReadUInt32();
|
||||
if (sigType < TicketSigType.Rsa4096Sha1 || sigType > TicketSigType.EcdsaSha256)
|
||||
{
|
||||
file.Position = position + 0x400;
|
||||
continue;
|
||||
}
|
||||
|
||||
file.Position -= 4;
|
||||
|
||||
var ticket = new Ticket(reader);
|
||||
tickets[ticket.RightsId.ToHexString()] = ticket;
|
||||
file.Position = position + 0x400;
|
||||
}
|
||||
|
||||
logger?.SetTotal(0);
|
||||
return tickets.Values.ToArray();
|
||||
}
|
||||
|
||||
public byte[] GetTitleKey(Keyset keyset)
|
||||
{
|
||||
if (TitleKeyType == TitleKeyType.Common)
|
||||
|
|
Loading…
Reference in a new issue