summaryrefslogtreecommitdiff
path: root/examples/triage/entropy.cpp
diff options
context:
space:
mode:
authorJordan Wiens <github@psifertex.com>2026-01-01 12:21:22 -0500
committerJordan Wiens <github@psifertex.com>2026-01-01 12:21:22 -0500
commit37a0604d805991b85a0590279ad993a19ddee7bb (patch)
treefa8054497a4761f134ab5b537dfb0dbfc9a64f32 /examples/triage/entropy.cpp
parent2448131059638409902821451115872036230328 (diff)
add whole-file entropy calculation to triage
Diffstat (limited to 'examples/triage/entropy.cpp')
-rw-r--r--examples/triage/entropy.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/examples/triage/entropy.cpp b/examples/triage/entropy.cpp
index da089fd6..dd643af7 100644
--- a/examples/triage/entropy.cpp
+++ b/examples/triage/entropy.cpp
@@ -12,6 +12,8 @@ EntropyThread::EntropyThread(BinaryViewRef data, size_t blockSize, QImage* image
m_blockSize = blockSize;
m_updated = false;
m_running = true;
+ m_averageEntropy = 0.0;
+ m_sampleCount = 0;
m_thread = std::thread([=, this]() { Run(); });
}
@@ -33,10 +35,22 @@ void EntropyThread::Run()
std::vector<float> entropy =
m_data->GetEntropy(m_data->GetStart() + ((uint64_t)i * m_blockSize), m_blockSize, m_blockSize);
int v;
+ float entropyValue = 0.0f;
if (entropy.size() == 0)
v = 0;
else
- v = (int)(entropy[0] * 255);
+ {
+ entropyValue = entropy[0];
+ v = (int)(entropyValue * 255);
+ }
+
+ // Update running average
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ m_sampleCount++;
+ m_averageEntropy += (entropyValue - m_averageEntropy) / m_sampleCount;
+ }
+
if (v >= 240)
{
QColor color = getThemeColor(YellowStandardHighlightColor);
@@ -54,6 +68,13 @@ void EntropyThread::Run()
}
+double EntropyThread::GetAverageEntropy() const
+{
+ std::lock_guard<std::mutex> lock(m_mutex);
+ return m_averageEntropy;
+}
+
+
EntropyWidget::EntropyWidget(QWidget* parent, TriageView* view, BinaryViewRef data) : QWidget(parent)
{
m_view = view;
@@ -106,6 +127,7 @@ void EntropyWidget::timerExpired()
{
m_thread->ResetUpdated();
update();
+ emit entropyUpdated(m_thread->GetAverageEntropy());
}
}
@@ -131,3 +153,9 @@ void EntropyWidget::mouseMoveEvent(QMouseEvent* event)
else
setToolTip(QString("File offset: 0x%1").arg(offset, 0, 16));
}
+
+
+double EntropyWidget::getAverageEntropy() const
+{
+ return m_thread->GetAverageEntropy();
+}