1. minibar

    OP minibar Member
    Newcomer

    Joined:
    Oct 23, 2018
    Messages:
    12
    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, Jan 18, 2019
    falcorr, SupImBirDy, klear and 13 others like this.
  2. XorTroll

    XorTroll Tired of classic HOME menu
    Developer

    Joined:
    Dec 28, 2017
    Messages:
    632
    Country:
    Spain
    Yeah this libraries are really amazing, I'll probably start using them in NSPack or any other tools.
    Really nice work man!
     
    NoNAND and H1B1Esquire like this.
  3. daedelus82

    daedelus82 Member
    Newcomer

    Joined:
    Jan 5, 2009
    Messages:
    45
    Country:
    Wow, nice work.

    So save signing would potentially allow us to inject a modified save to an unmodified console, for example via hacdiskmount?
     
  4. minibar

    OP minibar Member
    Newcomer

    Joined:
    Oct 23, 2018
    Messages:
    12
    Country:
    United States
    Yes. All you'd need from that Switch are its TSEC and Secure Boot keys.
     
  5. daedelus82

    daedelus82 Member
    Newcomer

    Joined:
    Jan 5, 2009
    Messages:
    45
    Country:
    Thanks so much for confirming, and thanks for this awesome library.
     
    H1B1Esquire likes this.
  6. daedelus82

    daedelus82 Member
    Newcomer

    Joined:
    Jan 5, 2009
    Messages:
    45
    Country:
    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, Nov 20, 2018
  7. Joom

    Joom  ❤❤❤
    Member

    Joined:
    Jan 8, 2016
    Messages:
    5,421
    Country:
    United States
    Why .NET? :[
     
  8. blubbflubb

    blubbflubb Newbie
    Newcomer

    Joined:
    Jul 29, 2013
    Messages:
    1
    Country:
    Gambia, The
    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.
     
    kimbra, wwm and hippy dave like this.
  9. wwm

    wwm Newbie
    Newcomer

    Joined:
    Jan 2, 2019
    Messages:
    2
    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!
     
    H1B1Esquire likes this.
  10. minibar

    OP minibar Member
    Newcomer

    Joined:
    Oct 23, 2018
    Messages:
    12
    Country:
    United States
    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
     
    wwm likes this.
  11. wwm

    wwm Newbie
    Newcomer

    Joined:
    Jan 2, 2019
    Messages:
    2
    Country:
    United States
    Oof, I was using a backslash for the paths.

    Problem solved, thanks for the help!
     
  12. minibar

    OP minibar Member
    Newcomer

    Joined:
    Oct 23, 2018
    Messages:
    12
    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
     
    klear, H1B1Esquire and hippy dave like this.
  13. magpte

    magpte Member
    Newcomer

    Joined:
    Sep 27, 2016
    Messages:
    20
    Country:
    Switzerland
    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, Feb 13, 2019
  14. reinaldox_

    reinaldox_ Member
    Newcomer

    Joined:
    Aug 18, 2009
    Messages:
    31
    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 :(
     
  15. minibar

    OP minibar Member
    Newcomer

    Joined:
    Oct 23, 2018
    Messages:
    12
    Country:
    United States
    This command will extract the save:

    hactoolnet.exe -t save <your save file name> --outdir <output folder name>
     
    reinaldox_ likes this.
  16. MushroomGod

    MushroomGod Member
    Newcomer

    Joined:
    Apr 22, 2019
    Messages:
    21
    Country:
    United States
    Can someone give me the command to repack a save file? Thanks in advance.
     
  17. kimbra

    kimbra Member
    Newcomer

    Joined:
    Jun 6, 2019
    Messages:
    41
    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?
     
  18. MushroomGod

    MushroomGod Member
    Newcomer

    Joined:
    Apr 22, 2019
    Messages:
    21
    Country:
    United States
    You should, but I have no idea how to use it.
     
  19. kimbra

    kimbra Member
    Newcomer

    Joined:
    Jun 6, 2019
    Messages:
    41
    Country:
    United States
    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, Jun 9, 2019
    MushroomGod likes this.
  20. aarti

    aarti Killua Zoldyck
    Member

    Joined:
    Jul 24, 2017
    Messages:
    517
    Country:
    Germany
    What is the command for this?
     
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - hactoolnet, LibHac,