1
0
mirror of synced 2024-11-28 17:40:51 +01:00

ux: Fixed goto to work with base addresses and added absolute goto

This commit is contained in:
WerWolv 2021-04-16 19:44:52 +02:00
parent fddb790c70
commit 72eac9f149
5 changed files with 36 additions and 31 deletions

View File

@ -77,9 +77,8 @@ namespace hex::plugin::builtin {
}) {}
void drawNode() override {
ImGui::TextUnformatted("0x"); ImGui::SameLine(0, 0);
ImGui::PushItemWidth(100);
ImGui::InputScalar("##integerValue", ImGuiDataType_U64, &this->m_value, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
ImGui::InputScalar("hex", ImGuiDataType_U64, &this->m_value, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
ImGui::PopItemWidth();
}

View File

@ -179,6 +179,7 @@ namespace hex::plugin::builtin {
{ "hex.view.hexeditor.search.find_next", "Nächstes" },
{ "hex.view.hexeditor.search.find_prev", "Vorheriges" },
{ "hex.view.hexeditor.menu.file.goto", "Sprung" },
{ "hex.view.hexeditor.goto.offset.absolute", "Absolut" },
{ "hex.view.hexeditor.goto.offset.current", "Momentan" },
{ "hex.view.hexeditor.goto.offset.begin", "Beginn" },
{ "hex.view.hexeditor.goto.offset.end", "Ende" },

View File

@ -179,6 +179,7 @@ namespace hex::plugin::builtin {
{ "hex.view.hexeditor.search.find_next", "Find next" },
{ "hex.view.hexeditor.search.find_prev", "Find previous" },
{ "hex.view.hexeditor.menu.file.goto", "Goto" },
{ "hex.view.hexeditor.goto.offset.absolute", "Absolute" },
{ "hex.view.hexeditor.goto.offset.current", "Current" },
{ "hex.view.hexeditor.goto.offset.begin", "Begin" },
{ "hex.view.hexeditor.goto.offset.end", "End" },

View File

@ -179,6 +179,7 @@ namespace hex::plugin::builtin {
{ "hex.view.hexeditor.search.find_next", "Cerca il prossimo" },
{ "hex.view.hexeditor.search.find_prev", "Cerca il precedente" },
{ "hex.view.hexeditor.menu.file.goto", "Vai a" },
{ "hex.view.hexeditor.goto.offset.absolute", "Assoluto" },
{ "hex.view.hexeditor.goto.offset.current", "Corrente" },
{ "hex.view.hexeditor.goto.offset.begin", "Inizo" },
{ "hex.view.hexeditor.goto.offset.end", "Fine" },

View File

@ -135,12 +135,12 @@ namespace hex {
EventManager::subscribe<RequestSelectionChange>(this, [this](Region region) {
auto provider = SharedData::currentProvider;
auto page = provider->getPageOfAddress(region.address);
auto page = provider->getPageOfAddress(region.address - provider->getBaseAddress());
if (!page.has_value())
return;
provider->setCurrentPage(page.value());
u64 start = region.address + provider->getBaseAddress();
u64 start = region.address - provider->getBaseAddress();
this->m_memoryEditor.GotoAddrAndHighlight(start, start + region.size - 1);
EventManager::post<EventRegionSelected>(region);
});
@ -1093,58 +1093,61 @@ R"(
void ViewHexEditor::drawGotoPopup() {
auto provider = SharedData::currentProvider;
auto baseAddress = provider->getBaseAddress();
auto dataSize = provider->getActualSize();
if (ImGui::BeginPopup("hex.view.hexeditor.menu.file.goto"_lang)) {
ImGui::TextUnformatted("hex.view.hexeditor.menu.file.goto"_lang);
if (ImGui::BeginTabBar("gotoTabs")) {
s64 newOffset = 0;
if (ImGui::BeginTabItem("hex.view.hexeditor.goto.offset.begin"_lang)) {
ImGui::InputScalar("##nolabel", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
u64 newOffset = 0;
if (ImGui::BeginTabItem("hex.view.hexeditor.goto.offset.absolute"_lang)) {
ImGui::InputScalar("hex", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
if (this->m_gotoAddress >= provider->getActualSize())
this->m_gotoAddress = provider->getActualSize() - 1;
if (this->m_gotoAddress < baseAddress || this->m_gotoAddress > baseAddress + dataSize)
this->m_gotoAddress = baseAddress;
newOffset = this->m_gotoAddress;
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("hex.view.hexeditor.goto.offset.begin"_lang)) {
ImGui::InputScalar("hex", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
if (this->m_gotoAddress < 0 || this->m_gotoAddress > dataSize)
this->m_gotoAddress = 0;
newOffset = this->m_gotoAddress + baseAddress;
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("hex.view.hexeditor.goto.offset.current"_lang)) {
ImGui::InputScalar("##nolabel", ImGuiDataType_S64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
ImGui::InputScalar("dec", ImGuiDataType_S64, &this->m_gotoAddress, nullptr, nullptr, "%lld", ImGuiInputTextFlags_CharsDecimal);
if (this->m_memoryEditor.DataPreviewAddr == -1 || this->m_memoryEditor.DataPreviewAddrEnd == -1) {
this->m_memoryEditor.DataPreviewAddr = 0;
this->m_memoryEditor.DataPreviewAddrEnd = 0;
}
s64 currSelectionOffset = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
s64 currHighlightStart = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
if (currSelectionOffset + this->m_gotoAddress < 0)
this->m_gotoAddress = -currSelectionOffset;
else if (currSelectionOffset + this->m_gotoAddress > dataSize)
this->m_gotoAddress = dataSize - currSelectionOffset;
newOffset = this->m_gotoAddress + currHighlightStart;
if (newOffset >= provider->getActualSize()) {
newOffset = provider->getActualSize() - 1;
this->m_gotoAddress = (provider->getActualSize() - 1) - currHighlightStart;
} else if (newOffset < 0) {
newOffset = 0;
this->m_gotoAddress = -currHighlightStart;
}
newOffset = currSelectionOffset + this->m_gotoAddress + baseAddress;
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("hex.view.hexeditor.goto.offset.end"_lang)) {
ImGui::InputScalar("##nolabel", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
ImGui::InputScalar("hex", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
if (this->m_gotoAddress >= provider->getActualSize())
this->m_gotoAddress = provider->getActualSize() - 1;
if (this->m_gotoAddress < 0 || this->m_gotoAddress > dataSize)
this->m_gotoAddress = 0;
newOffset = (provider->getActualSize() - 1) - this->m_gotoAddress;
newOffset = (baseAddress + dataSize) - this->m_gotoAddress - 1;
ImGui::EndTabItem();
}
if (ImGui::Button("hex.view.hexeditor.menu.file.goto"_lang)) {
provider->setCurrentPage(std::floor(newOffset / double(prv::Provider::PageSize)));
this->m_memoryEditor.GotoAddr = newOffset;
this->m_memoryEditor.DataPreviewAddr = newOffset;
this->m_memoryEditor.DataPreviewAddrEnd = newOffset;
provider->setCurrentPage(std::floor(double(newOffset - baseAddress) / prv::Provider::PageSize));
EventManager::post<RequestSelectionChange>(Region { newOffset, 1 });
}
ImGui::EndTabBar();