summaryrefslogtreecommitdiff
path: root/ui/variablelist.h
diff options
context:
space:
mode:
authorJon Palmisciano <jp@jonpalmisc.com>2021-06-09 10:52:24 -0400
committerJon Palmisciano <jp@jonpalmisc.com>2021-07-30 13:36:32 -0400
commit3ea20aa077fb3f0685b755a5e60654db6945538b (patch)
treea7617ba856aa9f7313f88c462948c28afa540728 /ui/variablelist.h
parent3e0c457f6067e3360e96b9dbae2665705221a2c5 (diff)
VariableList: It's here!
Diffstat (limited to 'ui/variablelist.h')
-rw-r--r--ui/variablelist.h185
1 files changed, 185 insertions, 0 deletions
diff --git a/ui/variablelist.h b/ui/variablelist.h
new file mode 100644
index 00000000..93e927d1
--- /dev/null
+++ b/ui/variablelist.h
@@ -0,0 +1,185 @@
+#pragma once
+
+#include <QtCore/QTimer>
+#include <QtWidgets/QListView>
+#include <QtWidgets/QStyledItemDelegate>
+#include <QtWidgets/QWidget>
+
+#include "binaryninjacore.h"
+#include "dockhandler.h"
+#include "uitypes.h"
+#include "viewframe.h"
+
+//! A variable list item can represent either a function-local variable, or a
+//! data variable referenced by the current function.
+enum class VariableListItemType
+{
+ LocalVariable,
+ DataVariable
+};
+
+//! An item part of VariableListModel.
+class VariableListItem
+{
+ FunctionRef m_func;
+ VariableListItemType m_type;
+ std::string m_name;
+
+ uint64_t m_refPoint;
+
+ BinaryNinja::Variable m_var;
+ BinaryNinja::DataVariable m_dataVar;
+ BinaryNinja::PossibleValueSet m_pvs;
+ bool m_hasUidf;
+
+ public:
+ //! Create a new VariableListItem of the LocalVariable type.
+ VariableListItem(FunctionRef func, BinaryNinja::Variable var, BinaryNinja::PossibleValueSet pvs,
+ bool hasUidf, std::string name);
+
+ //! Create a new VariableListItem of the DataVariable type.
+ VariableListItem(
+ FunctionRef func, BinaryNinja::DataVariable dataVar, uint64_t refPoint, std::string name);
+
+ //! Get the type of this list item.
+ VariableListItemType type() const;
+
+ //! Get the represented variable's display name.
+ std::string name() const;
+
+ //! Get the data variable's value; use with data variable items only.
+ std::string constantValue() const;
+
+ //! Get the variable possible value set; use with local variable items only.
+ BinaryNinja::PossibleValueSet possibleValueSet() const;
+
+ //! Is the PVS user-provided? Use with local variable items only.
+ bool hasUidf() const;
+
+ std::vector<BinaryNinja::InstructionTextToken> tokensBeforeName() const;
+ std::vector<BinaryNinja::InstructionTextToken> tokensAfterName() const;
+
+ //! Shorthand to get concatenated type, name, and value tokens.
+ std::vector<BinaryNinja::InstructionTextToken> displayTokens() const;
+
+ //! Get the represented variable; use with variable items only.
+ BinaryNinja::Variable variable() const;
+
+ //! Get the represented data variable; use with data variable items only.
+ BinaryNinja::DataVariable dataVariable() const;
+
+ //! Get the first use of this variable; use with data variables items only.
+ uint64_t refPoint() const;
+
+ //! Is any part of this item user-defined?
+ bool isUserDefined() const;
+};
+
+//! The backing model for the variable list widget, holds VariableListItem.
+class BINARYNINJAUIAPI VariableListModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+ ViewFrame* m_view;
+ BinaryViewRef m_data;
+ FunctionRef m_func;
+ std::vector<VariableListItem> m_items;
+
+ QItemSelectionModel* m_selModel;
+
+ size_t m_prevVariableCount;
+ uint64_t m_prevSelectionId;
+
+ public:
+ VariableListModel(QWidget* parent, ViewFrame* view, BinaryViewRef data);
+
+ //! Clear the list's content.
+ void clear();
+
+ //! Get the current function.
+ FunctionRef function() const;
+
+ //! Set the focused function and update the content of the list.
+ void setFunction(FunctionRef func, BNFunctionGraphType il, const HighlightTokenState& hts);
+
+ //! Set the selection model, should correspond to the parent widget's.
+ void setSelectionModel(QItemSelectionModel* model);
+
+ virtual QVariant data(const QModelIndex& i, int role) const override;
+ virtual QModelIndex index(
+ int row, int col, const QModelIndex& parent = QModelIndex()) const override;
+ virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
+ virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
+ Qt::ItemFlags flags(const QModelIndex& index) const override;
+ virtual QVariant headerData(int column, Qt::Orientation orientation, int role) const override;
+};
+
+class VariableListItemDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+ public:
+ VariableListItemDelegate();
+
+ void paint(QPainter* painter, const QStyleOptionViewItem& opt, const QModelIndex& index) const;
+ QSize sizeHint(const QStyleOptionViewItem& opt, const QModelIndex& index) const;
+};
+
+//! The main variable list dock widget.
+class BINARYNINJAUIAPI VariableList : public SidebarWidget
+{
+ Q_OBJECT
+
+ QWidget* m_header;
+
+ ViewFrame* m_view;
+ BinaryViewRef m_data;
+
+ VariableListModel* m_listModel;
+ QListView* m_list;
+
+ uint64_t m_lastOffset;
+ QTimer* m_refreshTimer;
+
+ void processRefresh();
+
+ public:
+ VariableList(ViewFrame* view, BinaryViewRef data);
+
+ virtual QWidget* headerWidget() override { return m_header; }
+
+ void refresh();
+
+ //! Get the VariableListItem corresponding to the current selection.
+ VariableListItem* selectedItem() const;
+
+ //! Show the rename dialog for the selected variable.
+ void changeSelectedVariableName();
+
+ //! Show the new type dialog for the seleected variable.
+ void changeSelectedVariableType();
+
+ //! Clear the selected variable's name.
+ void clearSelectedVariableName();
+
+ //! Clear the selected variable's type.
+ void clearSelectedVariableType();
+
+ //! Undefine the selected variable's user symbol.
+ void clearSelectedVariableNameAndType();
+
+ //! Navigate to the first usage of the selected variable.
+ void showSelectedVariableFirstUsage();
+
+ //! Navigate to the definition of the selected data variable.
+ void showSelectedDataVariableDefinition();
+
+ //! Set the selected variable's DSE policy.
+ void setSelectedVariableDeadStoreElimination(BNDeadStoreElimination dse);
+};
+
+class BINARYNINJAUIAPI VariableListSidebarWidgetType : public SidebarWidgetType
+{
+ public:
+ VariableListSidebarWidgetType();
+ virtual SidebarWidget* createWidget(ViewFrame* frame, BinaryViewRef data) override;
+};