Code Monkey home page Code Monkey logo

nstool's Introduction

Heyo 😁 👋🏻

My name is Jack, I'm a 👨🏻‍💻 software engineer & hacker.

My GitHub is used to host my hobby projects:

  • 🔍 Reverse engineering proprietary formats
  • 🛠 Writing cross-platform developer tools

You'll find me programming in:

  • C++ / C
  • Python

I'm learning:

  • Rust
  • 📱⌚️ Swift / iOS Development
  • Web APIs and related data models

Open Source Projects

Frameworks

  • libtoolchain - Library to ease the development of toolchain applications. (C++11)
  • libpietendo - Library for processing Nintendo file formats. (C++11)

Repackaged 3rd Party Frameworks

Applications

  • nstool - General purpose read/extract tool for Nintendo Switch file formats. (C++11)

nstool's People

Contributors

jakcron avatar sagumamugas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nstool's Issues

Cant extract Mario Kart 8 Update 2.0.0 nsp

I am on windows using NSTool v1.6.3,

This is the command I am using:

nstool.exe -k prod.keys --fstree "MK8 UPDATE 2.0.0.nsp"

This is thew error I get

[nn::hac::PartitionFsMetaGenerator ERROR] sPfsFile entry had unexpected data offset.

build errors on gcc-11.1.0 and clang++ 13.0.0 (fix included)

I am hitting plenty of errors about unknown numeric_limits

/data/sources/switch/nstool/deps/libtoolchain/include/tc/crypto/detail/XtsModeImpl.h: In member function ‘void tc::crypto::detail::XtsModeImpl<BlockCipher>::incr_tweak_be(byte_t*, uint64_t)’:
/data/sources/switch/nstool/deps/libtoolchain/include/tc/crypto/detailXtsModeImpl.h:275:51: error: ‘numeric_limits’ is not a member of ‘std’
  275 |                         uint64_t remaining = std::numeric_limits<uint64_t>::max() - word;
      |

the fix is to add

include <limits>

to deps/libtoolchain/include/tc/types.h

that seems to fix the build.

[BUG] NSTool reports wrong or unknown NCA Type

About

When reading NCA files, with the exception of "Program" titles, Content Type under [NCA Header] is formatted incorrectly.

Example

This was taken from the *.cnmt.nca from Just Dance 2022 [0100EA6014BB8000][v0].nsp

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    unk_0x01
  Key Generation:  11
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0xe00
  ProgID:          0x0100ea6014bb8000
  Content Index:   0
  SdkAddon Ver.:   12.0.0 (v201326592)

[Feature] Add support for Personalised eTickets

About

NSTool doesn't currently support personalised tickets, these are generated for paid content usually, and are locked to the device they were downloaded on.

Can support for this please be added to:

  • processing tickets directly
  • implicitly processing tickets to decrypt NCAs

Technical Details

Ticket Data

Only the Ticket Body is different, for reference included here:

struct sTicketBody_v2
{
	tc::bn::string<ticket::kIssuerSize> issuer;
	std::array<byte_t, ticket::kEncTitleKeySize> enc_title_key;
	byte_t format_version;
	byte_t title_key_enc_type;
	tc::bn::le16<uint16_t> ticket_version;
	byte_t license_type;
	byte_t common_key_id;
	tc::bn::bitarray<sizeof(uint16_t)> property_mask;
	std::array<byte_t, ticket::kReservedRegionSize> reserved_region; // explicitly reserved
	tc::bn::le64<uint64_t> ticket_id;
	tc::bn::le64<uint64_t> device_id;
	std::array<byte_t, ticket::kRightsIdSize> rights_id;
	tc::bn::le32<uint32_t> account_id;
	tc::bn::le32<uint32_t> sect_total_size;
	tc::bn::le32<uint32_t> sect_header_offset;
	tc::bn::le16<uint16_t> sect_num;
	tc::bn::le16<uint16_t> sect_entry_size;
};

When comparing personalised tickets with common tickets, these are the differences:

  • title_key_enc_type == 1
  • enc_title_key has an RSA2048-OAEP-SHA2256 encryption layer on top of the regular AES128-CBC, this RSA key is device specific, and is required
    • No label is used for the OAEP layer.
  • account_id should be non-zero
    • I believe this links it to the originating Nintendo Account
  • device_id should be non-zero
    • My understanding is each Nintendo Switch has it's own unique eTicket Personalisation RSA key
    • The device ID links the ticket to originating Nintendo Switch, and may be usable for selecting the correct Device RSA key if multiple are loaded at once into NSTool Key Manager.

How does the user get the RSA key?

Currently if the user generates prod.keys using LockPick_RCM, the RSA Key Pair is dumped with the name eticket_rsa_keypair.

It appears to be the raw decrypted structure from the Switch OS:

{
	std::array<byte_t, 0x100> private_exponent;
	std::array<byte_t, 0x100> modulus;
	std::array<byte_t, 0x004> public_exponent;
	tc::bn::pad<0xC>          reserved;
};

[Bug] Extracting single file - access denied

Version: 1.7.0
Built: 15:09:37 Jan 21 2023
OS: Windows 11

I thoroughly read the documentation about extracting files. I am unable to extract single files from any archive without editing your source code. Even when the program absolutely has write access to the given directory an access is denied error is thrown. This line in FsProcess.cpp is the culprit. I commented out this line and the first try/catch and the file was extracted successfully.

local_fs->getDirectoryListing(parent_dir_path, dir_listing);

nstool/src/FsProcess.cpp

Lines 121 to 135 in 7abcedb

try {
tc::io::sDirectoryListing dir_listing;
local_fs->getDirectoryListing(itr->extract_path, dir_listing);
tc::io::Path file_extract_path = itr->extract_path + itr->virtual_path.back();
fmt::print("Saving {:s}...\n", file_extract_path.to_string());
writeStreamToFile(file_stream, itr->extract_path + itr->virtual_path.back(), mDataCache);
continue;
} catch (tc::io::DirectoryNotFoundException&) {
// acceptable exception, just means directory didn't exist
}

This means we need to clarify and separate some parameters so we can rely on separate functions instead of one big function.

Perhaps:

-x --extract: Extract all files or extract a single file if an optional value is supplied.
-o --output: Specify the output path.
-n --name: Overwrite the original file name with one you supply.

Extract all files:
.\nstool --output "./files" --extract

Extract one file:
.\nstool --output "./files" --extract "f79d12018da9db962f796fad2256fdfb.cnmt.nca"

Extract one file and give it a new name:
.\nstool --output "./files" --extract "f79d12018da9db962f796fad2256fdfb.cnmt.nca" --name "meta.nca"

Confirming this is a valid file

.\nstool.exe --fstree "test.nsp"

[PartitionFs]
  Type:        PFS0
  FileNum:     6
[PartitionFs/Tree]
 Root:/
  0100100016fb0000000000000000000e.tik
  0100100016fb0000000000000000000e.cert
  f79d12018da9db962f796fad2256fdfb.cnmt.nca
  b129954666b4baa187ad57e15cd87e49.nca
  5fb8eb95a47d349cfd0d7bfab12c2674.nca
  65a1ed53bb896c71ec9e6af3568f6a59.nca

