Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions python/binaryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import inspect
import os
import uuid
from typing import Callable, Generator, Optional, Union, Tuple, List, Mapping, Any, \
from typing import Callable, Generator, Optional, Union, Tuple, List, Sequence, Mapping, Any, \
Iterator, Iterable, KeysView, ItemsView, ValuesView, Dict, overload
from dataclasses import dataclass
from enum import IntFlag
Expand Down Expand Up @@ -88,6 +88,7 @@
InstructionsType = Generator[Tuple[List['_function.InstructionTextToken'], int], None, None]
ProgressFuncType = Callable[[int, int], bool]
DataMatchCallbackType = Callable[[int, 'databuffer.DataBuffer'], bool]
TextMatchCallbackType = Callable[[int, str, 'lineardisassembly.LinearDisassemblyLine'], bool]
LineMatchCallbackType = Callable[[int, 'lineardisassembly.LinearDisassemblyLine'], bool]
StringOrType = Union[str, '_types.Type', '_types.TypeBuilder']

Expand Down Expand Up @@ -8560,7 +8561,7 @@ def define_user_type(self, name: Optional['_types.QualifiedNameType'], type_obj:
type_obj = type_obj.immutable_copy()
core.BNDefineUserAnalysisType(self.handle, _name, type_obj.handle)

def define_types(self, types: List[Tuple[str, Optional['_types.QualifiedNameType'], StringOrType]], progress_func: Optional[ProgressFuncType]) -> Mapping[str, '_types.QualifiedName']:
def define_types(self, types: Sequence[Tuple[str, Optional['_types.QualifiedNameType'], StringOrType]], progress_func: Optional[ProgressFuncType]) -> Mapping[str, '_types.QualifiedName']:
"""
``define_types`` registers multiple types as though calling :py:func:`define_type` multiple times.
The difference with this plural version is that it is optimized for adding many types
Expand Down Expand Up @@ -8612,7 +8613,7 @@ def define_types(self, types: List[Tuple[str, Optional['_types.QualifiedNameType
core.BNFreeStringList(result_ids, result_count)
core.BNFreeTypeNameList(result_names, result_count)

def define_user_types(self, types: List[Tuple[Optional['_types.QualifiedNameType'], StringOrType]], progress_func: Optional[ProgressFuncType]):
def define_user_types(self, types: Sequence[Tuple[Optional['_types.QualifiedNameType'], StringOrType]], progress_func: Optional[ProgressFuncType]):
"""
``define_user_types`` registers multiple types as though calling :py:func:`define_user_type` multiple times.
The difference with this plural version is that it is optimized for adding many types
Expand Down Expand Up @@ -9535,6 +9536,18 @@ def __next__(self):
if (not self.thread.is_alive()) and self.results.empty():
raise StopIteration

@overload
def find_all_data(
self, start: int, end: int, data: bytes, flags: FindFlag = FindFlag.FindCaseSensitive,
progress_func: Optional[ProgressFuncType] = None, match_callback: None = None
) -> QueueGenerator: ...

@overload
def find_all_data(
self, start: int, end: int, data: bytes, flags: FindFlag = FindFlag.FindCaseSensitive,
progress_func: Optional[ProgressFuncType] = None, match_callback: DataMatchCallbackType = None
) -> bool: ...

def find_all_data(
self, start: int, end: int, data: bytes, flags: FindFlag = FindFlag.FindCaseSensitive,
progress_func: Optional[ProgressFuncType] = None, match_callback: Optional[DataMatchCallbackType] = None
Expand Down Expand Up @@ -9610,10 +9623,24 @@ def _LinearDisassemblyLine_convertor(
core.BNFreeLinearDisassemblyLines(lines, 1)
return line

@overload
def find_all_text(
self, start: int, end: int, text: str, settings: Optional[_function.DisassemblySettings] = None,
flags=FindFlag.FindCaseSensitive, graph_type: _function.FunctionViewTypeOrName = FunctionGraphType.NormalFunctionGraph, progress_func=None,
match_callback: None = None
) -> QueueGenerator: ...

@overload
def find_all_text(
self, start: int, end: int, text: str, settings: Optional[_function.DisassemblySettings] = None,
flags=FindFlag.FindCaseSensitive, graph_type: _function.FunctionViewTypeOrName = FunctionGraphType.NormalFunctionGraph, progress_func=None,
match_callback: TextMatchCallbackType = None
) -> bool: ...

def find_all_text(
self, start: int, end: int, text: str, settings: Optional[_function.DisassemblySettings] = None,
flags=FindFlag.FindCaseSensitive, graph_type: _function.FunctionViewTypeOrName = FunctionGraphType.NormalFunctionGraph, progress_func=None,
match_callback=None
match_callback: Optional[TextMatchCallbackType] = None
) -> Union[QueueGenerator, bool]:
"""
``find_all_text`` searches for string ``text`` occurring in the linear view output starting
Expand Down Expand Up @@ -9679,7 +9706,7 @@ def find_all_text(
ctypes.POINTER(core.BNLinearDisassemblyLine)
)(
lambda ctxt, addr, match, line:
not match_callback(addr, match, self._LinearDisassemblyLine_convertor(line)) is False
not match_callback(addr, core.pyNativeStr(match), self._LinearDisassemblyLine_convertor(line)) is False
)

return core.BNFindAllTextWithProgress(
Expand All @@ -9692,7 +9719,7 @@ def find_all_text(
ctypes.c_bool, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_char_p,
ctypes.POINTER(core.BNLinearDisassemblyLine)
)(
lambda ctxt, addr, match, line: results.put((addr, match, self._LinearDisassemblyLine_convertor(line)))
lambda ctxt, addr, match, line: results.put((addr, core.pyNativeStr(match), self._LinearDisassemblyLine_convertor(line)))
or True
)

Expand All @@ -9705,6 +9732,20 @@ def find_all_text(

return self.QueueGenerator(t, results)

@overload
def find_all_constant(
self, start: int, end: int, constant: int, settings: Optional[_function.DisassemblySettings] = None,
graph_type: _function.FunctionViewTypeOrName = FunctionGraphType.NormalFunctionGraph, progress_func: Optional[ProgressFuncType] = None,
match_callback: None = None
) -> QueueGenerator: ...

@overload
def find_all_constant(
self, start: int, end: int, constant: int, settings: Optional[_function.DisassemblySettings] = None,
graph_type: _function.FunctionViewTypeOrName = FunctionGraphType.NormalFunctionGraph, progress_func: Optional[ProgressFuncType] = None,
match_callback: LineMatchCallbackType = None
) -> bool: ...

def find_all_constant(
self, start: int, end: int, constant: int, settings: Optional[_function.DisassemblySettings] = None,
graph_type: _function.FunctionViewTypeOrName = FunctionGraphType.NormalFunctionGraph, progress_func: Optional[ProgressFuncType] = None,
Expand Down Expand Up @@ -11497,6 +11538,12 @@ def __iter__(self):
for i in range(_type.count):
yield self[i]

@overload
def __getitem__(self, key: Union[str, int]) -> 'TypedDataAccessor': ...

@overload
def __getitem__(self, key: slice) -> List['TypedDataAccessor']: ...

def __getitem__(self, key: Union[str, int, slice]) -> Union['TypedDataAccessor', List['TypedDataAccessor']]:
_type = self.type
if isinstance(_type, _types.NamedTypeReferenceType):
Expand Down
14 changes: 7 additions & 7 deletions python/callingconvention.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,11 @@ def _get_incoming_reg_value(self, ctxt, reg, func, result):
result[0].state = api_obj.state
result[0].value = api_obj.value

def _get_incoming_flag_value(self, ctxt, reg, func, result):
def _get_incoming_flag_value(self, ctxt, flag, func, result):
try:
func_obj = function.Function(handle=core.BNNewFunctionReference(func))
reg_name = self.arch.get_reg_name(reg)
api_obj = self.perform_get_incoming_flag_value(reg_name, func_obj)._to_core_struct()
flag_name = self.arch.get_reg_name(flag)
api_obj = self.perform_get_incoming_flag_value(flag_name, func_obj)._to_core_struct()
except:
log_error_for_exception("Unhandled Python exception in CallingConvention._get_incoming_flag_value")
api_obj = variable.Undetermined()._to_core_struct()
Expand Down Expand Up @@ -444,7 +444,7 @@ def perform_get_incoming_reg_value(
return variable.Undetermined()

def perform_get_incoming_flag_value(
self, reg: 'architecture.RegisterName', func: 'function.Function'
self, flag: 'architecture.FlagName', func: 'function.Function'
) -> 'variable.RegisterValue':
return variable.Undetermined()

Expand Down Expand Up @@ -477,14 +477,14 @@ def get_incoming_reg_value(
)

def get_incoming_flag_value(
self, flag: 'architecture.FlagIndex', func: 'function.Function'
self, flag: 'architecture.FlagType', func: 'function.Function'
) -> 'variable.RegisterValue':
reg_num = self.arch.get_flag_index(flag)
flag_index = self.arch.get_flag_index(flag)
func_handle = None
if func is not None:
func_handle = func.handle
return variable.RegisterValue.from_BNRegisterValue(
core.BNGetIncomingFlagValue(self.handle, reg_num, func_handle), self.arch
core.BNGetIncomingFlagValue(self.handle, flag_index, func_handle), self.arch
)

def get_incoming_var_for_parameter_var(
Expand Down
8 changes: 4 additions & 4 deletions python/typeprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import ctypes
import dataclasses
from json import dumps
from typing import List, Tuple, Optional, Any
from typing import List, Sequence, Tuple, Optional, Any

import sys
import traceback
Expand Down Expand Up @@ -305,7 +305,7 @@ def _free_lines(self, ctxt, lines, count):
log_error_for_exception("Unhandled Python exception in TypePrinter._free_lines")
return False

def _default_print_all_types(self, types_: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, padding_cols = 64, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
def _default_print_all_types(self, types_: Sequence[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, padding_cols = 64, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
cpp_names = (core.BNQualifiedName * len(types_))()
cpp_types = (ctypes.POINTER(core.BNType) * len(types_))()

Expand Down Expand Up @@ -427,7 +427,7 @@ def get_type_lines(self, type: types.Type, container: 'typecontainer.TypeContain
"""
raise NotImplementedError()

def print_all_types(self, types: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, padding_cols = 64, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
def print_all_types(self, types: Sequence[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, padding_cols = 64, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
"""
Print all types to a single big string, including headers, sections, etc

Expand Down Expand Up @@ -541,7 +541,7 @@ def get_type_lines(self, type: types.Type, container: 'typecontainer.TypeContain
core.BNFreeTypeDefinitionLineList(core_lines, count.value)
return lines

def print_all_types(self, types_: List[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, padding_cols = 64, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
def print_all_types(self, types_: Sequence[Tuple[types.QualifiedNameType, types.Type]], data: binaryview.BinaryView, padding_cols = 64, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> str:
cpp_names = (core.BNQualifiedName * len(types_))()
cpp_types = (ctypes.POINTER(core.BNType) * len(types_))()

Expand Down
Loading