Skip to content

Commit e3060d1

Browse files
committed
[SharedCache] Warn when loading BNDB with different shared cache metadata version
This does not actually give the user control to exit early, that looks to need core changes.
1 parent f8e0ad8 commit e3060d1

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

view/sharedcache/core/DSCView.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ bool DSCView::Init()
195195
if (m_parseOnly)
196196
return true;
197197

198+
// Check the metadata version if there is one, so we can alert the user to why they have no loaded images.
199+
// TODO: Once the view is able to be exited early we should offer to close the view if the user does not want to upgrade.
200+
auto metadataVersion = SharedCacheCore::SharedCacheMetadata::ViewMetadataVersion(GetParentView());
201+
if (metadataVersion.has_value() && metadataVersion.value() != METADATA_VERSION)
202+
{
203+
ShowMessageBox("Invalid Shared Cache Metadata!", "The BNDB shared cache metadata was created with a different version of the Shared Cache view, to continue the metadata has to be recreated. You will need to add your images back again.");
204+
}
205+
198206
// Add Mach-O file header type info
199207
EnumerationBuilder cpuTypeBuilder;
200208
cpuTypeBuilder.AddMemberWithValue("CPU_TYPE_ANY", MACHO_CPU_TYPE_ANY);

view/sharedcache/core/SharedCache.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,6 +3594,21 @@ bool SharedCacheMetadata::ViewHasMetadata(BinaryView* view)
35943594
return view->QueryMetadata(Tag);
35953595
}
35963596

3597+
std::optional<unsigned int> SharedCacheMetadata::ViewMetadataVersion(BinaryView* view)
3598+
{
3599+
// Whether the view has compatible metadata. I.e. if the version differs.
3600+
Ref<Metadata> viewMetadata = view->QueryMetadata(Tag);
3601+
if (!viewMetadata)
3602+
return std::nullopt;
3603+
DeserializationContext context;
3604+
rapidjson::ParseResult result = context.doc.Parse(viewMetadata->GetString().c_str());
3605+
if (!result)
3606+
return std::nullopt;
3607+
if (!context.doc.HasMember("metadataVersion"))
3608+
return std::nullopt;
3609+
return context.doc["metadataVersion"].GetUint();
3610+
}
3611+
35973612
// static
35983613
std::optional<SharedCacheMetadata> SharedCacheMetadata::LoadFromView(BinaryView* view)
35993614
{

view/sharedcache/core/SharedCache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ namespace SharedCacheCore {
668668
public:
669669
static std::optional<SharedCacheMetadata> LoadFromView(BinaryView*);
670670
static bool ViewHasMetadata(BinaryView*);
671+
static std::optional<unsigned int> ViewMetadataVersion(BinaryView*);
671672

672673
const std::unordered_map<uint64_t, std::shared_ptr<std::unordered_map<uint64_t, Ref<Symbol>>>>& ExportInfos() const;
673674
std::string InstallNameForImageBaseAddress(uint64_t baseAddress) const;

0 commit comments

Comments
 (0)