Extracting all files is successful

.\nstool.exe --extract "./" "test.nsp"

[PartitionFs]
  Type:        PFS0
  FileNum:     6
[PartitionFs/Extract]
Saving .\0100100016fb0000000000000000000e.tik...
Saving .\0100100016fb0000000000000000000e.cert...
Saving .\f79d12018da9db962f796fad2256fdfb.cnmt.nca...
Saving .\b129954666b4baa187ad57e15cd87e49.nca...
Saving .\5fb8eb95a47d349cfd0d7bfab12c2674.nca...
Saving .\65a1ed53bb896c71ec9e6af3568f6a59.nca...

Extracting a single file fails

.\nstool.exe --extract "f79d12018da9db962f796fad2256fdfb.cnmt.nca" "./" "test.nsp"

[PartitionFs/Extract]
[tc::io::FileStream::open() ERROR] Access is denied.

Verification and Extraction failing on DBI NROs

Through nton, it's failing both verification and nacp extraction calls in the same way. I've tried various versions of DBI NROs, like the last few releases, releases from v3xx era, v2xx era, and so on with the same issue.

The only actual error message I seem to get is [tc::io::FileStream::read() ERROR] ptr was null

image

[make] No instructions to clone git submodules prior to using make

Downloaded the latest source and attempted to compile on ubuntu 20.04, you receive this error
CXX src/util.cpp In file included from src/util.h:2, from src/util.cpp:1: src/types.h:2:10: fatal error: tc/types.h: No such file or directory 2 | #include <tc/types.h> | ^~~~~~~~~~~~ compilation terminated. make: *** [makefile:130: src/util.o] Error 1

After spending an hour+ googling around this file as far as I can surmise no longer lives in the tc tool which is now part of the iproute2 package.

Please consider updating these dependencies or at least making a link or download available on where to get them from in order to compile the code.

I attempted to run your pre-compiled and it died trying to find old versions of GLIBC. Consider recompiling with a new version of Linux or specifying what you are running.

Extraction failed - NCA Partition 1 not readable. (Indirect storage not ascending ordered.)

Trying to extract the 1.3.0 update NCA for Sonic Frontiers and failing miserably because of this error which I've no clue what to do about.

>nstool -v -y -x "../Sonic Frontiers/GAME/patch" --titlekey 26B285006A0260150DEFC0F2DE515336 --basenca "../Sonic Frontiers/GAME/raw/48494a74aade50fac84d1a049823bcef.nca" "../Sonic Frontiers/GAME/patch/2b035deffd1fc67261bb36e27ba9cae7.nca"
[NCA Content Key]
  AES-CTR Key: 13E3945E2056BCCC37CAF44EC62513BF
stream properties: canRead()  = true
stream properties: canWrite() = false
stream properties: canSeek()  = true
[WARNING] NCA Header Main Signature: FAIL
[WARNING] ACID Signature: FAIL (Failed to verify Access Control Info Desc)
[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    Program
  Key Generation:  14
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x4ffa4200
  ProgID:          0x01004ad014bf0000
  Content Index:   0
  SdkAddon Ver.:   13.3.2 (v218300928)
  RightsId:        01004AD014BF0800000000000000000E
  Partitions:
    0:
      Offset:      0x4e1c8200
      Size:        0x1ddc000
      Format Type: PartitionFs
      Hash Type:   HierarchicalSha256
      Enc. Type:   AesCtr
      AesCtr Counter:
        00000001000000040000000004E1C820
      HierarchicalSha256 Header:
        Master Hash:
          46240DC3F67DEEDF5E231160A1F3B4D6
          4E4301051886585D6A6E8CBD6C62A7DF
        HashBlockSize:     0x8000
        Hash Layer 0:
          Offset:          0x0
          Size:            0x7760
        Data Layer:
          Offset:          0x8000
          Size:            0x1dd1db0
    1:
      Offset:      0x4000
      Size:        0x4e1c4200
      Format Type: RomFs
      Hash Type:   HierarchicalIntegrity
      Enc. Type:   AesCtrEx
      HierarchicalIntegrity Header:
        Hash Layer 0:
          Offset:          0x0
          Size:            0x4000
          BlockSize:       0x4000
        Hash Layer 1:
          Offset:          0x4000
          Size:            0x4000
          BlockSize:       0x4000
        Hash Layer 2:
          Offset:          0x8000
          Size:            0x4000
          BlockSize:       0x4000
        Hash Layer 3:
          Offset:          0xc000
          Size:            0xc000
          BlockSize:       0x4000
        Hash Layer 4:
          Offset:          0x18000
          Size:            0x15e0000
          BlockSize:       0x4000
        Data Layer:
          Offset:          0x15f8000
          Size:            0x2bbbc1794
          BlockSize:       0x4000
        Master Hash 0:
          BFB6F3EE50BC0DD063DA3FBBAED5B748
          99886960091668A410F950BB50388041
[WARNING] NCA Partition 1 not readable. (Indirect storage not ascending ordered.)
[ContentArchive/Extract]
Saving ..\Sonic Frontiers\GAME\patch\0\main...
Saving ..\Sonic Frontiers\GAME\patch\0\main.npdm...
Saving ..\Sonic Frontiers\GAME\patch\0\rtld...
Saving ..\Sonic Frontiers\GAME\patch\0\sdk...

Alternatively, I can use a plaintext version of the base NCA (decrypted with hactool), though that just makes nstool output just the AES-CTR key and nothing else happens.

>nstool -v -y -x "../Sonic Frontiers/GAME/patch" --titlekey 26B285006A0260150DEFC0F2DE515336 --basenca "../Sonic Frontiers/GAME/raw/plaintext.nca" "../Sonic Frontiers/GAME/patch/2b035deffd1fc67261bb36e27ba9cae7.nca"
[NCA Content Key]
  AES-CTR Key: 13E3945E2056BCCC37CAF44EC62513BF

cant extract minecraft romfs

nstool.exe -x ./ romfs.bin
[RomFs]
DirNum: 88
FileNum: 1284
[RomFs/Extract]
Saving ./Empty.txt...
[tc::io::SubStream::seek() ERROR] Failed to set stream position (stream is disposed)

[nstool] Release 1.7.0 fails to run on ubuntu 20.04

The latest release will not run on unbutu 20.04 receive errors:

cclansman@plexServer:~/repos/zelda3/platform/switch$ unzip nstool-v1.7.0-ubuntu_x86_64.zip 
Archive:  nstool-v1.7.0-ubuntu_x86_64.zip
  inflating: nstool                  
cclansman@plexServer:~/repos/zelda3/platform/switch$ chmod +x nstool
cclansman@plexServer:~/repos/zelda3/platform/switch$ ./nstool
./nstool: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./nstool)
./nstool: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by ./nstool)
./nstool: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./nstool)

Version 1.6.6 is working fine

Data layer block(s) failed hash validation when trying to extract

When trying to extract Zelda Totk the following error is shown

Saving .\app\1\Cull\MainField\E-5_X0Z1.bcul.zs...
[pie::hac::HierarchicalIntegrityStream ERROR] Data layer block(s) failed hash validation.

