Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture and handle logging messages from Binary Ninja backend #1413

Open
williballenthin opened this issue Mar 29, 2023 · 8 comments
Open

capture and handle logging messages from Binary Ninja backend #1413

williballenthin opened this issue Mar 29, 2023 · 8 comments
Labels
binary-ninja bug Something isn't working

Comments

@williballenthin
Copy link
Collaborator

as first described and triaged in the thread here: #1343 (comment)
Binary Ninja emits logging messages to stdout/stderr directly, which doesn't give Python a chance to handle/format/suppress messages. When they add support for registering a logging listener, we should use it to improve the user and tester experience of capa.

@williballenthin williballenthin added bug Something isn't working binary-ninja labels Mar 29, 2023
@williballenthin
Copy link
Collaborator Author

@xusheng6 for awareness of tracking issue

@xusheng6
Copy link
Contributor

xusheng6 commented Mar 29, 2023 via email

@xusheng6
Copy link
Contributor

xusheng6 commented Apr 7, 2023

I just realized that I should better fix the issue on our end before the new release. So that when we release it, we can update capa to utilize it. Otherwise, since capa CI uses the stable build of BN, we will have to wait longer.

@xusheng6
Copy link
Contributor

xusheng6 commented Apr 10, 2023

I notice a BN bug while dealing with this: Vector35/binaryninja-api#4205

Update: I have pushed a fix for it. Once we release the new stable, we should see far less warn messages

@xusheng6
Copy link
Contributor

I tried to understand why the BN logs are even printed at all. I checked our code and did some experiment, I figured that if we do not do anything, logs would not be printed to stdout/stderr by default. We must call log_to_stdout first so the logs would be printed to stdout. For example, see the code snippet in our API docs:

https://github.com/Vector35/binaryninja-api/blob/85e782ad57f27c753364faeaead01522982a12ec/python/log.py#L142-L144

@xusheng6
Copy link
Contributor

Oh nvm, I figured out. The output is dumped to stderr by default: https://github.com/Vector35/binaryninja-api/blob/94391b2730dcc2e6cfe9f26d13569b15c6d1a0ad/python/__init__.py#L168. So we would not be able to see it if we run something directly, but it can be captured by things like pytest.

@xusheng6
Copy link
Contributor

So we have decided to not merge the branch that fixes this issue Vector35/binaryninja-api#4156, primarily because of a performance consideration. It could become a footgun and slow down the analysis speed if the user uses in a wrong way.

This means we would not be able to fix this issue in a perfect way. However, I propose we solve it like this:

  1. Disable the default log by calling disable_default_log https://github.com/Vector35/binaryninja-api/blob/5721a4177f651a9d518f1a3b74caca450061e05c/python/__init__.py#L179
  2. Configure BN to log to a file, and then either inform the user the existence of the BN log file, or replay it at the end of analysis using Python's logging infra

@xusheng6
Copy link
Contributor

Not requiring the Python LogListener means this does not need to be completed before the next BN stable release. All the infra mentioned above is already existing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binary-ninja bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants