Simplify TitleKeysBin implementation to a simple function

This commit is contained in:
Pengfei
2021-07-16 21:46:10 +08:00
parent 374470cd60
commit 55db5f110f
3 changed files with 9 additions and 28 deletions
+4 -3
View File
@@ -154,10 +154,11 @@ bool CIABuilder::WriteTicket(const std::string& ticket_db_path,
ticket.body.common_key_index = legit_ticket.body.common_key_index;
ticket.body.title_key = legit_ticket.body.title_key;
} else if (TitleKeysBin enc_title_keys(enc_title_keys_bin_path);
enc_title_keys.IsGood() && enc_title_keys.entries.count(title_id)) { // support files
} else if (TitleKeysMap enc_title_keys;
LoadTitleKeysBin(enc_title_keys, enc_title_keys_bin_path) &&
enc_title_keys.count(title_id)) { // support files
const auto& entry = enc_title_keys.entries.at(title_id);
const auto& entry = enc_title_keys.at(title_id);
ticket.body.common_key_index = entry.common_key_index;
ticket.body.title_key = entry.title_key;
} else {
+2 -12
View File
@@ -7,17 +7,7 @@
namespace Core {
TitleKeysBin::TitleKeysBin(const std::string& path) {
is_good = Load(path);
}
TitleKeysBin::~TitleKeysBin() = default;
bool TitleKeysBin::IsGood() const {
return is_good;
}
bool TitleKeysBin::Load(const std::string& path) {
bool LoadTitleKeysBin(TitleKeysMap& out, const std::string& path) {
FileUtil::IOFile file(path, "rb");
if (!file) {
LOG_ERROR(Core, "Could not open file {}", path);
@@ -36,7 +26,7 @@ bool TitleKeysBin::Load(const std::string& path) {
LOG_ERROR(Core, "Could not read entry {} from {}", i, path);
return false;
}
entries.emplace(entry.title_id, entry);
out.emplace(entry.title_id, entry);
}
if (file.Tell() != file.GetSize()) {
+3 -13
View File
@@ -26,19 +26,9 @@ struct TitleKeysBinEntry {
};
static_assert(sizeof(TitleKeysBinEntry) == 32);
using TitleKeysMap = std::unordered_map<u64, TitleKeysBinEntry>;
// GM9 support files encTitleKeys.bin and decTitleKeys.bin.
class TitleKeysBin {
public:
explicit TitleKeysBin(const std::string& path);
~TitleKeysBin();
bool IsGood() const;
std::unordered_map<u64, TitleKeysBinEntry> entries;
private:
bool Load(const std::string& path);
bool is_good = false;
};
bool LoadTitleKeysBin(TitleKeysMap& out, const std::string& path);
} // namespace Core