From 9e62685fd1256a28c6b27887e359c5799d5bda71 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 11 Nov 2020 10:47:02 +0100 Subject: [PATCH] Fix crash when moving around certain views --- CMakeLists.txt | 1 + include/parser/ast_node.hpp | 2 +- include/providers/file_provider.hpp | 16 ++++++++-------- source/parser/lexer.cpp | 2 +- source/provider/file_provider.cpp | 4 ++-- source/views/view_hashes.cpp | 13 +++++++------ source/views/view_hexeditor.cpp | 1 + source/views/view_pattern.cpp | 27 ++++++++++++++------------- source/views/view_pattern_data.cpp | 4 +++- 9 files changed, 38 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b133c31b..93e37df93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ add_executable(ImHex source/views/view_pattern.cpp source/views/view_pattern_data.cpp source/views/view_hashes.cpp + source/views/view_entropy.cpp libs/glad/source/glad.c diff --git a/include/parser/ast_node.hpp b/include/parser/ast_node.hpp index bd29348ee..2288e38bb 100644 --- a/include/parser/ast_node.hpp +++ b/include/parser/ast_node.hpp @@ -17,7 +17,7 @@ namespace hex::lang { }; explicit ASTNode(Type type) : m_type(type) {} - virtual ~ASTNode() {} + virtual ~ASTNode() = default; Type getType() { return this->m_type; } diff --git a/include/providers/file_provider.hpp b/include/providers/file_provider.hpp index a8ee322d5..d966182d8 100644 --- a/include/providers/file_provider.hpp +++ b/include/providers/file_provider.hpp @@ -8,16 +8,16 @@ namespace hex::prv { class FileProvider : public Provider { public: - FileProvider(std::string_view path); - virtual ~FileProvider(); + explicit FileProvider(std::string_view path); + ~FileProvider() override; - virtual bool isAvailable() override; - virtual bool isReadable() override; - virtual bool isWritable() override; + bool isAvailable() override; + bool isReadable() override; + bool isWritable() override; - virtual void read(u64 offset, void *buffer, size_t size) override; - virtual void write(u64 offset, void *buffer, size_t size) override; - virtual size_t getSize() override; + void read(u64 offset, void *buffer, size_t size) override; + void write(u64 offset, void *buffer, size_t size) override; + size_t getSize() override; private: FILE *m_file; diff --git a/source/parser/lexer.cpp b/source/parser/lexer.cpp index 9da01ef2f..5d5e8463b 100644 --- a/source/parser/lexer.cpp +++ b/source/parser/lexer.cpp @@ -23,7 +23,7 @@ namespace hex::lang { std::optional parseInt(std::string_view string) { u64 integer = 0; - u8 base = 10; + u8 base; std::string_view numberData; diff --git a/source/provider/file_provider.cpp b/source/provider/file_provider.cpp index f410c8b96..125e5691b 100644 --- a/source/provider/file_provider.cpp +++ b/source/provider/file_provider.cpp @@ -27,11 +27,11 @@ namespace hex::prv { } bool FileProvider::isReadable() { - return this->m_readable; + return isAvailable() && this->m_readable; } bool FileProvider::isWritable() { - return this->m_writable; + return isAvailable() && this->m_writable; } diff --git a/source/views/view_hashes.cpp b/source/views/view_hashes.cpp index 98bda40b2..52b2c0f05 100644 --- a/source/views/view_hashes.cpp +++ b/source/views/view_hashes.cpp @@ -1,5 +1,7 @@ #include "views/view_hashes.hpp" +#include "providers/provider.hpp" + #include "utils.hpp" #include @@ -16,19 +18,19 @@ namespace hex { void ViewHashes::createView() { + static bool invalidate = false; + if (!this->m_windowOpen) return; - static bool invalidate = false; - if (ImGui::Begin("Hashing", &this->m_windowOpen)) { ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav); - ImGui::NewLine(); if (this->m_dataProvider != nullptr && this->m_dataProvider->isAvailable()) { - ImGui::Combo("Hash Function", &this->m_currHashFunction, HashFunctionNames, sizeof(HashFunctionNames) / sizeof(const char*)); + ImGui::Combo("Hash Function", &this->m_currHashFunction, HashFunctionNames, + sizeof(HashFunctionNames) / sizeof(const char *)); ImGui::NewLine(); ImGui::Separator(); @@ -115,10 +117,9 @@ namespace hex { invalidate = true; } - ImGui::EndChild(); - ImGui::End(); } + ImGui::End(); } void ViewHashes::createMenu() { diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 71d933f10..53eec55af 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -1,5 +1,6 @@ #include "views/view_hexeditor.hpp" +#include "providers/provider.hpp" #include "providers/file_provider.hpp" namespace hex { diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index 0ffc6085c..46bed7c0c 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -48,23 +48,24 @@ namespace hex { if (!this->m_windowOpen) return; - ImGui::Begin("Pattern", &this->m_windowOpen, ImGuiWindowFlags_None); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + if (ImGui::Begin("Pattern", &this->m_windowOpen, ImGuiWindowFlags_None)) { + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); - auto size = ImGui::GetWindowSize(); - size.y -= 50; - ImGui::InputTextMultiline("Pattern", this->m_buffer, 0xFFFF, size, ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_CallbackEdit, - [](ImGuiInputTextCallbackData* data) -> int { - auto _this = static_cast(data->UserData); + auto size = ImGui::GetWindowSize(); + size.y -= 50; + ImGui::InputTextMultiline("Pattern", this->m_buffer, 0xFFFF, size, ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_CallbackEdit, + [](ImGuiInputTextCallbackData* data) -> int { + auto _this = static_cast(data->UserData); - _this->parsePattern(data->Buf); + _this->parsePattern(data->Buf); - return 0; - }, this - ); + return 0; + }, this + ); - ImGui::PopStyleVar(2); + ImGui::PopStyleVar(2); + } ImGui::End(); } diff --git a/source/views/view_pattern_data.cpp b/source/views/view_pattern_data.cpp index 7aa4bdef2..270570efe 100644 --- a/source/views/view_pattern_data.cpp +++ b/source/views/view_pattern_data.cpp @@ -1,5 +1,7 @@ #include "views/view_pattern_data.hpp" +#include "providers/provider.hpp" + #include namespace hex { @@ -48,8 +50,8 @@ namespace hex { } ImGui::EndChild(); - ImGui::End(); } + ImGui::End(); } void ViewPatternData::createMenu() {