With hactool the file could be extracted without issues

Info from nstool about the file that fails to extract.

stream properties: canRead()  = true
stream properties: canWrite() = false
stream properties: canSeek()  = true
[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    Program
  Key Generation:  15
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x3fe270000
  ProgID:          0x0100f2c0115b6000
  Content Index:   0
  SdkAddon Ver.:   15.3.1 (v251855104)
  RightsId:        0100F2C0115B6000000000000000000F

Problem NCA

Hello
I used XCI-Explorer-v2.0.0 extracted .nca and .tik form .Nsp file.

I don't know the command to extract with nstool.exe.

after I extracted .nca with the following command but there is an error

Capture d’écran 2023-01-28 225637

Thank you for you help -_-

How to extract NCA patch file?

The tool is very useful that I can extract all .nsp files I got. But I only succeeded in extracting .nca files for base game.

For all patch/update, I got the following error:

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    Program
  Key Generation:  0
  Kaek Index:      Application (0)
  Size:            0x926a400
  ProgID:          0x01001d900d9ac000
  Content Index:   0
  SdkAddon Ver.:   v134348800 (8.2.0)
[PartitionFS]
  Type:        PFS0
  FileNum:     4
  MountPoint:  program:/code/
[WARNING] NCA Partition 1 not readable. (EncryptionType(AesCtrEx): UNSUPPORTED)

One example would be this file, where the extracted file with name 8759c093c9ac45ba455929e61d4a0195.nca cannot be further extracted and will produce the error above.

Where are the extracted game files of XCI image

I used nstool -x ./extract_dir/ C:\Users\frank\Downloads\Digimon_Story_Cyber_Sleuth_Hackers_Memory_JPN_V1.0.2_Switch-xci.com.xci
It extracted successfully, but I don't know where the extracted game files are....

memcpy not declared

rena@gabumon:…/projects/hax/switch/NXTools> make
cd lib && make && cd ..
make[1]: Entering directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib'
make[2]: Entering directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libfnd'
ar cr -o libfnd.a source/StringConv.o source/SimpleTextOutput.o source/SimpleFile.o source/ResourceFileReader.o source/Exception.o source/io.o 
make[2]: Leaving directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libfnd'
make[2]: Entering directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libcrypto'
ar cr -o libcrypto.a source/rsa_wrapper.o source/sha_wrapper.o source/base64_wrapper.o source/aes_wrapper.o   source/libpolarssl/source/sha1.o source/libpolarssl/source/rsa.o source/libpolarssl/source/md_wrap.o source/libpolarssl/source/sha2.o source/libpolarssl/source/md.o source/libpolarssl/source/base64.o source/libpolarssl/source/aes.o source/libpolarssl/source/bignum.o
make[2]: Leaving directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libcrypto'
make[2]: Entering directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libcompress'
ar cr -o libcompress.a source/lz4_wrapper.o   source/lz4/lz4.o
make[2]: Leaving directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libcompress'
make[2]: Entering directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libes'
ar cr -o libes.a source/SectionHeader_V2.o source/TicketBody_V2.o 
make[2]: Leaving directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libes'
make[2]: Entering directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libpki'
ar cr -o libpki.a source/SignatureBlock.o source/CertificateBody.o source/SignUtils.o 
make[2]: Leaving directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libpki'
make[2]: Entering directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libnx'
g++ -std=c++11 -I"include"  -I"../libfnd/include"  -I"../libcrypto/include" -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value -Wno-unused-but-set-variable   -c -o source/NroHeader.o source/NroHeader.cpp
g++ -std=c++11 -I"include"  -I"../libfnd/include"  -I"../libcrypto/include" -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value -Wno-unused-but-set-variable   -c -o source/FileSystemAccessControlBinary.o source/FileSystemAccessControlBinary.cpp
g++ -std=c++11 -I"include"  -I"../libfnd/include"  -I"../libcrypto/include" -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value -Wno-unused-but-set-variable   -c -o source/AesKeygen.o source/AesKeygen.cpp
g++ -std=c++11 -I"include"  -I"../libfnd/include"  -I"../libcrypto/include" -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value -Wno-unused-but-set-variable   -c -o source/NcaUtils.o source/NcaUtils.cpp
g++ -std=c++11 -I"include"  -I"../libfnd/include"  -I"../libcrypto/include" -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value -Wno-unused-but-set-variable   -c -o source/ApplicationControlPropertyBinary.o source/ApplicationControlPropertyBinary.cpp
g++ -std=c++11 -I"include"  -I"../libfnd/include"  -I"../libcrypto/include" -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value -Wno-unused-but-set-variable   -c -o source/ServiceAccessControlBinary.o source/ServiceAccessControlBinary.cpp
g++ -std=c++11 -I"include"  -I"../libfnd/include"  -I"../libcrypto/include" -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value -Wno-unused-but-set-variable   -c -o source/ContentMetaBinary.o source/ContentMetaBinary.cpp
In file included from include/nx/nca.h:5,
                 from include/nx/NcaUtils.h:2,
                 from source/NcaUtils.cpp:1:
../libcrypto/include/crypto/rsa.h: In member function ‘void crypto::rsa::sRsa1024Key::operator=(const crypto::rsa::sRsa1024Key&)’:
../libcrypto/include/crypto/rsa.h:31:18: warning: passing argument 1 to restrict-qualified parameter aliases with argument 2 [-Wrestrict]
     memcpy(this->modulus, modulus, kRsa1024Size);
            ~~~~~~^~~~~~~  ~~~~~~~
../libcrypto/include/crypto/rsa.h:32:18: warning: passing argument 1 to restrict-qualified parameter aliases with argument 2 [-Wrestrict]
     memcpy(this->priv_exponent, priv_exponent, kRsa1024Size);
            ~~~~~~^~~~~~~~~~~~~  ~~~~~~~~~~~~~
In file included from source/NroHeader.cpp:1:
include/nx/NroHeader.h: In member function ‘void nx::NroHeader::sRoCrt::operator=(const nx::NroHeader::sRoCrt&)’:
include/nx/NroHeader.h:18:5: error: ‘memcpy’ was not declared in this scope
     memcpy(data, other.data, nro::kRoCrtSize);
     ^~~~~~
include/nx/NroHeader.h:18:5: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
include/nx/NroHeader.h:5:1:
+#include <cstring>
 
include/nx/NroHeader.h:18:5:
     memcpy(data, other.data, nro::kRoCrtSize);
     ^~~~~~
include/nx/NroHeader.h: In member function ‘bool nx::NroHeader::sRoCrt::operator==(const nx::NroHeader::sRoCrt&) const’:
include/nx/NroHeader.h:23:12: error: ‘memcmp’ was not declared in this scope
     return memcmp(data, other.data, nro::kRoCrtSize) == 0;
            ^~~~~~
include/nx/NroHeader.h:23:12: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
include/nx/NroHeader.h: In member function ‘void nx::NroHeader::sModuleId::operator=(const nx::NroHeader::sModuleId&)’:
include/nx/NroHeader.h:38:5: error: ‘memcpy’ was not declared in this scope
     memcpy(data, other.data, nro::kModuleIdSize);
     ^~~~~~
include/nx/NroHeader.h:38:5: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
include/nx/NroHeader.h: In member function ‘bool nx::NroHeader::sModuleId::operator==(const nx::NroHeader::sModuleId&) const’:
include/nx/NroHeader.h:43:12: error: ‘memcmp’ was not declared in this scope
     return memcmp(data, other.data, nro::kModuleIdSize) == 0;
            ^~~~~~
include/nx/NroHeader.h:43:12: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
source/NroHeader.cpp: In member function ‘virtual void nx::NroHeader::toBytes()’:
source/NroHeader.cpp:60:2: error: ‘memcpy’ was not declared in this scope
  memcpy(hdr->ro_crt, mRoCrt.data, nro::kRoCrtSize);
  ^~~~~~
source/NroHeader.cpp:60:2: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
source/NroHeader.cpp:2:1:
+#include <cstring>
 
source/NroHeader.cpp:60:2:
  memcpy(hdr->ro_crt, mRoCrt.data, nro::kRoCrtSize);
  ^~~~~~
source/NroHeader.cpp: In member function ‘virtual void nx::NroHeader::fromBytes(const byte_t*, size_t)’:
source/NroHeader.cpp:109:2: error: ‘memcpy’ was not declared in this scope
  memcpy(mRawBinary.data(), data, mRawBinary.size());
  ^~~~~~
source/NroHeader.cpp:109:2: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
source/NroHeader.cpp: In member function ‘virtual void nx::NroHeader::clear()’:
source/NroHeader.cpp:161:2: error: ‘memset’ was not declared in this scope
  memset(&mRoCrt, 0, sizeof(mRoCrt));
  ^~~~~~
source/NroHeader.cpp:161:2: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
g++ -std=c++11 -I"include"  -I"../libfnd/include"  -I"../libcrypto/include" -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value -Wno-unused-but-set-variable   -c -o source/ServiceAccessControlEntry.o source/ServiceAccessControlEntry.cpp
make[2]: *** [<builtin>: source/NroHeader.o] Error 1
make[2]: *** Waiting for unfinished jobs....
source/ServiceAccessControlBinary.cpp: In member function ‘virtual void nx::ServiceAccessControlBinary::toBytes()’:
source/ServiceAccessControlBinary.cpp:41:3: error: ‘memcpy’ was not declared in this scope
   memcpy((mRawBinary.data() + pos), mServices[i].getBytes().data(), mServices[i].getBytes().size());
   ^~~~~~
source/ServiceAccessControlBinary.cpp:41:3: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
source/ServiceAccessControlBinary.cpp:2:1:
+#include <cstring>
 
source/ServiceAccessControlBinary.cpp:41:3:
   memcpy((mRawBinary.data() + pos), mServices[i].getBytes().data(), mServices[i].getBytes().size());
   ^~~~~~
source/ServiceAccessControlBinary.cpp: In member function ‘virtual void nx::ServiceAccessControlBinary::fromBytes(const byte_t*, size_t)’:
source/ServiceAccessControlBinary.cpp:49:2: error: ‘memcpy’ was not declared in this scope
  memcpy(mRawBinary.data(), data, mRawBinary.size());
  ^~~~~~
source/ServiceAccessControlBinary.cpp:49:2: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
make[2]: *** [<builtin>: source/ServiceAccessControlBinary.o] Error 1
source/ApplicationControlPropertyBinary.cpp: In member function ‘virtual void nx::ApplicationControlPropertyBinary::toBytes()’:
source/ApplicationControlPropertyBinary.cpp:114:3: error: ‘strncpy’ was not declared in this scope
   strncpy(data->title[mTitle[i].language].name, mTitle[i].name.c_str(), nacp::kNameLength);
   ^~~~~~~
source/ApplicationControlPropertyBinary.cpp:114:3: note: ‘strncpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
source/ApplicationControlPropertyBinary.cpp:2:1:
+#include <cstring>
 
source/ApplicationControlPropertyBinary.cpp:114:3:
   strncpy(data->title[mTitle[i].language].name, mTitle[i].name.c_str(), nacp::kNameLength);
   ^~~~~~~
source/ApplicationControlPropertyBinary.cpp:125:2: error: ‘strncpy’ was not declared in this scope
  strncpy(data->isbn, mIsbn.c_str(), nacp::kIsbnLength);
  ^~~~~~~
source/ApplicationControlPropertyBinary.cpp:125:2: note: ‘strncpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
source/ApplicationControlPropertyBinary.cpp:150:2: error: ‘memset’ was not declared in this scope
  memset(data->rating_age, nacp::kUnusedAgeRating, nacp::kRatingAgeCount); // clear ratings
  ^~~~~~
source/ApplicationControlPropertyBinary.cpp:150:2: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
source/ApplicationControlPropertyBinary.cpp: In member function ‘virtual void nx::ApplicationControlPropertyBinary::fromBytes(const byte_t*, size_t)’:
source/ApplicationControlPropertyBinary.cpp:195:2: error: ‘memcpy’ was not declared in this scope
  memcpy(mRawBinary.data(), bytes, mRawBinary.size());
  ^~~~~~
source/ApplicationControlPropertyBinary.cpp:195:2: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
In file included from include/nx/ApplicationControlPropertyBinary.h:3,
                 from source/ApplicationControlPropertyBinary.cpp:1:
source/ApplicationControlPropertyBinary.cpp:208:81: error: ‘strlen’ was not declared in this scope
    mTitle.addElement({ (nacp::Language)i, std::string(data->title[i].name, _MIN(strlen(data->title[i].name), nacp::kNameLength)), std::string(data->title[i].publisher, _MIN(strlen(data->title[i].publisher), nacp::kPublisherLength)) });
                                                                                 ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
source/ApplicationControlPropertyBinary.cpp:208:81: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    mTitle.addElement({ (nacp::Language)i, std::string(data->title[i].name, _MIN(strlen(data->title[i].name), nacp::kNameLength)), std::string(data->title[i].publisher, _MIN(strlen(data->title[i].publisher), nacp::kPublisherLength)) });
                                                                                 ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
source/ApplicationControlPropertyBinary.cpp:208:234: error: no matching function for call to ‘fnd::List<nx::ApplicationControlPropertyBinary::sTitle>::addElement(<brace-enclosed initializer list>)’
    mTitle.addElement({ (nacp::Language)i, std::string(data->title[i].name, _MIN(strlen(data->title[i].name), nacp::kNameLength)), std::string(data->title[i].publisher, _MIN(strlen(data->title[i].publisher), nacp::kPublisherLength)) });
                                                                                                                                                                                                                                          ^
In file included from include/nx/ApplicationControlPropertyBinary.h:5,
                 from source/ApplicationControlPropertyBinary.cpp:1:
../libfnd/include/fnd/List.h:82:14: note: candidate: ‘void fnd::List<T>::addElement(const T&) [with T = nx::ApplicationControlPropertyBinary::sTitle]’
  inline void List<T>::addElement(const T & element)
              ^~~~~~~
../libfnd/include/fnd/List.h:82:14: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const nx::ApplicationControlPropertyBinary::sTitle&’
In file included from include/nx/ApplicationControlPropertyBinary.h:3,
                 from source/ApplicationControlPropertyBinary.cpp:1:
source/ApplicationControlPropertyBinary.cpp:213:40: error: ‘strlen’ was not declared in this scope
   mIsbn = std::string(data->isbn, _MIN(strlen(data->isbn), nacp::kIsbnLength));
                                        ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
source/ApplicationControlPropertyBinary.cpp:213:40: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
   mIsbn = std::string(data->isbn, _MIN(strlen(data->isbn), nacp::kIsbnLength));
                                        ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
source/ApplicationControlPropertyBinary.cpp:215:61: error: ‘strlen’ was not declared in this scope
   mDisplayVersion = std::string(data->display_version, _MIN(strlen(data->display_version), nacp::kDisplayVersionLength));
                                                             ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
source/ApplicationControlPropertyBinary.cpp:215:61: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
   mDisplayVersion = std::string(data->display_version, _MIN(strlen(data->display_version), nacp::kDisplayVersionLength));
                                                             ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
source/ApplicationControlPropertyBinary.cpp:217:91: error: ‘strlen’ was not declared in this scope
   mApplicationErrorCodeCategory = std::string(data->application_error_code_category, _MIN(strlen(data->application_error_code_category), nacp::kApplicationErrorCodeCategoryLength));
                                                                                           ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
source/FileSystemAccessControlBinary.cpp: In member function ‘virtual void nx::FileSystemAccessControlBinary::fromBytes(const byte_t*, size_t)’:
source/FileSystemAccessControlBinary.cpp:107:2: error: ‘memcpy’ was not declared in this scope
  memcpy((void*)&hdr, data, sizeof(sFacHeader));
  ^~~~~~
source/ApplicationControlPropertyBinary.cpp:217:91: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
   mApplicationErrorCodeCategory = std::string(data->application_error_code_category, _MIN(strlen(data->application_error_code_category), nacp::kApplicationErrorCodeCategoryLength));
                                                                                           ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
source/FileSystemAccessControlBinary.cpp:107:2: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
source/FileSystemAccessControlBinary.cpp:4:1:
+#include <cstring>
 
source/FileSystemAccessControlBinary.cpp:107:2:
  memcpy((void*)&hdr, data, sizeof(sFacHeader));
  ^~~~~~
source/ApplicationControlPropertyBinary.cpp:219:60: error: ‘strlen’ was not declared in this scope
   mBcatPassphase = std::string(data->bcat_passphrase, _MIN(strlen(data->bcat_passphrase), nacp::kBcatPassphraseLength));
                                                            ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
source/ApplicationControlPropertyBinary.cpp:219:60: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
   mBcatPassphase = std::string(data->bcat_passphrase, _MIN(strlen(data->bcat_passphrase), nacp::kBcatPassphraseLength));
                                                            ^~~~~~
../libfnd/include/fnd/types.h:9:21: note: in definition of macro ‘_MIN’
 #define _MIN(x,y) ((x) <= (y)? (x) : (y))
                     ^
make[2]: *** [<builtin>: source/FileSystemAccessControlBinary.o] Error 1
make[2]: *** [<builtin>: source/ApplicationControlPropertyBinary.o] Error 1
source/ContentMetaBinary.cpp: In member function ‘virtual void nx::ContentMetaBinary::clear()’:
source/ContentMetaBinary.cpp:170:83: warning: ‘void* memset(void*, int, size_t)’ clearing an object of type ‘struct nx::ContentMetaBinary::ApplicationMetaExtendedHeader’ with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess]
  memset(&mApplicationMetaExtendedHeader, 0, sizeof(mApplicationMetaExtendedHeader));
                                                                                   ^
