Set immediate base from right click menu, Fix #17

This commit is contained in:
Florian Märkl 2017-11-28 14:13:22 +01:00
parent 871b930519
commit fad16b4a17
6 changed files with 122 additions and 6 deletions

View File

@ -344,6 +344,17 @@ void CutterCore::delComment(ut64 addr)
emit commentsChanged();
}
void CutterCore::setImmediateBase(const QString &r2BaseName, RVA offset)
{
if (offset == RVA_INVALID)
{
offset = getOffset();
}
this->cmd("ahi " + r2BaseName + " @ " + QString::number(offset));
emit instructionChanged(offset);
}
QMap<QString, QList<QList<QString>>> CutterCore::getNestedComments()
{
QMap<QString, QList<QList<QString>>> ret;

View File

@ -206,6 +206,7 @@ public:
void renameFlag(QString old_name, QString new_name);
void setComment(RVA addr, QString cmt);
void delComment(ut64 addr);
void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
QMap<QString, QList<QList<QString>>> getNestedComments();
void setOptions(QString key);
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);
@ -323,6 +324,7 @@ signals:
void functionRenamed(QString prev_name, QString new_name);
void flagsChanged();
void commentsChanged();
void instructionChanged(RVA offset);
void notesChanged(const QString &notes);
void projectSaved(const QString &name);

View File

@ -14,7 +14,15 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
actionAddFlag(this),
actionRename(this),
actionXRefs(this),
actionDisplayOptions(this)
actionDisplayOptions(this),
actionSetBaseBinary(this),
actionSetBaseOctal(this),
actionSetBaseDecimal(this),
actionSetBaseHexadecimal(this),
actionSetBasePort(this),
actionSetBaseIPAddr(this),
actionSetBaseSyscall(this),
actionSetBaseString(this)
{
init();
}
@ -51,24 +59,43 @@ QKeySequence DisassemblyContextMenu::getDisplayOptionsSequence() const
void DisassemblyContextMenu::init()
{
actionAddComment.setText("Add comment");
actionAddComment.setText(tr("Add Comment"));
this->addAction(&actionAddComment);
actionAddComment.setShortcut(getCommentSequence());
actionAddFlag.setText("Add flag");
actionAddFlag.setText(tr("Add Flag"));
this->addAction(&actionAddFlag);
actionAddComment.setShortcut(getAddFlagSequence());
actionRename.setText("Rename");
actionRename.setText(tr("Rename"));
this->addAction(&actionRename);
actionAddComment.setShortcut(getRenameSequence());
actionXRefs.setText("Show xrefs");
QMenu *baseMenu = addMenu(tr("Set Base to..."));
actionSetBaseBinary.setText(tr("Binary"));
baseMenu->addAction(&actionSetBaseBinary);
actionSetBaseOctal.setText(tr("Octal"));
baseMenu->addAction(&actionSetBaseOctal);
actionSetBaseDecimal.setText(tr("Decimal"));
baseMenu->addAction(&actionSetBaseDecimal);
actionSetBaseHexadecimal.setText(tr("Hexadecimal"));
baseMenu->addAction(&actionSetBaseHexadecimal);
actionSetBasePort.setText(tr("Network Port"));
baseMenu->addAction(&actionSetBasePort);
actionSetBaseIPAddr.setText(tr("IP Address"));
baseMenu->addAction(&actionSetBaseIPAddr);
actionSetBaseSyscall.setText(tr("Syscall"));
baseMenu->addAction(&actionSetBaseSyscall);
actionSetBaseString.setText(tr("String"));
baseMenu->addAction(&actionSetBaseString);
this->addSeparator();
actionXRefs.setText(tr("Show X-Refs"));
this->addAction(&actionXRefs);
actionAddComment.setShortcut(getXRefSequence());
this->addSeparator();
actionDisplayOptions.setText("Show options");
actionDisplayOptions.setText(tr("Show Options"));
actionAddComment.setShortcut(getDisplayOptionsSequence());
this->addAction(&actionDisplayOptions);
@ -104,6 +131,16 @@ void DisassemblyContextMenu::init()
connect(&actionRename, SIGNAL(triggered(bool)), this, SLOT(on_actionRename_triggered()));
connect(&actionXRefs, SIGNAL(triggered(bool)), this, SLOT(on_actionXRefs_triggered()));
connect(&actionDisplayOptions, SIGNAL(triggered()), this, SLOT(on_actionDisplayOptions_triggered()));
connect(&actionSetBaseBinary, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseBinary_triggered()));
connect(&actionSetBaseOctal, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseOctal_triggered()));
connect(&actionSetBaseDecimal, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseDecimal_triggered()));
connect(&actionSetBaseHexadecimal, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseHexadecimal_triggered()));
connect(&actionSetBasePort, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBasePort_triggered()));
connect(&actionSetBaseIPAddr, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseIPAddr_triggered()));
connect(&actionSetBaseSyscall, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseSyscall_triggered()));
connect(&actionSetBaseString, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseString_triggered()));
}
void DisassemblyContextMenu::on_actionAddComment_triggered()
@ -199,3 +236,43 @@ void DisassemblyContextMenu::on_actionDisplayOptions_triggered()
AsmOptionsDialog *dialog = new AsmOptionsDialog(this->parentWidget());
dialog->show();
}
void DisassemblyContextMenu::on_actionSetBaseBinary_triggered()
{
Core()->setImmediateBase("b", offset);
}
void DisassemblyContextMenu::on_actionSetBaseOctal_triggered()
{
Core()->setImmediateBase("o", offset);
}
void DisassemblyContextMenu::on_actionSetBaseDecimal_triggered()
{
Core()->setImmediateBase("d", offset);
}
void DisassemblyContextMenu::on_actionSetBaseHexadecimal_triggered()
{
Core()->setImmediateBase("h", offset);
}
void DisassemblyContextMenu::on_actionSetBasePort_triggered()
{
Core()->setImmediateBase("p", offset);
}
void DisassemblyContextMenu::on_actionSetBaseIPAddr_triggered()
{
Core()->setImmediateBase("i", offset);
}
void DisassemblyContextMenu::on_actionSetBaseSyscall_triggered()
{
Core()->setImmediateBase("S", offset);
}
void DisassemblyContextMenu::on_actionSetBaseString_triggered()
{
Core()->setImmediateBase("s", offset);
}

