From 7353c57278b4715e4ce303a88d8d5f8e59e356ee Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Wed, 3 Dec 2014 10:48:32 +0100 Subject: [PATCH] GUI: added Goto -> File offset --- .../Project/Src/Gui/CPUDisassembly.cpp | 28 +++++++++++++++++++ x64_dbg_gui/Project/Src/Gui/CPUDisassembly.h | 2 ++ x64_dbg_gui/Project/Src/Gui/CPUDump.cpp | 26 +++++++++++++++++ x64_dbg_gui/Project/Src/Gui/CPUDump.h | 2 ++ x64_dbg_gui/Project/Src/Gui/GotoDialog.cpp | 19 +++++++++++++ x64_dbg_gui/Project/Src/Gui/GotoDialog.h | 2 ++ 6 files changed, 79 insertions(+) diff --git a/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp b/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp index d8e08ba3..f9caea27 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp +++ b/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.cpp @@ -262,6 +262,9 @@ void CPUDisassembly::contextMenuEvent(QContextMenuEvent* event) if(historyHasNext()) mGotoMenu->addAction(mGotoNext); mGotoMenu->addAction(mGotoExpression); + char modname[MAX_MODULE_SIZE] = ""; + if(DbgGetModuleAt(wVA, modname)) + mGotoMenu->addAction(mGotoFileOffset); wMenu->addMenu(mGotoMenu); wMenu->addSeparator(); @@ -436,6 +439,10 @@ void CPUDisassembly::setupRightClickContextMenu() this->addAction(mGotoExpression); connect(mGotoExpression, SIGNAL(triggered()), this, SLOT(gotoExpression())); + // File offset action + mGotoFileOffset = new QAction("File Offset", this); + connect(mGotoFileOffset, SIGNAL(triggered()), this, SLOT(gotoFileOffset())); + //-------------------- Follow in Dump ---------------------------- // Menu mFollowMenu = new QMenu("&Follow in Dump", this); @@ -889,6 +896,27 @@ void CPUDisassembly::gotoExpression() } } +void CPUDisassembly::gotoFileOffset() +{ + if(!DbgIsDebugging()) + return; + char modname[MAX_MODULE_SIZE] = ""; + if(!DbgFunctions()->ModNameFromAddr(rvaToVa(getInitialSelection()), modname, true)) + { + QMessageBox::critical(this, "Error!", "Not inside a module..."); + return; + } + GotoDialog mGotoDialog(this); + mGotoDialog.fileOffset = true; + mGotoDialog.modName = QString(modname); + mGotoDialog.setWindowTitle("Goto File Offset in " + QString(modname)); + if(mGotoDialog.exec() != QDialog::Accepted) + return; + uint_t value = DbgValFromString(mGotoDialog.expressionText.toUtf8().constData()); + value = DbgFunctions()->FileOffsetToVa(modname, value); + DbgCmdExec(QString().sprintf("disasm \"%p\"", value).toUtf8().constData()); +} + void CPUDisassembly::followActionSlot() { QAction* action = qobject_cast(sender()); diff --git a/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.h b/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.h index 88cfe5e2..f29e486e 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.h +++ b/x64_dbg_gui/Project/Src/Gui/CPUDisassembly.h @@ -43,6 +43,7 @@ public slots: void toggleFunction(); void assembleAt(); void gotoExpression(); + void gotoFileOffset(); void followActionSlot(); void gotoPrevious(); void gotoNext(); @@ -102,6 +103,7 @@ private: QAction* msetHwBPOnSlot2Action; QAction* msetHwBPOnSlot3Action; QAction* mGotoExpression; + QAction* mGotoFileOffset; QAction* mGotoPrevious; QAction* mGotoNext; QAction* mReferenceSelectedAddress; diff --git a/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp b/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp index 7fc916d5..67021765 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp +++ b/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp @@ -246,6 +246,11 @@ void CPUDump::setupContextMenu() connect(mGotoExpression, SIGNAL(triggered()), this, SLOT(gotoExpressionSlot())); mGotoMenu->addAction(mGotoExpression); + // Goto->File offset + mGotoFileOffset = new QAction("File Offset", this); + connect(mGotoFileOffset, SIGNAL(triggered()), this, SLOT(gotoFileOffsetSlot())); + mGotoMenu->addAction(mGotoFileOffset); + //Hex menu mHexMenu = new QMenu("&Hex", this); //Hex->Ascii @@ -559,6 +564,27 @@ void CPUDump::gotoExpressionSlot() } } +void CPUDump::gotoFileOffsetSlot() +{ + if(!DbgIsDebugging()) + return; + char modname[MAX_MODULE_SIZE] = ""; + if(!DbgFunctions()->ModNameFromAddr(rvaToVa(getInitialSelection()), modname, true)) + { + QMessageBox::critical(this, "Error!", "Not inside a module..."); + return; + } + GotoDialog mGotoDialog(this); + mGotoDialog.fileOffset = true; + mGotoDialog.modName = QString(modname); + mGotoDialog.setWindowTitle("Goto File Offset in " + QString(modname)); + if(mGotoDialog.exec() != QDialog::Accepted) + return; + uint_t value = DbgValFromString(mGotoDialog.expressionText.toUtf8().constData()); + value = DbgFunctions()->FileOffsetToVa(modname, value); + DbgCmdExec(QString().sprintf("dump \"%p\"", value).toUtf8().constData()); +} + void CPUDump::hexAsciiSlot() { Config()->setUint("HexDump", "DefaultView", (uint_t)ViewHexAscii); diff --git a/x64_dbg_gui/Project/Src/Gui/CPUDump.h b/x64_dbg_gui/Project/Src/Gui/CPUDump.h index 8eeb0d70..4c315d95 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUDump.h +++ b/x64_dbg_gui/Project/Src/Gui/CPUDump.h @@ -39,6 +39,7 @@ public slots: void setLabelSlot(); void gotoExpressionSlot(); + void gotoFileOffsetSlot(); void hexAsciiSlot(); void hexUnicodeSlot(); @@ -110,6 +111,7 @@ private: QMenu* mGotoMenu; QAction* mGotoExpression; + QAction* mGotoFileOffset; QMenu* mHexMenu; QAction* mHexAsciiAction; diff --git a/x64_dbg_gui/Project/Src/Gui/GotoDialog.cpp b/x64_dbg_gui/Project/Src/Gui/GotoDialog.cpp index 57181ef8..152f8b83 100644 --- a/x64_dbg_gui/Project/Src/Gui/GotoDialog.cpp +++ b/x64_dbg_gui/Project/Src/Gui/GotoDialog.cpp @@ -19,6 +19,7 @@ GotoDialog::GotoDialog(QWidget* parent) : QDialog(parent), ui(new Ui::GotoDialog ui->editExpression->setFocus(); validRangeStart = 0; validRangeEnd = 0; + fileOffset = false; mValidateThread = new GotoDialogValidateThread(this); connect(this, SIGNAL(finished(int)), this, SLOT(finishedSlot(int))); } @@ -57,6 +58,24 @@ void GotoDialog::validateExpression() ui->buttonOk->setEnabled(false); expressionText.clear(); } + else if(fileOffset) + { + uint_t offset = DbgValFromString(expression.toUtf8().constData()); + uint_t va = DbgFunctions()->FileOffsetToVa(modName.toUtf8().constData(), offset); + if(va) + { + QString addrText = QString("%1").arg(va, sizeof(int_t) * 2, 16, QChar('0')).toUpper(); + ui->labelError->setText(QString("Correct expression! -> " + addrText)); + ui->buttonOk->setEnabled(true); + expressionText = expression; + } + else + { + ui->labelError->setText("Invalid file offset..."); + ui->buttonOk->setEnabled(false); + expressionText.clear(); + } + } else { uint_t addr = DbgValFromString(expression.toUtf8().constData()); diff --git a/x64_dbg_gui/Project/Src/Gui/GotoDialog.h b/x64_dbg_gui/Project/Src/Gui/GotoDialog.h index 83974c91..8362d13a 100644 --- a/x64_dbg_gui/Project/Src/Gui/GotoDialog.h +++ b/x64_dbg_gui/Project/Src/Gui/GotoDialog.h @@ -20,6 +20,8 @@ public: QString expressionText; uint_t validRangeStart; uint_t validRangeEnd; + bool fileOffset; + QString modName; void showEvent(QShowEvent* event); void hideEvent(QHideEvent* event); void validateExpression();