RELEASE LibHac & hactoolnet v0.1.3

Discussion in 'Switch - Emulation, Homebrew & Software Projects' started by minibar, Oct 23, 2018.

  1. minibar
    OP

    minibar Newbie

    Newcomer
    1
    Oct 23, 2018
    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

    Changelog

    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, Nov 3, 2018
    Garou, 8BitWonder, igotario2 and 7 others like this.
  2. XorTroll

    XorTroll Dev: Goldleaf, Brew.js, Plutonium, Brew.NET...

    Member
    9
    Dec 28, 2017
    Spain
    Nowhere
    Yeah this libraries are really amazing, I'll probably start using them in NSPack or any other tools.
    Really nice work man!
     
  3. daedelus82

    daedelus82 Member

    Newcomer
    2
    Jan 5, 2009
    Australia
    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 Newbie

    Newcomer
    1
    Oct 23, 2018
    United States
    Yes. All you'd need from that Switch are its TSEC and Secure Boot keys.
     
  5. daedelus82

    daedelus82 Member

    Newcomer
    2
    Jan 5, 2009
    Australia
    Thanks so much for confirming, and thanks for this awesome library.
     
  6. daedelus82

    daedelus82 Member

    Newcomer
    2
    Jan 5, 2009
    Australia
    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
    13
    Jan 8, 2016
    United States
    Why .NET? :[
     
  8. blubbflubb

    blubbflubb Newbie

    Newcomer
    1
    Jul 29, 2013
    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.
     
    wwm and hippy dave like this.