In file included from source/ContentMetaBinary.cpp:1:
include/nx/ContentMetaBinary.h:72:10: note: ‘struct nx::ContentMetaBinary::ApplicationMetaExtendedHeader’ declared here
   struct ApplicationMetaExtendedHeader
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source/ContentMetaBinary.cpp:171:71: warning: ‘void* memset(void*, int, size_t)’ clearing an object of type ‘struct nx::ContentMetaBinary::PatchMetaExtendedHeader’ with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess]
  memset(&mPatchMetaExtendedHeader, 0, sizeof(mPatchMetaExtendedHeader));
                                                                       ^
In file included from source/ContentMetaBinary.cpp:1:
include/nx/ContentMetaBinary.h:95:10: note: ‘struct nx::ContentMetaBinary::PatchMetaExtendedHeader’ declared here
   struct PatchMetaExtendedHeader
          ^~~~~~~~~~~~~~~~~~~~~~~
source/ContentMetaBinary.cpp:172:85: warning: ‘void* memset(void*, int, size_t)’ clearing an object of type ‘struct nx::ContentMetaBinary::AddOnContentMetaExtendedHeader’ with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess]
  memset(&mAddOnContentMetaExtendedHeader, 0, sizeof(mAddOnContentMetaExtendedHeader));
                                                                                     ^
