Skip to content

Commit cbd4d7f

Browse files
committed
Allow overriding common loader settings when automatic load file parsing fails.
1 parent 13e8a11 commit cbd4d7f

File tree

7 files changed

+29
-22
lines changed

7 files changed

+29
-22
lines changed

view/elf/elfview.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ bool ElfView::Init()
739739
m_logger->LogError("ELF architecture %d is not supported", m_commonHeader.arch);
740740
break;
741741
}
742+
743+
if (!m_parseOnly)
744+
m_logger->LogWarn("Unable to determine architecture. Please open the file with options and select a valid architecture.");
742745
return false;
743746
}
744747

@@ -2944,8 +2947,8 @@ Ref<Settings> ElfViewType::GetLoadSettingsForData(BinaryView* data)
29442947
Ref<BinaryView> viewRef = Parse(data);
29452948
if (!viewRef || !viewRef->Init())
29462949
{
2947-
m_logger->LogError("View type '%s' could not be created", GetName().c_str());
2948-
return nullptr;
2950+
m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str());
2951+
viewRef = data;
29492952
}
29502953

29512954
Ref<Settings> settings = GetDefaultLoadSettingsForData(viewRef);

view/macho/machoview.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,8 +3863,8 @@ Ref<Settings> MachoViewType::GetLoadSettingsForData(BinaryView* data)
38633863
Ref<BinaryView> viewRef = Parse(data);
38643864
if (!viewRef || !viewRef->Init())
38653865
{
3866-
m_logger->LogError("View type '%s' could not be created", GetName().c_str());
3867-
return nullptr;
3866+
m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str());
3867+
viewRef = data;
38683868
}
38693869

38703870
Ref<Settings> settings = GetDefaultLoadSettingsForData(viewRef);

view/md1rom/md1rom.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ Ref<Settings> Md1romViewType::GetLoadSettingsForData(BinaryNinja::BinaryView* da
423423
Ref<BinaryView> viewRef = Parse(data);
424424
if (!viewRef || !viewRef->Init())
425425
{
426-
m_logger->LogError("View type '%s' could not be created", GetName().c_str());
427-
return nullptr;
426+
m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str());
427+
viewRef = data;
428428
}
429429

430430
Ref<Settings> settings = GetDefaultLoadSettingsForData(viewRef);

view/pe/coffview.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ bool COFFView::Init()
459459
m_logger->LogError("COFF architecture '0x%x' is not supported", header.machine);
460460
break;
461461
}
462+
463+
if (!m_parseOnly)
464+
m_logger->LogWarn("Unable to determine architecture. Please open the file with options and select a valid architecture.");
465+
462466
return false;
463467
}
464468

@@ -1662,8 +1666,8 @@ Ref<Settings> COFFViewType::GetLoadSettingsForData(BinaryView* data)
16621666
Ref<BinaryView> viewRef = Parse(data);
16631667
if (!viewRef || !viewRef->Init())
16641668
{
1665-
m_logger->LogError("View type '%s' could not be created", GetName().c_str());
1666-
return nullptr;
1669+
m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str());
1670+
viewRef = data;
16671671
}
16681672

16691673
Ref<Settings> settings = GetDefaultLoadSettingsForData(viewRef);

view/pe/peview.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ bool PEView::Init()
640640
m_logger->LogError("PE architecture '0x%x' is not supported", header.machine);
641641
break;
642642
}
643+
644+
if (!m_parseOnly)
645+
m_logger->LogWarn("Unable to determine architecture. Please open the file with options and select a valid architecture.");
646+
643647
return false;
644648
}
645649

@@ -3086,8 +3090,8 @@ Ref<Settings> PEViewType::GetLoadSettingsForData(BinaryView* data)
30863090
Ref<BinaryView> viewRef = Parse(data);
30873091
if (!viewRef || !viewRef->Init())
30883092
{
3089-
m_logger->LogError("View type '%s' could not be created", GetName().c_str());
3090-
return nullptr;
3093+
m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str());
3094+
viewRef = data;
30913095
}
30923096

30933097
Ref<Settings> settings = GetDefaultLoadSettingsForData(viewRef);

view/pe/teview.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,12 @@ bool TEView::Init()
257257
break;
258258
default:
259259
LogError("TE platform '0x%x' is not supported", header.machine);
260+
if (!m_parseOnly)
261+
m_logger->LogWarn("Unable to determine architecture. Please open the file with options and select a valid architecture.");
260262
return false;
261263
}
262264
}
263265

264-
if (!platform)
265-
{
266-
LogError("Platform not supported by this version of Binary Ninja");
267-
return false;
268-
}
269-
270266
m_arch = platform->GetArchitecture();
271267
if (!m_arch)
272268
{
@@ -371,13 +367,13 @@ bool TEViewType::IsTypeValidForData(BinaryView* bv)
371367
return false;
372368
}
373369

374-
Ref<Settings> TEViewType::GetLoadSettingsForData(BinaryView *bv)
370+
Ref<Settings> TEViewType::GetLoadSettingsForData(BinaryView* data)
375371
{
376-
Ref<BinaryView> viewRef = Parse(bv);
372+
Ref<BinaryView> viewRef = Parse(data);
377373
if (!viewRef || !viewRef->Init())
378374
{
379-
m_logger->LogError("View type '%s' could not be created", GetName().c_str());
380-
return nullptr;
375+
m_logger->LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str());
376+
viewRef = data;
381377
}
382378

383379
// specify default load settings that can be overridden

view/sharedcache/core/DSCView.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,8 @@ Ref<Settings> DSCViewType::GetLoadSettingsForData(BinaryView* data)
769769
Ref<BinaryView> viewRef = Parse(data);
770770
if (!viewRef || !viewRef->Init())
771771
{
772-
LogError("View type '%s' could not be created", GetName().c_str());
773-
return nullptr;
772+
LogWarn("Failed to initialize view of type '%s'. Generating default load settings.", GetName().c_str());
773+
viewRef = data;
774774
}
775775

776776
Ref<Settings> settings = GetDefaultLoadSettingsForData(viewRef);

0 commit comments

Comments
 (0)