Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/binaryninja_mcp/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def high_level_il(self, address_or_name: str) -> str:
func = self.bv.get_function_at(addr)
if not func:
raise ValueError(f'No function found at address {hex(addr)}')
comments = func.comments

# Get HLIL
hlil = func.hlil
Expand All @@ -195,10 +196,17 @@ def high_level_il(self, address_or_name: str) -> str:

# Format the HLIL output
lines = []
for instruction in hlil.instructions:
lines.append(f'{instruction.address:#x}: {instruction}\n')
if func.comment:
lines.append(f'{func.start:#x}: // {func.comment}')
lines.append(f'{func.start:#x}: {func}')

return ''.join(lines)
for line in hlil.root.lines:
if line.address in comments:
lines.append(f'{line.address:#x}: {line} // {comments[line.address]}')
else:
lines.append(f'{line.address:#x}: {line}')

return '\n'.join(lines)

@handle_exceptions
def medium_level_il(self, address_or_name: str) -> str:
Expand All @@ -217,6 +225,7 @@ def medium_level_il(self, address_or_name: str) -> str:
func = self.bv.get_function_at(addr)
if not func:
raise ValueError(f'No function found at address {hex(addr)}')
comments = func.comments

# Get MLIL
mlil = func.mlil
Expand All @@ -225,10 +234,20 @@ def medium_level_il(self, address_or_name: str) -> str:

# Format the MLIL output
lines = []
if func.comment:
lines.append(f'{func.start:#x}: // {func.comment}')
lines.append(f'{func.start:#x}: {func}')

# MLIL doesn't have a root property like HLIL, so we iterate through instructions directly
for instruction in mlil.instructions:
lines.append(f'{instruction.address:#x}: {instruction}\n')
if instruction.address in comments:
lines.append(
f'{instruction.address:#x}: {instruction} // {comments[instruction.address]}'
)
else:
lines.append(f'{instruction.address:#x}: {instruction}')

return ''.join(lines)
return '\n'.join(lines)

@handle_exceptions
def disassembly(self, address_or_name: str, length: Optional[int] = None) -> str:
Expand Down