In file included from source/ContentMetaBinary.cpp:1:
include/nx/ContentMetaBinary.h:118:10: note: ‘struct nx::ContentMetaBinary::AddOnContentMetaExtendedHeader’ declared here
   struct AddOnContentMetaExtendedHeader
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source/ContentMetaBinary.cpp:173:71: warning: ‘void* memset(void*, int, size_t)’ clearing an object of type ‘struct nx::ContentMetaBinary::DeltaMetaExtendedHeader’ with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess]
  memset(&mDeltaMetaExtendedHeader, 0, sizeof(mDeltaMetaExtendedHeader));
                                                                       ^
In file included from source/ContentMetaBinary.cpp:1:
include/nx/ContentMetaBinary.h:141:10: note: ‘struct nx::ContentMetaBinary::DeltaMetaExtendedHeader’ declared here
   struct DeltaMetaExtendedHeader
          ^~~~~~~~~~~~~~~~~~~~~~~
source/ServiceAccessControlEntry.cpp: In member function ‘virtual void nx::ServiceAccessControlEntry::toBytes()’:
source/ServiceAccessControlEntry.cpp:68:2: error: ‘memcpy’ was not declared in this scope
  memcpy(mRawBinary.data() + 1, mName.c_str(), mName.length());
  ^~~~~~
source/ServiceAccessControlEntry.cpp:68:2: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
source/ServiceAccessControlEntry.cpp:2:1:
+#include <cstring>
 
source/ServiceAccessControlEntry.cpp:68:2:
  memcpy(mRawBinary.data() + 1, mName.c_str(), mName.length());
  ^~~~~~
source/ServiceAccessControlEntry.cpp: In member function ‘virtual void nx::ServiceAccessControlEntry::fromBytes(const byte_t*, size_t)’:
source/ServiceAccessControlEntry.cpp:91:2: error: ‘memcpy’ was not declared in this scope
  memcpy(mRawBinary.data(), data, mRawBinary.size());
  ^~~~~~
