#include "main_window.hpp" #include "strawberry/service_hints.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace strawberry::app { namespace { const QString kProcessScheme = QStringLiteral("sbprocess"); const QString kFindingScheme = QStringLiteral("sbfinding"); const QString kAllowHashScheme = QStringLiteral("sballowhash"); const QString kAllowPathRuleScheme = QStringLiteral("sballowpathrule"); const QString kContainScheme = QStringLiteral("sbcontain"); const QString kActionScheme = QStringLiteral("sbaction"); // sbaction:| const QString kQuarantineScheme = QStringLiteral("sbquarantine"); QString esc(const std::string& value) { return QString::fromStdString(value).toHtmlEscaped(); } QString link(const QString& scheme, const std::string& id, const QString& text) { return QStringLiteral("%3") .arg(scheme, QString::fromLatin1(QUrl::toPercentEncoding(QString::fromStdString(id))), text); } // Evidence timestamps are wall-clock nanoseconds; demo data may use small values. QString format_ns(int64_t ns) { if (ns <= 0) { return QStringLiteral("—"); } if (ns < 1'000'000'000'000'000LL) { return QString::number(ns); } return QDateTime::fromMSecsSinceEpoch(ns / 1'000'000).toString(QStringLiteral("yyyy-MM-dd HH:mm:ss")); } QString severity_color(const std::string& severity) { switch (severity_rank(severity)) { case 4: return QStringLiteral("#8b0012"); case 3: return QStringLiteral("#d72638"); case 2: return QStringLiteral("#c07a00"); case 1: return QStringLiteral("#5a6b7b"); default: return QStringLiteral("#666"); } } QString prop(const GraphNode& node, const char* key) { const auto it = node.properties.find(key); return it == node.properties.end() ? QString() : QString::fromStdString(it->second); } QString check(bool ok) { return ok ? QStringLiteral("✔") : QStringLiteral("✘"); } QString duration_text(qint64 seconds) { if (seconds < 120) return QStringLiteral("%1 s").arg(seconds); if (seconds < 7200) return QStringLiteral("%1 min").arg(seconds / 60); if (seconds < 172800) return QStringLiteral("%1 h").arg(seconds / 3600); return QStringLiteral("%1 days").arg(seconds / 86400); } int64_t json_ns(const QJsonObject& object, const char* key) { return static_cast(object.value(QLatin1String(key)).toDouble()); } } // namespace MainWindow::MainWindow(const EvidenceStore& store, QWidget* parent) : QMainWindow(parent), store_(store) { setWindowTitle(QStringLiteral("Strawberry")); resize(1100, 700); tabs_ = new QTabWidget(this); tabs_->addTab(build_findings_tab(), QStringLiteral("Findings")); tabs_->addTab(build_processes_tab(), QStringLiteral("Processes")); tabs_->addTab(build_rules_tab(), QStringLiteral("Rules")); tabs_->addTab(build_allowlist_tab(), QStringLiteral("Allowlist")); tabs_->addTab(build_response_tab(), QStringLiteral("Response")); tabs_->addTab(build_diagnostics_tab(), QStringLiteral("Diagnostics")); setCentralWidget(tabs_); } QWidget* MainWindow::build_findings_tab() { auto* page = new QWidget(this); auto* layout = new QVBoxLayout(page); auto* bar = new QHBoxLayout(); severity_filter_ = new QComboBox(page); severity_filter_->addItem(QStringLiteral("All severities"), 0); severity_filter_->addItem(QStringLiteral("Low and above"), 1); severity_filter_->addItem(QStringLiteral("Medium and above"), 2); severity_filter_->addItem(QStringLiteral("High and above"), 3); unseen_only_ = new QCheckBox(QStringLiteral("Unseen only"), page); auto* mark_all = new QPushButton(QStringLiteral("Mark all seen"), page); findings_banner_ = new QLabel(page); findings_banner_->setWordWrap(true); bar->addWidget(severity_filter_); bar->addWidget(unseen_only_); bar->addStretch(); bar->addWidget(mark_all); layout->addLayout(bar); layout->addWidget(findings_banner_); auto* splitter = new QSplitter(Qt::Vertical, page); findings_table_ = new QTableWidget(0, 4, splitter); findings_table_->setHorizontalHeaderLabels( {QStringLiteral("Severity"), QStringLiteral("Score"), QStringLiteral("Finding"), QStringLiteral("Last seen")}); findings_table_->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); findings_table_->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); findings_table_->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); findings_table_->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents); findings_table_->setSelectionBehavior(QAbstractItemView::SelectRows); findings_table_->setSelectionMode(QAbstractItemView::SingleSelection); findings_table_->setEditTriggers(QAbstractItemView::NoEditTriggers); findings_table_->verticalHeader()->setVisible(false); finding_detail_ = new QTextBrowser(splitter); finding_detail_->setOpenLinks(false); splitter->addWidget(findings_table_); splitter->addWidget(finding_detail_); splitter->setStretchFactor(0, 3); splitter->setStretchFactor(1, 2); layout->addWidget(splitter); connect(severity_filter_, &QComboBox::currentIndexChanged, this, [this]() { refresh_findings(seen_); }); connect(unseen_only_, &QCheckBox::toggled, this, [this]() { refresh_findings(seen_); }); connect(mark_all, &QPushButton::clicked, this, &MainWindow::mark_all_seen_requested); connect(finding_detail_, &QTextBrowser::anchorClicked, this, &MainWindow::on_link); connect(findings_table_, &QTableWidget::itemSelectionChanged, this, [this]() { const auto rows = findings_table_->selectionModel()->selectedRows(); if (rows.isEmpty()) { return; } const auto id = findings_table_->item(rows.first().row(), 0)->data(Qt::UserRole).toString().toStdString(); const auto it = std::find_if(findings_.begin(), findings_.end(), [&](const auto& f) { return f.id == id; }); if (it != findings_.end()) { render_finding_detail(*it); emit finding_viewed(QString::fromStdString(it->id), it->last_seen); } }); return page; } QWidget* MainWindow::build_processes_tab() { auto* page = new QWidget(this); auto* layout = new QVBoxLayout(page); auto* bar = new QHBoxLayout(); process_query_ = new QLineEdit(page); process_query_->setPlaceholderText(QStringLiteral("PID, path, hash, command line, rule or finding…")); process_query_->setClearButtonEnabled(true); auto* search = new QPushButton(QStringLiteral("Search"), page); bar->addWidget(process_query_); bar->addWidget(search); layout->addLayout(bar); auto* splitter = new QSplitter(Qt::Horizontal, page); process_results_ = new QListWidget(splitter); process_detail_ = new QTextBrowser(splitter); process_detail_->setOpenLinks(false); splitter->addWidget(process_results_); splitter->addWidget(process_detail_); splitter->setStretchFactor(0, 1); splitter->setStretchFactor(1, 2); layout->addWidget(splitter); process_result_ = new QLabel(page); process_result_->setWordWrap(true); layout->addWidget(process_result_); connect(search, &QPushButton::clicked, this, &MainWindow::run_process_search); connect(process_query_, &QLineEdit::returnPressed, this, &MainWindow::run_process_search); connect(process_detail_, &QTextBrowser::anchorClicked, this, &MainWindow::on_link); connect(process_results_, &QListWidget::currentRowChanged, this, [this](int row) { if (row >= 0 && static_cast(row) < process_hits_.size()) { render_process_detail(process_hits_[static_cast(row)]); } }); return page; } QWidget* MainWindow::build_diagnostics_tab() { auto* page = new QWidget(this); auto* layout = new QVBoxLayout(page); auto* bar = new QHBoxLayout(); reload_button_ = new QPushButton(QStringLiteral("Reload rules"), page); rescan_button_ = new QPushButton(QStringLiteral("Rescan running processes"), page); command_result_ = new QLabel(page); command_result_->setWordWrap(true); bar->addWidget(reload_button_); bar->addWidget(rescan_button_); bar->addWidget(command_result_, 1); layout->addLayout(bar); auto* startup = new QHBoxLayout(); autostart_ = new QCheckBox(QStringLiteral("Start Strawberry at login"), page); autostart_->setToolTip(QStringLiteral("Adds the tray app to ~/.config/autostart")); autostart_note_ = new QLabel(page); autostart_note_->setWordWrap(true); autostart_note_->setTextInteractionFlags(Qt::TextSelectableByMouse); startup->addWidget(autostart_); startup->addWidget(autostart_note_, 1); layout->addLayout(startup); connect(autostart_, &QCheckBox::toggled, this, &MainWindow::autostart_toggled); diagnostics_ = new QTextBrowser(page); layout->addWidget(diagnostics_); connect(reload_button_, &QPushButton::clicked, this, [this]() { command_result_->setText(QStringLiteral("Reloading rules…")); emit command_requested(QStringLiteral("reload-rules")); }); connect(rescan_button_, &QPushButton::clicked, this, [this]() { command_result_->setText(QStringLiteral("Requesting rescan…")); emit command_requested(QStringLiteral("rescan")); }); render_diagnostics(); return page; } void MainWindow::set_autostart_state(bool enabled, const QString& note) { const QSignalBlocker block(autostart_); autostart_->setChecked(enabled); autostart_note_->setText(note); } void MainWindow::refresh_findings(const AckMap& seen) { seen_ = seen; findings_ = store_.findings(); std::sort(findings_.begin(), findings_.end(), [](const auto& a, const auto& b) { if (a.score != b.score) return a.score > b.score; return a.last_seen > b.last_seen; }); const QString selected = [&]() { const auto rows = findings_table_->selectionModel()->selectedRows(); return rows.isEmpty() ? QString() : findings_table_->item(rows.first().row(), 0)->data(Qt::UserRole).toString(); }(); const int min_rank = severity_filter_->currentData().toInt(); findings_table_->blockSignals(true); findings_table_->setRowCount(0); for (const auto& finding : findings_) { const bool unseen = is_unseen({finding.id, finding.title, finding.severity, finding.last_seen}, seen_); if (severity_rank(finding.severity) < min_rank || (unseen_only_->isChecked() && !unseen)) { continue; } const int row = findings_table_->rowCount(); findings_table_->insertRow(row); auto* severity = new QTableWidgetItem(QString::fromStdString(finding.severity)); severity->setData(Qt::UserRole, QString::fromStdString(finding.id)); severity->setForeground(QColor(severity_color(finding.severity))); auto* score = new QTableWidgetItem(QString::number(finding.score)); auto* title = new QTableWidgetItem((unseen ? QStringLiteral("● ") : QString()) + QString::fromStdString(finding.title)); title->setToolTip(QString::fromStdString(finding.summary)); auto* last = new QTableWidgetItem(format_ns(finding.last_seen)); for (auto* item : {severity, score, title, last}) { QFont font = item->font(); font.setBold(unseen); item->setFont(font); } findings_table_->setItem(row, 0, severity); findings_table_->setItem(row, 1, score); findings_table_->setItem(row, 2, title); findings_table_->setItem(row, 3, last); if (!selected.isEmpty() && severity->data(Qt::UserRole).toString() == selected) { findings_table_->selectRow(row); } } findings_table_->blockSignals(false); if (!store_.available()) { findings_banner_->setText(QStringLiteral("Evidence unavailable: %1").arg(esc(store_.error()))); } else if (findings_.empty()) { findings_banner_->setText(QStringLiteral("No findings stored yet.")); } else { findings_banner_->setText(QStringLiteral("%1 finding(s); ● marks unseen.").arg(findings_.size())); } } void MainWindow::render_finding_detail(const FindingRecord& finding) { QString html; html += QStringLiteral("

