From e25d8896b6306cb6f984964c77b6a670a39cd11d Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Wed, 26 Jan 2022 10:44:52 -0500 Subject: Convert SizeWithConfidence to OffsetWithConfidence and remove --- python/function.py | 26 +++++++++++++------------- python/types.py | 50 +------------------------------------------------- 2 files changed, 14 insertions(+), 62 deletions(-) (limited to 'python') diff --git a/python/function.py b/python/function.py index e328fd04..a16fc6e4 100644 --- a/python/function.py +++ b/python/function.py @@ -1145,13 +1145,13 @@ class Function: core.BNSetUserFunctionHasVariableArguments(self.handle, bc) @property - def stack_adjustment(self) -> 'types.SizeWithConfidence': + def stack_adjustment(self) -> 'types.OffsetWithConfidence': """Number of bytes removed from the stack after return""" result = core.BNGetFunctionStackAdjustment(self.handle) - return types.SizeWithConfidence(result.value, confidence = result.confidence) + return types.OffsetWithConfidence(result.value, confidence = result.confidence) @stack_adjustment.setter - def stack_adjustment(self, value:'types.SizeWithConfidence') -> None: + def stack_adjustment(self, value:'types.OffsetWithConfidence') -> None: oc = core.BNOffsetWithConfidence() oc.value = int(value) if hasattr(value, 'confidence'): @@ -2414,10 +2414,10 @@ class Function: bc.confidence = core.max_confidence core.BNSetAutoFunctionCanReturn(self.handle, bc) - def set_auto_stack_adjustment(self, value:Union[int, 'types.SizeWithConfidence']) -> None: + def set_auto_stack_adjustment(self, value:Union[int, 'types.OffsetWithConfidence']) -> None: oc = core.BNOffsetWithConfidence() oc.value = int(value) - if isinstance(value, types.SizeWithConfidence): + if isinstance(value, types.OffsetWithConfidence): oc.confidence = value.confidence else: oc.confidence = core.max_confidence @@ -2661,14 +2661,14 @@ class Function: result = core.BNGetFunctionRegisterValueAtExit(self.handle, self.arch.get_reg_index(reg)) return variable.RegisterValue.from_BNRegisterValue(result, self.arch) - def set_auto_call_stack_adjustment(self, addr:int, adjust:Union[int, 'types.SizeWithConfidence'], + def set_auto_call_stack_adjustment(self, addr:int, adjust:Union[int, 'types.OffsetWithConfidence'], arch:Optional['architecture.Architecture']=None) -> None: if arch is None: if self.arch is None: raise ValueError(f"Can't call {_function_name_()} for function with no architecture specified") arch = self.arch - if not isinstance(adjust, types.SizeWithConfidence): - adjust = types.SizeWithConfidence(adjust) + if not isinstance(adjust, types.OffsetWithConfidence): + adjust = types.OffsetWithConfidence(adjust) core.BNSetAutoCallStackAdjustment(self.handle, arch.handle, addr, adjust.value, adjust.confidence) def set_auto_call_reg_stack_adjustment(self, addr:int, adjust:Mapping['architecture.RegisterStackName', int], @@ -2715,14 +2715,14 @@ class Function: tc = adjust_type._to_core_struct() core.BNSetUserCallTypeAdjustment(self.handle, arch.handle, addr, tc) - def set_call_stack_adjustment(self, addr:int, adjust:Union[int, 'types.SizeWithConfidence'], + def set_call_stack_adjustment(self, addr:int, adjust:Union[int, 'types.OffsetWithConfidence'], arch:Optional['architecture.Architecture']=None): if arch is None: if self.arch is None: raise ValueError(f"Can't call {_function_name_()} for function with no architecture specified") arch = self.arch - if not isinstance(adjust, types.SizeWithConfidence): - adjust = types.SizeWithConfidence(adjust) + if not isinstance(adjust, types.OffsetWithConfidence): + adjust = types.OffsetWithConfidence(adjust) core.BNSetUserCallStackAdjustment(self.handle, arch.handle, addr, adjust.value, adjust.confidence) def set_call_reg_stack_adjustment(self, addr:int, @@ -2767,13 +2767,13 @@ class Function: platform = self.platform return types.Type.create(core.BNNewTypeReference(result.type), platform = platform, confidence = result.confidence) - def get_call_stack_adjustment(self, addr:int, arch:Optional['architecture.Architecture']=None) -> 'types.SizeWithConfidence': + def get_call_stack_adjustment(self, addr:int, arch:Optional['architecture.Architecture']=None) -> 'types.OffsetWithConfidence': if arch is None: if self.arch is None: raise ValueError(f"Can't call {_function_name_()} for function with no architecture specified") arch = self.arch result = core.BNGetCallStackAdjustment(self.handle, arch.handle, addr) - return types.SizeWithConfidence(result.value, confidence = result.confidence) + return types.OffsetWithConfidence(result.value, confidence = result.confidence) def get_call_reg_stack_adjustment(self, addr:int, arch:Optional['architecture.Architecture']=None) -> \ Dict['architecture.RegisterStackName', 'types.RegisterStackAdjustmentWithConfidence']: diff --git a/python/types.py b/python/types.py index 65a9f311..5a7357ee 100644 --- a/python/types.py +++ b/python/types.py @@ -38,7 +38,6 @@ from . import typelibrary QualifiedNameType = Union[Iterable[Union[str, bytes]], str, 'QualifiedName'] BoolWithConfidenceType = Union[bool, 'BoolWithConfidence'] -SizeWithConfidenceType = Union[int, 'SizeWithConfidence'] OffsetWithConfidenceType = Union[int, 'OffsetWithConfidence'] ParamsType = Union[List['Type'], List['FunctionParameter'], List[Tuple['Type', str]]] MembersType = Union[List['StructureMember'], List['Type'], List[Tuple['Type', str]]] @@ -448,53 +447,6 @@ class BoolWithConfidence: return BoolWithConfidence(value)._to_core_struct() -@dataclass(frozen=True) -class SizeWithConfidence: - value:int - confidence:int=core.max_confidence - - def __int__(self): - return self.value - - def __eq__(self, other): - if not isinstance(other, self.__class__): - return self.value == int(other) - else: - return (self.value, self.confidence) == (other.value, other.confidence) - - def __ne__(self, other): - return not (self == other) - - def __gt__(self, other): - return self.value > int(other) - - def __le__(self, other): - return self.value <= int(other) - - def __ge__(self, other): - return self.value >= int(other) - - def __lt__(self, other): - return self.value < int(other) - - def _to_core_struct(self) -> core.BNSizeWithConfidence: - result = core.BNSizeWithConfidence() - result.value = self.value - result.confidence = self.confidence - return result - - @classmethod - def from_core_struct(cls, core_struct:core.BNSizeWithConfidence) -> 'SizeWithConfidence': - return cls(core_struct.value, core_struct.confidence) - - @staticmethod - def get_core_struct(value:SizeWithConfidenceType) -> core.BNSizeWithConfidence: - if isinstance(value, SizeWithConfidence): - return value._to_core_struct() - else: - return SizeWithConfidence(value)._to_core_struct() - - @dataclass class MutableTypeBuilder: type:'TypeBuilder' @@ -655,7 +607,7 @@ class TypeBuilder: @staticmethod def function(ret:Optional['Type']=None, params:Optional[ParamsType]=None, calling_convention:'callingconvention.CallingConvention'=None, variable_arguments:BoolWithConfidenceType=BoolWithConfidence(False), - stack_adjust:SizeWithConfidenceType=0) -> 'FunctionBuilder': + stack_adjust:OffsetWithConfidenceType=0) -> 'FunctionBuilder': """ ``function`` class method for creating an function Type. :param Type ret: return Type of the function -- cgit v1.3.1