feat: Added pattern export option to pattern data view
This commit is contained in:
parent
59aa52e744
commit
9712329924
2
lib/external/pattern_language
vendored
2
lib/external/pattern_language
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 86e4a8d4c0934412cf69713516a96f268f1d7e6d
|
Subproject commit 7d8d90fb2a421d0f47b3566584c976f061afe5ee
|
@ -70,4 +70,4 @@ elseif (APPLE)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_link_libraries(libimhex PRIVATE ${FMT_LIBRARIES})
|
target_link_libraries(libimhex PRIVATE ${FMT_LIBRARIES})
|
||||||
target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} libpl ${MINIAUDIO_LIBRARIES} libwolv-utils libwolv-io libwolv-hash libwolv-net libwolv-containers)
|
target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} libpl libpl-gen ${MINIAUDIO_LIBRARIES} libwolv-utils libwolv-io libwolv-hash libwolv-net libwolv-containers)
|
||||||
|
@ -2,15 +2,20 @@
|
|||||||
|
|
||||||
#include <pl/patterns/pattern.hpp>
|
#include <pl/patterns/pattern.hpp>
|
||||||
#include <pl/pattern_visitor.hpp>
|
#include <pl/pattern_visitor.hpp>
|
||||||
|
|
||||||
|
#include <pl/formatters.hpp>
|
||||||
|
|
||||||
#include <hex/providers/provider.hpp>
|
#include <hex/providers/provider.hpp>
|
||||||
|
|
||||||
namespace hex::plugin::builtin::ui {
|
namespace hex::plugin::builtin::ui {
|
||||||
|
|
||||||
class PatternDrawer : public pl::PatternVisitor {
|
class PatternDrawer : public pl::PatternVisitor {
|
||||||
public:
|
public:
|
||||||
PatternDrawer() = default;
|
PatternDrawer() {
|
||||||
|
this->m_formatters = pl::gen::fmt::createFormatters();
|
||||||
|
}
|
||||||
|
|
||||||
void draw(const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, float height = 0.0F);
|
void draw(const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, pl::PatternLanguage *runtime = nullptr, float height = 0.0F);
|
||||||
|
|
||||||
enum class TreeStyle {
|
enum class TreeStyle {
|
||||||
Default = 0,
|
Default = 0,
|
||||||
@ -87,5 +92,7 @@ namespace hex::plugin::builtin::ui {
|
|||||||
bool m_favoritesUpdated = false;
|
bool m_favoritesUpdated = false;
|
||||||
|
|
||||||
std::function<void(Region)> m_selectionCallback = [](Region) { };
|
std::function<void(Region)> m_selectionCallback = [](Region) { };
|
||||||
|
|
||||||
|
pl::gen::fmt::FormatterArray m_formatters;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -366,6 +366,7 @@
|
|||||||
"hex.builtin.nodes.visualizer.layered_dist.header": "Layered Distribution",
|
"hex.builtin.nodes.visualizer.layered_dist.header": "Layered Distribution",
|
||||||
"hex.builtin.pattern_drawer.color": "Color",
|
"hex.builtin.pattern_drawer.color": "Color",
|
||||||
"hex.builtin.pattern_drawer.double_click": "Double-click to see more items",
|
"hex.builtin.pattern_drawer.double_click": "Double-click to see more items",
|
||||||
|
"hex.builtin.pattern_drawer.export": "Export Patterns as...",
|
||||||
"hex.builtin.pattern_drawer.favorites": "Favorites",
|
"hex.builtin.pattern_drawer.favorites": "Favorites",
|
||||||
"hex.builtin.pattern_drawer.local": "Local",
|
"hex.builtin.pattern_drawer.local": "Local",
|
||||||
"hex.builtin.pattern_drawer.offset": "Offset",
|
"hex.builtin.pattern_drawer.offset": "Offset",
|
||||||
|
@ -44,7 +44,7 @@ namespace hex::plugin::builtin {
|
|||||||
this->m_shouldReset = false;
|
this->m_shouldReset = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m_patternDrawer.draw(runtime.getPatterns());
|
this->m_patternDrawer.draw(runtime.getPatterns(), &runtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -484,7 +484,7 @@ namespace hex::plugin::builtin {
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
if (*this->m_executionDone)
|
if (*this->m_executionDone)
|
||||||
patternDrawer.draw(patterns, 150_scaled);
|
patternDrawer.draw(patterns, &runtime, 150_scaled);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -988,7 +988,7 @@ namespace hex::plugin::builtin::ui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PatternDrawer::draw(const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, float height) {
|
void PatternDrawer::draw(const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, pl::PatternLanguage *runtime, float height) {
|
||||||
const auto treeStyleButton = [this](auto icon, TreeStyle style, const char *tooltip) {
|
const auto treeStyleButton = [this](auto icon, TreeStyle style, const char *tooltip) {
|
||||||
bool pushed = false;
|
bool pushed = false;
|
||||||
|
|
||||||
@ -1010,7 +1010,7 @@ namespace hex::plugin::builtin::ui {
|
|||||||
this->resetEditing();
|
this->resetEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGui::GetTextLineHeightWithSpacing() * 5.5);
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGui::GetTextLineHeightWithSpacing() * 7.5);
|
||||||
if (ImGui::InputTextIcon("##Search", ICON_VS_FILTER, this->m_filterText)) {
|
if (ImGui::InputTextIcon("##Search", ICON_VS_FILTER, this->m_filterText)) {
|
||||||
this->m_filter = parseRValueFilter(this->m_filterText);
|
this->m_filter = parseRValueFilter(this->m_filterText);
|
||||||
}
|
}
|
||||||
@ -1024,6 +1024,37 @@ namespace hex::plugin::builtin::ui {
|
|||||||
ImGui::SameLine(0, 0);
|
ImGui::SameLine(0, 0);
|
||||||
treeStyleButton(ICON_VS_LIST_FLAT, TreeStyle::Flattened, "hex.builtin.pattern_drawer.tree_style.flattened"_lang);
|
treeStyleButton(ICON_VS_LIST_FLAT, TreeStyle::Flattened, "hex.builtin.pattern_drawer.tree_style.flattened"_lang);
|
||||||
|
|
||||||
|
ImGui::SameLine(0, 15_scaled);
|
||||||
|
|
||||||
|
const auto startPos = ImGui::GetCursorPos();
|
||||||
|
|
||||||
|
ImGui::BeginDisabled(runtime == nullptr);
|
||||||
|
if (ImGui::DimmedIconButton(ICON_VS_EXPORT, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
||||||
|
ImGui::OpenPopup("ExportPatterns");
|
||||||
|
}
|
||||||
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
|
ImGui::InfoTooltip("hex.builtin.pattern_drawer.export"_lang);
|
||||||
|
|
||||||
|
ImGui::SetNextWindowPos(ImGui::GetWindowPos() + ImVec2(startPos.x, ImGui::GetCursorPosY()));
|
||||||
|
if (ImGui::BeginPopup("ExportPatterns")) {
|
||||||
|
for (const auto &formatter : this->m_formatters) {
|
||||||
|
const auto &name = formatter->getName();
|
||||||
|
const auto &extension = formatter->getFileExtension();
|
||||||
|
|
||||||
|
if (ImGui::MenuItem(name.c_str())) {
|
||||||
|
|
||||||
|
fs::openFileBrowser(fs::DialogMode::Save, { { name.c_str(), extension.c_str() } }, [&](const std::fs::path &path) {
|
||||||
|
auto result = formatter->format(*runtime);
|
||||||
|
|
||||||
|
wolv::io::File output(path, wolv::io::File::Mode::Create);
|
||||||
|
output.writeVector(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this->m_favoritesUpdated) {
|
if (!this->m_favoritesUpdated) {
|
||||||
this->m_favoritesUpdated = true;
|
this->m_favoritesUpdated = true;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user