%2

").arg(severity_color(finding.severity), esc(finding.title)); html += QStringLiteral("

%1 · score %2 · first seen %3 · last seen %4

") .arg(esc(finding.severity)).arg(finding.score).arg(format_ns(finding.first_seen), format_ns(finding.last_seen)); html += QStringLiteral("

%1

").arg(esc(finding.summary)); html += QStringLiteral("

Related processes

    "); bool any_process = false; for (const auto& node_id : finding.related_node_ids) { if (node_id.rfind("process_", 0) == 0) { any_process = true; html += QStringLiteral("
  • %1
  • ").arg(link(kProcessScheme, node_id, esc(node_id))); } } if (!any_process) { html += QStringLiteral("
  • none recorded
  • "); } html += QStringLiteral("
"); // One-click allowlisting for false positives. const auto meta = [&](const char* key) { const auto it = finding.metadata.find(key); return it == finding.metadata.end() ? std::string{} : it->second; }; const auto hash = meta("hash"); const auto path = meta("process_path"); QStringList actions; if (hash.size() == 64) { actions << link(kAllowHashScheme, hash, QStringLiteral("Allowlist this binary (all rules, by hash)")); } QString response; if (hash.size() == 64) { response = QStringLiteral("

Respond

%1

") .arg(link(kContainScheme, hash, QStringLiteral("Block this binary's network access (OpenSnitch)"))); } if (!path.empty() && path.front() == '/') { QString rules = QString::fromStdString(meta("rules")); for (const auto& rule : rules.split(QLatin1Char(','), Qt::SkipEmptyParts)) { actions << link(kAllowPathRuleScheme, rule.trimmed().toStdString() + "|" + path, QStringLiteral("Allowlist rule %1 at this path").arg(rule.trimmed().toHtmlEscaped())); } } html += response; if (!actions.isEmpty()) { html += QStringLiteral("