source/ServiceAccessControlEntry.cpp:91:2: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
make[2]: *** [<builtin>: source/ServiceAccessControlEntry.o] Error 1
make[2]: Leaving directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib/libnx'
/bin/sh: line 0: cd: libnx-hb: No such file or directory
make[1]: *** [makefile:7: build] Error 1
make[1]: Leaving directory '/home/rena/guilmon/projects/hax/switch/NXTools/lib'
make: *** [makefile:6: build] Error 2
 *** Process exited with status 2

Extracting a patch file with a ticket

I had no issues extracting the base game with this command:

nstool --tik maintik.tik -x ./game mainnca.nca

But I can't figure out how to extract the patch. The patch comes with it's own ticket, and I can only provide one. If I provide the main ticket:

nstool -x ./patch --tik ../main/maintik.tik --basenca ../main/mainnca.nca patchnca.nca

Nothing is extracted and I see this output:

[WARNING] NCA Partition 0 not readable. (AES-CTR Key was not determined)
[WARNING] NCA Partition 1 not readable. (AES-CTR Key was not determined)

If I provide the patch ticket:

nstool -x ./patch --tik patchtik.tik --basenca ../main/mainnca.nca patchnca.nca

Only partition 0 is extracted and I get this output:

[WARNING] NCA Partition 1 not readable. (Cannot determine RomFs from base nca.)

Is it possible to extract all icons from an asset?

For example, Fire Emblem Warriors has an icon file specific to each language. Yet, I can only seem to extract whatever is default, which I'm not sure is the first encountered in the asset, or something specifically marked as default.

Is it possible to specify which one to extract? Currently, I'm using nstool's python interface get_icon().

[Questions] how do I slipstream an update on the original archive

Forgive my ignorance this is the first time. I have received a base archive and a separate already extracted update archive. Both in nsp format. How do I apply the updated files over the base files

*Edit or possibly it is the diff file you speak of. I haven't compared the file names

The instructions show how the reverse is done. Extracting a patch from a base archive. Or something like that

I'm interested in applying a patch or update to the original version. Any help appreciated. Do I extract everything. Is that the only way. Extracting the update files with the help of the base files. And then creating s new archive? How do I create an archive. NSP archive in that case

Again forgive my lack of knowledge understanding

Data layer block(s) failed hash validation error when extracting NCA3 Meta files

I'm getting an error that says [pie::hac::HierarchicalIntegrityStream ERROR] Data layer block(s) failed hash validation when extracting files of the following type:

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    Meta
  Key Generation:  11
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0xdfe00
  ProgID:          0x010096f00ff22000
  Content Index:   0
  SdkAddon Ver.:   9.6.0 (v151388160)

[ContentArchive/Tree]
 meta:/
  0/
   control.nacp
   icon_AmericanEnglish.dat
   icon_BritishEnglish.dat
   icon_CanadianFrench.dat
   icon_French.dat
   icon_German.dat
   icon_Italian.dat
   icon_Japanese.dat
   icon_LatinAmericanSpanish.dat
   icon_Spanish.dat

Inspecting the files, they all look correct aside from the last one - icon_Spanish.dat in this case. It's an icon of the game/Title ID but part of it is cut off. The other icons render fine when opened up in an image editor. So it looks like for whatever reason, the length of the last file is calculated wrong when extracted. I'm not sure if it's related to the error message I received above but my guess is that it is.

FYI - I tried extracting other files of this type and same thing - the last icon in the set is cut off.

Let me know if you need me to upload any files. This is the command I used to extract:

./nstool -k prod.keys -x ./nacp/ 010096f00ff22000.bin

Error while extracting NCA file

I first extracted the contents of an NSP file, and then I tried to extract the archive which contained the program itself. However, nstool had extracted 5 files before throwing an error.

This was the command I ran:
nstool --tik "0100ec800800c0000000000000000004.tik" -x "./narutoprogram" -k "prod.keys" aaeb87f6434beb2f253400f62bc63b54.nca

And this was the output of the command:
[ContentArchive/Extract]
Saving .\narutoprogram\0\main...
Saving .\narutoprogram\0\main.npdm...
Saving .\narutoprogram\0\rtld...
Saving .\narutoprogram\0\sdk...
Saving .\narutoprogram\1\narutoNext123_Release_NX64.nspd_root...
[tc::io::VirtualFileSystem::openFile() ERROR] File does not exist.

NCA patch failed with some errors (Indirect storage not ascending ordered.)

game - Pokémon Violet
nstool --basenca ./b.nca -x ./out u.nca

Error:

[WARNING] NCA Header Main Signature: FAIL
[WARNING] ACID Signature: FAIL (Failed to verify Access Control Info Desc)
[NCA Header]
Format Type: NCA3
Dist. Type: Download
Content Type: Program
Key Generation: 10
Sig. Generation: 0
Kaek Index: Application (0)
Size: 0xb78af000
ProgID: 0x0100abf008968000
Content Index: 0
SdkAddon Ver.: 7.7.0 (v117899264)
[WARNING] NCA Partition 1 not readable. (Indirect storage not ascending ordered.)
[ContentArchive/Extract]
Saving ./out/0/main...
Saving ./out/0/main.npdm...
Saving ./out/0/rtld...
Saving ./out/0/sdk...
Saving ./out/0/subsdk0...
Saving ./out/0/subsdk1...

[FEATURE] When processing PFS0 archives, intelligently detect when it is NSP

About

NSPs are PFS0 archives that contain a bunch of *.nca files, at least one of which is a *.cnmt.nca file. This *.cnmt.nca file, contains in partition 0, a <TitleType>_<TitleId>.cnmt file, which contains metadata about the title, including which NCAs comprise this title, and what role each one has.

With this information, a composite filesystem can be created with all the NCAs. However a NSP can have more than one title included.

Additionally all of the *.tik files should be loaded/processed automatically.

Additionally, since *.cnmt includes hashes for the NCA files, verification should include verifying those hashes.

Example Data

File: Just Dance 2022 [0100EA6014BB8000][v0].nsp

Output of reading *.nsp

[PartitionFs]
  Type:        PFS0
  FileNum:     7
[PartitionFs/Tree]
 Root:/
  0100ea6014bb8000000000000000000b.tik
  0100ea6014bb8000000000000000000b.cert
  8b354a1c9a11cdd3d0b012e5f3b00bb0.cnmt.nca
  d5bdc4b294e5fdb8b4845510c0512a2f.nca
  f9e374d924fdaa8af4505b753aee6b9c.nca
  f0143905d50e559aaf78b34b638b1a56.nca
  24aec9556b304f835480dadb6c4288ef.nca

Output of reading 8b354a1c9a11cdd3d0b012e5f3b00bb0.cnmt.nca

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    Meta
  Key Generation:  11
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0xe00
  ProgID:          0x0100ea6014bb8000
  Content Index:   0
  SdkAddon Ver.:   12.0.0 (v201326592)
[ContentArchive/Tree]
 meta:/
  0/
   Application_0100ea6014bb8000.cnmt

Output of reading *.cnmt file

