Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/binaryninja_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ def update_analysis_and_wait(filename: str, ctx: Context) -> str:
tools = MCPTools(bv)
return tools.update_analysis_and_wait()

@mcp.tool()
def set_comment(filename: str, address_or_name: str, comment: str, ctx: Context) -> bool:
"""Set a comment for a function or at specific address
Note: comments must be a text without `//` characters"""
bnctx: BNContext = ctx.request_context.lifespan_context
bv = bnctx.get_bv(filename)
tools = MCPTools(bv)
return tools.set_comment(address_or_name, comment)

return mcp


Expand Down
27 changes: 27 additions & 0 deletions src/binaryninja_mcp/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,30 @@ def update_analysis_and_wait(self) -> str:
# Start the analysis update
self.bv.update_analysis_and_wait()
return f'Analysis updated successfully for {self.bv.file.filename}'

@handle_exceptions
def set_comment(self, address_or_name: str, comment: str) -> bool:
"""Set a comment at the specified address

Args:
address: Address (hex string) to set the comment
comment: Comment text to set

Returns:
True if successful, False otherwise
"""
addr = self.resolve_symbol(address_or_name)
if addr is None:
raise ValueError(f"No symbol found with name/address '{address_or_name}'")

# function comments are located above function
if func := self.bv.get_function_at(addr):
func.comment = comment
return True

try:
self.bv.set_comment_at(addr, comment)
return True
except Exception as e:
logger.exception(f'Failed to set comment at {hex(addr)}: {str(e)}')
return False