2020-11-21 00:12:58 +01:00
|
|
|
#include "views/view_data_inspector.hpp"
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
2020-11-21 00:12:58 +01:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
extern int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end);
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2021-01-13 01:24:27 +01:00
|
|
|
using NumberDisplayStyle = ContentRegistry::DataInspector::NumberDisplayStyle;
|
|
|
|
|
2021-03-03 22:26:17 +01:00
|
|
|
ViewDataInspector::ViewDataInspector() : View("hex.view.data_inspector.name") {
|
2021-01-21 10:53:12 +01:00
|
|
|
View::subscribeEvent(Events::RegionSelected, [this](auto userData) {
|
|
|
|
auto region = std::any_cast<Region>(userData);
|
2020-11-21 00:12:58 +01:00
|
|
|
|
2021-01-12 23:28:41 +01:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 15:39:06 +01:00
|
|
|
|
|
|
|
if (provider == nullptr) {
|
2020-12-21 11:23:57 +01:00
|
|
|
this->m_validBytes = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (region.address == (size_t)-1) {
|
|
|
|
this->m_validBytes = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-13 01:24:27 +01:00
|
|
|
this->m_validBytes = u64(provider->getSize() - region.address);
|
|
|
|
this->m_startAddress = region.address;
|
2020-11-21 00:12:58 +01:00
|
|
|
|
|
|
|
this->m_shouldInvalidate = true;
|
|
|
|
});
|
2021-01-13 01:24:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewDataInspector::~ViewDataInspector() {
|
|
|
|
View::unsubscribeEvent(Events::RegionSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewDataInspector::drawContent() {
|
|
|
|
if (this->m_shouldInvalidate) {
|
|
|
|
this->m_shouldInvalidate = false;
|
|
|
|
|
|
|
|
this->m_cachedData.clear();
|
|
|
|
auto provider = SharedData::currentProvider;
|
|
|
|
for (auto &entry : ContentRegistry::DataInspector::getEntries()) {
|
|
|
|
if (this->m_validBytes < entry.requiredSize)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::vector<u8> buffer(entry.requiredSize);
|
|
|
|
provider->read(this->m_startAddress, buffer.data(), buffer.size());
|
2021-03-02 22:09:38 +01:00
|
|
|
|
|
|
|
this->m_cachedData.push_back({ entry.unlocalizedName, entry.generatorFunction(buffer, this->m_endian, this->m_numberDisplayStyle) });
|
2020-11-21 00:36:38 +01:00
|
|
|
}
|
2020-11-21 00:12:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-03 22:26:17 +01:00
|
|
|
if (ImGui::Begin(View::toWindowName("hex.view.data_inspector.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
2021-01-12 23:28:41 +01:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 15:39:06 +01:00
|
|
|
|
|
|
|
if (provider != nullptr && provider->isReadable()) {
|
2021-01-03 17:12:20 +01:00
|
|
|
if (ImGui::BeginTable("##datainspector", 2,
|
|
|
|
ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg,
|
2021-01-13 01:24:27 +01:00
|
|
|
ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * (this->m_cachedData.size() + 1)))) {
|
2021-01-03 17:12:20 +01:00
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::TableSetupColumn("hex.view.data_inspector.table.name"_lang);
|
|
|
|
ImGui::TableSetupColumn("hex.view.data_inspector.table.value"_lang);
|
2021-01-03 17:12:20 +01:00
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
2021-03-02 22:09:38 +01:00
|
|
|
u32 i = 0;
|
2021-02-13 15:15:32 +01:00
|
|
|
for (const auto &[unlocalizedName, function] : this->m_cachedData) {
|
2021-03-02 22:09:38 +01:00
|
|
|
ImGui::PushID(i);
|
2021-01-03 17:12:20 +01:00
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
2021-02-13 15:15:32 +01:00
|
|
|
ImGui::TextUnformatted(LangEntry(unlocalizedName));
|
2021-01-03 17:12:20 +01:00
|
|
|
ImGui::TableNextColumn();
|
2021-03-02 22:09:38 +01:00
|
|
|
const auto ©Value = function();
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::Selectable("##InspectorLine", false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) {
|
|
|
|
ImGui::SetClipboardText(copyValue.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
i++;
|
2020-11-21 00:12:58 +01:00
|
|
|
}
|
2021-01-03 17:12:20 +01:00
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::RadioButton("hex.common.little_endian"_lang, this->m_endian == std::endian::little)) {
|
2021-01-03 17:12:20 +01:00
|
|
|
this->m_endian = std::endian::little;
|
|
|
|
this->m_shouldInvalidate = true;
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::RadioButton("hex.common.big_endian"_lang, this->m_endian == std::endian::big)) {
|
2021-01-03 17:12:20 +01:00
|
|
|
this->m_endian = std::endian::big;
|
|
|
|
this->m_shouldInvalidate = true;
|
2020-11-21 00:12:58 +01:00
|
|
|
}
|
2020-11-22 15:32:37 +01:00
|
|
|
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::RadioButton("hex.common.decimal"_lang, this->m_numberDisplayStyle == NumberDisplayStyle::Decimal)) {
|
2021-01-03 17:12:20 +01:00
|
|
|
this->m_numberDisplayStyle = NumberDisplayStyle::Decimal;
|
|
|
|
this->m_shouldInvalidate = true;
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::RadioButton("hex.common.hexadecimal"_lang, this->m_numberDisplayStyle == NumberDisplayStyle::Hexadecimal)) {
|
2021-01-03 17:12:20 +01:00
|
|
|
this->m_numberDisplayStyle = NumberDisplayStyle::Hexadecimal;
|
2020-11-22 15:32:37 +01:00
|
|
|
this->m_shouldInvalidate = true;
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::RadioButton("hex.common.octal"_lang, this->m_numberDisplayStyle == NumberDisplayStyle::Octal)) {
|
2021-01-03 17:12:20 +01:00
|
|
|
this->m_numberDisplayStyle = NumberDisplayStyle::Octal;
|
2020-11-22 15:32:37 +01:00
|
|
|
this->m_shouldInvalidate = true;
|
|
|
|
}
|
2020-11-21 00:12:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewDataInspector::drawMenu() {
|
2020-11-23 23:57:19 +01:00
|
|
|
|
2020-11-21 00:12:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|