[ContentMeta]
  TitleId:               0x0100ea6014bb8000
  Version:               0.0.0-0.0 (v0)
  Type:                  Application (128)
  Attributes:            0x0
  StorageId:             None (0)
  ContentInstallType:    Full (0)
  RequiredDownloadSystemVersion: 0.0.0-0.0 (v0)
  ApplicationExtendedHeader:
    RequiredApplicationVersion: 0.0.0-0.0 (v0)
    RequiredSystemVersion:      12.1.0-0.0 (v806354944)
    PatchId:                    0x0100ea6014bb8800
  ContentInfo:
    0
      Type:         Program (1)
      Id:           d5bdc4b294e5fdb8b4845510c0512a2f
      Size:         0x1a37e0000
      Hash:         d5bdc4b294e5fdb8b4845510c0512a2f5bc8185766ddbfb7d9fe9c0c40939cd2
    1
      Type:         Control (3)
      Id:           f9e374d924fdaa8af4505b753aee6b9c
      Size:         0x176400
      Hash:         f9e374d924fdaa8af4505b753aee6b9c2a66fbaa2f057718afe0ee5f5578038e
    2
      Type:         LegalInformation (5)
      Id:           f0143905d50e559aaf78b34b638b1a56
      Size:         0x4f000
      Hash:         f0143905d50e559aaf78b34b638b1a5621ea8ca75a1d1d708c8c3315fd122684
    3
      Type:         HtmlDocument (4)
      Id:           24aec9556b304f835480dadb6c4288ef
      Size:         0x1c000
      Hash:         24aec9556b304f835480dadb6c4288ef5fe31581c8245b95414da2ccf5199b57
  Digest:   5a154739b19383ecb5d2f7589bd5685a1caf1d9878df737988048405e6355625

Output of reading the Program NCA

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    Program
  Key Generation:  11
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x1a37e0000
  ProgID:          0x0100ea6014bb8000
  Content Index:   0
  SdkAddon Ver.:   11.4.3 (v184812288)
  RightsId:        0100EA6014BB8000000000000000000B
[ContentArchive/Tree]
 program:/
  0/
   main
   main.npdm
   rtld
   sdk
   subsdk0
  1/
   adventurerkids_nx.ipk
   baiana_nx.ipk
   balletkids_nx.ipk
   believer_nx.ipk
   blackmam_nx.ipk
   blackmamalt_nx.ipk
   boombayah_nx.ipk
   boombayahalt_nx.ipk
   bosswitch_nx.ipk
   buildab_nx.ipk
   bundle_nx.ipk
   chacarron_nx.ipk
   chandelier_nx.ipk
   chandelieralt_nx.ipk
   chefkids_nx.ipk
   china_nx.ipk
   chinaalt_nx.ipk
   fearlesspiratekids_nx.ipk
   firemenkids_nx.ipk
   flashpose_nx.ipk
   freedfromdesire_nx.ipk
   funk_nx.ipk
   funkyrobotkids_nx.ipk
   girllikeme_nx.ipk
   girllikemealt_nx.ipk
   happierthanever_nx.ipk
   human_nx.ipk
   imouttalove_nx.ipk
   jerusalema_nx.ipk
   jopping_nx.ipk
   joppingalt_nx.ipk
   judas_nx.ipk
   levelup_nx.ipk
   levitating_nx.ipk
   levitatingalt_nx.ipk
   lovestory_nx.ipk
   medievalkids_nx.ipk
   mightyreal_nx.ipk
   monstersacademykids_nx.ipk
   mood_nx.ipk
   mrbluesky_nx.ipk
   nailships_nx.ipk
   nailshipsjd_nx.ipk
   popstars_nx.ipk
   rockyourbody_nx.ipk
   saveyourtears_nx.ipk
   secure_fat.gf
   siargo_nx.ipk
   smalltownboy_nx.ipk
   stopdropandroll_nx.ipk
   suacara_nx.ipk
   suacaraalt_nx.ipk
   tgif_nx.ipk
   thinkaboutthings_nx.ipk
   whorun_nx.ipk
   whorunaltretake_nx.ipk
   youcandance_nx.ipk
  2/
   NintendoLogo.png
   StartupMovie.gif

Output of reading the Control NCA

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    Control
  Key Generation:  11
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x176400
  ProgID:          0x0100ea6014bb8000
  Content Index:   0
  SdkAddon Ver.:   11.4.3 (v184812288)
[ContentArchive/Tree]
 control:/
  0/
   control.nacp
   icon_AmericanEnglish.dat
   icon_BrazilianPortuguese.dat
   icon_BritishEnglish.dat
   icon_CanadianFrench.dat
   icon_Dutch.dat
   icon_French.dat
   icon_German.dat
   icon_Italian.dat
   icon_Japanese.dat
   icon_Korean.dat
   icon_LatinAmericanSpanish.dat
   icon_Portuguese.dat
   icon_Russian.dat
   icon_SimplifiedChinese.dat
   icon_Spanish.dat
   icon_TraditionalChinese.dat

Output of reading the LegalInformation NCA

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    Manual
  Key Generation:  11
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x4f000
  ProgID:          0x0100ea6014bb8000
  Content Index:   0
  SdkAddon Ver.:   11.4.3 (v184812288)
[ContentArchive/Tree]
 manual:/
  0/
   legalinfo.xml
   important.htdocs/
    index.html
    style.css
   ipnotices.htdocs/
    index.html
    style.css
   support.htdocs/
    index.html
    index_All.html
    index_China.html
    index_EU.html
    index_HongKongTaiwanKorea.html
    index_JP.html
    index_US.html
    regions.js
    style.css

Output of reading the HtmlDocument NCA

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Download
  Content Type:    Manual
  Key Generation:  11
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x1c000
  ProgID:          0x0100ea6014bb8000
  Content Index:   0
  SdkAddon Ver.:   11.4.3 (v184812288)
  RightsId:        0100EA6014BB8000000000000000000B
[ContentArchive/Tree]
 manual:/
  0/
   accessible-urls/
    accessible-urls.txt

Cannot compile on VS 2017

This cannot be compiled on VS 2017 since this commit

Got an error C2971 during compiling

Erreur C2971 'ISerialiseablePrimative' : paramètre de modèle 'F' : 'le_hword' : une variable avec une durée de stockage non statique ne peut pas être utilisée comme argument sans type libfnd d:\switch\nxtools-4cfcf6bae975dba823d2f2a8ea1a7b173a638054\lib\libfnd\include\fnd\endian.h 51

[Enhancement] Add format > nmeta conversion

Do you think you could add nacp > nmeta, cnmt > nmeta and npdm > nmeta conversion to nstool? Right now it only outputs the information in a terminal, which while it is fine for just trying to recreate the nmeta, having a way for it to output as nmeta would be much easier.

[FEATURE] Enable fine-grain control over CLI output, for improved usability in scripting.

About

To improve usability in scripting use-cases, three modes shall be provided to control what output is written to stdout/stderr.

Design

Modes

  • Silent Mode - Omit presenting file information to output
    • Enabled with CLI option -q/--quiet
  • Verbose Mode - Where information has been summarised, present the full version instead
    • Enabled with CLI option -v/--verbose
  • Verify Mode - Verify the file structures where possible, and present errors to output
    • Enabled with CLI option -y/--verify

