A library that reimplements parts of the Nintendo Switch OS
Find a file
2020-03-18 00:07:33 -07:00
build Finish OpenFileSystemWithId enough to work with most content 2020-03-10 15:07:06 -07:00
docs Add a basic Getting Started page (#59) 2019-05-16 14:47:47 -05:00
img Add NDepend logo 2019-04-01 15:07:11 -05:00
src xci test 2020-03-18 00:07:33 -07:00
tests/LibHac.Tests Enable OpenHostFileSystem in FileSystemProxy and add XML docs 2020-03-16 15:07:09 -07:00
.gitattributes Add build script (#20) 2018-11-21 22:57:18 -05:00
.gitignore Add a default, reflection-less Result name resolver 2020-02-27 11:33:39 -07:00
.nuke Add build script (#20) 2018-11-21 22:57:18 -05:00
appveyor.yml Target netstandard2.1 and netcoreapp3.0 (#99) 2019-11-29 13:11:04 -06:00
build.bat Version 0.4.1 2019-06-05 00:29:29 -05:00
build.ps1 Build script updates (#33) 2019-02-16 19:03:56 -06:00
build.sh Update build script permissions 2019-11-26 20:55:10 -06:00
DotnetCliVersion.txt Misc build updates 2020-02-29 01:36:23 -07:00
GitVersion.yml Bump version to 0.9.0 2020-02-28 23:58:29 -07:00
KEYS.md Bump version to 0.5.1 2019-08-11 16:42:17 -05:00
LibHac.sln Remove LibHac.Nand and related projects (#72) 2019-07-14 19:56:02 -05:00
LICENSE Use Storage throughout the library instead of Stream (#18) 2018-11-18 23:20:34 -05:00
nuget.config Simplify CoreRT build 2020-01-17 00:20:24 -07:00
README.md Add a basic Getting Started page (#59) 2019-05-16 14:47:47 -05:00

LibHac

NuGet MyGet AppVeyor Build Status

LibHac is a .NET and .NET Core library for opening, decrypting and extracting common content file formats used by the Nintendo Switch.

Most content is imported and exported using a standard IStorage interface. This means that reading nested file types and encryptions can easily be done by linking different file readers together.
For example, the files from a title stored on the external SD card can be read or extracted in this way.
NAX0 Reader -> NCA Reader -> RomFS Reader -> Individual Files

Getting Started

Library Overview and Samples

hactoolnet

hactoolnet is an example program that uses LibHac. It is used in a similar manner to hactool.

Usage

Usage: hactoolnet.exe [options...] <path>
Options:
  -r, --raw            Keep raw data, don't unpack.
  -y, --verify         Verify all hashes in the input file.
  -h, --enablehash     Enable hash checks when reading the input file.
  -d, --dev            Decrypt with development keys instead of retail.
  -k, --keyset         Load keys from an external file.
  -t, --intype=type    Specify input file type [nca, xci, romfs, pfs0, pk11, pk21, ini1, kip1, switchfs, save, ndv0, keygen, romfsbuild, pfsbuild]
  --titlekeys <file>   Load title keys from an external file.
NCA options:
  --plaintext <file>   Specify file path for saving a decrypted copy of the NCA.
  --header <file>      Specify Header file path.
  --section0 <file>    Specify Section 0 file path.
  --section1 <file>    Specify Section 1 file path.
  --section2 <file>    Specify Section 2 file path.
  --section3 <file>    Specify Section 3 file path.
  --section0dir <dir>  Specify Section 0 directory path.
  --section1dir <dir>  Specify Section 1 directory path.
  --section2dir <dir>  Specify Section 2 directory path.
  --section3dir <dir>  Specify Section 3 directory path.
  --exefs <file>       Specify ExeFS file path.
  --exefsdir <dir>     Specify ExeFS directory path.
  --romfs <file>       Specify RomFS file path.
  --romfsdir <dir>     Specify RomFS directory path.
  --listromfs          List files in RomFS.
  --basenca            Set Base NCA to use with update partitions.
RomFS options:
  --romfsdir <dir>     Specify RomFS directory path.
  --listromfs          List files in RomFS.
RomFS creation options:
                       Input path must be a directory
  --outfile <file>     Specify created RomFS file path.
Partition FS options:
  --outdir <dir>       Specify extracted FS directory path.
Partition FS creation options:
                       Input path must be a directory
  --outfile <file>     Specify created Partition FS file path.
  --hashedfs           Create a hashed Partition FS (HFS0).
XCI options:
  --rootdir <dir>      Specify root XCI directory path.
  --updatedir <dir>    Specify update XCI directory path.
  --normaldir <dir>    Specify normal XCI directory path.
  --securedir <dir>    Specify secure XCI directory path.
  --logodir <dir>      Specify logo XCI directory path.
  --outdir <dir>       Specify XCI directory path.
  --exefs <file>       Specify main ExeFS file path.
  --exefsdir <dir>     Specify main ExeFS directory path.
  --romfs <file>       Specify main RomFS file path.
  --romfsdir <dir>     Specify main RomFS directory path.
  --nspout <file>      Specify file for the created NSP.
Package1 options:
  --outdir <dir>       Specify Package1 directory path.
Package2 options:
  --outdir <dir>       Specify Package2 directory path.
INI1 options:
  --outdir <dir>       Specify INI1 directory path.
Switch FS options:
  --sdseed <seed>      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 <title id>   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)
  --exefsdir <dir>     Specify ExeFS directory path. (--title must be specified)
  --romfs <file>       Specify RomFS directory path. (--title must be specified)
  --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.
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)
  --trim               Trim garbage data in the save file. (Requires device_key in key file)
  --listfiles          List files in save file.
  --repack <dir>       Replaces the contents of the save data with the specified directory.
  --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.

Examples

List applications on a Switch SD card or NAND

hactoolnet -t switchfs --sdseed <sd_seed> --listapps <sd_root_path>

Extract a title from an SD card or NAND as NCA files

hactoolnet -t switchfs --sdseed <sd_seed> --title <title_id> --outdir output <sd_root_path>

Extract the RomFS from a title from an SD card or NAND

hactoolnet -t switchfs --sdseed <sd_seed> --title <title_id> --romfsdir romfs <sd_root_path>

Specifying the base title ID will extract the unpatched title.
Specifying the patch title ID will extract the patched title.

External Keys

For more detailed information on keyset files, see KEYS.md.

Keys can be loaded from a text file by specifying a filename with the -k argument. The file should be in the same format read by hactool:
"Keyset files are text files containing one key per line, in the form "key_name = HEXADECIMALKEY". Case shouldn't matter, nor should whitespace."

Console-unique keys can be loaded from a text file by specifying a filename with the --consolekeys argument. The file format is the same as the main keyset file.

Title keys can be loaded from a text file by specifying a filename with the --titlekeys argument. The file should contain one key per line in the form rights_id,HEXADECIMALKEY.

If a keyfile is not set at the command line, hactoolnet will search for and load keyfiles in $HOME/.switch/prod.keys, $HOME/.switch/console.keys and $HOME/.switch/title.keys.

Special Thanks

This project uses NDepend for static code analysis.

NDepend link