summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2023-11-01 17:03:17 -0400
committerGlenn Smith <glenn@vector35.com>2024-02-07 17:23:49 -0500
commit8037455723546000448135499957273623776581 (patch)
tree268322ef34d16e067210df592dd782d50f294e3c /ui
parente1542ed05f3f8c273206bb9ead8d39fea87430bb (diff)
Type Archives
Diffstat (limited to 'ui')
-rw-r--r--ui/commands.h4
-rw-r--r--ui/createstructdialog.h8
-rw-r--r--ui/typebrowser.h76
-rw-r--r--ui/typedialog.h12
-rw-r--r--ui/uitypes.h1
5 files changed, 86 insertions, 15 deletions
diff --git a/ui/commands.h b/ui/commands.h
index 62016bdb..441ca0ed 100644
--- a/ui/commands.h
+++ b/ui/commands.h
@@ -21,7 +21,7 @@ bool BINARYNINJAUIAPI inputNameForType(
QWidget* parent, std::string& name, const QString& title = "Set Name", const QString& msg = "Enter name:");
bool BINARYNINJAUIAPI InferArraySize(TypeRef& type, size_t selectionSize);
-bool BINARYNINJAUIAPI askForNewType(QWidget* parent, BinaryViewRef data, FunctionRef func, const std::string& title,
+bool BINARYNINJAUIAPI askForNewType(QWidget* parent, std::optional<BinaryNinja::TypeContainer> container, const std::string& title,
bool allowZeroSize, TypeRef& type, BinaryNinja::QualifiedName& name);
bool BINARYNINJAUIAPI inputNewType(QWidget* parent, BinaryViewRef data, FunctionRef currentFunction,
uint64_t currentAddr, size_t selectionSize, HighlightTokenState& highlight);
@@ -51,7 +51,7 @@ uint64_t BINARYNINJAUIAPI getInnerMostStructureOffset(
BinaryViewRef data, StructureRef structure, const std::vector<std::string>& nameList, size_t nameIndex);
// Auto generate a structure name
-std::string BINARYNINJAUIAPI createStructureName(BinaryViewRef data);
+std::string BINARYNINJAUIAPI createStructureName(BinaryNinja::TypeContainer types);
std::optional<BinaryNinja::Variable> BINARYNINJAUIAPI getSplitVariableForAssignment(
FunctionRef func, BNFunctionGraphType ilType, uint64_t location, const BinaryNinja::Variable& var);
diff --git a/ui/createstructdialog.h b/ui/createstructdialog.h
index 149a0583..0e331a2a 100644
--- a/ui/createstructdialog.h
+++ b/ui/createstructdialog.h
@@ -28,13 +28,13 @@ class BINARYNINJAUIAPI GetStructuresListThread : public QThread
std::function<void()> m_completeFunc;
std::mutex m_mutex;
bool m_done;
- BinaryViewRef m_view;
+ BinaryNinja::TypeContainer m_container;
protected:
virtual void run() override;
public:
- GetStructuresListThread(BinaryViewRef view, const std::function<void()>& completeFunc);
+ GetStructuresListThread(BinaryNinja::TypeContainer container, const std::function<void()>& completeFunc);
void cancel();
const QStringList& getTypes() const { return m_allTypes; }
@@ -79,7 +79,7 @@ class BINARYNINJAUIAPI CreateStructDialog : public QDialog
QCheckBox* m_propagateDataVarRefs;
QCheckBox* m_pointer;
- BinaryViewRef m_view;
+ std::optional<BinaryNinja::TypeContainer> m_typeContainer;
BinaryNinja::QualifiedName m_resultName;
uint64_t m_resultSize;
bool m_resultDataVarRefs;
@@ -95,7 +95,7 @@ class BINARYNINJAUIAPI CreateStructDialog : public QDialog
virtual void customEvent(QEvent* event) override;
public:
- CreateStructDialog(QWidget* parent, BinaryViewRef view, const std::string& name, bool askForPointer = false,
+ CreateStructDialog(QWidget* parent, std::optional<BinaryNinja::TypeContainer> typeContainer, const std::string& name, bool askForPointer = false,
bool defaultToPointer = false);
~CreateStructDialog();
diff --git a/ui/typebrowser.h b/ui/typebrowser.h
index 006568fa..36150597 100644
--- a/ui/typebrowser.h
+++ b/ui/typebrowser.h
@@ -111,6 +111,7 @@ public:
{
None,
TypeLibrary,
+ TypeArchive,
DebugInfo,
Platform,
Other
@@ -124,6 +125,7 @@ private:
SourceType m_sourceType;
std::optional<TypeLibraryRef> m_sourceLibrary;
+ std::optional<TypeArchiveRef> m_sourceArchive;
std::optional<std::string> m_sourceDebugInfoParser;
std::optional<PlatformRef> m_sourcePlatform;
std::optional<std::string> m_sourceOtherName;
@@ -179,7 +181,7 @@ protected:
//-----------------------------------------------------------------------------
-class BINARYNINJAUIAPI TypeBrowserModel : public QAbstractItemModel, public BinaryNinja::BinaryDataNotification
+class BINARYNINJAUIAPI TypeBrowserModel : public QAbstractItemModel, public BinaryNinja::BinaryDataNotification, public BinaryNinja::TypeArchiveNotification
{
Q_OBJECT
BinaryViewRef m_data;
@@ -197,12 +199,15 @@ class BINARYNINJAUIAPI TypeBrowserModel : public QAbstractItemModel, public Bina
std::map<std::string, BinaryNinja::TypeContainer> m_containers;
std::map<std::string, BinaryViewRef> m_containerViews;
+ std::map<std::string, TypeArchiveRef> m_containerArchives;
+ std::map<std::string, std::string> m_containerArchiveIds;
std::map<std::string, TypeLibraryRef> m_containerLibraries;
std::map<std::string, DebugInfoRef> m_containerDebugInfos;
std::map<std::string, PlatformRef> m_containerPlatforms;
- void updateContainerList();
+ void addContainer(BinaryNinja::TypeContainer cont);
void callUpdateCallbacks();
+ void commitUpdate(TypeBrowserTreeNode::UpdateData& update);
void commitUpdates(std::vector<TypeBrowserTreeNode::UpdateData>& updates);
public:
@@ -217,10 +222,24 @@ public:
std::optional<std::reference_wrapper<BinaryNinja::TypeContainer>> containerForContainerId(const std::string& id);
std::optional<std::reference_wrapper<const BinaryNinja::TypeContainer>> containerForContainerId(const std::string& id) const;
std::optional<BinaryViewRef> viewForContainerId(const std::string& id) const;
+ std::optional<TypeArchiveRef> archiveForContainerId(const std::string& id) const;
+ std::optional<std::string> archiveIdForContainerId(const std::string& id) const;
std::optional<TypeLibraryRef> libraryForContainerId(const std::string& id) const;
std::optional<DebugInfoRef> debugInfoForContainerId(const std::string& id) const;
std::optional<PlatformRef> platformForContainerId(const std::string& id) const;
+ void addAllContainersForView(BinaryViewRef view);
+
+ void addContainerForView(BinaryViewRef view);
+ void addUserContainerForView(BinaryViewRef view);
+ void addAutoContainerForView(BinaryViewRef view);
+ void addContainerForArchive(TypeArchiveRef archive);
+ void addContainerForArchiveId(const std::string& archiveId, const std::string& path);
+ void addContainerForLibrary(TypeLibraryRef library);
+ void addContainerForDebugInfo(DebugInfoRef debugInfo, const std::string& parser);
+ void addContainerForPlatform(PlatformRef platform);
+ void clearContainers();
+
void updateFonts();
void runAfterUpdate(std::function<void()> callback);
@@ -244,6 +263,16 @@ public:
void OnTypeReferenceChanged(BinaryNinja::BinaryView* data, const BinaryNinja::QualifiedName& name, BinaryNinja::Type* type) override;
void OnTypeFieldReferenceChanged(BinaryNinja::BinaryView* data, const BinaryNinja::QualifiedName& name, uint64_t offset) override;
+ void OnTypeAdded(TypeArchiveRef archive, const std::string& id, TypeRef definition) override;
+ void OnTypeUpdated(TypeArchiveRef archive, const std::string& id, TypeRef oldDefinition, TypeRef newDefinition) override;
+ void OnTypeRenamed(TypeArchiveRef archive, const std::string& id, const BinaryNinja::QualifiedName& oldName, const BinaryNinja::QualifiedName& newName) override;
+ void OnTypeDeleted(TypeArchiveRef archive, const std::string& id, TypeRef definition) override;
+
+ void OnTypeArchiveAttached(BinaryNinja::BinaryView* data, const std::string& id, const std::string& path) override;
+ void OnTypeArchiveDetached(BinaryNinja::BinaryView* data, const std::string& id, const std::string& path) override;
+ void OnTypeArchiveConnected(BinaryNinja::BinaryView* data, BinaryNinja::TypeArchive* archive) override;
+ void OnTypeArchiveDisconnected(BinaryNinja::BinaryView* data, BinaryNinja::TypeArchive* archive) override;
+
Q_SIGNALS:
void updatesAboutToHappen();
void updateComplete();
@@ -290,6 +319,7 @@ class BINARYNINJAUIAPI TypeBrowserItemDelegate : public QItemDelegate
void initFont();
public:
TypeBrowserItemDelegate(class TypeBrowserView* view);
+ int lineHeight() const;
void updateFonts();
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
@@ -340,6 +370,8 @@ class BINARYNINJAUIAPI TypeBrowserView : public QFrame, public View, public Filt
TypeEditor* m_typeEditor;
QTextEdit* m_debugText;
+ void updateInTransaction(std::function<bool()> transaction);
+
public:
TypeBrowserView(BinaryViewRef data, TypeBrowserContainer* container);
@@ -401,17 +433,53 @@ public:
// makeSureItHasPlatform: if the type container is a BV with no platform (raw), ask for one and return nullopt if rejected
// preferView: if the type container is a BV and the user/auto-only container, switch to the whole-view container for that BV instead
std::optional<BinaryNinja::TypeContainer> selectedTypeContainer(bool makeSureItHasPlatform = true, bool preferView = false) const;
+ // Same as above, but if it returns nullopt, try again with m_data
+ std::optional<BinaryNinja::TypeContainer> selectedTypeContainerOrMData(bool makeSureItHasPlatform = true, bool preferView = false) const;
+
+ // TA selected or TA relevant to selected types, only if JUST ta stuff is selected and only 1 TA
+ std::optional<TypeArchiveRef> selectedTA() const;
+ // Id of TA selected or TA relevant to selected types, only if JUST ta stuff is selected and only 1 TA
+ std::optional<std::string> selectedTAId() const;
+ // TAs selected or TAs relevant to selected types, only if JUST ta stuff is selected
+ std::optional<std::unordered_set<TypeArchiveRef>> selectedTAs() const;
+ // Ids of TAs selected or TAs relevant to selected types, only if JUST ta stuff is selected
+ std::optional<std::unordered_set<std::string>> selectedTAIds() const;
+ // If selectedTAs exist, map of ta ids to ids of selected types from that ta
+ std::optional<std::unordered_map<std::string, std::unordered_set<std::string>>> selectedTATypeIds() const;
+ // All type archives that are attached and connected
+ std::vector<TypeArchiveRef> connectedTAs(BinaryViewRef view) const;
// Names -> Ids, if any don't exist then nullopt
static std::optional<std::unordered_set<std::string>> typeIdsFromNames(BinaryViewRef view, const std::unordered_set<BinaryNinja::QualifiedName>& names);
+ // Ids -> Option<TypeArchive>
+ static std::unordered_map<std::optional<TypeArchiveRef>, std::unordered_set<std::string>> associatedTypeArchivesForTypeIds(BinaryViewRef view, const std::unordered_set<std::string>& typeIds);
- std::optional<std::reference_wrapper<BinaryNinja::TypeContainer>> containerForId(const std::string& containerId, bool makeSureItHasPlatform = false, bool preferView = false);
+ std::optional<BinaryNinja::TypeContainer> containerForId(const std::string& containerId, bool makeSureItHasPlatform = false, bool preferView = false) const;
// Menu actions
static void registerActions();
void bindActions();
void showContextMenu();
+ bool canConnectTypeArchive();
+ void connectTypeArchive();
+
+ bool canCreateTypeArchive();
+ void createTypeArchive();
+ bool canAttachTypeArchive();
+ void attachTypeArchive();
+ bool canDetachTypeArchive();
+ void detachTypeArchive();
+
+ bool canSyncSelectedTypes();
+ void syncSelectedTypes();
+ bool canPushSelectedTypes();
+ void pushSelectedTypes();
+ bool canPullSelectedTypes();
+ void pullSelectedTypes();
+ bool canDisassociateSelectedTypes();
+ void disassociateSelectedTypes();
+
bool canCreateNewTypes();
void createNewTypes();
bool canCreateNewStructure();
@@ -435,6 +503,8 @@ public:
void expandAll();
bool canCollapseAll();
void collapseAll();
+ bool canSwitchLayout();
+ void switchLayout();
Q_SIGNALS:
void typeNameNavigated(const std::string& typeName, bool newSelection);
diff --git a/ui/typedialog.h b/ui/typedialog.h
index 1825fdb5..f2173c93 100644
--- a/ui/typedialog.h
+++ b/ui/typedialog.h
@@ -36,13 +36,13 @@ class BINARYNINJAUIAPI GetTypesListThread : public QThread
std::function<void()> m_completeFunc;
std::mutex m_mutex;
bool m_done;
- BinaryViewRef m_view;
+ BinaryNinja::TypeContainer m_typeContainer;
protected:
virtual void run() override;
public:
- GetTypesListThread(BinaryViewRef view, const std::function<void()>& completeFunc);
+ GetTypesListThread(BinaryNinja::TypeContainer typeContainer, const std::function<void()>& completeFunc);
void cancel();
const QStringList& getTypes() const { return m_allTypes; }
@@ -58,7 +58,7 @@ class ParseTypeThread : public QThread
{
Q_OBJECT
- BinaryViewRef m_view;
+ std::optional<BinaryNinja::TypeContainer> m_typeContainer;
std::string m_text;
void run() override;
@@ -67,7 +67,7 @@ class ParseTypeThread : public QThread
void parsingComplete(bool valid, BinaryNinja::QualifiedNameAndType type, QString error);
public:
- ParseTypeThread(BinaryViewRef view, QString text);
+ ParseTypeThread(std::optional<BinaryNinja::TypeContainer> typeContainer, QString text);
void cancel();
};
#endif
@@ -84,7 +84,7 @@ class BINARYNINJAUIAPI TypeDialog : public QDialog
QStringListModel* m_model;
QLabel* m_prompt;
QString m_promptText;
- BinaryViewRef m_view;
+ std::optional<BinaryNinja::TypeContainer> m_typeContainer;
bool m_resultValid;
QStringList m_historyEntries;
int m_historySize;
@@ -113,7 +113,7 @@ class BINARYNINJAUIAPI TypeDialog : public QDialog
void updateTimerEvent();
public:
- TypeDialog(QWidget* parent, BinaryViewRef view, const QString& title = "Specify Type",
+ TypeDialog(QWidget* parent, std::optional<BinaryNinja::TypeContainer> typeContainer, const QString& title = "Specify Type",
const QString& prompt = "Enter Type Name", const QString& existing = "");
~TypeDialog();
BinaryNinja::QualifiedNameAndType getType() const { return m_type; }
diff --git a/ui/uitypes.h b/ui/uitypes.h
index 49ef0480..d2f43868 100644
--- a/ui/uitypes.h
+++ b/ui/uitypes.h
@@ -107,6 +107,7 @@ typedef BinaryNinja::Ref<BinaryNinja::TagType> TagTypeRef;
typedef BinaryNinja::Ref<BinaryNinja::TemporaryFile> TemporaryFileRef;
typedef BinaryNinja::Ref<BinaryNinja::Transform> TransformRef;
typedef BinaryNinja::Ref<BinaryNinja::Type> TypeRef;
+typedef BinaryNinja::Ref<BinaryNinja::TypeArchive> TypeArchiveRef;
typedef BinaryNinja::Ref<BinaryNinja::TypeLibrary> TypeLibraryRef;
typedef BinaryNinja::Ref<BinaryNinja::WebsocketClient> WebsocketClientRef;
typedef BinaryNinja::Ref<BinaryNinja::WebsocketProvider> WebsocketProviderRef;