From b3cfd46356af3416d72bd6593bb2a397e72554b6 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Tue, 18 Feb 2025 18:03:06 -0500 Subject: [SharedCache] Fix loading DSC BNDB from a local project crashing Also fixes a BinaryViewRef leak --- view/sharedcache/core/SharedCache.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'view/sharedcache/core/SharedCache.cpp') diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index 2980c0e2..e3c115cd 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -317,19 +317,16 @@ uint64_t SharedCache::FastGetBackingCacheCount(BinaryNinja::RefPath(); auto subCacheCount = header.subCacheArrayCount; return subCacheCount + 1; } case SplitCacheFormat: { - auto mainFileName = baseFile->Path(); auto subCacheCount = header.subCacheArrayCount; return subCacheCount + 2; } case iOS16CacheFormat: { - auto mainFileName = baseFile->Path(); auto subCacheCount = header.subCacheArrayCount; return subCacheCount + 2; } @@ -640,7 +637,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) subCachePath = path + "." + entry.fileExtension; subCacheFilename = mainFileName + "." + entry.fileExtension; } - auto subCacheFile = MapFileWithoutApplyingSlide(subCachePath); + auto subCacheFile = MapFileWithoutApplyingSlide(ResolveFilePath(m_dscView, subCachePath)); dyld_cache_header subCacheHeader {}; uint64_t headerSize = subCacheFile->ReadUInt32(16); @@ -727,7 +724,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) { auto subCachePath = path + "." + std::to_string(i); auto subCacheFilename = mainFileName + "." + std::to_string(i); - auto subCacheFile = MapFileWithoutApplyingSlide(subCachePath); + auto subCacheFile = MapFileWithoutApplyingSlide(ResolveFilePath(m_dscView, subCachePath)); dyld_cache_header subCacheHeader {}; uint64_t headerSize = subCacheFile->ReadUInt32(16); @@ -773,7 +770,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) // Load .symbols subcache try { auto subCachePath = path + ".symbols"; - auto subCacheFile = MapFileWithoutApplyingSlide(subCachePath); + auto subCacheFile = MapFileWithoutApplyingSlide(ResolveFilePath(m_dscView, subCachePath)); dyld_cache_header subCacheHeader {}; uint64_t headerSize = subCacheFile->ReadUInt32(16); @@ -870,7 +867,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) subCacheFilename = mainFileName + "." + entry.fileExtension; } - auto subCacheFile = MapFileWithoutApplyingSlide(subCachePath); + auto subCacheFile = MapFileWithoutApplyingSlide(ResolveFilePath(m_dscView, subCachePath)); dyld_cache_header subCacheHeader {}; uint64_t headerSize = subCacheFile->ReadUInt32(16); @@ -931,7 +928,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) try { auto subCachePath = path + ".symbols"; - auto subCacheFile = MapFileWithoutApplyingSlide(subCachePath); + auto subCacheFile = MapFileWithoutApplyingSlide(ResolveFilePath(m_dscView, subCachePath)); dyld_cache_header subCacheHeader {}; uint64_t headerSize = subCacheFile->ReadUInt32(16); if (subCacheFile->ReadUInt32(16) > sizeof(dyld_cache_header)) @@ -3564,7 +3561,7 @@ uint64_t SharedCache::GetObjCRelativeMethodBaseAddress(const VMReader& reader) c std::shared_ptr SharedCache::MapFile(const std::string& path) { uint64_t baseAddress = m_cacheInfo->BaseAddress(); - return MMappedFileAccessor::Open(m_dscView, m_dscView->GetFile()->GetSessionId(), path, + return MMappedFileAccessor::Open(m_dscView->GetFile()->GetSessionId(), path, [baseAddress, logger = m_logger](std::shared_ptr mmap) { ParseAndApplySlideInfoForFile(mmap, baseAddress, logger); }) -- cgit v1.3.1