summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/debuginfo.py2
-rw-r--r--python/function.py25
-rw-r--r--python/types.py30
3 files changed, 52 insertions, 5 deletions
diff --git a/python/debuginfo.py b/python/debuginfo.py
index 6e179ab8..d95657c6 100644
--- a/python/debuginfo.py
+++ b/python/debuginfo.py
@@ -325,7 +325,7 @@ class DebugInfo(object):
for i in range(0, count.value):
if functions[i].type:
- function_type = _types.Type(core.BNNewTypeReference(functions[i].type))
+ function_type = _types.Type.create(core.BNNewTypeReference(functions[i].type))
else:
function_type = None
diff --git a/python/function.py b/python/function.py
index 42e5ea44..97655e41 100644
--- a/python/function.py
+++ b/python/function.py
@@ -546,6 +546,22 @@ class Function:
core.BNSetUserFunctionCanReturn(self.handle, bc)
@property
+ def is_pure(self) -> 'types.BoolWithConfidence':
+ """Whether function is pure"""
+ result = core.BNIsFunctionPure(self.handle)
+ return types.BoolWithConfidence(result.value, confidence=result.confidence)
+
+ @is_pure.setter
+ def is_pure(self, value: 'types.BoolWithConfidence') -> None:
+ bc = core.BNBoolWithConfidence()
+ bc.value = bool(value)
+ if hasattr(value, 'confidence'):
+ bc.confidence = value.confidence
+ else:
+ bc.confidence = core.max_confidence
+ core.BNSetUserFunctionPure(self.handle, bc)
+
+ @property
@deprecation.deprecated(deprecated_in="3.4.4049", details="Use Function.has_explicitly_defined_type instead.")
def explicitly_defined_type(self) -> bool:
"""Whether function has explicitly defined types (read-only)"""
@@ -2592,6 +2608,15 @@ class Function:
bc.confidence = core.max_confidence
core.BNSetAutoFunctionCanReturn(self.handle, bc)
+ def set_auto_pure(self, value: Union[bool, 'types.BoolWithConfidence']) -> None:
+ bc = core.BNBoolWithConfidence()
+ bc.value = bool(value)
+ if isinstance(value, types.BoolWithConfidence):
+ bc.confidence = value.confidence
+ else:
+ bc.confidence = core.max_confidence
+ core.BNSetAutoFunctionPure(self.handle, bc)
+
def set_auto_stack_adjustment(self, value: Union[int, 'types.OffsetWithConfidence']) -> None:
oc = core.BNOffsetWithConfidence()
oc.value = int(value)
diff --git a/python/types.py b/python/types.py
index 52426474..94b90527 100644
--- a/python/types.py
+++ b/python/types.py
@@ -981,7 +981,8 @@ class FunctionBuilder(TypeBuilder):
platform: Optional['_platform.Platform'] = None, confidence: int = core.max_confidence,
can_return: Optional[BoolWithConfidence] = None, reg_stack_adjust: Optional[Dict['architecture.RegisterName', OffsetWithConfidenceType]] = None,
return_regs: Optional[Union['RegisterSet', List['architecture.RegisterType']]] = None,
- name_type: 'NameType' = NameType.NoNameType
+ name_type: 'NameType' = NameType.NoNameType,
+ pure: Optional[BoolWithConfidence] = None
) -> 'FunctionBuilder':
param_buf = FunctionBuilder._to_core_struct(params)
if return_type is None:
@@ -1029,6 +1030,11 @@ class FunctionBuilder(TypeBuilder):
else:
can_return_conf = BoolWithConfidence.get_core_struct(can_return, core.max_confidence)
+ if pure is None:
+ pure_conf = BoolWithConfidence.get_core_struct(False, 0)
+ else:
+ pure_conf = BoolWithConfidence.get_core_struct(pure, core.max_confidence)
+
if stack_adjust is None:
stack_adjust_conf = OffsetWithConfidence.get_core_struct(0, 0)
else:
@@ -1038,7 +1044,7 @@ class FunctionBuilder(TypeBuilder):
handle = core.BNCreateFunctionTypeBuilder(
ret_conf, conv_conf, param_buf, len(params), vararg_conf, can_return_conf, stack_adjust_conf,
reg_stack_adjust_regs, reg_stack_adjust_values, len(reg_stack_adjust),
- return_regs_set, name_type
+ return_regs_set, name_type, pure_conf
)
assert handle is not None, "BNCreateFunctionTypeBuilder returned None"
return cls(handle, platform, confidence)
@@ -1075,6 +1081,14 @@ class FunctionBuilder(TypeBuilder):
core.BNSetFunctionTypeBuilderCanReturn(self._handle, BoolWithConfidence.get_core_struct(value))
@property
+ def pure(self) -> BoolWithConfidence:
+ return BoolWithConfidence.from_core_struct(core.BNIsTypeBuilderPure(self._handle))
+
+ @pure.setter
+ def pure(self, value: BoolWithConfidenceType) -> None:
+ core.BNSetTypeBuilderPure(self._handle, BoolWithConfidence.get_core_struct(value))
+
+ @property
def stack_adjust(self) -> OffsetWithConfidence:
return OffsetWithConfidence.from_core_struct(core.BNGetTypeBuilderStackAdjustment(self._handle))
@@ -2742,7 +2756,8 @@ class FunctionType(Type):
confidence: int = core.max_confidence,
can_return: Union[BoolWithConfidence, bool] = True, reg_stack_adjust: Optional[Dict['architecture.RegisterName', OffsetWithConfidenceType]] = None,
return_regs: Optional[Union['RegisterSet', List['architecture.RegisterType']]] = None,
- name_type: 'NameType' = NameType.NoNameType
+ name_type: 'NameType' = NameType.NoNameType,
+ pure: Union[BoolWithConfidence, bool] = False
) -> 'FunctionType':
if ret is None:
ret = VoidType.create()
@@ -2792,12 +2807,13 @@ class FunctionType(Type):
return_regs_set[i] = platform.arch.get_reg_index(reg)
_can_return = BoolWithConfidence.get_core_struct(can_return)
+ _pure = BoolWithConfidence.get_core_struct(pure)
if params is None:
params = []
func_type = core.BNCreateFunctionType(
ret_conf, conv_conf, param_buf, len(params), _variable_arguments, _can_return, _stack_adjust,
reg_stack_adjust_regs, reg_stack_adjust_values, len(reg_stack_adjust),
- return_regs_set, name_type
+ return_regs_set, name_type, _pure
)
assert func_type is not None, f"core.BNCreateFunctionType returned None {ret_conf} {conv_conf} {param_buf} {_variable_arguments} {_stack_adjust}"
@@ -2865,6 +2881,12 @@ class FunctionType(Type):
return BoolWithConfidence(result.value, confidence=result.confidence)
@property
+ def pure(self) -> BoolWithConfidence:
+ """Whether type is pure"""
+ result = core.BNIsTypePure(self._handle)
+ return BoolWithConfidence(result.value, confidence=result.confidence)
+
+ @property
def children(self) -> List[Type]:
return [self.return_value, *[param.type for param in self.parameters]]