mirror of https://github.com/WerWolv/ImHex.git
ui: Highlight modified bytes in red
This commit is contained in:
parent
639390115b
commit
c769e9cc32
|
@ -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();
|
||||
|
|
|
@ -113,6 +113,8 @@ namespace hex::prv {
|
|||
this->writeRaw(patchAddress - this->getBaseAddress(), &patch, 1);
|
||||
}
|
||||
this->markDirty();
|
||||
|
||||
this->m_patches.emplace_back();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace hex::plugin::builtin {
|
|||
class ViewPatches : public View {
|
||||
public:
|
||||
explicit ViewPatches();
|
||||
~ViewPatches() override;
|
||||
~ViewPatches() override = default;
|
||||
|
||||
void drawContent() override;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue