| 441 | } |
| 442 | |
| 443 | bool ElfView::Init() |
| 444 | { |
| 445 | std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now(); |
| 446 | // Add segments for the program headers |
| 447 | BinaryReader reader(GetParentView()); |
| 448 | BinaryReader virtualReader(this); |
| 449 | |
| 450 | uint64_t initialImageBase = 0; |
| 451 | bool initialImageBaseSet = false; |
| 452 | for (const auto& i : m_programHeaders) |
| 453 | { |
| 454 | if ((i.type != ELF_PT_LOAD) || (!i.fileSize)) |
| 455 | continue; |
| 456 | |
| 457 | if (!initialImageBaseSet) |
| 458 | { |
| 459 | initialImageBase = i.virtualAddress; |
| 460 | initialImageBaseSet = true; |
| 461 | } |
| 462 | else if (i.virtualAddress < initialImageBase) |
| 463 | initialImageBase = i.virtualAddress; |
| 464 | } |
| 465 | |
| 466 | SetOriginalImageBase(initialImageBase); |
| 467 | uint64_t preferredImageBase = initialImageBase; |
| 468 | Ref<Settings> viewSettings = Settings::Instance(); |
| 469 | m_extractMangledTypes = viewSettings->Get<bool>("analysis.extractTypesFromMangledNames", this); |
| 470 | m_simplifyTemplates = viewSettings->Get<bool>("analysis.types.templateSimplifier", this); |
| 471 | |
| 472 | bool platformSetByUser = false; |
| 473 | Ref<Settings> settings = GetLoadSettings(GetTypeName()); |
| 474 | if (settings) |
| 475 | { |
| 476 | if (settings->Contains("loader.imageBase")) |
| 477 | preferredImageBase = settings->Get<uint64_t>("loader.imageBase", this); |
| 478 | |
| 479 | if (settings->Contains("loader.platform")) |
| 480 | { |
| 481 | BNSettingsScope scope = SettingsAutoScope; |
| 482 | Ref<Platform> platformOverride = Platform::GetByName(settings->Get<string>("loader.platform", this, &scope)); |
| 483 | if (platformOverride) |
| 484 | { |
| 485 | m_plat = platformOverride; |
| 486 | m_arch = m_plat->GetArchitecture(); |
| 487 | platformSetByUser = (scope == SettingsResourceScope); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | int64_t imageBaseAdjustment = 0; |
| 493 | if (!initialImageBase) |
| 494 | imageBaseAdjustment = preferredImageBase; |
| 495 | else if (initialImageBase <= preferredImageBase) |
| 496 | imageBaseAdjustment = preferredImageBase - initialImageBase; |
| 497 | else |
| 498 | imageBaseAdjustment = -(int64_t)(initialImageBase - preferredImageBase); |
| 499 | |
| 500 | m_entryPoint = m_entryPoint + imageBaseAdjustment; |
no test coverage detected