@@ -434,10 +434,7 @@ std::optional<SharedCacheMachOHeader> SharedCacheMachOHeader::ParseHeaderForAddr
434434 char sectionName[17 ];
435435 memcpy (sectionName, section.sectname , sizeof (section.sectname ));
436436 sectionName[16 ] = 0 ;
437- if (header.identifierPrefix .empty ())
438- header.sectionNames .emplace_back (sectionName);
439- else
440- header.sectionNames .push_back (header.identifierPrefix + " ::" + sectionName);
437+ header.sectionNames .push_back (header.identifierPrefix + " ::" + sectionName);
441438 }
442439 }
443440 catch (ReadException&)
@@ -565,30 +562,40 @@ std::optional<CacheSymbol> SharedCacheMachOHeader::AddExportTerminalSymbol(const
565562 if (symbolName.empty () || symbolAddress == 0 )
566563 return std::nullopt ;
567564
568- CacheSymbol exportSym;
569- exportSym.name = symbolName;
570- exportSym.type = DataSymbol;
571- exportSym.address = symbolAddress;
572-
573- uint32_t sectionFlags = 0 ;
574- for (const auto & section : sections)
575- {
576- if (section.addr < symbolAddress && section.addr + section.size > symbolAddress)
577- {
578- // Take the flags from the first containing section.
579- sectionFlags = section.flags ;
580- break ;
581- }
582- }
583-
584- // TODO: Is this enough to determine a function symbol?
585- // TODO: Might be the cause of https://github.com/Vector35/binaryninja-api/issues/6526
586- // Check the sections flags to see if we actually have a function symbol instead.
587- if ((sectionFlags & S_ATTR_PURE_INSTRUCTIONS) == S_ATTR_PURE_INSTRUCTIONS
588- || (sectionFlags & S_ATTR_SOME_INSTRUCTIONS) == S_ATTR_SOME_INSTRUCTIONS)
589- exportSym.type = FunctionSymbol;
590-
591- return exportSym;
565+ // Tries to get the symbol type based off the section containing it.
566+ auto sectionSymbolType = [&]() -> BNSymbolType {
567+ uint32_t sectionFlags = 0 ;
568+ for (const auto & section : sections)
569+ {
570+ if (symbolAddress >= section.addr && symbolAddress < section.addr + section.size )
571+ {
572+ // Take the flags from the first containing section.
573+ sectionFlags = section.flags ;
574+ break ;
575+ }
576+ }
577+
578+ // TODO: Is this enough to determine a function symbol?
579+ // TODO: Might be the cause of https://github.com/Vector35/binaryninja-api/issues/6526
580+ // Check the sections flags to see if we actually have a function symbol instead.
581+ if (sectionFlags & S_ATTR_PURE_INSTRUCTIONS || sectionFlags & S_ATTR_SOME_INSTRUCTIONS)
582+ return FunctionSymbol;
583+
584+ // By default, just return data symbol.
585+ return DataSymbol;
586+ };
587+
588+ switch (symbolFlags & EXPORT_SYMBOL_FLAGS_KIND_MASK)
589+ {
590+ case EXPORT_SYMBOL_FLAGS_KIND_REGULAR:
591+ case EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL:
592+ return CacheSymbol (sectionSymbolType (), symbolAddress, symbolName);
593+ case EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE:
594+ return CacheSymbol (DataSymbol, symbolAddress, symbolName);
595+ default :
596+ LogWarn (" Unhandled export symbol kind: %x" , symbolFlags & EXPORT_SYMBOL_FLAGS_KIND_MASK);
597+ return std::nullopt ;
598+ }
592599}
593600
594601// TODO: This is like 90% of the runtime.
0 commit comments