forked from Vector35/binaryninja-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pluginmanager.cpp
220 lines (184 loc) · 4.77 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
#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));
}
bool RepoPlugin::IsInstalled() const
{
return BNPluginIsInstalled(m_object);
}
void RepoPlugin::SetEnabled(bool enabled)
{
return BNPluginSetEnabled(m_object, enabled);
}
bool RepoPlugin::IsEnabled() const
{
return BNPluginIsEnabled(m_object);
}
PluginUpdateStatus RepoPlugin::GetPluginUpdateStatus() const
{
return BNPluginGetPluginUpdateStatus(m_object);
}
string RepoPlugin::GetApi() const
{
RETURN_STRING(BNPluginGetApi(m_object));
}
string RepoPlugin::GetAuthor() const
{
RETURN_STRING(BNPluginGetAuthor(m_object));
}
string RepoPlugin::GetDescription() const
{
RETURN_STRING(BNPluginGetDescription(m_object));
}
string RepoPlugin::GetLicense() const
{
RETURN_STRING(BNPluginGetLicense(m_object));
}
string RepoPlugin::GetLicenseText() const
{
RETURN_STRING(BNPluginGetLicenseText(m_object));
}
string RepoPlugin::GetLongdescription() const
{
RETURN_STRING(BNPluginGetLongdescription(m_object));
}
string RepoPlugin::GetMinimimVersions() const
{
RETURN_STRING(BNPluginGetMinimimVersions(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::GetUrl() const
{
RETURN_STRING(BNPluginGetUrl(m_object));
}
string RepoPlugin::GetVersion() const
{
RETURN_STRING(BNPluginGetVersion(m_object));
}
Repository::Repository(BNRepository* r)
{
m_object = r;
}
Repository::~Repository()
{
BNFreeRepository(m_object);
}
string Repository::GetUrl() const
{
RETURN_STRING(BNRepositoryGetUrl(m_object));
}
string Repository::GetRepoPath() const
{
RETURN_STRING(BNRepositoryGetRepoPath(m_object));
}
string Repository::GetLocalReference() const
{
RETURN_STRING(BNRepositoryGetLocalReference(m_object));
}
string Repository::GetRemoteReference() const
{
RETURN_STRING(BNRepositoryGetRemoteReference(m_object));
}
vector<Ref<RepoPlugin>> Repository::GetPlugins() const
{
vector<Ref<RepoPlugin>> plugins;
size_t count = 0;
BNRepoPlugin** pluginsPtr = BNRepositoryGetPlugins(m_object, &count);
for (size_t i = 0; i < count; i++)
plugins.push_back(new RepoPlugin(BNNewPluginReference(pluginsPtr[i])));
BNFreeRepositoryPluginList(pluginsPtr);
return plugins;
}
bool Repository::IsInitialized() const
{
return BNRepositoryIsInitialized(m_object);
}
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_core(false)
{
m_object = BNCreateRepositoryManager(enabledPluginsPath.c_str());
}
RepositoryManager::RepositoryManager(BNRepositoryManager* mgr)
:m_core(false)
{
m_object = mgr;
}
RepositoryManager::RepositoryManager()
:m_core(true)
{
m_object = BNGetRepositoryManager();
}
RepositoryManager::~RepositoryManager()
{
if (!m_core)
BNFreeRepositoryManager(m_object);
}
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
const std::string& localReference,
const std::string& remoteReference)
{
return BNRepositoryManagerAddRepository(m_object,
url.c_str(),
repoPath.c_str(),
localReference.c_str(),
remoteReference.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)));
}