MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / addHashField

Method addHashField

examples/triage/fileinfo.cpp:35–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35void FileInfoWidget::addHashField(
36 const QString& hashName, const QCryptographicHash::Algorithm& algorithm, const QByteArray& data)
37{
38 auto& [row, column] = this->m_fieldPosition;
39
40 const auto hashFieldColor = getThemeColor(AlphanumericHighlightColor);
41 auto hashLabel = new CopyableLabel("Calculating...", hashFieldColor);
42 hashLabel->setFont(getMonospaceFont(this));
43
44 this->m_layout->addWidget(new QLabel(hashName), row, column);
45 this->m_layout->addWidget(hashLabel, row++, column + 1);
46
47 // Process the hash calculations in a separate thread and update the label when done
48 QPointer<QFutureWatcher<QByteArray>> watcher = new QFutureWatcher<QByteArray>(this);
49 connect(watcher, &QFutureWatcher<QByteArray>::finished, this, [watcher, hashLabel]() {
50 if (watcher)
51 {
52 hashLabel->setText(watcher->result().toHex());
53 watcher->deleteLater();
54 }
55 });
56 QFuture<QByteArray> future = QtConcurrent::run([data, algorithm]() {
57 return QCryptographicHash::hash(data, algorithm);
58 });
59 watcher->setFuture(future);
60 connect(this, &QObject::destroyed, this, [watcher]() {
61 if (watcher && watcher->isRunning()) {
62 watcher->cancel();
63 watcher->waitForFinished();
64 }
65 });
66}
67
68FileInfoWidget::FileInfoWidget(QWidget* parent, BinaryViewRef bv)
69{

Callers 1

FileInfoWidgetMethod · 0.95

Calls 4

connectFunction · 0.85
runFunction · 0.85
resultMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected