From 7cdba75bef32f750a863e259222650f3e9fabb5e Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 16 Mar 2023 16:48:15 +0100 Subject: [PATCH] fix: Crash when not making a valid selection in provider load interfaces --- lib/libimhex/include/hex/providers/provider.hpp | 2 +- lib/libimhex/source/providers/provider.cpp | 3 ++- plugins/builtin/include/content/providers/disk_provider.hpp | 2 +- plugins/builtin/include/content/providers/gdb_provider.hpp | 2 +- plugins/builtin/source/content/providers/disk_provider.cpp | 4 +++- plugins/builtin/source/content/providers/gdb_provider.cpp | 4 +++- plugins/builtin/source/content/views/view_bookmarks.cpp | 4 ++-- .../builtin/source/content/views/view_provider_settings.cpp | 4 +++- .../include/content/providers/process_memory_provider.hpp | 2 +- .../source/content/providers/process_memory_provider.cpp | 4 +++- 10 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/libimhex/include/hex/providers/provider.hpp b/lib/libimhex/include/hex/providers/provider.hpp index fa97e98a3..a418a93ef 100644 --- a/lib/libimhex/include/hex/providers/provider.hpp +++ b/lib/libimhex/include/hex/providers/provider.hpp @@ -84,7 +84,7 @@ namespace hex::prv { [[nodiscard]] virtual bool hasLoadInterface() const; [[nodiscard]] virtual bool hasInterface() const; - virtual void drawLoadInterface(); + virtual bool drawLoadInterface(); virtual void drawInterface(); [[nodiscard]] u32 getID() const; diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index d62d02427..01baf1e63 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -243,7 +243,8 @@ namespace hex::prv { return false; } - void Provider::drawLoadInterface() { + bool Provider::drawLoadInterface() { + return true; } void Provider::drawInterface() { diff --git a/plugins/builtin/include/content/providers/disk_provider.hpp b/plugins/builtin/include/content/providers/disk_provider.hpp index 9a326beeb..b57861a4e 100644 --- a/plugins/builtin/include/content/providers/disk_provider.hpp +++ b/plugins/builtin/include/content/providers/disk_provider.hpp @@ -37,7 +37,7 @@ namespace hex::plugin::builtin { [[nodiscard]] std::vector> getDataDescription() const override; [[nodiscard]] bool hasLoadInterface() const override { return true; } - void drawLoadInterface() override; + bool drawLoadInterface() override; void loadSettings(const nlohmann::json &settings) override; [[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings = { }) const override; diff --git a/plugins/builtin/include/content/providers/gdb_provider.hpp b/plugins/builtin/include/content/providers/gdb_provider.hpp index b5cf85c9a..3eaee98af 100644 --- a/plugins/builtin/include/content/providers/gdb_provider.hpp +++ b/plugins/builtin/include/content/providers/gdb_provider.hpp @@ -41,7 +41,7 @@ namespace hex::plugin::builtin { [[nodiscard]] bool isConnected() const; [[nodiscard]] bool hasLoadInterface() const override { return true; } - void drawLoadInterface() override; + bool drawLoadInterface() override; void loadSettings(const nlohmann::json &settings) override; [[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override; diff --git a/plugins/builtin/source/content/providers/disk_provider.cpp b/plugins/builtin/source/content/providers/disk_provider.cpp index 850e47e28..3bb5573c6 100644 --- a/plugins/builtin/source/content/providers/disk_provider.cpp +++ b/plugins/builtin/source/content/providers/disk_provider.cpp @@ -312,7 +312,7 @@ namespace hex::plugin::builtin { #endif } - void DiskProvider::drawLoadInterface() { + bool DiskProvider::drawLoadInterface() { #if defined(OS_WINDOWS) if (this->m_availableDrives.empty()) @@ -340,6 +340,8 @@ namespace hex::plugin::builtin { this->m_path = this->m_pathBuffer; #endif + + return !this->m_path.empty(); } nlohmann::json DiskProvider::storeSettings(nlohmann::json settings) const { diff --git a/plugins/builtin/source/content/providers/gdb_provider.cpp b/plugins/builtin/source/content/providers/gdb_provider.cpp index 5691688e8..8cd8a8f0f 100644 --- a/plugins/builtin/source/content/providers/gdb_provider.cpp +++ b/plugins/builtin/source/content/providers/gdb_provider.cpp @@ -308,7 +308,7 @@ namespace hex::plugin::builtin { } - void GDBProvider::drawLoadInterface() { + bool GDBProvider::drawLoadInterface() { ImGui::InputText("hex.builtin.provider.gdb.ip"_lang, this->m_ipAddress); ImGui::InputInt("hex.builtin.provider.gdb.port"_lang, &this->m_port, 0, 0); @@ -320,6 +320,8 @@ namespace hex::plugin::builtin { this->m_port = 0; else if (this->m_port > 0xFFFF) this->m_port = 0xFFFF; + + return !this->m_ipAddress.empty() && this->m_port != 0; } void GDBProvider::loadSettings(const nlohmann::json &settings) { diff --git a/plugins/builtin/source/content/views/view_bookmarks.cpp b/plugins/builtin/source/content/views/view_bookmarks.cpp index eb3715176..dcd60a716 100644 --- a/plugins/builtin/source/content/views/view_bookmarks.cpp +++ b/plugins/builtin/source/content/views/view_bookmarks.cpp @@ -65,7 +65,7 @@ namespace hex::plugin::builtin { { ImGui::ColorButton("##color", ImColor(bookmark.color)); ImGui::SameLine(0, 10); - ImGui::TextUnformatted(bookmark.name.c_str()); + ImGui::TextFormatted("{} ", bookmark.name); if (ImGui::GetIO().KeyShift) { ImGui::Indent(); @@ -78,7 +78,7 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); ImGui::TextFormatted("{}: ", "hex.builtin.common.region"_lang.get()); ImGui::TableNextColumn(); - ImGui::TextFormatted("[ 0x{:08X} - 0x{:08X} ]", bookmark.region.getStartAddress(), bookmark.region.getEndAddress()); + ImGui::TextFormatted("[ 0x{:08X} - 0x{:08X} ] ", bookmark.region.getStartAddress(), bookmark.region.getEndAddress()); if (!bookmark.comment.empty() && bookmark.comment[0] != '\x00') { ImGui::TableNextRow(); diff --git a/plugins/builtin/source/content/views/view_provider_settings.cpp b/plugins/builtin/source/content/views/view_provider_settings.cpp index 0e3fcb17e..719489a70 100644 --- a/plugins/builtin/source/content/views/view_provider_settings.cpp +++ b/plugins/builtin/source/content/views/view_provider_settings.cpp @@ -29,11 +29,12 @@ namespace hex::plugin::builtin { auto provider = hex::ImHexApi::Provider::get(); if (provider != nullptr) { - provider->drawLoadInterface(); + bool settingsValid = provider->drawLoadInterface(); ImGui::NewLine(); ImGui::Separator(); + ImGui::BeginDisabled(!settingsValid); if (ImGui::Button("hex.builtin.common.open"_lang)) { if (provider->open()) { EventManager::post(provider); @@ -44,6 +45,7 @@ namespace hex::plugin::builtin { TaskManager::doLater([=] { ImHexApi::Provider::remove(provider); }); } } + ImGui::EndDisabled(); ImGui::SameLine(); diff --git a/plugins/windows/include/content/providers/process_memory_provider.hpp b/plugins/windows/include/content/providers/process_memory_provider.hpp index 89e1f50ac..7682eeb98 100644 --- a/plugins/windows/include/content/providers/process_memory_provider.hpp +++ b/plugins/windows/include/content/providers/process_memory_provider.hpp @@ -51,7 +51,7 @@ namespace hex::plugin::windows { [[nodiscard]] bool hasLoadInterface() const override { return true; } [[nodiscard]] bool hasInterface() const override { return true; } - void drawLoadInterface() override; + bool drawLoadInterface() override; void drawInterface() override; void loadSettings(const nlohmann::json &) override {} diff --git a/plugins/windows/source/content/providers/process_memory_provider.cpp b/plugins/windows/source/content/providers/process_memory_provider.cpp index 2f07d013f..7a48d1c44 100644 --- a/plugins/windows/source/content/providers/process_memory_provider.cpp +++ b/plugins/windows/source/content/providers/process_memory_provider.cpp @@ -55,7 +55,7 @@ namespace hex::plugin::windows { return { Region::Invalid(), false }; } - void ProcessMemoryProvider::drawLoadInterface() { + bool ProcessMemoryProvider::drawLoadInterface() { if (this->m_processes.empty() && !this->m_enumerationFailed) { DWORD numProcesses = 0; std::vector processIds; @@ -162,6 +162,8 @@ namespace hex::plugin::windows { } } + + return this->m_selectedProcess != nullptr; } void ProcessMemoryProvider::drawInterface() {