[Patcher] Fixed issue with incorrect patches endianness

This commit is contained in:
Gliniak 2022-06-08 19:42:18 +02:00
parent 0de0f40fb5
commit 25f3e16baa
3 changed files with 44 additions and 6 deletions

View File

@ -120,15 +120,34 @@ bool PatchDB::ReadPatchData(
size_t alloc_size = (size_t)data_type.second.size; size_t alloc_size = (size_t)data_type.second.size;
switch (data_type.second.type) { switch (data_type.second.type) {
case PatchDataType::be8: {
uint16_t value = *patch_data_table->get_as<uint8_t>("value");
patch_data.push_back({address, PatchDataValue(alloc_size, value)});
break;
}
case PatchDataType::be16: {
uint16_t value = *patch_data_table->get_as<uint16_t>("value");
patch_data.push_back(
{address, PatchDataValue(alloc_size, xe::byte_swap(value))});
break;
}
case PatchDataType::be32: {
uint32_t value = *patch_data_table->get_as<uint32_t>("value");
patch_data.push_back(
{address, PatchDataValue(alloc_size, xe::byte_swap(value))});
break;
}
case PatchDataType::f64: { case PatchDataType::f64: {
double val = *patch_data_table->get_as<double>("value"); double val = *patch_data_table->get_as<double>("value");
uint64_t value = *reinterpret_cast<uint64_t*>(&val); uint64_t value = *reinterpret_cast<uint64_t*>(&val);
patch_data.push_back({address, PatchDataValue(alloc_size, value)}); patch_data.push_back(
{address, PatchDataValue(alloc_size, xe::byte_swap(value))});
break; break;
} }
case PatchDataType::f32: { case PatchDataType::f32: {
float value = float(*patch_data_table->get_as<double>("value")); float value = float(*patch_data_table->get_as<double>("value"));
patch_data.push_back({address, PatchDataValue(alloc_size, value)}); patch_data.push_back(
{address, PatchDataValue(alloc_size, xe::byte_swap(value))});
break; break;
} }
case PatchDataType::string: { case PatchDataType::string: {
@ -157,7 +176,8 @@ bool PatchDB::ReadPatchData(
} }
default: { default: {
uint64_t value = *patch_data_table->get_as<uint64_t>("value"); uint64_t value = *patch_data_table->get_as<uint64_t>("value");
patch_data.push_back({address, PatchDataValue(alloc_size, value)}); patch_data.push_back(
{address, PatchDataValue(alloc_size, xe::byte_swap(value))});
break; break;
} }
} }

View File

@ -21,6 +21,24 @@ struct PatchDataValue {
const size_t alloc_size_; const size_t alloc_size_;
const uint8_t* patch_data_ptr_; const uint8_t* patch_data_ptr_;
PatchDataValue(const size_t alloc_size, const uint8_t value)
: alloc_size_(alloc_size) {
patch_data_ptr_ = new uint8_t[alloc_size_];
memcpy((void*)patch_data_ptr_, &value, alloc_size);
};
PatchDataValue(const size_t alloc_size, const uint16_t value)
: alloc_size_(alloc_size) {
patch_data_ptr_ = new uint8_t[alloc_size_];
memcpy((void*)patch_data_ptr_, &value, alloc_size);
};
PatchDataValue(const size_t alloc_size, const uint32_t value)
: alloc_size_(alloc_size) {
patch_data_ptr_ = new uint8_t[alloc_size_];
memcpy((void*)patch_data_ptr_, &value, alloc_size);
};
PatchDataValue(const size_t alloc_size, const uint64_t value) PatchDataValue(const size_t alloc_size, const uint64_t value)
: alloc_size_(alloc_size) { : alloc_size_(alloc_size) {
patch_data_ptr_ = new uint8_t[alloc_size_]; patch_data_ptr_ = new uint8_t[alloc_size_];

View File

@ -51,9 +51,9 @@ void Patcher::ApplyPatch(Memory* memory, const PatchInfoEntry* patch) {
(uint32_t)patch_data_entry.new_data_.alloc_size_, (uint32_t)patch_data_entry.new_data_.alloc_size_,
kMemoryProtectRead | kMemoryProtectWrite); kMemoryProtectRead | kMemoryProtectWrite);
xe::copy_and_swap(address,
(uint8_t*)patch_data_entry.new_data_.patch_data_ptr_, memcpy(address, patch_data_entry.new_data_.patch_data_ptr_,
patch_data_entry.new_data_.alloc_size_); patch_data_entry.new_data_.alloc_size_);
// Restore previous protection // Restore previous protection
heap->Protect(patch_data_entry.memory_address_, heap->Protect(patch_data_entry.memory_address_,