2019-01-31 09:10:19 +00:00
|
|
|
#pragma once
|
2021-09-28 11:15:54 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "KeyBag.h"
|
2019-01-31 09:10:19 +00:00
|
|
|
|
2021-09-28 11:15:54 +00:00
|
|
|
#include <nn/hac/ContentArchiveHeader.h>
|
2019-01-31 09:10:19 +00:00
|
|
|
|
2021-09-28 11:15:54 +00:00
|
|
|
namespace nstool {
|
2019-01-31 09:10:19 +00:00
|
|
|
|
|
|
|
class NcaProcess
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NcaProcess();
|
|
|
|
|
|
|
|
void process();
|
|
|
|
|
|
|
|
// generic
|
2021-09-28 11:15:54 +00:00
|
|
|
void setInputFile(const std::shared_ptr<tc::io::IStream>& file);
|
|
|
|
void setKeyCfg(const KeyBag& keycfg);
|
2019-01-31 09:10:19 +00:00
|
|
|
void setCliOutputMode(CliOutputMode type);
|
|
|
|
void setVerifyMode(bool verify);
|
|
|
|
|
|
|
|
// nca specfic
|
|
|
|
void setPartition0ExtractPath(const std::string& path);
|
|
|
|
void setPartition1ExtractPath(const std::string& path);
|
|
|
|
void setPartition2ExtractPath(const std::string& path);
|
|
|
|
void setPartition3ExtractPath(const std::string& path);
|
|
|
|
void setListFs(bool list_fs);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string kModuleName = "NcaProcess";
|
|
|
|
const std::string kNpdmExefsPath = "main.npdm";
|
|
|
|
|
|
|
|
// user options
|
2021-09-28 11:15:54 +00:00
|
|
|
std::shared_ptr<tc::io::IStream> mFile;
|
|
|
|
KeyBag mKeyCfg;
|
2019-01-31 09:10:19 +00:00
|
|
|
CliOutputMode mCliOutputMode;
|
|
|
|
bool mVerify;
|
|
|
|
|
|
|
|
struct sExtract
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
bool doExtract;
|
|
|
|
} mPartitionPath[nn::hac::nca::kPartitionNum];
|
|
|
|
|
|
|
|
bool mListFs;
|
|
|
|
|
|
|
|
// data
|
|
|
|
nn::hac::sContentArchiveHeaderBlock mHdrBlock;
|
|
|
|
fnd::sha::sSha256Hash mHdrHash;
|
|
|
|
nn::hac::ContentArchiveHeader mHdr;
|
|
|
|
|
|
|
|
// crypto
|
|
|
|
struct sKeys
|
|
|
|
{
|
|
|
|
struct sKeyAreaKey
|
|
|
|
{
|
|
|
|
byte_t index;
|
|
|
|
bool decrypted;
|
2021-09-28 11:15:54 +00:00
|
|
|
KeyBag::aes128_key_t enc;
|
|
|
|
KeyBag::aes128_key_t dec;
|
2019-01-31 09:10:19 +00:00
|
|
|
|
|
|
|
void operator=(const sKeyAreaKey& other)
|
|
|
|
{
|
|
|
|
index = other.index;
|
|
|
|
decrypted = other.decrypted;
|
|
|
|
enc = other.enc;
|
|
|
|
dec = other.dec;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const sKeyAreaKey& other) const
|
|
|
|
{
|
|
|
|
return (index == other.index) \
|
|
|
|
&& (decrypted == other.decrypted) \
|
|
|
|
&& (enc == other.enc) \
|
|
|
|
&& (dec == other.dec);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const sKeyAreaKey& other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
};
|
2021-09-28 11:15:54 +00:00
|
|
|
std::vector<sKeyAreaKey> kak_list;
|
2019-01-31 09:10:19 +00:00
|
|
|
|
2021-09-28 11:15:54 +00:00
|
|
|
tc::Optional<KeyBag::aes128_key_t> aes_ctr;
|
2019-01-31 09:10:19 +00:00
|
|
|
} mContentKey;
|
|
|
|
|
|
|
|
struct sPartitionInfo
|
|
|
|
{
|
2021-09-28 11:15:54 +00:00
|
|
|
std::shared_ptr<tc::io::IStream> reader;
|
2019-01-31 09:10:19 +00:00
|
|
|
std::string fail_reason;
|
|
|
|
size_t offset;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
// meta data
|
|
|
|
nn::hac::nca::FormatType format_type;
|
|
|
|
nn::hac::nca::HashType hash_type;
|
|
|
|
nn::hac::nca::EncryptionType enc_type;
|
|
|
|
fnd::LayeredIntegrityMetadata layered_intergrity_metadata;
|
|
|
|
fnd::aes::sAesIvCtr aes_ctr;
|
|
|
|
} mPartitions[nn::hac::nca::kPartitionNum];
|
|
|
|
|
|
|
|
void importHeader();
|
|
|
|
void generateNcaBodyEncryptionKeys();
|
|
|
|
void generatePartitionConfiguration();
|
|
|
|
void validateNcaSignatures();
|
|
|
|
void displayHeader();
|
|
|
|
void processPartitions();
|
|
|
|
|
|
|
|
const char* getContentTypeForMountStr(nn::hac::nca::ContentType cont_type) const;
|
2021-09-28 11:15:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|