summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2020-07-10 14:07:48 -0400
committerJosh Ferrell <josh@vector35.com>2020-07-10 14:07:48 -0400
commitde77d8ad64a3ed39e362f4fa979132d47d5a056c (patch)
tree0966d00826570f9c51ead0ad5eab278c09d2301b /python
parent045c1a93d032e96ef5647db51803efcd08b6551b (diff)
Add save settings
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py14
-rw-r--r--python/filemetadata.py34
2 files changed, 35 insertions, 13 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 3e1478be..1e7f7a44 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -32,7 +32,7 @@ from collections import OrderedDict
# Binary Ninja components
from binaryninja import _binaryninjacore as core
from binaryninja.enums import (AnalysisState, SymbolType, InstructionTextTokenType,
- Endianness, ModificationStatus, StringType, SegmentFlag, SectionSemantics, FindFlag, TypeClass)
+ Endianness, ModificationStatus, StringType, SegmentFlag, SectionSemantics, FindFlag, TypeClass, SaveOption)
import binaryninja
from binaryninja import associateddatastore # required for _BinaryViewAssociatedDataStore
from binaryninja import log
@@ -2480,30 +2480,30 @@ class BinaryView(object):
"""
return False
- def create_database(self, filename, progress_func=None, clean=False):
+ def create_database(self, filename, progress_func=None, settings=None):
"""
``create_database`` writes the current database (.bndb) file out to the specified file.
:param str filename: path and filename to write the bndb to, this string `should` have ".bndb" appended to it.
:param callback progress_func: optional function to be called with the current progress and total count.
- :param bool clean: optional argument to determine if undo data is saved in the database.
+ :param SaveSettings settings: optional argument for special save options.
:return: true on success, false on failure
:rtype: bool
"""
- return self._file.create_database(filename, progress_func, clean)
+ return self._file.create_database(filename, progress_func, settings)
- def save_auto_snapshot(self, progress_func=None, clean=False):
+ def save_auto_snapshot(self, progress_func=None, settings=None):
"""
``save_auto_snapshot`` saves the current database to the already created file.
.. note:: :py:meth:`create_database` should have been called prior to executing this method
:param callback progress_func: optional function to be called with the current progress and total count.
- :param bool clean: optional argument to determine if undo data is saved in the database.
+ :param SaveSettings settings: optional argument for special save options.
:return: True if it successfully saved the snapshot, False otherwise
:rtype: bool
"""
- return self._file.save_auto_snapshot(progress_func, clean)
+ return self._file.save_auto_snapshot(progress_func, settings)
def get_view_of_type(self, name):
"""
diff --git a/python/filemetadata.py b/python/filemetadata.py
index 937686b7..2b50f23b 100644
--- a/python/filemetadata.py
+++ b/python/filemetadata.py
@@ -27,6 +27,7 @@ import binaryninja
from binaryninja import _binaryninjacore as core
from binaryninja import associateddatastore #required for _FileMetadataAssociatedDataStore
from binaryninja import log
+from binaryninja.enums import SaveOption
class NavigationHandler(object):
def _register(self, handle):
@@ -60,6 +61,27 @@ class NavigationHandler(object):
return False
+class SaveSettings(object):
+ def __init__(self, handle = None):
+ if handle is None:
+ self.handle = core.BNCreateSaveSettings()
+ else:
+ self.handle = handle
+
+ def __del__(self):
+ core.BNFreeSaveSettings(self.handle)
+
+ def is_option_set(self, option):
+ if isinstance(option, str):
+ option = SaveOption[option]
+ return core.BNIsSaveSettingsOptionSet(self.handle, option)
+
+ def set_option(self, option, state = True):
+ if isinstance(option, str):
+ option = SaveOption[option]
+ core.BNSetSaveSettingsOption(self.handle, option, state)
+
+
class _FileMetadataAssociatedDataStore(associateddatastore._AssociatedDataStore):
_defaults = {}
@@ -331,13 +353,13 @@ class FileMetadata(object):
def navigate(self, view, offset):
return core.BNNavigate(self.handle, str(view), offset)
- def create_database(self, filename, progress_func = None, clean = False):
+ def create_database(self, filename, progress_func = None, settings = None):
if progress_func is None:
- return core.BNCreateDatabase(self.raw.handle, str(filename), clean)
+ return core.BNCreateDatabase(self.raw.handle, str(filename), settings)
else:
return core.BNCreateDatabaseWithProgress(self.raw.handle, str(filename), None,
ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_ulonglong)(
- lambda ctxt, cur, total: progress_func(cur, total)), clean)
+ lambda ctxt, cur, total: progress_func(cur, total)), settings)
def open_existing_database(self, filename, progress_func = None):
if progress_func is None:
@@ -356,13 +378,13 @@ class FileMetadata(object):
return None
return binaryninja.binaryview.BinaryView(file_metadata = self, handle = view)
- def save_auto_snapshot(self, progress_func = None, clean = False):
+ def save_auto_snapshot(self, progress_func = None, settings = None):
if progress_func is None:
- return core.BNSaveAutoSnapshot(self.raw.handle, clean)
+ return core.BNSaveAutoSnapshot(self.raw.handle, settings)
else:
return core.BNSaveAutoSnapshotWithProgress(self.raw.handle, None,
ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_ulonglong)(
- lambda ctxt, cur, total: progress_func(cur, total)), clean)
+ lambda ctxt, cur, total: progress_func(cur, total)), settings)
def merge_user_analysis(self, path, progress_func = None):
return core.BNMergeUserAnalysis(self.handle, str(path), None,