diff --git a/radare2 b/radare2 index 7ca83c40..3b2b5925 160000 --- a/radare2 +++ b/radare2 @@ -1 +1 @@ -Subproject commit 7ca83c40fac0b047a822ec73634a61547c483d21 +Subproject commit 3b2b592506809d4dcfed7c7cff29dd8fa2c2e9d1 diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index ec71caa0..de51bd33 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -690,12 +690,12 @@ void MainWindow::setCursorAddress(RVA addr) void MainWindow::backButton_clicked() { - core->cmd("s-"); + core->seekPrev(); } void MainWindow::on_actionForward_triggered() { - core->cmd("s+"); + core->seekNext(); } void MainWindow::on_actionCalculator_triggered() diff --git a/src/cutter.cpp b/src/cutter.cpp index e443880e..1f945c4d 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -339,10 +339,8 @@ void CutterCore::renameFunction(QString prev_name, QString new_name) emit functionRenamed(prev_name, new_name); } - void CutterCore::setComment(RVA addr, QString cmt) { - //r_meta_add (core->anal, 'C', addr, 1, cmt.toUtf8()); cmd("CC " + cmt + " @ " + QString::number(addr)); emit commentsChanged(); } @@ -351,7 +349,6 @@ void CutterCore::delComment(ut64 addr) { CORE_LOCK(); r_meta_del(core_->anal, 'C', addr, 1, NULL); - //cmd (QString("CC-@")+addr); } QMap>> CutterCore::getNestedComments() @@ -374,29 +371,35 @@ QMap>> CutterCore::getNestedComments() return ret; } - - void CutterCore::seek(QString addr) { - if (addr.length() > 0) - seek(this->math(addr.toUtf8().constData())); + // Slower than using the API, but the API is not complete + // which means we either have to duplicate code from radare2 + // here, or refactor radare2 API. + CORE_LOCK(); + cmd(QString("s %1").arg(addr)); + emit seekChanged(core_->offset); } void CutterCore::seek(ut64 offset) { - CORE_LOCK(); - r_core_seek(this->core_, offset, true); - emit seekChanged(core_->offset); + seek(QString::number(offset)); } - -RVA CutterCore::getSeekAddr() +void CutterCore::seekPrev() { - return cmd("s").toULongLong(nullptr, 16); + cmd("s-"); } +void CutterCore::seekNext() +{ + cmd("s+"); +} - +RVA CutterCore::getOffset() +{ + return core_->offset; +} bool CutterCore::tryFile(QString path, bool rw) { @@ -513,6 +516,7 @@ void CutterCore::triggerAsmOptionsChanged() void CutterCore::resetDefaultAsmOptions() { + // TODO Merge with Configuration.cpp setConfig("asm.esil", Config()->getAsmESIL()); setConfig("asm.pseudo", Config()->getAsmPseudo()); setConfig("asm.offset", Config()->getAsmOffset()); diff --git a/src/cutter.h b/src/cutter.h index a06f90e5..deffc6d5 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -209,9 +209,13 @@ public: bool loadFile(QString path, uint64_t loadaddr = 0LL, uint64_t mapaddr = 0LL, bool rw = false, int va = 0, int idx = 0, bool loadbin = false, const QString &forceBinPlugin = nullptr); bool tryFile(QString path, bool rw); void analyze(int level, QList advanced); + + // Seek functions void seek(QString addr); void seek(ut64 offset); - RVA getSeekAddr(); + void seekPrev(); + void seekNext(); + RVA getOffset(); ut64 math(const QString &expr); QString itoa(ut64 num, int rdx = 16); diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index ebc82403..6d0024bb 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -9,6 +9,7 @@ #include #include #include +#include "dialogs/XrefsDialog.h" #include "utils/Configuration.h" #include "utils/Colors.h" @@ -1668,6 +1669,14 @@ void DisassemblerGraphView::addReferenceAction(QMenu* menu, duint addr) void DisassemblerGraphView::setupContextMenu() { + // TODO make this prettier + QShortcut *shortcut_x = new QShortcut(QKeySequence(Qt::Key_X), this); + shortcut_x->setContext(Qt::WidgetShortcut); + connect(shortcut_x, SIGNAL(activated()), this, SLOT(xrefSlot())); + + QShortcut *shortcut_escape = new QShortcut(QKeySequence(Qt::Key_Escape), this); + shortcut_escape->setContext(Qt::WidgetShortcut); + connect(shortcut_escape, SIGNAL(activated()), this, SLOT(seekPrev())); /* mMenuBuilder = new MenuBuilder(this, [](QMenu*) { @@ -2015,22 +2024,10 @@ restart: void DisassemblerGraphView::xrefSlot() { - /* - if(!DbgIsDebugging()) - return; - duint wVA = this->get_cursor_pos(); - if(!DbgMemIsValidReadPtr(wVA)) - return; - XREF_INFO mXrefInfo; - DbgXrefGet(wVA, &mXrefInfo); - if(!mXrefInfo.refcount) - return; - BridgeFree(mXrefInfo.references); - if(!mXrefDlg) - mXrefDlg = new XrefBrowseDialog(this); - mXrefDlg->setup(wVA, "graph"); - mXrefDlg->showNormal(); - */ + RVA addr = highlight_token->addr; + XrefsDialog *dialog = new XrefsDialog(this); + dialog->fillRefsForAddress(addr, RAddressString(addr), false); + dialog->exec(); } void DisassemblerGraphView::decompileSlot() @@ -2072,3 +2069,8 @@ void DisassemblerGraphView::followActionSlot() } */ } + +void DisassemblerGraphView::seekPrev() +{ + Core()->seekPrev(); +} diff --git a/src/widgets/DisassemblerGraphView.h b/src/widgets/DisassemblerGraphView.h index e63c7c86..91c5f21f 100644 --- a/src/widgets/DisassemblerGraphView.h +++ b/src/widgets/DisassemblerGraphView.h @@ -285,6 +285,8 @@ public slots: void xrefSlot(); void decompileSlot(); + void seekPrev(); + private: MainWindow* main; QString status; diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index 4209021a..e8673385 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -3,9 +3,8 @@ #include "dialogs/XrefsDialog.h" #include "utils/HexAsciiHighlighter.h" #include "utils/HexHighlighter.h" -#include -#include #include "utils/Configuration.h" +#include DisassemblyWidget::DisassemblyWidget(QWidget *parent) : QDockWidget(parent), @@ -17,6 +16,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent) : setObjectName("DisassemblyWidget"); mDisasTextEdit->setFont(Config()->getFont()); + mDisasTextEdit->setReadOnly(true); // Increase asm text edit margin QTextDocument *asm_docu = mDisasTextEdit->document(); @@ -35,35 +35,12 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent) : this, SLOT(showDisasContextMenu(const QPoint &))); // x or X to show XRefs - connect(new QShortcut(QKeySequence(Qt::Key_X), mDisasTextEdit), - SIGNAL(activated()), this, SLOT(showXrefsDialog())); - connect(new QShortcut(Qt::SHIFT + Qt::Key_X, mDisasTextEdit), - SIGNAL(activated()), this, SLOT(showXrefsDialog())); + QShortcut *shortcut_x = new QShortcut(QKeySequence(Qt::Key_X), mDisasTextEdit); + shortcut_x->setContext(Qt::WidgetShortcut); + connect(shortcut_x, SIGNAL(activated()), this, SLOT(showXrefsDialog())); // Scrollbar connect(mDisasTextEdit->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(disasmScrolled())); - - // TODO Shortcuts - // Semicolon to add comment - //QShortcut *comment_shortcut = new QShortcut(QKeySequence(Qt::Key_Semicolon), mDisasTextEdit); - //connect(comment_shortcut, SIGNAL(activated()), this, SLOT(on_actionDisasAdd_comment_triggered())); - //comment_shortcut->setContext(Qt::WidgetShortcut); - - // N to rename function - //QShortcut *rename_shortcut = new QShortcut(QKeySequence(Qt::Key_N), mDisasTextEdit); - //connect(rename_shortcut, SIGNAL(activated()), this, SLOT(on_actionFunctionsRename_triggered())); - //rename_shortcut->setContext(Qt::WidgetShortcut); - - // Esc to seek back - //QShortcut *back_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), mDisasTextEdit); - //connect(back_shortcut, SIGNAL(activated()), this, SLOT(seek_back())); - //back_shortcut->setContext(Qt::WidgetShortcut); - - // CTRL + R to refresh the disasm - //QShortcut *refresh_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_R), mDisasTextEdit); - //connect(refresh_shortcut, SIGNAL(activated()), this, SLOT(refreshDisasm())); - //refresh_shortcut->setContext(Qt::WidgetShortcut); - // Seek signal connect(CutterCore::getInstance(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot())); @@ -74,6 +51,7 @@ DisassemblyWidget::DisassemblyWidget(const QString &title, QWidget *parent) : { this->setWindowTitle(title); } + void DisassemblyWidget::highlightCurrentLine() { QList extraSelections; @@ -139,22 +117,6 @@ void DisassemblyWidget::showDisasContextMenu(const QPoint &pt) menu.exec(mDisasTextEdit->mapToGlobal(pt)); } -void DisassemblyWidget::showXrefsDialog() -{ - // Get current offset - QTextCursor tc = mDisasTextEdit->textCursor(); - tc.select(QTextCursor::LineUnderCursor); - QString lastline = tc.selectedText(); - QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; - if (ele.contains("0x")) - { - RVA addr = ele.toLongLong(0, 16); - XrefsDialog *dialog = new XrefsDialog(this); - dialog->fillRefsForAddress(addr, RAddressString(addr), false); - dialog->exec(); - } -} - RVA DisassemblyWidget::readCurrentDisassemblyOffset() { // TODO: do this in a different way without parsing the disassembly text @@ -414,3 +376,19 @@ void DisassemblyWidget::fontsUpdatedSlot() mDisasTextEdit->setFont(Config()->getFont()); refreshDisasm(); } + +void DisassemblyWidget::showXrefsDialog() +{ + // Get current offset + QTextCursor tc = mDisasTextEdit->textCursor(); + tc.select(QTextCursor::LineUnderCursor); + QString lastline = tc.selectedText(); + QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; + if (ele.contains("0x")) + { + RVA addr = ele.toLongLong(0, 16); + XrefsDialog *dialog = new XrefsDialog(this); + dialog->fillRefsForAddress(addr, RAddressString(addr), false); + dialog->exec(); + } +} diff --git a/src/widgets/DisassemblyWidget.h b/src/widgets/DisassemblyWidget.h index 4b94524b..cd2678d1 100644 --- a/src/widgets/DisassemblyWidget.h +++ b/src/widgets/DisassemblyWidget.h @@ -4,6 +4,7 @@ #include "cutter.h" #include #include +#include class DisassemblyWidget : public QDockWidget { @@ -18,11 +19,11 @@ public slots: void highlightCurrentLine(); void disasmScrolled(); void showDisasContextMenu(const QPoint &pt); - void showXrefsDialog(); void on_mDisasTextEdit_cursorPositionChanged(); void on_seekChanged(RVA offset); void refreshDisasm(); void fontsUpdatedSlot(); + void showXrefsDialog(); private: QTextEdit *mDisasTextEdit; diff --git a/src/widgets/HexdumpWidget.cpp b/src/widgets/HexdumpWidget.cpp index b9972d93..220648c5 100644 --- a/src/widgets/HexdumpWidget.cpp +++ b/src/widgets/HexdumpWidget.cpp @@ -164,7 +164,7 @@ void HexdumpWidget::refresh(RVA addr) { if (addr == RVA_INVALID) { - addr = core->getSeekAddr(); + addr = core->getOffset(); } RCoreLocked lcore = this->core->core(); diff --git a/src/widgets/PreviewWidget.cpp b/src/widgets/PreviewWidget.cpp index 72417266..871051be 100644 --- a/src/widgets/PreviewWidget.cpp +++ b/src/widgets/PreviewWidget.cpp @@ -88,7 +88,7 @@ void PreviewWidget::refresh(RVA addr) { if (addr == RVA_INVALID) { - addr = core->getSeekAddr(); + addr = core->getOffset(); } // TODO: pseudo, ... diff --git a/src/widgets/SidebarWidget.cpp b/src/widgets/SidebarWidget.cpp index 7dd44dc8..1fc4d1b8 100644 --- a/src/widgets/SidebarWidget.cpp +++ b/src/widgets/SidebarWidget.cpp @@ -54,7 +54,7 @@ void SidebarWidget::on_seekChanged(RVA addr) void SidebarWidget::refresh(RVA addr) { if(addr == RVA_INVALID) - addr = core->getSeekAddr(); + addr = core->getOffset(); get_refs_data(addr); setFcnName(addr);