summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorrose <47357290+rompse@users.noreply.github.com>2021-10-05 17:20:51 -0400
committerrose <47357290+rompse@users.noreply.github.com>2021-10-06 15:55:01 -0400
commita396e114c14c5c1cf9fa12688fdbdafe2f07b61b (patch)
tree16c00c4b78413e0aea992de48601f2a7a5aec191 /examples
parentc4f4bf5be39c224b619a5928d380d91122ecf1d8 (diff)
TriageView: path, size, md5, sha1, sha256
Diffstat (limited to 'examples')
-rw-r--r--examples/triage/fileinfo.cpp99
-rw-r--r--examples/triage/fileinfo.h21
-rw-r--r--examples/triage/view.cpp9
3 files changed, 128 insertions, 1 deletions
diff --git a/examples/triage/fileinfo.cpp b/examples/triage/fileinfo.cpp
new file mode 100644
index 00000000..00b75ca2
--- /dev/null
+++ b/examples/triage/fileinfo.cpp
@@ -0,0 +1,99 @@
+#include "fileinfo.h"
+#include "fontsettings.h"
+#include "theme.h"
+#include <QClipboard>
+#include <QApplication>
+#include <QToolTip>
+#include <QPainter>
+
+class CopyableLabel: public QLabel
+{
+ QColor m_desiredColor{};
+
+public:
+ CopyableLabel(const QString& text, const QColor& color)
+ : QLabel(text), m_desiredColor(color)
+ {
+ this->setMouseTracking(true);
+ auto style = QPalette(palette());
+ style.setColor(QPalette::WindowText, m_desiredColor);
+ setPalette(style);
+ this->setToolTip("Copy");
+ }
+
+ void enterEvent(QEnterEvent* event) override
+ {
+ auto font = this->font();
+ font.setBold(true);
+ this->setFont(font);
+ QToolTip::showText(event->globalPosition().toPoint(), this->toolTip());
+ }
+
+ void leaveEvent(QEvent* event) override
+ {
+ auto font = this->font();
+ font.setBold(false);
+ this->setFont(font);
+ QToolTip::hideText();
+ }
+
+ void mousePressEvent(QMouseEvent* event) override
+ {
+ if (event->button() == Qt::LeftButton)
+ QApplication::clipboard()->setText(this->text());
+ }
+};
+
+void FileInfoWidget::addField(const QString& name, const QVariant& value)
+{
+ auto& [row, column] = this->m_fieldPosition;
+
+ const auto valueLabel = new QLabel(value.toString());
+ valueLabel->setFont(getMonospaceFont(this));
+
+ this->m_layout->addWidget(new QLabel(name), row, column);
+ this->m_layout->addWidget(valueLabel, row++, column + 1);
+}
+
+void FileInfoWidget::addHashField(const QString& hashName,
+ const QCryptographicHash::Algorithm& algorithm,
+ const QByteArray& data)
+{
+ auto& [row, column] = this->m_fieldPosition;
+
+ const auto hashFieldColor = getThemeColor(AlphanumericHighlightColor);
+ const auto crypto = QCryptographicHash::hash(data, algorithm);
+ const auto hashLabel = new CopyableLabel(crypto.toHex(), hashFieldColor);
+ hashLabel->setFont(getMonospaceFont(this));
+
+ this->m_layout->addWidget(new QLabel(hashName), row, column);
+ this->m_layout->addWidget(hashLabel, row++, column + 1);
+}
+
+FileInfoWidget::FileInfoWidget(QWidget* parent, BinaryViewRef bv)
+{
+ this->m_layout = new QGridLayout();
+ this->m_layout->setContentsMargins(0, 0, 0, 0);
+ this->m_layout->setVerticalSpacing(1);
+
+ const auto filePath = bv->GetFile()->GetOriginalFilename();
+ this->addField("Path: ", filePath.c_str());
+
+ const auto fileSize = QString::number(bv->GetParentView()->GetLength(), 16).prepend("0x");
+ this->addField("Size: ", fileSize);
+
+ const auto bufferSize = fileSize.toUInt(nullptr, 16);
+ const auto fileBuffer = std::make_unique<char[]>(bufferSize);
+ bv->GetParentView()->Read(fileBuffer.get(), 0, bufferSize);
+
+ const auto fileBytes = QByteArray(fileBuffer.get(), bufferSize);
+ this->addHashField("MD5: ", QCryptographicHash::Md5, fileBytes);
+ this->addHashField("SHA-1: ", QCryptographicHash::Sha1, fileBytes);
+ this->addHashField("SHA-256: ", QCryptographicHash::Sha256, fileBytes);
+
+ const auto scaledWidth = UIContext::getScaledWindowSize(20, 20).width();
+ this->m_layout->setColumnMinimumWidth(FileInfoWidget::m_maxColumns * 3 - 1, scaledWidth);
+ this->m_layout->setColumnStretch(FileInfoWidget::m_maxColumns * 3 - 1, 1);
+ setLayout(this->m_layout);
+}
+
diff --git a/examples/triage/fileinfo.h b/examples/triage/fileinfo.h
new file mode 100644
index 00000000..02cc154d
--- /dev/null
+++ b/examples/triage/fileinfo.h
@@ -0,0 +1,21 @@
+#pragma once
+#include <QtWidgets/QLabel>
+#include <QtWidgets/QWidget>
+#include <QCryptographicHash>
+#include "uitypes.h"
+#include "viewframe.h"
+
+class FileInfoWidget: public QWidget
+{
+ static constexpr std::int32_t m_maxColumns{2};
+ std::pair<std::int32_t, std::int32_t> m_fieldPosition{}; // row, column
+ QGridLayout* m_layout{};
+
+ void addField(const QString& name, const QVariant& value);
+ void addHashField(const QString& hashName,
+ const QCryptographicHash::Algorithm& algorithm,
+ const QByteArray& data);
+
+public:
+ FileInfoWidget(QWidget* parent, BinaryViewRef bv);
+};
diff --git a/examples/triage/view.cpp b/examples/triage/view.cpp
index e69fa0d9..2c5f7b9b 100644
--- a/examples/triage/view.cpp
+++ b/examples/triage/view.cpp
@@ -6,9 +6,10 @@
#include "imports.h"
#include "exports.h"
#include "sections.h"
+#include "fileinfo.h"
#include "headers.h"
#include "fontsettings.h"
-
+#include <binaryninjacore.h>
TriageView::TriageView(QWidget* parent, BinaryViewRef data): QScrollArea(parent)
{
@@ -25,6 +26,12 @@ TriageView::TriageView(QWidget* parent, BinaryViewRef data): QScrollArea(parent)
entropyGroup->setLayout(entropyLayout);
layout->addWidget(entropyGroup);
+ QGroupBox* fileInfoGroup = new QGroupBox("File Info", container);
+ QVBoxLayout* fileInfoLayout = new QVBoxLayout();
+ fileInfoLayout->addWidget(new FileInfoWidget(fileInfoGroup, m_data));
+ fileInfoGroup->setLayout(fileInfoLayout);
+ layout->addWidget(fileInfoGroup);
+
Headers* hdr = nullptr;
if (m_data->GetTypeName() == "PE")
hdr = new PEHeaders(m_data);