0

I have created a plugin/idascript (ida-batch_decompile) that aims to make it easier to decompile a target including images referenced as imports or any other decompilable files in the targets project dir. Optionally it also adds some helpful annotations to the pseudocode. In order to make this as convenient as possible I've added a Dialog that helps in enumerating target files and allows to select files for decompiliation from within ida pro. For the selection I'm using a variant of the Choose2 control that I borrowed from EiNSTeiN.

What I'd like to have is a way to dynamically add items (e.g. on button click) to an already displayed Choose2 list control. For some reason, this does not work, newly added items are not displayed unless I manually right-click/refresh on that listview control. I tried calling Chooser2.Refresh(), Form.Refresh() without any luck. The only workaround that kind of works is to close the form, add items to the listview and re-exec that form in order for it to show up. This is kind of ugly (see gif 1).

def OnButtonLoad(self, code=0):
    # superdirty close, propagate, execute hack, otherwise listview would not be updated
    self.Close(0)
    # add items to listview
    self.propagateItems(enumerate_other=True, enumerate_imports=True)
    self.Execute()

--?-- What is the correct way to add items to an already existing Choose2 listcontrol and have it refresh without having to Close(); Execute() the whole form?

I was searching for something like

Chooser.items.add(newItem)
Chooser.Refresh()

but that does not seem to refresh the listview control.

1 Answer 1

1

Unfortunately IDA's builtin controllers are rather simple and do not support the full flexibility of the QT controls you're based on.

Luckily for you, IDA exposed most of the QT API directly, and plugin developers are not able to interface with QT directly. In the past this wasn't possible, and we were bound to the Choose2, Ask* functions. I will not recommend anyone developing anything more than the simplest of plugins to use the provided IDA dialogs anymore. Instead, you should interface with QT directly for most of your UI development.

Although using QT is a bit more complex (you'll might need to deal with QT' signals and slots) it also enables a lot of flexibility.

Following is a short snippet that will let you update a list view. Every time the "add item" button is clicked, a new item will appear in the list.

form PyQt5 import QtWidgets

class ListViewDemoDialog(QtWidgets.QDialog):
    def __init__(self):
        super(ListViewDemoDialog, self).__init__(**kwargs)

        # create a layout to place controllers (called widgets) on
        layout = QtWidgets.QVBoxLayout())

        # create an empty list
        self.list = QtWidgets.QListWidget()

        # create a button and connect it's "clicked" signal to our "add_item" slot
        self.addbtn = QtWidgets.QPushButton("Add item")
        self.addbtn.clicked.connect(self.add_item)

        layout.addWidget(self.addbtn)
        layout.addWidget(self.list)

        # make our created layout the dialogs layout
        self.setLayout(layout)

     def add_item(self):
         self.list.addItem("This is an item")
1
  • thank you for the detailed answer. I really like the simplistic dialog interface to quickly draft a plugin therefore it is a pity that there is no way of updating a list once an item was added lateron. I'll probably look into QT if the form reload annoys me too much :) thanks.
    – tintin
    Oct 27, 2016 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.