summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorXusheng <xusheng@vector35.com>2024-07-26 15:57:14 +0800
committerXusheng <xusheng@vector35.com>2024-08-02 12:17:53 +0800
commitabbae639d8ba182e8b3cf2d5a9844a9b1f9844a1 (patch)
tree272322e3269b09201c12489d93e7fbeb614fb140 /examples
parent7a9a2503aae0c2b92b437b2ea7796efaae93a822 (diff)
Support setting user global pointer value
Diffstat (limited to 'examples')
-rw-r--r--examples/triage/analysisinfo.cpp76
-rw-r--r--examples/triage/analysisinfo.h29
-rw-r--r--examples/triage/headers.cpp16
-rw-r--r--examples/triage/headers.h4
-rw-r--r--examples/triage/view.cpp7
5 files changed, 120 insertions, 12 deletions
diff --git a/examples/triage/analysisinfo.cpp b/examples/triage/analysisinfo.cpp
new file mode 100644
index 00000000..a10b4472
--- /dev/null
+++ b/examples/triage/analysisinfo.cpp
@@ -0,0 +1,76 @@
+#include <QtCore/QTimer>
+#include "analysisinfo.h"
+#include "fontsettings.h"
+#include "util.h"
+
+AnalysisInfoWidget::AnalysisInfoWidget(QWidget* parent, BinaryViewRef data): QWidget(parent), m_data(data)
+{
+ m_layout = new QGridLayout();
+ m_layout->setContentsMargins(0, 0, 0, 0);
+ m_layout->setVerticalSpacing(1);
+
+ auto* gpValueLayout = new QHBoxLayout();
+ gpValueLayout->setContentsMargins(0, 0, 0, 0);
+ m_gpLabel = new NavigationAddressLabel("");
+ m_gpLabel->setFont(getMonospaceFont(this));
+ gpValueLayout->addWidget(m_gpLabel);
+
+ m_gpExtraLabel = new QLabel;
+ gpValueLayout->addWidget(m_gpExtraLabel);
+
+ m_layout->addWidget(new QLabel("Global Pointer Value:"), 0, 0);
+ m_layout->addLayout(gpValueLayout, 0, 1);
+
+ const auto scaledWidth = UIContext::getScaledWindowSize(20, 20).width();
+ this->m_layout->setColumnMinimumWidth(AnalysisInfoWidget::m_maxColumns * 3 - 1, scaledWidth);
+ this->m_layout->setColumnStretch(AnalysisInfoWidget::m_maxColumns * 3 - 1, 1);
+ setLayout(m_layout);
+
+ updateDisplay();
+
+ auto* timer = new QTimer(this);
+ connect(timer, &QTimer::timeout, this, &AnalysisInfoWidget::timerExpired);
+ timer->setInterval(100);
+ timer->setSingleShot(false);
+ timer->start();
+}
+
+
+AnalysisInfoWidget::~AnalysisInfoWidget()
+{
+
+}
+
+
+void AnalysisInfoWidget::timerExpired()
+{
+ auto gpValue = m_data->GetGlobalPointerValue();
+ if (gpValue == m_lastGPValue)
+ return;
+
+ m_lastGPValue = gpValue;
+ updateDisplay();
+}
+
+
+void AnalysisInfoWidget::updateDisplay()
+{
+ auto callingConvention = m_data->GetDefaultPlatform()->GetDefaultCallingConvention();
+ auto gpRegister = callingConvention->GetGlobalPointerRegister();
+ std::string gpString, gpExtraString;
+ if (gpRegister == BN_INVALID_REGISTER)
+ {
+ gpString = "N/A";
+ }
+ else
+ {
+ auto gpValue = m_data->GetGlobalPointerValue();
+ gpString = getStringForRegisterValue(m_data->GetDefaultArchitecture(), gpValue);
+ gpExtraString = std::string(" @ ") + m_data->GetDefaultArchitecture()->GetRegisterName(gpRegister);
+ if (m_data->UserGlobalPointerValueSet())
+ gpExtraString += " (*)";
+ }
+
+ m_gpLabel->setText(QString::fromStdString(gpString));
+ m_gpExtraLabel->setText(QString::fromStdString(gpExtraString));
+}
diff --git a/examples/triage/analysisinfo.h b/examples/triage/analysisinfo.h
new file mode 100644
index 00000000..4e6e6df3
--- /dev/null
+++ b/examples/triage/analysisinfo.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <QtWidgets/QWidget>
+#include <QtWidgets/QGridLayout>
+#include <QtWidgets/QLabel>
+#include "uitypes.h"
+#include "headers.h"
+
+class TriageView;
+
+class AnalysisInfoWidget : public QWidget
+{
+ static constexpr std::int32_t m_maxColumns {2};
+ BinaryViewRef m_data;
+ QGridLayout* m_layout {};
+ NavigationAddressLabel* m_gpLabel;
+ QLabel* m_gpExtraLabel;
+
+ BinaryNinja::Confidence<BinaryNinja::RegisterValue> m_lastGPValue;
+
+ void updateDisplay();
+
+public:
+ AnalysisInfoWidget(QWidget* parent, BinaryViewRef data);
+ virtual ~AnalysisInfoWidget();
+
+private Q_SLOTS:
+ void timerExpired();
+};
diff --git a/examples/triage/headers.cpp b/examples/triage/headers.cpp
index 1bdc31fe..6d6e2623 100644
--- a/examples/triage/headers.cpp
+++ b/examples/triage/headers.cpp
@@ -26,24 +26,24 @@ void NavigationLabel::mousePressEvent(QMouseEvent*)
NavigationAddressLabel::NavigationAddressLabel(const QString& text) :
NavigationLabel(text, getThemeColor(AddressColor), [this]() { clickEvent(); })
{
- m_address = text.toULongLong(nullptr, 0);
}
void NavigationAddressLabel::clickEvent()
{
+ auto address = text().toULongLong(nullptr, 0);
ViewFrame* viewFrame = ViewFrame::viewFrameForWidget(this);
if (viewFrame)
{
if (BinaryNinja::Settings::Instance()->Get<bool>("ui.view.graph.preferred") &&
viewFrame->getCurrentBinaryView() &&
- viewFrame->getCurrentBinaryView()->GetAnalysisFunctionsForAddress(m_address).size() > 0)
+ viewFrame->getCurrentBinaryView()->GetAnalysisFunctionsForAddress(address).size() > 0)
{
- viewFrame->navigate("Graph:" + viewFrame->getCurrentDataType(), m_address);
+ viewFrame->navigate("Graph:" + viewFrame->getCurrentDataType(), address);
}
else
{
- viewFrame->navigate("Linear:" + viewFrame->getCurrentDataType(), m_address);
+ viewFrame->navigate("Linear:" + viewFrame->getCurrentDataType(), address);
}
}
}
@@ -52,24 +52,24 @@ void NavigationAddressLabel::clickEvent()
NavigationCodeLabel::NavigationCodeLabel(const QString& text) :
NavigationLabel(text, getThemeColor(CodeSymbolColor), [this]() { clickEvent(); })
{
- m_address = text.toULongLong(nullptr, 0);
}
void NavigationCodeLabel::clickEvent()
{
+ auto address = text().toULongLong(nullptr, 0);
ViewFrame* viewFrame = ViewFrame::viewFrameForWidget(this);
if (viewFrame)
{
if (BinaryNinja::Settings::Instance()->Get<bool>("ui.view.graph.preferred") &&
viewFrame->getCurrentBinaryView() &&
- viewFrame->getCurrentBinaryView()->GetAnalysisFunctionsForAddress(m_address).size() > 0)
+ viewFrame->getCurrentBinaryView()->GetAnalysisFunctionsForAddress(address).size() > 0)
{
- viewFrame->navigate("Graph:" + viewFrame->getCurrentDataType(), m_address);
+ viewFrame->navigate("Graph:" + viewFrame->getCurrentDataType(), address);
}
else
{
- viewFrame->navigate("Linear:" + viewFrame->getCurrentDataType(), m_address);
+ viewFrame->navigate("Linear:" + viewFrame->getCurrentDataType(), address);
}
}
}
diff --git a/examples/triage/headers.h b/examples/triage/headers.h
index a8348401..e96dead5 100644
--- a/examples/triage/headers.h
+++ b/examples/triage/headers.h
@@ -20,8 +20,6 @@ class NavigationLabel : public QLabel
class NavigationAddressLabel : public NavigationLabel
{
- uint64_t m_address;
-
void clickEvent();
public:
@@ -31,8 +29,6 @@ class NavigationAddressLabel : public NavigationLabel
class NavigationCodeLabel : public NavigationLabel
{
- uint64_t m_address;
-
void clickEvent();
public:
diff --git a/examples/triage/view.cpp b/examples/triage/view.cpp
index 6a43d660..ad44da8c 100644
--- a/examples/triage/view.cpp
+++ b/examples/triage/view.cpp
@@ -12,6 +12,7 @@
#include "strings.h"
#include "baseaddress.h"
#include "fontsettings.h"
+#include "analysisinfo.h"
#include <binaryninjacore.h>
TriageView::TriageView(QWidget* parent, BinaryViewRef data) : QScrollArea(parent)
@@ -108,6 +109,12 @@ TriageView::TriageView(QWidget* parent, BinaryViewRef data) : QScrollArea(parent
if (sectionsWidget->GetSections().size() == 0)
sectionsGroup->hide();
+ QGroupBox* analysisInfoGroup = new QGroupBox("Analysis Info", container);
+ QVBoxLayout* analysisInfoLayout = new QVBoxLayout();
+ analysisInfoLayout->addWidget(new AnalysisInfoWidget(analysisInfoGroup, m_data));
+ analysisInfoGroup->setLayout(analysisInfoLayout);
+ layout->addWidget(analysisInfoGroup);
+
QGroupBox* stringsGroup = new QGroupBox("Strings", container);
QVBoxLayout* stringsLayout = new QVBoxLayout();
stringsLayout->addWidget(new StringsWidget(stringsGroup, this, m_data));