2020-11-10 20:31:04 +00:00
|
|
|
#include "views/view_pattern_data.hpp"
|
|
|
|
|
2020-11-11 09:47:02 +00:00
|
|
|
#include "providers/provider.hpp"
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2020-11-11 08:18:35 +00:00
|
|
|
ViewPatternData::ViewPatternData(prv::Provider* &dataProvider, std::vector<Highlight> &highlights)
|
|
|
|
: View(), m_dataProvider(dataProvider), m_highlights(highlights) {
|
2020-11-10 20:31:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewPatternData::~ViewPatternData() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-10 23:12:30 +00:00
|
|
|
std::string makeDisplayable(u8 *data, size_t size) {
|
|
|
|
std::string result;
|
|
|
|
for (u8* c = data; c < (data + size - 1); c++) {
|
|
|
|
if (iscntrl(*c) || *c > 0x7F)
|
|
|
|
result += " ";
|
|
|
|
else
|
|
|
|
result += *c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
|
|
|
|
void ViewPatternData::createView() {
|
|
|
|
if (!this->m_windowOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ImGui::Begin("Pattern Data", &this->m_windowOpen)) {
|
|
|
|
ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav);
|
|
|
|
|
2020-11-12 22:57:43 +00:00
|
|
|
if (this->m_dataProvider != nullptr && this->m_dataProvider->isReadable()) {
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-13 11:07:05 +00:00
|
|
|
for (auto&[offset, type, color, name] : this->m_highlights) {
|
|
|
|
std::vector<u8> buffer(type.size + 1, 0x00);
|
2020-11-11 08:18:35 +00:00
|
|
|
|
2020-11-13 11:07:05 +00:00
|
|
|
this->m_dataProvider->read(offset, buffer.data(), type.size);
|
2020-11-11 08:18:35 +00:00
|
|
|
|
2020-11-13 11:07:05 +00:00
|
|
|
if (type.size <= 8) {
|
2020-11-12 22:57:43 +00:00
|
|
|
u64 data = 0;
|
2020-11-13 11:07:05 +00:00
|
|
|
std::memcpy(&data, buffer.data(), type.size);
|
|
|
|
|
|
|
|
switch (type.kind) {
|
|
|
|
case VariableType::Kind::Unsigned:
|
|
|
|
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] %lu (0x%08lx) \"%s\"", offset,
|
|
|
|
offset + type.size, data, data,
|
|
|
|
makeDisplayable(buffer.data(), buffer.size()).c_str());
|
|
|
|
break;
|
|
|
|
case VariableType::Kind::Signed:
|
|
|
|
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] %ld (0x%08lx) \"%s\"", offset,
|
|
|
|
offset + type.size, data, data,
|
|
|
|
makeDisplayable(buffer.data(), buffer.size()).c_str());
|
|
|
|
break;
|
|
|
|
case VariableType::Kind::FloatingPoint:
|
|
|
|
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] %f (0x%08lx) \"%s\"", offset,
|
|
|
|
offset + type.size, data, data,
|
|
|
|
makeDisplayable(buffer.data(), buffer.size()).c_str());
|
|
|
|
break;
|
|
|
|
}
|
2020-11-12 22:57:43 +00:00
|
|
|
} else
|
2020-11-13 11:07:05 +00:00
|
|
|
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] [ ARRAY ] \"%s\"", offset, offset + type.size,
|
2020-11-12 22:57:43 +00:00
|
|
|
makeDisplayable(buffer.data(), buffer.size()).c_str());
|
2020-11-11 08:18:35 +00:00
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
2020-11-11 09:47:02 +00:00
|
|
|
ImGui::End();
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewPatternData::createMenu() {
|
2020-11-11 08:22:55 +00:00
|
|
|
if (ImGui::BeginMenu("View")) {
|
2020-11-10 20:31:04 +00:00
|
|
|
ImGui::MenuItem("Data View", "", &this->m_windowOpen);
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|