diff options
| author | Glenn Smith <glenn@vector35.com> | 2024-12-27 16:14:46 -0500 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2025-01-30 17:20:05 -0500 |
| commit | 8862696926173104957729683832591438161557 (patch) | |
| tree | 78ba6d7dc8144430136086c8dc84726171eec8ab /python/function.py | |
| parent | 5a5426d030b6be26d4564ba1eba2d8a275533256 (diff) | |
Render Layers
Diffstat (limited to 'python/function.py')
| -rw-r--r-- | python/function.py | 82 |
1 files changed, 79 insertions, 3 deletions
diff --git a/python/function.py b/python/function.py index 80f0a37c..14cc5e43 100644 --- a/python/function.py +++ b/python/function.py @@ -3335,15 +3335,29 @@ class AdvancedFunctionAnalysisDataRequestor: @dataclass +class DisassemblyTextLineTypeInfo: + parent_type: Optional['types.Type'] + field_index: int + offset: int + + +@dataclass class DisassemblyTextLine: tokens: List['InstructionTextToken'] highlight: '_highlight.HighlightColor' address: Optional[int] il_instruction: Optional[ILInstructionType] + tags: List['binaryview.Tag'] + type_info: Optional[DisassemblyTextLineTypeInfo] def __init__( - self, tokens: List['InstructionTextToken'], address: Optional[int] = None, il_instr: Optional[ILInstructionType] = None, - color: Optional[Union['_highlight.HighlightColor', HighlightStandardColor]] = None + self, + tokens: List['InstructionTextToken'], + address: Optional[int] = None, + il_instr: Optional[ILInstructionType] = None, + color: Optional[Union['_highlight.HighlightColor', HighlightStandardColor]] = None, + tags: Optional[List['binaryview.Tag']] = None, + type_info: Optional[DisassemblyTextLineTypeInfo] = None, ): self.address = address self.tokens = tokens @@ -3358,6 +3372,10 @@ class DisassemblyTextLine: self.highlight = _highlight.HighlightColor(color) else: self.highlight = color + if tags is None: + tags = [] + self.tags = tags + self.type_info = type_info def __str__(self): return "".join(map(str, self.tokens)) @@ -3413,6 +3431,64 @@ class DisassemblyTextLine: self._find_address_and_indentation_tokens(collect_tokens) return result + @classmethod + def _from_core_struct(cls, struct: core.BNDisassemblyTextLine, il_func: Optional['ILFunctionType'] = None): + il_instr = None + if il_func is not None and struct.instrIndex < len(il_func): + try: + il_instr = il_func[struct.instrIndex] + except: + il_instr = None + tokens = InstructionTextToken._from_core_struct(struct.tokens, struct.count) + + tags = [] + for i in range(struct.tagCount): + tags.append(binaryview.Tag(handle=core.BNNewTagReference(struct.tags[i]))) + + type_info = None + if struct.typeInfo.hasTypeInfo: + parent_type = None + if struct.typeInfo.parentType: + parent_type = types.Type.create(core.BNNewTypeReference(struct.typeInfo.parentType)) + type_info = DisassemblyTextLineTypeInfo( + parent_type=parent_type, + field_index=struct.typeInfo.fieldIndex, + offset=struct.typeInfo.offset + ) + + return DisassemblyTextLine( + tokens, + struct.addr, + il_instr, + _highlight.HighlightColor._from_core_struct(struct.highlight), + tags, + type_info + ) + + def _to_core_struct(self) -> core.BNDisassemblyTextLine: + result = core.BNDisassemblyTextLine() + result.addr = self.address + if self.il_instruction is not None: + result.instrIndex = self.il_instruction.instr_index + else: + result.instrIndex = 0xffffffffffffffff + result.tokens = InstructionTextToken._get_core_struct(self.tokens) + result.count = len(self.tokens) + result.highlight = self.highlight._to_core_struct() + result.tagCount = len(self.tags) + result.tags = (ctypes.POINTER(core.BNTag) * len(self.tags))() + for i, tag in enumerate(self.tags): + result.tags[i] = tag.handle + if self.type_info is None: + result.typeInfo.hasTypeInfo = False + else: + result.typeInfo.hasTypeInfo = True + if self.type_info.parent_type is not None: + result.typeInfo.parentType = self.type_info.parent_type.handle + result.typeInfo.fieldIndex = self.type_info.field_index + result.typeInfo.offset = self.type_info.offset + return result + class DisassemblyTextRenderer: def __init__( @@ -3463,7 +3539,7 @@ class DisassemblyTextRenderer: def basic_block(self) -> Optional['basicblock.BasicBlock']: result = core.BNGetDisassemblyTextRendererBasicBlock(self.handle) if result: - return basicblock.BasicBlock(handle=result) + return basicblock.BasicBlock._from_core_block(handle=result) return None @basic_block.setter |
