You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Printing instructions fails unless you sleep between function creation and printing #2295
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:
frombinaryninjaimportBinaryView, Function, Platformimporttime# Create a binary view from a data buffernew_bv: BinaryView=BinaryView.new("\x55\x55\x90\x90\xc3")
new_bv.platform=Platform["linux-x86_64"]
# Create a function at the start addressnew_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 workforinstrinfunc.instructions:
print(instr)
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.
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!
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:
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.
Activity
bpotchik commentedon Mar 4, 2021
If this is in headless (no UI), try calling
new_bv.update_analysis_and_wait()instead ofsleep.Vasco-jofra commentedon Mar 4, 2021
Thanks,
new_bv.update_analysis_and_wait()works. I though that after callingcreate_user_function, the fields of that function (likefunc.instructions) would be ready to use.If this is intended we can just close it
bpotchik commentedon Mar 4, 2021
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!
psifertex commentedon Mar 4, 2021
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.