| 555 | } |
| 556 | |
| 557 | bool SharedCacheMachOHeader::AddExportTerminalSymbol( |
| 558 | std::vector<CacheSymbol>& symbols, const std::string& symbolName, const uint8_t *current, const uint8_t *end) const |
| 559 | { |
| 560 | uint64_t symbolFlags = readValidULEB128(current, end); |
| 561 | if (symbolFlags & EXPORT_SYMBOL_FLAGS_REEXPORT) |
| 562 | return false; |
| 563 | |
| 564 | uint64_t imageOffset = readValidULEB128(current, end); |
| 565 | uint64_t symbolAddress = textBase + imageOffset; |
| 566 | if (symbolName.empty() || symbolAddress == 0) |
| 567 | return false; |
| 568 | |
| 569 | // Tries to get the symbol type based off the section containing it. |
| 570 | auto sectionSymbolType = [&]() -> BNSymbolType { |
| 571 | uint32_t sectionFlags = 0; |
| 572 | for (const auto& section : sections) |
| 573 | { |
| 574 | if (symbolAddress >= section.addr && symbolAddress < section.addr + section.size) |
| 575 | { |
| 576 | // Take the flags from the first containing section. |
| 577 | sectionFlags = section.flags; |
| 578 | break; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | // TODO: Is this enough to determine a function symbol? |
| 583 | // TODO: Might be the cause of https://github.com/Vector35/binaryninja-api/issues/6526 |
| 584 | // Check the sections flags to see if we actually have a function symbol instead. |
| 585 | if (sectionFlags & S_ATTR_PURE_INSTRUCTIONS || sectionFlags & S_ATTR_SOME_INSTRUCTIONS) |
| 586 | return FunctionSymbol; |
| 587 | |
| 588 | // By default, just return data symbol. |
| 589 | return DataSymbol; |
| 590 | }; |
| 591 | |
| 592 | switch (symbolFlags & EXPORT_SYMBOL_FLAGS_KIND_MASK) |
| 593 | { |
| 594 | case EXPORT_SYMBOL_FLAGS_KIND_REGULAR: |
| 595 | case EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL: |
| 596 | symbols.emplace_back(sectionSymbolType(), symbolAddress, symbolName); |
| 597 | break; |
| 598 | case EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE: |
| 599 | symbols.emplace_back(DataSymbol, symbolAddress, symbolName); |
| 600 | break; |
| 601 | default: |
| 602 | LogWarn("Unhandled export symbol kind: %llx", symbolFlags & EXPORT_SYMBOL_FLAGS_KIND_MASK); |
| 603 | return false; |
| 604 | } |
| 605 | |
| 606 | return true; |
| 607 | } |
| 608 | |
| 609 | std::vector<CacheSymbol> SharedCacheMachOHeader::ReadExportSymbolTrie(VirtualMemory& vm) const |
| 610 | { |
nothing calls this directly
no test coverage detected