summaryrefslogtreecommitdiff
path: root/python/typeprinter.py
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2023-02-20 21:58:55 -0500
committerGlenn Smith <glenn@vector35.com>2023-11-06 16:10:47 -0500
commit4108964609171327618627477163339656037111 (patch)
tree79f4c6da6394b973cee05cc42b6edd7e2e20909d /python/typeprinter.py
parentb270d7ebe1e2a406e1f7f14807987d24b0c4a846 (diff)
Type Containers
Diffstat (limited to 'python/typeprinter.py')
-rw-r--r--python/typeprinter.py30
1 files changed, 10 insertions, 20 deletions
diff --git a/python/typeprinter.py b/python/typeprinter.py
index d7af3087..d6bf579e 100644
--- a/python/typeprinter.py
+++ b/python/typeprinter.py
@@ -35,6 +35,7 @@ from . import platform as _platform
from . import types
from . import function as _function
from . import binaryview
+from . import typecontainer
from .log import log_error
from .enums import TokenEscapingType
@@ -220,11 +221,11 @@ class TypePrinter(metaclass=_TypePrinterMetaclass):
log_error(traceback.format_exc())
return False
- def _get_type_lines(self, ctxt, type, data, name, line_width, collapsed, escaping, result, result_count):
+ def _get_type_lines(self, ctxt, type, container, name, line_width, collapsed, escaping, result, result_count):
try:
result_py = self.get_type_lines(
types.Type.create(handle=core.BNNewTypeReference(type)),
- binaryview.BinaryView(handle=core.BNNewViewReference(data)),
+ typecontainer.TypeContainer(handle=container),
types.QualifiedName._from_core_struct(name.contents),
line_width, collapsed, escaping)
@@ -378,12 +379,12 @@ class TypePrinter(metaclass=_TypePrinterMetaclass):
"""
raise NotImplementedError()
- def get_type_lines(self, type: types.Type, data: binaryview.BinaryView, name: types.QualifiedNameType, line_width = 80, collapsed = False, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> List[types.TypeDefinitionLine]:
+ def get_type_lines(self, type: types.Type, container: 'typecontainer.TypeContainer', name: types.QualifiedNameType, line_width = 80, collapsed = False, escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType) -> List[types.TypeDefinitionLine]:
"""
Generate a multi-line representation of a type
:param type: Type to print
- :param data: Binary View in which the type is defined
+ :param container: Type Container containing the type and dependencies
:param name: Name of the type
:param line_width: Maximum width of lines, in characters
:param collapsed: Whether to collapse structure/enum blocks
@@ -488,31 +489,20 @@ class CoreTypePrinter(TypePrinter):
core.free_string(result_cpp)
return result
- def get_type_lines(self, type: types.Type, data: binaryview.BinaryView,
- name: types.QualifiedNameType, line_width = 80, collapsed = False,
+ def get_type_lines(self, type: types.Type, container: 'typecontainer.TypeContainer',
+ name: types.QualifiedNameType,
+ line_width = 80, collapsed = False,
escaping: TokenEscapingType = TokenEscapingType.BackticksTokenEscapingType
) -> List[types.TypeDefinitionLine]:
if not isinstance(name, types.QualifiedName):
name = types.QualifiedName(name)
count = ctypes.c_ulonglong()
core_lines = ctypes.POINTER(core.BNTypeDefinitionLine)()
- if not core.BNGetTypePrinterTypeLines(self.handle, type.handle, data.handle, name._to_core_struct(), line_width, collapsed, ctypes.c_int(escaping), core_lines, count):
+ if not core.BNGetTypePrinterTypeLines(self.handle, type.handle, container.handle, name._to_core_struct(), line_width, collapsed, ctypes.c_int(escaping), core_lines, count):
raise RuntimeError("BNGetTypePrinterTypeLines returned False")
lines = []
for i in range(count.value):
- tokens = _function.InstructionTextToken._from_core_struct(core_lines[i].tokens, core_lines[i].count)
- type_ = types.Type.create(handle=core.BNNewTypeReference(core_lines[i].type), platform=data.platform)
- root_type = types.Type.create(handle=core.BNNewTypeReference(core_lines[i].rootType), platform=data.platform)
- root_type_name = core.pyNativeStr(core_lines[i].rootTypeName)
- if core_lines[i].baseType:
- const_conf = types.BoolWithConfidence.get_core_struct(False, 0)
- volatile_conf = types.BoolWithConfidence.get_core_struct(False, 0)
- handle = core.BNCreateNamedTypeReference(core_lines[i].baseType, 0, 1, const_conf, volatile_conf)
- base_type = types.NamedTypeReferenceType(handle, data.platform)
- else:
- base_type = None
- line = types.TypeDefinitionLine(core_lines[i].lineType, tokens, type_, root_type, root_type_name, base_type,
- core_lines[i].baseOffset, core_lines[i].offset, core_lines[i].fieldIndex)
+ line = types.TypeDefinitionLine._from_core_struct(core_lines[i], container.platform)
lines.append(line)
core.BNFreeTypeDefinitionLineList(core_lines, count.value)
return lines