Shortcuts fixes

This commit is contained in:
xarkes 2017-10-16 21:00:47 +02:00
parent 996ff82d1b
commit 5e2223978d
11 changed files with 73 additions and 82 deletions

@ -1 +1 @@
Subproject commit 7ca83c40fac0b047a822ec73634a61547c483d21
Subproject commit 3b2b592506809d4dcfed7c7cff29dd8fa2c2e9d1

View File

@ -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()

View File

@ -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<QString, QList<QList<QString>>> CutterCore::getNestedComments()
@ -374,29 +371,35 @@ QMap<QString, QList<QList<QString>>> 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());

View File

@ -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<QString> 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);

View File

@ -9,6 +9,7 @@
#include <QMimeData>
#include <QFileDialog>
#include <QMessageBox>
#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();
}

View File

@ -285,6 +285,8 @@ public slots:
void xrefSlot();
void decompileSlot();
void seekPrev();
private:
MainWindow* main;
QString status;

View File

@ -3,9 +3,8 @@
#include "dialogs/XrefsDialog.h"
#include "utils/HexAsciiHighlighter.h"
#include "utils/HexHighlighter.h"
#include <QShortcut>
#include <QScrollBar>
#include "utils/Configuration.h"
#include <QScrollBar>
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<QTextEdit::ExtraSelection> 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();
}
}

View File

@ -4,6 +4,7 @@
#include "cutter.h"
#include <QDockWidget>
#include <QTextEdit>
#include <QShortcut>
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;

View File

@ -164,7 +164,7 @@ void HexdumpWidget::refresh(RVA addr)
{
if (addr == RVA_INVALID)
{
addr = core->getSeekAddr();
addr = core->getOffset();
}
RCoreLocked lcore = this->core->core();

View File

@ -88,7 +88,7 @@ void PreviewWidget::refresh(RVA addr)
{
if (addr == RVA_INVALID)
{
addr = core->getSeekAddr();
addr = core->getOffset();
}
// TODO: pseudo, ...

View File

@ -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);