Skip to content

Commit

Permalink
Fix object settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpotchik committed Dec 14, 2023
1 parent 70062be commit 12170f9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 113 deletions.
44 changes: 21 additions & 23 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -15012,27 +15012,27 @@ namespace BinaryNinja {
\c RegisterGroup method allows for specifying a UI friendly title for use in the Binary Ninja UI. Defining a new setting requires a
unique setting key and a JSON string of property, value pairs. The following table describes the available properties and values.

================== ====================================== ====================================== ======== =======================================================================
Property JSON Data Type Prerequisite Optional {Allowed Values} and Notes
================== ====================================== ====================================== ======== =======================================================================
"title" string None No Concise Setting Title
"type" string None No {"array", "boolean", "number", "object", "string"}
"elementType" string "type" is "array" or type is "object" No {"string"}
"enum" array : {string} "type" is "array" Yes Enumeration definitions
"enumDescriptions" array : {string} "type" is "array" Yes Enumeration descriptions that match "enum" array
"minValue" number "type" is "number" Yes Specify 0 to infer unsigned (default is signed)
"maxValue" number "type" is "number" Yes Values less than or equal to INT_MAX result in a QSpinBox UI element
"precision" number "type" is "number" Yes Specify precision for a QDoubleSpinBox
"default" {array, boolean, number, string, null} None Yes Specify optimal default value
"aliases" array : {string} None Yes Array of deprecated setting key(s)
"description" string None No Detailed setting description
"ignore" array : {string} None Yes {"SettingsUserScope", "SettingsProjectScope", "SettingsResourceScope"}
"message" string None Yes An optional message with additional emphasis
"readOnly" bool None Yes Only enforced by UI elements
"optional" bool None Yes Indicates setting can be null
"hidden" bool "type" is "string" Yes Indicates the UI should conceal the content
"requiresRestart bool None Yes Enable restart notification in the UI upon change
================== ====================================== ====================================== ======== =======================================================================
================== ====================================== ================== ======== =======================================================================
Property JSON Data Type Prerequisite Optional {Allowed Values} and Notes
================== ====================================== ================== ======== =======================================================================
"title" string None No Concise Setting Title
"type" string None No {"array", "boolean", "number", "string"}
"elementType" string "type" is "array" No {"string"}
"enum" array : {string} "type" is "array" Yes Enumeration definitions
"enumDescriptions" array : {string} "type" is "array" Yes Enumeration descriptions that match "enum" array
"minValue" number "type" is "number" Yes Specify 0 to infer unsigned (default is signed)
"maxValue" number "type" is "number" Yes Values less than or equal to INT_MAX result in a QSpinBox UI element
"precision" number "type" is "number" Yes Specify precision for a QDoubleSpinBox
"default" {array, boolean, number, string, null} None Yes Specify optimal default value
"aliases" array : {string} None Yes Array of deprecated setting key(s)
"description" string None No Detailed setting description
"ignore" array : {string} None Yes {"SettingsUserScope", "SettingsProjectScope", "SettingsResourceScope"}
"message" string None Yes An optional message with additional emphasis
"readOnly" bool None Yes Only enforced by UI elements
"optional" bool None Yes Indicates setting can be null
"hidden" bool "type" is "string" Yes Indicates the UI should conceal the content
"requiresRestart bool None Yes Enable restart notification in the UI upon change
================== ====================================== ================== ======== =======================================================================

\note In order to facilitate deterministic analysis results, settings from the <em><tt>default</tt></em> schema that impact analysis are serialized
from Default, User, and Project scope into Resource scope during initial BinaryView analysis. This allows an analysis database to be opened
Expand Down Expand Up @@ -15210,8 +15210,6 @@ namespace BinaryNinja {
BNSettingsScope scope = SettingsAutoScope);
bool Set(const std::string& key, const std::vector<std::string>& value, Ref<BinaryView> view = nullptr,
BNSettingsScope scope = SettingsAutoScope);
bool Set(const std::string& key, const std::map<std::string, std::string>& value, Ref<BinaryView> view = nullptr,
BNSettingsScope scope = SettingsAutoScope);
bool SetJson(const std::string& key, const std::string& value, Ref<BinaryView> view = nullptr,
BNSettingsScope scope = SettingsAutoScope);
};
Expand Down
9 changes: 2 additions & 7 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
#define BN_CURRENT_CORE_ABI_VERSION 43
#define BN_CURRENT_CORE_ABI_VERSION 44

// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
// will require rebuilding. The minimum version is increased when there are
// incompatible changes that break binary compatibility, such as changes to
// existing types or functions.
#define BN_MINIMUM_CORE_ABI_VERSION 43
#define BN_MINIMUM_CORE_ABI_VERSION 44

#ifdef __GNUC__
#ifdef BINARYNINJACORE_LIBRARY
Expand Down Expand Up @@ -3035,7 +3035,6 @@ extern "C"
BINARYNINJACOREAPI void BNFreeString(char* str);
BINARYNINJACOREAPI char** BNAllocStringList(const char** contents, size_t size);
BINARYNINJACOREAPI void BNFreeStringList(char** strs, size_t count);
BINARYNINJACOREAPI void BNFreeStringObject(char*** obj, size_t count);

BINARYNINJACOREAPI void BNShutdown(void);
BINARYNINJACOREAPI bool BNIsShutdownRequested(void);
Expand Down Expand Up @@ -6385,8 +6384,6 @@ extern "C"
BNSettings* settings, const char* key, BNBinaryView* view, BNSettingsScope* scope);
BINARYNINJACOREAPI const char** BNSettingsGetStringList(
BNSettings* settings, const char* key, BNBinaryView* view, BNSettingsScope* scope, size_t* inoutSize);
BINARYNINJACOREAPI const char*** BNSettingsGetStringObject(BNSettings* settings,
const char* key, BNBinaryView* view, BNSettingsScope* scope, size_t* entryCount);

BINARYNINJACOREAPI char* BNSettingsGetJson(
BNSettings* settings, const char* key, BNBinaryView* view, BNSettingsScope* scope);
Expand All @@ -6403,8 +6400,6 @@ extern "C"
BNSettings* settings, BNBinaryView* view, BNSettingsScope scope, const char* key, const char* value);
BINARYNINJACOREAPI bool BNSettingsSetStringList(BNSettings* settings, BNBinaryView* view, BNSettingsScope scope,
const char* key, const char** value, size_t size);
BINARYNINJACOREAPI bool BNSettingsSetStringObject(BNSettings* settings, BNBinaryView* view, BNSettingsScope scope,
const char* key, const char*** value, size_t size);
BINARYNINJACOREAPI bool BNSettingsSetJson(
BNSettings* settings, BNBinaryView* view, BNSettingsScope scope, const char* key, const char* value);

Expand Down
40 changes: 0 additions & 40 deletions python/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import ctypes

from typing import Dict

# Binary Ninja components
from . import _binaryninjacore as core
from .enums import SettingsScope
Expand Down Expand Up @@ -336,18 +334,6 @@ def get_string_list(self, key, view=None):
core.BNFreeStringList(result, length)
return out_list

def get_string_object(self, key, view=None):
if view is not None:
view = view.handle
length = ctypes.c_ulonglong()
result = core.BNSettingsGetStringObject(self.handle, key, view, None, ctypes.byref(length))
assert result is not None, "core.BNSettingsGetStringObject returned None"
out_dict = {}
for i in range(length.value):
out_dict[result[i][0].decode('utf8')] = (result[i][1].decode('utf8'))
core.BNFreeStringObject(result, length)
return out_dict

