Homebrew RELEASE LibHac & hactoolnet v0.1.3

minibar

Member
OP
Newcomer
Joined
Oct 23, 2018
Messages
12
Trophies
0
XP
196
Country
United States
Releases are available on GitHub.

LibHac

LibHac is a .NET Framework and .NET Core library for reading and editing file formats used by the Nintendo Switch.

Supported formats
  • NCA
  • XCI
  • NAX0
  • PFS0/HFS0/NSP
  • RomFS
  • Save file
  • Package1
  • Package2
  • INI1/KIP1
  • CNMT
  • NACP
  • Ticket
  • PRODINFO
  • Switch NAND and SD card

Additional features
  • Save file editing and signing
  • PFS0 creation
  • Switch key derivation
  • Integrity verification of NCA, XCI, etc.
  • Personalized title key reading
  • Read, parse and display information about a Switch NAND or SD card
  • Extract NCA, RomFS and other formats directly from an SD card or NAND, including patched titles
  • And more!

hactoolnet

Hactoolnet is a tool that uses LibHac for viewing and extracting data from common Nintendo Switch file formats. It partially mimics hactool's interface.

Features
  • Dump the container formats that LibHac supports
  • A progress bar!
  • Save file signing
  • Dump RomFS directly from an XCI or SD card
  • Dump SD card titles as NSP files
  • Verify the integrity of all titles on a Switch SD card
  • Switch key derivation
  • Automatic integrity verification of NCA, XCI, etc.
  • Give information about the titles and applications on a Switch NAND or SD card
  • Extract NCA, RomFS and other formats directly from an SD card or NAND, including patched titles

Download

Changelog


v0.2.0

A single-exe version of hactoolnet has been added to the downloads for convenience over using an exe with dlls
  • Use a new `IStorage` interface throughout the library instead of `Stream`
    • This interface is more similar to the `IStorage` interface used by Horizon.
    • Instead of having a Stream that keeps track of the current position, IStorage accepts an offset, buffer, and length when reading or writing.
    • Unlike a Stream, an IStorage instance can be shared between multiple consumers without issue
    • `Stream.AsStorage()` and `IStorage.AsStream()` methods are provided for switching between `Stream` and `IStorage`
  • Improve AES-XTS performance by ~16x
  • Improve AES-CTR performance by 2x
  • Add AES-XTS tests
  • Add benchmarks for AES-XTS and AES-CTR
  • Ability to open a decrypted IStorage of an NCA, Package1 or Package2
  • Validate NCA, NPDM and package2 signatures
  • Add NPDM parsing support
  • Allow more disposal methods to cascade down to the base storage
  • Support writing version 5 of `JournalStorage` used in newer save data files
  • Fix a fatal save allocation table bug that would occur if the last block of the save data FS was read
  • Add a build script

    hactoolnet changes

  • Add the ability to replace files in a save data file (Currently the new file must be the same size as the old file)
  • Add benchmarks for AES-XTS and AES-CTR
  • Change how Switch FS title info is displayed, and add an option to display info on all NCAs

v0.1.3
  • Add basic save file editing. Any files already in the save file can be written to
  • Check validity of save files
  • Check validity of PFS files
  • Check validity of SwitchFS and SD cards
  • Check file hashes in HFS archives
  • Partial NSO support
  • When keys required to decrypt an NCA are missing, throw an exception with information about the missing keys.
  • Add more sanity checks when reading an NCA.
  • Read only the NCA header when first opening an NCA. This allows for reading of partial NCAs and slightly improves performance when opening an NCA.
  • Fix bug in CombinationStream when reading across boundaries

    hactoolnet changes

  • Add option to verify SwitchFS and SD cards
  • Add option to export all keys
  • Add PFS0 extraction
  • Print more information about save files
 
Last edited by minibar,

daedelus82

Well-Known Member
Newcomer
Joined
Jan 5, 2009
Messages
45
Trophies
0
Location
Australia
Website
www.aamon.net
XP
197
Country
Yes. All you'd need from that Switch are its TSEC and Secure Boot keys.
I'm looking to do this now.
I've extracted a save successfully, I have a directory and two files within it.
It's a legit save, I've opened it in a save editor and confirmed.
I'm trying to sign it again, and I'm not sure what command arguments to use to pack it back into a single file + sign it.
Any assistance would be appreciated.