View File

@ -23,6 +23,15 @@ public slots:
void on_actionXRefs_triggered();
void on_actionDisplayOptions_triggered();
void on_actionSetBaseBinary_triggered();
void on_actionSetBaseOctal_triggered();
void on_actionSetBaseDecimal_triggered();
void on_actionSetBaseHexadecimal_triggered();
void on_actionSetBasePort_triggered();
void on_actionSetBaseIPAddr_triggered();
void on_actionSetBaseSyscall_triggered();
void on_actionSetBaseString_triggered();
private:
void init();
@ -39,5 +48,14 @@ private:
QAction actionRename;
QAction actionXRefs;
QAction actionDisplayOptions;
QAction actionSetBaseBinary;
QAction actionSetBaseOctal;
QAction actionSetBaseDecimal;
QAction actionSetBaseHexadecimal;
QAction actionSetBasePort;
QAction actionSetBaseIPAddr;
QAction actionSetBaseSyscall;
QAction actionSetBaseString;
};
#endif // DISASSEMBLYCONTEXTMENU_H

View File

@ -77,6 +77,8 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshView()));
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(onSeekChanged(RVA)));
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshView()));
connect(Core(), SIGNAL(instructionChanged(RVA)), this, SLOT(refreshView()));
//connect(Bridge::getBridge(), SIGNAL(loadGraph(BridgeCFGraphList*, duint)), this, SLOT(loadGraphSlot(BridgeCFGraphList*, duint)));
//connect(Bridge::getBridge(), SIGNAL(graphAt(duint)), this, SLOT(graphAtSlot(duint)));
//connect(Bridge::getBridge(), SIGNAL(updateGraph()), this, SLOT(updateGraphSlot()));

View File

@ -80,6 +80,12 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent)
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), &CutterCore::instructionChanged, this, [this](RVA offset) {
if (offset >= topOffset && offset <= bottomOffset)
{
refreshDisasm();
}
});
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));