diff options
| author | kat <kat@vector35.com> | 2024-10-30 08:39:09 -0400 |
|---|---|---|
| committer | kat <kat@vector35.com> | 2024-11-05 09:03:12 -0500 |
| commit | f4a4b17b9e30cf603eb614e153d68226a3b24520 (patch) | |
| tree | e33d18742c1a9e9b47af04df24bf88248c17f06a /view/sharedcache/api | |
| parent | fd8eb478a7a3bbc848da37bd33e62c2d8cf26b99 (diff) | |
[SharedCache] Implement LoadedImage API, Fix serialized image names, more robust system for out-of-date databases
Diffstat (limited to 'view/sharedcache/api')
| -rw-r--r-- | view/sharedcache/api/CMakeLists.txt | 32 | ||||
| -rw-r--r-- | view/sharedcache/api/python/_sharedcachecore.py | 17 | ||||
| -rw-r--r-- | view/sharedcache/api/python/sharedcache.py | 45 | ||||
| -rw-r--r-- | view/sharedcache/api/sharedcachecore.h | 1 |
4 files changed, 46 insertions, 49 deletions
diff --git a/view/sharedcache/api/CMakeLists.txt b/view/sharedcache/api/CMakeLists.txt index 1766352d..c14674a7 100644 --- a/view/sharedcache/api/CMakeLists.txt +++ b/view/sharedcache/api/CMakeLists.txt @@ -4,16 +4,36 @@ project(sharedcacheapi) file(GLOB BN_MACHO_API_SOURCES *.cpp *.h) add_library(sharedcacheapi OBJECT ${BN_MACHO_API_SOURCES}) + +set(COMPILE_DEFS "") + +if (HARD_FAIL_MODE) + set(COMPILE_DEFS "${COMPILE_DEFS} ABORT_FAILURES;") +endif() + +if (BN_REF_COUNT_DEBUG) + set(COMPILE_DEFS "${COMPILE_DEFS} BN_REF_COUNT_DEBUG;") +endif() + +if (SLIDEINFO_DEBUG_TAGS) + set(COMPILE_DEFS "${COMPILE_DEFS} SLIDEINFO_DEBUG_TAGS;") +endif() + +if (METADATA_VERSION) + set(COMPILE_DEFS "${COMPILE_DEFS} METADATA_VERSION=${METADATA_VERSION};") +else() + message(FATAL_ERROR "No metadata version provided. Fatal.") +endif() + if (VIEW_NAME) - if (BN_REF_COUNT_DEBUG) - target_compile_definitions(sharedcacheapi PRIVATE VIEW_NAME="${VIEW_NAME}" BN_REF_COUNT_DEBUG) - else() - target_compile_definitions(sharedcacheapi PRIVATE VIEW_NAME="${VIEW_NAME}") - endif() + set(COMPILE_DEFS "${COMPILE_DEFS} VIEW_NAME=\"${VIEW_NAME}\";") else() - error("VIEW_NAME must be defined") + message(FATAL_ERROR "No view name provided. Fatal.") endif() +target_compile_definitions(sharedcacheapi PRIVATE ${COMPILE_DEFS}) + + function(get_recursive_include_dirs target result) # Initialize an empty list to store include directories set(include_dirs "") diff --git a/view/sharedcache/api/python/_sharedcachecore.py b/view/sharedcache/api/python/_sharedcachecore.py index 93228468..d208048b 100644 --- a/view/sharedcache/api/python/_sharedcachecore.py +++ b/view/sharedcache/api/python/_sharedcachecore.py @@ -578,23 +578,6 @@ def BNDSCViewLoadSectionAtAddress( # ------------------------------------------------------- -# _BNDSCViewLoadedImageCount - -_BNDSCViewLoadedImageCount = core.BNDSCViewLoadedImageCount -_BNDSCViewLoadedImageCount.restype = ctypes.c_ulonglong -_BNDSCViewLoadedImageCount.argtypes = [ - ctypes.POINTER(BNSharedCache), - ] - - -# noinspection PyPep8Naming -def BNDSCViewLoadedImageCount( - cache: ctypes.POINTER(BNSharedCache) - ) -> int: - return _BNDSCViewLoadedImageCount(cache) - - -# ------------------------------------------------------- # _BNFreeSharedCacheReference _BNFreeSharedCacheReference = core.BNFreeSharedCacheReference diff --git a/view/sharedcache/api/python/sharedcache.py b/view/sharedcache/api/python/sharedcache.py index ca031e03..54745ed5 100644 --- a/view/sharedcache/api/python/sharedcache.py +++ b/view/sharedcache/api/python/sharedcache.py @@ -12,17 +12,15 @@ from .sharedcache_enums import * @dataclasses.dataclass class DSCMemoryMapping: - filePath: str name: str vmAddress: int - rawViewOffset: int size: int def __str__(self): return repr(self) def __repr__(self): - return f"<DSCMemoryMapping '{self.name}' {os.path.basename(self.filePath)} raw<{self.rawViewOffset:x}>: {self.vmAddress:x}+{self.size:x}>" + return f"<DSCMemoryMapping '{self.name}': {self.vmAddress:x}+{self.size:x}>" @dataclasses.dataclass @@ -176,31 +174,32 @@ class SharedCache: return result @property - def loaded_images(self): + def loaded_regions(self): + """ + Get all loaded regions in the shared cache + + The internal logic for loading images treats a region as 'loaded' whenever + that region has been mapped into memory, and, if it's located within an image, header information has been applied to that region. + + Individual segments within an image can be loaded independently of the image itself. + + Only once all regions of an image are loaded will the header processor refuse to run on that region. + :return: + """ count = ctypes.c_ulonglong() - value = sccore.BNDSCViewGetLoadedImages(self.handle, count) + value = sccore.BNDSCViewGetLoadedRegions(self.handle, count) if value is None: return [] result = [] for i in range(count.value): - mappings = [] - for j in range(value[i].mappingCount): - mapping = DSCMemoryMapping( - value[i].mappings[j].filePath, - value[i].mappings[j].name, - value[i].mappings[j].vmAddress, - value[i].mappings[j].rawViewOffset, - value[i].mappings[j].size - ) - mappings.append(mapping) - result.append(LoadedRegion( + mapping = DSCMemoryMapping( value[i].name, - value[i].headerAddress, - mappings - )) - - sccore.BNDSCViewFreeLoadedImages(value, count) + value[i].vmAddress, + value[i].size, + ) + result.append(mapping) + sccore.BNDSCViewFreeLoadedRegions(value, count) return result def load_all_symbols_and_wait(self): @@ -235,10 +234,6 @@ class SharedCache: return result @property - def image_count(self): - return sccore.BNDSCViewLoadedImageCount(self.handle) - - @property def state(self): return DSCViewState(sccore.BNDSCViewGetState(self.handle)) diff --git a/view/sharedcache/api/sharedcachecore.h b/view/sharedcache/api/sharedcachecore.h index 1c382e48..9fc33275 100644 --- a/view/sharedcache/api/sharedcachecore.h +++ b/view/sharedcache/api/sharedcachecore.h @@ -119,7 +119,6 @@ extern "C" SHAREDCACHE_FFI_API void BNFreeSharedCacheReference(BNSharedCache* cache); SHAREDCACHE_FFI_API char** BNDSCViewGetInstallNames(BNSharedCache* cache, size_t* count); - SHAREDCACHE_FFI_API uint64_t BNDSCViewLoadedImageCount(BNSharedCache* cache); SHAREDCACHE_FFI_API bool BNDSCViewLoadImageWithInstallName(BNSharedCache* cache, char* name); SHAREDCACHE_FFI_API bool BNDSCViewLoadSectionAtAddress(BNSharedCache* cache, uint64_t name); |
