forked from Vector35/binaryninja-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pluginmanager.cpp
344 lines (262 loc) · 6.55 KB
/
pluginmanager.cpp
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#include "binaryninjaapi.h"
using namespace BinaryNinja;
using namespace std;
#define RETURN_STRING(s) \
do \
{ \
char* contents = (char*)(s); \
string result(contents); \
BNFreeString(contents); \
return result; \
} while (0)
RepoPlugin::RepoPlugin(BNRepoPlugin* plugin)
{
m_object = plugin;
}
string RepoPlugin::GetPath() const
{
RETURN_STRING(BNPluginGetPath(m_object));
}
string RepoPlugin::GetSubdir() const
{
RETURN_STRING(BNPluginGetSubdir(m_object));
}
string RepoPlugin::GetDependencies() const
{
RETURN_STRING(BNPluginGetDependencies(m_object));
}
bool RepoPlugin::IsInstalled() const
{
return BNPluginIsInstalled(m_object);
}
bool RepoPlugin::IsEnabled() const
{
return BNPluginIsEnabled(m_object);
}
PluginStatus RepoPlugin::GetPluginStatus() const
{
return BNPluginGetPluginStatus(m_object);
}
vector<string> RepoPlugin::GetApis() const
{
vector<string> result;
size_t count = 0;
char** apis = BNPluginGetApis(m_object, &count);
result.reserve(count);
for (size_t i = 0; i < count; i++)
result.push_back(apis[i]);
BNFreeStringList(apis, count);
return result;
}
string RepoPlugin::GetAuthor() const
{
RETURN_STRING(BNPluginGetAuthor(m_object));
}
string RepoPlugin::GetDescription() const
{
RETURN_STRING(BNPluginGetDescription(m_object));
}
string RepoPlugin::GetLicenseText() const
{
RETURN_STRING(BNPluginGetLicenseText(m_object));
}
string RepoPlugin::GetLongdescription() const
{
RETURN_STRING(BNPluginGetLongdescription(m_object));
}
BNVersionInfo RepoPlugin::GetMinimumVersionInfo() const
{
return BNPluginGetMinimumVersionInfo(m_object);
}
BNVersionInfo RepoPlugin::GetMaximumVersionInfo() const
{
return BNPluginGetMaximumVersionInfo(m_object);
}
string RepoPlugin::GetName() const
{
RETURN_STRING(BNPluginGetName(m_object));
}
vector<PluginType> RepoPlugin::GetPluginTypes() const
{
size_t count;
BNPluginType* pluginTypesPtr = BNPluginGetPluginTypes(m_object, &count);
vector<PluginType> pluginTypes;
for (size_t i = 0; i < count; i++)
{
pluginTypes.push_back((PluginType)pluginTypesPtr[i]);
}
BNFreePluginTypes(pluginTypesPtr);
return pluginTypes;
}
string RepoPlugin::GetProjectUrl() const
{
RETURN_STRING(BNPluginGetProjectUrl(m_object));
}
string RepoPlugin::GetPackageUrl() const
{
RETURN_STRING(BNPluginGetPackageUrl(m_object));
}
string RepoPlugin::GetAuthorUrl() const
{
RETURN_STRING(BNPluginGetAuthorUrl(m_object));
}
string RepoPlugin::GetVersion() const
{
RETURN_STRING(BNPluginGetVersion(m_object));
}
string RepoPlugin::GetCommit() const
{
RETURN_STRING(BNPluginGetCommit(m_object));
}
bool RepoPlugin::IsViewOnly() const
{
return BNPluginGetViewOnly(m_object);
}
string RepoPlugin::GetRepository() const
{
RETURN_STRING(BNPluginGetRepository(m_object));
}
vector<string> RepoPlugin::GetInstallPlatforms() const
{
vector<string> result;
size_t count = 0;
char** platforms = BNPluginGetPlatforms(m_object, &count);
for (size_t i = 0; i < count; i++)
result.push_back(platforms[i]);
BNFreeStringList(platforms, count);
return result;
}
bool RepoPlugin::IsBeingDeleted() const
{
return BNPluginIsBeingDeleted(m_object);
}
bool RepoPlugin::IsBeingUpdated() const
{
return BNPluginIsBeingUpdated(m_object);
}
bool RepoPlugin::IsRunning() const
{
return BNPluginIsRunning(m_object);
}
bool RepoPlugin::IsUpdatePending() const
{
return BNPluginIsUpdatePending(m_object);
}
bool RepoPlugin::IsDisablePending() const
{
return BNPluginIsDisablePending(m_object);
}
bool RepoPlugin::IsDeletePending() const
{
return BNPluginIsDeletePending(m_object);
}
bool RepoPlugin::IsUpdateAvailable() const
{
return BNPluginIsUpdateAvailable(m_object);
}
bool RepoPlugin::AreDependenciesBeingInstalled() const
{
return BNPluginAreDependenciesBeingInstalled(m_object);
}
uint64_t RepoPlugin::GetLastUpdate()
{
return BNPluginGetLastUpdate(m_object);
}
string RepoPlugin::GetProjectData()
{
RETURN_STRING(BNPluginGetProjectData(m_object));
}
bool RepoPlugin::Uninstall()
{
return BNPluginUninstall(m_object);
}
bool RepoPlugin::Install()
{
return BNPluginInstall(m_object);
}
bool RepoPlugin::InstallDependencies()
{
return BNPluginInstallDependencies(m_object);
}
bool RepoPlugin::Enable(bool force)
{
return BNPluginEnable(m_object, force);
}
bool RepoPlugin::Update()
{
return BNPluginUpdate(m_object);
}
bool RepoPlugin::Disable()
{
return BNPluginDisable(m_object);
}
Repository::Repository(BNRepository* r)
{
m_object = r;
}
string Repository::GetUrl() const
{
RETURN_STRING(BNRepositoryGetUrl(m_object));
}
string Repository::GetRepoPath() const
{
RETURN_STRING(BNRepositoryGetRepoPath(m_object));
}
vector<Ref<RepoPlugin>> Repository::GetPlugins() const
{
vector<Ref<RepoPlugin>> plugins;
size_t count = 0;
BNRepoPlugin** pluginsPtr = BNRepositoryGetPlugins(m_object, &count);
plugins.reserve(count);
for (size_t i = 0; i < count; i++)
plugins.push_back(new RepoPlugin(BNNewPluginReference(pluginsPtr[i])));
BNFreeRepositoryPluginList(pluginsPtr);
return plugins;
}
Ref<RepoPlugin> Repository::GetPluginByPath(const string& pluginPath)
{
return new RepoPlugin(BNNewPluginReference(BNRepositoryGetPluginByPath(m_object, pluginPath.c_str())));
}
string Repository::GetFullPath() const
{
RETURN_STRING(BNRepositoryGetPluginsPath(m_object));
}
RepositoryManager::RepositoryManager(const string& enabledPluginsPath)
{
m_object = BNCreateRepositoryManager(enabledPluginsPath.c_str());
}
RepositoryManager::RepositoryManager(BNRepositoryManager* mgr)
{
m_object = mgr;
}
RepositoryManager::RepositoryManager()
{
m_object = BNGetRepositoryManager();
}
bool RepositoryManager::CheckForUpdates()
{
return BNRepositoryManagerCheckForUpdates(m_object);
}
vector<Ref<Repository>> RepositoryManager::GetRepositories()
{
vector<Ref<Repository>> repos;
size_t count = 0;
BNRepository** reposPtr = BNRepositoryManagerGetRepositories(m_object, &count);
for (size_t i = 0; i < count; i++)
repos.push_back(new Repository(BNNewRepositoryReference(reposPtr[i])));
BNFreeRepositoryManagerRepositoriesList(reposPtr);
return repos;
}
bool RepositoryManager::AddRepository(const std::string& url,
const std::string& repoPath) // Relative path within the repositories directory
{
return BNRepositoryManagerAddRepository(m_object, url.c_str(), repoPath.c_str());
}
Ref<Repository> RepositoryManager::GetRepositoryByPath(const std::string& repoPath)
{
return new Repository(BNNewRepositoryReference(BNRepositoryGetRepositoryByPath(m_object, repoPath.c_str())));
}
Ref<Repository> RepositoryManager::GetDefaultRepository()
{
return new Repository(BNNewRepositoryReference(BNRepositoryManagerGetDefaultRepository(m_object)));
}