From 13491e5eb8d50c242cf6858b111e404ea9f79239 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Fri, 22 Jul 2016 03:00:52 -0400 Subject: Add API to set type of function --- python/__init__.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/__init__.py b/python/__init__.py index fd4af520..9f090c2f 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -1733,6 +1733,18 @@ class BinaryView(object): return iter(LinearDisassemblyIterator(self, settings)) + def parse_type_string(self, text): + result = core.BNNameAndType() + errors = ctypes.c_char_p() + if not core.BNParseTypeString(self.handle, text, result, errors): + error_str = errors.value + core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte))) + raise SyntaxError, error_str + type_obj = Type(core.BNNewTypeReference(result.type)) + name = result.name + core.BNFreeNameAndType(result) + return type_obj, name + def __setattr__(self, name, value): try: object.__setattr__(self,name,value) @@ -2523,10 +2535,14 @@ class Function(object): core.BNGetFunctionLiftedIL(self.handle)), self) @property - def type(self): - """Function type (read-only)""" + def function_type(self): + """Function type""" return Type(core.BNGetFunctionType(self.handle)) + @function_type.setter + def function_type(self, value): + self.set_user_type(value) + @property def stack_layout(self): """List of function stack (read-only)""" @@ -2783,6 +2799,12 @@ class Function(object): core.BNFreeInstructionTextLines(lines, count.value) return result + def set_auto_type(self, value): + core.BNSetFunctionAutoType(self.handle, value.handle) + + def set_user_type(self, value): + core.BNSetFunctionUserType(self.handle, value.handle) + class BasicBlockEdge: def __init__(self, branch_type, target, arch): self.type = core.BNBranchType_names[branch_type] -- cgit v1.3.1