summaryrefslogtreecommitdiff
path: root/examples/triage/analysisinfo.cpp
blob: cd18e2421471ea21c5888aac104ed7af90cc88f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#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 defaultPlatform = m_data->GetDefaultPlatform();
	if (defaultPlatform)
	{
		auto callingConvention = defaultPlatform->GetDefaultCallingConvention();
		if (callingConvention)
		{
			auto gpRegister = callingConvention->GetGlobalPointerRegister();
			if (gpRegister != BN_INVALID_REGISTER)
			{
				auto gpValue = m_data->GetGlobalPointerValue();
				std::string gpString = getStringForRegisterValue(m_data->GetDefaultArchitecture(), gpValue);
				std::string 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));
				return;
			}
		}
	}

	m_gpLabel->setText("N/A");
}