summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2023-01-11 13:26:05 -0500
committerJosh Ferrell <josh@vector35.com>2023-01-11 17:44:59 -0500
commit60bf10e1239c790b073e8b3f7664c9b96532ed64 (patch)
treefe86ffaf78cc76695276924d1b59e5f9cdbf2ef3 /python
parent90fdc9606e1954612bb765e81470d10c4dd81f1a (diff)
Fix more api type hints
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py35
-rw-r--r--python/function.py24
2 files changed, 31 insertions, 28 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 8f2dae07..917d9e51 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -399,7 +399,7 @@ class BinaryViewEvent:
cls._binaryview_events[len(cls._binaryview_events)] = callback_obj
@staticmethod
- def _notify(view: core.BNBinaryView, callback: BinaryViewEventCallback) -> None:
+ def _notify(view: core.BNBinaryViewHandle, callback: BinaryViewEventCallback) -> None:
try:
file_metadata = filemetadata.FileMetadata(handle=core.BNGetFileForView(view))
view_obj = BinaryView(file_metadata=file_metadata, handle=core.BNNewViewReference(view))
@@ -519,25 +519,25 @@ class BinaryDataNotificationCallbacks:
except:
log_error(traceback.format_exc())
- def _function_added(self, ctxt, view: core.BNBinaryView, func: core.BNFunction) -> None:
+ def _function_added(self, ctxt, view: core.BNBinaryView, func: core.BNFunctionHandle) -> None:
try:
self._notify.function_added(self._view, _function.Function(self._view, core.BNNewFunctionReference(func)))
except:
log_error(traceback.format_exc())
- def _function_removed(self, ctxt, view: core.BNBinaryView, func: core.BNFunction) -> None:
+ def _function_removed(self, ctxt, view: core.BNBinaryView, func: core.BNFunctionHandle) -> None:
try:
self._notify.function_removed(self._view, _function.Function(self._view, core.BNNewFunctionReference(func)))
except:
log_error(traceback.format_exc())
- def _function_updated(self, ctxt, view: core.BNBinaryView, func: core.BNFunction) -> None:
+ def _function_updated(self, ctxt, view: core.BNBinaryView, func: core.BNFunctionHandle) -> None:
try:
self._notify.function_updated(self._view, _function.Function(self._view, core.BNNewFunctionReference(func)))
except:
log_error(traceback.format_exc())
- def _function_update_requested(self, ctxt, view: core.BNBinaryView, func: core.BNFunction) -> None:
+ def _function_update_requested(self, ctxt, view: core.BNBinaryView, func: core.BNFunctionHandle) -> None:
try:
self._notify.function_update_requested(
self._view, _function.Function(self._view, core.BNNewFunctionReference(func))
@@ -545,19 +545,19 @@ class BinaryDataNotificationCallbacks:
except:
log_error(traceback.format_exc())
- def _data_var_added(self, ctxt, view: core.BNBinaryView, var: core.BNDataVariable) -> None:
+ def _data_var_added(self, ctxt, view: core.BNBinaryView, var: core.BNDataVariableHandle) -> None:
try:
self._notify.data_var_added(self._view, DataVariable.from_core_struct(var[0], self._view))
except:
log_error(traceback.format_exc())
- def _data_var_removed(self, ctxt, view: core.BNBinaryView, var: core.BNDataVariable) -> None:
+ def _data_var_removed(self, ctxt, view: core.BNBinaryView, var: core.BNDataVariableHandle) -> None:
try:
self._notify.data_var_removed(self._view, DataVariable.from_core_struct(var[0], self._view))
except:
log_error(traceback.format_exc())
- def _data_var_updated(self, ctxt, view: core.BNBinaryView, var: core.BNDataVariable) -> None:
+ def _data_var_updated(self, ctxt, view: core.BNBinaryView, var: core.BNDataVariableHandle) -> None:
try:
self._notify.data_var_updated(self._view, DataVariable.from_core_struct(var[0], self._view))
except:
@@ -569,7 +569,7 @@ class BinaryDataNotificationCallbacks:
except:
log_error(traceback.format_exc())
- def _tag_type_updated(self, ctxt, view: core.BNBinaryView, tag_type: core.BNTagType) -> None:
+ def _tag_type_updated(self, ctxt, view: core.BNBinaryView, tag_type: core.BNTagTypeHandle) -> None:
try:
core_tag_type = core.BNNewTagTypeReference(tag_type)
assert core_tag_type is not None, "core.BNNewTagTypeReference returned None"
@@ -577,7 +577,7 @@ class BinaryDataNotificationCallbacks:
except:
log_error(traceback.format_exc())
- def _tag_added(self, ctxt, view: core.BNBinaryView, tag_ref: core.BNTagReference) -> None:
+ def _tag_added(self, ctxt, view: core.BNBinaryView, tag_ref: core.BNTagReferenceHandle) -> None:
try:
ref_type = tag_ref[0].refType
auto_defined = tag_ref[0].autoDefined
@@ -598,7 +598,7 @@ class BinaryDataNotificationCallbacks:
except:
log_error(traceback.format_exc())
- def _tag_updated(self, ctxt, view: core.BNBinaryView, tag_ref: core.BNTagReference) -> None:
+ def _tag_updated(self, ctxt, view: core.BNBinaryView, tag_ref: core.BNTagReferenceHandle) -> None:
try:
ref_type = tag_ref[0].refType
auto_defined = tag_ref[0].autoDefined
@@ -619,7 +619,7 @@ class BinaryDataNotificationCallbacks:
except:
log_error(traceback.format_exc())
- def _tag_removed(self, ctxt, view: core.BNBinaryView, tag_ref: core.BNTagReference) -> None:
+ def _tag_removed(self, ctxt, view: core.BNBinaryView, tag_ref: core.BNTagReferenceHandle) -> None:
try:
ref_type = tag_ref[0].refType
auto_defined = tag_ref[0].autoDefined
@@ -1645,10 +1645,11 @@ class SymbolMapping(collections.abc.Mapping): # type: ignore
else:
self._symbol_cache[sym.raw_name] = [sym]
except UnicodeDecodeError:
- if sym.raw_bytes in self._symbol_cache:
- self._symbol_cache[sym.raw_bytes].append(sym)
+ mapped_str = sym.raw_bytes.decode('charmap')
+ if mapped_str in self._symbol_cache:
+ self._symbol_cache[mapped_str].append(sym)
else:
- self._symbol_cache[sym.raw_bytes] = [sym]
+ self._symbol_cache[mapped_str] = [sym]
def __iter__(self) -> Iterator[str]:
if self._symbol_cache is None:
@@ -2462,8 +2463,8 @@ class BinaryView:
return FunctionList(self)
def mlil_functions(
- self, preload_limit: Optional[int] = None, function_generator: Generator['_function.Function', None,
- None] = None
+ self, preload_limit: Optional[int] = None,
+ function_generator: Optional[Generator['_function.Function', None, None]] = None
) -> Generator['mediumlevelil.MediumLevelILFunction', None, None]:
"""
Generates a list of il functions. This method should be used instead of 'functions' property if
diff --git a/python/function.py b/python/function.py
index dba979cb..4a780a67 100644
--- a/python/function.py
+++ b/python/function.py
@@ -2660,7 +2660,7 @@ class Function:
display_type = IntegerDisplayType[display_type]
core.BNSetIntegerConstantDisplayType(self.handle, arch.handle, instr_addr, value, operand, display_type)
- def reanalyze(self, update_type: Optional[FunctionUpdateType] = FunctionUpdateType.UserFunctionUpdate) -> None:
+ def reanalyze(self, update_type: FunctionUpdateType = FunctionUpdateType.UserFunctionUpdate) -> None:
"""
``reanalyze`` causes this functions to be reanalyzed. This function does not wait for the analysis to finish.
@@ -2672,7 +2672,7 @@ class Function:
"""
core.BNReanalyzeFunction(self.handle, update_type)
- def mark_updates_required(self, update_type: Optional[FunctionUpdateType] = FunctionUpdateType.UserFunctionUpdate) -> None:
+ def mark_updates_required(self, update_type: FunctionUpdateType = FunctionUpdateType.UserFunctionUpdate) -> None:
"""
``mark_updates_required`` indicates that this function needs to be reanalyzed during the next update cycle
@@ -2682,7 +2682,7 @@ class Function:
"""
core.BNMarkUpdatesRequired(self.handle, update_type)
- def mark_caller_updates_required(self, update_type: Optional[FunctionUpdateType] = FunctionUpdateType.UserFunctionUpdate) -> None:
+ def mark_caller_updates_required(self, update_type: FunctionUpdateType = FunctionUpdateType.UserFunctionUpdate) -> None:
"""
``mark_caller_updates_required`` indicates that callers of this function need to be reanalyzed during the next update cycle
@@ -2916,17 +2916,19 @@ class Function:
"""
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:
- type_conf = None
- else:
+
+ if adjust_type is not None:
+ if isinstance(adjust_type, str):
+ (adjust_type, _) = self.view.parse_type_string(adjust_type)
+ confidence = core.max_confidence
+ else:
+ confidence = adjust_type.confidence
type_conf = core.BNTypeWithConfidence()
type_conf.type = adjust_type.handle
type_conf.confidence = confidence
+ else:
+ type_conf = None
+
core.BNSetUserCallTypeAdjustment(self.handle, arch.handle, addr, type_conf)
def set_call_stack_adjustment(