diff options
Diffstat (limited to 'view/sharedcache')
| -rw-r--r-- | view/sharedcache/core/SharedCache.cpp | 8 | ||||
| -rw-r--r-- | view/sharedcache/core/SharedCacheView.cpp | 13 |
2 files changed, 13 insertions, 8 deletions
diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index 2eb885d4..4950c8c0 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -59,12 +59,10 @@ CacheEntry CacheEntry::FromFile(const std::string& filePath, const std::string& // Read the header, this _should_ be compatible with all known DSC formats. // Mason: the above is not true! https://github.com/Vector35/binaryninja-api/issues/6073 + // The mappingOffset should point right after the header. We use this to constrain the read size so unsupported fields are zeroed. + auto headerSize = file->ReadUInt32(0x10); dyld_cache_header header = {}; - file->Read(&header, 0, sizeof(header)); - - // Adjust the array count to actually be the "real" number for comparisons with what we load. - // This is required so we can check if we loaded the required number of caches, in view init. - header.subCacheArrayCount += header.cacheSubType; + file->Read(&header, 0, headerSize); // Read the mappings using the headers `mappingCount` and `mappingOffset`. dyld_cache_mapping_info currentMapping = {}; diff --git a/view/sharedcache/core/SharedCacheView.cpp b/view/sharedcache/core/SharedCacheView.cpp index fb80d132..4218a2fe 100644 --- a/view/sharedcache/core/SharedCacheView.cpp +++ b/view/sharedcache/core/SharedCacheView.cpp @@ -861,16 +861,23 @@ bool SharedCacheView::InitController() LogSecondaryFileName(entry.GetFileName()); // Set the number of sub-caches so we can verify it later. if (entry.GetType() == CacheEntryType::Primary) - expectedFileCount += entry.GetHeader().subCacheArrayCount; + { + const auto& entryHeader = entry.GetHeader(); + // TODO: Some caches seem to have less sub caches than what we report having. + expectedFileCount += entryHeader.subCacheArrayCount; + // On older caches we don't have any sub-caches, so we want to skip alerting the user to that fact. + if (entryHeader.subCacheArrayOffset == 0) + expectedFileCount = 0; + } } for (const auto& missingFileName: missingCacheEntries) m_logger->LogErrorF("Secondary cache file '{}' is missing!", missingFileName); // Verify that we have the required amount of sub-caches, if not alert the user. if (expectedFileCount == 1) - m_logger->LogAlertF("Primary cache file '{}' has no sub-caches! You are likely opening a secondary cache file instead of a primary one.", m_primaryFileName); + m_logger->LogWarnF("Primary cache file '{}' has no sub-caches! You are likely opening a secondary cache file instead of a primary one.", m_primaryFileName); else if (totalEntries < expectedFileCount) - m_logger->LogAlertF("Insufficient cache files in dyld header ({}/{}), loading as partial shared cache...", totalEntries, expectedFileCount); + m_logger->LogWarnF("Insufficient cache files in dyld header ({}/{}), loading as partial shared cache...", totalEntries, expectedFileCount); } auto sharedCache = sharedCacheBuilder.Finalize(); |
