Can you explain why headless requires a sleep for the same code that does not from the UI? #2296
-
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. 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) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
In headless you should use This is 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. |
Beta Was this translation helpful? Give feedback.
-
Thanks, If this is intended we can just close it |
Beta Was this translation helpful? Give feedback.
-
Ah yes, 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! |
Beta Was this translation helpful? Give feedback.
In headless you should use
new_bv.update_analysis_and_wait()
instead ofsleep
.This is 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.