Skip to content

Commit 5a99579

Browse files
committed
This reverts commit 7228ba0.
1 parent e5c73ff commit 5a99579

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

ui/containerbrowser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <vector>
1717

18+
class ContainerOpenRequest;
1819

1920
class ContainerTreeModel : public QAbstractItemModel
2021
{
@@ -121,4 +122,8 @@ class BINARYNINJAUIAPI ContainerBrowser : public QDialog
121122
bool openWithOptionsRequested() const { return m_openWithOptionsRequested; }
122123

123124
static std::vector<TransformContextRef> openContainerFile(const QString& path, bool forceShowDialog = false, bool* outOpenWithOptions = nullptr);
125+
126+
// Show the container browser dialog for the given open request.
127+
// Returns the selected contexts, or empty if the user cancelled.
128+
static std::vector<TransformContextRef> showBrowser(ContainerOpenRequest& request, bool* outOpenWithOptions = nullptr);
124129
};

ui/containeropenrequest.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
3+
#include "uitypes.h"
4+
5+
#include <optional>
6+
#include <string>
7+
#include <vector>
8+
9+
10+
// Captures user settings and intent for opening a container file, and provides
11+
// policy decisions (e.g. whether to show the container browser) after processing.
12+
class BINARYNINJAUIAPI ContainerOpenRequest
13+
{
14+
public:
15+
enum Action {
16+
Cancel,
17+
AutoOpen,
18+
BrowseContainer,
19+
SelectArchitecture,
20+
};
21+
22+
explicit ContainerOpenRequest(const std::string& path, bool forceContainerBrowser = false);
23+
24+
TransformSessionRef session() const { return m_session; }
25+
26+
// Create the session, process it, and determine what action the caller
27+
// should take. Returns Cancel if the session could not be created.
28+
Action resolve();
29+
30+
// Get the default selection from a processed session. If no selection has
31+
// been made (e.g. because the session auto-opened), selects the current leaf.
32+
std::vector<TransformContextRef> selectedContexts();
33+
34+
// When the container is a universal binary, the available architectures and the
35+
// index of the preferred one (if any).
36+
const std::vector<TransformContextRef>& architectureContexts() const { return m_archContexts; }
37+
std::optional<size_t> preferredArchitectureIndex() const { return m_preferredArch; }
38+
39+
private:
40+
Action resolveUniversal(TransformContextRef universalCtx);
41+
42+
TransformSessionRef m_session;
43+
std::vector<TransformContextRef> m_archContexts;
44+
std::optional<size_t> m_preferredArch;
45+
bool m_forceContainerBrowser = false;
46+
bool m_autoOpen = false;
47+
};

view/macho/universaltransform.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,20 @@ bool UniversalTransform::DecodeWithContext(Ref<TransformContext> context, const
266266
architectures.push_back(archName);
267267
}
268268

269-
if (!context->IsInteractive())
269+
// TODO: It is surprising that this is UniversalTransform's responsibility.
270+
if (!BinaryNinja::IsUIEnabled())
270271
{
272+
// When headless, filter to the preferred architecture if one is configured.
271273
vector<string> archPref = context->GetSettings()->Get<vector<string>>("files.universal.architecturePreference");
272274
if (auto result = find_first_of(archPref.begin(), archPref.end(), architectures.begin(), architectures.end()); result != archPref.end())
273275
{
274-
// Filter to preferred architecture to support container auto-open policy
275276
size_t archIndex = find(architectures.begin(), architectures.end(), *result) - architectures.begin();
276277
context->SetAvailableFiles({architectures[archIndex]});
277278
return false;
278279
}
279280

280-
// Preserve original headless load behavior when no architecturePreference is specified
281-
if (!BinaryNinja::IsUIEnabled() && archPref.empty() && architectures.size())
281+
// Load the first architecture if no preference is found.
282+
if (archPref.empty() && architectures.size())
282283
{
283284
context->SetAvailableFiles({architectures[0]});
284285
return false;

0 commit comments

Comments
 (0)