False positive?

%1

").arg(actions.join(QStringLiteral(" · "))); } html += QStringLiteral("

Details

"); for (const auto& [key, value] : finding.metadata) { html += QStringLiteral("").arg(esc(key), esc(value)); } html += QStringLiteral("
%1%2

%1

").arg(esc(finding.id)); finding_detail_->setHtml(html); } void MainWindow::run_process_search() { const auto query = process_query_->text().trimmed().toStdString(); process_hits_ = store_.search_processes(query); process_results_->clear(); for (const auto& hit : process_hits_) { const auto& node = hit.process; auto label = QStringLiteral("PID %1 %2").arg(prop(node, "pid"), prop(node, "path")); if (!hit.findings.empty()) { label = QStringLiteral("⚠ ") + label; } process_results_->addItem(label); } if (process_hits_.empty()) { process_detail_->setHtml(store_.available() ? QStringLiteral("

No matching processes.

") : QStringLiteral("

Evidence unavailable: %1

").arg(esc(store_.error()))); } else { process_results_->setCurrentRow(0); } } void MainWindow::render_process_detail(const ProcessSearchResult& result) { const auto& node = result.process; QString html; html += QStringLiteral("

PID %1 — %2

").arg(prop(node, "pid").toHtmlEscaped(), prop(node, "path").toHtmlEscaped()); QStringList flags; if (prop(node, "exe_memfd") == QStringLiteral("true")) flags << QStringLiteral("running from memfd (fileless)"); if (prop(node, "exe_deleted") == QStringLiteral("true")) flags << QStringLiteral("executable deleted from disk"); if (!flags.isEmpty()) { html += QStringLiteral("

