From bc779f1e0140a933d65926b9af840a80636a6dd4 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 11 Jan 2018 13:52:12 -0500 Subject: get_valid_list is now a dict, as well as add documentation for plugin registration functions --- python/plugin.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/plugin.py b/python/plugin.py index f038d122..e0054d86 100644 --- a/python/plugin.py +++ b/python/plugin.py @@ -168,6 +168,17 @@ class PluginCommand(object): @classmethod def register(cls, name, description, action, is_valid = None): + """ + ``register`` Register a plugin + + :param str name: name of the plugin + :param str description: description of the plugin + :param action: function to call with the ``BinaryView`` as an argument + :param is_valid: optional argument of a function passed a ``BinaryView`` to determine whether the plugin should be enabled for that view + :rtype: None + + .. warning:: Calling ``register`` with the same function name will replace the existing function but will leak the memory of the original plugin. + """ startup._init_plugins() action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView))(lambda ctxt, view: cls._default_action(view, action)) is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView))(lambda ctxt, view: cls._default_is_valid(view, is_valid)) @@ -176,6 +187,17 @@ class PluginCommand(object): @classmethod def register_for_address(cls, name, description, action, is_valid = None): + """ + ``register_for_address`` Register a plugin to be called with an address argument + + :param str name: name of the plugin + :param str description: description of the plugin + :param action: function to call with the ``BinaryView`` and address as arguments + :param is_valid: optional argument of a function passed a ``BinaryView`` to determine whether the plugin should be enabled for that view + :rtype: None + + .. warning:: Calling ``register_for_address`` with the same function name will replace the existing function but will leak the memory of the original plugin. + """ startup._init_plugins() action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong)(lambda ctxt, view, addr: cls._address_action(view, addr, action)) is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong)(lambda ctxt, view, addr: cls._address_is_valid(view, addr, is_valid)) @@ -184,6 +206,17 @@ class PluginCommand(object): @classmethod def register_for_range(cls, name, description, action, is_valid = None): + """ + ``register_for_range`` Register a plugin to be called with a range argument + + :param str name: name of the plugin + :param str description: description of the plugin + :param action: function to call with the ``BinaryView`` and ``AddressRange`` as arguments + :param is_valid: optional argument of a function passed a ``BinaryView`` to determine whether the plugin should be enabled for that view + :rtype: None + + .. warning:: Calling ``register_for_range`` with the same function name will replace the existing function but will leak the memory of the original plugin. + """ startup._init_plugins() action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong, ctypes.c_ulonglong)(lambda ctxt, view, addr, length: cls._range_action(view, addr, length, action)) is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong, ctypes.c_ulonglong)(lambda ctxt, view, addr, length: cls._range_is_valid(view, addr, length, is_valid)) @@ -192,6 +225,17 @@ class PluginCommand(object): @classmethod def register_for_function(cls, name, description, action, is_valid = None): + """ + ``register_for_function`` Register a plugin to be called with a function argument + + :param str name: name of the plugin + :param str description: description of the plugin + :param action: function to call with the ``BinaryView`` and a ``Function`` as arguments + :param is_valid: optional argument of a function passed a ``BinaryView`` to determine whether the plugin should be enabled for that view + :rtype: None + + .. warning:: Calling ``register_for_function`` with the same function name will replace the existing function but will leak the memory of the original plugin. + """ startup._init_plugins() action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.POINTER(core.BNFunction))(lambda ctxt, view, func: cls._function_action(view, func, action)) is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.POINTER(core.BNFunction))(lambda ctxt, view, func: cls._function_is_valid(view, func, is_valid)) @@ -200,11 +244,12 @@ class PluginCommand(object): @classmethod def get_valid_list(cls, context): + """Dict of registered plugins""" commands = cls.list - result = [] + result = {} for cmd in commands: if cmd.is_valid(context): - result.append(cmd) + result[cmd.name] = cmd return result def is_valid(self, context): -- cgit v1.3.1 From 4866de9b9f0ef32dfa568aa38faafdfd4def4638 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 11 Jan 2018 20:49:32 -0500 Subject: fixes binaryninja-api #784 improper call to BNCreateEnumerationType --- python/types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/types.py b/python/types.py index 2557db2c..49f1fdeb 100644 --- a/python/types.py +++ b/python/types.py @@ -515,10 +515,10 @@ class Type(object): return Type(core.BNCreateNamedTypeReferenceFromType(view.handle, name)) @classmethod - def enumeration_type(self, arch, e, width=None): + def enumeration_type(self, arch, e, width=None, sign=False): if width is None: width = arch.default_int_size - return Type(core.BNCreateEnumerationType(e.handle, width)) + return Type(core.BNCreateEnumerationType(arch.handle, e.handle, width, sign)) @classmethod def pointer(self, arch, t, const=None, volatile=None, ref_type=None): -- cgit v1.3.1 From 5c6b13a5576ccbf9c64ba51079d1a3625661cb50 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 15 Jan 2018 18:29:11 -0500 Subject: Fix 'demangled' typo. --- python/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/types.py b/python/types.py index 49f1fdeb..27b4828f 100644 --- a/python/types.py +++ b/python/types.py @@ -634,7 +634,7 @@ class Type(object): return core.BNGenerateAutoDemangledTypeId(name) @classmethod - def get_auto_demanged_type_id_source(self): + def get_auto_demangled_type_id_source(self): return core.BNGetAutoDemangledTypeIdSource() def with_confidence(self, confidence): -- cgit v1.3.1 From cd8903be01bee8f38833bbabca2b7ae31880abb7 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 15 Jan 2018 18:30:08 -0500 Subject: Add platform check and access correct autodefined field. --- python/binaryview.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/binaryview.py b/python/binaryview.py index 6eb59db1..fae98c14 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -2095,6 +2095,8 @@ class BinaryView(object): """ if plat is None: plat = self.platform + if plat is None: + return None func = core.BNGetAnalysisFunction(self.handle, plat.handle, addr) if func is None: return None @@ -3398,7 +3400,7 @@ class BinaryView(object): return None result = Section(section.name, section.type, section.start, section.length, section.linkedSection, section.infoSection, section.infoData, section.align, section.entrySize, section.semantics, - section_list.autoDefined) + section.autoDefined) core.BNFreeSection(section) return result -- cgit v1.3.1 From a5328d944c9ba71e67ad2607d0a7f943f91645c2 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 25 Jan 2018 10:30:43 -0500 Subject: fixes #912 --- python/types.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/types.py b/python/types.py index 27b4828f..feb256d0 100644 --- a/python/types.py +++ b/python/types.py @@ -471,6 +471,7 @@ class Type(object): :param int width: width of the integer in bytes :param bool sign: optional variable representing signedness + :param string altname: alternate name for type """ if sign is None: sign = BoolWithConfidence(True, confidence = 0) @@ -484,8 +485,14 @@ class Type(object): return Type(core.BNCreateIntegerType(width, sign_conf, altname)) @classmethod - def float(self, width): - return Type(core.BNCreateFloatType(width)) + def float(self, width, altname=""): + """ + ``float`` class method for creating an floating point Types. + + :param int width: width of the floating point number in bytes + :param string altname: alternate name for type + """ + return Type(core.BNCreateFloatType(width, altname)) @classmethod def structure_type(self, structure_type): -- cgit v1.3.1