views: Added constants search view
This commit is contained in:
parent
1e1cdb0ef0
commit
35c7f826bc
@ -84,6 +84,7 @@ add_executable(imhex ${application_type}
|
||||
source/views/view_settings.cpp
|
||||
source/views/view_data_processor.cpp
|
||||
source/views/view_yara.cpp
|
||||
source/views/view_constants.cpp
|
||||
|
||||
${imhex_icon}
|
||||
)
|
||||
|
39
include/views/view_constants.hpp
Normal file
39
include/views/view_constants.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/views/view.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
namespace hex {
|
||||
|
||||
enum class ConstantType {
|
||||
Int10,
|
||||
Int16BigEndian,
|
||||
Int16LittleEndian
|
||||
};
|
||||
|
||||
struct Constant {
|
||||
std::string name, description;
|
||||
std::string category;
|
||||
ConstantType type;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
class ViewConstants : public View {
|
||||
public:
|
||||
explicit ViewConstants();
|
||||
~ViewConstants() override;
|
||||
|
||||
void drawContent() override;
|
||||
void drawMenu() override;
|
||||
|
||||
private:
|
||||
void reloadConstants();
|
||||
|
||||
std::vector<Constant> m_constants;
|
||||
std::vector<Constant*> m_filteredConstants;
|
||||
std::string m_search;
|
||||
};
|
||||
|
||||
}
|
@ -229,7 +229,8 @@ namespace hex {
|
||||
Plugins,
|
||||
Yara,
|
||||
Config,
|
||||
Resources
|
||||
Resources,
|
||||
Constants
|
||||
};
|
||||
|
||||
std::vector<std::string> getPath(ImHexPath path);
|
||||
|
@ -222,6 +222,8 @@ namespace hex {
|
||||
return { (appDataDir / "imhex" / "config").string() };
|
||||
case ImHexPath::Resources:
|
||||
return { (parentDir / "resources").string() };
|
||||
case ImHexPath::Constants:
|
||||
return { (parentDir / "constants").string() };
|
||||
default: __builtin_unreachable();
|
||||
}
|
||||
#elif defined(OS_MACOS)
|
||||
@ -268,6 +270,10 @@ namespace hex {
|
||||
std::transform(dataDirs.begin(), dataDirs.end(), std::back_inserter(result),
|
||||
[](auto p) { return (p / "imhex" / "resources").string(); });
|
||||
return result;
|
||||
case ImHexPath::Constants:
|
||||
std::transform(dataDirs.begin(), dataDirs.end(), std::back_inserter(result),
|
||||
[](auto p) { return (p / "imhex" / "constants").string(); });
|
||||
return result;
|
||||
default: __builtin_unreachable();
|
||||
}
|
||||
#endif
|
||||
|
@ -43,6 +43,9 @@
|
||||
case ImHexPath::Resources:
|
||||
result = [appSupportDir URLByAppendingPathComponent:@"imhex/resources"];
|
||||
break;
|
||||
case ImHexPath::Constants:
|
||||
result = [appSupportDir URLByAppendingPathComponent:@"imhex/constants"];
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == nil) {
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "views/view_settings.hpp"
|
||||
#include "views/view_data_processor.hpp"
|
||||
#include "views/view_yara.hpp"
|
||||
#include "views/view_constants.hpp"
|
||||
|
||||
#include "helpers/plugin_manager.hpp"
|
||||
|
||||
@ -92,6 +93,7 @@ namespace hex::init {
|
||||
ContentRegistry::Views::add<ViewSettings>();
|
||||
ContentRegistry::Views::add<ViewDataProcessor>();
|
||||
ContentRegistry::Views::add<ViewYara>();
|
||||
ContentRegistry::Views::add<ViewConstants>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
111
source/views/view_constants.cpp
Normal file
111
source/views/view_constants.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
#include "views/view_constants.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
ViewConstants::ViewConstants() : View("hex.view.constants.name") {
|
||||
this->reloadConstants();
|
||||
this->m_search.resize(0xFFF, 0x00);
|
||||
}
|
||||
|
||||
ViewConstants::~ViewConstants() {
|
||||
|
||||
}
|
||||
|
||||
void ViewConstants::reloadConstants() {
|
||||
this->m_constants.clear();
|
||||
|
||||
for (auto &path : hex::getPath(ImHexPath::Constants)) {
|
||||
if (!std::filesystem::exists(path)) continue;
|
||||
|
||||
for (auto &file : std::filesystem::directory_iterator(path)) {
|
||||
if (!file.is_regular_file()) continue;
|
||||
|
||||
try {
|
||||
nlohmann::json content;
|
||||
std::ifstream(file.path()) >> content;
|
||||
|
||||
for (auto value : content["values"]) {
|
||||
Constant constant;
|
||||
constant.category = content["name"];
|
||||
constant.name = value["name"];
|
||||
if (value.contains("desc"))
|
||||
constant.description = value["desc"];
|
||||
constant.value = value["value"];
|
||||
|
||||
auto type = value["type"];
|
||||
if (type == "int10")
|
||||
constant.type = ConstantType::Int10;
|
||||
else if (type == "int16be")
|
||||
constant.type = ConstantType::Int16BigEndian;
|
||||
else if (type == "int16le")
|
||||
constant.type = ConstantType::Int16LittleEndian;
|
||||
else
|
||||
throw std::runtime_error("Invalid type");
|
||||
|
||||
this->m_constants.push_back(constant);
|
||||
}
|
||||
} catch (...) {
|
||||
log::info("Error");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewConstants::drawContent() {
|
||||
if (ImGui::Begin(View::toWindowName("hex.view.constants.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
|
||||
if (ImGui::InputText("##search", this->m_search.data(), this->m_search.size())) {
|
||||
this->m_filteredConstants.clear();
|
||||
for (auto &constant : this->m_constants) {
|
||||
if (constant.value.starts_with(this->m_search.c_str()) || constant.name.starts_with(this->m_search.c_str()) || constant.description.starts_with(this->m_search.c_str()))
|
||||
this->m_filteredConstants.push_back(&constant);
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::BeginTable("##strings", 4,
|
||||
ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable |
|
||||
ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
|
||||
ImGui::TableSetupScrollFreeze(0, 1);
|
||||
ImGui::TableSetupColumn("hex.view.constants.category"_lang, 0, -1, ImGui::GetID("category"));
|
||||
ImGui::TableSetupColumn("hex.view.constants.name"_lang, 0, -1, ImGui::GetID("name"));
|
||||
ImGui::TableSetupColumn("hex.view.constants.desc"_lang, 0, -1, ImGui::GetID("desc"));
|
||||
ImGui::TableSetupColumn("hex.view.constants.value"_lang, 0, -1, ImGui::GetID("value"));
|
||||
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
ImGuiListClipper clipper;
|
||||
clipper.Begin(this->m_filteredConstants.size());
|
||||
|
||||
while (clipper.Step()) {
|
||||
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", this->m_filteredConstants[i]->category.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", this->m_filteredConstants[i]->name.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", this->m_filteredConstants[i]->description.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", this->m_filteredConstants[i]->value.c_str());
|
||||
}
|
||||
}
|
||||
clipper.End();
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ViewConstants::drawMenu() {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user