%1

").arg(flags.join(QStringLiteral(" · "))); } html += QStringLiteral(""); const auto row = [&](const QString& label, const QString& value) { if (!value.isEmpty()) { html += QStringLiteral("").arg(label, value.toHtmlEscaped()); } }; row(QStringLiteral("Command line"), prop(node, "cmdline")); row(QStringLiteral("SHA-256"), prop(node, "hash")); row(QStringLiteral("Node id"), QString::fromStdString(node.id)); if (result.first_seen) row(QStringLiteral("First seen"), format_ns(static_cast(*result.first_seen))); if (result.last_seen) row(QStringLiteral("Last seen"), format_ns(static_cast(*result.last_seen))); html += QStringLiteral("
%1%2
"); html += QStringLiteral("

Lineage

    "); if (result.parent_process) { html += QStringLiteral("
  • Parent: %1
  • ").arg(link(kProcessScheme, result.parent_process->id, QStringLiteral("PID %1 %2").arg(prop(*result.parent_process, "pid"), prop(*result.parent_process, "path")).toHtmlEscaped())); } else { html += QStringLiteral("
  • Parent: not recorded
  • "); } for (const auto& child : result.child_processes) { html += QStringLiteral("
  • Child: %1
  • ").arg(link(kProcessScheme, child.id, QStringLiteral("PID %1 %2").arg(prop(child, "pid"), prop(child, "path")).toHtmlEscaped())); } html += QStringLiteral("
