From a8c9e96b72c909d7ae46aafaa0d37d1f94daf371 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 9 Sep 2021 01:56:48 +0200 Subject: [PATCH] fix: Inverted logic when checking for libmagic error --- external/ImGui/include/imgui_memory_editor.h | 2 +- plugins/libimhex/include/hex.hpp | 14 ++-- .../libimhex/include/hex/helpers/concepts.hpp | 71 ++++++++++--------- plugins/libimhex/source/helpers/magic.cpp | 4 +- 4 files changed, 51 insertions(+), 40 deletions(-) diff --git a/external/ImGui/include/imgui_memory_editor.h b/external/ImGui/include/imgui_memory_editor.h index 993a47fb5..eb3b2fe76 100644 --- a/external/ImGui/include/imgui_memory_editor.h +++ b/external/ImGui/include/imgui_memory_editor.h @@ -231,7 +231,7 @@ struct MemoryEditor if (ImGui::Begin(title, p_open, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNavInputs)) { if (DataPreviewAddr != DataPreviewAddrOld || DataPreviewAddrEnd != DataPreviewAddrEndOld) { - Region selectionRegion = { std::min(DataPreviewAddr, DataPreviewAddrEnd) + base_display_addr, std::max(DataPreviewAddr, DataPreviewAddrEnd) - std::min(DataPreviewAddr, DataPreviewAddrEnd) }; + hex::Region selectionRegion = { std::min(DataPreviewAddr, DataPreviewAddrEnd) + base_display_addr, std::max(DataPreviewAddr, DataPreviewAddrEnd) - std::min(DataPreviewAddr, DataPreviewAddrEnd) }; hex::EventManager::post(selectionRegion); } diff --git a/plugins/libimhex/include/hex.hpp b/plugins/libimhex/include/hex.hpp index 6d400d696..ff92b6f70 100644 --- a/plugins/libimhex/include/hex.hpp +++ b/plugins/libimhex/include/hex.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include constexpr static const auto ImHexApiURL = "https://api.werwolv.net/imhex"; constexpr static const auto GitHubApiURL = "https://api.github.com/repos/WerWolv/ImHex"; @@ -17,7 +18,12 @@ using s32 = std::int32_t; using s64 = std::int64_t; using s128 = __int128_t; -struct Region { - u64 address; - size_t size; -}; \ No newline at end of file +namespace hex { + + struct Region { + u64 address; + size_t size; + }; + +} + diff --git a/plugins/libimhex/include/hex/helpers/concepts.hpp b/plugins/libimhex/include/hex/helpers/concepts.hpp index e74a8dfb1..5cfa58049 100644 --- a/plugins/libimhex/include/hex/helpers/concepts.hpp +++ b/plugins/libimhex/include/hex/helpers/concepts.hpp @@ -1,6 +1,7 @@ #pragma once -#include +#include + #include namespace hex { @@ -59,53 +60,55 @@ namespace hex { template struct is_integral : public is_integral_helper>::type { }; -template -struct is_signed_helper : public std::false_type { }; -template<> -struct is_signed_helper : public std::true_type { }; + template + struct is_signed_helper : public std::false_type { }; -template<> -struct is_signed_helper : public std::true_type { }; + template<> + struct is_signed_helper : public std::true_type { }; -template<> -struct is_signed_helper : public std::true_type { }; + template<> + struct is_signed_helper : public std::true_type { }; -template<> -struct is_signed_helper : public std::true_type { }; + template<> + struct is_signed_helper : public std::true_type { }; -template<> -struct is_signed_helper : public std::true_type { }; + template<> + struct is_signed_helper : public std::true_type { }; -template<> -struct is_signed_helper : public std::true_type { }; + template<> + struct is_signed_helper : public std::true_type { }; -template<> -struct is_signed_helper : public std::true_type { }; + template<> + struct is_signed_helper : public std::true_type { }; -template<> -struct is_signed_helper : public std::true_type { }; + template<> + struct is_signed_helper : public std::true_type { }; -template<> -struct is_signed_helper : public std::true_type { }; + template<> + struct is_signed_helper : public std::true_type { }; -template -struct is_signed : public is_signed_helper>::type { }; + template<> + struct is_signed_helper : public std::true_type { }; -template -struct is_floating_point_helper : public std::false_type { }; + template + struct is_signed : public is_signed_helper>::type { }; -template<> -struct is_floating_point_helper : public std::true_type { }; -template<> -struct is_floating_point_helper : public std::true_type { }; + template + struct is_floating_point_helper : public std::false_type { }; -template<> -struct is_floating_point_helper : public std::true_type { }; + template<> + struct is_floating_point_helper : public std::true_type { }; -template -struct is_floating_point : public is_floating_point_helper>::type { }; + template<> + struct is_floating_point_helper : public std::true_type { }; + + template<> + struct is_floating_point_helper : public std::true_type { }; + + template + struct is_floating_point : public is_floating_point_helper>::type { }; } @@ -132,6 +135,7 @@ namespace hex { // [concepts.arithmetic] namespace hex { + template concept integral = hex::is_integral::value; @@ -143,6 +147,7 @@ namespace hex { template concept floating_point = std::is_floating_point::value; + } namespace hex { diff --git a/plugins/libimhex/source/helpers/magic.cpp b/plugins/libimhex/source/helpers/magic.cpp index 98d216103..852f32d31 100644 --- a/plugins/libimhex/source/helpers/magic.cpp +++ b/plugins/libimhex/source/helpers/magic.cpp @@ -56,7 +56,7 @@ namespace hex::magic { magic_t ctx = magic_open(MAGIC_NONE); ON_SCOPE_EXIT { magic_close(ctx); }; - if (magic_load(ctx, magicFiles->c_str())) + if (magic_load(ctx, magicFiles->c_str()) == 0) return magic_buffer(ctx, data.data(), data.size()) ?: ""; } @@ -77,7 +77,7 @@ namespace hex::magic { magic_t ctx = magic_open(MAGIC_MIME); ON_SCOPE_EXIT { magic_close(ctx); }; - if (magic_load(ctx, magicFiles->c_str())) + if (magic_load(ctx, magicFiles->c_str()) == 0) return magic_buffer(ctx, data.data(), data.size()) ?: ""; }