MetadataChoiceDialog is a dynamic UI View and Controller that allows the user to make a selection given a list of entries, and metadata about those entries.
The Model's data is left up to the developer using the dialog to manage. A developer can implement a second checkbox-toggled filter, custom metadata shown in a box to the right of the table, and/or a custom second column with additional info about entries.
Content from all of these callbacks is cached, however these caches can be evicted if data has changed or been added.
This dialog can to scale to very large amounts of arbitrary info by lazily loading it from provided callbacks, without requiring bespoke dialogs being built for those applications.
Example:
QStringList entries;
std::vector<TypeRef> entryTypes;
for (auto type : bv->GetTypes())
{
entries.push_back(QString::fromStdString(type.first.GetString()));
entryTypes.push_back(type.second);
}
std::function<std::vector<BinaryNinja::DisassemblyTextLine>(
EntryItem item)> getMetadata =
{
TypeRef type = entryTypes.at(item.idx);
std::vector<BinaryNinja::DisassemblyTextLine> metadata;
for (
auto line : type->
GetLines(data, entries.at(item.idx).toStdString()))
{
DisassemblyTextLine l;
l.tokens = line.tokens;
metadata.push_back(l);
}
return metadata;
};
choiceDialog->SetMetadataCallback(getMetadata);
std::function<bool(
EntryItem item)> isEntryEnum =
{
TypeRef type = entryTypes.at(item.idx);
};
choiceDialog->SetExtraFilter("Hide non-enums", isEntryEnum);
std::function<QString(
EntryItem item)> secondColumnText =
{
TypeRef type = entryTypes.at(item.idx);
return "0x" + QString::number(type->
GetWidth(), 16);
};
choiceDialog->SetSecondColumnTextCallback("Type Width", secondColumnText);
choiceDialog->exec();
if (choiceDialog->GetChosenEntry().has_value())
return entryTypes.at(choiceDialog->GetChosenEntry().value().idx);
else
return nullptr;
Definition: metadatachoicedialog.h:21
std::vector< TypeDefinitionLine > GetLines(Ref< BinaryView > data, const std::string &name, int lineWidth=80, bool collapsed=false, BNTokenEscapingType escaping=NoTokenEscapingType)
Definition: type.cpp:1200
bool IsEnumeration() const
Check whether this type is an Enumeration type.
Definition: binaryninjaapi.h:7822
bool IsEnumReference()
If this Type is a NamedTypeReference, check whether it refers to an Enum Type.
Definition: binaryninjaapi.h:7758
uint64_t GetWidth() const
Get the width in bytes of the Type.
Definition: type.cpp:549
AddContextButton and AddContextMenuItem can also be used for more complex UI behavior if required, and examples are provided for using those in their respective documentation. There are also several methods for adding or editing entries, evicting caches, and so on, if you need to modify the dialog's contents on the fly via a button or context menu item.
Public Slots |
virtual void | selectionChanged (std::optional< size_t > idx) |
|
void | accept () override |
|
void | reject () override |
|
Public Member Functions |
| MetadataChoiceDialog (QWidget *parent, const QString &title, const QStringList &entries, std::unordered_map< size_t, QString > metadata) |
| Create a choice selection dialog with a Title, list of entries, and pre-built set of metadata for those entries. More...
|
|
| MetadataChoiceDialog (QWidget *parent, const QString &title, const QStringList &entries, std::unordered_map< size_t, std::vector< BinaryNinja::DisassemblyTextLine > > metadata) |
| Create a choice selection dialog with a Title, list of entries, and pre-built set of metadata for those entries. More...
|
|
| MetadataChoiceDialog (QWidget *parent, const QString &title, const QStringList &entries) |
| Create a choice selection dialog with a Title and list of entries. More...
|
|
| MetadataChoiceDialog (QWidget *parent, const QString &title) |
|
void | SetMetadataCallback (const std::function< QString(EntryItem item)> &callback) |
| Set the callback the dialog will execute to retrieve metadata for a given item. More...
|
|
void | SetMetadataCallback (const std::function< std::vector< BinaryNinja::DisassemblyTextLine >(EntryItem item)> &callback) |
| Set the callback the dialog will execute to retrieve metadata for a given item. More...
|
|
void | AddColumn (QString columnTitle, const std::function< QString(EntryItem item)> &callback) |
| Set the callback the dialog will execute to retrieve second column text for a given item. More...
|
|
void | SetExtraFilter (QString filterTitle, const std::function< bool(EntryItem item)> callback) |
| Set a callback for any optional extra conditions that entries must pass to be displayed. More...
|
|
void | SetShouldCacheMetadata (bool s) |
| Set whether metadata should be cached after calling the metadata callback once. More...
|
|
void | SetShouldCacheExtraFilterResults (bool s) |
| Set whether the entries that pass the extra filter should be cached. More...
|
|
std::optional< EntryItem > | GetChosenEntry () const |
| Get the chosen entry. More...
|
|
void | AddEntries (QStringList &entries) |
| Add entries to the initial set. More...
|
|
void | InvalidateAllCaches () |
| Clear all caches. More...
|
|
void | AddContextButton (QWidget *button) |
| Add a button (or other widget) to the right side of the search bar. More...
|
|
void | AddContextMenuItem (QString title, const std::function< void(EntryItem item)>action) |
|
void | SelectFirstValidEntry () |
|
virtual | ~ManagedTableDelegate () |
|
virtual size_t | ManagedTableColumnCount ()=0 |
|
virtual size_t | ManagedTableRowCount ()=0 |
|
virtual QString | ManagedTableColumnName (size_t)=0 |
|
virtual QString | ManagedTableDisplayText (size_t row, size_t col)=0 |
|
virtual std::vector< std::pair< QString, std::function< void(EntryItem item)> > > | GetTableContextMenuItems ()=0 |
|
virtual void | ExecuteContextMenuItem (size_t menuItemIndex, size_t idx)=0 |
|
virtual std::vector< EntryItem > | GetAllItems () const =0 |
|
virtual bool | EntryItemPassesExtraFilters (EntryItem &item)=0 |
|
virtual | ~EntryItemMetadataViewDelegate () |
|
virtual MetadataMode | GetCurrentMode ()=0 |
|
virtual std::vector< BinaryNinja::DisassemblyTextLine > | LinesForEntryItem (EntryItem &item)=0 |
|
virtual QString | PlaintextForEntryItem (EntryItem &item)=0 |
|
Protected Member Functions |
virtual size_t | ManagedTableColumnCount () override |
|
virtual size_t | ManagedTableRowCount () override |
|
virtual QString | ManagedTableColumnName (size_t) override |
|
virtual QString | ManagedTableDisplayText (size_t row, size_t col) override |
|
virtual std::vector< std::pair< QString, std::function< void(EntryItem item)> > > | GetTableContextMenuItems () override |
|
virtual void | ExecuteContextMenuItem (size_t menuItemIndex, size_t idx) override |
|
virtual bool | EntryItemPassesExtraFilters (EntryItem &item) override |
|
virtual std::vector< EntryItem > | GetAllItems () const override |
|
virtual MetadataMode | GetCurrentMode () override |
|
virtual std::vector< BinaryNinja::DisassemblyTextLine > | LinesForEntryItem (EntryItem &item) override |
|
virtual QString | PlaintextForEntryItem (EntryItem &item) override |
|
bool | ExtraFilterEnabled () |
|
void | AddWidthRequiredByItem (void *item, size_t widthRequired) |
|
void | RemoveWidthRequiredByItem (QWidget *item) |
|
void | AddHeightRequiredByItem (void *item, size_t widthRequired) |
|
void | RemoveHeightRequiredByItem (QWidget *item) |
|
void | UpdateMinimumSpace () |
|
Protected Attributes |
std::vector< EntryItem > | m_entries |
|
QHBoxLayout * | m_midRowLayout |
|
bool | m_secondColumnCacheEnabled = true |
|
std::vector< InfoColumn > | m_infoColumns |
|
std::vector< std::pair< QString, std::function< void(EntryItem item)> > > | m_contextMenuItems |
|
ManagedTableView * | m_entryListView |
|
EntryItemMetadataView * | m_metadataView |
|
FilteredView * | m_filterView |
|
FilterEdit * | m_edit |
|
MetadataState | m_metadata |
|
QCheckBox * | m_extraFilterCheckbox |
|
ExtraFilterState | m_extraFilter |
|
QLabel * | m_selectedText |
|
QPushButton * | m_cancel |
|
QPushButton * | m_choose |
|
std::optional< EntryItem > | m_chosenEntry |
|
std::optional< EntryItem > | m_selectedEntry |
|