Skip to content

Commit 86690fa

Browse files
committed
[SharedCache] Consistent logger naming and misc changes
1 parent 0aabebe commit 86690fa

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

view/sharedcache/core/MachOProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using namespace BinaryNinja;
66
SharedCacheMachOProcessor::SharedCacheMachOProcessor(Ref<BinaryView> view, std::shared_ptr<VirtualMemory> vm)
77
{
88
m_view = view;
9-
m_logger = new Logger("SharedCacheMachOProcessor", view->GetFile()->GetSessionId());
9+
m_logger = new Logger("SharedCache.MachOProcessor", view->GetFile()->GetSessionId());
1010
m_vm = std::move(vm);
1111

1212
// Adjust processor settings.

view/sharedcache/core/SharedCache.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ std::optional<CacheSymbol> SharedCache::GetSymbolWithName(const std::string& nam
491491
CacheProcessor::CacheProcessor(Ref<BinaryView> view)
492492
{
493493
m_view = std::move(view);
494-
m_logger = new Logger("CacheProcessor", m_view->GetFile()->GetSessionId());
494+
m_logger = new Logger("SharedCache.Processor", m_view->GetFile()->GetSessionId());
495495
}
496496

497497
bool CacheProcessor::ProcessCache(SharedCache& cache)
@@ -523,6 +523,7 @@ bool CacheProcessor::ProcessFileCache(SharedCache& cache)
523523
catch (const std::exception& e)
524524
{
525525
// Just return false so the view init can continue.
526+
m_logger->LogErrorF("Failed to load base entry {}... {}", baseFileName, e.what());
526527
return false;
527528
}
528529

@@ -535,7 +536,7 @@ bool CacheProcessor::ProcessFileCache(SharedCache& cache)
535536
auto currentFilePath = entry.path().string();
536537
auto currentFileName = BaseFileName(currentFilePath);
537538
// Skip our base file, obviously.
538-
if (currentFilePath== baseFilePath)
539+
if (currentFilePath == baseFilePath)
539540
continue;
540541
// Filter files that don't contain the base file name i.e. "dyld_shared_cache_arm64e"
541542
if (currentFilePath.find(baseFileName) == std::string::npos)
@@ -559,7 +560,9 @@ bool CacheProcessor::ProcessFileCache(SharedCache& cache)
559560
cache.AddEntry(std::move(*additionalEntry));
560561
}
561562
catch (const std::exception& e)
562-
{}
563+
{
564+
m_logger->LogErrorF("Failed to load entry {}... {}", currentFileName, e.what());
565+
}
563566
}
564567

565568
return true;

view/sharedcache/core/SharedCacheController.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ DSCRef<SharedCacheController> SharedCacheController::Initialize(BinaryView& view
6969
{
7070
auto id = GetViewIdFromView(view);
7171
std::unique_lock<std::shared_mutex> lock(GlobalControllersMutex);
72-
auto logger = new Logger("SharedCacheController", view.GetFile()->GetSessionId());
72+
auto logger = new Logger("SharedCache.Controller", view.GetFile()->GetSessionId());
7373
DSCRef<SharedCacheController> dscView = new SharedCacheController(std::move(cache), logger);
7474

7575
// Pull the settings from the view.
@@ -216,6 +216,8 @@ bool SharedCacheController::ApplyImage(BinaryView& view, const CacheImage& image
216216

217217
m_loadedImages.insert(image.headerAddress);
218218

219+
m_logger->LogInfoF("Loaded image: '{}'", image.path);
220+
219221
// TODO: This needs to be done in a "database save" callback.
220222
view.StoreMetadata(METADATA_KEY, GetMetadata());
221223

view/sharedcache/core/SharedCacheView.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bool SharedCacheView::Init()
169169
std::string os;
170170
std::string arch;
171171

172-
auto logger = new Logger("SharedCacheView", GetFile()->GetSessionId());
172+
auto logger = new Logger("SharedCache.View", GetFile()->GetSessionId());
173173

174174
uint32_t platform;
175175
GetParentView()->Read(&platform, 0xd8, 4);
@@ -794,6 +794,7 @@ bool SharedCacheView::Init()
794794
// TODO: Prompt the user to select the primary cache file? We can still recover from here.
795795
// Oh no, we failed to process the cache, this likely means the primary on-disk file was not able to be found.
796796
logger->LogError("Failed to process cache, likely missing cache files.");
797+
// TODO: Returning false here does not prevent the file from being opened.
797798
// NOTE: An interaction handler headlessly could select yes to this, however for the purposes of this we will just let them continue by defualt.
798799
if (IsUIEnabled() && ShowMessageBox("Continue opening", "This shared cache file was unable to be processed, would you like to open without shared cache information?", YesNoButtonSet, QuestionIcon) != YesButton)
799800
return false;

0 commit comments

Comments
 (0)