summaryrefslogtreecommitdiff
path: root/plugins/warp/ui/shared/processordialog.h
blob: 3f69601d37cdc8ff46759dbf20acfe3adbeb5e3f (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#pragma once

#include <QDialog>
#include <QStackedWidget>
#include <QComboBox>
#include <QProgressBar>
#include <QThread>
#include <QTimer>
#include <QMenu>
#include <QSpinBox>
#include <QElapsedTimer>
#include <utility>

#include "binaryninjaapi.h"
#include "warp.h"
#include "file.h"

// TODO: Both of these are bothersome but I don't really want to do a ID lookup.
Q_DECLARE_METATYPE(BinaryNinja::Ref<BinaryNinja::Project>)
Q_DECLARE_METATYPE(BinaryNinja::Ref<BinaryNinja::ProjectFile>)

// Worker to run the processor
class WarpProcessorWorker : public QThread
{
	Q_OBJECT

	std::shared_ptr<Warp::Processor> m_processor;

public:
	WarpProcessorWorker(std::shared_ptr<Warp::Processor> processor, QObject* parent = nullptr) :
		QThread(parent), m_processor(std::move(processor))
	{}

	void run() override
	{
		Warp::Ref<Warp::File> file = m_processor->Start();
		emit finishedProcessing(file);
	}

signals:
	void finishedProcessing(Warp::Ref<Warp::File> file);
};

class ProcessorDialog : public QDialog
{
	Q_OBJECT

public:
	explicit ProcessorDialog(QWidget* parent = nullptr);
	~ProcessorDialog() override;

	void onAddBinaryView(BinaryNinja::Ref<BinaryNinja::BinaryView> view);
	void onAddProjectFiles();

private slots:
	void onStartProcessing();
	void onProcessingFinished(Warp::Ref<Warp::File> file);
	void onCancelProcessing();
	void onUpdateState();
	void onSaveToFile();
	void onCommit();
	void onAddPath();
	void onAddDirectory();
	void onRemoveItem();
	void onSearchItems();
	void onAddEntryMenu();
	void showContextMenu(const QPoint& pos);

private:
	void addAddActionsToMenu(QMenu* menu);
	void addPathRecursive(const QString& path);
	void addSinglePath(const QString& path);
	struct ToProcessEntry
	{
		enum Type
		{
			ViewMode,
			PathMode,
			ProjectMode,
			ProjectFileMode
		} type;
		BinaryNinja::Ref<BinaryNinja::BinaryView> view;
		std::string path;
		BinaryNinja::Ref<BinaryNinja::Project> project;
		BinaryNinja::Ref<BinaryNinja::ProjectFile> projectFile;
		QString displayName;
	};

	Warp::Ref<Warp::File> m_file;
	std::shared_ptr<Warp::Processor> m_processor;
	std::vector<ToProcessEntry> m_toProcess;

	enum Page
	{
		ConfigurationPage = 0,
		ProcessingPage = 1,
		ResultsPage = 2
	};

	QStackedWidget* m_stack;

	// Page 1: Configuration
	QLineEdit* m_entrySearch;
	QPushButton* m_addButton;
	QListWidget* m_entryList;

	// Global Config
	QComboBox* m_includedDataCombo;
	QComboBox* m_includedFunctionsCombo;
	QSpinBox* m_workerCountSpinBox;
	QPushButton* m_processButton;

	// Page 2: Processing
	QLabel* m_processingLabel;
	QProgressBar* m_progressBar;
	QListWidget* m_stateList;
	QPushButton* m_cancelButton;
	QTimer* m_updateTimer;

	// Page 3: Results
	FileWidget* m_fileWidget;
	QPushButton* m_saveButton;
	QLabel* m_elapsedLabel;
	QPushButton* m_commitButton;

	QElapsedTimer m_processTimer;
};