From 66cb2fa84df35f02c4aa69513bec91d3ff4a0933 Mon Sep 17 00:00:00 2001 From: hasherezade Date: Wed, 3 Jun 2026 06:23:25 -0800 Subject: [PATCH] [FEATURE] Added following various types of addresses from the HexDump --- bearparser | 2 +- pe-bear/HexView.cpp | 60 +++++++++++++++++++++++++++++++++------------ pe-bear/HexView.h | 12 ++++++--- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/bearparser b/bearparser index 9221510..c18e939 160000 --- a/bearparser +++ b/bearparser @@ -1 +1 @@ -Subproject commit 9221510838a07bdcdebe47920bbc4c71a574daf5 +Subproject commit c18e939d7ee83c1988b1d3b0c442092eed280bb1 diff --git a/pe-bear/HexView.cpp b/pe-bear/HexView.cpp index a4c522d..7aa592e 100644 --- a/pe-bear/HexView.cpp +++ b/pe-bear/HexView.cpp @@ -249,9 +249,20 @@ void HexTableView::initMenu() undoAction->setShortcut(Qt::CTRL | Qt::Key_Z); connect(undoAction, SIGNAL(triggered()), this, SLOT(undoLastModification())); - followAction = new QAction(tr("Follow selected VA"), menu); - menu->addAction(followAction); - connect(followAction, SIGNAL(triggered()), this, SLOT(followSelected())); + followAddrSubmenu = menu->addMenu(tr("Follow selected address")); + + followAction[Executable::RAW] = new QAction(tr("Raw"), menu); + followAddrSubmenu->addAction(followAction[Executable::RAW]); + connect(followAction[Executable::RAW], SIGNAL(triggered()), this, SLOT(followSelectedRaw())); + + followAction[Executable::RVA] = new QAction(tr("RVA"), menu); + followAddrSubmenu->addAction(followAction[Executable::RVA]); + connect(followAction[Executable::RVA], SIGNAL(triggered()), this, SLOT(followSelectedRva())); + + followAction[Executable::VA] = new QAction(tr("VA"), menu); + followAddrSubmenu->addAction(followAction[Executable::VA]); + connect(followAction[Executable::VA], SIGNAL(triggered()), this, SLOT(followSelectedVa())); + connect(menu, &QMenu::aboutToShow, this, &HexTableView::updateFollowAction); } @@ -298,19 +309,38 @@ void HexTableView::onDataSet(int col, int row) void HexTableView::updateFollowAction() { - bool isEnabled = false; - if (this->hexModel && hexModel->myPeHndl) { - PeHandler* hndl = hexModel->myPeHndl; - offset_t addr = getSelectedAddress(); - if (hndl->isValidAddr(Executable::VA, addr)) { - isEnabled = true; - followAction->setText("Follow: 0x" + QString::number(addr, 16)); + const QString defaultDesc = tr("Follow selected address"); + + PeHandler* hndl = hexModel->myPeHndl; + const offset_t addr = getSelectedAddress(); + + if (!hndl || addr == INVALID_ADDR) { + this->followAddrSubmenu->setTitle(defaultDesc); + followAddrSubmenu->setEnabled(false); + return; + } + + bool isMenuEnabled = false; + + for (int t = 0; t < Executable::ADDR_TYPE_COUNT; ++t) { + const Executable::addr_type aType = static_cast(t); + bool _isVisible = false; + if (hndl->isValidAddr(aType, addr)) { + isMenuEnabled = true; + _isVisible = true; + } + if (followAction[aType]) { + followAction[aType]->setVisible(_isVisible); } } - if (!isEnabled) { - followAction->setText("Follow selected VA"); + + followAddrSubmenu->setEnabled(isMenuEnabled); + + if (!isMenuEnabled) { + this->followAddrSubmenu->setTitle(defaultDesc); + return; } - followAction->setEnabled(isEnabled); + followAddrSubmenu->setTitle("Follow: 0x" + QString::number(addr, 16)); } offset_t HexTableView::getSelectedAddress() @@ -333,7 +363,7 @@ offset_t HexTableView::getSelectedAddress() return static_cast(number); } -void HexTableView::followSelected() +void HexTableView::followSelected(const Executable::addr_type& aType) { if (!this->hexModel) return; @@ -341,7 +371,7 @@ void HexTableView::followSelected() if (!hndl) return; const offset_t addr = getSelectedAddress(); - hndl->setDisplayed(Executable::VA, addr); + hndl->setDisplayed(aType, addr); } void HexTableView::copySelected() diff --git a/pe-bear/HexView.h b/pe-bear/HexView.h index cdec862..7f5995f 100644 --- a/pe-bear/HexView.h +++ b/pe-bear/HexView.h @@ -69,8 +69,10 @@ public slots: virtual void pasteToSelected(); virtual void clearSelected(); virtual void fillSelected(); - virtual void followSelected(); - offset_t getSelectedAddress(); + + virtual void followSelectedVa() { return followSelected(Executable::VA); } + virtual void followSelectedRva() { return followSelected(Executable::RVA); } + virtual void followSelectedRaw() { return followSelected(Executable::RAW); } void updateFollowAction(); @@ -84,6 +86,8 @@ public slots: void onResetRequested() { reset(); } protected: + offset_t getSelectedAddress(); + void followSelected(const Executable::addr_type& type); bool isIndexListContinuous(QModelIndexList &list); inline void adjustMinWidth(); @@ -95,7 +99,9 @@ protected: void initMenu(); void setSelectionColor(const QColor& color); - QAction *backAction, *undoAction, *followAction; + QMenu* followAddrSubmenu; + QAction* followAction[Executable::ADDR_TYPE_COUNT] = { nullptr }; + QAction *backAction, *undoAction; OffsetHeader* vHdr; QHeaderView *hHdr;