edit: hmm. I'm guessing maybe it can't right now? I only see an Extract method. There are also a whole bunch of header and metadata information which simply doesn't exist in the outdir, so I don't think it would be possible to rebuild from that.
edit2: i'm a little confused how to use it, when you process a savefile with --outdir, you get a directory of files, however when you go to sign a save file, it accepts only a single file as the input, however I can't find a way to repack it back into a single file for signing.
 
Last edited by daedelus82,

blubbflubb

New Member
Newbie
Joined
Jul 29, 2013
Messages
1
Trophies
0
Age
41
XP
34
Country
Gambia, The
I'm looking to do this now.
I've extracted a save successfully, I have a directory and two files within it.
It's a legit save, I've opened it in a save editor and confirmed.
I'm trying to sign it again, and I'm not sure what command arguments to use to pack it back into a single file + sign it.
Any assistance would be appreciated.

edit: hmm. I'm guessing maybe it can't right now? I only see an Extract method. There are also a whole bunch of header and metadata information which simply doesn't exist in the outdir, so I don't think it would be possible to rebuild from that.
edit2: i'm a little confused how to use it, when you process a savefile with --outdir, you get a directory of files, however when you go to sign a save file, it accepts only a single file as the input, however I can't find a way to repack it back into a single file for signing.

This is now possible with v0.2.0.

- memloader and HacDiskMount to copy the savefile from the Switch
- hactoolnet and the outdir option to extract it
- editing the extracted savegame with your preferred method
- hactoolnet and the replacefile option to inject the edited savegame and signing it
- memloader and HacDiskMount to copy it back to the Switch

This way there's never any CFW started on the Switch and no need to deal with NAND backups etc.
The library is awesome and doesn't get nearly as much attention as it deserves.
 

wwm

New Member
Newbie
Joined
Jan 2, 2019
Messages
2
Trophies
0
Age
31
XP
31
Country
United States
Thanks for making and releasing this tool to the public! It's extremely useful!

I was wondering if someone could help me though: I've edited my BotW save and am trying to use '--replacefile' to put my game_data.sav back into the main file for that title. (ex. 00000000000000xx )

The problem is that BotW has multiple folders for each individual save (00, 01, 02, 03, 04, etc.) and I'm not sure how to include the folder into the parameter. The error is receive is "Unable to find the specified file"

Any help would be appreciated!
 
  • Like
Reactions: H1B1Esquire

minibar

Member
OP
Newcomer
Joined
Oct 23, 2018
Messages
12
Trophies
0
XP
196
Country
United States
The problem is that BotW has multiple folders for each individual save (00, 01, 02, 03, 04, etc.) and I'm not sure how to include the folder into the parameter. The error is receive is "Unable to find the specified file"

You need to include the entire path in the argument. e.g. /folder/folder/file

You can use --listfiles to get a list of all the files in the save data
 
  • Like
Reactions: wwm

minibar

Member
OP
Newcomer
Joined
Oct 23, 2018
Messages
12
Trophies
0
XP
196
Country
United States
I'm a little late posting it here, but v0.2.0 has been released.

Download

v0.2.0

A single-exe version of hactoolnet has been added to the downloads for convenience over using an exe with dlls
  • Use a new `IStorage` interface throughout the library instead of `Stream`
    • This interface is more similar to the `IStorage` interface used by Horizon.
    • Instead of having a Stream that keeps track of the current position, IStorage accepts an offset, buffer, and length when reading or writing.
    • Unlike a Stream, an IStorage instance can be shared between multiple consumers without issue
    • `Stream.AsStorage()` and `IStorage.AsStream()` methods are provided for switching between `Stream` and `IStorage`
  • Improve AES-XTS performance by ~16x
  • Improve AES-CTR performance by 2x
  • Add AES-XTS tests
  • Add benchmarks for AES-XTS and AES-CTR
  • Ability to open a decrypted IStorage of an NCA, Package1 or Package2
  • Validate NCA, NPDM and package2 signatures
  • Add NPDM parsing support
  • Allow more disposal methods to cascade down to the base storage
  • Support writing version 5 of `JournalStorage` used in newer save data files
  • Fix a fatal save allocation table bug that would occur if the last block of the save data FS was read
  • Add a build script

    hactoolnet changes

  • Add the ability to replace files in a save data file (Currently the new file must be the same size as the old file)
  • Add benchmarks for AES-XTS and AES-CTR
  • Change how Switch FS title info is displayed, and add an option to display info on all NCAs
 

