diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/__init__.py | 15 | ||||
| -rw-r--r-- | python/architecture.py | 4 | ||||
| -rw-r--r-- | python/basicblock.py | 4 | ||||
| -rw-r--r-- | python/binaryview.py | 8 | ||||
| -rw-r--r-- | python/examples/version_switcher.py | 34 | ||||
| -rw-r--r-- | python/function.py | 6 | ||||
| -rw-r--r-- | python/types.py | 14 | ||||
| -rw-r--r-- | python/update.py | 24 |
8 files changed, 90 insertions, 19 deletions
diff --git a/python/__init__.py b/python/__init__.py index 9b87aa47..b1f5cd08 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -48,6 +48,9 @@ from .scriptingprovider import * def shutdown(): + """ + ``shutdown`` cleanly shuts down the core, stopping all workers and closing all log files. + """ core.BNShutdown() @@ -80,4 +83,16 @@ bundled_plugin_path = core.BNGetBundledPluginDirectory() user_plugin_path = core.BNGetUserPluginDirectory() core_version = core.BNGetVersionString() +'''Core version''' + core_build_id = core.BNGetBuildId() +'''Build ID''' + +core_product = core.BNGetProduct() +'''Product string from the license file''' + +core_product_type = core.BNGetProductType() +'''Product type from the license file''' + +core_license_count = core.BNGetLicenseCount() +'''License count from the license file''' diff --git a/python/architecture.py b/python/architecture.py index 4cd0c597..5bafe949 100644 --- a/python/architecture.py +++ b/python/architecture.py @@ -1164,8 +1164,8 @@ class Architecture(object): def get_instruction_low_level_il(self, data, addr, il): """ - ``get_instruction_low_level_il`` appends LowLevelILExpr objects for the instruction at the given virtual - address ``addr`` with data ``data``. + ``get_instruction_low_level_il`` appends LowLevelILExpr objects to ``il`` for the instruction at the given + virtual address ``addr`` with data ``data``. :param str data: max_instruction_length bytes from the binary at virtual address ``addr`` :param int addr: virtual address of bytes in ``data`` diff --git a/python/basicblock.py b/python/basicblock.py index ffbcd217..f6dbd60d 100644 --- a/python/basicblock.py +++ b/python/basicblock.py @@ -217,6 +217,8 @@ class BasicBlock(object): """ if not isinstance(color, HighlightStandardColor) and not isinstance(color, highlight.HighlightColor): raise ValueError("Specified color is not one of HighlightStandardColor, highlight.HighlightColor") + if isinstance(color, HighlightStandardColor): + color = highlight.HighlightColor(color) core.BNSetAutoBasicBlockHighlight(self.handle, color._get_core_struct()) def set_user_highlight(self, color): @@ -231,4 +233,6 @@ class BasicBlock(object): """ if not isinstance(color, HighlightStandardColor) and not isinstance(color, highlight.HighlightColor): raise ValueError("Specified color is not one of HighlightStandardColor, highlight.HighlightColor") + if isinstance(color, HighlightStandardColor): + color = highlight.HighlightColor(color) core.BNSetUserBasicBlockHighlight(self.handle, color._get_core_struct()) diff --git a/python/binaryview.py b/python/binaryview.py index caa5d780..9753b653 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -348,7 +348,11 @@ class BinaryViewType(object): return None for available in view.available_view_types: if available.name != "Raw": - bv = cls[available.name].open(filename) + if filename.endswith(".bndb"): + bv = view.get_view_of_type(available.name) + else: + bv = cls[available.name].open(filename) + if update_analysis: bv.update_analysis_and_wait() return bv @@ -1952,7 +1956,7 @@ class BinaryView(object): def get_basic_blocks_starting_at(self, addr): """ - ``get_basic_blocks_at`` get a list of :py:Class:`BasicBlock` objects which start at the provided virtual address. + ``get_basic_blocks_starting_at`` get a list of :py:Class:`BasicBlock` objects which start at the provided virtual address. :param int addr: virtual address of BasicBlock desired :return: a list of :py:Class:`BasicBlock` objects diff --git a/python/examples/version_switcher.py b/python/examples/version_switcher.py index bc4f576c..9d5bbf05 100644 --- a/python/examples/version_switcher.py +++ b/python/examples/version_switcher.py @@ -20,10 +20,12 @@ # IN THE SOFTWARE. import sys -import binaryninja + +from binaryninja.update import UpdateChannel, are_auto_updates_enabled, set_auto_updates_enabled, is_update_installation_pending, install_pending_update +from binaryninja import core_version import datetime -chandefault = binaryninja.UpdateChannel.list[0].name +chandefault = UpdateChannel.list[0].name channel = None versions = [] @@ -31,17 +33,17 @@ versions = [] def load_channel(newchannel): global channel global versions - if (channel is None and newchannel == channel.name): + if (channel is not None and newchannel == channel.name): print "Same channel, not updating." else: try: print "Loading channel %s" % newchannel - channel = binaryninja.UpdateChannel[newchannel] + channel = UpdateChannel[newchannel] print "Loading versions..." versions = channel.versions except Exception: print "%s is not a valid channel name. Defaulting to " % chandefault - channel = binaryninja.UpdateChannel[chandefault] + channel = UpdateChannel[chandefault] def select(version): @@ -66,16 +68,20 @@ def select(version): print "Requesting update to latest version." else: print "Requesting update to prior version." - if binaryninja.are_auto_updates_enabled(): + if are_auto_updates_enabled(): print "Disabling automatic updates." - binaryninja.set_auto_updates_enabled(False) - if (version.version == binaryninja.core_version): + set_auto_updates_enabled(False) + if (version.version == core_version): print "Already running %s" % version.version else: print "version.version %s" % version.version - print "binaryninja.core_version %s" % binaryninja.core_version - print "Updating..." + print "core_version %s" % core_version + print "Downloading..." print version.update() + print "Installing..." + if is_update_installation_pending: + #note that the GUI will be launched after update but should still do the upgrade headless + install_pending_update() # forward updating won't work without reloading sys.exit() else: @@ -86,7 +92,7 @@ def list_channels(): done = False print "\tSelect channel:\n" while not done: - channel_list = binaryninja.UpdateChannel.list + channel_list = UpdateChannel.list for index, item in enumerate(channel_list): print "\t%d)\t%s" % (index + 1, item.name) print "\t%d)\t%s" % (len(channel_list) + 1, "Main Menu") @@ -104,7 +110,7 @@ def list_channels(): def toggle_updates(): - binaryninja.set_auto_updates_enabled(not binaryninja.are_auto_updates_enabled()) + set_auto_updates_enabled(not are_auto_updates_enabled()) def main(): @@ -114,8 +120,8 @@ def main(): while not done: print "\n\tBinary Ninja Version Switcher" print "\t\tCurrent Channel:\t%s" % channel.name - print "\t\tCurrent Version:\t%s" % binaryninja.core_version - print "\t\tAuto-Updates On:\t%s\n" % binaryninja.are_auto_updates_enabled() + print "\t\tCurrent Version:\t%s" % core_version + print "\t\tAuto-Updates On:\t%s\n" % are_auto_updates_enabled() for index, version in enumerate(versions): date = datetime.datetime.fromtimestamp(version.time).strftime('%c') print "\t%d)\t%s (%s)" % (index + 1, version.version, date) diff --git a/python/function.py b/python/function.py index 5f9f475a..3aeb8e22 100644 --- a/python/function.py +++ b/python/function.py @@ -766,7 +766,9 @@ class Function(object): """ if arch is None: arch = self.arch - if not isinstance(color, highlight.HighlightColor): + if not isinstance(color, HighlightStandardColor) and not isinstance(color, highlight.HighlightColor): + raise ValueError("Specified color is not one of HighlightStandardColor, highlight.HighlightColor") + if isinstance(color, HighlightStandardColor): color = highlight.HighlightColor(color = color) core.BNSetAutoInstructionHighlight(self.handle, arch.handle, addr, color._get_core_struct()) @@ -786,6 +788,8 @@ class Function(object): arch = self.arch if not isinstance(color, HighlightStandardColor) and not isinstance(color, highlight.HighlightColor): raise ValueError("Specified color is not one of HighlightStandardColor, highlight.HighlightColor") + if isinstance(color, HighlightStandardColor): + color = highlight.HighlightColor(color) core.BNSetUserInstructionHighlight(self.handle, arch.handle, addr, color._get_core_struct()) diff --git a/python/types.py b/python/types.py index f66625f8..43aaa66f 100644 --- a/python/types.py +++ b/python/types.py @@ -378,6 +378,12 @@ class Type(object): @classmethod def int(self, width, sign = True, altname=""): + """ + ``int`` class method for creating an int Type. + + :param int width: width of the integer in bytes + :param bool sign: optional variable representing signedness + """ return Type(core.BNCreateIntegerType(width, sign, altname)) @classmethod @@ -427,6 +433,14 @@ class Type(object): @classmethod def function(self, ret, params, calling_convention=None, variable_arguments=False): + """ + ``function`` class method for creating an function Type. + + :param Type ret: width of the integer in bytes + :param list(Type) params: list of parameter Types + :param CallingConvention calling_convention: optional argument for function calling convention + :param bool variable_arguments: optional argument for functions that have a variable number of arguments + """ param_buf = (core.BNNameAndType * len(params))() for i in xrange(0, len(params)): if isinstance(params[i], Type): diff --git a/python/update.py b/python/update.py index 7e2bd4ef..6417e4a0 100644 --- a/python/update.py +++ b/python/update.py @@ -238,5 +238,29 @@ def get_time_since_last_update_check(): return core.BNGetTimeSinceLastUpdateCheck() +def is_update_installation_pending(): + """ + ``is_update_installation_pending`` whether an update has been downloaded and is waiting installation + + :return: boolean True if an update is pending, false if no update is pending + :rtype: bool + """ + return core.BNIsUpdateInstallationPending() + + +def install_pending_update(): + """ + ``install_pending_update`` installs any pending updates + + :rtype: None + """ + errors = ctypes.c_char_p() + core.BNInstallPendingUpdate(errors) + if errors: + error_str = errors.value + core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte))) + raise IOError(error_str) + + def updates_checked(): core.BNUpdatesChecked() |
