@@ -84,50 +84,58 @@ void SharedCacheMachOProcessor::ApplyHeader(const SharedCache& cache, SharedCach
8484 }
8585
8686 // Apply symbols from the .symbols cache files.
87- for (const auto &entry: cache.GetEntries ())
88- {
89- // NOTE: We check addr size as we only support 64bit .symbols files currently.
90- if (entry.GetType () != CacheEntryType::Symbols && m_vm->GetAddressSize () == 8 )
91- continue ;
92- const auto & entryHeader = entry.GetHeader ();
87+ ApplyUnmappedLocalSymbols (cache, header, std::move (typeLib));
88+ }
9389
94- // This is where we get the symbol and string table information from in the .symbols file.
95- dyld_cache_local_symbols_info localSymbolsInfo = {};
96- auto localSymbolsInfoAddr = entry.GetMappedAddress (entryHeader.localSymbolsOffset );
97- if (!localSymbolsInfoAddr.has_value ())
98- continue ;
99- m_vm->Read (&localSymbolsInfo, *localSymbolsInfoAddr, sizeof (dyld_cache_local_symbols_info));
90+ void SharedCacheMachOProcessor::ApplyUnmappedLocalSymbols (const SharedCache& cache, const SharedCacheMachOHeader& header, Ref<TypeLibrary> typeLib)
91+ {
92+ const auto & localSymbolsCacheEntry = cache.GetLocalSymbolsEntry ();
93+ auto localSymbolsVM = cache.GetLocalSymbolsVM ();
94+ if (!localSymbolsCacheEntry || !localSymbolsVM)
95+ return ;
96+
97+ // NOTE: We check addr size as we only support 64bit .symbols files currently.
98+ // TODO: Support 32-bit nlist
99+ if (localSymbolsVM->GetAddressSize () != 8 )
100+ return ;
101+
102+ const auto & entryHeader = localSymbolsCacheEntry->GetHeader ();
103+
104+ // This is where we get the symbol and string table information from in the .symbols file.
105+ dyld_cache_local_symbols_info localSymbolsInfo = {};
106+ auto localSymbolsInfoAddr = entryHeader.localSymbolsOffset ;
107+
108+ localSymbolsVM->Read (&localSymbolsInfo, localSymbolsInfoAddr, sizeof (dyld_cache_local_symbols_info));
100109
101- // Read each symbols entry, looking for the current image entry.
102- uint64_t localEntriesAddr = * localSymbolsInfoAddr + localSymbolsInfo.entriesOffset ;
103- uint64_t localSymbolsAddr = * localSymbolsInfoAddr + localSymbolsInfo.nlistOffset ;
104- uint64_t localStringsAddr = * localSymbolsInfoAddr + localSymbolsInfo.stringsOffset ;
110+ // Read each symbols entry, looking for the current image entry.
111+ uint64_t localEntriesAddr = localSymbolsInfoAddr + localSymbolsInfo.entriesOffset ;
112+ uint64_t localSymbolsAddr = localSymbolsInfoAddr + localSymbolsInfo.nlistOffset ;
113+ uint64_t localStringsAddr = localSymbolsInfoAddr + localSymbolsInfo.stringsOffset ;
105114
115+ for (uint32_t i = 0 ; i < localSymbolsInfo.entriesCount ; i++)
116+ {
106117 dyld_cache_local_symbols_entry_64 localSymbolsEntry = {};
107- for (uint32_t i = 0 ; i < localSymbolsInfo.entriesCount ; i++)
118+ localSymbolsVM->Read (&localSymbolsEntry, localEntriesAddr + i * sizeof (dyld_cache_local_symbols_entry_64),
119+ sizeof (dyld_cache_local_symbols_entry_64));
120+
121+ // The dylibOffset is the offset from the cache base address to the image header.
122+ const auto imageAddr = cache.GetBaseAddress () + localSymbolsEntry.dylibOffset ;
123+ if (imageAddr != header.textBase )
124+ continue ;
125+
126+ // We have found the entry to read!
127+ uint64_t symbolTableStart = localSymbolsAddr + (localSymbolsEntry.nlistStartIndex * sizeof (nlist_64));
128+ TableInfo symbolInfo = {symbolTableStart, localSymbolsEntry.nlistCount };
129+ TableInfo stringInfo = {localStringsAddr, localSymbolsInfo.stringsSize };
130+ m_view->BeginBulkModifySymbols ();
131+ const auto symbols = header.ReadSymbolTable (*localSymbolsVM, symbolInfo, stringInfo);
132+ for (const auto &sym: symbols)
108133 {
109- m_vm->Read (&localSymbolsEntry, localEntriesAddr + i * sizeof (dyld_cache_local_symbols_entry_64),
110- sizeof (dyld_cache_local_symbols_entry_64));
111- // The dylibOffset is the offset from the cache base address to the image header.
112- const auto imageAddr = cache.GetBaseAddress () + localSymbolsEntry.dylibOffset ;
113- if (imageAddr == header.textBase )
114- {
115- // We have found the entry to read!
116- // TODO: Support 32bit nlist
117- uint64_t symbolTableStart = localSymbolsAddr + (localSymbolsEntry.nlistStartIndex * sizeof (nlist_64));
118- TableInfo symbolInfo = {symbolTableStart, localSymbolsEntry.nlistCount };
119- TableInfo stringInfo = {localStringsAddr, localSymbolsInfo.stringsSize };
120- m_view->BeginBulkModifySymbols ();
121- const auto symbols = header.ReadSymbolTable (*m_vm, symbolInfo, stringInfo);
122- for (const auto &sym: symbols)
123- {
124- auto [symbol, symbolType] = sym.GetBNSymbolAndType (*m_view);
125- ApplySymbol (m_view, typeLib, symbol, symbolType);
126- }
127- m_view->EndBulkModifySymbols ();
128- break ;
129- }
134+ auto [symbol, symbolType] = sym.GetBNSymbolAndType (*m_view);
135+ ApplySymbol (m_view, typeLib, std::move (symbol), std::move (symbolType));
130136 }
137+ m_view->EndBulkModifySymbols ();
138+ return ;
131139 }
132140}
133141
0 commit comments