@@ -196,13 +196,25 @@ bool COFFView::Init()
196196
197197 m_imageBase = 0 ; // 0 for COFF? opt.imageBase;
198198 settings = GetLoadSettings (GetTypeName ());
199- if (settings && settings-> Contains ( " loader.imageBase " ) && settings-> Contains ( " loader.architecture " )) // handle overrides
199+ if (settings)
200200 {
201- m_imageBase = settings->Get <uint64_t >(" loader.imageBase" , this );
201+ if (settings->Contains (" loader.imageBase" ))
202+ m_imageBase = settings->Get <uint64_t >(" loader.imageBase" , this );
202203
203- Ref<Architecture> arch = Architecture::GetByName (settings->Get <string>(" loader.architecture" , this ));
204- if (!m_arch || (arch && (arch->GetName () != m_arch->GetName ())))
205- m_arch = arch;
204+ if (settings->Contains (" loader.platform" ))
205+ {
206+ auto platformName = settings->Get <string>(" loader.platform" , this );
207+ platform = Platform::GetByName (platformName);
208+ if (platform)
209+ {
210+ m_arch = platform->GetArchitecture ();
211+ LogDebug (" COFF: loader.platform override (%#x, arch: %s): %s" , header.machine , m_arch->GetName ().c_str (), platformName.c_str ());
212+ }
213+ else
214+ {
215+ LogError (" COFF: Cannot find platform \" %s\" specified in loader.platform override" , platformName.c_str ());
216+ }
217+ }
206218 }
207219
208220 Ref<Settings> viewSettings = Settings::Instance ();
@@ -448,30 +460,16 @@ bool COFFView::Init()
448460 SetDefaultArchitecture (entryPointArch);
449461 GetParentView ()->SetDefaultArchitecture (entryPointArch);
450462
451- platform = g_coffViewType->GetPlatform (IMAGE_SUBSYSTEM_UNKNOWN, m_arch);
452- LogDebug (" COFF: initial platform (%#x, arch: %s): %s" , header.machine , m_arch->GetName ().c_str (), platform->GetName ().c_str ());
453-
454463 if (!platform)
455- platform = m_arch->GetStandalonePlatform ();
464+ {
465+ platform = g_coffViewType->GetPlatform (IMAGE_SUBSYSTEM_UNKNOWN, m_arch);
466+ LogDebug (" COFF: initial platform (%#x, arch: %s): %s" , header.machine , m_arch->GetName ().c_str (), platform->GetName ().c_str ());
467+ }
468+
456469 platform = platform->GetAssociatedPlatformByAddress (entryPointAddress);
457470 entryPointAddress = m_entryPoint;
458471 LogDebug (" COFF: entry point %#" PRIx64 " associated platform (%#x, arch: %s): %s" , entryPointAddress, header.machine , m_arch->GetName ().c_str (), platform->GetName ().c_str ());
459472
460- if (settings && settings->Contains (" loader.platform" )) // handle overrides
461- {
462- auto platformOverrideName = settings->Get <string>(" loader.platform" , this );
463- Ref<Platform> platformOverride = Platform::GetByName (platformOverrideName);
464- if (platformOverride)
465- {
466- platform = platformOverride;
467- LogDebug (" COFF: loader.platform override (%#x, arch: %s): %s" , header.machine , m_arch->GetName ().c_str (), platform->GetName ().c_str ());
468- }
469- else
470- {
471- LogError (" COFF: Cannot find platform \" %s\" specified in loader.platform override" , platformOverrideName.c_str ());
472- }
473- }
474-
475473 SetDefaultPlatform (platform);
476474 SetDefaultArchitecture (platform->GetArchitecture ());
477475 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<Settings> COFFViewType::GetLoadSettingsForData(BinaryView* data)
16471645 Ref<Settings> settings = GetDefaultLoadSettingsForData (viewRef);
16481646
16491647 // specify default load settings that can be overridden
1650- vector<string> overrides = {" loader.architecture " , " loader. imageBase" , " loader.platform" };
1648+ vector<string> overrides = {" loader.imageBase" , " loader.platform" };
16511649 if (!viewRef->IsRelocatable ())
16521650 settings->UpdateProperty (" loader.imageBase" , " message" , " Note: File indicates image is not relocatable." );
16531651
0 commit comments