diff options
Diffstat (limited to 'view/sharedcache')
| -rw-r--r-- | view/sharedcache/core/DSCView.cpp | 8 | ||||
| -rw-r--r-- | view/sharedcache/core/SharedCache.cpp | 15 | ||||
| -rw-r--r-- | view/sharedcache/core/SharedCache.h | 1 |
3 files changed, 24 insertions, 0 deletions
diff --git a/view/sharedcache/core/DSCView.cpp b/view/sharedcache/core/DSCView.cpp index 782bbe30..aae1e3c4 100644 --- a/view/sharedcache/core/DSCView.cpp +++ b/view/sharedcache/core/DSCView.cpp @@ -195,6 +195,14 @@ bool DSCView::Init() if (m_parseOnly) return true; + // Check the metadata version if there is one, so we can alert the user to why they have no loaded images. + // 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. + auto metadataVersion = SharedCacheCore::SharedCacheMetadata::ViewMetadataVersion(GetParentView()); + if (metadataVersion.has_value() && metadataVersion.value() != METADATA_VERSION) + { + 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."); + } + // Add Mach-O file header type info EnumerationBuilder cpuTypeBuilder; cpuTypeBuilder.AddMemberWithValue("CPU_TYPE_ANY", MACHO_CPU_TYPE_ANY); diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index 9e578384..a9d8a70b 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -3594,6 +3594,21 @@ bool SharedCacheMetadata::ViewHasMetadata(BinaryView* view) return view->QueryMetadata(Tag); } +std::optional<unsigned int> SharedCacheMetadata::ViewMetadataVersion(BinaryView* view) +{ + // Whether the view has compatible metadata. I.e. if the version differs. + Ref<Metadata> viewMetadata = view->QueryMetadata(Tag); + if (!viewMetadata) + return std::nullopt; + DeserializationContext context; + rapidjson::ParseResult result = context.doc.Parse(viewMetadata->GetString().c_str()); + if (!result) + return std::nullopt; + if (!context.doc.HasMember("metadataVersion")) + return std::nullopt; + return context.doc["metadataVersion"].GetUint(); +} + // static std::optional<SharedCacheMetadata> SharedCacheMetadata::LoadFromView(BinaryView* view) { diff --git a/view/sharedcache/core/SharedCache.h b/view/sharedcache/core/SharedCache.h index f6a1e7a8..c78ad554 100644 --- a/view/sharedcache/core/SharedCache.h +++ b/view/sharedcache/core/SharedCache.h @@ -668,6 +668,7 @@ private: public: static std::optional<SharedCacheMetadata> LoadFromView(BinaryView*); static bool ViewHasMetadata(BinaryView*); + static std::optional<unsigned int> ViewMetadataVersion(BinaryView*); const std::unordered_map<uint64_t, std::shared_ptr<std::unordered_map<uint64_t, Ref<Symbol>>>>& ExportInfos() const; std::string InstallNameForImageBaseAddress(uint64_t baseAddress) const; |
