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
53 changes: 53 additions & 0 deletions README_Contribution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Cutter Contribution: Team 21 ECE49595OSS

Cutter is a free and open-source reverse engineering platform powered by rizin. This document details contributions made by Team 21 for ECE49595OSS

## Base Cutter Documentation

This section provides the documentation for Cutter itself.

### [Cutter README](https://github.com/rizinorg/cutter/blob/dev/README.md)

### [User Guide](https://cutter.re/docs/user-docs.html)

### [Contribution Guidelines](https://cutter.re/docs/contributing.html)

### [Developers Docs](https://cutter.re/docs/contributing/code.html)

## Contributions

This section details the issues we solved to contribute to Cutter.

### Issue 1

#### [Allow adding new flags from hexdump](https://github.com/rizinorg/cutter/issues/2932)

For this issue, we were tasked with adding a feature in the hexdump view that allows flags to be added into the hexdump view.

This is done by right clicking or pressing the keyboard shortcut N on the line you wish to add a flag to, entering a valid flag name, then confirming that action.

The flags added into the hexdump view are synchronized with the disassembly view.

##### Screenshots

Right Click shortcut for adding a new flag
![Screenshot](https://private-user-images.githubusercontent.com/90643076/305260361-e2ea623b-57c9-4929-bcce-ec374c560625.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTI5NjUzMzUsIm5iZiI6MTcxMjk2NTAzNSwicGF0aCI6Ii85MDY0MzA3Ni8zMDUyNjAzNjEtZTJlYTYyM2ItNTdjOS00OTI5LWJjY2UtZWMzNzRjNTYwNjI1LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDEyVDIzMzcxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ0OTI0YjA5MjcwZWJjNDVhZDFhNTRhOWE3ZmUyZGMzOTAxYmIxMzQzNWU5Nzk1NTk3MGJhNDUyMTI2MTAxODgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.keHDwZfUCFWq5qScsKmmkNcjF3hLa5jXB-thXNZKp6M)

Menu for adding a flag
![Screenshot](https://private-user-images.githubusercontent.com/90643076/305260362-ca3aeeb1-c7da-48aa-a6e9-46ca9933fa9f.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTI5NjUzMzUsIm5iZiI6MTcxMjk2NTAzNSwicGF0aCI6Ii85MDY0MzA3Ni8zMDUyNjAzNjItY2EzYWVlYjEtYzdkYS00OGFhLWE2ZTktNDZjYTk5MzNmYTlmLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDEyVDIzMzcxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI1ZDcxNGY3YTYwYzE1MGZjZThhNThiZmVmMjExZTFkNWRmNDk5MjcxMmU5MDhhOGQzYjAzZTNlM2FkMGE1N2YmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TMLuyPEXNxE2TpUtcRR6zSjQCPMmu5lf1eCqE_Izrvk)

Synchronization in the disassembly view
![Screenshot](https://private-user-images.githubusercontent.com/90643076/305260366-5d3afbda-89ce-44a4-932a-b189ebc573fd.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTI5NjUzMzUsIm5iZiI6MTcxMjk2NTAzNSwicGF0aCI6Ii85MDY0MzA3Ni8zMDUyNjAzNjYtNWQzYWZiZGEtODljZS00NGE0LTkzMmEtYjE4OWViYzU3M2ZkLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDEyVDIzMzcxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU2NmUzMDEyZTM4NzJiN2Y5NGZjNTZlNmU3YjM2MzEwYzcyZTliOGMyNTQ5ZTc3NThkM2EwNjczYjQ4MmI5NWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.IH045Omdh8cE63-v0zuEX03j2-X1cIJPN48wnYzU86o)

Showing the new flag in the hexdump view
![Screenshot](https://private-user-images.githubusercontent.com/90643076/305260370-d7e29740-3c89-44ce-bc77-908f0efd5fc2.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTI5NjUzMzUsIm5iZiI6MTcxMjk2NTAzNSwicGF0aCI6Ii85MDY0MzA3Ni8zMDUyNjAzNzAtZDdlMjk3NDAtM2M4OS00NGNlLWJjNzctOTA4ZjBlZmQ1ZmMyLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDEyVDIzMzcxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk3ZmFmMjkxZWYyNTI0ZTQyYTgxNzlmNmVmYmU5NDcxOTYxNTI3Y2U2OTg0MTI1NjUwZDdmYjZkMWQzMWNlMTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.wVJgHz2GwfsdCnsmnZkxmnVYgfhYJ5lvjIzqnrSaBsk)

Showing the ability to edit the new flag
![Screenshot](https://private-user-images.githubusercontent.com/90643076/305260371-22fa6817-35e4-487b-b6fb-9dcaaffc5890.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTI5NjUxMDUsIm5iZiI6MTcxMjk2NDgwNSwicGF0aCI6Ii85MDY0MzA3Ni8zMDUyNjAzNzEtMjJmYTY4MTctMzVlNC00ODdiLWI2ZmItOWRjYWFmZmM1ODkwLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDEyVDIzMzMyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg3NTZhYWIzYzgyNTRlZDE1MWQ2YmM0YjZmNWMwYzBjZTA5NDVlYTFiYzZlM2I4NDNmNzk3NThiNmFhMGYyZjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.jGLBUGoA2mLehKcnD-Z8UOYCDDw3BgQ0SP7xWr8mNBE)

Showing the edit menu for an existing flag in the hexdump view
![Screenshot](https://private-user-images.githubusercontent.com/90643076/305260371-22fa6817-35e4-487b-b6fb-9dcaaffc5890.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTI5NjUzMzUsIm5iZiI6MTcxMjk2NTAzNSwicGF0aCI6Ii85MDY0MzA3Ni8zMDUyNjAzNzEtMjJmYTY4MTctMzVlNC00ODdiLWI2ZmItOWRjYWFmZmM1ODkwLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDEyVDIzMzcxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThhMTIxMTUwOTMyOThiOTZlMmZmN2MzMmU0NGM2Mzc2YTM2NDEzYTVkZmYwZDdjMmQ3ODk2OTBiNWZmZTc4YzYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TENgRqIKJerKAuwBRVmM80cRu0YLM1Q-nNGfHYbXR6k)

### Issue 2

#### [Multiline Operations / Multiline Selection](https://github.com/rizinorg/cutter/issues/2601)
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``
42 changes: 40 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 @@ -1160,6 +1172,17 @@ void HexWidget::contextMenuEvent(QContextMenuEvent *event)
actionComment->setText(tr("Edit Comment"));
}

auto coreLock = Core()->core();
RzFlagItem *flagItem = rz_flag_get_i(coreLock->flags, cursor.address);

if (flagItem == 0x0) {
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 +1256,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