From f661f4d1d698f8fd45ab87cecfbfdf15e112fecf Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 7 Mar 2023 16:03:34 +0100 Subject: [PATCH] fix: GDB provider not working nicely anymore --- .../content/providers/file_provider.cpp | 9 ++++--- .../source/content/providers/gdb_provider.cpp | 26 +++++++++++++------ .../source/content/views/view_patches.cpp | 2 +- .../content/views/view_provider_settings.cpp | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index a49f1539c..11ff7d072 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -41,12 +41,13 @@ namespace hex::plugin::builtin { this->readRaw(offset - this->getBaseAddress(), buffer, size); - for (u64 i = 0; i < size; i++) - if (getPatches().contains(offset + i)) - reinterpret_cast(buffer)[i] = getPatches()[offset + i]; + if (overlays) { + for (u64 i = 0; i < size; i++) + if (getPatches().contains(offset + i)) + reinterpret_cast(buffer)[i] = getPatches()[offset + i]; - if (overlays) this->applyOverlays(offset, buffer, size); + } } void FileProvider::write(u64 offset, const void *buffer, size_t size) { diff --git a/plugins/builtin/source/content/providers/gdb_provider.cpp b/plugins/builtin/source/content/providers/gdb_provider.cpp index 1fdece352..c456af311 100644 --- a/plugins/builtin/source/content/providers/gdb_provider.cpp +++ b/plugins/builtin/source/content/providers/gdb_provider.cpp @@ -47,7 +47,8 @@ namespace hex::plugin::builtin { std::string data = packet.substr(1, packet.length() - 4); std::string checksum = packet.substr(packet.length() - 2, 2); - if (checksum.length() != 2 || crypt::decode16(checksum)[0] != calculateChecksum(data)) + auto decodedChecksum = crypt::decode16(checksum); + if (checksum.length() != 2 || decodedChecksum.empty() || decodedChecksum[0] != calculateChecksum(data)) return std::nullopt; return data; @@ -178,12 +179,13 @@ namespace hex::plugin::builtin { } } - for (u64 i = 0; i < size; i++) - if (getPatches().contains(offset + i)) - reinterpret_cast(buffer)[i] = getPatches()[offset + PageSize * this->m_currPage + i]; + if (overlays) { + for (u64 i = 0; i < size; i++) + if (getPatches().contains(offset + i)) + reinterpret_cast(buffer)[i] = getPatches()[offset + PageSize * this->m_currPage + i]; - if (overlays) this->applyOverlays(offset, buffer, size); + } } void GDBProvider::write(u64 offset, const void *buffer, size_t size) { @@ -200,7 +202,8 @@ namespace hex::plugin::builtin { return; auto data = gdb::readMemory(this->m_socket, offset, size); - std::memcpy(buffer, &data[0], data.size()); + if (!data.empty()) + std::memcpy(buffer, &data[0], data.size()); } void GDBProvider::writeRaw(u64 offset, const void *buffer, size_t size) { @@ -257,7 +260,13 @@ namespace hex::plugin::builtin { if (cacheLine != this->m_cache.end()) { auto data = gdb::readMemory(this->m_socket, cacheLine->address, 0x1000); - while (this->m_cache.size() > 10) { + if (data.empty()) { + this->m_cache.erase(cacheLine); + cacheLine = this->m_cache.begin(); + continue; + } + + while (this->m_cache.size() > 5) { this->m_cache.pop_front(); cacheLine = this->m_cache.begin(); } @@ -265,9 +274,10 @@ namespace hex::plugin::builtin { std::memcpy(cacheLine->data.data(), data.data(), data.size()); } - cacheLine++; if (cacheLine == this->m_cache.end()) cacheLine = this->m_cache.begin(); + else + cacheLine++; } std::this_thread::sleep_for(100ms); } diff --git a/plugins/builtin/source/content/views/view_patches.cpp b/plugins/builtin/source/content/views/view_patches.cpp index cbc54069d..a8c070e5e 100644 --- a/plugins/builtin/source/content/views/view_patches.cpp +++ b/plugins/builtin/source/content/views/view_patches.cpp @@ -39,7 +39,7 @@ namespace hex::plugin::builtin { auto provider = ImHexApi::Provider::get(); u8 byte = 0x00; - provider->readRaw(offset, &byte, sizeof(u8)); + provider->read(offset, &byte, sizeof(u8), false); const auto &patches = provider->getPatches(); if (patches.contains(offset) && patches.at(offset) != byte) diff --git a/plugins/builtin/source/content/views/view_provider_settings.cpp b/plugins/builtin/source/content/views/view_provider_settings.cpp index 21cb5495e..0e3fcb17e 100644 --- a/plugins/builtin/source/content/views/view_provider_settings.cpp +++ b/plugins/builtin/source/content/views/view_provider_settings.cpp @@ -4,7 +4,7 @@ namespace hex::plugin::builtin { ViewProviderSettings::ViewProviderSettings() : hex::View("hex.builtin.view.provider_settings.name") { EventManager::subscribe(this, [](hex::prv::Provider *provider) { - if (provider->hasLoadInterface()) + if (provider->hasLoadInterface() && !provider->shouldSkipLoadInterface()) EventManager::post(View::toWindowName("hex.builtin.view.provider_settings.load_popup")); }); }