diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/binaryview.py | 4 | ||||
| -rw-r--r-- | python/plugin.py | 49 | ||||
| -rw-r--r-- | python/types.py | 17 |
3 files changed, 62 insertions, 8 deletions
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 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): diff --git a/python/types.py b/python/types.py index d44cc736..42ed7ddd 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): @@ -515,10 +522,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): @@ -634,7 +641,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): |
