diff options
| author | Josh F <josh@vector35.com> | 2022-07-06 13:40:52 -0400 |
|---|---|---|
| committer | Josh F <josh@vector35.com> | 2022-07-18 16:13:50 -0400 |
| commit | 11458f3160e9c82d3e0f48b7013d952b729ec38b (patch) | |
| tree | 4c2165c208fa9542a2c744b7a3f94be52877315e /ui/memorymap.h | |
| parent | c3362d1ffb2c581c0647a1e9f480b98e7976fe25 (diff) | |
Memory map sidebar widget + segment/section notifications
Diffstat (limited to 'ui/memorymap.h')
| -rw-r--r-- | ui/memorymap.h | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/ui/memorymap.h b/ui/memorymap.h new file mode 100644 index 00000000..fe85035c --- /dev/null +++ b/ui/memorymap.h @@ -0,0 +1,182 @@ +#pragma once + +#include <QtWidgets/QAbstractScrollArea> +#include <QtWidgets/QComboBox> +#include <QtWidgets/QDialog> +#include <QtWidgets/QLineEdit> +#include <QtWidgets/QTableWidget> +#include <QtWidgets/QCheckBox> +#include <QtWidgets/QPushButton> +#include <QtWidgets/QStyledItemDelegate> + +#include "dockhandler.h" +#include "render.h" +#include "sidebar.h" +#include "uitypes.h" +#include "fontsettings.h" + + +class BINARYNINJAUIAPI DataComparedTableItem : public QTableWidgetItem +{ +public: + DataComparedTableItem(const QString& text, int type=QTableWidgetItem::ItemType::Type): QTableWidgetItem(text, type) {}; + bool operator<(const QTableWidgetItem& other) const; +}; + + +class BINARYNINJAUIAPI MemoryMapItemDelegate : public QStyledItemDelegate +{ +public: + MemoryMapItemDelegate(QObject* parent = nullptr): QStyledItemDelegate(parent) {}; + virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; +}; + + +class BINARYNINJAUIAPI SegmentDialog : public QDialog +{ + + QPushButton* m_acceptButton; + QPushButton* m_cancelButton; + QLineEdit* m_startField; + QLineEdit* m_lengthField; + QLineEdit* m_dataOffsetField; + QLineEdit* m_dataLengthField; + QCheckBox* m_flagRead; + QCheckBox* m_flagWrite; + QCheckBox* m_flagExec; + + BinaryViewRef m_data; + SegmentRef m_segment; + + void Submit(); +public: + SegmentDialog(QWidget* parent, BinaryViewRef data, SegmentRef segment = nullptr); +}; + + +class BINARYNINJAUIAPI SectionDialog : public QDialog +{ + + QPushButton* m_acceptButton; + QPushButton* m_cancelButton; + QLineEdit* m_nameField; + QLineEdit* m_startField; + QLineEdit* m_lengthField; + QComboBox* m_semanticsField; + + BinaryViewRef m_data; + SectionRef m_section; + + void Submit(); +public: + SectionDialog(QWidget* parent, BinaryViewRef data, SectionRef section = nullptr); +}; + + +class BINARYNINJAUIAPI SegmentWidget : public QWidget, public BinaryNinja::BinaryDataNotification +{ + Q_OBJECT + + enum SEGMENT_COLUMN { + START = 0, + END, + DATA_OFFSET, + DATA_LENGTH, + FLAGS, + COLUMN_COUNT, + }; + + BinaryViewRef m_data; + QTableWidget* m_table; + std::mutex m_updateMutex; + + void updateInfo(); + void showContextMenu(const QPoint& point); + + void addSegment(); + void editSegment(SegmentRef segment); + void removeSegment(SegmentRef segment); + +public: + SegmentWidget(BinaryViewRef data); + + void updateFont(); + void highlightRelatedSegments(SectionRef section); + void itemChanged(QTableWidgetItem* current, QTableWidgetItem* previous); + + virtual void OnSegmentAdded(BinaryNinja::BinaryView* data, BinaryNinja::Segment* segment) override { updateInfo(); }; + virtual void OnSegmentUpdated(BinaryNinja::BinaryView* data, BinaryNinja::Segment* segment) override { updateInfo(); }; + virtual void OnSegmentRemoved(BinaryNinja::BinaryView* data, BinaryNinja::Segment* segment) override { updateInfo(); }; + +Q_SIGNALS: + void currentSegmentChanged(SegmentRef current); + void addressDoubleClicked(uint64_t address); +}; + + +class BINARYNINJAUIAPI SectionWidget : public QWidget, public BinaryNinja::BinaryDataNotification +{ + Q_OBJECT + + enum SECTION_COLUMN { + NAME = 0, + START, + END, + SEMANTICS, + COLUMN_COUNT, + }; + + BinaryViewRef m_data; + QTableWidget* m_table; + std::mutex m_updateMutex; + + void updateInfo(); + void showContextMenu(const QPoint& point); + + void addSection(); + void editSection(SectionRef section); + void removeSection(SectionRef section); + +public: + SectionWidget(BinaryViewRef data); + + void updateFont(); + void highlightRelatedSections(SegmentRef segment); + void itemChanged(QTableWidgetItem* current, QTableWidgetItem* previous); + + virtual void OnSectionAdded(BinaryNinja::BinaryView* data, BinaryNinja::Section* section) override { updateInfo(); }; + virtual void OnSectionUpdated(BinaryNinja::BinaryView* data, BinaryNinja::Section* section) override { updateInfo(); }; + virtual void OnSectionRemoved(BinaryNinja::BinaryView* data, BinaryNinja::Section* section) override { updateInfo(); }; + +Q_SIGNALS: + void currentSectionChanged(SectionRef current); + void addressDoubleClicked(uint64_t address); +}; + + +class BINARYNINJAUIAPI MemoryMapSidebarWidget : public SidebarWidget, public BinaryNinja::BinaryDataNotification +{ + Q_OBJECT + + SectionWidget* m_sectionWidget; + SegmentWidget* m_segmentWidget; + QWidget* m_header; + BinaryViewRef m_data; + ViewFrame* m_frame; + + void navigateToAddress(uint64_t address); + + public: + MemoryMapSidebarWidget(ViewFrame* view, BinaryViewRef data); + + void notifyFontChanged() override; + QWidget* headerWidget() override { return m_header; } +}; + + +class BINARYNINJAUIAPI MemoryMapSidebarWidgetType : public SidebarWidgetType +{ + public: + MemoryMapSidebarWidgetType(); + SidebarWidget* createWidget(ViewFrame* frame, BinaryViewRef data) override; +}; |
