From 86019f825db516d8d5349c271f702dfe69b5fead Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Thu, 10 Apr 2025 00:53:06 -0400 Subject: [SharedCache] Make the shared cache file lookup more straightforward We already had separated this part out into the `CacheProcessor` but its more like a builder than anything, so this refactors that out into a `SharedCacheBuilder`. - Separate out the `CacheProcessor` and simplify its implementation - Move more implementation specific stuff to the shared cache view - Prepare for more validation of the shared cache to detect irregular or incomplete shared cache information - Deduplicate a lot of file vs. project file lookup stuff - Stop copying all images when getting the number of images to log - Allow user to select another directory to scan for shared cache files, might make this a warning instead to prevent users from relying on this behavior We will likely follow this commit up soon with better open behavior, maybe open with options can specify a list of cache entry files? Shouldn't be too much effort aside from making the UI modal for that. --- view/sharedcache/core/SharedCache.h | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) (limited to 'view/sharedcache/core/SharedCache.h') diff --git a/view/sharedcache/core/SharedCache.h b/view/sharedcache/core/SharedCache.h index 0bf04776..8aea0362 100644 --- a/view/sharedcache/core/SharedCache.h +++ b/view/sharedcache/core/SharedCache.h @@ -7,8 +7,6 @@ #include "MachO.h" #include "VirtualMemory.h" -class SharedCache; - struct CacheSymbol { BNSymbolType type; @@ -16,19 +14,15 @@ struct CacheSymbol std::string name; CacheSymbol() = default; - CacheSymbol(BNSymbolType type, uint64_t address, std::string name) : type(type), address(address), name(std::move(name)) {} - ~CacheSymbol() = default; CacheSymbol(const CacheSymbol& other) = default; - CacheSymbol& operator=(const CacheSymbol& other) = default; CacheSymbol(CacheSymbol&& other) noexcept = default; - CacheSymbol& operator=(CacheSymbol&& other) noexcept = default; std::pair> DemangledName(BinaryNinja::BinaryView& view) const; @@ -56,15 +50,12 @@ struct CacheRegion BNSegmentFlag flags; CacheRegion() = default; - ~CacheRegion() = default; CacheRegion(const CacheRegion& other) = default; - CacheRegion& operator=(const CacheRegion& other) = default; CacheRegion(CacheRegion&& other) noexcept = default; - CacheRegion& operator=(CacheRegion&& other) noexcept = default; AddressRange AsAddressRange() const { return {start, start + size}; } @@ -95,15 +86,12 @@ struct CacheImage std::shared_ptr header; CacheImage() = default; - ~CacheImage() = default; CacheImage(const CacheImage& other) = default; - CacheImage& operator=(const CacheImage& other) = default; CacheImage(CacheImage&& other) noexcept = default; - CacheImage& operator=(CacheImage&& other) noexcept = default; // Get the file name from the path. @@ -145,11 +133,9 @@ public: std::vector mappings, std::vector> images); CacheEntry() = default; - CacheEntry(const CacheEntry&) = default; CacheEntry(CacheEntry&&) = default; - CacheEntry& operator=(CacheEntry&&) = default; // Construct a cache entry from the file on disk. @@ -213,6 +199,7 @@ class SharedCache bool AddNonOverlappingRegion(CacheRegion region); public: + SharedCache() = default; explicit SharedCache(uint64_t addressSize); SharedCache(const SharedCache &) = delete; @@ -269,23 +256,3 @@ public: std::optional GetSymbolWithName(const std::string& name); }; - -// This constructs a Cache, give it a file path, and it will add all relevant cache entries. -class CacheProcessor -{ - BinaryNinja::Ref m_view; - BinaryNinja::Ref m_logger; - -public: - explicit CacheProcessor(BinaryNinja::Ref view); - - // Construct a cache from the root file, this will parse the cache header and locate all - // applicable cache entries and add them as well. - bool ProcessCache(SharedCache& cache); - - // Process a cache on the file system, this is for when not using a project. - bool ProcessFileCache(SharedCache& cache); - - // Process a cache using Binary Ninja's project system. - bool ProcessProjectCache(SharedCache& cache); -}; -- cgit v1.3.1