From be738eb5e7d24e3afe333e168dc756e88594bdf5 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 20 Jan 2021 18:10:40 +0100 Subject: [PATCH] Improved byte highlighting --- CMakeLists.txt | 2 +- .../include/hex/lang/pattern_data.hpp | 2 +- source/views/view_hexeditor.cpp | 20 +++++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4207f47fe..bd6727449 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,7 +182,7 @@ set_target_properties(imhex PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_directories(imhex PRIVATE ${CRYPTO_LIBRARY_DIRS} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS}) if (WIN32) - target_link_libraries(imhex libdl.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a libshlwapi.a libcrypto.a libwinpthread.a libcapstone.a LLVMDemangle libimhex ${Python_LIBRARIES}) + target_link_libraries(imhex libdl.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a libshlwapi.a libcrypto.a libwinpthread.a libcapstone.a LLVMDemangle libimhex ${Python_LIBRARIES} wsock32 ws2_32) elseif (UNIX) target_link_libraries(imhex magic crypto ${CMAKE_DL_LIBS} capstone LLVMDemangle libimhex ${Python_LIBRARIES} dl) endif() diff --git a/plugins/libimhex/include/hex/lang/pattern_data.hpp b/plugins/libimhex/include/hex/lang/pattern_data.hpp index 561c6ed51..d29d9f506 100644 --- a/plugins/libimhex/include/hex/lang/pattern_data.hpp +++ b/plugins/libimhex/include/hex/lang/pattern_data.hpp @@ -183,7 +183,7 @@ namespace hex::lang { class PatternDataPadding : public PatternData { public: - PatternDataPadding(u64 offset, size_t size) : PatternData(offset, size, 0x00FFFFFF) { } + PatternDataPadding(u64 offset, size_t size) : PatternData(offset, size, 0xFF000000) { } PatternData* clone() override { return new PatternDataPadding(*this); diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 73d173f4a..d25ee7b4c 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -46,22 +46,26 @@ namespace hex { for (const auto &[region, name, comment, color] : _this->m_bookmarks) { if (off >= region.address && off < (region.address + region.size)) - currColor = (color & 0x00FFFFFF) | 0x40000000; + currColor = (color & 0x00FFFFFF) | 0x80000000; if ((off - 1) >= region.address && (off - 1) < (region.address + region.size)) - prevColor = (color & 0x00FFFFFF) | 0x40000000;; + prevColor = (color & 0x00FFFFFF) | 0x80000000; } - if (_this->m_highlightedBytes.contains(off)) - currColor = _this->m_highlightedBytes[off]; - if (_this->m_highlightedBytes.contains(off - 1)) - prevColor = _this->m_highlightedBytes[off - 1]; + if (_this->m_highlightedBytes.contains(off)) { + auto color = (_this->m_highlightedBytes[off] & 0x00FFFFFF) | 0x80000000; + currColor = currColor.has_value() ? ImAlphaBlendColors(color, currColor.value()) : color; + } + if (_this->m_highlightedBytes.contains(off - 1)) { + auto color = (_this->m_highlightedBytes[off - 1] & 0x00FFFFFF) | 0x80000000; + prevColor = prevColor.has_value() ? ImAlphaBlendColors(color, prevColor.value()) : color; + } if (next && prevColor != currColor) { return false; } - if (currColor.has_value()) { - _this->m_memoryEditor.HighlightColor = currColor.value(); + if (currColor.has_value() && (currColor.value() & 0x00FFFFFF) != 0x00) { + _this->m_memoryEditor.HighlightColor = (currColor.value() & 0x00FFFFFF) | 0x40000000; return true; }