Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions view/sharedcache/core/SharedCacheController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,27 @@ void SharedCacheController::LoadMetadata(const Metadata& metadata)
m_loadedImages.insert(region);
}
}


void SharedCacheController::ProcessObjCForLoadedImages(BinaryView& view)
{
if (!m_processObjC || m_loadedImages.empty())
return;

for (const auto& headerAddress : m_loadedImages)
{
auto image = m_cache.GetImageAt(headerAddress);
if (!image)
continue;

auto objcProcessor = DSCObjC::SharedCacheObjCProcessor(&view, image->headerAddress);
try
{
objcProcessor.ProcessObjCData();
}
catch (std::exception& e)
{
m_logger->LogErrorForExceptionF(e, "Failed to restore ObjC metadata for image at {:#x}: {}", headerAddress, e.what());
}
}
}
3 changes: 3 additions & 0 deletions view/sharedcache/core/SharedCacheController.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ namespace BinaryNinja::DSC {
Ref<Metadata> GetMetadata() const;

void LoadMetadata(const Metadata& metadata);

// Re-run the ObjC processor for loaded images to restore Objective-C metadata.
void ProcessObjCForLoadedImages(BinaryView& view);
};
} // namespace BinaryNinja::DSC
8 changes: 8 additions & 0 deletions view/sharedcache/core/SharedCacheView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,14 @@ bool SharedCacheView::InitController()
return true;
}


void SharedCacheView::DidApplySnapshotData()
{
if (auto controller = SharedCacheController::FromView(*this))
controller->ProcessObjCForLoadedImages(*this);
}


void SharedCacheView::SetPrimaryFileName(std::string primaryFileName)
{
m_primaryFileName = std::move(primaryFileName);
Expand Down
1 change: 1 addition & 0 deletions view/sharedcache/core/SharedCacheView.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SharedCacheView : public BinaryNinja::BinaryView
~SharedCacheView() override = default;

bool Init() override;
void DidApplySnapshotData() override;

// Initialized the shared cache controller for this view. This is what allows us to load images and regions.
bool InitController();
Expand Down