Skip to content

Commit 4f7d5e4

Browse files
committed
[SharedCache] Fix overzealous alert about missing shared cache entries
Following the conversation in #6631 we are going to make the edited alerts warnings and then also fix the warning showing on certain shared caches even when all entries are present.
1 parent 507935f commit 4f7d5e4

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

view/sharedcache/core/SharedCache.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ CacheEntry CacheEntry::FromFile(const std::string& filePath, const std::string&
5959

6060
// Read the header, this _should_ be compatible with all known DSC formats.
6161
// Mason: the above is not true! https://github.com/Vector35/binaryninja-api/issues/6073
62+
// The mappingOffset should point right after the header. We use this to constrain the read size so unsupported fields are zeroed.
63+
auto headerSize = file->ReadUInt32(0x10);
6264
dyld_cache_header header = {};
63-
file->Read(&header, 0, sizeof(header));
64-
65-
// Adjust the array count to actually be the "real" number for comparisons with what we load.
66-
// This is required so we can check if we loaded the required number of caches, in view init.
67-
header.subCacheArrayCount += header.cacheSubType;
65+
file->Read(&header, 0, headerSize);
6866

6967
// Read the mappings using the headers `mappingCount` and `mappingOffset`.
7068
dyld_cache_mapping_info currentMapping = {};

view/sharedcache/core/SharedCacheView.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,16 +861,23 @@ bool SharedCacheView::InitController()
861861
LogSecondaryFileName(entry.GetFileName());
862862
// Set the number of sub-caches so we can verify it later.
863863
if (entry.GetType() == CacheEntryType::Primary)
864-
expectedFileCount += entry.GetHeader().subCacheArrayCount;
864+
{
865+
const auto& entryHeader = entry.GetHeader();
866+
// TODO: Some caches seem to have less sub caches than what we report having.
867+
expectedFileCount += entryHeader.subCacheArrayCount;
868+
// On older caches we don't have any sub-caches, so we want to skip alerting the user to that fact.
869+
if (entryHeader.subCacheArrayOffset == 0)
870+
expectedFileCount = 0;
871+
}
865872
}
866873
for (const auto& missingFileName: missingCacheEntries)
867874
m_logger->LogErrorF("Secondary cache file '{}' is missing!", missingFileName);
868875

869876
// Verify that we have the required amount of sub-caches, if not alert the user.
870877
if (expectedFileCount == 1)
871-
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);
878+
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);
872879
else if (totalEntries < expectedFileCount)
873-
m_logger->LogAlertF("Insufficient cache files in dyld header ({}/{}), loading as partial shared cache...", totalEntries, expectedFileCount);
880+
m_logger->LogWarnF("Insufficient cache files in dyld header ({}/{}), loading as partial shared cache...", totalEntries, expectedFileCount);
874881
}
875882

876883
auto sharedCache = sharedCacheBuilder.Finalize();

0 commit comments

Comments
 (0)