summaryrefslogtreecommitdiff
path: root/examples/uinotification/uinotification.cpp
blob: b7c22bde73de3c4d328ba29e5215dc40a10f462e (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
#include "uinotification.h"
#include "filecontext.h"
#include "viewframe.h"
#include <QMessageBox>

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");
}


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