diff options
| author | Alexander Taylor <alex@vector35.com> | 2025-04-14 11:15:01 -0400 |
|---|---|---|
| committer | Alexander Taylor <alex@vector35.com> | 2025-04-14 14:53:51 -0400 |
| commit | 507935f828188047ee009d2216a2c2d92c8b83fd (patch) | |
| tree | 4247355ef5788809c8e47fc11e345a623f053196 /view/sharedcache/ui/symboltable.cpp | |
| parent | 37e20cc30d57fff6b78bf6be9be2230a8ff973cc (diff) | |
Fixes for multiple issues in DSC/KC Triage views.
1. Crash on kernel cache image load
2. Duplicate Load Image buttons in kernel cache view
3. Improper selection behavior in both views
4. Address column should no longer resize to be smaller than contents
5. Symbol tables should now be properly sortable
Diffstat (limited to 'view/sharedcache/ui/symboltable.cpp')
| -rw-r--r-- | view/sharedcache/ui/symboltable.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/view/sharedcache/ui/symboltable.cpp b/view/sharedcache/ui/symboltable.cpp index 1df7d529..b0247f2b 100644 --- a/view/sharedcache/ui/symboltable.cpp +++ b/view/sharedcache/ui/symboltable.cpp @@ -10,23 +10,27 @@ using namespace BinaryNinja; using namespace SharedCacheAPI; + SymbolTableModel::SymbolTableModel(SymbolTableView* parent) : QAbstractTableModel(parent), m_parent(parent) { // TODO: Need to implement updating this font if it is changed by the user m_font = getMonospaceFont(parent); } + int SymbolTableModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent); return static_cast<int>(m_modelSymbols.size()); } + int SymbolTableModel::columnCount(const QModelIndex& parent) const { Q_UNUSED(parent); // We have 3 columns: Address, Type, Name return 3; } + QVariant SymbolTableModel::data(const QModelIndex& index, int role) const { if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::FontRole)) { return QVariant(); @@ -58,6 +62,7 @@ QVariant SymbolTableModel::data(const QModelIndex& index, int role) const { } } + QVariant SymbolTableModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole || orientation != Qt::Horizontal) { return QVariant(); @@ -75,12 +80,58 @@ QVariant SymbolTableModel::headerData(int section, Qt::Orientation orientation, } } + +void SymbolTableModel::sort(int column, Qt::SortOrder order) +{ + beginResetModel(); + + std::function<bool(const CacheSymbol&, const CacheSymbol&)> comparator; + + switch (column) + { + case 0: // Address column + comparator = [](const CacheSymbol& a, const CacheSymbol& b) { + return a.address < b.address; + }; + break; + case 1: // Type column + comparator = [](const CacheSymbol& a, const CacheSymbol& b) { + return GetSymbolTypeAsString(a.type) < GetSymbolTypeAsString(b.type); + }; + break; + case 2: // Name column + comparator = [](const CacheSymbol& a, const CacheSymbol& b) { + return a.name < b.name; + }; + break; + default: + endResetModel(); + return; + } + + if (order == Qt::DescendingOrder) + { + std::sort(m_modelSymbols.begin(), m_modelSymbols.end(), + [&comparator](const CacheSymbol& a, const CacheSymbol& b) { + return comparator(b, a); + }); + } + else + { + std::sort(m_modelSymbols.begin(), m_modelSymbols.end(), comparator); + } + + endResetModel(); +} + + void SymbolTableModel::updateSymbols(std::vector<CacheSymbol>&& symbols) { m_preparedSymbols = symbols; setFilter(m_filter); } + const CacheSymbol& SymbolTableModel::symbolAt(int row) const { return m_modelSymbols.at(row); |
