diff options
| author | Glenn Smith <glenn@vector35.com> | 2022-10-10 16:16:43 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2022-10-10 16:16:43 -0400 |
| commit | 1a4af13fbd61d68373335a458efe7780b7a67155 (patch) | |
| tree | 4a85f40d36b71499b79ad51c6247f9755433ad9b /python/types.py | |
| parent | b6a83fe96111ad3b6568666dead646ace54fd7e6 (diff) | |
[Python API] Fixed PointerType.origin to return a valid NTRType
Have to extract all the fields from it manually since python doesn't really have the concept of a bare NTR
Diffstat (limited to 'python/types.py')
| -rw-r--r-- | python/types.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/python/types.py b/python/types.py index 9febfa32..6ca9434c 100644 --- a/python/types.py +++ b/python/types.py @@ -2456,12 +2456,30 @@ class PointerType(Type): assert core_type is not None, "core.BNCreatePointerTypeOfWidth returned None" return cls(core.BNNewTypeReference(core_type), platform, confidence) - @property - def origin(self) -> Optional[Tuple['NamedTypeReferenceType', int]]: + def origin(self, bv: Optional['binaryview.BinaryView']) -> Optional[Tuple['NamedTypeReferenceType', int]]: ntr_handle = core.BNGetTypeNamedTypeReference(self._handle) if ntr_handle is None: return None - return (NamedTypeReferenceType(self._handle, self.platform, self.confidence, ntr_handle), self.offset) + + name = core.BNGetTypeReferenceName(ntr_handle) + type_name = QualifiedName._from_core_struct(name) + core.BNFreeQualifiedName(name) + + type_id = core.BNGetTypeReferenceId(ntr_handle) + t = None + if bv is not None: + t = bv.get_type_by_id(type_id) + + alignment = 0 + if t is not None: + alignment = t.alignment + width = 0 + if t is not None: + width = t.width + + type_class = core.BNGetTypeReferenceClass(ntr_handle) + + return (NamedTypeReferenceType.create(type_class, type_id, type_name, alignment, width, self.platform, self.confidence, self.const, self.volatile), self.offset) @property def target(self) -> Type: |
