From de76c37ffb737752557e0c26d3eda04cf29d3a3f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 3 Jun 2023 23:57:41 +0200 Subject: [PATCH] fix: Multiple file provider resize issues --- lib/libimhex/source/providers/provider.cpp | 11 ++++++++--- .../source/content/providers/file_provider.cpp | 3 +-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index a12d3d3ec..cd2d178e6 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -62,6 +62,11 @@ namespace hex::prv { file.writeBuffer(buffer.data(), bufferSize); } + for (auto &[patchAddress, patch] : getPatches()) { + file.seek(patchAddress - this->getBaseAddress()); + file.writeBuffer(&patch, 1); + } + EventManager::post(this); } } @@ -130,13 +135,13 @@ namespace hex::prv { } void Provider::applyPatches() { + if (!this->isWritable()) + return; + for (auto &[patchAddress, patch] : getPatches()) { this->writeRaw(patchAddress - this->getBaseAddress(), &patch, 1); } - if (!this->isWritable()) - return; - this->markDirty(); this->m_patches.emplace_back(); diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index c5a89d4be..f4bbfb947 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -116,7 +116,6 @@ namespace hex::plugin::builtin { void FileProvider::remove(u64 offset, size_t size) { auto oldSize = this->getActualSize(); - this->resize(oldSize + size); std::vector buffer(0x1000); @@ -230,7 +229,7 @@ namespace hex::plugin::builtin { } void FileProvider::close() { - + this->m_file.unmap(); } void FileProvider::loadSettings(const nlohmann::json &settings) {