summaryrefslogtreecommitdiff
path: root/examples/triage/baseaddress.h
blob: ba512ff122f9d0fc094ed96cd95a45ba103b43fe (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
82
83
84
85
86
87
88
89
90
91
92
#pragma once

#include <QThread>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QTableWidget>
#include <QHeaderView>
#include <QCoreApplication>
#include "theme.h"
#include "fontsettings.h"
#include "expandablegroup.h"
#include "viewframe.h"
#include "binaryninjaapi.h"
#include "binaryninjacore.h"
#include "progresstask.h"

struct BaseAddressDetectionQtInputs
{
	QComboBox* ArchitectureBox;
	QComboBox* AnalysisBox;
	QLineEdit* StrlenLineEdit;
	QLineEdit* AlignmentLineEdit;
	QLineEdit* LowerBoundary;
	QLineEdit* UpperBoundary;
	QComboBox* POIBox;
	QLineEdit* MaxPointersPerCluster;
};

struct BaseAddressDetectionQtResults
{
	std::string Status;
	std::set<std::pair<size_t, uint64_t>> Scores;
	BNBaseAddressDetectionConfidence Confidence;
	std::map<uint64_t, std::vector<BNBaseAddressDetectionReason>> Reasons;
	uint64_t LastTestedBaseAddress;
};

class BaseAddressDetectionThread : public QThread
{
	Q_OBJECT
	BinaryNinja::Ref<BinaryNinja::BinaryView> m_view;
	BinaryNinja::BaseAddressDetection* m_baseDetection;
	BaseAddressDetectionQtInputs* m_inputs {};
	void run() override;

public:
	BaseAddressDetectionThread(BaseAddressDetectionQtInputs* widgetInputs, BinaryNinja::Ref<BinaryNinja::BinaryView> bv)
	{
		m_inputs = widgetInputs;
		m_view = bv;
		m_baseDetection = new BinaryNinja::BaseAddressDetection(m_view);
	}

	void Abort() { m_baseDetection->Abort(); }
	bool IsAborted() { return m_baseDetection->IsAborted(); }

signals:
	void ResultReady(const BaseAddressDetectionQtResults& result);
};

class BaseAddressDetectionWidget : public QWidget
{
	BaseAddressDetectionThread* m_worker;
	BinaryNinja::Ref<BinaryNinja::BinaryView> m_view;
	BaseAddressDetectionQtInputs m_inputs;

	QGridLayout* m_layout {};
	QPushButton* m_startButton = nullptr;
	QPushButton* m_abortButton = nullptr;
	QLabel* m_preferredBaseLabel;
	QLabel* m_preferredBase;
	QLabel* m_confidenceLabel;
	QLabel* m_confidence;
	QLabel* m_status;
	QLineEdit* m_reloadBase;
	QPushButton* m_rebaseButton;
	QTableWidget* m_resultsTableWidget;
	ExpandableGroup* m_advancedSettingsGroup;

	void DetectBaseAddress();
	const std::string GetRebaseViewName();
	void RebaseWithFullAnalysis();
	void Abort();
	void HandleResults(const BaseAddressDetectionQtResults& results);
	void HideResultsWidgets(bool hide);
	void CreateAdvancedSettingsGroup();
	void GetClickedBaseAddress(const QModelIndex& index);

public:
	BaseAddressDetectionWidget(QWidget* parent, BinaryNinja::Ref<BinaryNinja::BinaryView> bv);
};