mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-07 15:32:13 +00:00
HexdumpWidget enhancements (#235)
This commit is contained in:
parent
70a361ab91
commit
9847836d73
@ -120,6 +120,15 @@ namespace qhelpers
|
|||||||
widget->setMaximumHeight(max);
|
widget->setMaximumHeight(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getMaxFullyDisplayedLines(QTextEdit *textEdit)
|
||||||
|
{
|
||||||
|
QFontMetrics fontMetrics(textEdit->document()->defaultFont());
|
||||||
|
return (textEdit->height()
|
||||||
|
- (textEdit->contentsMargins().top()
|
||||||
|
+ textEdit->contentsMargins().bottom()
|
||||||
|
+ (int)(textEdit->document()->documentMargin() * 2)))
|
||||||
|
/ fontMetrics.lineSpacing();
|
||||||
|
}
|
||||||
|
|
||||||
int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit)
|
int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ namespace qhelpers
|
|||||||
SizePolicyMinMax forceWidth(QWidget *widget, int width);
|
SizePolicyMinMax forceWidth(QWidget *widget, int width);
|
||||||
SizePolicyMinMax forceHeight(QWidget *widget, int height);
|
SizePolicyMinMax forceHeight(QWidget *widget, int height);
|
||||||
|
|
||||||
|
int getMaxFullyDisplayedLines(QTextEdit *textEdit);
|
||||||
int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit);
|
int getMaxFullyDisplayedLines(QPlainTextEdit *plainTextEdit);
|
||||||
|
|
||||||
QByteArray applyColorToSvg(const QByteArray &data, QColor color);
|
QByteArray applyColorToSvg(const QByteArray &data, QColor color);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,32 +1,28 @@
|
|||||||
|
|
||||||
#ifndef HEXDUMPWIDGET_H
|
#ifndef HEXDUMPWIDGET_H
|
||||||
#define HEXDUMPWIDGET_H
|
#define HEXDUMPWIDGET_H
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
#include <QTreeWidget>
|
|
||||||
#include <QTabWidget>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QPlainTextEdit>
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "cutter.h"
|
#include "cutter.h"
|
||||||
#include "utils/Highlighter.h"
|
#include "utils/Highlighter.h"
|
||||||
#include "utils/HexAsciiHighlighter.h"
|
#include "utils/HexAsciiHighlighter.h"
|
||||||
#include "utils/HexHighlighter.h"
|
#include "utils/HexHighlighter.h"
|
||||||
|
#include "utils/SvgIconEngine.h"
|
||||||
|
|
||||||
#include "Dashboard.h"
|
#include "Dashboard.h"
|
||||||
|
|
||||||
|
#include "ui_HexdumpWidget.h"
|
||||||
namespace Ui
|
|
||||||
{
|
|
||||||
class HexdumpWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
class HexdumpWidget : public QDockWidget
|
class HexdumpWidget : public QDockWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit HexdumpWidget(const QString &title, QWidget *parent = nullptr, Qt::WindowFlags flags = 0);
|
explicit HexdumpWidget(const QString &title, QWidget *parent = nullptr, Qt::WindowFlags flags = 0);
|
||||||
@ -35,16 +31,22 @@ public:
|
|||||||
|
|
||||||
Highlighter *highlighter;
|
Highlighter *highlighter;
|
||||||
|
|
||||||
//signals:
|
enum Format {
|
||||||
// void fontChanged(QFont font);
|
Hex,
|
||||||
|
Octal,
|
||||||
|
// TODO:
|
||||||
|
// HalfWord,
|
||||||
|
// Word,
|
||||||
|
// QuadWord,
|
||||||
|
// Emoji,
|
||||||
|
// SignedInt1,
|
||||||
|
// SignedInt2,
|
||||||
|
// SignedInt4,
|
||||||
|
};
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void initParsing();
|
void initParsing();
|
||||||
|
|
||||||
QString normalize_addr(QString addr);
|
|
||||||
|
|
||||||
QString normalizeAddr(QString addr);
|
|
||||||
|
|
||||||
void showOffsets(bool show);
|
void showOffsets(bool show);
|
||||||
|
|
||||||
void zoomIn(int range = 1);
|
void zoomIn(int range = 1);
|
||||||
@ -55,41 +57,67 @@ protected:
|
|||||||
virtual void wheelEvent(QWheelEvent* event) override;
|
virtual void wheelEvent(QWheelEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int linesMarginMin;
|
static const int linesMarginMin = 32;
|
||||||
static const int linesMarginDefault;
|
static const int linesMarginDefault = 48;
|
||||||
static const int linesMarginMax;
|
static const int linesMarginMax = 64;
|
||||||
|
|
||||||
|
enum Format format = Format::Hex;
|
||||||
|
|
||||||
std::unique_ptr<Ui::HexdumpWidget> ui;
|
std::unique_ptr<Ui::HexdumpWidget> ui;
|
||||||
|
|
||||||
RVA topOffset;
|
bool sent_seek = false;
|
||||||
RVA bottomOffset;
|
bool scroll_disabled = false;
|
||||||
|
|
||||||
|
RVA first_loaded_address = RVA_INVALID;
|
||||||
|
RVA last_loaded_address = RVA_INVALID;
|
||||||
|
|
||||||
void refresh(RVA addr = RVA_INVALID);
|
void refresh(RVA addr = RVA_INVALID);
|
||||||
void appendHexdumpLines(int lines, bool top);
|
|
||||||
void removeHexdumpLines(int lines, bool top);
|
|
||||||
void selectHexPreview();
|
void selectHexPreview();
|
||||||
void updateHeaders();
|
void updateHeaders();
|
||||||
|
|
||||||
std::array<QString, 3> fetchHexdump(RVA offset, RVA bytes);
|
std::array<QString, 3> fetchHexdump(RVA addr, int lines);
|
||||||
|
|
||||||
void connectScroll(bool disconnect);
|
void connectScroll(bool disconnect_);
|
||||||
void setupScrollSync();
|
void setupScrollSync();
|
||||||
|
|
||||||
void setupFonts();
|
void setupFonts();
|
||||||
|
|
||||||
|
// If bottom = false gets the FIRST displayed line, otherwise the LAST displayed
|
||||||
|
// line.
|
||||||
|
int getDisplayedLined(QTextEdit *textEdit, bool bottom = false);
|
||||||
|
|
||||||
|
static void removeTopLinesWithoutScroll(QTextEdit *textEdit, int lines);
|
||||||
|
static void removeBottomLinesWithoutScroll(QTextEdit *textEdit, int lines);
|
||||||
|
static void prependWithoutScroll(QTextEdit *textEdit, QString text);
|
||||||
|
static void appendWithoutScroll(QTextEdit *textEdit, QString text);
|
||||||
|
static void setTextEditPosition(QTextEdit *textEdit, int position);
|
||||||
|
|
||||||
|
RVA hexPositionToAddress(int position);
|
||||||
|
RVA asciiPositionToAddress(int position);
|
||||||
|
int hexAddressToPosition(RVA address);
|
||||||
|
int asciiAddressToPosition(RVA address);
|
||||||
|
void updateWidths();
|
||||||
|
|
||||||
|
void updateParseWindow(RVA start_address, int size);
|
||||||
|
void clearParseWindow();
|
||||||
|
|
||||||
|
int bufferLines;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_seekChanged(RVA addr);
|
void on_seekChanged(RVA addr);
|
||||||
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
|
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
|
||||||
|
|
||||||
void highlightHexCurrentLine();
|
// Currently unused/untested
|
||||||
|
// void highlightHexCurrentLine();
|
||||||
|
// void highlightHexWords(const QString &str);
|
||||||
|
|
||||||
void highlightHexWords(const QString &str);
|
|
||||||
void on_actionHideHexdump_side_panel_triggered();
|
void on_actionHideHexdump_side_panel_triggered();
|
||||||
|
|
||||||
void showHexdumpContextMenu(const QPoint &pt);
|
void showHexdumpContextMenu(const QPoint &pt);
|
||||||
void showHexASCIIContextMenu(const QPoint &pt);
|
void showHexASCIIContextMenu(const QPoint &pt);
|
||||||
|
|
||||||
void on_hexHexText_selectionChanged();
|
void selectionChanged();
|
||||||
|
void scrollChanged();
|
||||||
|
|
||||||
void on_parseArchComboBox_currentTextChanged(const QString &arg1);
|
void on_parseArchComboBox_currentTextChanged(const QString &arg1);
|
||||||
void on_parseBitsComboBox_currentTextChanged(const QString &arg1);
|
void on_parseBitsComboBox_currentTextChanged(const QString &arg1);
|
||||||
@ -104,7 +132,8 @@ private slots:
|
|||||||
void on_action32columns_triggered();
|
void on_action32columns_triggered();
|
||||||
void on_action64columns_triggered();
|
void on_action64columns_triggered();
|
||||||
|
|
||||||
void adjustHexdumpLines();
|
void on_actionFormatHex_triggered();
|
||||||
|
void on_actionFormatOctal_triggered();
|
||||||
|
|
||||||
void fontsUpdated();
|
void fontsUpdated();
|
||||||
void colorsUpdatedSlot();
|
void colorsUpdatedSlot();
|
||||||
|
@ -152,47 +152,10 @@ QToolTip {
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0">
|
<item row="1" column="2">
|
||||||
<widget class="QPlainTextEdit" name="hexOffsetText">
|
<widget class="QTextEdit" name="hexHexText">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="acceptDrops">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true"/>
|
|
||||||
</property>
|
|
||||||
<property name="frameShape">
|
|
||||||
<enum>QFrame::NoFrame</enum>
|
|
||||||
</property>
|
|
||||||
<property name="lineWidth">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="verticalScrollBarPolicy">
|
|
||||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
|
||||||
</property>
|
|
||||||
<property name="horizontalScrollBarPolicy">
|
|
||||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeAdjustPolicy">
|
|
||||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
|
||||||
</property>
|
|
||||||
<property name="lineWrapMode">
|
|
||||||
<enum>QPlainTextEdit::NoWrap</enum>
|
|
||||||
</property>
|
|
||||||
<property name="readOnly">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QPlainTextEdit" name="hexHexText">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -228,17 +191,92 @@ QToolTip {
|
|||||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="lineWrapMode">
|
<property name="lineWrapMode">
|
||||||
<enum>QPlainTextEdit::NoWrap</enum>
|
<enum>QTextEdit::NoWrap</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="readOnly">
|
<property name="cursorWidth">
|
||||||
<bool>true</bool>
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<property name="textInteractionFlags">
|
||||||
|
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="2">
|
<item row="1" column="3">
|
||||||
<widget class="QPlainTextEdit" name="hexASCIIText">
|
<widget class="Line" name="line_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QLabel" name="hexHeaderLabel">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>0 1 2 3 ...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QTextEdit" name="hexOffsetText">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="acceptDrops">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true"/>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="verticalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
|
<property name="horizontalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="4">
|
||||||
|
<widget class="QLabel" name="asciiHeaderLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>0123...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="offsetHeaderLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Offset</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="4">
|
||||||
|
<widget class="QTextEdit" name="hexASCIIText">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -280,31 +318,23 @@ QToolTip {
|
|||||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="lineWrapMode">
|
<property name="lineWrapMode">
|
||||||
<enum>QPlainTextEdit::NoWrap</enum>
|
<enum>QTextEdit::NoWrap</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="readOnly">
|
<property name="cursorWidth">
|
||||||
<bool>true</bool>
|
<number>3</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="1" column="5">
|
||||||
<widget class="QLabel" name="offsetHeaderLabel">
|
<widget class="QTextEdit" name="hexSpacerText">
|
||||||
<property name="text">
|
<property name="frameShape">
|
||||||
<string>Offset</string>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="frameShadow">
|
||||||
</item>
|
<enum>QFrame::Plain</enum>
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QLabel" name="hexHeaderLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>0 1 2 3 ...</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="textInteractionFlags">
|
||||||
</item>
|
<set>Qt::NoTextInteraction</set>
|
||||||
<item row="0" column="2">
|
|
||||||
<widget class="QLabel" name="asciiHeaderLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>0123...</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -974,6 +1004,60 @@ QToolTip {
|
|||||||
<string>Insert String</string>
|
<string>Insert String</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionFormatHex">
|
||||||
|
<property name="text">
|
||||||
|
<string>Hex</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFormatOctal">
|
||||||
|
<property name="text">
|
||||||
|
<string>Octal</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFormatHalfWord">
|
||||||
|
<property name="text">
|
||||||
|
<string>Half-word</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFormatWord">
|
||||||
|
<property name="text">
|
||||||
|
<string>Word</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFormatQuadWord">
|
||||||
|
<property name="text">
|
||||||
|
<string>Quad-word</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFormatEmoji">
|
||||||
|
<property name="text">
|
||||||
|
<string>Emoji</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFormatSignedInt1">
|
||||||
|
<property name="text">
|
||||||
|
<string>1 byte</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>1 byte</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFormatSignedInt2">
|
||||||
|
<property name="text">
|
||||||
|
<string>2 bytes</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>2 bytes</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFormatSignedInt4">
|
||||||
|
<property name="text">
|
||||||
|
<string>4 bytes</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>4 bytes</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../resources.qrc"/>
|
<include location="../resources.qrc"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user