Skip to content

Commit 0a35657

Browse files
committed
[DSC] Process Objective-C metadata when loading view from .bndb
The processed Objective-C metadata is not saved to the .bdnb. It must be recomputed when the view is loaded. Fixes #8030.
1 parent ddd7aa4 commit 0a35657

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

view/sharedcache/core/SharedCacheController.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,27 @@ void SharedCacheController::LoadMetadata(const Metadata& metadata)
292292
m_loadedImages.insert(region);
293293
}
294294
}
295+
296+
297+
void SharedCacheController::ProcessObjCForLoadedImages(BinaryView& view)
298+
{
299+
if (!m_processObjC || m_loadedImages.empty())
300+
return;
301+
302+
for (const auto& headerAddress : m_loadedImages)
303+
{
304+
auto image = m_cache.GetImageAt(headerAddress);
305+
if (!image)
306+
continue;
307+
308+
auto objcProcessor = DSCObjC::SharedCacheObjCProcessor(&view, image->headerAddress);
309+
try
310+
{
311+
objcProcessor.ProcessObjCData();
312+
}
313+
catch (std::exception& e)
314+
{
315+
m_logger->LogErrorForExceptionF(e, "Failed to restore ObjC metadata for image at {:#x}: {}", headerAddress, e.what());
316+
}
317+
}
318+
}

view/sharedcache/core/SharedCacheController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,8 @@ namespace BinaryNinja::DSC {
6363
Ref<Metadata> GetMetadata() const;
6464

6565
void LoadMetadata(const Metadata& metadata);
66+
67+
// Re-run the ObjC processor for loaded images to restore Objective-C metadata.
68+
void ProcessObjCForLoadedImages(BinaryView& view);
6669
};
6770
} // namespace BinaryNinja::DSC

view/sharedcache/core/SharedCacheView.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,14 @@ bool SharedCacheView::InitController()
981981
return true;
982982
}
983983

984+
985+
void SharedCacheView::OnAfterSnapshotDataApplied()
986+
{
987+
if (auto controller = SharedCacheController::FromView(*this))
988+
controller->ProcessObjCForLoadedImages(*this);
989+
}
990+
991+
984992
void SharedCacheView::SetPrimaryFileName(std::string primaryFileName)
985993
{
986994
m_primaryFileName = std::move(primaryFileName);

view/sharedcache/core/SharedCacheView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class SharedCacheView : public BinaryNinja::BinaryView
2525
~SharedCacheView() override = default;
2626

2727
bool Init() override;
28+
void OnAfterSnapshotDataApplied() override;
2829

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

0 commit comments

Comments
 (0)