"); if (!result.findings.empty()) { html += QStringLiteral("

Findings

    "); for (const auto& finding : result.findings) { html += QStringLiteral("
  • [%2] %3
  • ") .arg(severity_color(finding.severity), esc(finding.severity), link(kFindingScheme, finding.id, esc(finding.title))); } html += QStringLiteral("
"); } html += QStringLiteral("

Related evidence

    "); for (const auto& related : result.related_nodes) { QString text = QString::fromStdString(related.type) + QStringLiteral(": "); if (related.type == "indicator") { text += prop(related, "rule_name") + QStringLiteral(" [") + prop(related, "severity") + QStringLiteral("]"); } else if (related.type == "file") { text += prop(related, "path"); } else { text += QString::fromStdString(related.id); } html += QStringLiteral("
  • %1
  • ").arg(text.toHtmlEscaped()); } html += QStringLiteral("
"); if (const auto hash = prop(node, "hash"); hash.size() == 64) { html += QStringLiteral("

Binary: %1 · %2 · %3

") .arg(link(kContainScheme, hash.toStdString(), QStringLiteral("Block network (OpenSnitch)")), link(kQuarantineScheme, hash.toStdString(), QStringLiteral("Quarantine (block execution)")), link(kAllowHashScheme, hash.toStdString(), QStringLiteral("Allowlist this binary (by hash)"))); } // Live actions need a stable id (pid + boot + start time) so the daemon can // verify it is still the same process. if (std::count(node.id.begin(), node.id.end(), '_') == 3) { const auto action = [&](const char* verb, const QString& text) { return link(kActionScheme, std::string(verb) + "|" + node.id, text); }; html += QStringLiteral("

Process (if still running): %1 · %2 · %3 · %4

") .arg(action("scan-memory", QStringLiteral("Scan memory")), action("process-suspend", QStringLiteral("Suspend")), action("process-resume", QStringLiteral("Resume")), action("process-kill", QStringLiteral("Kill"))); } if (process_result_ != nullptr) { process_result_->clear(); } const auto trace = store_.trace(node.id, 2); if (!trace.empty()) { html += QStringLiteral("

Incident trace

