2023-12-05 10:49:51 +01:00
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
|
2023-12-23 22:01:47 +01:00
|
|
|
#include <hex/providers/memory_provider.hpp>
|
|
|
|
|
2023-12-05 10:49:51 +01:00
|
|
|
#include <imgui.h>
|
|
|
|
|
2023-12-23 21:09:41 +01:00
|
|
|
#include <pl/pattern_language.hpp>
|
|
|
|
#include <pl/patterns/pattern.hpp>
|
|
|
|
|
2023-12-05 10:49:51 +01:00
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
|
|
|
#include <ui/hex_editor.hpp>
|
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
void drawHexVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
|
|
|
static ui::HexEditor editor;
|
2023-12-23 22:01:47 +01:00
|
|
|
static prv::MemoryProvider dataProvider;
|
2023-12-05 10:49:51 +01:00
|
|
|
|
|
|
|
if (shouldReset) {
|
|
|
|
auto pattern = arguments[0].toPattern();
|
|
|
|
std::vector<u8> data;
|
|
|
|
|
|
|
|
try {
|
|
|
|
data = pattern->getBytes();
|
|
|
|
} catch (const std::exception &) {
|
2023-12-23 22:01:47 +01:00
|
|
|
dataProvider.resize(0);
|
2023-12-05 10:49:51 +01:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2023-12-23 22:01:47 +01:00
|
|
|
dataProvider.resize(data.size());
|
|
|
|
dataProvider.writeRaw(0x00, data.data(), data.size());
|
2023-12-05 10:49:51 +01:00
|
|
|
|
2023-12-23 22:01:47 +01:00
|
|
|
editor.setProvider(&dataProvider);
|
2023-12-05 10:49:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::BeginChild("##editor", scaled(ImVec2(600, 400)), false, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
|
|
|
|
editor.draw();
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|