From d78fd19ab4c79b55276466dc6091409b0c708ad2 Mon Sep 17 00:00:00 2001 From: Gliniak Date: Fri, 29 Apr 2022 20:33:21 +0200 Subject: [PATCH] Fixed incorrect hash generation + lint fixes --- src/xenia/cpu/xex_module.cc | 2 -- src/xenia/kernel/user_module.cc | 22 ++++++++++------------ src/xenia/kernel/user_module.h | 1 + src/xenia/patcher/patch_db.cc | 5 +++-- src/xenia/patcher/patch_db.h | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/xenia/cpu/xex_module.cc b/src/xenia/cpu/xex_module.cc index 672d44666..b0b963467 100644 --- a/src/xenia/cpu/xex_module.cc +++ b/src/xenia/cpu/xex_module.cc @@ -930,8 +930,6 @@ bool XexModule::Load(const std::string_view name, const std::string_view path, name_ = name; path_ = path; - uint8_t* data = memory()->TranslateVirtual(base_address_); - // Load in the XEX basefile // We'll try using both XEX2 keys to see if any give a valid PE int result_code = ReadImage(xex_addr, xex_length, false); diff --git a/src/xenia/kernel/user_module.cc b/src/xenia/kernel/user_module.cc index e9ed11e2b..c12da3705 100644 --- a/src/xenia/kernel/user_module.cc +++ b/src/xenia/kernel/user_module.cc @@ -73,12 +73,6 @@ X_STATUS UserModule::LoadFromFile(const std::string_view path) { // Load the module. result = LoadFromMemory(mmap->data(), mmap->size()); - if (XSUCCEEDED(result)) { - XXH3_state_t hash_state; - XXH3_64bits_reset(&hash_state); - XXH3_64bits_update(&hash_state, mmap->data(), mmap->size()); - hash_ = XXH3_64bits_digest(&hash_state); - } } else { std::vector buffer(fs_entry->size()); @@ -100,12 +94,6 @@ X_STATUS UserModule::LoadFromFile(const std::string_view path) { // Load the module. result = LoadFromMemory(buffer.data(), bytes_read); - // Generate xex hash - XXH3_state_t hash_state; - XXH3_64bits_reset(&hash_state); - XXH3_64bits_update(&hash_state, buffer.data(), bytes_read); - hash_ = XXH3_64bits_digest(&hash_state); - // Close the file. file->Destroy(); } @@ -141,6 +129,8 @@ X_STATUS UserModule::LoadFromFile(const std::string_view path) { } } + CalculateHash(); + XELOGI("Module hash: {:016X} for {}", hash_, name_); return LoadXexContinue(); } @@ -818,5 +808,13 @@ void UserModule::Dump() { xe::logging::AppendLogLine(xe::LogLevel::Info, 'i', sb.to_string_view()); } +void UserModule::CalculateHash() { + uint8_t* base_adr = memory()->TranslateVirtual(xex_module()->base_address()); + + XXH3_state_t hash_state; + XXH3_64bits_reset(&hash_state); + XXH3_64bits_update(&hash_state, base_adr, xex_module()->image_size()); + hash_ = XXH3_64bits_digest(&hash_state); +} } // namespace kernel } // namespace xe diff --git a/src/xenia/kernel/user_module.h b/src/xenia/kernel/user_module.h index 7b949ce86..a11deba73 100644 --- a/src/xenia/kernel/user_module.h +++ b/src/xenia/kernel/user_module.h @@ -98,6 +98,7 @@ class UserModule : public XModule { private: X_STATUS LoadXexContinue(); + void CalculateHash(); std::string name_; std::string path_; diff --git a/src/xenia/patcher/patch_db.cc b/src/xenia/patcher/patch_db.cc index c1e1d0267..9a830e226 100644 --- a/src/xenia/patcher/patch_db.cc +++ b/src/xenia/patcher/patch_db.cc @@ -15,7 +15,8 @@ #include "xenia/patcher/patch_db.h" -DEFINE_bool(apply_patches, true, "Enables custom patching functionality", "General"); +DEFINE_bool(apply_patches, true, "Enables custom patching functionality", + "General"); namespace xe { namespace patcher { @@ -183,7 +184,7 @@ std::vector PatchDB::GetTitlePatches(uint32_t title_id, return title_patches; } -void PatchDB::ReadHash(PatchFileEntry &patchEntry, +void PatchDB::ReadHash(PatchFileEntry& patchEntry, std::shared_ptr patch_toml_fields) { auto title_hashes = patch_toml_fields->get_array_of("hash"); diff --git a/src/xenia/patcher/patch_db.h b/src/xenia/patcher/patch_db.h index c6adecf26..f4991cfb1 100644 --- a/src/xenia/patcher/patch_db.h +++ b/src/xenia/patcher/patch_db.h @@ -124,7 +124,7 @@ class PatchDB { {"be16", PatchData(sizeof(uint16_t), PatchDataType::be16)}, {"be8", PatchData(sizeof(uint8_t), PatchDataType::be8)}}; - void ReadHash(PatchFileEntry &patchEntry, + void ReadHash(PatchFileEntry& patchEntry, std::shared_ptr patch_toml_fields); }; } // namespace patcher