Repository navigation
Unexpected behavior of get_view_of_file when using progress_func #4116
Copy link
Copy link
Closed
Labels
Effort: TrivialIssues require < 1 day of workIssues require < 1 day of workImpact: LowIssue is a papercut or has a good, supported workaroundIssue is a papercut or has a good, supported workaround
Milestone
Description
Version and Platform (required):
- Headless (on 3.3.4012-dev)
- OS: MacOS
- OS Version: 13.1
- CPU Architecture: M1
Bug Description:
- When supplying a
.bndbfile along withprogress_funcBinaryNinja is unable to open the.bndbbut whenprogress_funcis 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>- Additionally, when supplying a callable
progress_funcwhen usingopen_viewtheprogress_funcis only updated when supplying a.bndbfile 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:
- Use
progress_funcin 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
Labels
Effort: TrivialIssues require < 1 day of workIssues require < 1 day of workImpact: LowIssue is a papercut or has a good, supported workaroundIssue is a papercut or has a good, supported workaround
Activity
plafosse commentedon Mar 21, 2023
Ok this one had me confused for a bit too. So the progress function should be returning a bool
Trueto continue andFalseto stop loading. As your example returnsNoneBinaryNinja cancels its loading. Change your code toplafosse commentedon Mar 21, 2023
On think I noticed I can fix though which might have helped you out is I'm adding a LogInfo to indicate that loading has been cancelled. This would have probably clued you into the problem. Additionally the documentation should be improved to state this.
jprokos26 commentedon Mar 21, 2023
@plafosse Great, I can see the progress function when supplying a Callable that returns true.
With regards to the second issue, the
progress_funcstill is not called when supplying a non-bndb file toopen_view:Should I open a new PR for this issue?
plafosse commentedon Mar 21, 2023
So... oddly enough the API for opening a non-bndb doesn't have a way of accepting a progress_function. This would actually require a considerable refactor to accomplish. We could make this happen but only after this issue is addressed #2604
jprokos26 commentedon Mar 22, 2023
Got it, thanks for the clarification!