diff options
| author | Mason Reed <mason@vector35.com> | 2025-04-02 14:42:55 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-04-02 14:42:55 -0400 |
| commit | 003072f957498a11b7fdcbb56892af0c281c85b3 (patch) | |
| tree | f7ded5b8b876e717b20ed4402e6582b6e7aeb7d2 /view/sharedcache | |
| parent | 49ea03c417168a707125169b77e6ff1c7ebbe097 (diff) | |
[SharedCache] Misc fixes and comments
Diffstat (limited to 'view/sharedcache')
| -rw-r--r-- | view/sharedcache/core/MachOProcessor.cpp | 2 | ||||
| -rw-r--r-- | view/sharedcache/core/MappedFileAccessor.cpp | 2 | ||||
| -rw-r--r-- | view/sharedcache/core/MappedFileAccessor.h | 2 | ||||
| -rw-r--r-- | view/sharedcache/core/SharedCacheController.cpp | 5 | ||||
| -rw-r--r-- | view/sharedcache/core/SharedCacheController.h | 2 | ||||
| -rw-r--r-- | view/sharedcache/workflow/SharedCacheWorkflow.cpp | 2 |
6 files changed, 13 insertions, 2 deletions
diff --git a/view/sharedcache/core/MachOProcessor.cpp b/view/sharedcache/core/MachOProcessor.cpp index 565e6d06..7f3da817 100644 --- a/view/sharedcache/core/MachOProcessor.cpp +++ b/view/sharedcache/core/MachOProcessor.cpp @@ -193,6 +193,8 @@ uint64_t SharedCacheMachOProcessor::ApplyHeaderSections(SharedCacheMachOHeader& if (strncmp(section.segname, "__DATA_CONST", sizeof(section.segname)) == 0) semantics = ReadOnlyDataSectionSemantics; + // Typically a view would add auto sections but those won't persist when loading the BNDB. + // if we want to use an auto section here we would need to allow the core to apply auto sections from the database. m_view->AddUserSection(sectionName, section.addr, section.size, semantics, type, section.align); return true; diff --git a/view/sharedcache/core/MappedFileAccessor.cpp b/view/sharedcache/core/MappedFileAccessor.cpp index 9d6663b5..3c9bf1e2 100644 --- a/view/sharedcache/core/MappedFileAccessor.cpp +++ b/view/sharedcache/core/MappedFileAccessor.cpp @@ -14,6 +14,8 @@ std::shared_ptr<MappedFileAccessor> MappedFileAccessor::Open(const std::string& // TODO: Will obviously not work on 32bit binaries, need to make WritePointer64 and 32 equiv. void MappedFileAccessor::WritePointer(size_t address, size_t pointer) { + if (address + sizeof(size_t*) > Length()) + throw UnmappedAccessException(address + sizeof(size_t*), Length()); m_dirty = true; *reinterpret_cast<size_t*>(&m_file._mmap[address]) = pointer; } diff --git a/view/sharedcache/core/MappedFileAccessor.h b/view/sharedcache/core/MappedFileAccessor.h index 7b01cb0d..2bbf4ba9 100644 --- a/view/sharedcache/core/MappedFileAccessor.h +++ b/view/sharedcache/core/MappedFileAccessor.h @@ -19,7 +19,7 @@ public: { thread_local std::string message; message = - fmt::format("Tried to access unmapped address {0:x} for file with length of {0:x}", m_address, m_fileLen); + fmt::format("Tried to access unmapped address {0:x} for file with length of {01:x}", m_address, m_fileLen); return message.c_str(); } }; diff --git a/view/sharedcache/core/SharedCacheController.cpp b/view/sharedcache/core/SharedCacheController.cpp index 5b14d7ce..2dabefb5 100644 --- a/view/sharedcache/core/SharedCacheController.cpp +++ b/view/sharedcache/core/SharedCacheController.cpp @@ -83,6 +83,11 @@ DSCRef<SharedCacheController> SharedCacheController::Initialize(BinaryView& view dscView->m_regionFilter = std::regex(settings->Get<std::string>("loader.dsc.regionFilter", &view)); } + // TODO: Support old shared cache metadata + // TODO: Not strictly necessary as the user has already loaded the information into the database, this would just + // TODO: prevent incidental extra work from being done when loading a region or image. + // const uint64_t oldStateCount = view.GetUIntMetadata(OLD_METADATA_KEY_COUNT); + // Check the view auto metadata for shared cache information. // This effectively restores the state of the opened database to when it was last saved. // NOTE: We store on the parent view because hilariously, the metadata is not present until after view init. diff --git a/view/sharedcache/core/SharedCacheController.h b/view/sharedcache/core/SharedCacheController.h index 3b92f198..caf61e41 100644 --- a/view/sharedcache/core/SharedCacheController.h +++ b/view/sharedcache/core/SharedCacheController.h @@ -12,6 +12,8 @@ void RegisterSharedCacheControllerDestructor(); namespace BinaryNinja::DSC { static const char* METADATA_KEY = "shared_cache"; + static const char* OLD_METADATA_KEY_COUNT = "SHAREDCACHE-ModifiedState-Count"; + static const char* OLD_METADATA_KEY_PREFIX = "SHAREDCACHE-ModifiedState-"; // Represents the view state for a given `DSCache` class SharedCacheController : public DSCRefCountObject diff --git a/view/sharedcache/workflow/SharedCacheWorkflow.cpp b/view/sharedcache/workflow/SharedCacheWorkflow.cpp index 8046ed22..7dde4089 100644 --- a/view/sharedcache/workflow/SharedCacheWorkflow.cpp +++ b/view/sharedcache/workflow/SharedCacheWorkflow.cpp @@ -126,7 +126,7 @@ void AnalyzeStubFunction(Ref<Function> func, Ref<MediumLevelILFunction> mlil, Sh // We allow the user to automatically load the directly referenced objc images as having the calls inlined is extremely useful for objc. auto loadTargetImage = [&](uint64_t imageAddr) { - auto image = controller.GetImageContaining(imageAddr); + const auto image = controller.GetImageContaining(imageAddr); if (!image.has_value()) return false; return controller.ApplyImage(*view, *image); |
