Skip to content

BinaryView::AddUserSection gets increasingly slower for sections with semantics that aren't DefaultSectionSemantics #6271

@WeiN76LQh

Description

@WeiN76LQh

Version and Platform (required):

  • Binary Ninja Version: 4.3.6572-dev (37fd69ad)
  • OS: macOS
  • OS Version: 15.1
  • CPU Architecture: M1

Bug Description:
There's a performance issue with BinaryView::AddUserSection where the more sections a BinaryView has the longer it takes to complete if the semantics for the section aren't DefaultSectionSemantics. In the case of DefaultSectionSemantics it appears this always takes less than a millisecond (faster than the resolution of time I was reporting). Outside of DefaultSectionSemantics it doesn't seem to matter what the size of the section is or what the semantics for it are, the time it takes for BinaryView::AddUserSection to complete will be roughly the same and gradually increase as more sections are added.

Steps To Reproduce:
I'm using a modified version of the DSC plugin, which is roughly the same as this PR and then I'm using std::chrono::high_resolution_clock::now() to time how long this call to BinaryView::AddUserSection is taking.

I'm then just running the following script I have in the snippet editor plugin:

import binaryninja.sharedcache
dsc = binaryninja.sharedcache.SharedCache(bv)
bv.set_analysis_hold(True)
for image in dsc.images:
    dsc.load_image_with_install_name(image.name, True) # skip ObjC processing

NOTE: the extra argument to load_image_with_install_name is to skip Objective-C processing which is added with this PR that has not currently been merged.

The script pauses analysis and then just loads all images in the DSC one by one.

Expected Behavior:
It seems to me that this is an unnecessary performance issue. As in its likely that whatever is causing the slow down could be avoided with some optimisation. It would not surprise me if whats going on here is there's a data copy occurring each time BinaryView::AddUserSection based on the number of sections in the binary view. Without seeing the code I'd suspect there's something like an array of non-DefaultSectionSemantics sections and each time a new section is added to that array its getting resized and requiring a memcpy to move the data from the old array to the new one.

Binary:
I was testing on an iOS DSC extracted from iOS 18.1.1, it shouldn't matter exactly which.

Metadata

Metadata

Assignees

Labels

Effort: MediumIssues require < 1 month of workImpact: MediumIssue is impactful with a bad, or no, workaround

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions