From 8e82653a052cb1b32e2d5ca53fd8f014df3e8737 Mon Sep 17 00:00:00 2001 From: Galen Williamson Date: Fri, 23 Dec 2022 15:06:03 -0500 Subject: correct usage of `BNSetUserCallTypeAdjustment` in `Function.set_call_type_adjustment`. Fixes #3503 --- python/function.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'python') diff --git a/python/function.py b/python/function.py index 692761e5..8523e485 100644 --- a/python/function.py +++ b/python/function.py @@ -2882,17 +2882,36 @@ class Function: ) def set_call_type_adjustment( - self, addr: int, adjust_type: StringOrType, arch: Optional['architecture.Architecture'] = None + self, addr: int, adjust_type: Optional[StringOrType] = None, arch: Optional['architecture.Architecture'] = None ) -> None: - if isinstance(adjust_type, str): - (adjust_type, _) = self.view.parse_type_string(adjust_type) + """ + ``set_call_type_adjustment`` sets or removes the call type override at a call site to the given type. + + :param int addr: virtual address of the call instruction to adjust + :param str|types.Type|types.TypeBuilder adjust_type: (optional) overridden call type, or `None` to remove an existing adjustment + :param Architecture arch: (optional) Architecture of the instruction if different from self.arch + :Example: + + >>> # Change the current call site to no-return + >>> target = bv.get_function_at(list(filter(lambda ref: ref.address == here, current_function.call_sites))[0].mlil.dest.value.value) + >>> ft = target.function_type.mutable_copy() + >>> ft.can_return = False + >>> current_function.set_call_type_adjustment(here, ft) + """ if arch is None: arch = self.arch + if isinstance(adjust_type, str): + (adjust_type, _) = self.view.parse_type_string(adjust_type) + confidence = core.max_confidence + elif adjust_type is not None: + confidence = adjust_type.confidence if adjust_type is None: - tc = None + type_conf = None else: - tc = adjust_type._to_core_struct() - core.BNSetUserCallTypeAdjustment(self.handle, arch.handle, addr, tc) + type_conf = core.BNTypeWithConfidence() + type_conf.type = adjust_type.handle + type_conf.confidence = confidence + core.BNSetUserCallTypeAdjustment(self.handle, arch.handle, addr, type_conf) def set_call_stack_adjustment( self, addr: int, adjust: Union[int, 'types.OffsetWithConfidence'], -- cgit v1.3.1