Skip to content

Commit 0232317

Browse files
committed
Implement the rest of DTL FFI
1 parent 6245591 commit 0232317

File tree

1 file changed

+56
-7
lines changed

1 file changed

+56
-7
lines changed

python/function.py

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,16 +3334,30 @@ def close(self) -> None:
33343334
self._function = None
33353335

33363336

3337+
@dataclass
3338+
class DisassemblyTextLineTypeInfo:
3339+
parent_type: Optional['types.Type']
3340+
field_index: int
3341+
offset: int
3342+
3343+
33373344
@dataclass
33383345
class DisassemblyTextLine:
33393346
tokens: List['InstructionTextToken']
33403347
highlight: '_highlight.HighlightColor'
33413348
address: Optional[int]
33423349
il_instruction: Optional[ILInstructionType]
3350+
tags: List['binaryview.Tag']
3351+
type_info: Optional[DisassemblyTextLineTypeInfo]
33433352

33443353
def __init__(
3345-
self, tokens: List['InstructionTextToken'], address: Optional[int] = None, il_instr: Optional[ILInstructionType] = None,
3346-
color: Optional[Union['_highlight.HighlightColor', HighlightStandardColor]] = None
3354+
self,
3355+
tokens: List['InstructionTextToken'],
3356+
address: Optional[int] = None,
3357+
il_instr: Optional[ILInstructionType] = None,
3358+
color: Optional[Union['_highlight.HighlightColor', HighlightStandardColor]] = None,
3359+
tags: Optional[List['binaryview.Tag']] = None,
3360+
type_info: Optional[DisassemblyTextLineTypeInfo] = None,
33473361
):
33483362
self.address = address
33493363
self.tokens = tokens
@@ -3358,6 +3372,10 @@ def __init__(
33583372
self.highlight = _highlight.HighlightColor(color)
33593373
else:
33603374
self.highlight = color
3375+
if tags is None:
3376+
tags = []
3377+
self.tags = tags
3378+
self.type_info = type_info
33613379

33623380
def __str__(self):
33633381
return "".join(map(str, self.tokens))
@@ -3422,7 +3440,30 @@ def _from_core_struct(cls, struct: core.BNDisassemblyTextLine, il_func: Optional
34223440
except:
34233441
il_instr = None
34243442
tokens = InstructionTextToken._from_core_struct(struct.tokens, struct.count)
3425-
return DisassemblyTextLine(tokens, struct.addr, il_instr, _highlight.HighlightColor._from_core_struct(struct.highlight))
3443+
3444+
tags = []
3445+
for i in range(struct.tagCount):
3446+
tags.append(binaryview.Tag(handle=core.BNNewTagReference(struct.tags[i])))
3447+
3448+
type_info = None
3449+
if struct.typeInfo.hasTypeInfo:
3450+
parent_type = None
3451+
if struct.typeInfo.parentType:
3452+
parent_type = types.Type.create(core.BNNewTypeReference(struct.typeInfo.parentType))
3453+
type_info = DisassemblyTextLineTypeInfo(
3454+
parent_type=parent_type,
3455+
field_index=struct.typeInfo.fieldIndex,
3456+
offset=struct.typeInfo.offset
3457+
)
3458+
3459+
return DisassemblyTextLine(
3460+
tokens,
3461+
struct.addr,
3462+
il_instr,
3463+
_highlight.HighlightColor._from_core_struct(struct.highlight),
3464+
tags,
3465+
type_info
3466+
)
34263467

34273468
def _to_core_struct(self) -> core.BNDisassemblyTextLine:
34283469
result = core.BNDisassemblyTextLine()
@@ -3434,10 +3475,18 @@ def _to_core_struct(self) -> core.BNDisassemblyTextLine:
34343475
result.tokens = InstructionTextToken._get_core_struct(self.tokens)
34353476
result.count = len(self.tokens)
34363477
result.highlight = self.highlight._to_core_struct()
3437-
result.tagCount = 0 # TODO: Tags?
3438-
result.tags = None
3439-
# result.typeInfo = # TODO: LineTypeInfo ?
3440-
result.typeInfo.hasTypeInfo = False
3478+
result.tagCount = len(self.tags)
3479+
result.tags = (ctypes.POINTER(core.BNTag) * len(self.tags))()
3480+
for i, tag in enumerate(self.tags):
3481+
result.tags[i] = tag.handle
3482+
if self.type_info is None:
3483+
result.typeInfo.hasTypeInfo = False
3484+
else:
3485+
result.typeInfo.hasTypeInfo = True
3486+
if self.type_info.parent_type is not None:
3487+
result.typeInfo.parentType = self.type_info.parent_type.handle
3488+
result.typeInfo.fieldIndex = self.type_info.field_index
3489+
result.typeInfo.offset = self.type_info.offset
34413490
return result
34423491

34433492

0 commit comments

Comments
 (0)