Skip to content

Commit

Permalink
Move the toggle immediate base handling to DisassemblyWidget.cpp
Browse files Browse the repository at this point in the history
(Removes the entry from the context menu)
  • Loading branch information
plaets committed Sep 23, 2020
1 parent 84049e8 commit 1473d2f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
20 changes: 0 additions & 20 deletions src/menus/DisassemblyContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main

addSetBaseMenu();

initAction(&actionToggleBase, tr("Toggle Immediate Base (Hex/Dec)"),
SLOT(on_actionToggleBase_triggered()), getToggleBaseSequence());
addAction(&actionToggleBase);

addSetBitsMenu();

structureOffsetMenu = addMenu(tr("Structure offset"));
Expand Down Expand Up @@ -678,11 +674,6 @@ QKeySequence DisassemblyContextMenu::getUndefineFunctionSequence() const
return {Qt::Key_U};
}

QKeySequence DisassemblyContextMenu::getToggleBaseSequence() const
{
return {Qt::Key_H};
}


void DisassemblyContextMenu::on_actionEditInstruction_triggered()
{
Expand Down Expand Up @@ -812,17 +803,6 @@ void DisassemblyContextMenu::on_actionAnalyzeFunction_triggered()
}
}

// TODO: requires the user to trigger the action twice if the number is in decimals
void DisassemblyContextMenu::on_actionToggleBase_triggered()
{
int base = Core()->getImmediateBase(offset);
if (base == 10) {
setBase("h");
} else {
setBase("d");
}
}

void DisassemblyContextMenu::on_actionAddFlag_triggered()
{
FlagDialog dialog(offset, this->parentWidget());
Expand Down
4 changes: 0 additions & 4 deletions src/menus/DisassemblyContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ private slots:
void on_actionSetToData_triggered();
void on_actionSetToDataEx_triggered();

void on_actionToggleBase_triggered();

/**
* @brief Executed on selecting an offset from the structureOffsetMenu
* Uses the applyStructureOffset() function of CutterCore to apply the
Expand Down Expand Up @@ -103,7 +101,6 @@ private slots:
QKeySequence getDefineNewFunctionSequence() const;
QKeySequence getUndefineFunctionSequence() const;
QKeySequence getEditFunctionSequence() const;
QKeySequence getToggleBaseSequence() const;
QList<QKeySequence> getAddBPSequence() const;

/**
Expand Down Expand Up @@ -159,7 +156,6 @@ private slots:
QAction actionSetBaseIPAddr;
QAction actionSetBaseSyscall;
QAction actionSetBaseString;
QAction actionToggleBase;

QMenu *setBitsMenu;
QAction actionSetBits16;
Expand Down
23 changes: 23 additions & 0 deletions src/widgets/DisassemblyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main)
ADD_ACTION(QKeySequence::MoveToPreviousPage, Qt::WidgetWithChildrenShortcut, [this]() {
moveCursorRelative(true, true);
})

ADD_ACTION(Qt::Key_H, Qt::WidgetWithChildrenShortcut, [this]() {
toggleBase();
})
#undef ADD_ACTION
}

Expand Down Expand Up @@ -623,6 +627,25 @@ void DisassemblyWidget::jumpToOffsetUnderCursor(const QTextCursor &cursor)
seekable->seekToReference(offset);
}

// TODO: requires the user to trigger the action twice if the number is in decimals
void DisassemblyWidget::toggleBase()
{
RVA offset = readCurrentDisassemblyOffset();
QJsonObject instObject = Core()->cmdj("aoj @ " + QString::number(
offset)).array().first().toObject();
auto keys = instObject.keys();
bool immBase = keys.contains("val") || keys.contains("ptr");

if(immBase) {
int base = Core()->getImmediateBase(offset);
if (base == 10) {
Core()->setImmediateBase("h", offset);
} else {
Core()->setImmediateBase("d", offset);
}
}
}

bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonDblClick
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/DisassemblyWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ protected slots:
void moveCursorRelative(bool up, bool page);

void jumpToOffsetUnderCursor(const QTextCursor&);

void toggleBase();
};

class DisassemblyScrollArea : public QAbstractScrollArea
Expand Down

0 comments on commit 1473d2f

Please sign in to comment.