Vector35 / binaryninja-api

Public API, examples, documentation and issues for Binary Ninja
https://binary.ninja/
MIT License
921 stars 208 forks source link

Ability to prefill form elements in bn.interaction #902

Closed whitequark closed 3 years ago

whitequark commented 6 years ago

For example, I'm trying to make a plugin that simplifies changing ABI of a function:

import binaryninja as bn
import binaryninja.interaction as bni

def change_abi(view, func):
    cconvs = view.platform.calling_conventions
    cconv_names = map(lambda x: x.name, cconvs)
    cconv_field = bni.ChoiceField("Calling convention", cconv_names)
    cconv_field.result = cconvs.index(func.calling_convention)

    if bni.get_form_input([xx, cconv_field], "Function ABI"):
        func.calling_convention = cconvs[cconv_field.result]

bn.PluginCommand.register_for_function(
    'Change ABI...', 'Change ABI of this function.', change_abi
)

Right now, the dialog always appears with the first result selected in it, regardless of what I put into cconv_field.result. Actually, looking at the code, there already seems to be functionality for handling this case (_fill_core_result), not sure why it doesn't work.

jeffli678 commented 3 years ago

Setting the result in advance does not make it the default. We should provide a mechanism to set default.

Once it is implemented, https://github.com/Vector35/binaryninja-api/blob/dev/python/examples/export_svg.py should be updated to set the default IL view.

plafosse commented 3 years ago

We recommend using a UI Plugin now and will not likely be adding additional functionality to these APIs.

psifertex commented 3 years ago

Also, to clarify, there is a small-work-around as well using interaction of just ordering the list such that the desired default is first. It's not great, but raw PySide will always be the right solution for more complicated UI elements at this point.