Implement Seek to start/end of function Shortcuts (#1589)

* fix ctrl+'+' to zoom in`

* Add '^' and '$' shortcuts
This commit is contained in:
Itay Cohen 2019-05-30 11:41:14 +03:00 committed by GitHub
parent 53756f29d2
commit c141eb34cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 1 deletions

View File

@ -826,6 +826,47 @@ RAnalFunction *CutterCore::functionAt(ut64 addr)
return r_anal_get_fcn_in(core_->anal, addr, 0);
}
/**
* @brief finds the start address of a function in a given address
* @param addr - an address which belongs to a function
* @returns if function exists, return its start address. Otherwise return RVA_INVALID
*/
RVA CutterCore::getFunctionStart(RVA addr)
{
CORE_LOCK();
RAnalFunction *fcn = Core()->functionAt(addr);
return fcn ? fcn->addr : RVA_INVALID;
}
/**
* @brief finds the end address of a function in a given address
* @param addr - an address which belongs to a function
* @returns if function exists, return its end address. Otherwise return RVA_INVALID
*/
RVA CutterCore::getFunctionEnd(RVA addr)
{
CORE_LOCK();
RAnalFunction *fcn = Core()->functionAt(addr);
return fcn ? fcn->addr : RVA_INVALID;
}
/**
* @brief finds the last instruction of a function in a given address
* @param addr - an address which belongs to a function
* @returns if function exists, return the address of its last instruction. Otherwise return RVA_INVALID
*/
RVA CutterCore::getLastFunctionInstruction(RVA addr)
{
CORE_LOCK();
RAnalFunction *fcn = Core()->functionAt(addr);
if (!fcn) {
return RVA_INVALID;
}
RAnalBlock *lastBB = (RAnalBlock *)r_list_last(fcn->bbs);
return lastBB ? lastBB->addr + r_anal_bb_offset_inst(lastBB, lastBB->ninstr-1) : RVA_INVALID;
}
QString CutterCore::cmdFunctionAt(QString addr)
{
QString ret;

View File

@ -77,6 +77,9 @@ public:
void delFunction(RVA addr);
void renameFlag(QString old_name, QString new_name);
RAnalFunction *functionAt(ut64 addr);
RVA getFunctionStart(RVA addr);
RVA getFunctionEnd(RVA addr);
RVA getLastFunctionInstruction(RVA addr);
QString cmdFunctionAt(QString addr);
QString cmdFunctionAt(RVA addr);
QString createFunctionAt(RVA addr, QString name);

View File

@ -140,6 +140,10 @@ void MainWindow::initUI()
connect(goto_shortcut, SIGNAL(activated()), this->omnibar, SLOT(setFocus()));
QShortcut *seek_shortcut = new QShortcut(QKeySequence(Qt::Key_S), this);
connect(seek_shortcut, SIGNAL(activated()), this->omnibar, SLOT(setFocus()));
QShortcut *seek_to_func_end_shortcut = new QShortcut(QKeySequence(Qt::Key_Dollar), this);
connect(seek_to_func_end_shortcut, SIGNAL(activated()), SLOT(seekToFunctionLastInstruction()));
QShortcut *seek_to_func_start_shortcut = new QShortcut(QKeySequence(Qt::Key_AsciiCircum), this);
connect(seek_to_func_start_shortcut, SIGNAL(activated()), SLOT(seekToFunctionStart()));
QShortcut *refresh_shortcut = new QShortcut(QKeySequence(QKeySequence::Refresh), this);
connect(refresh_shortcut, SIGNAL(activated()), this, SLOT(refreshAll()));
@ -1141,6 +1145,15 @@ void MainWindow::on_actionGrouped_dock_dragging_triggered(bool checked)
setDockOptions(options);
}
void MainWindow::seekToFunctionLastInstruction()
{
Core()->seek(Core()->getLastFunctionInstruction(Core()->getOffset()));
}
void MainWindow::seekToFunctionStart()
{
Core()->seek(Core()->getFunctionStart(Core()->getOffset()));
}
void MainWindow::projectSaved(bool successfully, const QString &name)
{

View File

@ -115,7 +115,8 @@ public slots:
void finalizeOpen();
void refreshAll();
void seekToFunctionLastInstruction();
void seekToFunctionStart();
void setPanelLock();
void setTabLocation();

View File

@ -182,7 +182,11 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action)
ADD_ACTION(QKeySequence::MoveToPreviousPage, Qt::WidgetWithChildrenShortcut, [this]() {
moveCursorRelative(true, true);
})
// Plus sign in num-bar considered "Qt::Key_Equal"
ADD_ACTION(QKeySequence(Qt::CTRL + Qt::Key_Equal), Qt::WidgetWithChildrenShortcut, &DisassemblyWidget::zoomIn)
// Plus sign in numpad
ADD_ACTION(QKeySequence(Qt::CTRL + Qt::Key_Plus), Qt::WidgetWithChildrenShortcut, &DisassemblyWidget::zoomIn)
ADD_ACTION(QKeySequence(Qt::CTRL + Qt::Key_Minus), Qt::WidgetWithChildrenShortcut, &DisassemblyWidget::zoomOut)
#undef ADD_ACTION
}