Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to add new flags from hexdump #2932 #3297

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
78 changes: 77 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
{
"cmake.sourceDirectory": "${workspaceFolder}"
"cmake.sourceDirectory": "${workspaceFolder}",
Rohan-Sagar marked this conversation as resolved.
Show resolved Hide resolved
"files.associations": {
"typeinfo": "cpp",
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__functional_base": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cmath": "cpp",
"compare": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"random": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"variant": "cpp",
"vector": "cpp"
}
}
16 changes: 15 additions & 1 deletion docs/source/user-docs/menus/hexdump-widget-context-menu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,18 @@ Available options are:
- 8 bytes
- 16 bytes
- 32 bytes
- Power of 2 (Auto)
- Power of 2 (Auto)

Add Flag
----------------------------------------
**Description:** Add a flag to the selected item or location by bookmarking and giving it a name.

**Steps:** Right-click an address or item and choose ``Add Flag``

**Shortcut:** :kbd:`N`

Delete Flag
----------------------------------------
**Description:** Delete a flag from the selected item or location.

**Steps:** Right-click an address or item and choose ``Delete Flag``
1 change: 0 additions & 1 deletion src/dialogs/CommentsDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "CommentsDialog.h"
#include "ui_CommentsDialog.h"

karliss marked this conversation as resolved.
Show resolved Hide resolved
#include <QErrorMessage>

#include "core/Cutter.h"
Expand Down
1 change: 0 additions & 1 deletion src/dialogs/FlagDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "FlagDialog.h"
#include "ui_FlagDialog.h"

Rohan-Sagar marked this conversation as resolved.
Show resolved Hide resolved
#include <QIntValidator>
#include "core/Cutter.h"

Expand Down
1 change: 0 additions & 1 deletion src/menus/DisassemblyContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "dialogs/EditStringDialog.h"
#include "dialogs/BreakpointsDialog.h"
#include "MainWindow.h"

karliss marked this conversation as resolved.
Show resolved Hide resolved
#include <QtCore>
#include <QShortcut>
#include <QJsonArray>
Expand Down
47 changes: 45 additions & 2 deletions src/widgets/HexWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Configuration.h"
#include "dialogs/WriteCommandsDialogs.h"
#include "dialogs/CommentsDialog.h"

#include "dialogs/FlagDialog.h"
#include <QPainter>
#include <QPaintEvent>
#include <QResizeEvent>
Expand Down Expand Up @@ -50,7 +50,6 @@ HexWidget::HexWidget(QWidget *parent)
setFocusPolicy(Qt::FocusPolicy::StrongFocus);
connect(horizontalScrollBar(), &QScrollBar::valueChanged, this,
[this]() { viewport()->update(); });

connect(Config(), &Configuration::colorsUpdated, this, &HexWidget::updateColors);
connect(Config(), &Configuration::fontsUpdated, this,
[this]() { setMonospaceFont(Config()->getFont()); });
Expand Down Expand Up @@ -137,6 +136,19 @@ HexWidget::HexWidget(QWidget *parent)
&HexWidget::onActionDeleteCommentTriggered);
addAction(actionDeleteComment);

// Add flag option
actionFlag = new QAction(tr("Add Flag"), this);
actionFlag->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);
actionFlag->setShortcut(Qt::Key_N);
connect(actionFlag, &QAction::triggered, this, &HexWidget::onActionAddFlagTriggered);
addAction(actionFlag);

// Delete flag option
actionDeleteFlag = new QAction(tr("Delete Flag"), this);
actionDeleteFlag->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);
connect(actionDeleteFlag, &QAction::triggered, this, &HexWidget::onActionDeleteFlagTriggered);
addAction(actionDeleteFlag);

actionSelectRange = new QAction(tr("Select range"), this);
connect(actionSelectRange, &QAction::triggered, this,
[this]() { rangeDialog.open(cursor.address); });
Expand Down Expand Up @@ -214,6 +226,11 @@ HexWidget::HexWidget(QWidget *parent)
connect(&warningTimer, &QTimer::timeout, this, &HexWidget::hideWarningRect);
}

QWidget *HexWidget::parentForDialog()
Rohan-Sagar marked this conversation as resolved.
Show resolved Hide resolved
{
return parentWidget();
}

void HexWidget::setMonospaceFont(const QFont &font)
{
if (!(font.styleHint() & QFont::Monospace)) {
Expand Down Expand Up @@ -1160,6 +1177,17 @@ void HexWidget::contextMenuEvent(QContextMenuEvent *event)
actionComment->setText(tr("Edit Comment"));
}

QString flag = Core()->flagAt(cursor.address);
karliss marked this conversation as resolved.
Show resolved Hide resolved
RzFlagItem *flagItem = rz_flag_get_i(Core()->core()->flags, cursor.address);
Rohan-Sagar marked this conversation as resolved.
Show resolved Hide resolved

if (flagItem == 0x0 || flag.isNull() || flag.isEmpty()) {
actionDeleteFlag->setVisible(false);
actionFlag->setText(tr("Add Flag"));
} else {
actionDeleteFlag->setVisible(true);
actionFlag->setText(tr("Edit Flag"));
}

if (!ioModesController.canWrite()) {
actionKeyboardEdit->setChecked(false);
}
Expand Down Expand Up @@ -1233,6 +1261,21 @@ void HexWidget::onActionAddCommentTriggered()
CommentsDialog::addOrEditComment(addr, this);
}

// slog for add flag action
void HexWidget::onActionAddFlagTriggered()
{
uint64_t addr = cursor.address;
FlagDialog dialog(addr, this);
dialog.exec();
}

// slot for deleting flag action
void HexWidget::onActionDeleteFlagTriggered()
{
uint64_t addr = cursor.address;
Core()->delFlag(addr);
}

// slot for deleting comment action
void HexWidget::onActionDeleteCommentTriggered()
{
Expand Down
5 changes: 5 additions & 0 deletions src/widgets/HexWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ private slots:
void copyAddress();
void onRangeDialogAccepted();
void onActionAddCommentTriggered();
void onActionAddFlagTriggered();
void onActionDeleteFlagTriggered();
void onActionDeleteCommentTriggered();

// Write command slots
Expand Down Expand Up @@ -424,6 +426,7 @@ private slots:
QString renderItem(int offset, QColor *color = nullptr);
QChar renderAscii(int offset, QColor *color = nullptr);
QString getFlagsAndComment(uint64_t address);
QWidget *parentForDialog();
/**
* @brief Get the location on which operations such as Writing should apply.
* @return Start of selection if multiple bytes are selected. Otherwise, the curren seek of the
Expand Down Expand Up @@ -576,6 +579,8 @@ private slots:
QAction *actionCopy;
QAction *actionCopyAddress;
QAction *actionComment;
QAction *actionFlag;
QAction *actionDeleteFlag;
QAction *actionDeleteComment;
QAction *actionSelectRange;
QAction *actionKeyboardEdit;
Expand Down
1 change: 1 addition & 0 deletions src/widgets/HexdumpWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class HexdumpWidget : public MemoryDockWidget
Highlighter *highlighter;

static QString getWidgetType();
QWidget *parentForDialog();

public slots:
void initParsing();
Expand Down
Loading