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). --- view/macho/universaltransform.cpp | 9 +++++---- view/macho/universalview.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'view') diff --git a/view/macho/universaltransform.cpp b/view/macho/universaltransform.cpp index 3309d853..33164215 100644 --- a/view/macho/universaltransform.cpp +++ b/view/macho/universaltransform.cpp @@ -266,19 +266,20 @@ bool UniversalTransform::DecodeWithContext(Ref context, const architectures.push_back(archName); } - if (!context->IsInteractive()) + // TODO: It is surprising that this is UniversalTransform's responsibility. + if (!BinaryNinja::IsUIEnabled()) { + // When headless, filter to the preferred architecture if one is configured. vector archPref = context->GetSettings()->Get>("files.universal.architecturePreference"); if (auto result = find_first_of(archPref.begin(), archPref.end(), architectures.begin(), architectures.end()); result != archPref.end()) { - // Filter to preferred architecture to support container auto-open policy size_t archIndex = find(architectures.begin(), architectures.end(), *result) - architectures.begin(); context->SetAvailableFiles({architectures[archIndex]}); return false; } - // Preserve original headless load behavior when no architecturePreference is specified - if (!BinaryNinja::IsUIEnabled() && archPref.empty() && architectures.size()) + // Load the first architecture if no preference is found. + if (archPref.empty() && architectures.size()) { context->SetAvailableFiles({architectures[0]}); return false; diff --git a/view/macho/universalview.cpp b/view/macho/universalview.cpp index 16e973f5..bd8fc7ef 100644 --- a/view/macho/universalview.cpp +++ b/view/macho/universalview.cpp @@ -30,7 +30,7 @@ void BinaryNinja::InitUniversalViewType() "type" : "array", "sorted" : false, "default" : [], - "description" : "Specify an architecture preference for automatic loading of a Mach-O file from a Universal archive. When unset, headless operation defaults to the first available architecture, while interactive operation presents all available architectures for selection.", + "description" : "Architectures to prefer when loading Universal (fat) Mach-O archives, in order of priority. Determines which architecture is pre-selected in the architecture picker, or loaded automatically when prompting is set to 'automatic' or 'never'.", "ignore" : ["SettingsProjectScope", "SettingsResourceScope"] })"); -- cgit v1.3.1