summaryrefslogtreecommitdiff
path: root/examples/uinotification/uinotification.cpp
blob: 5072d98ab798c6012150cea7ba5cc5e04da4e514 (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
128
#include "inttypes.h"
#include "uinotification.h"
#include "filecontext.h"
#include "viewframe.h"
#include <QtWidgets/QMessageBox>
#include <QtCore/QFileInfo>

using namespace BinaryNinja;

NotificationListener* NotificationListener::m_instance = nullptr;

void NotificationListener::init()
{
	m_instance = new NotificationListener;
	UIContext::registerNotification(m_instance);
}


void NotificationListener::OnContextOpen(UIContext* context)
{
	LogInfo("OnContextOpen");
}


void NotificationListener::OnContextClose(UIContext* context)
{
	LogInfo("OnContextClose");
}


bool NotificationListener::OnBeforeOpenDatabase(UIContext* context, FileMetadataRef metadata)
{
	LogInfo("OnBeforeOpenDatabase");
	return QMessageBox::question(context->mainWindow(), "OnBeforeOpenDatabase", "OnBeforeOpenDatabase")
	       == QMessageBox::StandardButton::Yes;
}


bool NotificationListener::OnAfterOpenDatabase(UIContext* context, FileMetadataRef metadata, BinaryViewRef data)
{
	LogInfo("OnAfterOpenDatabase");
	return QMessageBox::question(context->mainWindow(), "OnAfterOpenDatabase", "OnAfterOpenDatabase")
	       == QMessageBox::StandardButton::Yes;
}


bool NotificationListener::OnBeforeOpenFile(UIContext* context, FileContext* file)
{
	LogInfo("OnBeforeOpenFile");
	return QMessageBox::question(context->mainWindow(), "OnBeforeOpenFile", "OnBeforeOpenFile")
	       == QMessageBox::StandardButton::Yes;
}


void NotificationListener::OnAfterOpenFile(UIContext* context, FileContext* file, ViewFrame* frame)
{
	LogInfo("OnAfterOpenFile");
}


bool NotificationListener::OnBeforeSaveFile(UIContext* context, FileContext* file, ViewFrame* frame)
{
	LogInfo("OnBeforeSaveFile");
	return QMessageBox::question(context->mainWindow(), "OnBeforeSaveFile", "OnBeforeSaveFile")
	       == QMessageBox::StandardButton::Yes;
}


void NotificationListener::OnAfterSaveFile(UIContext* context, FileContext* file, ViewFrame* frame)
{
	LogInfo("OnAfterSaveFile");
}


bool NotificationListener::OnBeforeCloseFile(UIContext* context, FileContext* file, ViewFrame* frame)
{
	LogInfo("OnBeforeCloseFile");
	return QMessageBox::question(context->mainWindow(), "OnBeforeCloseFile", "OnBeforeCloseFile")
	       == QMessageBox::StandardButton::Yes;
}


void NotificationListener::OnAfterCloseFile(UIContext* context, FileContext* file, ViewFrame* frame)
{
	LogInfo("OnAfterCloseFile");
}


void NotificationListener::OnViewChange(UIContext* context, ViewFrame* frame, const QString& type)
{
	LogInfo("OnViewChange");
}


void NotificationListener::OnAddressChange(
    UIContext* context, ViewFrame* frame, View* view, const ViewLocation& location)
{
	LogInfo("OnAddressChange: 0x%" PRIx64, location.getOffset());
}


bool NotificationListener::GetNameForFile(UIContext* context, FileContext* file, QString& name)
{
	LogInfo("GetNameForFile");
	name = file->getFilename() + " Foo";
	return true;
}


bool NotificationListener::GetNameForPath(UIContext* context, const QString& path, QString& name)
{
	QFileInfo info(path);
	LogInfo("GetNameForPath");
	name = info.baseName() + " Foo";
	return true;
}


extern "C"
{
	BN_DECLARE_UI_ABI_VERSION

	BINARYNINJAPLUGIN bool UIPluginInit()
	{
		NotificationListener::init();
		return true;
	}
}