def get_json(self, key, view=None):
if view is not None:
view = view.handle
Expand Down Expand Up @@ -394,19 +380,6 @@ def get_string_list_with_scope(self, key, view=None, scope=SettingsScope.Setting
core.BNFreeStringList(result, length)
return (out_list, SettingsScope(c_scope.value))

def get_string_object_with_scope(self, key, view=None, scope=SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
c_scope = core.SettingsScopeEnum(scope)
length = ctypes.c_ulonglong()
result = core.BNSettingsGetStringObject(self.handle, key, view, ctypes.byref(c_scope), ctypes.byref(length))
assert result is not None, "core.BNSettingsGetStringObject returned None"
out_dict = {}
for i in range(length.value):
out_dict[result[i][0].decode('utf8')] = (result[i][1].decode('utf8'))
core.BNFreeStringObject(result, length)
return (out_dict, SettingsScope(c_scope.value))

def get_json_with_scope(self, key, view=None, scope=SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
Expand Down Expand Up @@ -444,19 +417,6 @@ def set_string_list(self, key, value, view=None, scope=SettingsScope.SettingsAut
string_list[i] = value[i].encode('charmap')
return core.BNSettingsSetStringList(self.handle, view, scope, key, string_list, length)

def set_string_object(self, key, value: Dict[str, str], view=None, scope=SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
length = ctypes.c_ulonglong()
length.value = len(value)
entry_val = (ctypes.c_char_p * 2)
string_obj = (ctypes.POINTER(ctypes.c_char_p) * len(value))()
for i,entry in enumerate(value.items()):
string_obj[i] = entry_val()
string_obj[i][0] = entry[0].encode('charmap')
string_obj[i][1] = entry[1].encode('charmap')
return core.BNSettingsSetStringObject(self.handle, view, scope, key, string_obj, length)

def set_json(self, key, value, view=None, scope=SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
Expand Down
43 changes: 0 additions & 43 deletions settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,26 +259,6 @@ vector<string> Settings::Get<vector<string>>(const string& key, Ref<BinaryView>
}


template <>
map<string, string> Settings::Get<map<string, string>>(const string& key, Ref<BinaryView> view, BNSettingsScope* scope)
{
// [[key, val], ...]
size_t size = 0;
char*** outBuffer =
(char***)BNSettingsGetStringObject(m_object, key.c_str(), view ? view->GetObject() : nullptr, scope, &size);

map<string, string> result;
for (size_t i = 0; i < size; i++)
{
char** entry = outBuffer[i];
result[entry[0]] = entry[1];
}

BNFreeStringObject(outBuffer, size);
return result;
}


string Settings::GetJson(const string& key, Ref<BinaryView> view, BNSettingsScope* scope)
{
char* tmpStr = BNSettingsGetJson(m_object, key.c_str(), view ? view->GetObject() : nullptr, scope);
Expand Down Expand Up @@ -349,29 +329,6 @@ bool Settings::Set(const string& key, const vector<string>& value, Ref<BinaryVie
}


bool Settings::Set(const string& key, const map<string, string>& value, Ref<BinaryView> view, BNSettingsScope scope)
{
char*** buffer = new char**[value.size()];
if (!buffer)
return false;

size_t i = 0;
for (const auto& entry : value)
{
buffer[i] = new char*[2];
buffer[i][0] = BNAllocString(entry.first.c_str());
buffer[i][1] = BNAllocString(entry.second.c_str());
i++;
}

bool result = BNSettingsSetStringObject(
m_object, view ? view->GetObject() : nullptr, scope, key.c_str(), (const char***)buffer, value.size());

BNFreeStringObject(buffer, value.size());
return result;
}


bool Settings::SetJson(const string& key, const string& value, Ref<BinaryView> view, BNSettingsScope scope)
{
return BNSettingsSetJson(m_object, view ? view->GetObject() : nullptr, scope, key.c_str(), value.c_str());
Expand Down

0 comments on commit 12170f9

Please sign in to comment.