%1
").arg(esc(trace)); } process_detail_->setHtml(html); } void MainWindow::on_link(const QUrl& url) { const auto id = QUrl::fromPercentEncoding(url.path().toLatin1()); if (url.scheme() == kProcessScheme) { show_process(id); } else if (url.scheme() == kFindingScheme) { show_finding(id); } else if (url.scheme() == kContainScheme) { if (QMessageBox::question(this, QStringLiteral("Block network"), QStringLiteral("Deny all network access for this binary via OpenSnitch?\n\nsha256 %1\n\n" "You can undo this in the Response tab.").arg(id)) == QMessageBox::Yes) { tabs_->setCurrentWidget(contain_table_->parentWidget()); response_result_->setText(QStringLiteral("Blocking network…")); emit policy_change_requested(QStringLiteral("contain-add"), QJsonObject{{QStringLiteral("sha256"), id}}); } } else if (url.scheme() == kQuarantineScheme) { if (QMessageBox::question(this, QStringLiteral("Quarantine binary"), QStringLiteral("Block every execution of this exact binary (and its network access)?\n\n" "sha256 %1\n\nThe file is not moved or deleted. Undo in the Response tab.").arg(id)) == QMessageBox::Yes) { process_result_->setText(QStringLiteral("Quarantining…")); emit policy_change_requested(QStringLiteral("quarantine"), QJsonObject{{QStringLiteral("sha256"), id}}); } } else if (url.scheme() == kActionScheme) { const auto sep = id.indexOf(QLatin1Char('|')); if (sep <= 0) { return; } const auto verb = id.left(sep); const auto node_id = id.mid(sep + 1); QString question; if (verb == QStringLiteral("process-kill")) { question = QStringLiteral("Kill this process immediately (SIGKILL)? Unsaved work in it is lost."); } else if (verb == QStringLiteral("process-suspend")) { question = QStringLiteral("Suspend this process (SIGSTOP)? It stays frozen until you resume it."); } if (!question.isEmpty() && QMessageBox::question(this, QStringLiteral("Confirm"), question + QStringLiteral("\n\n") + node_id) != QMessageBox::Yes) { return; } process_result_->setText(QStringLiteral("Sending…")); emit policy_change_requested(verb, QJsonObject{{QStringLiteral("node_id"), node_id}}); } else if (url.scheme() == kAllowHashScheme) { propose_allowlist(QStringLiteral("sha256"), id, {}, QStringLiteral("every rule match on this exact binary")); } else if (url.scheme() == kAllowPathRuleScheme) { const auto sep = id.indexOf(QLatin1Char('|')); if (sep > 0) { propose_allowlist(QStringLiteral("path"), id.mid(sep + 1), id.left(sep), QStringLiteral("rule %1 for this path only").arg(id.left(sep))); } } } void MainWindow::show_finding(const QString& finding_id) { tabs_->setCurrentIndex(0); severity_filter_->setCurrentIndex(0); unseen_only_->setChecked(false); refresh_findings(seen_); for (int row = 0; row < findings_table_->rowCount(); ++row) { if (findings_table_->item(row, 0)->data(Qt::UserRole).toString() == finding_id) { findings_table_->selectRow(row); findings_table_->scrollToItem(findings_table_->item(row, 0)); return; } } } void MainWindow::select_tab(const QString& name) { for (int i = 0; i < tabs_->count(); ++i) { if (tabs_->tabText(i).compare(name, Qt::CaseInsensitive) == 0) { tabs_->setCurrentIndex(i); return; } } } void MainWindow::show_process(const QString& node_id) { tabs_->setCurrentIndex(1); process_query_->setText(node_id); process_hits_.clear(); process_results_->clear(); if (auto result = store_.process(node_id.toStdString())) { process_hits_.push_back(*result); process_results_->addItem(QStringLiteral("PID %1 %2").arg(prop(result->process, "pid"), prop(result->process, "path"))); process_results_->setCurrentRow(0); } else { process_detail_->setHtml(QStringLiteral("

Process %1 is not in the evidence store.

").arg(node_id.toHtmlEscaped())); } } void MainWindow::update_status(const QJsonObject& status, const QString& error, const TrayState& tray) { status_ = status; status_error_ = error; tray_ = tray; reload_button_->setEnabled(error.isEmpty()); rescan_button_->setEnabled(error.isEmpty()); render_diagnostics(); render_rules(); render_response(); } void MainWindow::show_command_result(const QString& verb, bool ok, const QString& message) { QString name = QStringLiteral("Rule reload"); if (verb == QStringLiteral("rescan")) { name = QStringLiteral("Rescan"); } else if (verb == QStringLiteral("update-rules")) { name = QStringLiteral("Rule update"); } if (rules_result_ != nullptr && verb != QStringLiteral("rescan")) { rules_result_->setText(QStringLiteral("%2: %3") .arg(ok ? QStringLiteral("#2ea043") : QStringLiteral("#d72638"), name, message.toHtmlEscaped())); } command_result_->setText(QStringLiteral("%2: %3") .arg(ok ? QStringLiteral("#2ea043") : QStringLiteral("#d72638"), name, message.toHtmlEscaped())); } void MainWindow::render_diagnostics() { if (diagnostics_ == nullptr) { return; } QString html; if (!status_error_.isEmpty() || status_.isEmpty()) { html += QStringLiteral("

%1 Scanner not reachable

%2

") .arg(check(false), (status_error_.isEmpty() ? QStringLiteral("waiting for first status…") : status_error_).toHtmlEscaped()); html += QStringLiteral("

