diff options
| author | Rusty Wagner <rusty.wagner@gmail.com> | 2022-07-07 21:03:29 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty.wagner@gmail.com> | 2022-08-10 15:17:53 -0400 |
| commit | 390d5d27d4de6b7c9cb06b957a483bb2ab69f241 (patch) | |
| tree | 556133db637166968a77d68daf7ff2160df79b40 /ui | |
| parent | 4037000b6cb8a184ad098d0eff397518d7fe55b9 (diff) | |
Merge variables API/UI, variable liveness API for determining soundness of variable merges
Diffstat (limited to 'ui')
| -rw-r--r-- | ui/flowgraphwidget.h | 1 | ||||
| -rw-r--r-- | ui/linearview.h | 39 | ||||
| -rw-r--r-- | ui/mergevariablesdialog.h | 76 | ||||
| -rw-r--r-- | ui/uitypes.h | 2 |
4 files changed, 98 insertions, 20 deletions
diff --git a/ui/flowgraphwidget.h b/ui/flowgraphwidget.h index f6a38a85..f4751dea 100644 --- a/ui/flowgraphwidget.h +++ b/ui/flowgraphwidget.h @@ -338,6 +338,7 @@ class BINARYNINJAUIAPI FlowGraphWidget : void tagAddress(); void tagAddressAccepted(TagTypeRef tt); void manageAddressTags(); + void mergeVariables(); void convertToNop(); void alwaysBranch(); diff --git a/ui/linearview.h b/ui/linearview.h index 6bec459c..38d8dfaf 100644 --- a/ui/linearview.h +++ b/ui/linearview.h @@ -66,7 +66,7 @@ class BINARYNINJAUIAPI LinearViewHistoryEntry : public HistoryEntry bool m_inFunc = false; HighlightTokenState m_highlight; - public: +public: const std::vector<BinaryNinja::LinearViewObjectIdentifier>& getTopPath() const { return m_topPath; } size_t getTopLineIndex() const { return m_topLineIndex; } uint64_t getTopAddress() const { return m_topAddr; } @@ -99,22 +99,22 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub class LinearViewOptionsWidget : public MenuHelper { - public: + public: LinearViewOptionsWidget(LinearView* parent); - protected: + protected: virtual void showMenu(); - private: + private: LinearView* m_view; }; class LinearViewOptionsIconWidget : public QWidget { - public: + public: LinearViewOptionsIconWidget(LinearView* parent); - private: + private: LinearView* m_view; ContextMenuManager* m_contextMenuManager; Menu m_menu; @@ -124,11 +124,11 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub class LinearViewStatusBarWidget : public StatusBarWidget { - public: + public: LinearViewStatusBarWidget(LinearView* parent); virtual void updateStatus() override; - private: + private: LinearView* m_view; LinearViewOptionsWidget* m_options; ILChooserWidget* m_chooser; @@ -199,7 +199,7 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub void refreshAtCurrentLocation(bool cursorFixup = false); bool navigateToAddress(uint64_t addr, bool center, bool updateHighlight, bool navByRef = false); bool navigateToLine( - FunctionRef func, uint64_t offset, size_t instrIndex, bool center, bool updateHighlight, bool navByRef = false); + FunctionRef func, uint64_t offset, size_t instrIndex, bool center, bool updateHighlight, bool navByRef = false); bool navigateToGotoLabel(uint64_t label); void viewData(); @@ -209,7 +209,7 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub static void addOptionsMenuActions(Menu& menu); void getHexDumpLineBytes( - const BinaryNinja::LinearDisassemblyLine& line, size_t& skippedBytes, size_t& totalBytes, size_t& totalCols); + const BinaryNinja::LinearDisassemblyLine& line, size_t& skippedBytes, size_t& totalBytes, size_t& totalCols); void paintHexDumpLine(QPainter& p, const LinearViewLine& line, int xoffset, int y, uint32_t addrLen, int tagOffset); void paintAnalysisWarningLine(QPainter& p, const LinearViewLine& line, int xoffset, int y); @@ -223,9 +223,9 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub TypeRef createStructure(BinaryNinja::QualifiedName& name, uint64_t size); TypeRef getInnerType(TypeRef type, uint64_t offset, uint64_t size, std::set<TypeRef>& seen); StructureRef defineInnerType( - TypeRef type, TypeRef baseType, uint64_t offset, uint64_t size, std::set<TypeRef>& seen); + TypeRef type, TypeRef baseType, uint64_t offset, uint64_t size, std::set<TypeRef>& seen); StructureRef defineInnerPointer(TypeRef type, ArchitectureRef arch, uint64_t baseAddress, uint64_t offset, - uint64_t size, std::set<TypeRef>& seen); + uint64_t size, std::set<TypeRef>& seen); StructureRef defineInnerStruct(TypeRef type, uint64_t offset, uint64_t size, std::set<TypeRef>& seen); StructureRef defineInnerArray(TypeRef type, uint64_t offset, uint64_t size, std::set<TypeRef>& seen); StructureRef defineInnerName(TypeRef type, uint64_t offset, uint64_t size, std::set<TypeRef>& seen); @@ -239,7 +239,7 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub bool updateCursor(LinearViewCursorPosition& cursorToUpdate, BinaryNinja::LinearViewCursor* matched, bool fullMatch); bool updateCursor(LinearViewCursorPosition& cursorToUpdate, BinaryNinja::LinearViewCursor* newCursor); bool updateCursor(LinearViewCursorPosition& cursorToUpdate, - const std::vector<BinaryNinja::LinearViewObjectIdentifier>& path, BinaryNinja::LinearViewCursor* newCursor); + const std::vector<BinaryNinja::LinearViewObjectIdentifier>& path, BinaryNinja::LinearViewCursor* newCursor); uint64_t getOrderingIndexForLine(const LinearViewLine& line); void updateAnalysisRequestorsForCache(); @@ -250,13 +250,13 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub BNAnalysisWarningActionType getAnalysisWarningActionAtPos(const LinearViewLine& line, int x); void getCurrentOffsetByTypeInternal( - TypeRef resType, uint64_t baseAddr, uint64_t& begin, uint64_t& end, bool singleLine, std::set<TypeRef>& seen); + TypeRef resType, uint64_t baseAddr, uint64_t& begin, uint64_t& end, bool singleLine, std::set<TypeRef>& seen); BNDeadStoreElimination getCurrentVariableDeadStoreElimination(); void setDataButtonVisible(bool visible); - private Q_SLOTS: +private Q_SLOTS: void adjustSize(int width, int height); void viewInHexEditor(); void viewInGraph(); @@ -310,6 +310,7 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub void createArray(); void createStruct(); void createNewTypes(); + void mergeVariables(); //! Get the length of of the string (if there is one) starting at the //! given address. String type is assumed to be UTF-8 by default, but the @@ -335,10 +336,10 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub void setCurrentVariableDeadStoreElimination(BNDeadStoreElimination elimination); - Q_SIGNALS: +Q_SIGNALS: void notifyResizeEvent(int width, int height); - public: +public: explicit LinearView(BinaryViewRef data, ViewFrame* view); virtual ~LinearView(); @@ -423,7 +424,7 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub static void registerActions(); - protected: +protected: virtual void resizeEvent(QResizeEvent* event) override; virtual void paintEvent(QPaintEvent* event) override; virtual void wheelEvent(QWheelEvent* event) override; @@ -452,7 +453,7 @@ class LinearViewType : public ViewType { static LinearViewType* m_instance; - public: +public: LinearViewType(); virtual int getPriority(BinaryViewRef data, const QString& filename) override; virtual QWidget* create(BinaryViewRef data, ViewFrame* viewFrame) override; diff --git a/ui/mergevariablesdialog.h b/ui/mergevariablesdialog.h new file mode 100644 index 00000000..b4c81c06 --- /dev/null +++ b/ui/mergevariablesdialog.h @@ -0,0 +1,76 @@ +#pragma once + +#include <QtWidgets/QDialog> +#include <QtWidgets/QComboBox> +#include <QtWidgets/QListWidget> +#include <QtWidgets/QListWidgetItem> +#include <QtWidgets/QStyledItemDelegate> + +#include <string> +#include "binaryninjaapi.h" +#include "uicontext.h" +#include "render.h" + +class BINARYNINJAUIAPI MergeVariableHeader : public QWidget +{ + std::vector<BinaryNinja::InstructionTextToken> m_tokens; + RenderContext m_renderContext; + int m_length; + +protected: + void paintEvent(QPaintEvent* event) override; + QSize sizeHint() const override; + +public: + MergeVariableHeader(const std::vector<BinaryNinja::InstructionTextToken>& tokens, QWidget* parent = nullptr); +}; + +class BINARYNINJAUIAPI MergeVariableListItem : public QListWidgetItem +{ + QWidget* m_owner; + FunctionRef m_func; + BinaryNinja::Variable m_var; + std::string m_name; + BinaryNinja::Confidence<BinaryNinja::Ref<BinaryNinja::Type>> m_type; + bool m_grayed; + +public: + MergeVariableListItem(QWidget* parent, BinaryNinja::Function* func, const BinaryNinja::Variable& var, + const std::string& name, BinaryNinja::Confidence<BinaryNinja::Ref<BinaryNinja::Type>> type, + const QString& warnings, bool grayed); + const BinaryNinja::Variable& variable() const { return m_var; } + virtual QVariant data(int role) const override; + + static std::vector<BinaryNinja::InstructionTextToken> tokensForVariable(BinaryNinja::Function* func, + const BinaryNinja::Variable& var, BinaryNinja::Confidence<BinaryNinja::Ref<BinaryNinja::Type>> type, + const std::string& name); +}; + +class BINARYNINJAUIAPI MergeVariableItemDelegate : public QStyledItemDelegate +{ + Q_OBJECT + + QWidget* m_parent; + QFont m_font; + int m_baseline, m_charWidth, m_charHeight, m_charOffset; + +public: + MergeVariableItemDelegate(QWidget* parent); + + void updateFonts(); + virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& idx) const override; + virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& idx) const override; +}; + +class BINARYNINJAUIAPI MergeVariablesDialog : public QDialog +{ + Q_OBJECT + QListWidget* m_list; + std::set<BinaryNinja::Variable> m_existingVariables; + +public: + MergeVariablesDialog(QWidget* parent, FunctionRef func, BinaryNinja::Variable target); + + std::set<BinaryNinja::Variable> mergedVariables(); + std::set<BinaryNinja::Variable> unmergedVariables(); +}; diff --git a/ui/uitypes.h b/ui/uitypes.h index f16a84eb..b47444e4 100644 --- a/ui/uitypes.h +++ b/ui/uitypes.h @@ -6,7 +6,7 @@ // there are changes to the API that affect linking, including new functions, // new types, modifications to existing functions or types, or new versions // of the Qt libraries. -#define BN_CURRENT_UI_ABI_VERSION 5 +#define BN_CURRENT_UI_ABI_VERSION 6 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and |
