summaryrefslogtreecommitdiff
path: root/examples/triage/headers.h
blob: a834840149e10d9d8a7fd808ee728049c60b9972 (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
93
94
95
96
97
98
99
#pragma once

#include <QtWidgets/QLabel>
#include <QtWidgets/QWidget>
#include <functional>
#include "uitypes.h"


class NavigationLabel : public QLabel
{
	std::function<void()> m_func;

  public:
	NavigationLabel(const QString& text, QColor color, const std::function<void()>& func);

  protected:
	virtual void mousePressEvent(QMouseEvent* event) override;
};


class NavigationAddressLabel : public NavigationLabel
{
	uint64_t m_address;

	void clickEvent();

  public:
	NavigationAddressLabel(const QString& text);
};


class NavigationCodeLabel : public NavigationLabel
{
	uint64_t m_address;

	void clickEvent();

  public:
	NavigationCodeLabel(const QString& text);
};


enum HeaderFieldType
{
	TextHeaderField,
	AddressHeaderField,
	CodeHeaderField
};


struct HeaderField
{
	QString title;
	std::vector<QString> values;
	HeaderFieldType type;
};


class Headers
{
	std::vector<HeaderField> m_fields;
	size_t m_columns, m_rowsPerColumn;

  public:
	Headers();
	void AddField(const QString& title, const QString& value, HeaderFieldType type = TextHeaderField);
	void AddField(const QString& title, const std::vector<QString>& values, HeaderFieldType type = TextHeaderField);
	const std::vector<HeaderField>& GetFields() const { return m_fields; }
	void SetColumns(size_t cols) { m_columns = cols; }
	void SetRowsPerColumn(size_t rows) { m_rowsPerColumn = rows; }
	size_t GetColumns() const { return m_columns; }
	size_t GetRowsPerColumn() const { return m_rowsPerColumn; }
};


class GenericHeaders : public Headers
{
  public:
	GenericHeaders(BinaryViewRef data);
};


class PEHeaders : public Headers
{
	uint64_t GetValueOfStructMember(
	    BinaryViewRef data, const std::string& structName, uint64_t structStart, const std::string& fieldName);
	uint64_t GetAddressAfterStruct(BinaryViewRef data, const std::string& structName, uint64_t structStart);
	QString GetNameOfEnumerationMember(BinaryViewRef data, const std::string& enumName, uint64_t value);

  public:
	PEHeaders(BinaryViewRef data);
};


class HeaderWidget : public QWidget
{
  public:
	HeaderWidget(QWidget* parent, const Headers& headers);
};