ui: Highlight modified bytes in red

This commit is contained in:
WerWolv 2022-09-28 15:01:43 +02:00
parent 639390115b
commit c769e9cc32
8 changed files with 31 additions and 11 deletions

View File

@ -66,7 +66,7 @@ namespace hex {
namespace impl {
using HighlightingFunction = std::function<std::optional<color_t>(u64, const u8*, size_t)>;
using HighlightingFunction = std::function<std::optional<color_t>(u64, const u8*, size_t, bool)>;
std::map<u32, Highlighting> &getBackgroundHighlights();
std::map<u32, HighlightingFunction> &getBackgroundHighlightingFunctions();

View File

@ -113,6 +113,8 @@ namespace hex::prv {
this->writeRaw(patchAddress - this->getBaseAddress(), &patch, 1);
}
this->markDirty();
this->m_patches.emplace_back();
}

View File

@ -12,7 +12,7 @@ namespace hex::plugin::builtin {
class ViewPatches : public View {
public:
explicit ViewPatches();
~ViewPatches() override;
~ViewPatches() override = default;
void drawContent() override;

View File

@ -33,7 +33,7 @@ namespace hex::plugin::builtin {
ImHexApi::Provider::markDirty();
});
ImHexApi::HexEditor::addBackgroundHighlightingProvider([](u64 address, const u8* data, size_t size) -> std::optional<color_t> {
ImHexApi::HexEditor::addBackgroundHighlightingProvider([](u64 address, const u8* data, size_t size, bool) -> std::optional<color_t> {
hex::unused(data);
for (const auto &bookmark : ProviderExtraData::getCurrent().bookmarks) {

View File

@ -16,7 +16,7 @@ namespace hex::plugin::builtin {
ViewFind::ViewFind() : View("hex.builtin.view.find.name") {
const static auto HighlightColor = [] { return (ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarPurple) & 0x00FFFFFF) | 0x70000000; };
ImHexApi::HexEditor::addBackgroundHighlightingProvider([this](u64 address, const u8* data, size_t size) -> std::optional<color_t> {
ImHexApi::HexEditor::addBackgroundHighlightingProvider([this](u64 address, const u8* data, size_t size, bool) -> std::optional<color_t> {
hex::unused(data, size);
if (this->m_searchTask.isRunning())

View File

@ -460,9 +460,12 @@ namespace hex::plugin::builtin {
this->registerEvents();
this->registerMenuItems();
ImHexApi::HexEditor::addForegroundHighlightingProvider([this](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
ImHexApi::HexEditor::addForegroundHighlightingProvider([this](u64 address, const u8 *data, size_t size, bool hasColor) -> std::optional<color_t> {
hex::unused(address);
if (hasColor)
return std::nullopt;
if (!this->m_grayOutZero)
return std::nullopt;
@ -484,11 +487,15 @@ namespace hex::plugin::builtin {
}
static std::optional<color_t> queryBackgroundColor(u64 address, const u8 *data, size_t size) {
std::optional<color_t> result;
for (const auto &[id, callback] : ImHexApi::HexEditor::impl::getBackgroundHighlightingFunctions()) {
if (auto color = callback(address, data, size); color.has_value())
if (auto color = callback(address, data, size, result.has_value()); color.has_value())
return color.value();
}
if (result.has_value())
return result;
for (const auto &[id, highlighting] : ImHexApi::HexEditor::impl::getBackgroundHighlights()) {
if (highlighting.getRegion().overlaps({ address, size }))
return highlighting.getColor();
@ -498,11 +505,15 @@ namespace hex::plugin::builtin {
}
static std::optional<color_t> queryForegroundColor(u64 address, const u8 *data, size_t size) {
std::optional<color_t> result;
for (const auto &[id, callback] : ImHexApi::HexEditor::impl::getForegroundHighlightingFunctions()) {
if (auto color = callback(address, data, size); color.has_value())
return color.value();
if (auto color = callback(address, data, size, result.has_value()); color.has_value())
result = color;
}
if (result.has_value())
return result;
for (const auto &[id, highlighting] : ImHexApi::HexEditor::impl::getForegroundHighlights()) {
if (highlighting.getRegion().overlaps({ address, size }))
return highlighting.getColor();

View File

@ -29,10 +29,17 @@ namespace hex::plugin::builtin {
return true;
}
});
}
ViewPatches::~ViewPatches() {
ImHexApi::HexEditor::addForegroundHighlightingProvider([](u64 offset, const u8* buffer, size_t, bool) -> std::optional<color_t> {
if (!ImHexApi::Provider::isValid())
return std::nullopt;
auto &patches = ImHexApi::Provider::get()->getPatches();
if (patches.contains(offset) && patches[offset] != buffer[0])
return ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarRed);
else
return std::nullopt;
});
}
void ViewPatches::drawContent() {

View File

@ -250,7 +250,7 @@ namespace hex::plugin::builtin {
});
ImHexApi::HexEditor::addBackgroundHighlightingProvider([this](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
ImHexApi::HexEditor::addBackgroundHighlightingProvider([this](u64 address, const u8 *data, size_t size, bool) -> std::optional<color_t> {
hex::unused(data, size);
if (this->m_runningEvaluators != 0)