From 5088febc53fb9f0d6496a410baf8b393befb845d Mon Sep 17 00:00:00 2001 From: Brandon Miller Date: Wed, 15 May 2024 09:44:37 -0400 Subject: Removed loader.architecture override from views Architecture is derived from platform object and can be overriden using loader.platform --- view/pe/coffview.cpp | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'view/pe/coffview.cpp') diff --git a/view/pe/coffview.cpp b/view/pe/coffview.cpp index 8422a07b..f7d02fa8 100644 --- a/view/pe/coffview.cpp +++ b/view/pe/coffview.cpp @@ -196,13 +196,25 @@ bool COFFView::Init() m_imageBase = 0; // 0 for COFF? opt.imageBase; settings = GetLoadSettings(GetTypeName()); - if (settings && settings->Contains("loader.imageBase") && settings->Contains("loader.architecture")) // handle overrides + if (settings) { - m_imageBase = settings->Get("loader.imageBase", this); + if (settings->Contains("loader.imageBase")) + m_imageBase = settings->Get("loader.imageBase", this); - Ref arch = Architecture::GetByName(settings->Get("loader.architecture", this)); - if (!m_arch || (arch && (arch->GetName() != m_arch->GetName()))) - m_arch = arch; + if (settings->Contains("loader.platform")) + { + auto platformName = settings->Get("loader.platform", this); + platform = Platform::GetByName(platformName); + if (platform) + { + m_arch = platform->GetArchitecture(); + LogDebug("COFF: loader.platform override (%#x, arch: %s): %s", header.machine, m_arch->GetName().c_str(), platformName.c_str()); + } + else + { + LogError("COFF: Cannot find platform \"%s\" specified in loader.platform override", platformName.c_str()); + } + } } Ref viewSettings = Settings::Instance(); @@ -448,30 +460,16 @@ bool COFFView::Init() SetDefaultArchitecture(entryPointArch); GetParentView()->SetDefaultArchitecture(entryPointArch); - platform = g_coffViewType->GetPlatform(IMAGE_SUBSYSTEM_UNKNOWN, m_arch); - LogDebug("COFF: initial platform (%#x, arch: %s): %s", header.machine, m_arch->GetName().c_str(), platform->GetName().c_str()); - if (!platform) - platform = m_arch->GetStandalonePlatform(); + { + platform = g_coffViewType->GetPlatform(IMAGE_SUBSYSTEM_UNKNOWN, m_arch); + LogDebug("COFF: initial platform (%#x, arch: %s): %s", header.machine, m_arch->GetName().c_str(), platform->GetName().c_str()); + } + platform = platform->GetAssociatedPlatformByAddress(entryPointAddress); entryPointAddress = m_entryPoint; LogDebug("COFF: entry point %#" PRIx64 " associated platform (%#x, arch: %s): %s", entryPointAddress, header.machine, m_arch->GetName().c_str(), platform->GetName().c_str()); - if (settings && settings->Contains("loader.platform")) // handle overrides - { - auto platformOverrideName = settings->Get("loader.platform", this); - Ref platformOverride = Platform::GetByName(platformOverrideName); - if (platformOverride) - { - platform = platformOverride; - LogDebug("COFF: loader.platform override (%#x, arch: %s): %s", header.machine, m_arch->GetName().c_str(), platform->GetName().c_str()); - } - else - { - LogError("COFF: Cannot find platform \"%s\" specified in loader.platform override", platformOverrideName.c_str()); - } - } - SetDefaultPlatform(platform); SetDefaultArchitecture(platform->GetArchitecture()); LogDebug("COFF: final entry point %#" PRIx64 " default (%#x, arch: %s): %s", entryPointAddress, header.machine, platform->GetName().c_str(), GetDefaultPlatform()->GetName().c_str()); @@ -1647,7 +1645,7 @@ Ref COFFViewType::GetLoadSettingsForData(BinaryView* data) Ref settings = GetDefaultLoadSettingsForData(viewRef); // specify default load settings that can be overridden - vector overrides = {"loader.architecture", "loader.imageBase", "loader.platform"}; + vector overrides = {"loader.imageBase", "loader.platform"}; if (!viewRef->IsRelocatable()) settings->UpdateProperty("loader.imageBase", "message", "Note: File indicates image is not relocatable."); -- cgit v1.3.1