mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
* Add tooltip for displaying flag and comment in hexdump (#1471) Co-authored-by: Itay Cohen <itaycohen23@gmail.com> Co-authored-by: karliss <karlis3p70l1ij@gmail.com>
This commit is contained in:
parent
401b824030
commit
7110d73979
@ -775,6 +775,16 @@ void CutterCore::delComment(RVA addr)
|
|||||||
emit commentsChanged();
|
emit commentsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the comment present at a specific address
|
||||||
|
* @param addr The address to be checked
|
||||||
|
* @return String containing comment
|
||||||
|
*/
|
||||||
|
QString CutterCore::getCommentAt(RVA addr)
|
||||||
|
{
|
||||||
|
return Core()->cmdRawAt("CC.", addr);
|
||||||
|
}
|
||||||
|
|
||||||
void CutterCore::setImmediateBase(const QString &r2BaseName, RVA offset)
|
void CutterCore::setImmediateBase(const QString &r2BaseName, RVA offset)
|
||||||
{
|
{
|
||||||
if (offset == RVA_INVALID) {
|
if (offset == RVA_INVALID) {
|
||||||
@ -3465,6 +3475,17 @@ void CutterCore::addFlag(RVA offset, QString name, RVA size)
|
|||||||
emit flagsChanged();
|
emit flagsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets all the flags present at a specific address
|
||||||
|
* @param addr The address to be checked
|
||||||
|
* @return String containing all the flags which are comma-separated
|
||||||
|
*/
|
||||||
|
QString CutterCore::listFlagsAsStringAt(RVA addr)
|
||||||
|
{
|
||||||
|
CORE_LOCK();
|
||||||
|
return r_flag_get_liststr (core->flags, addr);
|
||||||
|
}
|
||||||
|
|
||||||
QString CutterCore::nearestFlag(RVA offset, RVA *flagOffsetOut)
|
QString CutterCore::nearestFlag(RVA offset, RVA *flagOffsetOut)
|
||||||
{
|
{
|
||||||
auto r = cmdj(QString("fdj @") + QString::number(offset)).object();
|
auto r = cmdj(QString("fdj @") + QString::number(offset)).object();
|
||||||
|
@ -169,6 +169,7 @@ public:
|
|||||||
void delFlag(RVA addr);
|
void delFlag(RVA addr);
|
||||||
void delFlag(const QString &name);
|
void delFlag(const QString &name);
|
||||||
void addFlag(RVA offset, QString name, RVA size);
|
void addFlag(RVA offset, QString name, RVA size);
|
||||||
|
QString listFlagsAsStringAt(RVA addr);
|
||||||
/**
|
/**
|
||||||
* @brief Get nearest flag at or before offset.
|
* @brief Get nearest flag at or before offset.
|
||||||
* @param offset search position
|
* @param offset search position
|
||||||
@ -217,6 +218,7 @@ public:
|
|||||||
/* Comments */
|
/* Comments */
|
||||||
void setComment(RVA addr, const QString &cmt);
|
void setComment(RVA addr, const QString &cmt);
|
||||||
void delComment(RVA addr);
|
void delComment(RVA addr);
|
||||||
|
QString getCommentAt(RVA addr);
|
||||||
void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
|
void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
|
||||||
void setCurrentBits(int bits, RVA offset = RVA_INVALID);
|
void setCurrentBits(int bits, RVA offset = RVA_INVALID);
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QToolTip>
|
||||||
|
|
||||||
static constexpr uint64_t MAX_COPY_SIZE = 128 * 1024 * 1024;
|
static constexpr uint64_t MAX_COPY_SIZE = 128 * 1024 * 1024;
|
||||||
static constexpr int MAX_LINE_WIDTH_PRESET = 32;
|
static constexpr int MAX_LINE_WIDTH_PRESET = 32;
|
||||||
@ -467,6 +468,15 @@ void HexWidget::mouseMoveEvent(QMouseEvent *event)
|
|||||||
QPoint pos = event->pos();
|
QPoint pos = event->pos();
|
||||||
pos.rx() += horizontalScrollBar()->value();
|
pos.rx() += horizontalScrollBar()->value();
|
||||||
|
|
||||||
|
auto mouseAddr = mousePosToAddr(pos).address;
|
||||||
|
|
||||||
|
QString metaData = getFlagsAndComment(mouseAddr);
|
||||||
|
if (!metaData.isEmpty() && itemArea.contains(pos)) {
|
||||||
|
QToolTip::showText(event->globalPos(), metaData.replace(",", ", "), this);
|
||||||
|
} else {
|
||||||
|
QToolTip::hideText();
|
||||||
|
}
|
||||||
|
|
||||||
if (!updatingSelection) {
|
if (!updatingSelection) {
|
||||||
if (itemArea.contains(pos) || asciiArea.contains(pos))
|
if (itemArea.contains(pos) || asciiArea.contains(pos))
|
||||||
setCursor(Qt::IBeamCursor);
|
setCursor(Qt::IBeamCursor);
|
||||||
@ -1010,6 +1020,14 @@ void HexWidget::drawItemArea(QPainter &painter)
|
|||||||
for (int j = 0; j < itemColumns; ++j) {
|
for (int j = 0; j < itemColumns; ++j) {
|
||||||
for (int k = 0; k < itemGroupSize && itemAddr <= data->maxIndex(); ++k, itemAddr += itemByteLen) {
|
for (int k = 0; k < itemGroupSize && itemAddr <= data->maxIndex(); ++k, itemAddr += itemByteLen) {
|
||||||
itemString = renderItem(itemAddr - startAddress, &itemColor);
|
itemString = renderItem(itemAddr - startAddress, &itemColor);
|
||||||
|
|
||||||
|
if (!getFlagsAndComment(itemAddr).isEmpty()) {
|
||||||
|
QColor markerColor(borderColor);
|
||||||
|
markerColor.setAlphaF(0.5);
|
||||||
|
const auto shape = rangePolygons(itemAddr, itemAddr, false)[0];
|
||||||
|
painter.setPen(markerColor);
|
||||||
|
painter.drawPolyline(shape);
|
||||||
|
}
|
||||||
if (selection.contains(itemAddr) && !cursorOnAscii) {
|
if (selection.contains(itemAddr) && !cursorOnAscii) {
|
||||||
itemColor = palette().highlightedText().color();
|
itemColor = palette().highlightedText().color();
|
||||||
}
|
}
|
||||||
@ -1454,6 +1472,27 @@ QChar HexWidget::renderAscii(int offset, QColor *color)
|
|||||||
return QChar(byte);
|
return QChar(byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the available flags and comment at a specific address.
|
||||||
|
* @param address Address of Item to be checked.
|
||||||
|
* @return String containing the flags and comment available at the address.
|
||||||
|
*/
|
||||||
|
QString HexWidget::getFlagsAndComment(uint64_t address)
|
||||||
|
{
|
||||||
|
QString flagNames = Core()->listFlagsAsStringAt(address);
|
||||||
|
QString metaData = flagNames.isEmpty() ? "" : "Flags: " + flagNames.trimmed();
|
||||||
|
|
||||||
|
QString comment = Core()->getCommentAt(address);
|
||||||
|
if (!comment.isEmpty()) {
|
||||||
|
if (!metaData.isEmpty()) {
|
||||||
|
metaData.append("\n");
|
||||||
|
}
|
||||||
|
metaData.append("Comment: " + comment.trimmed());
|
||||||
|
}
|
||||||
|
|
||||||
|
return metaData;
|
||||||
|
}
|
||||||
|
|
||||||
void HexWidget::fetchData()
|
void HexWidget::fetchData()
|
||||||
{
|
{
|
||||||
data.swap(oldData);
|
data.swap(oldData);
|
||||||
|
@ -329,6 +329,7 @@ private:
|
|||||||
QVariant readItem(int offset, QColor *color = nullptr);
|
QVariant readItem(int offset, QColor *color = nullptr);
|
||||||
QString renderItem(int offset, QColor *color = nullptr);
|
QString renderItem(int offset, QColor *color = nullptr);
|
||||||
QChar renderAscii(int offset, QColor *color = nullptr);
|
QChar renderAscii(int offset, QColor *color = nullptr);
|
||||||
|
QString getFlagsAndComment(uint64_t address);
|
||||||
/**
|
/**
|
||||||
* @brief Get the location on which operations such as Writing should apply.
|
* @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 widget.
|
* @return Start of selection if multiple bytes are selected. Otherwise, the curren seek of the widget.
|
||||||
|
Loading…
Reference in New Issue
Block a user