@@ -480,6 +480,7 @@ void SharedCacheMachOProcessor::ApplyHeader(Ref<BinaryView> view, SharedCacheMac
480480 // Mach-O View symtab processing with
481481 // a ton of stuff cut out so it can work
482482 // NOTE: This table is read relative to the link edit segment file base.
483+ // TODO: Remove this and use the m_symbols in the cache?
483484 const auto symbols = header.ReadSymbolTable (*view, *m_vm);
484485 for (const auto & sym : symbols)
485486 ApplySymbol (view, typeLib, sym.ToBNSymbol ());
@@ -489,6 +490,7 @@ void SharedCacheMachOProcessor::ApplyHeader(Ref<BinaryView> view, SharedCacheMac
489490 if (header.exportTriePresent )
490491 {
491492 // NOTE: This table is read relative to the link edit segment file base.
493+ // TODO: Remove this and use the m_symbols in the cache?
492494 const auto exportSymbols = header.ReadExportSymbolTable (*view, *m_vm);
493495 for (const auto & sym : exportSymbols)
494496 ApplySymbol (view, typeLib, sym.ToBNSymbol ());
@@ -811,13 +813,11 @@ std::vector<CacheSymbol> SharedCacheMachOHeader::ReadSymbolTable(BinaryView& vie
811813 uint64_t symbolsAddress = GetLinkEditFileBase () + symtab.symoff ;
812814 uint64_t stringsAddress = GetLinkEditFileBase () + symtab.stroff ;
813815 uint64_t link = GetLinkEditFileBase ();
814- LogInfo (" link edit file base %llx" , link);
815816 if (!vm.IsAddressMapped (link))
816817 {
817- LogError (" Link edit segment not mapped" );
818+ LogError (" Link edit segment not mapped %llx " , link );
818819 return {};
819820 }
820- auto strings = vm.ReadBuffer (stringsAddress, symtab.strsize );
821821
822822 // TODO: This needs to be passed in as an optional argument.
823823 // TODO: Sometimes symbol tables are shared and we have to offset into the table for a specific header.
@@ -857,23 +857,17 @@ std::vector<CacheSymbol> SharedCacheMachOHeader::ReadSymbolTable(BinaryView& vie
857857 continue ;
858858 }
859859
860- std::string symbolName (( char *)strings. GetDataAt ( nlist.n_strx ) );
860+ std::string symbolName = vm. ReadCString (stringsAddress + nlist.n_strx );
861861 if (symbolName == " <redacted>" )
862862 continue ;
863863
864864 std::optional<BNSymbolType> symbolType;
865865 if ((nlist.n_type & N_TYPE) == N_SECT && nlist.n_sect > 0 && (size_t )(nlist.n_sect - 1 ) < sections.size ())
866- {
867866 symbolType = DataSymbol;
868- }
869867 else if ((nlist.n_type & N_TYPE) == N_ABS)
870- {
871868 symbolType = DataSymbol;
872- }
873869 else if ((nlist.n_type & N_EXT))
874- {
875870 symbolType = ExternalSymbol;
876- }
877871
878872 if (!symbolType.has_value ())
879873 {
@@ -913,7 +907,7 @@ std::vector<CacheSymbol> SharedCacheMachOHeader::ReadSymbolTable(BinaryView& vie
913907
914908 CacheSymbol symbol;
915909 symbol.address = symbolAddress;
916- symbol.name = symbolName;
910+ symbol.name = std::move ( symbolName) ;
917911 symbol.type = symbolType.value ();
918912 symbolList.emplace_back (symbol);
919913 }
@@ -956,10 +950,11 @@ std::optional<CacheSymbol> SharedCacheMachOHeader::AddExportTerminalSymbol(const
956950 return exportSym;
957951}
958952
959- void SharedCacheMachOHeader::ProcessLinkEditTrie (std::vector<CacheSymbol>& symbols, const std::string& currentText, const uint8_t * begin, const uint8_t * current, const uint8_t * end) const
953+ // TODO: This is like 90% of the runtime.
954+ bool SharedCacheMachOHeader::ProcessLinkEditTrie (std::vector<CacheSymbol>& symbols, const std::string& currentText, const uint8_t * begin, const uint8_t * current, const uint8_t * end) const
960955{
961956 if (current >= end)
962- throw ReadException () ;
957+ return false ;
963958
964959 uint64_t terminalSize = readValidULEB128 (current, end);
965960 const uint8_t * child = current + terminalSize;
@@ -980,18 +975,21 @@ void SharedCacheMachOHeader::ProcessLinkEditTrie(std::vector<CacheSymbol>& symbo
980975 for (uint8_t i = 0 ; i < childCount; ++i)
981976 {
982977 if (current >= end)
983- throw ReadException () ;
978+ return false ;
984979 const auto it = std::find (current, end, 0 );
985980 childText.append (current, it);
986981 current = it + 1 ;
987982 if (current >= end)
988- throw ReadException () ;
989- auto next = readValidULEB128 (current, end);
983+ return false ;
984+ const auto next = readValidULEB128 (current, end);
990985 if (next == 0 )
991- throw ReadException ();
992- ProcessLinkEditTrie (symbols, childText, begin, begin + next, end);
986+ return false ;
987+ if (!ProcessLinkEditTrie (symbols, childText, begin, begin + next, end))
988+ return false ;
993989 childText.resize (currentText.size ());
994990 }
991+
992+ return true ;
995993}
996994
997995std::vector<CacheSymbol> SharedCacheMachOHeader::ReadExportSymbolTable (BinaryView& view, VirtualMemory& vm) const
0 commit comments