From f8e724fe0b9df65a16ebf26f87641f30011f7e05 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 3 Feb 2019 19:27:09 -0600 Subject: [PATCH] Add RomFS building to hactoolnet --- README.md | 19 +++++++++++++---- src/hactoolnet/CliParser.cs | 9 +++++--- src/hactoolnet/Options.cs | 1 + src/hactoolnet/ProcessRomFsBuild.cs | 32 +++++++++++++++++++++++++++++ src/hactoolnet/Program.cs | 3 +++ 5 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 src/hactoolnet/ProcessRomFsBuild.cs diff --git a/README.md b/README.md index 49409d88..c8ccab69 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,10 @@ Options: -y, --verify Verify all hashes in the input file. -h, --enablehash Enable hash checks when reading the input file. -k, --keyset Load keys from an external file. - -t, --intype=type Specify input file type [nca, xci, romfs, pk11, pk21, ini1, kip1, switchfs, save, keygen] + -t, --intype=type Specify input file type [nca, xci, romfs, pk11, pk21, ini1, kip1, switchfs, save, ndv0, keygen, romfsbuild] --titlekeys Load title keys from an external file. NCA options: + --plaintext Specify file path for saving a decrypted copy of the NCA. --section0 Specify Section 0 file path. --section1 Specify Section 1 file path. --section2 Specify Section 2 file path. @@ -29,15 +30,18 @@ NCA options: --section1dir Specify Section 1 directory path. --section2dir Specify Section 2 directory path. --section3dir Specify Section 3 directory path. - --exefs Specify ExeFS directory path. + --exefs Specify ExeFS file path. --exefsdir Specify ExeFS directory path. - --romfs Specify RomFS directory path. + --romfs Specify RomFS file path. --romfsdir Specify RomFS directory path. --listromfs List files in RomFS. --basenca Set Base NCA to use with update partitions. RomFS options: --romfsdir Specify RomFS directory path. --listromfs List files in RomFS. +RomFS creation options: + Input path must be a directory + --outfile Specify created RomFS file path. XCI options: --rootdir Specify root XCI directory path. --updatedir Specify update XCI directory path. @@ -60,6 +64,7 @@ Switch FS options: --sdseed Set console unique seed for SD card NAX0 encryption. --listapps List application info. --listtitles List title info for all titles. + --listncas List info for all NCAs. --title Specify title ID to use. --outdir <dir> Specify directory path to save title NCAs to. (--title must be specified) --exefs <file> Specify ExeFS directory path. (--title must be specified) @@ -68,10 +73,16 @@ Switch FS options: --romfsdir <dir> Specify RomFS directory path. (--title must be specified) --savedir <dir> Specify save file directory path. -y, --verify Verify all titles, or verify a single title if --title is set. -Savefile options: +Save data options: --outdir <dir> Specify directory path to save contents to. --debugoutdir <dir> Specify directory path to save intermediate data to for debugging. --sign Sign the save file. (Requires device_key in key file) + --listfiles List files in save file. + --replacefile <filename in save> <file> Replaces a file in the save data +NDV0 (Delta) options: + Input delta patch can be a delta NCA file or a delta fragment file. + --basefile <file> Specify base file path. + --outfile Specify patched file path. Keygen options: --outdir <dir> Specify directory path to save key files to. ``` diff --git a/src/hactoolnet/CliParser.cs b/src/hactoolnet/CliParser.cs index 06be3c81..694b508b 100644 --- a/src/hactoolnet/CliParser.cs +++ b/src/hactoolnet/CliParser.cs @@ -162,7 +162,7 @@ namespace hactoolnet sb.AppendLine(" -y, --verify Verify all hashes in the input file."); sb.AppendLine(" -h, --enablehash Enable hash checks when reading the input file."); sb.AppendLine(" -k, --keyset Load keys from an external file."); - sb.AppendLine(" -t, --intype=type Specify input file type [nca, xci, romfs, pk11, pk21, ini1, kip1, switchfs, save, ndv0, keygen]"); + sb.AppendLine(" -t, --intype=type Specify input file type [nca, xci, romfs, pk11, pk21, ini1, kip1, switchfs, save, ndv0, keygen, romfsbuild]"); sb.AppendLine(" --titlekeys <file> Load title keys from an external file."); sb.AppendLine("NCA options:"); sb.AppendLine(" --plaintext <file> Specify file path for saving a decrypted copy of the NCA."); @@ -174,15 +174,18 @@ namespace hactoolnet sb.AppendLine(" --section1dir <dir> Specify Section 1 directory path."); sb.AppendLine(" --section2dir <dir> Specify Section 2 directory path."); sb.AppendLine(" --section3dir <dir> Specify Section 3 directory path."); - sb.AppendLine(" --exefs <file> Specify ExeFS directory path."); + sb.AppendLine(" --exefs <file> Specify ExeFS file path."); sb.AppendLine(" --exefsdir <dir> Specify ExeFS directory path."); - sb.AppendLine(" --romfs <file> Specify RomFS directory path."); + sb.AppendLine(" --romfs <file> Specify RomFS file path."); sb.AppendLine(" --romfsdir <dir> Specify RomFS directory path."); sb.AppendLine(" --listromfs List files in RomFS."); sb.AppendLine(" --basenca Set Base NCA to use with update partitions."); sb.AppendLine("RomFS options:"); sb.AppendLine(" --romfsdir <dir> Specify RomFS directory path."); sb.AppendLine(" --listromfs List files in RomFS."); + sb.AppendLine("RomFS creation options:"); + sb.AppendLine(" Input path must be a directory"); + sb.AppendLine(" --outfile <file> Specify created RomFS file path."); sb.AppendLine("XCI options:"); sb.AppendLine(" --rootdir <dir> Specify root XCI directory path."); sb.AppendLine(" --updatedir <dir> Specify update XCI directory path."); diff --git a/src/hactoolnet/Options.cs b/src/hactoolnet/Options.cs index 4cfdc7af..6ecf38d2 100644 --- a/src/hactoolnet/Options.cs +++ b/src/hactoolnet/Options.cs @@ -64,6 +64,7 @@ namespace hactoolnet Pfs0, Nsp, Romfs, + RomfsBuild, Nax0, Xci, SwitchFs, diff --git a/src/hactoolnet/ProcessRomFsBuild.cs b/src/hactoolnet/ProcessRomFsBuild.cs new file mode 100644 index 00000000..8cd6d525 --- /dev/null +++ b/src/hactoolnet/ProcessRomFsBuild.cs @@ -0,0 +1,32 @@ +using System.IO; +using LibHac.IO; +using LibHac.IO.RomFs; + +namespace hactoolnet +{ + internal static class ProcessRomFsBuild + { + public static void Process(Context ctx) + { + if (ctx.Options.OutFile == null) + { + ctx.Logger.LogMessage("Output file must be specified."); + return; + } + + var localFs = new LocalFileSystem(ctx.Options.InFile); + + var builder = new RomFsBuilder(localFs); + IStorage romfs = builder.Build(); + + ctx.Logger.LogMessage($"Building RomFS as {ctx.Options.OutFile}"); + + using (var outFile = new FileStream(ctx.Options.OutFile, FileMode.Create, FileAccess.ReadWrite)) + { + romfs.CopyToStream(outFile, romfs.Length, ctx.Logger); + } + + ctx.Logger.LogMessage($"Finished writing {ctx.Options.OutFile}"); + } + } +} diff --git a/src/hactoolnet/Program.cs b/src/hactoolnet/Program.cs index 05623145..bc73f0b0 100644 --- a/src/hactoolnet/Program.cs +++ b/src/hactoolnet/Program.cs @@ -64,6 +64,9 @@ namespace hactoolnet case FileType.Romfs: ProcessRomfs.Process(ctx); break; + case FileType.RomfsBuild: + ProcessRomFsBuild.Process(ctx); + break; case FileType.Nax0: break; case FileType.SwitchFs: