2018-05-22 06:38:14 +00:00
|
|
|
#include <iostream>
|
2018-08-13 17:14:21 +00:00
|
|
|
#include <iomanip>
|
2018-05-11 16:26:19 +00:00
|
|
|
#include <sstream>
|
2018-04-25 15:21:47 +00:00
|
|
|
#include <fnd/SimpleTextOutput.h>
|
2018-10-06 08:45:09 +00:00
|
|
|
#include <fnd/OffsetAdjustedIFile.h>
|
|
|
|
#include <fnd/AesCtrWrappedIFile.h>
|
|
|
|
#include <fnd/LayeredIntegrityWrappedIFile.h>
|
2018-08-07 07:17:51 +00:00
|
|
|
#include <nn/hac/NcaUtils.h>
|
|
|
|
#include <nn/hac/AesKeygen.h>
|
2018-10-06 08:45:09 +00:00
|
|
|
#include <nn/hac/HierarchicalSha256Header.h>
|
|
|
|
#include <nn/hac/HierarchicalIntegrityHeader.h>
|
2018-05-11 09:51:14 +00:00
|
|
|
#include "NcaProcess.h"
|
|
|
|
#include "PfsProcess.h"
|
|
|
|
#include "RomfsProcess.h"
|
2018-05-12 15:02:53 +00:00
|
|
|
#include "NpdmProcess.h"
|
2018-10-06 08:45:09 +00:00
|
|
|
|
2018-04-25 15:21:47 +00:00
|
|
|
|
2018-05-22 11:03:42 +00:00
|
|
|
NcaProcess::NcaProcess() :
|
2018-09-23 03:29:22 +00:00
|
|
|
mFile(),
|
2018-06-18 15:30:19 +00:00
|
|
|
mCliOutputMode(_BIT(OUTPUT_BASIC)),
|
2018-05-22 11:03:42 +00:00
|
|
|
mVerify(false),
|
|
|
|
mListFs(false)
|
|
|
|
{
|
2018-08-07 07:17:51 +00:00
|
|
|
for (size_t i = 0; i < nn::hac::nca::kPartitionNum; i++)
|
2018-05-22 11:03:42 +00:00
|
|
|
{
|
|
|
|
mPartitionPath[i].doExtract = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NcaProcess::process()
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
// import header
|
|
|
|
importHeader();
|
2018-05-22 11:03:42 +00:00
|
|
|
|
|
|
|
// determine keys
|
|
|
|
generateNcaBodyEncryptionKeys();
|
|
|
|
|
|
|
|
// import/generate fs header data
|
|
|
|
generatePartitionConfiguration();
|
|
|
|
|
|
|
|
// validate signatures
|
|
|
|
if (mVerify)
|
|
|
|
validateNcaSignatures();
|
|
|
|
|
|
|
|
// display header
|
2018-06-18 15:30:19 +00:00
|
|
|
if (_HAS_BIT(mCliOutputMode, OUTPUT_BASIC))
|
2018-05-22 11:03:42 +00:00
|
|
|
displayHeader();
|
|
|
|
|
|
|
|
// process partition
|
|
|
|
processPartitions();
|
|
|
|
}
|
|
|
|
|
2018-09-23 03:29:22 +00:00
|
|
|
void NcaProcess::setInputFile(const fnd::SharedPtr<fnd::IFile>& file)
|
2018-05-22 11:03:42 +00:00
|
|
|
{
|
2018-06-03 08:48:12 +00:00
|
|
|
mFile = file;
|
2018-05-22 11:03:42 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 12:03:19 +00:00
|
|
|
void NcaProcess::setKeyCfg(const KeyConfiguration& keycfg)
|
2018-05-22 11:03:42 +00:00
|
|
|
{
|
2018-08-21 12:03:19 +00:00
|
|
|
mKeyCfg = keycfg;
|
2018-05-22 11:03:42 +00:00
|
|
|
}
|
|
|
|
|
2018-06-18 15:30:19 +00:00
|
|
|
void NcaProcess::setCliOutputMode(CliOutputMode type)
|
2018-05-22 11:03:42 +00:00
|
|
|
{
|
2018-06-18 15:30:19 +00:00
|
|
|
mCliOutputMode = type;
|
2018-05-22 11:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NcaProcess::setVerifyMode(bool verify)
|
|
|
|
{
|
|
|
|
mVerify = verify;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NcaProcess::setPartition0ExtractPath(const std::string& path)
|
|
|
|
{
|
|
|
|
mPartitionPath[0].path = path;
|
|
|
|
mPartitionPath[0].doExtract = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NcaProcess::setPartition1ExtractPath(const std::string& path)
|
|
|
|
{
|
|
|
|
mPartitionPath[1].path = path;
|
|
|
|
mPartitionPath[1].doExtract = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NcaProcess::setPartition2ExtractPath(const std::string& path)
|
|
|
|
{
|
|
|
|
mPartitionPath[2].path = path;
|
|
|
|
mPartitionPath[2].doExtract = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NcaProcess::setPartition3ExtractPath(const std::string& path)
|
|
|
|
{
|
|
|
|
mPartitionPath[3].path = path;
|
|
|
|
mPartitionPath[3].doExtract = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NcaProcess::setListFs(bool list_fs)
|
|
|
|
{
|
|
|
|
mListFs = list_fs;
|
|
|
|
}
|
|
|
|
|
2018-08-13 17:14:21 +00:00
|
|
|
void NcaProcess::importHeader()
|
|
|
|
{
|
2018-09-23 03:29:22 +00:00
|
|
|
if (*mFile == nullptr)
|
2018-08-13 17:14:21 +00:00
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "No file reader set.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// read header block
|
2018-09-23 03:29:22 +00:00
|
|
|
(*mFile)->read((byte_t*)&mHdrBlock, 0, sizeof(nn::hac::sNcaHeaderBlock));
|
2018-08-13 17:14:21 +00:00
|
|
|
|
|
|
|
// decrypt header block
|
2018-08-21 12:03:19 +00:00
|
|
|
fnd::aes::sAesXts128Key header_key;
|
|
|
|
mKeyCfg.getNcaHeaderKey(header_key);
|
|
|
|
nn::hac::NcaUtils::decryptNcaHeader((byte_t*)&mHdrBlock, (byte_t*)&mHdrBlock, header_key);
|
2018-08-13 17:14:21 +00:00
|
|
|
|
|
|
|
// generate header hash
|
|
|
|
fnd::sha::Sha256((byte_t*)&mHdrBlock.header, sizeof(nn::hac::sNcaHeader), mHdrHash.bytes);
|
|
|
|
|
|
|
|
// proccess main header
|
|
|
|
mHdr.fromBytes((byte_t*)&mHdrBlock.header, sizeof(nn::hac::sNcaHeader));
|
|
|
|
}
|
|
|
|
|
2018-05-11 16:26:19 +00:00
|
|
|
void NcaProcess::generateNcaBodyEncryptionKeys()
|
|
|
|
{
|
|
|
|
// create zeros key
|
2018-08-07 08:35:03 +00:00
|
|
|
fnd::aes::sAes128Key zero_aesctr_key;
|
2018-05-11 16:26:19 +00:00
|
|
|
memset(zero_aesctr_key.key, 0, sizeof(zero_aesctr_key));
|
|
|
|
|
|
|
|
// get key data from header
|
2018-08-07 07:17:51 +00:00
|
|
|
byte_t masterkey_rev = nn::hac::NcaUtils::getMasterKeyRevisionFromKeyGeneration(mHdr.getKeyGeneration());
|
2018-05-11 16:26:19 +00:00
|
|
|
byte_t keak_index = mHdr.getKaekIndex();
|
|
|
|
|
2018-05-23 07:19:54 +00:00
|
|
|
// process key area
|
2018-08-21 12:03:19 +00:00
|
|
|
sKeys::sKeyAreaKey kak;
|
|
|
|
fnd::aes::sAes128Key key_area_enc_key;
|
2018-08-07 07:17:51 +00:00
|
|
|
for (size_t i = 0; i < nn::hac::nca::kAesKeyNum; i++)
|
2018-05-23 07:19:54 +00:00
|
|
|
{
|
|
|
|
if (mHdr.getEncAesKeys()[i] != zero_aesctr_key)
|
|
|
|
{
|
2018-08-21 12:03:19 +00:00
|
|
|
kak.index = (byte_t)i;
|
|
|
|
kak.enc = mHdr.getEncAesKeys()[i];
|
|
|
|
// key[0-3]
|
|
|
|
if (i < 4 && mKeyCfg.getNcaKeyAreaEncryptionKey(masterkey_rev, keak_index, key_area_enc_key) == true)
|
2018-05-23 07:19:54 +00:00
|
|
|
{
|
2018-08-21 12:03:19 +00:00
|
|
|
kak.decrypted = true;
|
|
|
|
nn::hac::AesKeygen::generateKey(kak.dec.key, kak.enc.key, key_area_enc_key.key);
|
|
|
|
}
|
|
|
|
// key[4]
|
|
|
|
else if (i == 4 && mKeyCfg.getNcaKeyAreaEncryptionKeyHw(masterkey_rev, keak_index, key_area_enc_key) == true)
|
|
|
|
{
|
|
|
|
kak.decrypted = true;
|
|
|
|
nn::hac::AesKeygen::generateKey(kak.dec.key, kak.enc.key, key_area_enc_key.key);
|
2018-05-23 07:19:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-21 12:03:19 +00:00
|
|
|
kak.decrypted = false;
|
2018-05-23 07:19:54 +00:00
|
|
|
}
|
2018-08-21 12:18:14 +00:00
|
|
|
mContentKey.kak_list.addElement(kak);
|
2018-05-23 07:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 16:26:19 +00:00
|
|
|
// set flag to indicate that the keys are not available
|
2018-08-21 12:18:14 +00:00
|
|
|
mContentKey.aes_ctr.isSet = false;
|
2018-05-11 16:26:19 +00:00
|
|
|
|
|
|
|
// if this has a rights id, the key needs to be sourced from a ticket
|
|
|
|
if (mHdr.hasRightsId() == true)
|
|
|
|
{
|
2018-08-21 12:03:19 +00:00
|
|
|
fnd::aes::sAes128Key tmp_key;
|
|
|
|
if (mKeyCfg.getNcaExternalContentKey(mHdr.getRightsId(), tmp_key) == true)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
mContentKey.aes_ctr = tmp_key;
|
2018-08-21 12:03:19 +00:00
|
|
|
}
|
|
|
|
else if (mKeyCfg.getNcaExternalContentKey(kDummyRightsIdForUserTitleKey, tmp_key) == true)
|
|
|
|
{
|
|
|
|
fnd::aes::sAes128Key common_key;
|
|
|
|
if (mKeyCfg.getETicketCommonKey(masterkey_rev, common_key) == true)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
2018-08-21 12:03:19 +00:00
|
|
|
nn::hac::AesKeygen::generateKey(tmp_key.key, tmp_key.key, common_key.key);
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
2018-08-21 12:18:14 +00:00
|
|
|
mContentKey.aes_ctr = tmp_key;
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// otherwise decrypt key area
|
|
|
|
else
|
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
fnd::aes::sAes128Key kak_aes_ctr = zero_aesctr_key;
|
|
|
|
for (size_t i = 0; i < mContentKey.kak_list.size(); i++)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
if (mContentKey.kak_list[i].index == nn::hac::nca::KEY_AESCTR && mContentKey.kak_list[i].decrypted)
|
2018-05-23 07:19:54 +00:00
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
kak_aes_ctr = mContentKey.kak_list[i].dec;
|
2018-05-23 07:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 12:18:14 +00:00
|
|
|
if (kak_aes_ctr != zero_aesctr_key)
|
2018-05-23 07:19:54 +00:00
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
mContentKey.aes_ctr = kak_aes_ctr;
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the keys weren't generated, check if the keys were supplied by the user
|
2018-08-21 12:18:14 +00:00
|
|
|
if (mContentKey.aes_ctr.isSet == false)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
if (mKeyCfg.getNcaExternalContentKey(kDummyRightsIdForUserBodyKey, mContentKey.aes_ctr.var) == true)
|
|
|
|
mContentKey.aes_ctr.isSet = true;
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
2018-05-22 11:03:42 +00:00
|
|
|
|
2018-08-21 12:03:19 +00:00
|
|
|
|
2018-06-18 15:30:19 +00:00
|
|
|
if (_HAS_BIT(mCliOutputMode, OUTPUT_KEY_DATA))
|
2018-05-22 05:47:07 +00:00
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
if (mContentKey.aes_ctr.isSet)
|
2018-06-18 15:30:19 +00:00
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
std::cout << "[NCA Content Key]" << std::endl;
|
2018-08-24 08:10:03 +00:00
|
|
|
std::cout << " AES-CTR Key: " << fnd::SimpleTextOutput::arrayToString(mContentKey.aes_ctr.var.key, sizeof(mContentKey.aes_ctr.var), true, ":") << std::endl;
|
2018-06-18 15:30:19 +00:00
|
|
|
}
|
2018-05-22 05:47:07 +00:00
|
|
|
}
|
2018-06-18 15:30:19 +00:00
|
|
|
|
|
|
|
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NcaProcess::generatePartitionConfiguration()
|
|
|
|
{
|
|
|
|
std::stringstream error;
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t i = 0; i < mHdr.getPartitions().size(); i++)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
|
|
|
// get reference to relevant structures
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::NcaHeader::sPartition& partition = mHdr.getPartitions()[i];
|
|
|
|
nn::hac::sNcaFsHeader& fs_header = mHdrBlock.fs_header[partition.index];
|
2018-05-11 16:26:19 +00:00
|
|
|
|
2018-05-20 13:57:38 +00:00
|
|
|
// output structure
|
|
|
|
sPartitionInfo& info = mPartitions[partition.index];
|
|
|
|
|
2018-05-11 16:26:19 +00:00
|
|
|
// validate header hash
|
2018-08-07 08:35:03 +00:00
|
|
|
fnd::sha::sSha256Hash calc_hash;
|
|
|
|
fnd::sha::Sha256((const byte_t*)&mHdrBlock.fs_header[partition.index], sizeof(nn::hac::sNcaFsHeader), calc_hash.bytes);
|
2018-05-11 16:26:19 +00:00
|
|
|
if (calc_hash.compare(partition.hash) == false)
|
|
|
|
{
|
|
|
|
error.clear();
|
|
|
|
error << "NCA FS Header [" << partition.index << "] Hash: FAIL \n";
|
|
|
|
throw fnd::Exception(kModuleName, error.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
if (fs_header.version.get() != nn::hac::nca::kDefaultFsHeaderVersion)
|
2018-05-21 12:49:28 +00:00
|
|
|
{
|
|
|
|
error.clear();
|
2018-05-22 06:38:14 +00:00
|
|
|
error << "NCA FS Header [" << partition.index << "] Version(" << fs_header.version.get() << "): UNSUPPORTED";
|
2018-05-21 12:49:28 +00:00
|
|
|
throw fnd::Exception(kModuleName, error.str());
|
|
|
|
}
|
|
|
|
|
2018-05-11 16:26:19 +00:00
|
|
|
// setup AES-CTR
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::NcaUtils::getNcaPartitionAesCtr(&fs_header, info.aes_ctr.iv);
|
2018-05-11 16:26:19 +00:00
|
|
|
|
|
|
|
// save partition config
|
2018-05-20 13:57:38 +00:00
|
|
|
info.reader = nullptr;
|
|
|
|
info.offset = partition.offset;
|
|
|
|
info.size = partition.size;
|
2018-08-07 07:17:51 +00:00
|
|
|
info.format_type = (nn::hac::nca::FormatType)fs_header.format_type;
|
|
|
|
info.hash_type = (nn::hac::nca::HashType)fs_header.hash_type;
|
|
|
|
info.enc_type = (nn::hac::nca::EncryptionType)fs_header.encryption_type;
|
|
|
|
if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_SHA256)
|
2018-10-06 05:31:24 +00:00
|
|
|
{
|
|
|
|
// info.hash_tree_meta.importData(fs_header.hash_superblock, nn::hac::nca::kFsHeaderHashSuperblockLen, LayeredIntegrityMetadata::HASH_TYPE_SHA256);
|
|
|
|
nn::hac::HierarchicalSha256Header hdr;
|
2018-10-06 08:45:09 +00:00
|
|
|
fnd::List<fnd::LayeredIntegrityMetadata::sLayer> hash_layers;
|
|
|
|
fnd::LayeredIntegrityMetadata::sLayer data_layer;
|
2018-10-06 05:31:24 +00:00
|
|
|
fnd::List<fnd::sha::sSha256Hash> master_hash_list;
|
|
|
|
|
|
|
|
// import raw data
|
|
|
|
hdr.fromBytes(fs_header.hash_superblock, nn::hac::nca::kFsHeaderHashSuperblockLen);
|
|
|
|
for (size_t i = 0; i < hdr.getLayerInfo().size(); i++)
|
|
|
|
{
|
2018-10-06 08:45:09 +00:00
|
|
|
fnd::LayeredIntegrityMetadata::sLayer layer;
|
2018-10-06 05:31:24 +00:00
|
|
|
layer.offset = hdr.getLayerInfo()[i].offset;
|
|
|
|
layer.size = hdr.getLayerInfo()[i].size;
|
|
|
|
layer.block_size = hdr.getHashBlockSize();
|
|
|
|
if (i + 1 == hdr.getLayerInfo().size())
|
|
|
|
{
|
|
|
|
data_layer = layer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash_layers.addElement(layer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
master_hash_list.addElement(hdr.getMasterHash());
|
|
|
|
|
|
|
|
// write data into metadata
|
|
|
|
info.layered_intergrity_metadata.setAlignHashToBlock(false);
|
|
|
|
info.layered_intergrity_metadata.setHashLayerInfo(hash_layers);
|
|
|
|
info.layered_intergrity_metadata.setDataLayerInfo(data_layer);
|
|
|
|
info.layered_intergrity_metadata.setMasterHashList(master_hash_list);
|
|
|
|
}
|
2018-08-07 07:17:51 +00:00
|
|
|
else if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_INTERGRITY)
|
2018-10-06 05:31:24 +00:00
|
|
|
{
|
|
|
|
// info.hash_tree_meta.importData(fs_header.hash_superblock, nn::hac::nca::kFsHeaderHashSuperblockLen, LayeredIntegrityMetadata::HASH_TYPE_INTEGRITY);
|
|
|
|
nn::hac::HierarchicalIntegrityHeader hdr;
|
2018-10-06 08:45:09 +00:00
|
|
|
fnd::List<fnd::LayeredIntegrityMetadata::sLayer> hash_layers;
|
|
|
|
fnd::LayeredIntegrityMetadata::sLayer data_layer;
|
2018-10-06 05:31:24 +00:00
|
|
|
fnd::List<fnd::sha::sSha256Hash> master_hash_list;
|
|
|
|
|
|
|
|
hdr.fromBytes(fs_header.hash_superblock, nn::hac::nca::kFsHeaderHashSuperblockLen);
|
|
|
|
for (size_t i = 0; i < hdr.getLayerInfo().size(); i++)
|
|
|
|
{
|
2018-10-06 08:45:09 +00:00
|
|
|
fnd::LayeredIntegrityMetadata::sLayer layer;
|
2018-10-06 05:31:24 +00:00
|
|
|
layer.offset = hdr.getLayerInfo()[i].offset;
|
|
|
|
layer.size = hdr.getLayerInfo()[i].size;
|
|
|
|
layer.block_size = _BIT(hdr.getLayerInfo()[i].block_size);
|
|
|
|
if (i + 1 == hdr.getLayerInfo().size())
|
|
|
|
{
|
|
|
|
data_layer = layer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash_layers.addElement(layer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// write data into metadata
|
|
|
|
info.layered_intergrity_metadata.setAlignHashToBlock(true);
|
|
|
|
info.layered_intergrity_metadata.setHashLayerInfo(hash_layers);
|
|
|
|
info.layered_intergrity_metadata.setDataLayerInfo(data_layer);
|
|
|
|
info.layered_intergrity_metadata.setMasterHashList(hdr.getMasterHashList());
|
|
|
|
}
|
2018-05-11 16:26:19 +00:00
|
|
|
|
2018-05-22 11:03:42 +00:00
|
|
|
// create reader
|
2018-05-22 06:38:14 +00:00
|
|
|
try
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
2018-05-22 06:38:14 +00:00
|
|
|
// filter out unrecognised format types
|
|
|
|
switch (info.format_type)
|
|
|
|
{
|
2018-08-07 07:17:51 +00:00
|
|
|
case (nn::hac::nca::FORMAT_PFS0):
|
|
|
|
case (nn::hac::nca::FORMAT_ROMFS):
|
2018-05-22 06:38:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error.clear();
|
|
|
|
error << "FormatType(" << info.format_type << "): UNKNOWN";
|
|
|
|
throw fnd::Exception(kModuleName, error.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// create reader based on encryption type0
|
2018-08-07 07:17:51 +00:00
|
|
|
if (info.enc_type == nn::hac::nca::CRYPT_NONE)
|
2018-05-22 06:38:14 +00:00
|
|
|
{
|
2018-10-06 08:45:09 +00:00
|
|
|
info.reader = new fnd::OffsetAdjustedIFile(mFile, info.offset, info.size);
|
2018-05-22 06:38:14 +00:00
|
|
|
}
|
2018-08-07 07:17:51 +00:00
|
|
|
else if (info.enc_type == nn::hac::nca::CRYPT_AESCTR)
|
2018-05-22 06:38:14 +00:00
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
if (mContentKey.aes_ctr.isSet == false)
|
2018-05-22 06:38:14 +00:00
|
|
|
throw fnd::Exception(kModuleName, "AES-CTR Key was not determined");
|
2018-10-06 08:45:09 +00:00
|
|
|
info.reader = new fnd::OffsetAdjustedIFile(new fnd::AesCtrWrappedIFile(mFile, mContentKey.aes_ctr.var, info.aes_ctr), info.offset, info.size);
|
2018-05-22 06:38:14 +00:00
|
|
|
}
|
2018-08-07 07:17:51 +00:00
|
|
|
else if (info.enc_type == nn::hac::nca::CRYPT_AESXTS || info.enc_type == nn::hac::nca::CRYPT_AESCTREX)
|
2018-05-22 06:38:14 +00:00
|
|
|
{
|
2018-05-21 12:49:28 +00:00
|
|
|
error.clear();
|
2018-05-26 04:07:42 +00:00
|
|
|
error << "EncryptionType(" << getEncryptionTypeStr(info.enc_type) << "): UNSUPPORTED";
|
2018-05-21 12:49:28 +00:00
|
|
|
throw fnd::Exception(kModuleName, error.str());
|
2018-05-22 06:38:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.clear();
|
|
|
|
error << "EncryptionType(" << info.enc_type << "): UNKNOWN";
|
|
|
|
throw fnd::Exception(kModuleName, error.str());
|
|
|
|
}
|
2018-05-11 16:26:19 +00:00
|
|
|
|
2018-05-22 06:38:14 +00:00
|
|
|
// filter out unrecognised hash types, and hash based readers
|
2018-08-07 07:17:51 +00:00
|
|
|
if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_SHA256 || info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_INTERGRITY)
|
2018-05-22 11:03:42 +00:00
|
|
|
{
|
2018-10-06 08:45:09 +00:00
|
|
|
info.reader = new fnd::LayeredIntegrityWrappedIFile(info.reader, info.layered_intergrity_metadata);
|
2018-05-22 06:38:14 +00:00
|
|
|
}
|
2018-08-07 07:17:51 +00:00
|
|
|
else if (info.hash_type != nn::hac::nca::HASH_NONE)
|
2018-05-22 06:38:14 +00:00
|
|
|
{
|
2018-05-11 16:26:19 +00:00
|
|
|
error.clear();
|
2018-05-22 06:38:14 +00:00
|
|
|
error << "HashType(" << info.hash_type << "): UNKNOWN";
|
2018-05-11 16:26:19 +00:00
|
|
|
throw fnd::Exception(kModuleName, error.str());
|
2018-05-22 06:38:14 +00:00
|
|
|
}
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
2018-05-22 06:38:14 +00:00
|
|
|
catch (const fnd::Exception& e)
|
2018-05-21 13:08:37 +00:00
|
|
|
{
|
2018-05-22 06:38:14 +00:00
|
|
|
info.fail_reason = std::string(e.error());
|
2018-05-21 13:08:37 +00:00
|
|
|
}
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NcaProcess::validateNcaSignatures()
|
|
|
|
{
|
|
|
|
// validate signature[0]
|
2018-08-21 12:03:19 +00:00
|
|
|
fnd::rsa::sRsa2048Key sign0_key;
|
|
|
|
mKeyCfg.getNcaHeader0SignKey(sign0_key);
|
|
|
|
if (fnd::rsa::pss::rsaVerify(sign0_key, fnd::sha::HASH_SHA256, mHdrHash.bytes, mHdrBlock.signature_main) != 0)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "[WARNING] NCA Header Main Signature: FAIL" << std::endl;
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// validate signature[1]
|
2018-08-07 07:17:51 +00:00
|
|
|
if (mHdr.getContentType() == nn::hac::nca::TYPE_PROGRAM)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
2018-08-07 07:17:51 +00:00
|
|
|
if (mPartitions[nn::hac::nca::PARTITION_CODE].format_type == nn::hac::nca::FORMAT_PFS0)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
2018-09-23 03:29:22 +00:00
|
|
|
if (*mPartitions[nn::hac::nca::PARTITION_CODE].reader != nullptr)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
|
|
|
PfsProcess exefs;
|
2018-09-23 03:29:22 +00:00
|
|
|
exefs.setInputFile(mPartitions[nn::hac::nca::PARTITION_CODE].reader);
|
2018-06-18 15:30:19 +00:00
|
|
|
exefs.setCliOutputMode(0);
|
2018-05-11 16:26:19 +00:00
|
|
|
exefs.process();
|
|
|
|
|
|
|
|
// open main.npdm
|
|
|
|
if (exefs.getPfsHeader().getFileList().hasElement(kNpdmExefsPath) == true)
|
|
|
|
{
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::PfsHeader::sFile& file = exefs.getPfsHeader().getFileList().getElement(kNpdmExefsPath);
|
2018-05-11 16:26:19 +00:00
|
|
|
|
2018-05-12 15:02:53 +00:00
|
|
|
NpdmProcess npdm;
|
2018-10-06 08:45:09 +00:00
|
|
|
npdm.setInputFile(new fnd::OffsetAdjustedIFile(mPartitions[nn::hac::nca::PARTITION_CODE].reader, file.offset, file.size));
|
2018-06-18 15:30:19 +00:00
|
|
|
npdm.setCliOutputMode(0);
|
2018-05-12 15:02:53 +00:00
|
|
|
npdm.process();
|
2018-05-11 16:26:19 +00:00
|
|
|
|
2018-08-07 08:35:03 +00:00
|
|
|
if (fnd::rsa::pss::rsaVerify(npdm.getNpdmBinary().getAcid().getNcaHeaderSignature2Key(), fnd::sha::HASH_SHA256, mHdrHash.bytes, mHdrBlock.signature_acid) != 0)
|
2018-05-11 16:26:19 +00:00
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "[WARNING] NCA Header ACID Signature: FAIL" << std::endl;
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "[WARNING] NCA Header ACID Signature: FAIL (\"" << kNpdmExefsPath << "\" not present in ExeFs)" << std::endl;
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "[WARNING] NCA Header ACID Signature: FAIL (ExeFs unreadable)" << std::endl;
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "[WARNING] NCA Header ACID Signature: FAIL (No ExeFs partition)" << std::endl;
|
2018-05-11 16:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 15:21:47 +00:00
|
|
|
void NcaProcess::displayHeader()
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "[NCA Header]" << std::endl;
|
|
|
|
std::cout << " Format Type: " << getFormatVersionStr(mHdr.getFormatVersion()) << std::endl;
|
|
|
|
std::cout << " Dist. Type: " << getDistributionTypeStr(mHdr.getDistributionType()) << std::endl;
|
|
|
|
std::cout << " Content Type: " << getContentTypeStr(mHdr.getContentType()) << std::endl;
|
|
|
|
std::cout << " Key Generation: " << std::dec << (uint32_t)mHdr.getKeyGeneration() << std::endl;
|
|
|
|
std::cout << " Kaek Index: " << getKaekIndexStr((nn::hac::nca::KeyAreaEncryptionKeyIndex)mHdr.getKaekIndex()) << " (" << std::dec << (uint32_t)mHdr.getKaekIndex() << ")" << std::endl;
|
|
|
|
std::cout << " Size: 0x" << std::hex << mHdr.getContentSize() << std::endl;
|
|
|
|
std::cout << " ProgID: 0x" << std::hex << std::setw(16) << std::setfill('0') << mHdr.getProgramId() << std::endl;
|
|
|
|
std::cout << " Content Index: " << std::dec << mHdr.getContentIndex() << std::endl;
|
|
|
|
#define _SPLIT_VER(ver) std::dec << (uint32_t)((ver>>24) & 0xff) << "." << (uint32_t)((ver>>16) & 0xff) << "." << (uint32_t)((ver>>8) & 0xff)
|
|
|
|
std::cout << " SdkAddon Ver.: v" << std::dec << mHdr.getSdkAddonVersion() << " (" << _SPLIT_VER(mHdr.getSdkAddonVersion()) << ")" << std::endl;
|
2018-05-12 16:04:07 +00:00
|
|
|
#undef _SPLIT_VER
|
2018-05-26 04:07:42 +00:00
|
|
|
if (mHdr.hasRightsId())
|
|
|
|
{
|
2018-08-14 07:25:33 +00:00
|
|
|
std::cout << " RightsId: " << fnd::SimpleTextOutput::arrayToString(mHdr.getRightsId(), nn::hac::nca::kRightsIdLen, true, "") << std::endl;
|
2018-05-26 04:07:42 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 12:18:14 +00:00
|
|
|
if (mContentKey.kak_list.size() > 0 && _HAS_BIT(mCliOutputMode, OUTPUT_KEY_DATA))
|
2018-04-25 15:21:47 +00:00
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " Key Area:" << std::endl;
|
2018-08-24 08:10:03 +00:00
|
|
|
std::cout << " <--------------------------------------------------------------------------------------------------------->" << std::endl;
|
|
|
|
std::cout << " | IDX | ENCRYPTED KEY | DECRYPTED KEY |" << std::endl;
|
|
|
|
std::cout << " |-----|-------------------------------------------------|-------------------------------------------------|" << std::endl;
|
2018-08-21 12:18:14 +00:00
|
|
|
for (size_t i = 0; i < mContentKey.kak_list.size(); i++)
|
2018-04-25 15:21:47 +00:00
|
|
|
{
|
2018-08-21 12:18:14 +00:00
|
|
|
std::cout << " | " << std::dec << std::setw(3) << std::setfill(' ') << (uint32_t)mContentKey.kak_list[i].index << " | ";
|
2018-05-23 07:19:54 +00:00
|
|
|
|
2018-08-24 08:10:03 +00:00
|
|
|
std::cout << fnd::SimpleTextOutput::arrayToString(mContentKey.kak_list[i].enc.key, 16, true, ":") << " | ";
|
2018-05-23 07:19:54 +00:00
|
|
|
|
|
|
|
|
2018-08-21 12:18:14 +00:00
|
|
|
if (mContentKey.kak_list[i].decrypted)
|
2018-08-24 08:10:03 +00:00
|
|
|
std::cout << fnd::SimpleTextOutput::arrayToString(mContentKey.kak_list[i].dec.key, 16, true, ":");
|
2018-05-23 07:19:54 +00:00
|
|
|
else
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "<unable to decrypt> ";
|
2018-05-23 07:19:54 +00:00
|
|
|
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " |" << std::endl;
|
2018-04-25 15:21:47 +00:00
|
|
|
}
|
2018-08-24 08:10:03 +00:00
|
|
|
std::cout << " <--------------------------------------------------------------------------------------------------------->" << std::endl;
|
2018-04-25 15:21:47 +00:00
|
|
|
}
|
2018-05-11 09:51:14 +00:00
|
|
|
|
2018-06-18 15:30:19 +00:00
|
|
|
if (_HAS_BIT(mCliOutputMode, OUTPUT_LAYOUT))
|
2018-05-11 09:51:14 +00:00
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " Partitions:" << std::endl;
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t i = 0; i < mHdr.getPartitions().size(); i++)
|
2018-05-11 09:51:14 +00:00
|
|
|
{
|
2018-08-04 02:05:47 +00:00
|
|
|
size_t index = mHdr.getPartitions()[i].index;
|
|
|
|
sPartitionInfo& info = mPartitions[index];
|
2018-06-18 15:30:19 +00:00
|
|
|
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " " << std::dec << index << ":" << std::endl;
|
|
|
|
std::cout << " Offset: 0x" << std::hex << (uint64_t)info.offset << std::endl;
|
|
|
|
std::cout << " Size: 0x" << std::hex << (uint64_t)info.size << std::endl;
|
|
|
|
std::cout << " Format Type: " << getFormatTypeStr(info.format_type) << std::endl;
|
|
|
|
std::cout << " Hash Type: " << getHashTypeStr(info.hash_type) << std::endl;
|
|
|
|
std::cout << " Enc. Type: " << getEncryptionTypeStr(info.enc_type) << std::endl;
|
2018-08-07 07:17:51 +00:00
|
|
|
if (info.enc_type == nn::hac::nca::CRYPT_AESCTR)
|
2018-05-11 09:51:14 +00:00
|
|
|
{
|
2018-08-07 08:35:03 +00:00
|
|
|
fnd::aes::sAesIvCtr ctr;
|
|
|
|
fnd::aes::AesIncrementCounter(info.aes_ctr.iv, info.offset>>4, ctr.iv);
|
2018-08-24 08:10:03 +00:00
|
|
|
std::cout << " AesCtr Counter:" << std::endl;
|
|
|
|
std::cout << " " << fnd::SimpleTextOutput::arrayToString(ctr.iv, sizeof(fnd::aes::sAesIvCtr), true, ":") << std::endl;
|
2018-05-11 09:51:14 +00:00
|
|
|
}
|
2018-08-07 07:17:51 +00:00
|
|
|
if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_INTERGRITY)
|
2018-06-18 15:30:19 +00:00
|
|
|
{
|
2018-10-06 08:45:09 +00:00
|
|
|
fnd::LayeredIntegrityMetadata& hash_hdr = info.layered_intergrity_metadata;
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " HierarchicalIntegrity Header:" << std::endl;
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t j = 0; j < hash_hdr.getHashLayerInfo().size(); j++)
|
2018-06-18 15:30:19 +00:00
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " Hash Layer " << std::dec << j << ":" << std::endl;
|
|
|
|
std::cout << " Offset: 0x" << std::hex << (uint64_t)hash_hdr.getHashLayerInfo()[j].offset << std::endl;
|
|
|
|
std::cout << " Size: 0x" << std::hex << (uint64_t)hash_hdr.getHashLayerInfo()[j].size << std::endl;
|
|
|
|
std::cout << " BlockSize: 0x" << std::hex << (uint32_t)hash_hdr.getHashLayerInfo()[j].block_size << std::endl;
|
2018-06-18 15:30:19 +00:00
|
|
|
}
|
2018-05-21 13:08:37 +00:00
|
|
|
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " Data Layer:" << std::endl;
|
|
|
|
std::cout << " Offset: 0x" << std::hex << (uint64_t)hash_hdr.getDataLayer().offset << std::endl;
|
|
|
|
std::cout << " Size: 0x" << std::hex << (uint64_t)hash_hdr.getDataLayer().size << std::endl;
|
|
|
|
std::cout << " BlockSize: 0x" << std::hex << (uint32_t)hash_hdr.getDataLayer().block_size << std::endl;
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t j = 0; j < hash_hdr.getMasterHashList().size(); j++)
|
2018-06-18 15:30:19 +00:00
|
|
|
{
|
2018-08-24 08:10:03 +00:00
|
|
|
std::cout << " Master Hash " << std::dec << j << ":" << std::endl;
|
|
|
|
std::cout << " " << fnd::SimpleTextOutput::arrayToString(hash_hdr.getMasterHashList()[j].bytes, 0x10, true, ":") << std::endl;
|
|
|
|
std::cout << " " << fnd::SimpleTextOutput::arrayToString(hash_hdr.getMasterHashList()[j].bytes+0x10, 0x10, true, ":") << std::endl;
|
2018-06-18 15:30:19 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-07 07:17:51 +00:00
|
|
|
else if (info.hash_type == nn::hac::nca::HASH_HIERARCHICAL_SHA256)
|
2018-05-19 03:57:40 +00:00
|
|
|
{
|
2018-10-06 08:45:09 +00:00
|
|
|
fnd::LayeredIntegrityMetadata& hash_hdr = info.layered_intergrity_metadata;
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " HierarchicalSha256 Header:" << std::endl;
|
2018-08-24 08:10:03 +00:00
|
|
|
std::cout << " Master Hash:" << std::endl;
|
|
|
|
std::cout << " " << fnd::SimpleTextOutput::arrayToString(hash_hdr.getMasterHashList()[0].bytes, 0x10, true, ":") << std::endl;
|
|
|
|
std::cout << " " << fnd::SimpleTextOutput::arrayToString(hash_hdr.getMasterHashList()[0].bytes+0x10, 0x10, true, ":") << std::endl;
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " HashBlockSize: 0x" << std::hex << (uint32_t)hash_hdr.getDataLayer().block_size << std::endl;
|
|
|
|
std::cout << " Hash Layer:" << std::endl;
|
|
|
|
std::cout << " Offset: 0x" << std::hex << (uint64_t)hash_hdr.getHashLayerInfo()[0].offset << std::endl;
|
|
|
|
std::cout << " Size: 0x" << std::hex << (uint64_t)hash_hdr.getHashLayerInfo()[0].size << std::endl;
|
|
|
|
std::cout << " Data Layer:" << std::endl;
|
|
|
|
std::cout << " Offset: 0x" << std::hex << (uint64_t)hash_hdr.getDataLayer().offset << std::endl;
|
|
|
|
std::cout << " Size: 0x" << std::hex << (uint64_t)hash_hdr.getDataLayer().size << std::endl;
|
2018-05-19 03:57:40 +00:00
|
|
|
}
|
2018-05-11 09:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-25 15:21:47 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 09:51:14 +00:00
|
|
|
|
|
|
|
void NcaProcess::processPartitions()
|
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t i = 0; i < mHdr.getPartitions().size(); i++)
|
2018-05-11 09:51:14 +00:00
|
|
|
{
|
2018-05-11 16:26:19 +00:00
|
|
|
size_t index = mHdr.getPartitions()[i].index;
|
|
|
|
struct sPartitionInfo& partition = mPartitions[index];
|
2018-05-11 09:51:14 +00:00
|
|
|
|
|
|
|
// if the reader is null, skip
|
2018-09-23 03:29:22 +00:00
|
|
|
if (*partition.reader == nullptr)
|
2018-05-11 09:51:14 +00:00
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << "[WARNING] NCA Partition " << std::dec << index << " not readable.";
|
2018-05-22 06:38:14 +00:00
|
|
|
if (partition.fail_reason.empty() == false)
|
|
|
|
{
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << " (" << partition.fail_reason << ")";
|
2018-05-22 06:38:14 +00:00
|
|
|
}
|
2018-08-13 17:14:21 +00:00
|
|
|
std::cout << std::endl;
|
2018-05-11 09:51:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
if (partition.format_type == nn::hac::nca::FORMAT_PFS0)
|
2018-05-11 09:51:14 +00:00
|
|
|
{
|
|
|
|
PfsProcess pfs;
|
2018-09-23 03:29:22 +00:00
|
|
|
pfs.setInputFile(partition.reader);
|
2018-06-18 15:30:19 +00:00
|
|
|
pfs.setCliOutputMode(mCliOutputMode);
|
2018-05-11 09:51:14 +00:00
|
|
|
pfs.setListFs(mListFs);
|
2018-08-07 07:17:51 +00:00
|
|
|
if (mHdr.getContentType() == nn::hac::nca::TYPE_PROGRAM)
|
2018-05-15 15:00:07 +00:00
|
|
|
{
|
2018-08-04 02:05:47 +00:00
|
|
|
pfs.setMountPointName(std::string(getContentTypeForMountStr(mHdr.getContentType())) + ":/" + std::string(getProgramPartitionNameStr(index)));
|
2018-05-15 15:00:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-26 04:07:42 +00:00
|
|
|
pfs.setMountPointName(std::string(getContentTypeForMountStr(mHdr.getContentType())) + ":/");
|
2018-05-15 15:00:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 16:26:19 +00:00
|
|
|
if (mPartitionPath[index].doExtract)
|
|
|
|
pfs.setExtractPath(mPartitionPath[index].path);
|
2018-05-11 09:51:14 +00:00
|
|
|
pfs.process();
|
|
|
|
}
|
2018-08-07 07:17:51 +00:00
|
|
|
else if (partition.format_type == nn::hac::nca::FORMAT_ROMFS)
|
2018-05-11 09:51:14 +00:00
|
|
|
{
|
|
|
|
RomfsProcess romfs;
|
2018-09-23 03:29:22 +00:00
|
|
|
romfs.setInputFile(partition.reader);
|
2018-06-18 15:30:19 +00:00
|
|
|
romfs.setCliOutputMode(mCliOutputMode);
|
2018-05-11 09:51:14 +00:00
|
|
|
romfs.setListFs(mListFs);
|
2018-08-07 07:17:51 +00:00
|
|
|
if (mHdr.getContentType() == nn::hac::nca::TYPE_PROGRAM)
|
2018-05-15 15:00:07 +00:00
|
|
|
{
|
2018-08-04 02:05:47 +00:00
|
|
|
romfs.setMountPointName(std::string(getContentTypeForMountStr(mHdr.getContentType())) + ":/" + std::string(getProgramPartitionNameStr(index)));
|
2018-05-15 15:00:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-26 04:07:42 +00:00
|
|
|
romfs.setMountPointName(std::string(getContentTypeForMountStr(mHdr.getContentType())) + ":/");
|
2018-05-15 15:00:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 16:26:19 +00:00
|
|
|
if (mPartitionPath[index].doExtract)
|
|
|
|
romfs.setExtractPath(mPartitionPath[index].path);
|
2018-05-11 09:51:14 +00:00
|
|
|
romfs.process();
|
2018-04-25 15:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-12 05:23:39 +00:00
|
|
|
|
|
|
|
const char* NcaProcess::getFormatVersionStr(nn::hac::NcaHeader::FormatVersion format_ver) const
|
|
|
|
{
|
|
|
|
const char* str = nullptr;
|
|
|
|
|
|
|
|
switch (format_ver)
|
|
|
|
{
|
|
|
|
case (nn::hac::NcaHeader::NCA2_FORMAT):
|
|
|
|
str = "NCA2";
|
|
|
|
break;
|
|
|
|
case (nn::hac::NcaHeader::NCA3_FORMAT):
|
|
|
|
str = "NCA3";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* NcaProcess::getDistributionTypeStr(nn::hac::nca::DistributionType dist_type) const
|
|
|
|
{
|
|
|
|
const char* str = nullptr;
|
|
|
|
|
|
|
|
switch (dist_type)
|
|
|
|
{
|
|
|
|
case (nn::hac::nca::DIST_DOWNLOAD):
|
|
|
|
str = "Download";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::DIST_GAME_CARD):
|
|
|
|
str = "Game Card";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* NcaProcess::getContentTypeStr(nn::hac::nca::ContentType cont_type) const
|
|
|
|
{
|
|
|
|
const char* str = nullptr;
|
|
|
|
|
|
|
|
switch (cont_type)
|
|
|
|
{
|
|
|
|
case (nn::hac::nca::TYPE_PROGRAM):
|
|
|
|
str = "Program";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_META):
|
|
|
|
str = "Meta";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_CONTROL):
|
|
|
|
str = "Control";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_MANUAL):
|
|
|
|
str = "Manual";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_DATA):
|
|
|
|
str = "Data";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_PUBLIC_DATA):
|
|
|
|
str = "PublicData";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* NcaProcess::getEncryptionTypeStr(nn::hac::nca::EncryptionType enc_type) const
|
|
|
|
{
|
|
|
|
const char* str = nullptr;
|
|
|
|
|
|
|
|
switch (enc_type)
|
|
|
|
{
|
|
|
|
case (nn::hac::nca::CRYPT_AUTO):
|
|
|
|
str = "Auto";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::CRYPT_NONE):
|
|
|
|
str = "None";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::CRYPT_AESXTS):
|
|
|
|
str = "AesXts";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::CRYPT_AESCTR):
|
|
|
|
str = "AesCtr";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::CRYPT_AESCTREX):
|
|
|
|
str = "AesCtrEx";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* NcaProcess::getHashTypeStr(nn::hac::nca::HashType hash_type) const
|
|
|
|
{
|
|
|
|
const char* str = nullptr;
|
|
|
|
|
|
|
|
switch (hash_type)
|
|
|
|
{
|
|
|
|
case (nn::hac::nca::HASH_AUTO):
|
|
|
|
str = "Auto";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::HASH_NONE):
|
|
|
|
str = "None";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::HASH_HIERARCHICAL_SHA256):
|
|
|
|
str = "HierarchicalSha256";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::HASH_HIERARCHICAL_INTERGRITY):
|
|
|
|
str = "HierarchicalIntegrity";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* NcaProcess::getFormatTypeStr(nn::hac::nca::FormatType format_type) const
|
|
|
|
{
|
|
|
|
const char* str = nullptr;
|
|
|
|
|
|
|
|
switch (format_type)
|
|
|
|
{
|
|
|
|
case (nn::hac::nca::FORMAT_ROMFS):
|
|
|
|
str = "RomFs";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::FORMAT_PFS0):
|
|
|
|
str = "PartitionFs";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* NcaProcess::getKaekIndexStr(nn::hac::nca::KeyAreaEncryptionKeyIndex keak_index) const
|
|
|
|
{
|
|
|
|
const char* str = nullptr;
|
|
|
|
|
|
|
|
switch (keak_index)
|
|
|
|
{
|
|
|
|
case (nn::hac::nca::KAEK_IDX_APPLICATION):
|
|
|
|
str = "Application";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::KAEK_IDX_OCEAN):
|
|
|
|
str = "Ocean";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::KAEK_IDX_SYSTEM):
|
|
|
|
str = "System";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* NcaProcess::getContentTypeForMountStr(nn::hac::nca::ContentType cont_type) const
|
|
|
|
{
|
|
|
|
const char* str = nullptr;
|
|
|
|
|
|
|
|
switch (cont_type)
|
|
|
|
{
|
|
|
|
case (nn::hac::nca::TYPE_PROGRAM):
|
|
|
|
str = "program";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_META):
|
|
|
|
str = "meta";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_CONTROL):
|
|
|
|
str = "control";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_MANUAL):
|
|
|
|
str = "manual";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_DATA):
|
|
|
|
str = "data";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::TYPE_PUBLIC_DATA):
|
|
|
|
str = "publicData";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* NcaProcess::getProgramPartitionNameStr(size_t i) const
|
|
|
|
{
|
|
|
|
const char* str = nullptr;
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case (nn::hac::nca::PARTITION_CODE):
|
|
|
|
str = "code";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::PARTITION_DATA):
|
|
|
|
str = "data";
|
|
|
|
break;
|
|
|
|
case (nn::hac::nca::PARTITION_LOGO):
|
|
|
|
str = "logo";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|