Check the service: %1

").arg(QString::fromUtf8(strawberry::hints::kStatus)); } else { const auto monitor = status_.value(QStringLiteral("monitor")).toObject(); const auto rules = status_.value(QStringLiteral("rules")).toObject(); const auto pipeline = status_.value(QStringLiteral("pipeline")).toObject(); const auto backend = monitor.value(QStringLiteral("backend")).toString(); const qint64 now = json_ns(status_, "now_ns"); const qint64 started = json_ns(status_, "started_at_ns"); html += QStringLiteral("

%1 Scanner %2

").arg(check(tray_.problems.empty()), tray_.problems.empty() ? QStringLiteral("healthy") : QStringLiteral("degraded")); if (!tray_.problems.empty()) { html += QStringLiteral("
    "); for (const auto& problem : tray_.problems) { html += QStringLiteral("
  • %1
  • ").arg(esc(problem)); } html += QStringLiteral("
"); } html += QStringLiteral("

Monitoring

"); html += QStringLiteral("").arg(check(backend == QStringLiteral("bpf")), backend.toHtmlEscaped(), backend == QStringLiteral("bpf") ? QString() : QStringLiteral(" (eBPF unavailable; polling /proc)")); html += QStringLiteral("").arg(check(monitor.value(QStringLiteral("execveat")).toBool())); html += QStringLiteral("").arg(check(monitor.value(QStringLiteral("fork_tracepoint")).toBool())); html += QStringLiteral("").arg(monitor.value(QStringLiteral("events")).toDouble(), 0, 'f', 0); html += QStringLiteral("
%1Backend: %2%3
%1execveat hooked (fexecve / memfd executions)
%1Fork tracepoint (parent PID enrichment, optional)
Process events seen: %1
"); const qint64 loaded_at = json_ns(rules, "loaded_at_ns"); html += QStringLiteral("

Rules

"); html += QStringLiteral("") .arg(check(rules.value(QStringLiteral("loaded")).toBool())) .arg(rules.value(QStringLiteral("files")).toInt()) .arg(rules.value(QStringLiteral("path")).toString().toHtmlEscaped()); if (loaded_at > 0) { html += QStringLiteral("") .arg(format_ns(loaded_at), duration_text((now - loaded_at) / 1'000'000'000)) .arg(rules.value(QStringLiteral("generation")).toInt()); } const auto rules_error = rules.value(QStringLiteral("last_error")).toString(); if (!rules_error.isEmpty()) { html += QStringLiteral("") .arg(check(false), rules_error.toHtmlEscaped()); } html += QStringLiteral("
%1%2 rule file(s) from %3
Loaded %1 (%2 ago), generation %3
%1Last reload failed: %2 (previous rules still active)
"); const auto count = [&](const char* key) { return QString::number(pipeline.value(QLatin1String(key)).toDouble(), 'f', 0); }; html += QStringLiteral("

Detection pipeline

"); html += QStringLiteral("").arg(count("events")); html += QStringLiteral("").arg(count("scanned"), count("cache_hits")); html += QStringLiteral("").arg(count("detections"), format_ns(json_ns(pipeline, "last_detection_ns"))); html += QStringLiteral("").arg(count("images_unavailable")); html += QStringLiteral("").arg(count("scan_errors")); html += QStringLiteral("
Events handled%1
Images scanned%1 (+%2 from cache)
Detections stored%1 (last: %2)
Images gone before scan%1
Scan errors%1
"); const auto resources = status_.value(QStringLiteral("resources")).toObject(); if (!resources.isEmpty()) { const auto host = resources.value(QStringLiteral("host")).toObject(); const auto level = resources.value(QStringLiteral("level")).toString(); const auto num = [](const QJsonObject& o, const char* key, int decimals = 0) { return QString::number(o.value(QLatin1String(key)).toDouble(), 'f', decimals); }; html += QStringLiteral("

Resources

