From 9b008755f81cf3019c81af9f59d82b05ade0d9b5 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Sat, 7 Feb 2026 12:04:49 -0800 Subject: Refactor where architecture selection is performed for universal binaries Responsibility for selecting an architecture is moved out of `UniversalTransform` and into a new `ContainerOpenRequest` class. `UniversalTransform` still handles architecture selection in headless operation (for now). --- ui/containerbrowser.h | 5 +++++ ui/containeropenrequest.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 ui/containeropenrequest.h (limited to 'ui') diff --git a/ui/containerbrowser.h b/ui/containerbrowser.h index 363e5446..b9ba278f 100644 --- a/ui/containerbrowser.h +++ b/ui/containerbrowser.h @@ -15,6 +15,7 @@ #include +class ContainerOpenRequest; class ContainerTreeModel : public QAbstractItemModel { @@ -121,4 +122,8 @@ public: bool openWithOptionsRequested() const { return m_openWithOptionsRequested; } static std::vector openContainerFile(const QString& path, bool forceShowDialog = false, bool* outOpenWithOptions = nullptr); + + // Show the container browser dialog for the given open request. + // Returns the selected contexts, or empty if the user cancelled. + static std::vector showBrowser(ContainerOpenRequest& request, bool* outOpenWithOptions = nullptr); }; diff --git a/ui/containeropenrequest.h b/ui/containeropenrequest.h new file mode 100644 index 00000000..55d8923e --- /dev/null +++ b/ui/containeropenrequest.h @@ -0,0 +1,46 @@ +#pragma once + +#include "uitypes.h" + +#include +#include +#include + + +// Captures user settings and intent for opening a container file, and provides +// policy decisions (e.g. whether to show the container browser) after processing. +class BINARYNINJAUIAPI ContainerOpenRequest +{ +public: + enum Action { + Cancel, + AutoOpen, + BrowseContainer, + }; + + explicit ContainerOpenRequest(const std::string& path, bool forceContainerBrowser = false); + + TransformSessionRef session() const { return m_session; } + + // Create the session, process it, and determine what action the caller + // should take. Returns Cancel if the session could not be created. + Action resolve(); + + // Get the default selection from a processed session. If no selection has + // been made (e.g. because the session auto-opened), selects the current leaf. + std::vector selectedContexts(); + + // When the container is a universal binary, the available architectures and the + // index of the preferred one (if any). + const std::vector& architectureContexts() const { return m_archContexts; } + std::optional preferredArchitectureIndex() const { return m_preferredArch; } + +private: + Action resolveUniversal(TransformContextRef universalCtx); + + TransformSessionRef m_session; + std::vector m_archContexts; + std::optional m_preferredArch; + bool m_forceContainerBrowser = false; + bool m_autoOpen = false; +}; -- cgit v1.3.1