From 3dd22f40996fc128ffce6026e8e747ca66bcc21d Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Mon, 22 Jan 2024 16:11:19 -0500 Subject: Project support --- ui/externallocationdialog.h | 29 ++++++++++++++++++++++++++++ ui/linearview.h | 5 +++++ ui/options.h | 1 + ui/settingsview.h | 6 ++++-- ui/uicontext.h | 46 ++++++++++++++++++++++++++++++++++++++++++++- ui/uitypes.h | 5 +++++ ui/util.h | 2 +- 7 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 ui/externallocationdialog.h (limited to 'ui') diff --git a/ui/externallocationdialog.h b/ui/externallocationdialog.h new file mode 100644 index 00000000..c86eea70 --- /dev/null +++ b/ui/externallocationdialog.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include +#include +#include "uitypes.h" + + +class BINARYNINJAUIAPI ExternalLocationDialog : public QDialog +{ + QPushButton* m_acceptButton; + QPushButton* m_cancelButton; + + QLineEdit* m_internalSymbolField; + QComboBox* m_libraryField; + QLineEdit* m_externalSymbolField; + QLineEdit* m_addressField; + + BinaryViewRef m_data; + ExternalLocationRef m_location; + + void Submit(); + + void updateForm(); + +public: + ExternalLocationDialog(QWidget* parent, BinaryViewRef data, ExternalLocationRef loc = nullptr, ExternalLibraryRef lib = nullptr, std::optional rawSym = {}); +}; diff --git a/ui/linearview.h b/ui/linearview.h index 7f590ce0..936ceb59 100644 --- a/ui/linearview.h +++ b/ui/linearview.h @@ -251,6 +251,7 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub bool navigateToLine( FunctionRef func, uint64_t offset, size_t instrIndex, bool center, bool updateHighlight, bool navByRef = false); bool navigateToGotoLabel(uint64_t label); + bool navigateToExternalLink(uint64_t linkSourceAddr); void viewData(); void scrollLines(int count); @@ -335,6 +336,10 @@ private Q_SLOTS: void tagAddressAccepted(TagTypeRef tt); void manageAddressTags(); + void createExternalLink(); + void editExternalLink(); + void removeExternalLink(); + void convertToNop(); void alwaysBranch(); void invertBranch(); diff --git a/ui/options.h b/ui/options.h index 0bfba08c..4c7153c7 100644 --- a/ui/options.h +++ b/ui/options.h @@ -43,6 +43,7 @@ class BINARYNINJAUIAPI OptionsDialog : public QDialog FileContext* m_file = nullptr; FileMetadataRef m_fileMetadata = nullptr; BinaryViewRef m_rawData = nullptr; + ProjectRef m_project = nullptr; std::vector> m_objects; const std::string m_oldFlag = "old:"; diff --git a/ui/settingsview.h b/ui/settingsview.h index 8ec548b7..812eed3c 100644 --- a/ui/settingsview.h +++ b/ui/settingsview.h @@ -371,9 +371,9 @@ class BINARYNINJAUIAPI SettingsScopeBar : public QWidget Q_OBJECT QPushButton* m_userLabel; - BinaryViewScopeLabel* m_projectLabel; + QPushButton* m_projectLabel; BinaryViewScopeLabel* m_resourceLabel; - ClickableLabel* m_openProjectLabel; + //ClickableLabel* m_openProjectLabel; QLabel* m_desc; unsigned long m_highlightIdx; @@ -384,6 +384,7 @@ class BINARYNINJAUIAPI SettingsScopeBar : public QWidget void refresh(); void setResource(BinaryViewRef view); + void setScope(BNSettingsScope scope); void updateTheme(); Q_SIGNALS: @@ -453,6 +454,7 @@ class BINARYNINJAUIAPI SettingsView : public QWidget void refreshAllSettings(); void refreshCurrentScope(); void setData(BinaryViewRef view, const QString& name = ""); + void setScope(BNSettingsScope scope); void setDefaultGroupSelection(const QString& group, const QString& subgroup = ""); void focusSearch(); void setSearchFilter(const QString& filter) { if (m_search) m_search->setText(filter); }; diff --git a/ui/uicontext.h b/ui/uicontext.h index 99abb84e..df4ff0a2 100644 --- a/ui/uicontext.h +++ b/ui/uicontext.h @@ -7,6 +7,7 @@ #include "binaryninjaapi.h" #include "action.h" #include "preview.h" +#include "uitypes.h" #define PREVIEW_HOVER_TIME 500 @@ -78,6 +79,41 @@ class BINARYNINJAUIAPI UIContextNotification (void)data; return true; } + /*! + Callback after a project is opened + \param context Context which opened the project + \param project Project that was opened + \param frame ViewFrame constructed to display the project + */ + virtual void OnAfterOpenProject(UIContext* context, ProjectRef project) + { + (void)context; + (void)project; + } + /*! + Callback before a project file is opened + \param context Context opening the project file + \param projectFile Project file that is being opened + \return True if the project file should be opened + */ + virtual bool OnBeforeOpenProjectFile(UIContext* context, ProjectFileRef projectFile) + { + (void)context; + (void)projectFile; + return true; + } + /*! + Callback after a project file is opened + \param context Context which opened the project file + \param projectFile Project file that was opened + \param frame ViewFrame constructed to display the project file + */ + virtual void OnAfterOpenProjectFile(UIContext* context, ProjectFileRef projectFile, ViewFrame* frame) + { + (void)context; + (void)projectFile; + (void)frame; + } /*! Callback before a file (raw or database) is opened (after OnAfterOpenDatabase if opening a database) \param context Context opening the file @@ -264,6 +300,9 @@ class BINARYNINJAUIAPI UIContext bool NotifyOnBeforeOpenDatabase(FileMetadataRef metadata); bool NotifyOnAfterOpenDatabase(FileMetadataRef metadata, BinaryViewRef data); + void NotifyOnAfterOpenProject(ProjectRef project); + bool NotifyOnBeforeOpenProjectFile(ProjectFileRef projectFile); + void NotifyOnAfterOpenProjectFile(ProjectFileRef projectFile, ViewFrame* frame); bool NotifyOnBeforeOpenFile(FileContext* file); void NotifyOnAfterOpenFile(FileContext* file, ViewFrame* frame); bool NotifyOnBeforeSaveFile(FileContext* file, ViewFrame* frame); @@ -326,8 +365,9 @@ public: Open a tab containing the given widget with the given name \param name Name for tab \param widget Widget to display in the tab (optionally a ViewFrame) + \return Index of created tab */ - virtual void createTabForWidget(const QString& name, QWidget* widget) = 0; + virtual int createTabForWidget(const QString& name, QWidget* widget) = 0; /*! * Open a new window with the same file context and Navigate to a given location @@ -409,8 +449,12 @@ public: */ virtual std::vector getAllViewFramesForTab(QWidget* tab) const = 0; + virtual ProjectRef getProject(); + virtual bool openFilename(const QString& path, bool openOptions = false); + virtual ProjectRef openProject(const QString& path); virtual ViewFrame* openFileContext(FileContext* file, const QString& forcedView = "", bool addTab = true); + virtual bool openProjectFile(ProjectFileRef file, ExternalLocationRef loc = nullptr, bool openWithOptions = false); virtual void recreateViewFrames(FileContext* file) = 0; UIActionHandler* globalActions() { return &m_globalActions; } diff --git a/ui/uitypes.h b/ui/uitypes.h index 083c4ac5..49ef0480 100644 --- a/ui/uitypes.h +++ b/ui/uitypes.h @@ -75,6 +75,8 @@ typedef BinaryNinja::Ref DisassemblySettingsRe typedef BinaryNinja::Ref DownloadInstanceRef; typedef BinaryNinja::Ref DownloadProviderRef; typedef BinaryNinja::Ref EnumerationRef; +typedef BinaryNinja::Ref ExternalLibraryRef; +typedef BinaryNinja::Ref ExternalLocationRef; typedef BinaryNinja::Ref FileMetadataRef; typedef BinaryNinja::Ref FlowGraphRef; typedef BinaryNinja::Ref FlowGraphLayoutRequestRef; @@ -86,6 +88,9 @@ typedef BinaryNinja::Ref MainThreadActionRef; typedef BinaryNinja::Ref MediumLevelILFunctionRef; typedef BinaryNinja::Ref HighLevelILFunctionRef; typedef BinaryNinja::Ref PlatformRef; +typedef BinaryNinja::Ref ProjectRef; +typedef BinaryNinja::Ref ProjectFileRef; +typedef BinaryNinja::Ref ProjectFolderRef; typedef BinaryNinja::Ref ReportCollectionRef; typedef BinaryNinja::Ref SaveSettingsRef; typedef BinaryNinja::Ref ScriptingInstanceRef; diff --git a/ui/util.h b/ui/util.h index a49fc007..a733acea 100644 --- a/ui/util.h +++ b/ui/util.h @@ -29,7 +29,7 @@ bool BINARYNINJAUIAPI showDisassemblyPreview(QWidget* parent, ViewFrame* frame, const ViewLocation& location); void BINARYNINJAUIAPI showTextTooltip(QWidget* parent, const QPoint& previewPos, const QString& text); -bool BINARYNINJAUIAPI isBinaryNinjaDataBase(QFileInfo& info, QFileAccessor& accessor); +bool BINARYNINJAUIAPI isBinaryNinjaDatabase(QFileInfo& info, QFileAccessor& accessor); PlatformRef BINARYNINJAUIAPI getOrAskForPlatform(QWidget* parent, BinaryViewRef data); PlatformRef BINARYNINJAUIAPI getOrAskForPlatform(QWidget* parent, PlatformRef defaultValue); -- cgit v1.3.1