forked from Vector35/binaryninja-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.cpp
More file actions
174 lines (144 loc) · 4.97 KB
/
settings.cpp
File metadata and controls
174 lines (144 loc) · 4.97 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
#include "binaryninjaapi.h"
#include <string.h>
using namespace BinaryNinja;
using namespace std;
bool Setting::GetBool(const std::string& pluginName, const std::string& name, bool defaultValue)
{
return BNSettingGetBool(pluginName.c_str(), name.c_str(), defaultValue);
}
int64_t Setting::GetInteger(const std::string& pluginName, const std::string& name, int64_t defaultValue)
{
return BNSettingGetInteger(pluginName.c_str(), name.c_str(), defaultValue);
}
std::string Setting::GetString(const std::string& pluginName, const std::string& name, const std::string& defaultValue)
{
return BNSettingGetString(pluginName.c_str(), name.c_str(), defaultValue.c_str());
}
double Setting::GetDouble(const std::string& pluginName, const std::string& name, double defaultValue)
{
return BNSettingGetDouble(pluginName.c_str(), name.c_str(), defaultValue);
}
std::vector<int64_t> Setting::GetIntegerList(const std::string& pluginName,
const std::string& name,
const std::vector<int64_t>& defaultValue)
{
int64_t* buffer = new int64_t[defaultValue.size()];
memcpy(&buffer[0], &defaultValue[0], sizeof(int64_t) * defaultValue.size());
size_t size = defaultValue.size();
int64_t* outBuffer = BNSettingGetIntegerList(pluginName.c_str(), name.c_str(), buffer, &size);
delete[] buffer;
vector<int64_t> out(outBuffer, outBuffer + size);
BNFreeSettingIntegerList(outBuffer);
return out;
}
std::vector<std::string> Setting::GetStringList(const std::string& pluginName,
const std::string& name,
const std::vector<std::string>& defaultValue)
{
char** buffer = new char*[defaultValue.size()];
for (size_t i = 0; i < defaultValue.size(); i++)
buffer[i] = BNAllocString(defaultValue[i].c_str());
size_t size = defaultValue.size();
char** outBuffer = (char**)BNSettingGetStringList(pluginName.c_str(), name.c_str(), (const char**)buffer, &size);
vector<string> result;
for (size_t i = 0; i < size; i++)
result.push_back(string(outBuffer[i]));
for (size_t i = 0; i < defaultValue.size(); i++)
BNFreeString(buffer[i]);
delete[] buffer;
BNFreeStringList(outBuffer, size);
return result;
}
bool Setting::IsPresent(const std::string& pluginName, const std::string& name)
{
return BNSettingIsPresent(pluginName.c_str(), name.c_str());
}
bool Setting::IsBool(const std::string& pluginName, const std::string& name)
{
return BNSettingIsBool(pluginName.c_str(), name.c_str());
}
bool Setting::IsInteger(const std::string& pluginName, const std::string& name)
{
return BNSettingIsInteger(pluginName.c_str(), name.c_str());
}
bool Setting::IsString(const std::string& pluginName, const std::string& name)
{
return BNSettingIsString(pluginName.c_str(), name.c_str());
}
bool Setting::IsIntegerList(const std::string& pluginName, const std::string& name)
{
return BNSettingIsIntegerList(pluginName.c_str(), name.c_str());
}
bool Setting::IsStringList(const std::string& pluginName, const std::string& name)
{
return BNSettingIsStringList(pluginName.c_str(), name.c_str());
}
bool Setting::IsDouble(const std::string& pluginName, const std::string& name)
{
return BNSettingIsDouble(pluginName.c_str(), name.c_str());
}
bool Setting::Set(const std::string& settingGroup,
const std::string& name,
bool value,
bool autoFlush)
{
return BNSettingSetBool(settingGroup.c_str(), name.c_str(), value, autoFlush);
}
bool Setting::Set(const std::string& settingGroup,
const std::string& name,
int64_t value,
bool autoFlush)
{
return BNSettingSetInteger(settingGroup.c_str(), name.c_str(), value, autoFlush);
}
bool Setting::Set(const std::string& settingGroup,
const std::string& name,
const std::string& value,
bool autoFlush)
{
return BNSettingSetString(settingGroup.c_str(), name.c_str(), value.c_str(), autoFlush);
}
bool Setting::Set(const std::string& settingGroup,
const std::string& name,
const std::vector<int64_t>& value,
bool autoFlush)
{
return BNSettingSetIntegerList(settingGroup.c_str(), name.c_str(), &value[0], value.size(), autoFlush);
}
bool Setting::Set(const std::string& settingGroup,
const std::string& name,
const std::vector<std::string>& value,
bool autoFlush)
{
char** buffer = new char*[value.size()];
if (!buffer)
return false;
for (size_t i = 0; i < value.size(); i++)
buffer[i] = BNAllocString(value[i].c_str());
bool result = BNSettingSetStringList(settingGroup.c_str(),
name.c_str(),
(const char**)buffer,
value.size(),
autoFlush);
BNFreeStringList(buffer, value.size());
return result;
}
bool Setting::Set(const std::string& settingGroup,
const std::string& name,
double value,
bool autoFlush)
{
return BNSettingSetDouble(settingGroup.c_str(), name.c_str(), value, autoFlush);
}
bool Setting::RemoveSettingGroup(const std::string& settingGroup, bool autoFlush)
{
return BNSettingRemoveSettingGroup(settingGroup.c_str(), autoFlush);
}
bool Setting::RemoveSetting(const std::string& settingGroup, const std::string& setting, bool autoFlush)
{
return BNSettingRemoveSetting(settingGroup.c_str(), setting.c_str(), autoFlush);
}
bool Setting::FlushSettings()
{
return BNSettingFlushSettings();
}