LibHac/hactoolnet/Program.cs

125 lines
4.2 KiB
C#
Raw Normal View History

2018-06-21 18:16:51 +02:00
using System;
using System.IO;
2018-07-03 04:21:35 +02:00
using System.Text;
2018-08-31 17:47:11 +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
{
2018-07-05 23:37:30 +02:00
public static void Main(string[] args)
2018-06-28 03:25:25 +02:00
{
2018-07-03 04:21:35 +02:00
Console.OutputEncoding = Encoding.UTF8;
2018-07-02 22:12:41 +02:00
var ctx = new Context();
ctx.Options = CliParser.Parse(args);
if (ctx.Options == null) return;
using (var logger = new ProgressBar())
{
ctx.Logger = logger;
OpenKeyset(ctx);
2018-07-06 04:37:46 +02:00
if (ctx.Options.RunCustom)
{
CustomTask(ctx);
return;
}
2018-07-02 22:12:41 +02:00
switch (ctx.Options.InFileType)
{
case FileType.Nca:
ProcessNca.Process(ctx);
2018-07-02 22:12:41 +02:00
break;
case FileType.Pfs0:
break;
case FileType.Romfs:
ProcessRomfs.Process(ctx);
2018-07-02 22:12:41 +02:00
break;
case FileType.Nax0:
break;
case FileType.SwitchFs:
ProcessSwitchFs.Process(ctx);
2018-07-02 22:12:41 +02:00
break;
case FileType.Save:
2018-10-01 19:55:10 +02:00
ProcessSave.Process(ctx);
break;
2018-08-12 22:45:10 +02:00
case FileType.Xci:
ProcessXci.Process(ctx);
2018-08-12 22:45:10 +02:00
break;
2018-08-28 00:40:06 +02:00
case FileType.Keygen:
ProcessKeygen(ctx);
break;
2018-09-13 02:51:21 +02:00
case FileType.Pk11:
ProcessPackage.ProcessPk11(ctx);
2018-09-13 02:51:21 +02:00
break;
2018-09-17 03:26:16 +02:00
case FileType.Pk21:
ProcessPackage.ProcessPk21(ctx);
break;
2018-09-18 02:18:28 +02:00
case FileType.Kip1:
ProcessKip.ProcessKip1(ctx);
break;
2018-09-18 02:52:22 +02:00
case FileType.Ini1:
ProcessKip.ProcessIni1(ctx);
break;
2018-07-02 22:12:41 +02:00
default:
throw new ArgumentOutOfRangeException();
}
}
2018-06-28 03:25:25 +02:00
}
2018-07-02 22:12:41 +02:00
private static void OpenKeyset(Context ctx)
{
2018-10-03 00:25:58 +02:00
string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string homeKeyFile = Path.Combine(home, ".switch", "prod.keys");
string homeTitleKeyFile = Path.Combine(home, ".switch", "title.keys");
string homeConsoleKeyFile = Path.Combine(home, ".switch", "console.keys");
string keyFile = ctx.Options.Keyfile;
string titleKeyFile = ctx.Options.TitleKeyFile;
string consoleKeyFile = ctx.Options.ConsoleKeyFile;
2018-07-03 04:21:35 +02:00
if (keyFile == null && File.Exists(homeKeyFile))
{
keyFile = homeKeyFile;
}
if (titleKeyFile == null && File.Exists(homeTitleKeyFile))
{
titleKeyFile = homeTitleKeyFile;
}
2018-07-09 18:47:32 +02:00
if (consoleKeyFile == null && File.Exists(homeConsoleKeyFile))
{
consoleKeyFile = homeConsoleKeyFile;
}
ctx.Keyset = ExternalKeys.ReadKeyFile(keyFile, titleKeyFile, consoleKeyFile, ctx.Logger);
2018-07-03 04:21:35 +02:00
if (ctx.Options.SdSeed != null)
{
ctx.Keyset.SetSdSeed(ctx.Options.SdSeed.ToBytes());
}
2018-10-03 05:00:57 +02:00
if (ctx.Options.OutDir != null)
{
string dir = ctx.Options.OutDir;
Directory.CreateDirectory(dir);
File.WriteAllText(Path.Combine(dir, "prod.keys"), ExternalKeys.PrintCommonKeys(ctx.Keyset));
File.WriteAllText(Path.Combine(dir, "console.keys"), ExternalKeys.PrintUniqueKeys(ctx.Keyset));
File.WriteAllText(Path.Combine(dir, "title.keys"), ExternalKeys.PrintTitleKeys(ctx.Keyset));
}
2018-07-02 22:12:41 +02:00
}
2018-08-28 00:40:06 +02:00
private static void ProcessKeygen(Context ctx)
{
2018-09-24 21:42:06 +02:00
Console.WriteLine(ExternalKeys.PrintCommonKeys(ctx.Keyset));
2018-08-28 00:40:06 +02:00
}
2018-07-05 23:37:30 +02:00
// For running random stuff
// ReSharper disable once UnusedParameter.Local
private static void CustomTask(Context ctx)
2018-10-01 19:55:10 +02:00
{
2018-07-05 23:37:30 +02:00
}
2018-06-16 19:11:38 +02:00
}
}