-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathInteractionHandler.cs
More file actions
183 lines (158 loc) · 4.79 KB
/
Copy pathInteractionHandler.cs
File metadata and controls
183 lines (158 loc) · 4.79 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
namespace BinaryNinja
{
/// <summary>Handles reports, prompts, and progress requests from the core.</summary>
public abstract partial class InteractionHandler
{
private static readonly object registrationLock = new object();
private static InteractionHandler? registeredHandler;
/// <summary>Registers this handler as the process-wide interaction handler.</summary>
public void Register()
{
lock (InteractionHandler.registrationLock)
{
this.InitializeCallbacks();
BNInteractionHandlerCallbacks callbacks = this.CreateCallbacks();
NativeMethods.BNRegisterInteractionHandler(in callbacks);
InteractionHandler.registeredHandler = this;
}
}
public abstract void ShowPlainTextReport(
BinaryView? view,
string title,
string contents
);
public virtual void ShowMarkdownReport(
BinaryView? view,
string title,
string contents,
string plainText
)
{
if (!string.IsNullOrEmpty(plainText))
{
this.ShowPlainTextReport(view, title, plainText);
}
}
public virtual void ShowHTMLReport(
BinaryView? view,
string title,
string contents,
string plainText
)
{
if (!string.IsNullOrEmpty(plainText))
{
this.ShowPlainTextReport(view, title, plainText);
}
}
public virtual void ShowGraphReport(
BinaryView? view,
string title,
FlowGraph graph
)
{
}
public virtual void ShowReportCollection(
string title,
ReportCollection reports
)
{
}
public abstract string? GetTextLineInput(string prompt, string title);
public virtual long? GetIntegerInput(string prompt, string title)
{
while (true)
{
string? text = this.GetTextLineInput(prompt, title);
if (string.IsNullOrEmpty(text))
{
return null;
}
if (long.TryParse(text, out long value))
{
return value;
}
}
}
public virtual ulong? GetAddressInput(
string prompt,
string title,
BinaryView? view,
ulong currentAddress
)
{
long? value = this.GetIntegerInput(prompt, title);
return value.HasValue ? unchecked((ulong)value.Value) : null;
}
public abstract ulong? GetChoiceInput(
string prompt,
string title,
string[] choices
);
public abstract ulong? GetLargeChoiceInput(
string prompt,
string title,
string[] choices
);
public virtual string? GetOpenFileNameInput(
string prompt,
string extension
)
{
return this.GetTextLineInput(prompt, "Open File");
}
public virtual string? GetSaveFileNameInput(
string prompt,
string extension,
string defaultName
)
{
return this.GetTextLineInput(prompt, "Save File");
}
public virtual string? GetDirectoryNameInput(
string prompt,
string defaultName
)
{
return this.GetTextLineInput(prompt, "Select Directory");
}
public virtual long? GetCheckboxInput(
string prompt,
string title,
long defaultChoice
)
{
return null;
}
public abstract bool GetFormInput(FormInputField[] fields, string title);
public abstract MessageBoxButtonResult ShowMessageBox(
string title,
string text,
MessageBoxButtonSet buttons,
MessageBoxIcon icon
);
public abstract bool OpenUrl(string url);
public virtual bool RunProgressDialog(
string title,
bool canCancel,
ProgressTaskDelegate task
)
{
task(InteractionHandler.ContinueProgress);
return true;
}
private static bool ContinueProgress(ulong current, ulong total)
{
return true;
}
private void LogCallbackException(string name, Exception exception)
{
Core.LogError(
"Unhandled exception in InteractionHandler.{0}: {1}",
name,
exception
);
}
}
}