2018-06-21 18:16:51 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2018-06-21 23:03:58 +02:00
|
|
|
|
using System.Linq;
|
2018-06-21 16:25:20 +02:00
|
|
|
|
using libhac;
|
2018-06-16 19:11:38 +02:00
|
|
|
|
|
2018-06-21 16:25:20 +02:00
|
|
|
|
namespace hactoolnet
|
2018-06-16 19:11:38 +02:00
|
|
|
|
{
|
2018-06-21 16:25:20 +02:00
|
|
|
|
public static class Program
|
2018-06-16 19:11:38 +02:00
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
2018-06-28 03:25:25 +02:00
|
|
|
|
{
|
2018-06-28 22:02:23 +02:00
|
|
|
|
//ReadNca();
|
|
|
|
|
ListSdfs(args);
|
2018-06-28 03:25:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ListSdfs(string[] args)
|
2018-06-21 18:16:51 +02:00
|
|
|
|
{
|
2018-06-27 02:10:21 +02:00
|
|
|
|
var sdfs = LoadSdFs(args);
|
|
|
|
|
|
2018-06-25 21:01:24 +02:00
|
|
|
|
Console.WriteLine("Listing NCA files");
|
2018-06-27 02:10:21 +02:00
|
|
|
|
ListNcas(sdfs);
|
2018-06-25 21:01:24 +02:00
|
|
|
|
|
|
|
|
|
Console.WriteLine("Listing titles");
|
2018-06-27 02:10:21 +02:00
|
|
|
|
ListTitles(sdfs);
|
2018-06-25 21:01:24 +02:00
|
|
|
|
|
2018-06-27 02:10:21 +02:00
|
|
|
|
//DecryptNax0(sdfs, "C0628FB07A89E9050BDA258F74868E8D");
|
2018-06-28 22:02:23 +02:00
|
|
|
|
//DecryptTitle(sdfs, 0x010023900AEE0000);
|
2018-06-28 03:25:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ReadNca()
|
|
|
|
|
{
|
|
|
|
|
var keyset = ExternalKeys.ReadKeyFile("keys.txt", "titlekeys.txt");
|
2018-06-28 22:02:23 +02:00
|
|
|
|
using (var file = new FileStream("bf8b106a2e68df3c3f1694636423585a.nca", FileMode.Open, FileAccess.Read))
|
2018-06-28 03:25:25 +02:00
|
|
|
|
{
|
|
|
|
|
var nca = new Nca(keyset, file, false);
|
2018-06-28 22:02:23 +02:00
|
|
|
|
var romfs = nca.OpenSection(0, false);
|
2018-06-28 03:25:25 +02:00
|
|
|
|
|
|
|
|
|
using (var output = new FileStream("romfs_net", FileMode.Create))
|
|
|
|
|
{
|
|
|
|
|
romfs.CopyTo(output);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-21 18:16:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 02:10:21 +02:00
|
|
|
|
static void DecryptNax0(SdFs sdFs, string name)
|
2018-06-16 19:11:38 +02:00
|
|
|
|
{
|
2018-06-27 02:42:01 +02:00
|
|
|
|
if (!sdFs.Ncas.ContainsKey(name)) return;
|
2018-06-27 02:10:21 +02:00
|
|
|
|
var nca = sdFs.Ncas[name];
|
|
|
|
|
using (var output = new FileStream($"{nca.NcaId}.nca", FileMode.Create))
|
|
|
|
|
using (var progress = new ProgressBar())
|
2018-06-20 19:42:56 +02:00
|
|
|
|
{
|
2018-06-27 02:10:21 +02:00
|
|
|
|
progress.LogMessage($"Title ID: {nca.Header.TitleId:X16}");
|
|
|
|
|
progress.LogMessage($"Writing {nca.NcaId}.nca");
|
|
|
|
|
nca.Stream.Position = 0;
|
|
|
|
|
nca.Stream.CopyStream(output, nca.Stream.Length, progress);
|
2018-06-20 19:42:56 +02:00
|
|
|
|
}
|
2018-06-16 19:11:38 +02:00
|
|
|
|
}
|
2018-06-21 18:16:51 +02:00
|
|
|
|
|
2018-06-27 02:42:01 +02:00
|
|
|
|
static void DecryptTitle(SdFs sdFs, ulong titleId)
|
|
|
|
|
{
|
|
|
|
|
var title = sdFs.Titles[titleId];
|
|
|
|
|
var dirName = $"{titleId:X16}v{title.Version.Version}";
|
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(dirName);
|
|
|
|
|
|
|
|
|
|
foreach (var nca in title.Ncas)
|
|
|
|
|
{
|
|
|
|
|
using (var output = new FileStream(Path.Combine(dirName, nca.Filename), FileMode.Create))
|
|
|
|
|
using (var progress = new ProgressBar())
|
|
|
|
|
{
|
|
|
|
|
progress.LogMessage($"Writing {nca.Filename}");
|
|
|
|
|
nca.Stream.Position = 0;
|
|
|
|
|
nca.Stream.CopyStream(output, nca.Stream.Length, progress);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 02:10:21 +02:00
|
|
|
|
static SdFs LoadSdFs(string[] args)
|
2018-06-22 23:17:20 +02:00
|
|
|
|
{
|
2018-06-28 22:02:23 +02:00
|
|
|
|
var keyset = ExternalKeys.ReadKeyFile(args[0], "titlekeys.txt");
|
2018-06-22 23:17:20 +02:00
|
|
|
|
keyset.SetSdSeed(args[1].ToBytes());
|
2018-06-27 02:10:21 +02:00
|
|
|
|
var sdfs = new SdFs(keyset, args[2]);
|
|
|
|
|
return sdfs;
|
|
|
|
|
}
|
2018-06-26 00:26:47 +02:00
|
|
|
|
|
2018-06-27 02:10:21 +02:00
|
|
|
|
static void ListNcas(SdFs sdfs)
|
|
|
|
|
{
|
|
|
|
|
foreach (Nca nca in sdfs.Ncas.Values.OrderBy(x => x.Header.TitleId))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"{nca.Header.TitleId:X16} {nca.Header.ContentType.ToString().PadRight(10, ' ')} {nca.NcaId}");
|
2018-06-22 23:17:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 02:10:21 +02:00
|
|
|
|
static void ListTitles(SdFs sdfs)
|
2018-06-21 18:16:51 +02:00
|
|
|
|
{
|
2018-06-27 02:10:21 +02:00
|
|
|
|
foreach (var title in sdfs.Titles.Values.OrderBy(x => x.Id))
|
2018-06-26 00:26:47 +02:00
|
|
|
|
{
|
2018-06-27 02:10:21 +02:00
|
|
|
|
Console.WriteLine($"{title.Id:X16} v{title.Version.Version} ({title.Version}) {title.Metadata.Type}");
|
2018-06-22 23:17:20 +02:00
|
|
|
|
|
2018-06-27 02:10:21 +02:00
|
|
|
|
foreach (var content in title.Metadata.ContentEntries)
|
2018-06-22 23:17:20 +02:00
|
|
|
|
{
|
2018-06-27 02:10:21 +02:00
|
|
|
|
Console.WriteLine(
|
2018-06-27 02:42:01 +02:00
|
|
|
|
$" {content.NcaId.ToHexString()}.nca {content.Type} {Util.GetBytesReadable(content.Size)}");
|
2018-06-23 04:02:19 +02:00
|
|
|
|
}
|
2018-06-27 02:10:21 +02:00
|
|
|
|
|
2018-06-28 22:02:23 +02:00
|
|
|
|
foreach (var nca in title.Ncas)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($" {nca.HasRightsId} {nca.NcaId} {nca.Header.ContentType}");
|
|
|
|
|
|
|
|
|
|
foreach (var sect in nca.Sections)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($" {sect.SectionNum} {sect.Type} {sect.Header.CryptType} {sect.SuperblockHashValidity}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 02:10:21 +02:00
|
|
|
|
Console.WriteLine("");
|
2018-06-21 18:16:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-16 19:11:38 +02:00
|
|
|
|
}
|
|
|
|
|
}
|