mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-28 05:34:11 -04:00
strat: use m_ for member variables
This commit is contained in:
parent
ce28591ab2
commit
a595c232b9
425 changed files with 8531 additions and 8484 deletions
|
@ -35,10 +35,10 @@ namespace ams::fssystem {
|
|||
|
||||
}
|
||||
|
||||
NcaReader::NcaReader() : shared_base_storage(), header_storage(), body_storage(), decrypt_aes_ctr(), decrypt_aes_ctr_external(), is_software_aes_prioritized(false), header_encryption_type(NcaHeader::EncryptionType::Auto) {
|
||||
std::memset(std::addressof(this->header), 0, sizeof(this->header));
|
||||
std::memset(std::addressof(this->decryption_keys), 0, sizeof(this->decryption_keys));
|
||||
std::memset(std::addressof(this->external_decryption_key), 0, sizeof(this->external_decryption_key));
|
||||
NcaReader::NcaReader() : m_shared_base_storage(), m_header_storage(), m_body_storage(), m_decrypt_aes_ctr(), m_decrypt_aes_ctr_external(), m_is_software_aes_prioritized(false), m_header_encryption_type(NcaHeader::EncryptionType::Auto) {
|
||||
std::memset(std::addressof(m_header), 0, sizeof(m_header));
|
||||
std::memset(std::addressof(m_decryption_keys), 0, sizeof(m_decryption_keys));
|
||||
std::memset(std::addressof(m_external_decryption_key), 0, sizeof(m_external_decryption_key));
|
||||
}
|
||||
|
||||
NcaReader::~NcaReader() {
|
||||
|
@ -46,14 +46,14 @@ namespace ams::fssystem {
|
|||
}
|
||||
|
||||
Result NcaReader::Initialize(std::shared_ptr<fs::IStorage> base_storage, const NcaCryptoConfiguration &crypto_cfg) {
|
||||
this->shared_base_storage = base_storage;
|
||||
return this->Initialize(this->shared_base_storage.get(), crypto_cfg);
|
||||
m_shared_base_storage = base_storage;
|
||||
return this->Initialize(m_shared_base_storage.get(), crypto_cfg);
|
||||
}
|
||||
|
||||
Result NcaReader::Initialize(fs::IStorage *base_storage, const NcaCryptoConfiguration &crypto_cfg) {
|
||||
/* Validate preconditions. */
|
||||
AMS_ASSERT(base_storage != nullptr);
|
||||
AMS_ASSERT(this->body_storage == nullptr);
|
||||
AMS_ASSERT(m_body_storage == nullptr);
|
||||
R_UNLESS(crypto_cfg.generate_key != nullptr, fs::ResultInvalidArgument());
|
||||
|
||||
/* Generate keys for header. */
|
||||
|
@ -68,16 +68,16 @@ namespace ams::fssystem {
|
|||
R_UNLESS(work_header_storage != nullptr, fs::ResultAllocationFailureInNcaReaderA());
|
||||
|
||||
/* Read the header. */
|
||||
R_TRY(work_header_storage->Read(0, std::addressof(this->header), sizeof(this->header)));
|
||||
R_TRY(work_header_storage->Read(0, std::addressof(m_header), sizeof(m_header)));
|
||||
|
||||
/* Validate the magic. */
|
||||
if (Result magic_result = CheckNcaMagic(this->header.magic); R_FAILED(magic_result)) {
|
||||
if (Result magic_result = CheckNcaMagic(m_header.magic); R_FAILED(magic_result)) {
|
||||
/* If we're not allowed to use plaintext headers, stop here. */
|
||||
R_UNLESS(crypto_cfg.is_plaintext_header_available, magic_result);
|
||||
|
||||
/* Try to use a plaintext header. */
|
||||
R_TRY(base_storage->Read(0, std::addressof(this->header), sizeof(this->header)));
|
||||
R_UNLESS(R_SUCCEEDED(CheckNcaMagic(this->header.magic)), magic_result);
|
||||
R_TRY(base_storage->Read(0, std::addressof(m_header), sizeof(m_header)));
|
||||
R_UNLESS(R_SUCCEEDED(CheckNcaMagic(m_header.magic)), magic_result);
|
||||
|
||||
/* Configure to use the plaintext header. */
|
||||
s64 base_storage_size;
|
||||
|
@ -85,103 +85,103 @@ namespace ams::fssystem {
|
|||
work_header_storage.reset(new fs::SubStorage(base_storage, 0, base_storage_size));
|
||||
R_UNLESS(work_header_storage != nullptr, fs::ResultAllocationFailureInNcaReaderA());
|
||||
|
||||
this->header_encryption_type = NcaHeader::EncryptionType::None;
|
||||
m_header_encryption_type = NcaHeader::EncryptionType::None;
|
||||
}
|
||||
|
||||
/* Validate the fixed key signature. */
|
||||
R_UNLESS(this->header.header1_signature_key_generation <= NcaCryptoConfiguration::Header1SignatureKeyGenerationMax, fs::ResultInvalidNcaHeader1SignatureKeyGeneration());
|
||||
const u8 *header_1_sign_key_modulus = crypto_cfg.header_1_sign_key_moduli[this->header.header1_signature_key_generation];
|
||||
R_UNLESS(m_header.header1_signature_key_generation <= NcaCryptoConfiguration::Header1SignatureKeyGenerationMax, fs::ResultInvalidNcaHeader1SignatureKeyGeneration());
|
||||
const u8 *header_1_sign_key_modulus = crypto_cfg.header_1_sign_key_moduli[m_header.header1_signature_key_generation];
|
||||
AMS_ABORT_UNLESS(header_1_sign_key_modulus != nullptr);
|
||||
{
|
||||
const u8 *sig = this->header.header_sign_1;
|
||||
const u8 *sig = m_header.header_sign_1;
|
||||
const size_t sig_size = NcaHeader::HeaderSignSize;
|
||||
const u8 *mod = header_1_sign_key_modulus;
|
||||
const size_t mod_size = NcaCryptoConfiguration::Rsa2048KeyModulusSize;
|
||||
const u8 *exp = crypto_cfg.header_1_sign_key_public_exponent;
|
||||
const size_t exp_size = NcaCryptoConfiguration::Rsa2048KeyPublicExponentSize;
|
||||
const u8 *msg = static_cast<const u8 *>(static_cast<const void *>(std::addressof(this->header.magic)));
|
||||
const u8 *msg = static_cast<const u8 *>(static_cast<const void *>(std::addressof(m_header.magic)));
|
||||
const size_t msg_size = NcaHeader::Size - NcaHeader::HeaderSignSize * NcaHeader::HeaderSignCount;
|
||||
const bool is_signature_valid = crypto::VerifyRsa2048PssSha256(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size);
|
||||
R_UNLESS(is_signature_valid, fs::ResultNcaHeaderSignature1VerificationFailed());
|
||||
}
|
||||
|
||||
/* Validate the sdk version. */
|
||||
R_UNLESS(this->header.sdk_addon_version >= SdkAddonVersionMin, fs::ResultUnsupportedSdkVersion());
|
||||
R_UNLESS(m_header.sdk_addon_version >= SdkAddonVersionMin, fs::ResultUnsupportedSdkVersion());
|
||||
|
||||
/* Validate the key index. */
|
||||
R_UNLESS(this->header.key_index < NcaCryptoConfiguration::KeyAreaEncryptionKeyIndexCount, fs::ResultInvalidNcaKeyIndex());
|
||||
R_UNLESS(m_header.key_index < NcaCryptoConfiguration::KeyAreaEncryptionKeyIndexCount, fs::ResultInvalidNcaKeyIndex());
|
||||
|
||||
/* Check if we have a rights id. */
|
||||
constexpr const u8 ZeroRightsId[NcaHeader::RightsIdSize] = {};
|
||||
if (crypto::IsSameBytes(ZeroRightsId, this->header.rights_id, NcaHeader::RightsIdSize)) {
|
||||
if (crypto::IsSameBytes(ZeroRightsId, m_header.rights_id, NcaHeader::RightsIdSize)) {
|
||||
/* If we do, then we don't have an external key, so we need to generate decryption keys. */
|
||||
crypto_cfg.generate_key(this->decryption_keys[NcaHeader::DecryptionKey_AesCtr], crypto::AesDecryptor128::KeySize, this->header.encrypted_key_area + NcaHeader::DecryptionKey_AesCtr * crypto::AesDecryptor128::KeySize, crypto::AesDecryptor128::KeySize, GetKeyTypeValue(this->header.key_index, this->header.GetProperKeyGeneration()), crypto_cfg);
|
||||
crypto_cfg.generate_key(m_decryption_keys[NcaHeader::DecryptionKey_AesCtr], crypto::AesDecryptor128::KeySize, m_header.encrypted_key_area + NcaHeader::DecryptionKey_AesCtr * crypto::AesDecryptor128::KeySize, crypto::AesDecryptor128::KeySize, GetKeyTypeValue(m_header.key_index, m_header.GetProperKeyGeneration()), crypto_cfg);
|
||||
|
||||
/* Copy the hardware speed emulation key. */
|
||||
std::memcpy(this->decryption_keys[NcaHeader::DecryptionKey_AesCtrHw], this->header.encrypted_key_area + NcaHeader::DecryptionKey_AesCtrHw * crypto::AesDecryptor128::KeySize, crypto::AesDecryptor128::KeySize);
|
||||
std::memcpy(m_decryption_keys[NcaHeader::DecryptionKey_AesCtrHw], m_header.encrypted_key_area + NcaHeader::DecryptionKey_AesCtrHw * crypto::AesDecryptor128::KeySize, crypto::AesDecryptor128::KeySize);
|
||||
}
|
||||
|
||||
/* Clear the external decryption key. */
|
||||
std::memset(this->external_decryption_key, 0, sizeof(this->external_decryption_key));
|
||||
std::memset(m_external_decryption_key, 0, sizeof(m_external_decryption_key));
|
||||
|
||||
/* Set our decryptor functions. */
|
||||
this->decrypt_aes_ctr = crypto_cfg.decrypt_aes_ctr;
|
||||
this->decrypt_aes_ctr_external = crypto_cfg.decrypt_aes_ctr_external;
|
||||
m_decrypt_aes_ctr = crypto_cfg.decrypt_aes_ctr;
|
||||
m_decrypt_aes_ctr_external = crypto_cfg.decrypt_aes_ctr_external;
|
||||
|
||||
/* Set our storages. */
|
||||
this->header_storage = std::move(work_header_storage);
|
||||
this->body_storage = base_storage;
|
||||
m_header_storage = std::move(work_header_storage);
|
||||
m_body_storage = base_storage;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
fs::IStorage *NcaReader::GetBodyStorage() {
|
||||
return this->body_storage;
|
||||
return m_body_storage;
|
||||
}
|
||||
|
||||
u32 NcaReader::GetMagic() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
return this->header.magic;
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
return m_header.magic;
|
||||
}
|
||||
|
||||
NcaHeader::DistributionType NcaReader::GetDistributionType() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
return this->header.distribution_type;
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
return m_header.distribution_type;
|
||||
}
|
||||
|
||||
NcaHeader::ContentType NcaReader::GetContentType() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
return this->header.content_type;
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
return m_header.content_type;
|
||||
}
|
||||
|
||||
u8 NcaReader::GetKeyGeneration() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
return this->header.GetProperKeyGeneration();
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
return m_header.GetProperKeyGeneration();
|
||||
}
|
||||
|
||||
u8 NcaReader::GetKeyIndex() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
return this->header.key_index;
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
return m_header.key_index;
|
||||
}
|
||||
|
||||
u64 NcaReader::GetContentSize() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
return this->header.content_size;
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
return m_header.content_size;
|
||||
}
|
||||
|
||||
u64 NcaReader::GetProgramId() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
return this->header.program_id;
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
return m_header.program_id;
|
||||
}
|
||||
|
||||
u32 NcaReader::GetContentIndex() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
return this->header.content_index;
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
return m_header.content_index;
|
||||
}
|
||||
|
||||
u32 NcaReader::GetSdkAddonVersion() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
return this->header.sdk_addon_version;
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
return m_header.sdk_addon_version;
|
||||
}
|
||||
|
||||
void NcaReader::GetRightsId(u8 *dst, size_t dst_size) const {
|
||||
|
@ -189,16 +189,16 @@ namespace ams::fssystem {
|
|||
AMS_ASSERT(dst_size >= NcaHeader::RightsIdSize);
|
||||
AMS_UNUSED(dst_size);
|
||||
|
||||
std::memcpy(dst, this->header.rights_id, NcaHeader::RightsIdSize);
|
||||
std::memcpy(dst, m_header.rights_id, NcaHeader::RightsIdSize);
|
||||
}
|
||||
|
||||
bool NcaReader::HasFsInfo(s32 index) const {
|
||||
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
|
||||
return this->header.fs_info[index].start_sector != 0 || this->header.fs_info[index].end_sector != 0;
|
||||
return m_header.fs_info[index].start_sector != 0 || m_header.fs_info[index].end_sector != 0;
|
||||
}
|
||||
|
||||
s32 NcaReader::GetFsCount() const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
for (s32 i = 0; i < NcaHeader::FsCountMax; i++) {
|
||||
if (!this->HasFsInfo(i)) {
|
||||
return i;
|
||||
|
@ -208,62 +208,62 @@ namespace ams::fssystem {
|
|||
}
|
||||
|
||||
const Hash &NcaReader::GetFsHeaderHash(s32 index) const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
|
||||
return this->header.fs_header_hash[index];
|
||||
return m_header.fs_header_hash[index];
|
||||
}
|
||||
|
||||
void NcaReader::GetFsHeaderHash(Hash *dst, s32 index) const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
|
||||
AMS_ASSERT(dst != nullptr);
|
||||
std::memcpy(dst, std::addressof(this->header.fs_header_hash[index]), sizeof(*dst));
|
||||
std::memcpy(dst, std::addressof(m_header.fs_header_hash[index]), sizeof(*dst));
|
||||
}
|
||||
|
||||
void NcaReader::GetFsInfo(NcaHeader::FsInfo *dst, s32 index) const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
|
||||
AMS_ASSERT(dst != nullptr);
|
||||
std::memcpy(dst, std::addressof(this->header.fs_info[index]), sizeof(*dst));
|
||||
std::memcpy(dst, std::addressof(m_header.fs_info[index]), sizeof(*dst));
|
||||
}
|
||||
|
||||
u64 NcaReader::GetFsOffset(s32 index) const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
|
||||
return NcaHeader::SectorToByte(this->header.fs_info[index].start_sector);
|
||||
return NcaHeader::SectorToByte(m_header.fs_info[index].start_sector);
|
||||
}
|
||||
|
||||
u64 NcaReader::GetFsEndOffset(s32 index) const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
|
||||
return NcaHeader::SectorToByte(this->header.fs_info[index].end_sector);
|
||||
return NcaHeader::SectorToByte(m_header.fs_info[index].end_sector);
|
||||
}
|
||||
|
||||
u64 NcaReader::GetFsSize(s32 index) const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
|
||||
return NcaHeader::SectorToByte(this->header.fs_info[index].end_sector - this->header.fs_info[index].start_sector);
|
||||
return NcaHeader::SectorToByte(m_header.fs_info[index].end_sector - m_header.fs_info[index].start_sector);
|
||||
}
|
||||
|
||||
void NcaReader::GetEncryptedKey(void *dst, size_t size) const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
AMS_ASSERT(dst != nullptr);
|
||||
AMS_ASSERT(size >= NcaHeader::EncryptedKeyAreaSize);
|
||||
AMS_UNUSED(size);
|
||||
|
||||
std::memcpy(dst, this->header.encrypted_key_area, NcaHeader::EncryptedKeyAreaSize);
|
||||
std::memcpy(dst, m_header.encrypted_key_area, NcaHeader::EncryptedKeyAreaSize);
|
||||
}
|
||||
|
||||
const void *NcaReader::GetDecryptionKey(s32 index) const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
AMS_ASSERT(0 <= index && index < NcaHeader::DecryptionKey_Count);
|
||||
return this->decryption_keys[index];
|
||||
return m_decryption_keys[index];
|
||||
}
|
||||
|
||||
bool NcaReader::HasValidInternalKey() const {
|
||||
constexpr const u8 ZeroKey[crypto::AesDecryptor128::KeySize] = {};
|
||||
for (s32 i = 0; i < NcaHeader::DecryptionKey_Count; i++) {
|
||||
if (!crypto::IsSameBytes(ZeroKey, this->header.encrypted_key_area + i * crypto::AesDecryptor128::KeySize, crypto::AesDecryptor128::KeySize)) {
|
||||
if (!crypto::IsSameBytes(ZeroKey, m_header.encrypted_key_area + i * crypto::AesDecryptor128::KeySize, crypto::AesDecryptor128::KeySize)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -276,11 +276,11 @@ namespace ams::fssystem {
|
|||
}
|
||||
|
||||
bool NcaReader::IsSoftwareAesPrioritized() const {
|
||||
return this->is_software_aes_prioritized;
|
||||
return m_is_software_aes_prioritized;
|
||||
}
|
||||
|
||||
void NcaReader::PrioritizeSoftwareAes() {
|
||||
this->is_software_aes_prioritized = true;
|
||||
m_is_software_aes_prioritized = true;
|
||||
}
|
||||
|
||||
bool NcaReader::HasExternalDecryptionKey() const {
|
||||
|
@ -289,38 +289,38 @@ namespace ams::fssystem {
|
|||
}
|
||||
|
||||
const void *NcaReader::GetExternalDecryptionKey() const {
|
||||
return this->external_decryption_key;
|
||||
return m_external_decryption_key;
|
||||
}
|
||||
|
||||
void NcaReader::SetExternalDecryptionKey(const void *src, size_t size) {
|
||||
AMS_ASSERT(src != nullptr);
|
||||
AMS_ASSERT(size == sizeof(this->external_decryption_key));
|
||||
AMS_ASSERT(size == sizeof(m_external_decryption_key));
|
||||
AMS_UNUSED(size);
|
||||
|
||||
std::memcpy(this->external_decryption_key, src, sizeof(this->external_decryption_key));
|
||||
std::memcpy(m_external_decryption_key, src, sizeof(m_external_decryption_key));
|
||||
}
|
||||
|
||||
void NcaReader::GetRawData(void *dst, size_t dst_size) const {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
AMS_ASSERT(dst != nullptr);
|
||||
AMS_ASSERT(dst_size >= sizeof(NcaHeader));
|
||||
AMS_UNUSED(dst_size);
|
||||
|
||||
std::memcpy(dst, std::addressof(this->header), sizeof(NcaHeader));
|
||||
std::memcpy(dst, std::addressof(m_header), sizeof(NcaHeader));
|
||||
}
|
||||
|
||||
DecryptAesCtrFunction NcaReader::GetExternalDecryptAesCtrFunction() const {
|
||||
AMS_ASSERT(this->decrypt_aes_ctr != nullptr);
|
||||
return this->decrypt_aes_ctr;
|
||||
AMS_ASSERT(m_decrypt_aes_ctr != nullptr);
|
||||
return m_decrypt_aes_ctr;
|
||||
}
|
||||
|
||||
DecryptAesCtrFunction NcaReader::GetExternalDecryptAesCtrFunctionForExternalKey() const {
|
||||
AMS_ASSERT(this->decrypt_aes_ctr_external != nullptr);
|
||||
return this->decrypt_aes_ctr_external;
|
||||
AMS_ASSERT(m_decrypt_aes_ctr_external != nullptr);
|
||||
return m_decrypt_aes_ctr_external;
|
||||
}
|
||||
|
||||
NcaHeader::EncryptionType NcaReader::GetEncryptionType() const {
|
||||
return this->header_encryption_type;
|
||||
return m_header_encryption_type;
|
||||
}
|
||||
|
||||
Result NcaReader::ReadHeader(NcaFsHeader *dst, s32 index) const {
|
||||
|
@ -328,18 +328,18 @@ namespace ams::fssystem {
|
|||
AMS_ASSERT(0 <= index && index < NcaHeader::FsCountMax);
|
||||
|
||||
const s64 offset = sizeof(NcaHeader) + sizeof(NcaFsHeader) * index;
|
||||
return this->header_storage->Read(offset, dst, sizeof(NcaFsHeader));
|
||||
return m_header_storage->Read(offset, dst, sizeof(NcaFsHeader));
|
||||
}
|
||||
|
||||
Result NcaReader::VerifyHeaderSign2(const void *mod, size_t mod_size) {
|
||||
AMS_ASSERT(this->body_storage != nullptr);
|
||||
AMS_ASSERT(m_body_storage != nullptr);
|
||||
constexpr const u8 HeaderSign2KeyPublicExponent[] = { 0x01, 0x00, 0x01 };
|
||||
|
||||
const u8 *sig = this->header.header_sign_2;
|
||||
const u8 *sig = m_header.header_sign_2;
|
||||
const size_t sig_size = NcaHeader::HeaderSignSize;
|
||||
const u8 *exp = HeaderSign2KeyPublicExponent;
|
||||
const size_t exp_size = sizeof(HeaderSign2KeyPublicExponent);
|
||||
const u8 *msg = static_cast<const u8 *>(static_cast<const void *>(std::addressof(this->header.magic)));
|
||||
const u8 *msg = static_cast<const u8 *>(static_cast<const void *>(std::addressof(m_header.magic)));
|
||||
const size_t msg_size = NcaHeader::Size - NcaHeader::HeaderSignSize * NcaHeader::HeaderSignCount;
|
||||
const bool is_signature_valid = crypto::VerifyRsa2048PssSha256(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size);
|
||||
R_UNLESS(is_signature_valid, fs::ResultNcaHeaderSignature2VerificationFailed());
|
||||
|
@ -349,20 +349,20 @@ namespace ams::fssystem {
|
|||
|
||||
Result NcaFsHeaderReader::Initialize(const NcaReader &reader, s32 index) {
|
||||
/* Reset ourselves to uninitialized. */
|
||||
this->fs_index = -1;
|
||||
m_fs_index = -1;
|
||||
|
||||
/* Read the header. */
|
||||
R_TRY(reader.ReadHeader(std::addressof(this->data), index));
|
||||
R_TRY(reader.ReadHeader(std::addressof(m_data), index));
|
||||
|
||||
/* Generate the hash. */
|
||||
Hash hash;
|
||||
crypto::GenerateSha256Hash(std::addressof(hash), sizeof(hash), std::addressof(this->data), sizeof(NcaFsHeader));
|
||||
crypto::GenerateSha256Hash(std::addressof(hash), sizeof(hash), std::addressof(m_data), sizeof(NcaFsHeader));
|
||||
|
||||
/* Validate the hash. */
|
||||
R_UNLESS(crypto::IsSameBytes(std::addressof(reader.GetFsHeaderHash(index)), std::addressof(hash), sizeof(Hash)), fs::ResultNcaFsHeaderHashVerificationFailed());
|
||||
|
||||
/* Set our index. */
|
||||
this->fs_index = index;
|
||||
m_fs_index = index;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
@ -372,72 +372,72 @@ namespace ams::fssystem {
|
|||
AMS_ASSERT(dst_size >= sizeof(NcaFsHeader));
|
||||
AMS_UNUSED(dst_size);
|
||||
|
||||
std::memcpy(dst, std::addressof(this->data), sizeof(NcaFsHeader));
|
||||
std::memcpy(dst, std::addressof(m_data), sizeof(NcaFsHeader));
|
||||
}
|
||||
|
||||
NcaFsHeader::HashData &NcaFsHeaderReader::GetHashData() {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.hash_data;
|
||||
return m_data.hash_data;
|
||||
}
|
||||
|
||||
const NcaFsHeader::HashData &NcaFsHeaderReader::GetHashData() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.hash_data;
|
||||
return m_data.hash_data;
|
||||
}
|
||||
|
||||
u16 NcaFsHeaderReader::GetVersion() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.version;
|
||||
return m_data.version;
|
||||
}
|
||||
|
||||
s32 NcaFsHeaderReader::GetFsIndex() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->fs_index;
|
||||
return m_fs_index;
|
||||
}
|
||||
|
||||
NcaFsHeader::FsType NcaFsHeaderReader::GetFsType() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.fs_type;
|
||||
return m_data.fs_type;
|
||||
}
|
||||
|
||||
NcaFsHeader::HashType NcaFsHeaderReader::GetHashType() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.hash_type;
|
||||
return m_data.hash_type;
|
||||
}
|
||||
|
||||
NcaFsHeader::EncryptionType NcaFsHeaderReader::GetEncryptionType() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.encryption_type;
|
||||
return m_data.encryption_type;
|
||||
}
|
||||
|
||||
NcaPatchInfo &NcaFsHeaderReader::GetPatchInfo() {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.patch_info;
|
||||
return m_data.patch_info;
|
||||
}
|
||||
|
||||
const NcaPatchInfo &NcaFsHeaderReader::GetPatchInfo() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.patch_info;
|
||||
return m_data.patch_info;
|
||||
}
|
||||
|
||||
const NcaAesCtrUpperIv NcaFsHeaderReader::GetAesCtrUpperIv() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.aes_ctr_upper_iv;
|
||||
return m_data.aes_ctr_upper_iv;
|
||||
}
|
||||
|
||||
bool NcaFsHeaderReader::ExistsSparseLayer() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.sparse_info.generation != 0;
|
||||
return m_data.sparse_info.generation != 0;
|
||||
}
|
||||
|
||||
NcaSparseInfo &NcaFsHeaderReader::GetSparseInfo() {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.sparse_info;
|
||||
return m_data.sparse_info;
|
||||
}
|
||||
|
||||
const NcaSparseInfo &NcaFsHeaderReader::GetSparseInfo() const {
|
||||
AMS_ASSERT(this->IsInitialized());
|
||||
return this->data.sparse_info;
|
||||
return m_data.sparse_info;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue