From cbd4d7f12d54ddc4b6d3d90a8d7b49591f468a94 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 20 Jan 2025 16:34:57 -0500 Subject: Allow overriding common loader settings when automatic load file parsing fails. --- view/elf/elfview.cpp | 7 +++++-- view/macho/machoview.cpp | 4 ++-- view/md1rom/md1rom.cpp | 4 ++-- view/pe/coffview.cpp | 8 ++++++-- view/pe/peview.cpp | 8 ++++++-- view/pe/teview.cpp | 16 ++++++---------- view/sharedcache/core/DSCView.cpp | 4 ++-- 7 files changed, 29 insertions(+), 22 deletions(-) diff --git a/view/elf/elfview.cpp b/view/elf/elfview.cpp index bf447a9a..29fc03d9 100644 --- a/view/elf/elfview.cpp +++ b/view/elf/elfview.cpp @@ -739,6 +739,9 @@ bool ElfView::Init() m_logger->LogError("ELF architecture %d is not supported", m_commonHeader.arch); break; } + + if (!m_parseOnly) + m_logger->LogWarn("Unable to determine architecture. Please open the file with options and select a valid architecture."); return false; } @@ -2944,8 +2947,8 @@ Ref ElfViewType::GetLoadSettingsForData(BinaryView* data) Ref viewRef = Parse(data); if (!viewRef || !viewRef->Init()) { - m_logger->LogError("View type '%s' could not be created", GetName().c_str()); - return nullptr; + m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str()); + viewRef = data; } Ref settings = GetDefaultLoadSettingsForData(viewRef); diff --git a/view/macho/machoview.cpp b/view/macho/machoview.cpp index d26769e1..9ee393e8 100644 --- a/view/macho/machoview.cpp +++ b/view/macho/machoview.cpp @@ -3863,8 +3863,8 @@ Ref MachoViewType::GetLoadSettingsForData(BinaryView* data) Ref viewRef = Parse(data); if (!viewRef || !viewRef->Init()) { - m_logger->LogError("View type '%s' could not be created", GetName().c_str()); - return nullptr; + m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str()); + viewRef = data; } Ref settings = GetDefaultLoadSettingsForData(viewRef); diff --git a/view/md1rom/md1rom.cpp b/view/md1rom/md1rom.cpp index 3e8cb64c..1d8da293 100644 --- a/view/md1rom/md1rom.cpp +++ b/view/md1rom/md1rom.cpp @@ -423,8 +423,8 @@ Ref Md1romViewType::GetLoadSettingsForData(BinaryNinja::BinaryView* da Ref viewRef = Parse(data); if (!viewRef || !viewRef->Init()) { - m_logger->LogError("View type '%s' could not be created", GetName().c_str()); - return nullptr; + m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str()); + viewRef = data; } Ref settings = GetDefaultLoadSettingsForData(viewRef); diff --git a/view/pe/coffview.cpp b/view/pe/coffview.cpp index 814c8cf2..4296917a 100644 --- a/view/pe/coffview.cpp +++ b/view/pe/coffview.cpp @@ -459,6 +459,10 @@ bool COFFView::Init() m_logger->LogError("COFF architecture '0x%x' is not supported", header.machine); break; } + + if (!m_parseOnly) + m_logger->LogWarn("Unable to determine architecture. Please open the file with options and select a valid architecture."); + return false; } @@ -1662,8 +1666,8 @@ Ref COFFViewType::GetLoadSettingsForData(BinaryView* data) Ref viewRef = Parse(data); if (!viewRef || !viewRef->Init()) { - m_logger->LogError("View type '%s' could not be created", GetName().c_str()); - return nullptr; + m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str()); + viewRef = data; } Ref settings = GetDefaultLoadSettingsForData(viewRef); diff --git a/view/pe/peview.cpp b/view/pe/peview.cpp index f0c43056..77c52da8 100644 --- a/view/pe/peview.cpp +++ b/view/pe/peview.cpp @@ -640,6 +640,10 @@ bool PEView::Init() m_logger->LogError("PE architecture '0x%x' is not supported", header.machine); break; } + + if (!m_parseOnly) + m_logger->LogWarn("Unable to determine architecture. Please open the file with options and select a valid architecture."); + return false; } @@ -3086,8 +3090,8 @@ Ref PEViewType::GetLoadSettingsForData(BinaryView* data) Ref viewRef = Parse(data); if (!viewRef || !viewRef->Init()) { - m_logger->LogError("View type '%s' could not be created", GetName().c_str()); - return nullptr; + m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str()); + viewRef = data; } Ref settings = GetDefaultLoadSettingsForData(viewRef); diff --git a/view/pe/teview.cpp b/view/pe/teview.cpp index f8666717..e5fb2a1b 100644 --- a/view/pe/teview.cpp +++ b/view/pe/teview.cpp @@ -257,16 +257,12 @@ bool TEView::Init() break; default: LogError("TE platform '0x%x' is not supported", header.machine); + if (!m_parseOnly) + m_logger->LogWarn("Unable to determine architecture. Please open the file with options and select a valid architecture."); return false; } } - if (!platform) - { - LogError("Platform not supported by this version of Binary Ninja"); - return false; - } - m_arch = platform->GetArchitecture(); if (!m_arch) { @@ -371,13 +367,13 @@ bool TEViewType::IsTypeValidForData(BinaryView* bv) return false; } -Ref TEViewType::GetLoadSettingsForData(BinaryView *bv) +Ref TEViewType::GetLoadSettingsForData(BinaryView* data) { - Ref viewRef = Parse(bv); + Ref viewRef = Parse(data); if (!viewRef || !viewRef->Init()) { - m_logger->LogError("View type '%s' could not be created", GetName().c_str()); - return nullptr; + m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str()); + viewRef = data; } // specify default load settings that can be overridden diff --git a/view/sharedcache/core/DSCView.cpp b/view/sharedcache/core/DSCView.cpp index 1ef6198b..459a37bc 100644 --- a/view/sharedcache/core/DSCView.cpp +++ b/view/sharedcache/core/DSCView.cpp @@ -769,8 +769,8 @@ Ref DSCViewType::GetLoadSettingsForData(BinaryView* data) Ref viewRef = Parse(data); if (!viewRef || !viewRef->Init()) { - LogError("View type '%s' could not be created", GetName().c_str()); - return nullptr; + LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str()); + viewRef = data; } Ref settings = GetDefaultLoadSettingsForData(viewRef); -- cgit v1.3.1