set_comment
Add or update comments at specific addresses in IDA Pro’s disassembly and pseudocode to enhance code analysis and documentation during reverse engineering tasks.
Instructions
Set a comment for a given address in the function disassembly and pseudocode
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Address in the function to set the comment for | |
| comment | Yes | Comment text |
Implementation Reference
- Handler function for setting comments at specified addresses in both disassembly and decompiler views. This is the core implementation of the comment-setting tool (named 'set_comments').@tool @idawrite def set_comments(items: list[CommentOp] | CommentOp): """Set comments at addresses (both disassembly and decompiler views)""" if isinstance(items, dict): items = [items] results = [] for item in items: addr_str = item.get("addr", "") comment = item.get("comment", "") try: ea = parse_address(addr_str) if not idaapi.set_cmt(ea, comment, False): results.append( { "addr": addr_str, "error": f"Failed to set disassembly comment at {hex(ea)}", } ) continue if not ida_hexrays.init_hexrays_plugin(): results.append({"addr": addr_str, "ok": True}) continue try: cfunc = decompile_checked(ea) except IDAError: results.append({"addr": addr_str, "ok": True}) continue if ea == cfunc.entry_ea: idc.set_func_cmt(ea, comment, True) cfunc.refresh_func_ctext() results.append({"addr": addr_str, "ok": True}) continue eamap = cfunc.get_eamap() if ea not in eamap: results.append( { "addr": addr_str, "ok": True, "error": f"Failed to set decompiler comment at {hex(ea)}", } ) continue nearest_ea = eamap[ea][0].ea if cfunc.has_orphan_cmts(): cfunc.del_orphan_cmts() cfunc.save_user_cmts() tl = idaapi.treeloc_t() tl.ea = nearest_ea for itp in range(idaapi.ITP_SEMI, idaapi.ITP_COLON): tl.itp = itp cfunc.set_user_cmt(tl, comment) cfunc.save_user_cmts() cfunc.refresh_func_ctext() if not cfunc.has_orphan_cmts(): results.append({"addr": addr_str, "ok": True}) break cfunc.del_orphan_cmts() cfunc.save_user_cmts() else: results.append( { "addr": addr_str, "ok": True, "error": f"Failed to set decompiler comment at {hex(ea)}", } ) except Exception as e: results.append({"addr": addr_str, "error": str(e)}) return results
- TypedDict defining the input schema for comment operations: address and comment text.class CommentOp(TypedDict): """Comment operation""" addr: Annotated[str, "Address (hex or decimal)"] comment: Annotated[str, "Comment text"]
- src/ida_pro_mcp/ida_mcp/__init__.py:24-30 (registration)Import of api_modify module in __init__.py which triggers registration of all @tool decorated functions including set_comments via the MCP_SERVER.tool decorator.from . import api_modify from . import api_stack from . import api_debug from . import api_python from . import api_resources # Re-export key components for external use
- src/ida_pro_mcp/ida_mcp/rpc.py:17-18 (registration)The @tool decorator definition that registers functions with the MCP server under their function name (e.g., 'set_comments').def tool(func): return MCP_SERVER.tool(func)