magpte

Member
Newcomer
Joined
Sep 27, 2016
Messages
20
Trophies
0
Age
20
XP
72
Country
Switzerland
Oof, I was using a backslash for the paths.

Problem solved, thanks for the help!

As I am running system 7.0, and I had already got the tsec_key, secure_boot_key, device_key.
I can replace save but can't sign it as it Required more key. it memtioned for header key, but from the post above and readme in hactoolnet, only tsec_key, secure_boot_key, device_key is ok. may I know if 7.0.0 update is not capable so far?
 
Last edited by magpte,

reinaldox_

Active Member
Newcomer
Joined
Aug 18, 2009
Messages
31
Trophies
0
XP
202
Country
United States
I'm looking to do this now.
I've extracted a save successfully, I have a directory and two files within it.
It's a legit save, I've opened it in a save editor and confirmed.
I'm trying to sign it again, and I'm not sure what command arguments to use to pack it back into a single file + sign it.
Any assistance would be appreciated.

edit: hmm. I'm guessing maybe it can't right now? I only see an Extract method. There are also a whole bunch of header and metadata information which simply doesn't exist in the outdir, so I don't think it would be possible to rebuild from that.
edit2: i'm a little confused how to use it, when you process a savefile with --outdir, you get a directory of files, however when you go to sign a save file, it accepts only a single file as the input, however I can't find a way to repack it back into a single file for signing.


dude can you help me? i have the main save files (ex. 00000000000000xx ) but i dont have a clue how to use hactoolnet. can you make a small tutorial? please. i need to extract the saves inside those files :(
 

minibar

Member
OP
Newcomer
Joined
Oct 23, 2018
Messages
12
Trophies
0
XP
196
Country
United States
dude can you help me? i have the main save files (ex. 00000000000000xx ) but i dont have a clue how to use hactoolnet. can you make a small tutorial? please. i need to extract the saves inside those files :(

This command will extract the save:

hactoolnet.exe -t save <your save file name> --outdir <output folder name>
 
  • Like
Reactions: reinaldox_

kimbra

Well-Known Member
Newcomer
Joined
Jun 6, 2019
Messages
46
Trophies
0
Age
27
Location
United States
XP
957
Country
United States
Wow, this seems to be a great find! According to everything I read in this thread, I should be able to backup sysNAND regularly, extract save data from the sysNAND for editing, inject the edited save data back into the sysNAND, and revert to this new sysNAND “backup” to have edited save data on an OFW Switch console?
 

kimbra

Well-Known Member
Newcomer
Joined
Jun 6, 2019
Messages
46
Trophies
0
Age
27
Location
United States
XP
957
Country
United States
You should, but I have no idea how to use it.
I'm attempting it right now. I believe I just managed to successfully back up my NAND, mount it, retrieve workable save data files, edit them, replace and resign them back into NAND format, and I'm currently restoring this edited NAND to see what happens.

I will keep you updated, and if it works I'll also make an easy-to-follow post on how to do it for pretty much any game!

EDIT1: so I was unsuccessful unfortunately. When the restore completed, I popped in a game whose save data I edited, and when I tried to start the game from the home screen, it immediately crashed to a black screen and the console offered to send this data to Nintendo. Wondering what I did wrong at this point :wacko:
 
Last edited by kimbra,
  • Like
Reactions: MushroomGod
General chit-chat
Help Users
  • No one is chatting at the moment.
    SG854 @ SG854: Even if they fix these issues I'm still not buying it. $30 for drip fed n64 games is fucking...