diff options
| author | Glenn Smith <glenn@vector35.com> | 2022-02-03 21:45:09 -0500 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2022-02-10 20:11:05 -0500 |
| commit | ece59d9114f566a0f364cf8c56d555b70952f70b (patch) | |
| tree | fa8703614af89adea1cfca26fe9a3cc13c4e1994 /python | |
| parent | babc57fefb70199ef388cab6d0feca95cc43307f (diff) | |
Move TypeView::getLinesForType into core as Type::GetLines
Diffstat (limited to 'python')
| -rw-r--r-- | python/types.py | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/python/types.py b/python/types.py index 055bf8d4..7538bcd5 100644 --- a/python/types.py +++ b/python/types.py @@ -28,7 +28,7 @@ from abc import abstractmethod from . import _binaryninjacore as core from .enums import ( StructureVariant, SymbolType, SymbolBinding, TypeClass, NamedTypeReferenceClass, ReferenceType, VariableSourceType, - TypeReferenceType, MemberAccess, MemberScope + TypeReferenceType, MemberAccess, MemberScope, TypeDefinitionLineType ) from . import callingconvention from . import function as _function @@ -199,6 +199,23 @@ class NameSpace(QualifiedName): return NameSpace(name)._to_core_struct() +@dataclass(frozen=True) +class TypeDefinitionLine: + line_type: TypeDefinitionLineType + tokens: List['_function.InstructionTextToken'] + type: 'Type' + root_type: 'Type' + root_type_name: str + offset: int + field_index: int + + def __str__(self): + return "".join(map(str, self.tokens)) + + def __repr__(self): + return f"<typeDefinitionLine {self.type}: {self}>" + + class CoreSymbol: def __init__(self, handle: core.BNSymbolHandle): self._handle = handle @@ -1590,6 +1607,36 @@ class Type: core.BNFreeInstructionText(tokens, count.value) return result + def get_lines( + self, bv: 'binaryview.BinaryView', name: str, line_width: int = 80, collapsed: bool = False + ) -> List['TypeDefinitionLine']: + """ + Get a list of :py:class:`TypeDefinitionLine` structures for representing a Type in a structured form. + This structure uses the same logic as Types View and will expand structures and enumerations + unless `collapsed` is set. + + :param BinaryView bv: BinaryView object owning this Type + :param str name: Displayed name of the Type + :param int line_width: Maximum width of lines (in characters) + :param bool collapsed: If the type should be collapsed, and not show fields/members + :return: Returns a list of :py:class:`TypeDefinitionLine` structures + :rtype: :py:class:`TypeDefinitionLine` + """ + count = ctypes.c_ulonglong() + core_lines = core.BNGetTypeLines(self._handle, bv.handle, name, line_width, collapsed, count) + assert core_lines is not None, "core.BNGetTypeLines returned None" + lines = [] + for i in range(count.value): + tokens = _function.InstructionTextToken._from_core_struct(core_lines[i].tokens, core_lines[i].count) + type_ = Type.create(handle=core.BNNewTypeReference(core_lines[i].type), platform=self._platform) + root_type = Type.create(handle=core.BNNewTypeReference(core_lines[i].rootType), platform=self._platform) + root_type_name = core.pyNativeStr(core_lines[i].rootTypeName) + line = TypeDefinitionLine(core_lines[i].lineType, tokens, type_, root_type, root_type_name, + core_lines[i].offset, core_lines[i].fieldIndex) + lines.append(line) + core.BNFreeTypeDefinitionLineList(core_lines, count.value) + return lines + def with_confidence(self, confidence) -> 'Type': return Type.create(handle=core.BNNewTypeReference(self._handle), platform=self._platform, confidence=confidence) |
