From 4f22a944d77f784b53ee3a37d9f1966ede1c98a4 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 4 Apr 2025 23:57:13 -0400 Subject: [SharedCache] Prevent all functions from being queued up for reanalysis when adding new images and regions Within the user section creation we will assume that because a non-default section was added, we should mark all functions for reanalysis. From initial testing this isn't an extreme slowdown, but with the addition of more images the number of queued up functions becomes much greater, even if those are unmarked immediately and processing of those functions isn't slow it is unneeded and might lead to other non-obvious slowdowns. To be clear, we do not need to queue up functions from already analyzed images to be analyzed again, there is no benefit, our workflow handles cross images calls already, so those places will already be queued up, and if they aren't, that is the issue to solve, not this. --- view/sharedcache/core/SharedCacheController.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'view/sharedcache/core/SharedCacheController.cpp') diff --git a/view/sharedcache/core/SharedCacheController.cpp b/view/sharedcache/core/SharedCacheController.cpp index 678f4b59..13afb476 100644 --- a/view/sharedcache/core/SharedCacheController.cpp +++ b/view/sharedcache/core/SharedCacheController.cpp @@ -159,7 +159,15 @@ bool SharedCacheController::ApplyRegion(BinaryView& view, const CacheRegion& reg // If we are not associated with an image we can create a section here to set the semantics. // This is important for stub regions, as they will deref non image data that we want to retrieve the value of. if (region.type != CacheRegionType::Image) + { + // Adding a user section will mark all functions for updates unless we disable this. + // Because images are known separate compilation units, we have a real reason to make sure we don't mark all previously + // analyzed functions as updated. + auto prevDisabledState = view.GetFunctionAnalysisUpdateDisabled(); + view.SetFunctionAnalysisUpdateDisabled(true); view.AddUserSection(memoryRegionName, region.start, region.size, region.SectionSemanticsForRegion()); + view.SetFunctionAnalysisUpdateDisabled(prevDisabledState); + } m_loadedRegions.insert(region.start); @@ -198,7 +206,14 @@ bool SharedCacheController::ApplyImage(BinaryView& view, const CacheImage& image { // Header information is applied to the view here, such as sections. auto machoProcessor = SharedCacheMachOProcessor(&view, m_cache.GetVirtualMemory()); + + // Adding a user section will mark all functions for updates unless we disable this. + // Because images are known separate compilation units, we have a real reason to make sure we don't mark all previously + // analyzed functions as updated. + auto prevDisabledState = view.GetFunctionAnalysisUpdateDisabled(); + view.SetFunctionAnalysisUpdateDisabled(true); machoProcessor.ApplyHeader(*image.header); + view.SetFunctionAnalysisUpdateDisabled(prevDisabledState); // TODO: Passing in an image name here is weird considering this is shared with the MACHO view. // TODO: We should abstract out the "image" into an objc image type that represents what is required, which ig is the name? -- cgit v1.3.1