1
0
mirror of synced 2025-01-30 03:27:25 +01:00

feat: Added pattern export option to pattern data view

This commit is contained in:
WerWolv 2023-06-05 11:57:26 +02:00
parent 59aa52e744
commit 9712329924
7 changed files with 47 additions and 8 deletions

@ -1 +1 @@
Subproject commit 86e4a8d4c0934412cf69713516a96f268f1d7e6d
Subproject commit 7d8d90fb2a421d0f47b3566584c976f061afe5ee

View File

@ -70,4 +70,4 @@ elseif (APPLE)
endif ()
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)

View File

@ -2,15 +2,20 @@
#include <pl/patterns/pattern.hpp>
#include <pl/pattern_visitor.hpp>
#include <pl/formatters.hpp>
#include <hex/providers/provider.hpp>
namespace hex::plugin::builtin::ui {
class PatternDrawer : public pl::PatternVisitor {
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 {
Default = 0,
@ -87,5 +92,7 @@ namespace hex::plugin::builtin::ui {
bool m_favoritesUpdated = false;
std::function<void(Region)> m_selectionCallback = [](Region) { };
pl::gen::fmt::FormatterArray m_formatters;
};
}

View File

@ -366,6 +366,7 @@
"hex.builtin.nodes.visualizer.layered_dist.header": "Layered Distribution",
"hex.builtin.pattern_drawer.color": "Color",
"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.local": "Local",
"hex.builtin.pattern_drawer.offset": "Offset",

View File

@ -44,7 +44,7 @@ namespace hex::plugin::builtin {
this->m_shouldReset = false;
}
this->m_patternDrawer.draw(runtime.getPatterns());
this->m_patternDrawer.draw(runtime.getPatterns(), &runtime);
}
}
}

View File

@ -484,7 +484,7 @@ namespace hex::plugin::builtin {
}();
if (*this->m_executionDone)
patternDrawer.draw(patterns, 150_scaled);
patternDrawer.draw(patterns, &runtime, 150_scaled);
};
}

View File

@ -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) {
bool pushed = false;
@ -1010,7 +1010,7 @@ namespace hex::plugin::builtin::ui {
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)) {
this->m_filter = parseRValueFilter(this->m_filterText);
}
@ -1024,6 +1024,37 @@ namespace hex::plugin::builtin::ui {
ImGui::SameLine(0, 0);
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) {
this->m_favoritesUpdated = true;