Fix Disassembly double click, Fix #112

This commit is contained in:
Florian Märkl 2017-11-28 12:56:38 +01:00
parent 816cc6151f
commit 871b930519
4 changed files with 35 additions and 28 deletions

View File

@ -716,10 +716,17 @@ QString CutterCore::getOffsetInfo(QString addr)
return cmd("ao @ " + addr);
}
QString CutterCore::getOffsetJump(QString addr)
RVA CutterCore::getOffsetJump(RVA addr)
{
QString ret = cmd("ao @" + addr + "~jump[1]");
return ret;
bool ok;
RVA value = cmdj("aoj @" + QString::number(addr)).array().first().toObject().value("jump").toVariant().toULongLong(&ok);
if (!ok)
{
return RVA_INVALID;
}
return value;
}
QString CutterCore::getDecompiledCode(QString addr)

View File

@ -258,7 +258,7 @@ public:
ulong get_baddr();
QList<QList<QString>> get_exec_sections();
QString getOffsetInfo(QString addr);
QString getOffsetJump(QString addr);
RVA getOffsetJump(RVA addr);
QString getDecompiledCode(QString addr);
QString getFileInfo();
QStringList getStats();

View File

@ -277,13 +277,17 @@ void DisassemblyWidget::showDisasContextMenu(const QPoint &pt)
}
RVA DisassemblyWidget::readCurrentDisassemblyOffset()
{
QTextCursor tc = mDisasTextEdit->textCursor();
return readDisassemblyOffset(tc);
}
RVA DisassemblyWidget::readDisassemblyOffset(QTextCursor tc)
{
// TODO: do this in a different way without parsing the disassembly text
static const QRegularExpression offsetRegExp("^0x[0-9A-Fa-f]*");
QTextCursor tc = mDisasTextEdit->textCursor();
while (true)
{
tc.select(QTextCursor::LineUnderCursor);
@ -385,33 +389,28 @@ bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
if ((obj == mDisasTextEdit || obj == mDisasTextEdit->viewport()) && event->type() == QEvent::MouseButtonDblClick)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
//qDebug()<<QString("Click location: (%1,%2)").arg(mouseEvent->x()).arg(mouseEvent->y());
QTextCursor cursor = mDisasTextEdit->cursorForPosition(QPoint(mouseEvent->x(), mouseEvent->y()));
cursor.select(QTextCursor::LineUnderCursor);
QString lastline = cursor.selectedText();
auto eles = lastline.split(" ", QString::SkipEmptyParts);
QString ele = eles.isEmpty() ? "" : eles[0];
if (ele.contains("0x"))
RVA offset = readDisassemblyOffset(cursor);
RVA jump = Core()->getOffsetJump(offset);
if (jump == RVA_INVALID)
{
QString jump = CutterCore::getInstance()->getOffsetJump(ele);
if (!jump.isEmpty())
bool ok;
RVA xref = Core()->cmdj("axfj@" + QString::number(offset)).array().first().toObject().value("to").toVariant().toULongLong(&ok);
if (ok)
{
if (jump.contains("0x"))
{
QString fcn = CutterCore::getInstance()->cmdFunctionAt(jump);
if (!fcn.isEmpty())
{
RVA addr = jump.trimmed().toULongLong(0, 16);
CutterCore::getInstance()->seek(addr);
}
}
else
{
RVA addr = CutterCore::getInstance()->cmd("?v " + jump).toULongLong(0, 16);
CutterCore::getInstance()->seek(addr);
}
jump = xref;
}
}
if (jump != RVA_INVALID)
{
CutterCore::getInstance()->seek(jump);
}
return true;
}
return QDockWidget::eventFilter(obj, event);
}

View File

@ -47,6 +47,7 @@ private:
QString readDisasm(const QString &cmd, bool stripLastNewline);
RVA readCurrentDisassemblyOffset();
RVA readDisassemblyOffset(QTextCursor tc);
bool eventFilter(QObject *obj, QEvent *event);
void updateCursorPosition();