From 8581ab9eb32600e5104299889c2afd778874ddd6 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 6 Nov 2023 15:15:35 +0100 Subject: [PATCH] feat: Added simple data access graph to pattern editor --- lib/external/pattern_language | 2 +- .../content/views/view_pattern_editor.hpp | 8 ++++ .../content/views/view_pattern_editor.cpp | 42 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 6eb555610..d70f027c0 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 6eb55561040c61782e4edcc19d794920b141e2f3 +Subproject commit d70f027c015b784140b3e8be60370df3e58c4fa6 diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 6d584844f..5cd37302c 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -132,6 +132,11 @@ namespace hex::plugin::builtin { } }; + struct AccessData { + float progress; + u32 color; + }; + std::unique_ptr m_parserRuntime; PerProvider> m_possiblePatternFiles; @@ -179,6 +184,9 @@ namespace hex::plugin::builtin { std::atomic m_resetDebuggerVariables; int m_debuggerScopeIndex = 0; + std::array m_accessHistory; + u32 m_accessHistoryIndex = 0; + private: void drawConsole(ImVec2 size); void drawEnvVars(ImVec2 size, std::list &envVars); diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index f6ac325ac..94bcb18bd 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -244,6 +244,45 @@ namespace hex::plugin::builtin { } else { ImGui::TextSpinner("hex.builtin.view.pattern_editor.evaluating"_lang); } + + ImGui::SameLine(); + ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); + ImGui::SameLine(); + + const auto padding = ImGui::GetStyle().FramePadding.y; + + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2()); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2()); + if (ImGui::BeginChild("##read_cursor", ImGui::GetContentRegionAvail() + ImVec2(0, padding), true)) { + const auto startPos = ImGui::GetCursorScreenPos(); + const auto size = ImGui::GetContentRegionAvail(); + + const auto dataBaseAddress = runtime.getInternals().evaluator->getDataBaseAddress(); + const auto dataSize = runtime.getInternals().evaluator->getDataSize(); + + const auto insertPos = [&, this](u64 address, u32 color) { + const auto progress = (address - dataBaseAddress) / float(dataSize); + + this->m_accessHistory[this->m_accessHistoryIndex] = { progress, color }; + this->m_accessHistoryIndex = (this->m_accessHistoryIndex + 1) % this->m_accessHistory.size(); + }; + + insertPos(runtime.getLastReadAddress(), ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarBlue)); + insertPos(runtime.getLastWriteAddress(), ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarRed)); + insertPos(runtime.getLastPatternPlaceAddress(), ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarGreen)); + + auto drawList = ImGui::GetWindowDrawList(); + for (const auto &[progress, color] : this->m_accessHistory) { + if (progress <= 0) continue; + + const auto linePos = startPos + ImVec2(size.x * progress, 0); + + drawList->AddLine(linePos, linePos + ImVec2(0, size.y), color, 2_scaled); + } + } + ImGui::EndChild(); + ImGui::PopStyleVar(2); + } else { if (ImGui::Checkbox("hex.builtin.view.pattern_editor.auto"_lang, &this->m_runAutomatically)) { if (this->m_runAutomatically) @@ -942,6 +981,9 @@ namespace hex::plugin::builtin { this->m_sectionWindowDrawer.clear(); this->m_consoleEditor.SetText(""); + this->m_accessHistory = {}; + this->m_accessHistoryIndex = 0; + EventManager::post(); TaskManager::createTask("hex.builtin.view.pattern_editor.evaluating", TaskManager::NoProgress, [this, code, provider](auto &task) {