Skip to content

Unexpected behavior of get_view_of_file when using progress_func #4116

@jprokos26

Description

@jprokos26

Version and Platform (required):

  • Headless (on 3.3.4012-dev)
  • OS: MacOS
  • OS Version: 13.1
  • CPU Architecture: M1

Bug Description:

  1. When supplying a .bndb file along with progress_func BinaryNinja is unable to open the .bndb but when progress_func is not supplied it opens fine:
>>> bv_path PosixPath('libc.so.6.bndb') >>> open_view(bv_path, progress_func=lambda p,t: print(p,t)) 0 1000000 1 1 Traceback (most recent call last): File "<console>", line 1, in <module> File "/Applications/Binary Ninja.app/Contents/Resources/python/binaryninja/__init__.py", line 360, in open_view bv = BinaryViewType.get_view_of_file_with_options(*args, **kwargs) File "/Applications/Binary Ninja.app/Contents/Resources/python/binaryninja/binaryview.py", line 1033, in get_view_of_file_with_options return BinaryViewType.load(filename, update_analysis, progress_func, options) File "/Applications/Binary Ninja.app/Contents/Resources/python/binaryninja/binaryview.py", line 1199, in load return BinaryViewType.load_raw_view_with_options(raw_view, *args, **kwargs) File "/Applications/Binary Ninja.app/Contents/Resources/python/binaryninja/binaryview.py", line 1147, in load_raw_view_with_options raise Exception(f"Unable to open_existing_database with filename {raw_view.file.filename}") Exception: Unable to open_existing_database with filename libc.so.6.bndb >>> open_view(bv_path) <BinaryView: 'libc.so.6.bndb', len 0x227ed8> >>> path PosixPath('libc.so.6') >>> open_view(path, progress_func=lambda p,t: print(p,t)) <BinaryView: 'libc.so.6', len 0x227ed8>
  1. Additionally, when supplying a callable progress_func when using open_view the progress_func is only updated when supplying a .bndb file and never gets called otherwise. Specifically in get_view_of_file:
is_database = filename.endswith(".bndb")	if is_database:	f = open(filename, 'rb')	if f is None or f.read(len(sqlite)) != sqlite:	return None	f.close()	view = filemetadata.FileMetadata().open_existing_database(filename, progress_func)	else:	view = BinaryView.open(filename) 

From the docs it would be expected that progress_func is called on any valid filename not just .bndb files:
progress_func (callback) – optional function to be called with the current progress and total count

Steps To Reproduce:

  1. Use progress_func in any context.

Expected Behavior:
Progress bar to be called

Screenshots:
N/A

Additional Information:
For the second example I am unsure if this is a bug or intended behavior; if the latter then this is a DOCS issue not a BUG.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Effort: TrivialIssues require < 1 day of workImpact: LowIssue is a papercut or has a good, supported workaround

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions