Select region when clicking on string, disassembly or pattern data item

This commit is contained in:
WerWolv 2020-11-23 13:10:14 +01:00
parent c281372b8d
commit 84f80b3e06
8 changed files with 65 additions and 1 deletions

View File

@ -9,7 +9,9 @@ namespace hex {
DataChanged, DataChanged,
PatternChanged, PatternChanged,
FileDropped, FileDropped,
ByteSelected ByteSelected,
SelectionChangeRequest
}; };
struct EventHandler { struct EventHandler {

View File

@ -13,6 +13,8 @@
namespace hex::lang { namespace hex::lang {
using namespace ::std::literals::string_literals;
namespace { namespace {
std::string makeDisplayable(u8 *data, size_t size) { std::string makeDisplayable(u8 *data, size_t size) {
@ -131,6 +133,11 @@ namespace hex::lang {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip); ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Selectable(("##PatternDataLine"s + std::to_string(this->getOffset())).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) {
Region selectRegion = { this->getOffset(), this->getSize() };
View::postEvent(Events::SelectionChangeRequest, &selectRegion);
}
ImGui::SameLine();
ImGui::Text("%s", this->getName().c_str()); ImGui::Text("%s", this->getName().c_str());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("0x%08lx : 0x%08lx", this->getOffset(), this->getOffset() + this->getSize() - 1); ImGui::Text("0x%08lx : 0x%08lx", this->getOffset(), this->getOffset() + this->getSize() - 1);

View File

@ -3,6 +3,7 @@
#include <hex.hpp> #include <hex.hpp>
#include <cmath> #include <cmath>
#include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
@ -35,6 +36,15 @@ namespace hex::prv {
return std::min(this->getActualSize() - PageSize * this->m_currPage, PageSize); return std::min(this->getActualSize() - PageSize * this->m_currPage, PageSize);
} }
virtual std::optional<u32> getPageOfAddress(u64 address) {
u32 page = std::floor(address / double(PageSize));
if (page >= this->getPageCount())
return { };
return page;
}
virtual std::vector<std::pair<std::string, std::string>> getDataInformation() = 0; virtual std::vector<std::pair<std::string, std::string>> getDataInformation() = 0;
protected: protected:

View File

@ -136,4 +136,9 @@ namespace hex {
private: private:
std::function<void()> m_func; std::function<void()> m_func;
}; };
struct Region {
u64 address;
size_t size;
};
} }

View File

@ -15,6 +15,7 @@ namespace hex {
struct Disassembly { struct Disassembly {
u64 address; u64 address;
u64 offset; u64 offset;
size_t size;
std::string bytes; std::string bytes;
std::string opcodeString; std::string opcodeString;
}; };

View File

@ -59,6 +59,7 @@ namespace hex {
Disassembly disassembly = { 0 }; Disassembly disassembly = { 0 };
disassembly.address = instructions[instr].address; disassembly.address = instructions[instr].address;
disassembly.offset = this->m_codeOffset + address + usedBytes; disassembly.offset = this->m_codeOffset + address + usedBytes;
disassembly.size = instructions[instr].size;
disassembly.opcodeString = instructions[instr].mnemonic + " "s + instructions[instr].op_str; disassembly.opcodeString = instructions[instr].mnemonic + " "s + instructions[instr].op_str;
for (u8 i = 0; i < instructions[instr].size; i++) for (u8 i = 0; i < instructions[instr].size; i++)
@ -120,6 +121,9 @@ namespace hex {
this->m_micoMode = false; this->m_micoMode = false;
this->m_sparcV9Mode = false; this->m_sparcV9Mode = false;
if (this->m_modeBasicARM == cs_mode(0))
this->m_modeBasicARM = CS_MODE_ARM;
if (ImGui::RadioButton("ARM mode", this->m_modeBasicARM == CS_MODE_ARM)) if (ImGui::RadioButton("ARM mode", this->m_modeBasicARM == CS_MODE_ARM))
this->m_modeBasicARM = CS_MODE_ARM; this->m_modeBasicARM = CS_MODE_ARM;
ImGui::SameLine(); ImGui::SameLine();
@ -142,6 +146,9 @@ namespace hex {
this->m_modeBasicPPC = cs_mode(0); this->m_modeBasicPPC = cs_mode(0);
this->m_sparcV9Mode = false; this->m_sparcV9Mode = false;
if (this->m_modeBasicMIPS == cs_mode(0))
this->m_modeBasicMIPS = CS_MODE_MIPS32;
if (ImGui::RadioButton("MIPS32 mode", this->m_modeBasicMIPS == CS_MODE_MIPS32)) if (ImGui::RadioButton("MIPS32 mode", this->m_modeBasicMIPS == CS_MODE_MIPS32))
this->m_modeBasicMIPS = CS_MODE_MIPS32; this->m_modeBasicMIPS = CS_MODE_MIPS32;
ImGui::SameLine(); ImGui::SameLine();
@ -161,6 +168,9 @@ namespace hex {
this->m_micoMode = false; this->m_micoMode = false;
this->m_sparcV9Mode = false; this->m_sparcV9Mode = false;
if (this->m_modeBasicX86 == cs_mode(0))
this->m_modeBasicX86 = CS_MODE_16;
if (ImGui::RadioButton("16-bit mode", this->m_modeBasicX86 == CS_MODE_16)) if (ImGui::RadioButton("16-bit mode", this->m_modeBasicX86 == CS_MODE_16))
this->m_modeBasicX86 = CS_MODE_16; this->m_modeBasicX86 = CS_MODE_16;
ImGui::SameLine(); ImGui::SameLine();
@ -178,6 +188,9 @@ namespace hex {
this->m_micoMode = false; this->m_micoMode = false;
this->m_sparcV9Mode = false; this->m_sparcV9Mode = false;
if (m_modeBasicPPC == cs_mode(0))
this->m_modeBasicPPC = CS_MODE_32;
if (ImGui::RadioButton("32-bit mode", this->m_modeBasicPPC == CS_MODE_32)) if (ImGui::RadioButton("32-bit mode", this->m_modeBasicPPC == CS_MODE_32))
this->m_modeBasicPPC = CS_MODE_32; this->m_modeBasicPPC = CS_MODE_32;
ImGui::SameLine(); ImGui::SameLine();
@ -236,6 +249,11 @@ namespace hex {
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Selectable(("##DisassemblyLine"s + std::to_string(i)).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) {
Region selectRegion = { this->m_disassembly[i].offset, this->m_disassembly[i].size };
View::postEvent(Events::SelectionChangeRequest, &selectRegion);
}
ImGui::SameLine();
ImGui::Text("0x%llx", this->m_disassembly[i].address); ImGui::Text("0x%llx", this->m_disassembly[i].address);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("0x%llx", this->m_disassembly[i].offset); ImGui::Text("0x%llx", this->m_disassembly[i].offset);

View File

@ -56,6 +56,19 @@ namespace hex {
if (filePath != nullptr) if (filePath != nullptr)
this->openFile(filePath); this->openFile(filePath);
}); });
View::subscribeEvent(Events::SelectionChangeRequest, [this](const void *userData) {
const Region &region = *reinterpret_cast<const Region*>(userData);
auto page = this->m_dataProvider->getPageOfAddress(region.address);
if (!page.has_value())
return;
this->m_dataProvider->setCurrentPage(page.value());
this->m_memoryEditor.GotoAddr = region.address;
this->m_memoryEditor.DataPreviewAddr = region.address;
this->m_memoryEditor.DataPreviewAddrEnd = region.address + region.size - 1;
});
} }
ViewHexEditor::~ViewHexEditor() { ViewHexEditor::~ViewHexEditor() {

View File

@ -1,9 +1,12 @@
#include "views/view_strings.hpp" #include "views/view_strings.hpp"
#include "providers/provider.hpp" #include "providers/provider.hpp"
#include "utils.hpp"
#include <cstring> #include <cstring>
using namespace std::literals::string_literals;
namespace hex { namespace hex {
ViewStrings::ViewStrings(prv::Provider* &dataProvider) : View(), m_dataProvider(dataProvider) { ViewStrings::ViewStrings(prv::Provider* &dataProvider) : View(), m_dataProvider(dataProvider) {
@ -122,6 +125,11 @@ namespace hex {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Selectable(("##StringLine"s + std::to_string(i)).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) {
Region selectRegion = { foundString.offset, foundString.size };
View::postEvent(Events::SelectionChangeRequest, &selectRegion);
}
ImGui::SameLine();
ImGui::Text("0x%08lx : 0x%08lx", foundString.offset, foundString.offset + foundString.size); ImGui::Text("0x%08lx : 0x%08lx", foundString.offset, foundString.offset + foundString.size);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("0x%04lx", foundString.size); ImGui::Text("0x%04lx", foundString.size);