From 9fa3dd7b2f00fe2e988e319d3fdb83ee99e30cd0 Mon Sep 17 00:00:00 2001 From: WeiN76LQh Date: Thu, 28 Nov 2024 18:52:19 +0000 Subject: [SharedCache] Define BackingCacheType Split out from https://github.com/WeiN76LQh/binaryninja-api/tree/process-local-symbols --- view/sharedcache/CMakeLists.txt | 2 +- view/sharedcache/api/python/sharedcache.py | 13 +++++++++--- view/sharedcache/api/python/sharedcache_enums.py | 6 ++++++ view/sharedcache/api/sharedcache.cpp | 2 +- view/sharedcache/api/sharedcacheapi.h | 2 +- view/sharedcache/api/sharedcachecore.h | 8 +++++++- view/sharedcache/core/SharedCache.cpp | 26 +++++++++++++----------- view/sharedcache/core/SharedCache.h | 2 +- 8 files changed, 41 insertions(+), 20 deletions(-) (limited to 'view/sharedcache') diff --git a/view/sharedcache/CMakeLists.txt b/view/sharedcache/CMakeLists.txt index 07c58514..8620975c 100644 --- a/view/sharedcache/CMakeLists.txt +++ b/view/sharedcache/CMakeLists.txt @@ -33,7 +33,7 @@ endif() set(HARD_FAIL_MODE OFF CACHE BOOL "Enable hard fail mode") set(SLIDEINFO_DEBUG_TAGS OFF CACHE BOOL "Enable debug tags in slideinfo") set(VIEW_NAME "DSCView" CACHE STRING "Name of the view") -set(METADATA_VERSION 4 CACHE STRING "Version of the metadata") +set(METADATA_VERSION 5 CACHE STRING "Version of the metadata") add_subdirectory(core) add_subdirectory(api) diff --git a/view/sharedcache/api/python/sharedcache.py b/view/sharedcache/api/python/sharedcache.py index e0e18bde..e3ccbb9b 100644 --- a/view/sharedcache/api/python/sharedcache.py +++ b/view/sharedcache/api/python/sharedcache.py @@ -52,14 +52,21 @@ class DSCBackingCacheMapping: @dataclasses.dataclass class DSCBackingCache: path: str - isPrimary: bool + cacheType: BackingCacheType mappings: list[DSCBackingCacheMapping] def __str__(self): return repr(self) def __repr__(self): - return f"" + match self.cacheType: + case BackingCacheType.BackingCacheTypePrimary: + cacheTypeStr = 'Primary' + case BackingCacheType.BackingCacheTypeSecondary: + cacheTypeStr = 'Secondary' + case BackingCacheType.BackingCacheTypeSymbols: + cacheTypeStr = 'Symbols' + return f"" @dataclasses.dataclass @@ -142,7 +149,7 @@ class SharedCache: mappings.append(mapping) result.append(DSCBackingCache( value[i].path, - value[i].isPrimary, + value[i].cacheType, mappings )) diff --git a/view/sharedcache/api/python/sharedcache_enums.py b/view/sharedcache/api/python/sharedcache_enums.py index 34668424..ea86b5c6 100644 --- a/view/sharedcache/api/python/sharedcache_enums.py +++ b/view/sharedcache/api/python/sharedcache_enums.py @@ -1,6 +1,12 @@ import enum +class BackingCacheType(enum.IntEnum): + BackingCacheTypePrimary = 0 + BackingCacheTypeSecondary = 1 + BackingCacheTypeSymbols = 2 + + class DSCViewLoadProgress(enum.IntEnum): LoadProgressNotStarted = 0 LoadProgressLoadingCaches = 1 diff --git a/view/sharedcache/api/sharedcache.cpp b/view/sharedcache/api/sharedcache.cpp index a0c4e961..d9838057 100644 --- a/view/sharedcache/api/sharedcache.cpp +++ b/view/sharedcache/api/sharedcache.cpp @@ -102,7 +102,7 @@ namespace SharedCacheAPI { { BackingCache cache; cache.path = value[i].path; - cache.isPrimary = value[i].isPrimary; + cache.cacheType = value[i].cacheType; for (size_t j = 0; j < value[i].mappingCount; j++) { BackingCacheMapping mapping; diff --git a/view/sharedcache/api/sharedcacheapi.h b/view/sharedcache/api/sharedcacheapi.h index 712cc98e..af82bb62 100644 --- a/view/sharedcache/api/sharedcacheapi.h +++ b/view/sharedcache/api/sharedcacheapi.h @@ -105,7 +105,7 @@ namespace SharedCacheAPI { struct BackingCache { std::string path; - bool isPrimary; + BNBackingCacheType cacheType; std::vector mappings; }; diff --git a/view/sharedcache/api/sharedcachecore.h b/view/sharedcache/api/sharedcachecore.h index c2e1c7bd..54899919 100644 --- a/view/sharedcache/api/sharedcachecore.h +++ b/view/sharedcache/api/sharedcachecore.h @@ -64,6 +64,12 @@ extern "C" LoadProgressFinished, } BNDSCViewLoadProgress; + typedef enum BNBackingCacheType { + BackingCacheTypePrimary, + BackingCacheTypeSecondary, + BackingCacheTypeSymbols, + } BNBackingCacheType; + typedef struct BNBinaryView BNBinaryView; typedef struct BNSharedCache BNSharedCache; typedef struct BNStringRef BNStringRef; @@ -98,7 +104,7 @@ extern "C" typedef struct BNDSCBackingCache { char* path; - bool isPrimary; + BNBackingCacheType cacheType; BNDSCBackingCacheMapping* mappings; size_t mappingCount; } BNDSCBackingCache; diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index 9139d7ba..eae2e5b8 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -517,7 +517,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) { dyld_cache_mapping_info mapping {}; BackingCache cache; - cache.isPrimary = true; + cache.cacheType = BackingCacheTypePrimary; cache.path = path; for (size_t i = 0; i < primaryCacheHeader.mappingCount; i++) @@ -583,7 +583,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) // briefly. BackingCache cache; - cache.isPrimary = true; + cache.cacheType = BackingCacheTypePrimary; cache.path = path; for (size_t i = 0; i < primaryCacheHeader.mappingCount; i++) @@ -654,7 +654,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) dyld_cache_mapping_info subCacheMapping {}; BackingCache subCache; - subCache.isPrimary = false; + subCache.cacheType = BackingCacheTypeSecondary; subCache.path = subCachePath; for (size_t j = 0; j < subCacheHeader.mappingCount; j++) @@ -688,7 +688,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) dyld_cache_mapping_info mapping {}; // We're going to reuse this for all of the mappings. We only need it // briefly. BackingCache cache; - cache.isPrimary = true; + cache.cacheType = BackingCacheTypePrimary; cache.path = path; for (size_t i = 0; i < primaryCacheHeader.mappingCount; i++) @@ -740,7 +740,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) subCacheFile->Read(&subCacheHeader, 0, headerSize); BackingCache subCache; - subCache.isPrimary = false; + subCache.cacheType = BackingCacheTypeSecondary; subCache.path = subCachePath; dyld_cache_mapping_info subCacheMapping {}; @@ -808,7 +808,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) dyld_cache_mapping_info mapping {}; BackingCache cache; - cache.isPrimary = true; + cache.cacheType = BackingCacheTypePrimary; cache.path = path; for (size_t i = 0; i < primaryCacheHeader.mappingCount; i++) @@ -885,7 +885,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) dyld_cache_mapping_info subCacheMapping {}; BackingCache subCache; - subCache.isPrimary = false; + subCache.cacheType = BackingCacheTypeSecondary; subCache.path = subCachePath; for (size_t j = 0; j < subCacheHeader.mappingCount; j++) @@ -942,7 +942,7 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) subCacheFile->Read(&subCacheHeader, 0, headerSize); BackingCache subCache; - subCache.isPrimary = false; + subCache.cacheType = BackingCacheTypeSymbols; subCache.path = subCachePath; dyld_cache_mapping_info subCacheMapping {}; @@ -957,7 +957,9 @@ void SharedCache::PerformInitialLoad(std::lock_guard& lock) initialState.backingCaches.push_back(std::move(subCache)); } catch (...) - {} + { + m_logger->LogWarn("Failed to load the symbols cache"); + } break; } } @@ -3370,7 +3372,7 @@ extern "C" for (size_t i = 0; i < viewCaches.size(); i++) { caches[i].path = BNAllocString(viewCaches[i].path.c_str()); - caches[i].isPrimary = viewCaches[i].isPrimary; + caches[i].cacheType = viewCaches[i].cacheType; BNDSCBackingCacheMapping* mappings; mappings = new BNDSCBackingCacheMapping[viewCaches[i].mappings.size()]; @@ -3750,7 +3752,7 @@ void SharedCache::ModifiedState::Merge(SharedCache::ModifiedState&& newer) void BackingCache::Store(SerializationContext& context) const { MSS(path); - MSS(isPrimary); + MSS_CAST(cacheType, uint32_t); MSS(mappings); } @@ -3758,7 +3760,7 @@ BackingCache BackingCache::Load(DeserializationContext& context) { BackingCache cache; cache.MSL(path); - cache.MSL(isPrimary); + cache.MSL_CAST(cacheType, uint32_t, BNBackingCacheType); cache.MSL(mappings); return cache; } diff --git a/view/sharedcache/core/SharedCache.h b/view/sharedcache/core/SharedCache.h index f5f63749..ee4228ef 100644 --- a/view/sharedcache/core/SharedCache.h +++ b/view/sharedcache/core/SharedCache.h @@ -104,7 +104,7 @@ namespace SharedCacheCore { struct BackingCache : public MetadataSerializable { std::string path; - bool isPrimary = false; + BNBackingCacheType cacheType = BackingCacheTypeSecondary; std::vector mappings; void Store(SerializationContext& context) const; -- cgit v1.3.1