mirror of https://github.com/WerWolv/ImHex.git
Select region when clicking on string, disassembly or pattern data item
This commit is contained in:
parent
c281372b8d
commit
84f80b3e06
|
@ -9,7 +9,9 @@ namespace hex {
|
|||
DataChanged,
|
||||
PatternChanged,
|
||||
FileDropped,
|
||||
ByteSelected
|
||||
ByteSelected,
|
||||
|
||||
SelectionChangeRequest
|
||||
};
|
||||
|
||||
struct EventHandler {
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
namespace hex::lang {
|
||||
|
||||
using namespace ::std::literals::string_literals;
|
||||
|
||||
namespace {
|
||||
|
||||
std::string makeDisplayable(u8 *data, size_t size) {
|
||||
|
@ -131,6 +133,11 @@ namespace hex::lang {
|
|||
ImGui::TableNextColumn();
|
||||
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip);
|
||||
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::TableNextColumn();
|
||||
ImGui::Text("0x%08lx : 0x%08lx", this->getOffset(), this->getOffset() + this->getSize() - 1);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <hex.hpp>
|
||||
|
||||
#include <cmath>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -35,6 +36,15 @@ namespace hex::prv {
|
|||
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;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -136,4 +136,9 @@ namespace hex {
|
|||
private:
|
||||
std::function<void()> m_func;
|
||||
};
|
||||
|
||||
struct Region {
|
||||
u64 address;
|
||||
size_t size;
|
||||
};
|
||||
}
|
|
@ -15,6 +15,7 @@ namespace hex {
|
|||
struct Disassembly {
|
||||
u64 address;
|
||||
u64 offset;
|
||||
size_t size;
|
||||
std::string bytes;
|
||||
std::string opcodeString;
|
||||
};
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace hex {
|
|||
Disassembly disassembly = { 0 };
|
||||
disassembly.address = instructions[instr].address;
|
||||
disassembly.offset = this->m_codeOffset + address + usedBytes;
|
||||
disassembly.size = instructions[instr].size;
|
||||
disassembly.opcodeString = instructions[instr].mnemonic + " "s + instructions[instr].op_str;
|
||||
|
||||
for (u8 i = 0; i < instructions[instr].size; i++)
|
||||
|
@ -120,6 +121,9 @@ namespace hex {
|
|||
this->m_micoMode = 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))
|
||||
this->m_modeBasicARM = CS_MODE_ARM;
|
||||
ImGui::SameLine();
|
||||
|
@ -142,6 +146,9 @@ namespace hex {
|
|||
this->m_modeBasicPPC = cs_mode(0);
|
||||
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))
|
||||
this->m_modeBasicMIPS = CS_MODE_MIPS32;
|
||||
ImGui::SameLine();
|
||||
|
@ -161,6 +168,9 @@ namespace hex {
|
|||
this->m_micoMode = 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))
|
||||
this->m_modeBasicX86 = CS_MODE_16;
|
||||
ImGui::SameLine();
|
||||
|
@ -178,6 +188,9 @@ namespace hex {
|
|||
this->m_micoMode = 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))
|
||||
this->m_modeBasicPPC = CS_MODE_32;
|
||||
ImGui::SameLine();
|
||||
|
@ -236,6 +249,11 @@ namespace hex {
|
|||
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||
ImGui::TableNextRow();
|
||||
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::TableNextColumn();
|
||||
ImGui::Text("0x%llx", this->m_disassembly[i].offset);
|
||||
|
|
|
@ -56,6 +56,19 @@ namespace hex {
|
|||
if (filePath != nullptr)
|
||||
this->openFile(filePath);
|
||||
});
|
||||
|
||||
View::subscribeEvent(Events::SelectionChangeRequest, [this](const void *userData) {
|
||||
const Region ®ion = *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() {
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#include "views/view_strings.hpp"
|
||||
|
||||
#include "providers/provider.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
namespace hex {
|
||||
|
||||
ViewStrings::ViewStrings(prv::Provider* &dataProvider) : View(), m_dataProvider(dataProvider) {
|
||||
|
@ -122,6 +125,11 @@ namespace hex {
|
|||
|
||||
ImGui::TableNextRow();
|
||||
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::TableNextColumn();
|
||||
ImGui::Text("0x%04lx", foundString.size);
|
||||
|
|
Loading…
Reference in New Issue