diff --git a/include/helpers/math_evaluator.hpp b/include/helpers/math_evaluator.hpp index eb7c081e5..4c93e4b7e 100644 --- a/include/helpers/math_evaluator.hpp +++ b/include/helpers/math_evaluator.hpp @@ -74,7 +74,7 @@ namespace hex { void setVariable(std::string name, long double value); void setFunction(std::string name, std::function(std::vector)> function, size_t minNumArgs, size_t maxNumArgs); - const std::unordered_map& getVariables() { return this->m_variables; } + std::unordered_map& getVariables() { return this->m_variables; } private: std::queue parseInput(const char *input); diff --git a/include/views/view_tools.hpp b/include/views/view_tools.hpp index 09468ba40..ac7ad2ca7 100644 --- a/include/views/view_tools.hpp +++ b/include/views/view_tools.hpp @@ -15,13 +15,15 @@ namespace hex { class ViewTools : public View { public: - ViewTools(); + ViewTools(hex::prv::Provider* &provider); ~ViewTools() override; void createView() override; void createMenu() override; private: + hex::prv::Provider* &m_dataProvider; + char *m_mangledBuffer = nullptr; std::string m_demangledName; diff --git a/source/main.cpp b/source/main.cpp index 181850257..99176c511 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -36,7 +36,7 @@ int main() { window.addView(dataProvider); window.addView(dataProvider); window.addView(dataProvider); - window.addView(); + window.addView(dataProvider); window.addView(); window.loop(); diff --git a/source/views/view_tools.cpp b/source/views/view_tools.cpp index 150d0a00b..a0d4c0dda 100644 --- a/source/views/view_tools.cpp +++ b/source/views/view_tools.cpp @@ -4,13 +4,14 @@ #include #include +#include "providers/provider.hpp" #include "helpers/utils.hpp" #include namespace hex { - ViewTools::ViewTools() : View("Tools") { + ViewTools::ViewTools(hex::prv::Provider* &provider) : View("Tools"), m_dataProvider(provider) { this->m_mangledBuffer = new char[0xF'FFFF]; std::memset(this->m_mangledBuffer, 0x00, 0xF'FFFF); @@ -26,13 +27,40 @@ namespace hex { std::memset(this->m_mathInput, 0x00, 0xFFFF); this->m_mathEvaluator.registerStandardVariables(); this->m_mathEvaluator.registerStandardFunctions(); + this->m_mathEvaluator.setFunction("clear", [this](auto args) -> std::optional { this->m_mathHistory.clear(); this->m_lastMathError.clear(); + this->m_mathEvaluator.getVariables().clear(); + this->m_mathEvaluator.registerStandardVariables(); std::memset(this->m_mathInput, 0x00, 0xFFFF); return { }; }, 0, 0); + + this->m_mathEvaluator.setFunction("read", [this](auto args) -> std::optional { + u8 value = 0; + + if (this->m_dataProvider == nullptr || !this->m_dataProvider->isReadable() || args[0] >= this->m_dataProvider->getActualSize()) + return { }; + + this->m_dataProvider->read(args[0], &value, sizeof(u8)); + + return value; + }, 1, 1); + + this->m_mathEvaluator.setFunction("write", [this](auto args) -> std::optional { + if (this->m_dataProvider == nullptr || !this->m_dataProvider->isWritable() || args[0] >= this->m_dataProvider->getActualSize()) + return { }; + + if (args[1] > 0xFF) + return { }; + + u8 value = args[1]; + this->m_dataProvider->write(args[0], &value, sizeof(u8)); + + return { }; + }, 2, 2); } ViewTools::~ViewTools() { @@ -198,6 +226,9 @@ namespace hex { ImGui::TableHeadersRow(); while (clipper.Step()) { for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + if (i == 0) + ImGui::PushStyleColor(ImGuiCol_Text, ImU32(ImColor(0xA5, 0x45, 0x45))); + ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -214,6 +245,9 @@ namespace hex { u64(this->m_mathHistory[(this->m_mathHistory.size() - 1) - i])); break; } + + if (i == 0) + ImGui::PopStyleColor(); } }