2017-10-10 10:17:05 +00:00
|
|
|
#include "DisassemblyContextMenu.h"
|
|
|
|
#include "dialogs/AsmOptionsDialog.h"
|
|
|
|
#include "dialogs/CommentsDialog.h"
|
|
|
|
#include "dialogs/FlagDialog.h"
|
|
|
|
#include "dialogs/RenameDialog.h"
|
|
|
|
#include "dialogs/XrefsDialog.h"
|
|
|
|
#include <QtCore>
|
2017-11-03 11:31:20 +00:00
|
|
|
#include <QShortcut>
|
2017-10-10 10:17:05 +00:00
|
|
|
|
|
|
|
DisassemblyContextMenu::DisassemblyContextMenu(RVA offset, QWidget *parent) :
|
|
|
|
QMenu(parent),
|
|
|
|
offset(offset)
|
2017-11-03 11:31:20 +00:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
DisassemblyContextMenu::DisassemblyContextMenu(QWidget*parent)
|
|
|
|
: QMenu(parent)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyContextMenu::setOffset(RVA offset)
|
|
|
|
{
|
|
|
|
this->offset = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
QKeySequence DisassemblyContextMenu::getCommentSequence() const
|
|
|
|
{
|
|
|
|
return {";"};
|
|
|
|
}
|
|
|
|
|
|
|
|
QKeySequence DisassemblyContextMenu::getAddFlagSequence() const
|
|
|
|
{
|
|
|
|
return {}; //TODO insert correct sequence
|
|
|
|
}
|
|
|
|
|
|
|
|
QKeySequence DisassemblyContextMenu::getRenameSequence() const
|
|
|
|
{
|
|
|
|
return {}; //TODO insert correct sequence
|
|
|
|
}
|
|
|
|
|
|
|
|
QKeySequence DisassemblyContextMenu::getXRefSequence() const
|
|
|
|
{
|
|
|
|
return {Qt::Key_X};
|
|
|
|
}
|
|
|
|
|
|
|
|
QKeySequence DisassemblyContextMenu::getDisplayOptionsSequence() const
|
|
|
|
{
|
|
|
|
return {}; //TODO insert correct sequence
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyContextMenu::init()
|
2017-10-10 10:17:05 +00:00
|
|
|
{
|
|
|
|
actionAddComment.setText("Add comment");
|
|
|
|
this->addAction(&actionAddComment);
|
2017-11-03 11:31:20 +00:00
|
|
|
actionAddComment.setShortcut(getCommentSequence());
|
|
|
|
|
2017-10-10 10:17:05 +00:00
|
|
|
actionAddFlag.setText("Add flag");
|
|
|
|
this->addAction(&actionAddFlag);
|
2017-11-03 11:31:20 +00:00
|
|
|
actionAddComment.setShortcut(getAddFlagSequence());
|
|
|
|
|
2017-10-10 10:17:05 +00:00
|
|
|
actionRename.setText("Rename");
|
|
|
|
this->addAction(&actionRename);
|
2017-11-03 11:31:20 +00:00
|
|
|
actionAddComment.setShortcut(getRenameSequence());
|
|
|
|
|
2017-10-10 10:17:05 +00:00
|
|
|
actionXRefs.setText("Show xrefs");
|
|
|
|
this->addAction(&actionXRefs);
|
2017-11-03 11:31:20 +00:00
|
|
|
actionAddComment.setShortcut(getXRefSequence());
|
|
|
|
|
2017-10-10 10:17:05 +00:00
|
|
|
this->addSeparator();
|
|
|
|
actionDisplayOptions.setText("Show options");
|
2017-11-03 11:31:20 +00:00
|
|
|
actionAddComment.setShortcut(getDisplayOptionsSequence());
|
2017-10-10 10:17:05 +00:00
|
|
|
this->addAction(&actionDisplayOptions);
|
|
|
|
|
2017-11-03 11:31:20 +00:00
|
|
|
auto pWidget = parentWidget();
|
|
|
|
|
|
|
|
QShortcut *shortcut_dispOptions = new QShortcut(getDisplayOptionsSequence(), pWidget);
|
|
|
|
shortcut_dispOptions->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(shortcut_dispOptions, &QShortcut::activated,
|
|
|
|
this, &DisassemblyContextMenu::on_actionDisplayOptions_triggered);
|
|
|
|
|
|
|
|
QShortcut *shortcut_x = new QShortcut(getXRefSequence(), pWidget);
|
|
|
|
shortcut_x->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(shortcut_x, &QShortcut::activated,
|
|
|
|
this, &DisassemblyContextMenu::on_actionXRefs_triggered);
|
|
|
|
|
|
|
|
QShortcut *shortcut_comment = new QShortcut(getCommentSequence(), pWidget);
|
|
|
|
shortcut_comment->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(shortcut_comment, &QShortcut::activated,
|
|
|
|
this, &DisassemblyContextMenu::on_actionAddComment_triggered);
|
|
|
|
|
|
|
|
QShortcut *shortcut_addFlag = new QShortcut(getAddFlagSequence(), pWidget);
|
|
|
|
shortcut_addFlag->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(shortcut_addFlag, &QShortcut::activated,
|
|
|
|
this, &DisassemblyContextMenu::on_actionAddFlag_triggered);
|
|
|
|
|
|
|
|
QShortcut *shortcut_renameSequence = new QShortcut(getRenameSequence(), pWidget);
|
|
|
|
shortcut_renameSequence->setContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
connect(shortcut_renameSequence, &QShortcut::activated,
|
|
|
|
this, &DisassemblyContextMenu::on_actionRename_triggered);
|
|
|
|
|
2017-10-10 10:17:05 +00:00
|
|
|
connect(&actionAddComment, SIGNAL(triggered(bool)), this, SLOT(on_actionAddComment_triggered()));
|
|
|
|
connect(&actionAddFlag, SIGNAL(triggered(bool)), this, SLOT(on_actionAddFlag_triggered()));
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyContextMenu::on_actionAddComment_triggered()
|
|
|
|
{
|
2017-11-08 09:18:07 +00:00
|
|
|
RAnalFunction *fcn = Core()->functionAt(offset);
|
2017-10-10 10:17:05 +00:00
|
|
|
CommentsDialog *c = new CommentsDialog(this);
|
|
|
|
if (c->exec())
|
|
|
|
{
|
|
|
|
QString comment = c->getComment();
|
2017-11-08 09:18:07 +00:00
|
|
|
Core()->setComment(offset, comment);
|
2017-10-10 10:17:05 +00:00
|
|
|
if (fcn)
|
|
|
|
{
|
2017-11-08 09:18:07 +00:00
|
|
|
Core()->seek(fcn->addr);
|
2017-10-10 10:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyContextMenu::on_actionAddFlag_triggered()
|
|
|
|
{
|
|
|
|
FlagDialog *dialog = new FlagDialog(offset, this->parentWidget());
|
|
|
|
dialog->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyContextMenu::on_actionRename_triggered()
|
|
|
|
{
|
|
|
|
// Get function for clicked offset
|
|
|
|
RAnalFunction *fcn = CutterCore::getInstance()->functionAt(offset);
|
2017-11-08 09:02:39 +00:00
|
|
|
if( nullptr == fcn )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-10 10:17:05 +00:00
|
|
|
RenameDialog *dialog = new RenameDialog(this);
|
|
|
|
// Get function based on click position
|
|
|
|
dialog->setFunctionName(fcn->name);
|
|
|
|
if (dialog->exec())
|
|
|
|
{
|
|
|
|
// Get new function name
|
|
|
|
QString new_name = dialog->getFunctionName();
|
|
|
|
// Rename function in r2 core
|
|
|
|
CutterCore::getInstance()->renameFunction(fcn->name, new_name);
|
|
|
|
// Seek to new renamed function
|
|
|
|
CutterCore::getInstance()->seek(fcn->addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyContextMenu::on_actionXRefs_triggered()
|
|
|
|
{
|
|
|
|
XrefsDialog *dialog = new XrefsDialog(this);
|
|
|
|
dialog->fillRefsForAddress(offset, RAddressString(offset), false);
|
|
|
|
dialog->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblyContextMenu::on_actionDisplayOptions_triggered()
|
|
|
|
{
|
|
|
|
AsmOptionsDialog *dialog = new AsmOptionsDialog(this->parentWidget());
|
|
|
|
dialog->show();
|
|
|
|
}
|