From e937b89628f3b3ce039d641fe849796cc295c41a Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Sat, 13 Sep 2025 16:17:43 -0700 Subject: [DSC] Rework handling of .symbols files to be compatible with iOS 15 In some iOS 15 caches, the .symbols file's mapping has an address of 0. This would cause it to be returned by `SharedCache::GetEntryContaining` and loaded into the view. The .symbols file contains the local symbol tables for images in the shared cache. It is not intended to be mapped into the same address space as the rest of the shared cache. `SharedCache` now tracks the symbols cache entry separately from other entries. A dedicated `VirtualMemory` region is used when accessing the data it contains. This could be a `FileAccessor`, but that would require additional changes within `SharedCacheMachOHeader`. `SharedCacheMachOProcessor` now directly accesses the local symbols cache entry rather than needing to search for it. --- view/sharedcache/core/SharedCache.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'view/sharedcache/core/SharedCache.cpp') diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index 0a14cfaf..c084c692 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -91,10 +91,8 @@ CacheEntry CacheEntry::FromFile(const std::string& filePath, const std::string& { // We found a single symbols cache entry file. Mark it as such! type = CacheEntryType::Symbols; - // Adjust the mapping for the symbol file, they seem to be only for the header. - // If we do not adjust the mapping than we will not be able to read the symbol table through the virtual memory. - mappings[0].fileOffset = 0; - mappings[0].size = file->Length(); + // Symbol files are not mapped into the address space. + mappings.clear(); } else if (mappings.size() == 1 && header.imagesCountOld == 0 && header.imagesCount == 0 && header.imagesTextOffset == 0) @@ -231,6 +229,17 @@ void SharedCache::AddEntry(CacheEntry entry) // Get the file accessor to associate with the virtual memory region. auto fileAccessor = FileAccessorCache::Global().Open(entry.GetFilePath()); + if (entry.GetType() == CacheEntryType::Symbols) + { + m_localSymbolsEntry = std::move(entry); + // Map the entire file into its own virtual memory space. + // This is necessary due to code that processes symbols being written in terms of a `VirtualMemory` + // rather than something more generic. + m_localSymbolsVM = std::make_shared(m_vm->GetAddressSize()); + m_localSymbolsVM->MapRegion(fileAccessor, {0, fileAccessor.lock()->Length()}, 0); + return; + } + // Populate virtual memory using the entry mappings, by doing so we can now // read the memory of the mapped regions of the cache entry file. const auto& mappings = entry.GetMappings(); -- cgit v1.3.1