"); html += QStringLiteral("") .arg(check(level == QStringLiteral("normal") || level == QStringLiteral("warning")), resources.value(QStringLiteral("profile")).toString().toHtmlEscaped(), level.toHtmlEscaped(), resources.value(QStringLiteral("host_busy")).toBool() ? QStringLiteral(" · host busy: background work waits") : QString()); html += QStringLiteral("") .arg(num(resources, "own_cpu_pct", 1), num(resources, "cpu_capacity", 1), num(resources, "rss_mb"), num(resources, "memory_budget_mb")); html += QStringLiteral("") .arg(host.value(QStringLiteral("source")).toString().toHtmlEscaped(), num(host, "cpu_some_pct", 1), num(host, "io_some_pct", 1), num(host, "memory_some_pct", 1), num(host, "mem_available_mb")); QStringList deferring; for (const auto& name : resources.value(QStringLiteral("deferring")).toArray()) { deferring << name.toString().toHtmlEscaped(); } if (!deferring.isEmpty()) { html += QStringLiteral("") .arg(deferring.join(QStringLiteral(", ")), num(resources, "longest_deferral_s")); } html += QStringLiteral("") .arg(num(resources, "inventory_pending"), num(resources, "memory_scans_skipped"), num(resources, "guard_degraded"), QString::number(resources.value(QStringLiteral("read_paced_ms")).toDouble() / 1000.0, 'f', 1)); html += QStringLiteral("
%1Profile %2, pressure %3%4
Scanner CPU %1% of %2 CPU(s) · memory %3 / %4 MiB
Host pressure (%1): cpu %2% · io %3% · memory %4% · %5 MiB available
Waiting for a calmer system: %1 (%2 s)
Inventory pending %1 · memory scans skipped %2 · exec checks reduced to hash-only %3 · read pacing %4 s
"); } const auto timings = status_.value(QStringLiteral("timings")).toObject(); if (!timings.isEmpty()) { const std::pair rows[] = { {"exec_decision", "Program launch check"}, {"exec_assess", "Exec guard scan"}, {"queue_wait", "Queue wait"}, {"image_scan", "Image read + scan"}, {"yara_scan", "YARA scan"}, {"db_commit", "Database commit"}, {"correlation", "Correlation pass"}, {"rule_compile", "Rule compile"}, {"memory_scan", "Memory scan"}, }; html += QStringLiteral("

Timings

" ""); for (const auto& [key, label] : rows) { const auto t = timings.value(QLatin1String(key)).toObject(); const auto n = t.value(QStringLiteral("count")).toDouble(); if (n <= 0) { continue; } html += QStringLiteral("") .arg(QLatin1String(label), QString::number(n, 'f', 0), QString::number(t.value(QStringLiteral("p50_ms")).toDouble(), 'f', 1), QString::number(t.value(QStringLiteral("p95_ms")).toDouble(), 'f', 1), QString::number(t.value(QStringLiteral("max_ms")).toDouble(), 'f', 1)); } html += QStringLiteral("
countp50 msp95 msmax ms
%1%2%3%4%5
"); } html += QStringLiteral("

Daemon

"); html += QStringLiteral("") .arg(status_.value(QStringLiteral("version")).toString().toHtmlEscaped()) .arg(status_.value(QStringLiteral("pid")).toInt()); if (started > 0) { html += QStringLiteral("").arg(duration_text((now - started) / 1'000'000'000)); } html += QStringLiteral("").arg(status_.value(QStringLiteral("config_path")).toString().toHtmlEscaped()); html += QStringLiteral("
Version / PID%1 / %2
Uptime%1
Config%1
"); } html += QStringLiteral("

Evidence database

"); html += QStringLiteral("") .arg(check(store_.available()), QString::fromStdString(store_.path()).toHtmlEscaped(), store_.available() ? QStringLiteral(" (%1 KiB, read-only)").arg(store_.size_bytes() / 1024) : QString()); if (!store_.available()) { html += QStringLiteral("").arg(esc(store_.error())); } html += QStringLiteral("
%1%2%3
%1
"); html += QStringLiteral("

Logs: %1

").arg(QString::fromUtf8(strawberry::hints::kFollowLogs)); diagnostics_->setHtml(html); } } // namespace strawberry::app