Skip to content

Printing instructions fails unless you sleep between function creation and printing #2295

Closed

Description

@Vasco-jofra

As seen in the image below, iterating and printing the instructions of a newly created function does not work, unless you sleep between creating the function and printing its instructions.

Screenshot 2021-03-04 at 12 43 59

The code:

from binaryninja import BinaryView, Function, Platform
import time

# Create a binary view from a data buffer
new_bv: BinaryView = BinaryView.new("\x55\x55\x90\x90\xc3")
new_bv.platform = Platform["linux-x86_64"]

# Create a function at the start address
new_bv.create_user_function(0)
func: Function = new_bv.get_function_at(0)

time.sleep(0.1) # <--- remove me and the print below does not work

for instr in func.instructions:
    print(instr)

Activity

  1. bpotchik commented on Mar 4, 2021

    @bpotchik
    Member

    If this is in headless (no UI), try calling new_bv.update_analysis_and_wait() instead of sleep.

  2. Vasco-jofra commented on Mar 4, 2021

    @Vasco-jofra
    ContributorAuthor

    Thanks, new_bv.update_analysis_and_wait() works. I though that after calling create_user_function, the fields of that function (like func.instructions) would be ready to use.

    If this is intended we can just close it

  3. bpotchik commented on Mar 4, 2021

    @bpotchik
    Member

    Ah yes, update_analysis_and_wait(), corrected above.

    So for headless processing it make sense to batch multiple analysis actions before requesting the core to perform the analysis. This can yield better performance, especially on multi-core machines. Thanks!

  4. self-assigned this
    on Mar 4, 2021
  5. psifertex commented on Mar 4, 2021

    @psifertex
    Member

    Just to clarify this is slightly different than the scripting console in the full UI because in that case, we assume you want to see updated results immediately for any command you run as it violates the principal of least surprise. You can see that here:

    https://github.com/Vector35/binaryninja-api/blob/dev/python/scriptingprovider.py#L676-L677

    Headless however is much more likely to be building a set of actions and you may want more control over when analysis updates since you can queue up multiple actions without being able to see the results.

  6. locked and limited conversation to collaborators on Mar 4, 2021
  7. added theissue type on Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions