Fixed incorrect hash generation + lint fixes

This commit is contained in:
Gliniak 2022-04-29 20:33:21 +02:00
parent 585b208fc0
commit d78fd19ab4
5 changed files with 15 additions and 17 deletions

View File

@ -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);

View File

@ -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<uint8_t> 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

View File

@ -98,6 +98,7 @@ class UserModule : public XModule {
private:
X_STATUS LoadXexContinue();
void CalculateHash();
std::string name_;
std::string path_;

View File

@ -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<PatchFileEntry> PatchDB::GetTitlePatches(uint32_t title_id,
return title_patches;
}
void PatchDB::ReadHash(PatchFileEntry &patchEntry,
void PatchDB::ReadHash(PatchFileEntry& patchEntry,
std::shared_ptr<cpptoml::table> patch_toml_fields) {
auto title_hashes = patch_toml_fields->get_array_of<std::string>("hash");

View File

@ -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<cpptoml::table> patch_toml_fields);
};
} // namespace patcher