Skip to content

Commit bd163fb

Browse files
committed
Update the Settings IsEmpty API for querying resources.
1 parent 55b3ce7 commit bd163fb

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

binaryninjaapi.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17125,9 +17125,10 @@ namespace BinaryNinja {
1712517125

1712617126
/*! Determine if the active settings schema is empty
1712717127

17128+
\param scope the settings scope to check, defaults to SettingsAutoScope
1712817129
\return True if the active settings schema is empty, False otherwise
1712917130
*/
17130-
bool IsEmpty();
17131+
bool IsEmpty(BNSettingsScope scope = SettingsAutoScope);
1713117132

1713217133
/*! Retrieve the list of setting identifiers in the active settings schema
1713317134

@@ -17154,6 +17155,7 @@ namespace BinaryNinja {
1715417155
const std::string& contents, Ref<BinaryView> view = nullptr, BNSettingsScope scope = SettingsAutoScope);
1715517156
std::string SerializeSettings(Ref<BinaryView> view = nullptr, BNSettingsScope scope = SettingsAutoScope);
1715617157

17158+
bool IsEmpty(Ref<BinaryView> view, BNSettingsScope scope = SettingsAutoScope);
1715717159
bool Reset(const std::string& key, Ref<BinaryView> view = nullptr, BNSettingsScope scope = SettingsAutoScope);
1715817160
bool ResetAll(
1715917161
Ref<BinaryView> view = nullptr, BNSettingsScope scope = SettingsAutoScope, bool schemaOnly = true);
@@ -17210,6 +17212,7 @@ namespace BinaryNinja {
1721017212
bool DeserializeSettings(const std::string& contents, Ref<Function> func, BNSettingsScope scope = SettingsAutoScope);
1721117213
std::string SerializeSettings(Ref<Function> func, BNSettingsScope scope = SettingsAutoScope);
1721217214

17215+
bool IsEmpty(Ref<Function> func, BNSettingsScope scope = SettingsAutoScope);
1721317216
bool Reset(const std::string& key, Ref<Function> func, BNSettingsScope scope = SettingsAutoScope);
1721417217
bool ResetAll(Ref<Function> func, BNSettingsScope scope = SettingsAutoScope, bool schemaOnly = true);
1721517218

binaryninjacore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
// Current ABI version for linking to the core. This is incremented any time
3838
// there are changes to the API that affect linking, including new functions,
3939
// new types, or modifications to existing functions or types.
40-
#define BN_CURRENT_CORE_ABI_VERSION 112
40+
#define BN_CURRENT_CORE_ABI_VERSION 113
4141

4242
// Minimum ABI version that is supported for loading of plugins. Plugins that
4343
// are linked to an ABI version less than this will not be able to load and
4444
// will require rebuilding. The minimum version is increased when there are
4545
// incompatible changes that break binary compatibility, such as changes to
4646
// existing types or functions.
47-
#define BN_MINIMUM_CORE_ABI_VERSION 100
47+
#define BN_MINIMUM_CORE_ABI_VERSION 113
4848

4949
#ifdef __GNUC__
5050
#ifdef BINARYNINJACORE_LIBRARY
@@ -7429,7 +7429,7 @@ extern "C"
74297429
BINARYNINJACOREAPI bool BNSettingsRegisterGroup(BNSettings* settings, const char* group, const char* title);
74307430
BINARYNINJACOREAPI bool BNSettingsRegisterSetting(BNSettings* settings, const char* key, const char* properties);
74317431
BINARYNINJACOREAPI bool BNSettingsContains(BNSettings* settings, const char* key);
7432-
BINARYNINJACOREAPI bool BNSettingsIsEmpty(BNSettings* settings);
7432+
BINARYNINJACOREAPI bool BNSettingsIsEmpty(BNSettings* settings, BNBinaryView* view, BNFunction* func, BNSettingsScope scope);
74337433
BINARYNINJACOREAPI const char** BNSettingsKeysList(BNSettings* settings, size_t* inoutSize);
74347434
BINARYNINJACOREAPI char* BNSettingsQueryPropertyString(BNSettings* settings, const char* key, const char* property);
74357435
BINARYNINJACOREAPI const char** BNSettingsQueryPropertyStringList(BNSettings* settings, const char* key, const char* property, size_t* inoutSize);

python/settings.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,25 @@ def contains(self, key: str) -> bool:
244244
"""
245245
return core.BNSettingsContains(self.handle, key)
246246

247-
def is_empty(self) -> bool:
247+
def is_empty(self, resource: Optional[Union['binaryview.BinaryView', 'function.Function']] = None, scope: 'SettingsScope' = SettingsScope.SettingsAutoScope) -> bool:
248248
"""
249249
``is_empty`` determine if the active settings schema is empty
250250
251+
:param resource: a BinaryView or Function object to check for emptiness
252+
:param scope: the SettingsScope to check for emptiness
251253
:return: True if the active settings schema is empty, False otherwise
252254
:rtype: bool
253255
"""
254-
return core.BNSettingsIsEmpty(self.handle)
256+
view_handle = None
257+
func_handle = None
258+
if resource is not None:
259+
if isinstance(resource, binaryview.BinaryView):
260+
view_handle = resource.handle
261+
elif isinstance(resource, function.Function):
262+
func_handle = resource.handle
263+
else:
264+
raise TypeError("Expected resource to be either a BinaryView or a Function.")
265+
return core.BNSettingsIsEmpty(self.handle, view_handle, func_handle, scope)
255266

256267
def keys(self) -> List[str]:
257268
"""

settings.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ bool Settings::Contains(const string& key)
5757
}
5858

5959

60-
bool Settings::IsEmpty()
60+
bool Settings::IsEmpty(BNSettingsScope scope)
6161
{
62-
return BNSettingsIsEmpty(m_object);
62+
return BNSettingsIsEmpty(m_object, nullptr, nullptr, scope);
6363
}
6464

6565

@@ -202,6 +202,12 @@ string Settings::SerializeSettings(Ref<BinaryView> view, BNSettingsScope scope)
202202
}
203203

204204

205+
bool Settings::IsEmpty(Ref<BinaryView> view, BNSettingsScope scope)
206+
{
207+
return BNSettingsIsEmpty(m_object, view ? view->GetObject() : nullptr, nullptr, scope);
208+
}
209+
210+
205211
bool Settings::Reset(const string& key, Ref<BinaryView> view, BNSettingsScope scope)
206212
{
207213
return BNSettingsReset(m_object, key.c_str(), view ? view->GetObject() : nullptr, nullptr, scope);
@@ -360,6 +366,12 @@ string Settings::SerializeSettings(Ref<Function> func, BNSettingsScope scope)
360366
}
361367

362368

369+
bool Settings::IsEmpty(Ref<Function> func, BNSettingsScope scope)
370+
{
371+
return BNSettingsIsEmpty(m_object, nullptr, func ? func->GetObject() : nullptr, scope);
372+
}
373+
374+
363375
bool Settings::Reset(const string& key, Ref<Function> func, BNSettingsScope scope)
364376
{
365377
return BNSettingsReset(m_object, key.c_str(), nullptr, func ? func->GetObject() : nullptr, scope);

0 commit comments

Comments
 (0)