ida_get_function_assembly_by_address
Retrieve assembly code for a specific function using its memory address through the IDA-MCP server, enabling analysis and debugging of binary files.
Instructions
Get assembly code for a function by address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes |
Implementation Reference
- Core IDA Pro implementation that retrieves function assembly by address using IDA APIs (ida_funcs.get_func, idautils.FuncItems, idc.GetDisasm). Wrapped with @idaread decorator for thread-safe execution.@idaread def get_function_assembly_by_address(self, address: int) -> Dict[str, Any]: """Get assembly code for a function by its address""" return self._get_function_assembly_by_address_internal(address) def _get_function_assembly_by_address_internal(self, address: int) -> Dict[str, Any]: """Internal implementation for get_function_assembly_by_address without sync wrapper""" try: # Get function object func = ida_funcs.get_func(address) # Get function name func_name = idaapi.get_func_name(func.start_ea) if not func: return {"error": f"Invalid function at {hex(address)}"} # Collect all assembly instructions assembly_lines = [] for instr_addr in idautils.FuncItems(address): disasm = idc.GetDisasm(instr_addr) assembly_lines.append(f"{hex(instr_addr)}: {disasm}") if not assembly_lines: return {"error": "No assembly instructions found"} return {"assembly": "\n".join(assembly_lines), "function_name": func_name} except Exception as e: print(f"Error getting function assembly: {str(e)}") traceback.print_exc() return {"error": str(e)}
- src/mcp_server_ida/server.py:826-857 (handler)MCP server-side handler proxy that validates input, converts address, sends socket request to IDA plugin, and formats response.def get_function_assembly_by_address(self, address: str) -> str: """Get assembly code for a function by its address""" try: # Convert string address to int try: addr_int = int(address, 16) if address.startswith("0x") else int(address) except ValueError: return f"Error: Invalid address format '{address}', expected hexadecimal (0x...) or decimal" response: Dict[str, Any] = self.communicator.send_request( "get_function_assembly_by_address", {"address": addr_int} ) if "error" in response: return f"Error retrieving assembly for address '{address}': {response['error']}" assembly: Any = response.get("assembly") function_name: str = response.get("function_name", "Unknown function") # Verify assembly is string type if assembly is None: return f"Error: No assembly data returned for address '{address}'" if not isinstance(assembly, str): self.logger.warning(f"Assembly data type is not string but {type(assembly).__name__}, attempting conversion") assembly = str(assembly) return f"Assembly code for function '{function_name}' at address {address}:\n{assembly}" except Exception as e: self.logger.error(f"Error getting function assembly by address: {str(e)}", exc_info=True) return f"Error retrieving assembly for address '{address}': {str(e)}"
- src/mcp_server_ida/server.py:21-22 (schema)Pydantic model defining the input schema for the tool (address as string).class GetFunctionAssemblyByAddress(BaseModel): address: str # Hexadecimal address as string
- src/mcp_server_ida/server.py:924-927 (registration)MCP tool registration in server.list_tools(), associating name, description, and input schema.name=IDATools.GET_FUNCTION_ASSEMBLY_BY_ADDRESS, description="Get assembly code for a function by address", inputSchema=GetFunctionAssemblyByAddress.schema(), ),
- src/mcp_server_ida/server.py:1034-1039 (handler)Dispatcher case in MCP server's call_tool() that invokes the handler function and returns TextContent response.case IDATools.GET_FUNCTION_ASSEMBLY_BY_ADDRESS: assembly: str = ida_functions.get_function_assembly_by_address(arguments["address"]) return [TextContent( type="text", text=assembly )]