diff --git a/lib/libimhex/include/hex/providers/provider.hpp b/lib/libimhex/include/hex/providers/provider.hpp index f429393d8..6a4aa3d5f 100644 --- a/lib/libimhex/include/hex/providers/provider.hpp +++ b/lib/libimhex/include/hex/providers/provider.hpp @@ -108,7 +108,7 @@ namespace hex::prv { * @param size number of bytes to read * @param overlays apply overlays and patches is true. Same as readRaw() if false */ - virtual void read(u64 offset, void *buffer, size_t size, bool overlays = true); + void read(u64 offset, void *buffer, size_t size, bool overlays = true); /** * @brief Write data to the patches of this provider. Will not directly modify provider. @@ -116,7 +116,7 @@ namespace hex::prv { * @param buffer buffer to take data to write from * @param size number of bytes to write */ - virtual void write(u64 offset, const void *buffer, size_t size); + void write(u64 offset, const void *buffer, size_t size); /** * @brief Read data from this provider, without applying overlays and patches diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index eaa3a9bd4..c61993c42 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -36,6 +36,9 @@ namespace hex::prv { hex::unused(overlays); this->readRaw(offset - this->getBaseAddress(), buffer, size); + + if (overlays) + this->applyOverlays(offset, buffer, size); } void Provider::write(u64 offset, const void *buffer, size_t size) { diff --git a/plugins/builtin/include/content/providers/gdb_provider.hpp b/plugins/builtin/include/content/providers/gdb_provider.hpp index 9a0958338..7c506e32b 100644 --- a/plugins/builtin/include/content/providers/gdb_provider.hpp +++ b/plugins/builtin/include/content/providers/gdb_provider.hpp @@ -22,9 +22,6 @@ namespace hex::plugin::builtin { [[nodiscard]] bool isResizable() const override; [[nodiscard]] bool isSavable() const override; - void read(u64 offset, void *buffer, size_t size, bool overlays) override; - void write(u64 offset, const void *buffer, size_t size) override; - void readRaw(u64 offset, void *buffer, size_t size) override; void writeRaw(u64 offset, const void *buffer, size_t size) override; [[nodiscard]] size_t getActualSize() const override; diff --git a/plugins/builtin/source/content/providers/gdb_provider.cpp b/plugins/builtin/source/content/providers/gdb_provider.cpp index 4c86d08da..2231ca4a8 100644 --- a/plugins/builtin/source/content/providers/gdb_provider.cpp +++ b/plugins/builtin/source/content/providers/gdb_provider.cpp @@ -146,8 +146,7 @@ namespace hex::plugin::builtin { return false; } - - void GDBProvider::read(u64 offset, void *buffer, size_t size, bool overlays) { + void GDBProvider::readRaw(u64 offset, void *buffer, size_t size) { if ((offset - this->getBaseAddress()) > (this->getActualSize() - size) || buffer == nullptr || size == 0) return; @@ -176,40 +175,23 @@ namespace hex::plugin::builtin { } else { while (size > 0) { size_t readSize = std::min(size, CacheLineSize); - this->readRaw(offset, buffer, readSize); + + auto data = gdb::readMemory(this->m_socket, offset, size); + if (!data.empty()) + std::memcpy(buffer, &data[0], data.size()); size -= readSize; offset += readSize; } } - - if (overlays) { - this->applyOverlays(offset, buffer, size); - } - } - - void GDBProvider::write(u64 offset, const void *buffer, size_t size) { - if ((offset - this->getBaseAddress()) > (this->getActualSize() - size) || buffer == nullptr || size == 0) - return; - - offset -= this->getBaseAddress(); - - gdb::writeMemory(this->m_socket, offset, buffer, size); - } - - void GDBProvider::readRaw(u64 offset, void *buffer, size_t size) { - if ((offset - this->getBaseAddress()) > (this->getActualSize() - size) || buffer == nullptr || size == 0) - return; - - auto data = gdb::readMemory(this->m_socket, offset, size); - if (!data.empty()) - std::memcpy(buffer, &data[0], data.size()); } void GDBProvider::writeRaw(u64 offset, const void *buffer, size_t size) { if ((offset - this->getBaseAddress()) > (this->getActualSize() - size) || buffer == nullptr || size == 0) return; + offset -= this->getBaseAddress(); + gdb::writeMemory(this->m_socket, offset, buffer, size); } diff --git a/plugins/windows/include/content/providers/process_memory_provider.hpp b/plugins/windows/include/content/providers/process_memory_provider.hpp index 70992f23a..12c77d318 100644 --- a/plugins/windows/include/content/providers/process_memory_provider.hpp +++ b/plugins/windows/include/content/providers/process_memory_provider.hpp @@ -23,9 +23,6 @@ namespace hex::plugin::windows { [[nodiscard]] bool isSavable() const override { return false; } [[nodiscard]] bool isDumpable() const override { return false; } - void read(u64 address, void *buffer, size_t size, bool) override { this->readRaw(address, buffer, size); } - void write(u64 address, const void *buffer, size_t size) override { this->writeRaw(address, buffer, size); } - void readRaw(u64 address, void *buffer, size_t size) override; void writeRaw(u64 address, const void *buffer, size_t size) override; [[nodiscard]] size_t getActualSize() const override { return 0xFFFF'FFFF'FFFF; }