summaryrefslogtreecommitdiff
path: root/plugins/warp/ui/shared/constraint.cpp
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-01-31 12:59:42 -0500
committerMason Reed <mason@vector35.com>2025-07-02 01:58:31 -0400
commit110c06851bbbd09f78a3e87979d529d6e09df851 (patch)
tree7849015b26a14cd2b7be2d87fc1e0d5c101ef457 /plugins/warp/ui/shared/constraint.cpp
parent7b1e8bbdb971aed21b6d889aa4a46f9ef54829c1 (diff)
WARP 1.0
- Added FFI - Added a sidebar to the UI - Added project, directory and archive processing - Added generic `Container` interface for extensible stores of WARP data - Fixed type references being constructed and pulled incorrectly - Added HTML, Markdown and JSON report generation - Made the WARP information added as an analysis activity - Flattened the signatures directory, the target information is stored in the file now - Matched function information is stored as function metadata in the database to reliably persist, alongside the function GUID - Split the matching out from the application, allowing you to match on a given function without applying it - Added more/better tests - Added support for binaries with multiple architectures, the functions are now also queried based off the Target, see WARP spec for more details - Greatly improved support for RISC architectures, see WARP spec for more details - Greatly improved UX when loading files after the fact, will now sanely rerun the matcher - Omitted the function type if not a user type, this greatly reduces file size - Improved support for functions that reference a page aligned base pointer, see WARP spec for more details - Removed some extra cache structures that were causing erroneous behavior - Fixed edge-case in LLIL traversal missing some constant pointers, this was a bug in the Rust bindings - Added support for function comments - Made long running tasks, such as generating, matching and loading signatures, cancellable where possible - Made function constraints more versatile, allowing for easy extensions in the future, see WARP spec for details - Added options to signature generation, such as what data to store, and whether to compress the data or not - Made all long running tasks prompt the user for required information before the task starts, allowing users to "set it and forget it" and not have to baby sit the finalization of the task - Myriad of other changes to the actual WARP format that impact performance, file size and general feature set, see https://github.com/Vector35/warp for more details
Diffstat (limited to 'plugins/warp/ui/shared/constraint.cpp')
-rw-r--r--plugins/warp/ui/shared/constraint.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/plugins/warp/ui/shared/constraint.cpp b/plugins/warp/ui/shared/constraint.cpp
new file mode 100644
index 00000000..1d369bcd
--- /dev/null
+++ b/plugins/warp/ui/shared/constraint.cpp
@@ -0,0 +1,118 @@
+#include "constraint.h"
+
+#include <QGridLayout>
+#include <QHeaderView>
+
+WarpConstraintItem::WarpConstraintItem(const Warp::Constraint &constraint) : m_constraint(constraint)
+{
+ QString guidStr = QString::fromStdString(constraint.guid.ToString());
+ if (const auto offset = constraint.offset; offset)
+ guidStr += QString(" @ %1").arg(*offset, 0, 16);
+ setText(guidStr);
+}
+
+WarpConstraintItemModel::WarpConstraintItemModel(const QStringList &labels, QObject *parent)
+{
+ this->setHorizontalHeaderLabels(labels);
+}
+
+void WarpConstraintItemModel::AddItem(WarpConstraintItem *item)
+{
+ QList<QStandardItem *> row = {};
+ row.insert(COL_CONSTRAINT_ITEM, item);
+ appendRow(row);
+}
+
+WarpConstraintItem *WarpConstraintItemModel::GetItem(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return nullptr;
+ return dynamic_cast<WarpConstraintItem *>(item(index.row(), COL_CONSTRAINT_ITEM));
+}
+
+QVariant WarpConstraintItemModel::data(const QModelIndex &index, int role) const
+{
+ // Highlight constraints that are found in analysis.
+ if (role == Qt::BackgroundRole)
+ {
+ if (const auto item = GetItem(index); item)
+ {
+ auto itemConstraint = item->GetConstraint();
+ // TODO: We really should store the guid in a hashmap or something instead of looping over it for every item.
+ // TODO: A less intense green?
+ // TODO: Take into account the constraint offset.
+ for (const auto &constraint: m_matchedConstraints)
+ if (constraint.guid == itemConstraint.guid)
+ return QBrush(Qt::green);
+ }
+ }
+
+ return QStandardItemModel::data(index, role);
+}
+
+WarpConstraintTableWidget::WarpConstraintTableWidget(QWidget *parent)
+{
+ QGridLayout *layout = new QGridLayout(this);
+ layout->setContentsMargins(2, 2, 2, 2);
+ layout->setVerticalSpacing(4);
+
+ m_table = new QTableView(this);
+ m_model = new WarpConstraintItemModel({"Constraint"}, this);
+ m_proxyModel = new GenericTextFilterModel(this);
+ m_proxyModel->setSourceModel(m_model);
+ m_table->setModel(m_proxyModel);
+
+ m_filterEdit = new FilterEdit(this);
+ m_filterView = new FilteredView(this, m_table, this, m_filterEdit);
+ m_filterView->setFilterPlaceholderText("Search constraints");
+
+ layout->addWidget(m_filterEdit, 0, 0, 1, 5);
+ layout->addWidget(m_table, 1, 0, 1, 5);
+
+ // Make the table look nice.
+ m_table->horizontalHeader()->setStretchLastSection(true);
+ m_table->verticalHeader()->hide();
+ m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
+ m_table->setSelectionMode(QAbstractItemView::SingleSelection);
+ m_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ m_table->setFocusPolicy(Qt::NoFocus);
+ m_table->setShowGrid(false);
+ m_table->setAlternatingRowColors(false);
+ m_table->setSortingEnabled(true);
+ // NOTE: We only have a single column right now, so disable the header.
+ m_table->horizontalHeader()->hide();
+ // Decrease row height to make it look nice.
+ m_table->verticalHeader()->setDefaultSectionSize(30);
+}
+
+void WarpConstraintTableWidget::SetConstraints(QVector<WarpConstraintItem *> constraints)
+{
+ // Clear matches as they are no longer valid.
+ m_model->clear();
+ m_model->setRowCount(0);
+
+ // Temporarily disable sorting so we can add rows faster
+ m_table->setModel(m_model);
+ m_table->setSortingEnabled(false);
+ m_table->setEnabled(false);
+
+ for (const auto &constraint: constraints)
+ m_model->AddItem(constraint);
+
+ // We are done, re-enable table.
+ m_table->setEnabled(true);
+ m_table->setModel(m_proxyModel);
+ m_table->setSortingEnabled(true);
+}
+
+void WarpConstraintTableWidget::SetMatchedConstraints(
+ const std::vector<Warp::Constraint> &analysisConstraints)
+{
+ m_model->SetMatchedConstraints(analysisConstraints);
+}
+
+void WarpConstraintTableWidget::setFilter(const std::string &filter)
+{
+ m_proxyModel->setFilterFixedString(QString::fromStdString(filter));
+ m_filterView->showFilter(QString::fromStdString(filter));
+}