summaryrefslogtreecommitdiff
path: root/view/sharedcache/core/SharedCacheView.h
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-14 02:01:45 -0400
committerMason Reed <mason@vector35.com>2025-04-14 03:20:51 -0400
commit09a617a7a86207eaf09ccd5ebc72e734275baa66 (patch)
treeba2888f3c6a6e0b012bcc93d4c29ed1230201473 /view/sharedcache/core/SharedCacheView.h
parente311e603a8e7f855ce09f68cc45f08c35571144c (diff)
[SharedCache] Improve the gathering of cache entries in view init
This commit addresses some of the issues regarding the retrieval of cache entries during view init, we now will try and store information in the database about the given shared cache entries so that we can better alert the user to possible issues during the loading of saved shared cache databases. We also simplified the logic so that the flow for retrieving the primary file cache is easier and users should be prompted when necessary to select the primary cache file if we cannot. More errors will also be shown to provide the users with more information about the shared cache and what issues they might have. For example we will now try and warn the users when they are opening a shared cache with less entries than what the shared cache reports having. We will also warn the users when opening a database if a previous secondary cache file is no longer available. In the future we can also utilize the shared cache UUID's for individual files to do a more aggressive search across directories in a project. This will make the file name lookup stuff potentially unnecessary, at least when opening a database with all file UUID's stored.
Diffstat (limited to 'view/sharedcache/core/SharedCacheView.h')
-rw-r--r--view/sharedcache/core/SharedCacheView.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/view/sharedcache/core/SharedCacheView.h b/view/sharedcache/core/SharedCacheView.h
index 0ae43368..8d4332cb 100644
--- a/view/sharedcache/core/SharedCacheView.h
+++ b/view/sharedcache/core/SharedCacheView.h
@@ -7,12 +7,20 @@
#include <binaryninjaapi.h>
+static const char* VIEW_METADATA_KEY = "shared_cache_view";
class SharedCacheView : public BinaryNinja::BinaryView
{
bool m_parseOnly;
BinaryNinja::Ref<BinaryNinja::Logger> m_logger;
+ // Restored primary file name from metadata, or the file name on first open.
+ std::string m_primaryFileName;
+
+ // Restored associated file names from metadata, this is all the associated cache entries.
+ // NOTE: Currently this is just used to alert the user to supposed missing files.
+ std::set<std::string> m_secondaryFileNames;
+
public:
SharedCacheView(const std::string& typeName, BinaryView* data, bool parseOnly = false);
@@ -22,6 +30,19 @@ public:
// Initialized the shared cache controller for this view. This is what allows us to load images and regions.
bool InitController();
+
+ void SetPrimaryFileName(std::string primaryFileName);
+
+ // Logs the secondary file name to `m_secondaryFileNames`, see the note on the field about usage.
+ void LogSecondaryFileName(std::string associatedFileName);
+
+ // Get the path to the primary file.
+ std::optional<std::string> GetPrimaryFilePath();
+
+ // Get the metadata for saving the state of the shared cache.
+ BinaryNinja::Ref<BinaryNinja::Metadata> GetMetadata() const;
+
+ void LoadMetadata(const BinaryNinja::Metadata& metadata);
};