Added encryption scheme display.

This commit is contained in:
zhupengfei
2020-01-17 10:10:58 +08:00
parent 48c7c3d70d
commit 0708744a17
6 changed files with 125 additions and 14 deletions
+13 -5
View File
@@ -296,7 +296,8 @@ std::vector<ContentSpecifier> SDMCImporter::ListContent() const {
// Regex for half Title IDs
static const std::regex title_regex{"[0-9a-f]{8}"};
std::pair<std::string, u64> SDMCImporter::LoadTitleData(const std::string& path) const {
std::tuple<std::string, u64, EncryptionType, bool> SDMCImporter::LoadTitleData(
const std::string& path) const {
// Remove trailing '/'
const auto sdmc_path = config.sdmc_path.substr(0, config.sdmc_path.size() - 1);
@@ -356,8 +357,14 @@ std::pair<std::string, u64> SDMCImporter::LoadTitleData(const std::string& path)
u64 extdata_id{};
ncch.ReadExtdataId(extdata_id);
return {Common::UTF16BufferToUTF8(smdh.GetShortTitle(SMDH::TitleLanguage::English)),
extdata_id};
EncryptionType encryption = EncryptionType::None;
ncch.ReadEncryptionType(encryption);
bool seed_crypto{};
ncch.ReadSeedCrypto(seed_crypto);
return {Common::UTF16BufferToUTF8(smdh.GetShortTitle(SMDH::TitleLanguage::English)), extdata_id,
encryption, seed_crypto};
}
void SDMCImporter::ListTitle(std::vector<ContentSpecifier>& out) const {
@@ -385,11 +392,12 @@ void SDMCImporter::ListTitle(std::vector<ContentSpecifier>& out) const {
if (FileUtil::Exists(directory + virtual_name + "/content/")) {
const auto content_path =
fmt::format("/title/{:08x}/{}/content/", high_id, virtual_name);
const auto& [name, extdata_id] = LoadTitleData(content_path);
const auto& [name, extdata_id, encryption, seed_crypto] =
LoadTitleData(content_path);
out.push_back(
{type, id, FileUtil::Exists(citra_path + "content/"),
FileUtil::GetDirectoryTreeSize(directory + virtual_name + "/content/"),
name, extdata_id});
name, extdata_id, encryption, seed_crypto});
}
if (type != ContentType::Application) {
+17 -2
View File
@@ -27,6 +27,18 @@ enum class ContentType {
Sysdata,
};
/**
* Encryption type of an importable content.
*/
enum class EncryptionType {
None,
FixedKey,
NCCHSecure1,
NCCHSecure2,
NCCHSecure3,
NCCHSecure4,
};
/**
* Struct that specifies an importable content.
*/
@@ -37,6 +49,8 @@ struct ContentSpecifier {
u64 maximum_size; ///< The maximum size of the content. May be slightly bigger than real size.
std::string name; ///< Optional. The content's preferred display name.
u64 extdata_id; ///< Extdata ID for Applications.
EncryptionType encryption = EncryptionType::None; ///< Only for NCCHs. Encryption scheme.
bool seed_crypto = false; ///< Only for NCCHs. Whether seed crypto is used.
};
/**
@@ -126,11 +140,12 @@ private:
void DeleteSysdata(u64 id) const;
/**
* Loads the English short title name and extdata id of a title.
* Loads the English short title name, extdata id and encryption of a title.
* @param path Path of the 'content' folder relative to the SDMC root folder.
* Required to end with '/'.
* @return {name, extdata_id, encryption, seed_crypto}
*/
std::pair<std::string, u64> LoadTitleData(const std::string& path) const;
std::tuple<std::string, u64, EncryptionType, bool> LoadTitleData(const std::string& path) const;
bool is_good{};
Config config;
+47
View File
@@ -309,6 +309,53 @@ bool NCCHContainer::HasExHeader() {
return has_exheader;
}
ResultStatus NCCHContainer::ReadEncryptionType(EncryptionType& encryption) {
ResultStatus result = Load();
if (result != ResultStatus::Success)
return result;
if (!has_header)
return ResultStatus::ErrorNotUsed;
if (!is_encrypted) {
encryption = EncryptionType::None;
} else if (ncch_header.fixed_key) {
encryption = EncryptionType::FixedKey;
} else {
switch (ncch_header.secondary_key_slot) {
case 0:
encryption = EncryptionType::NCCHSecure1;
break;
case 1:
encryption = EncryptionType::NCCHSecure2;
break;
case 10:
encryption = EncryptionType::NCCHSecure3;
break;
case 11:
encryption = EncryptionType::NCCHSecure4;
break;
default:
LOG_ERROR(Service_FS, "Unknown encryption type {:X}!", ncch_header.secondary_key_slot);
return ResultStatus::ErrorNotUsed;
}
}
return ResultStatus::Success;
}
ResultStatus NCCHContainer::ReadSeedCrypto(bool& used) {
ResultStatus result = Load();
if (result != ResultStatus::Success)
return result;
if (!has_header)
return ResultStatus::ErrorNotUsed;
used = ncch_header.seed_crypto;
return ResultStatus::Success;
}
#pragma pack(push, 1)
struct RomFSIVFCHeader {
u32_le magic;
+13
View File
@@ -13,6 +13,7 @@
#include "common/file_util.h"
#include "common/swap.h"
#include "core/decryptor.h"
#include "core/importer.h"
#include "core/result_status.h"
namespace Core {
@@ -252,6 +253,18 @@ public:
*/
bool HasExHeader();
/**
* Gets encryption type (which key is used).
* @return ResultStatus result of function.
*/
ResultStatus ReadEncryptionType(EncryptionType& encryption);
/**
* Gets whether seed crypto is used.
* @return ResultStatus result of function.
*/
ResultStatus ReadSeedCrypto(bool& used);
NCCH_Header ncch_header;
ExHeader_Header exheader_header;
ExeFs_Header exefs_header;