LibHac/Net/Program.cs

70 lines
2.1 KiB
C#
Raw Normal View History

2018-07-28 20:33:34 +02:00
using System;
using System.IO;
using System.Text;
using libhac;
namespace Net
{
public static class Program
{
public static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
var ctx = new Context();
ctx.Options = CliParser.Parse(args);
if (ctx.Options == null) return;
using (var logger = new ProgressBar())
{
ctx.Logger = logger;
OpenKeyset(ctx);
ProcessNet(ctx);
}
}
private static void ProcessNet(Context ctx)
{
if (ctx.Options.DeviceId == 0)
{
CliParser.PrintWithUsage("A non-zero Device ID must be set.");
return;
}
var net = new NetContext(ctx);
var cnmt = net.GetCnmt(ctx.Options.TitleId, ctx.Options.Version);
foreach (var entry in cnmt.ContentEntries)
{
Console.WriteLine($"{entry.NcaId.ToHexString()} {entry.Type}");
}
}
private static void OpenKeyset(Context ctx)
{
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var homeKeyFile = Path.Combine(home, ".switch", "prod.keys");
var homeTitleKeyFile = Path.Combine(home, ".switch", "title.keys");
var homeConsoleKeyFile = Path.Combine(home, ".switch", "console.keys");
var keyFile = ctx.Options.Keyfile;
var titleKeyFile = ctx.Options.TitleKeyFile;
var consoleKeyFile = ctx.Options.ConsoleKeyFile;
if (keyFile == null && File.Exists(homeKeyFile))
{
keyFile = homeKeyFile;
}
if (titleKeyFile == null && File.Exists(homeTitleKeyFile))
{
titleKeyFile = homeTitleKeyFile;
}
if (consoleKeyFile == null && File.Exists(homeConsoleKeyFile))
{
consoleKeyFile = homeConsoleKeyFile;
}
ctx.Keyset = ExternalKeys.ReadKeyFile(keyFile, titleKeyFile, consoleKeyFile, ctx.Logger);
}
}
}