Output Types

NSTool shall classify CLI output as one of three types:

  • File Information (file structures, and filesystem trees, enum decoding, etc...)
    • These are printed to stdout.
    • These are the only output silenced in silent mode.
    • Where file information is too long (would exceed terminal history buffer) or redundant (unused fields) that information should be summarised
      • The unsummarised version should only be shown in verbose mode.
  • Warnings & Progress Indicators (these inform the user of potential errors, and state of an operation)
    • These are printed to stderr.
    • This information is only shown in verbose mode.
    • These are prefixed in output with a tag [nstool::ClassNameHere LOG] ....
    • Progress indicators include output like Extracting X to Y....
  • Errors (these inform the user of un-recoverable errors)
    • These are printed to stderr.
    • These will always be shown.
    • These are prefixed in output with a tag [nstool::ClassNameHere ERROR] ....
    • Note verification errors are only shown in verify mode.
    • Errors that have a hierarchy (like blocks, within an IVFC layer, within a IVFC image) should be summarised.
      • Granularity on specific element in the hierarchy should only be shown in verbose mode.

Requirements

  • Maintain CLI argument backwards compatibility (Minor change)

nstool failed to patch update on base nca (Indirect storage not ascending ordered)

Hey there,
I m trying to patch a game using nstool
But i got an error, hactool also shows the same error but somehow hac2l and hactoolnet are able to patch them is it possible to fix with nstool ?

game - Pokemon Violet, patch update v1.1.0

here's the errors -

[WARNING] NCA Header Main Signature: FAIL
[WARNING] ACID Signature: FAIL (Failed to verify Access Control Info Desc)
[NCA Header]
Format Type: NCA3
Dist. Type: Download
Content Type: Program
Key Generation: 10
Sig. Generation: 0
Kaek Index: Application (0)
Size: 0xb78af000
ProgID: 0x0100abf008968000
Content Index: 0
SdkAddon Ver.: 7.7.0 (v117899264)
[WARNING] NCA Partition 1 not readable. (Indirect storage not ascending ordered.)
[ContentArchive/Extract]
Saving ./out/0/main...
Saving ./out/0/main.npdm...
Saving ./out/0/rtld...
Saving ./out/0/sdk...
Saving ./out/0/subsdk0...
Saving ./out/0/subsdk1...

thanks in advance

Extract only certain files from NSP (to get .cnmt)?

Many thanks for this great tool. Is it possible to extract only certain files from a .nsp file instead of extracting the entire nsp? Or is there any other way or shortcut to get directly to the .cnmt file without extracting the entire nsp and extracting part0 from cnmt.nca?

Windows 7 Compatibility

Hi, I use your project in my small project XCI Organizer (and XCI Explorer) for extracting data from NSP files smaller than 10 MB. A few users are saying that it doesn't work in Windows 7. Any idea what could be triggering that? Thanks.
EDIT: I'm not using it anymore, but thought I'd let you know about the compatibility issues.
StudentBlake/XCI-Explorer#12

[BUG] NCA Key Area is formatted incorrectly

About

When using NSTool in verbose mode while reading a NCA with a Key Area in the header, the formatting is incorrect.

Steps to Reproduce

  1. Locate an NCA that has a key area (no ticket)
  2. Run NSTool in verbose mode while reading NCA nstool -v <name of nca file>

Actual Output

Pokemon Legends Arceus (decrypted key redacted):

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Game Card
  Content Type:    Program
  Key Generation:  13
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x181024000
  ProgID:          0x01001f5010dfa000
  Content Index:   0
  SdkAddon Ver.:   11.4.6 (v184813056)
  Key Area:
    <--------------------------------------------------------------------------------------------------------->
    | IDX | ENCRYPTED KEY                                   | DECRYPTED KEY                                   |
    |-----|-------------------------------------------------|-------------------------------------------------|
    |   0 | 3BA15D9CCC8F5A4795424FC2F7D5BDBE | 00000000000000000000000000000000 |
    |   1 | 3BA15D9CCC8F5A4795424FC2F7D5BDBE | 00000000000000000000000000000000 |
    |   2 | 11491FEBA949A1651ED1CB86722B1C14 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
    |   3 | 3BA15D9CCC8F5A4795424FC2F7D5BDBE | 00000000000000000000000000000000 |
    <--------------------------------------------------------------------------------------------------------->

Expected Output

Pokemon Legends Arceus (decrypted key redacted):

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Game Card
  Content Type:    Program
  Key Generation:  13
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x181024000
  ProgID:          0x01001f5010dfa000
  Content Index:   0
  SdkAddon Ver.:   11.4.6 (v184813056)
  Key Area:
    <--------------------------------------------------------------------------->
    | IDX | ENCRYPTED KEY                    | DECRYPTED KEY                    |
    |-----|----------------------------------|----------------------------------|
    |   0 | 3BA15D9CCC8F5A4795424FC2F7D5BDBE | 00000000000000000000000000000000 |
    |   1 | 3BA15D9CCC8F5A4795424FC2F7D5BDBE | 00000000000000000000000000000000 |
    |   2 | 11491FEBA949A1651ED1CB86722B1C14 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
    |   3 | 3BA15D9CCC8F5A4795424FC2F7D5BDBE | 00000000000000000000000000000000 |
    <--------------------------------------------------------------------------->

[BUG] NSTool incorrectly marks SaveDataOwnerId as FAIL

About

When verifying Program NCA or NPDM files, SaveDataOwnerId (if present) is incorrectly marked as FAIL.

Steps to reproduce

  1. Locate a Program NCA or NPDM file that has SaveDataOwnerId values populated
  2. Run NSTool in verify mode for that file nstool -y <file path>

Actual output

Pokemon Legends Arceus Program NCA:

[WARNING] ACI/FAC SaveDataOwnerId: FAIL (0x010003f003a34000 (1) not permitted)
[WARNING] ACI/FAC SaveDataOwnerId: FAIL (0x0100187003a36000 (1) not permitted)
[WARNING] ACI/FAC SaveDataOwnerId: FAIL (0x0100abf008968000 (1) not permitted)
[WARNING] ACI/FAC SaveDataOwnerId: FAIL (0x01008db008c2c000 (1) not permitted)
[WARNING] ACI/FAC SaveDataOwnerId: FAIL (0x0100000011d90000 (1) not permitted)
[WARNING] ACI/FAC SaveDataOwnerId: FAIL (0x010018e011d92000 (1) not permitted)
[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Game Card
  Content Type:    Program
  Key Generation:  13
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x181024000
  ProgID:          0x01001f5010dfa000
  Content Index:   0
  SdkAddon Ver.:   11.4.6 (v184813056)

Expected output

Pokemon Legends Arceus Program NCA:

[NCA Header]
  Format Type:     NCA3
  Dist. Type:      Game Card
  Content Type:    Program
  Key Generation:  13
  Sig. Generation: 0
  Kaek Index:      Application (0)
  Size:            0x181024000
  ProgID:          0x01001f5010dfa000
  Content Index:   0
  SdkAddon Ver.:   11.4.6 (v184813056)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.